HD300 - add basic RTC support

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28697 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Marcin Bukat 2010-11-28 22:51:14 +00:00
parent 084c6905db
commit 2d3064a7aa
4 changed files with 133 additions and 2 deletions

View file

@ -252,6 +252,8 @@ drivers/rtc/rtc_tcc77x.c
drivers/rtc/rtc_jz4740.c
#elif (CONFIG_RTC == RTC_S35390A)
drivers/rtc/rtc_s35390a.c
#elif (CONFIG_RTC == RTC_S35380A)
drivers/rtc/rtc_s35380a.c
#elif (CONFIG_RTC == RTC_D2)
drivers/rtc/rtc_d2.c
#endif /* (CONFIG_RTC == RTC_) */

View file

@ -0,0 +1,128 @@
/***************************************************************************
* __________ __ ___.
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/
* $Id$
*
* adopted for HD300 by Marcin Bukat
* Copyright (C) 2009 by Bertrik Sikken
* Copyright (C) 2008 by Robert Kukla
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
****************************************************************************/
#include "config.h"
#include "rtc.h"
#include "i2c-coldfire.h"
/* Driver for the Seiko S35380A real-time clock chip with i2c interface
This driver was derived from rtc_s3539a.c and adapted for the MPIO HD300
*/
#define RTC_ADDR 0x60
#define STATUS_REG1 0
#define STATUS_REG2 1
#define REALTIME_DATA1 2
#define REALTIME_DATA2 3
#define INT1_REG 4
#define INT2_REG 5
#define CLOCK_CORR_REG 6
#define FREE_REG 7
/* STATUS_REG1 flags */
#define STATUS_REG1_POC 0x80
#define STATUS_REG1_BLD 0x40
#define STATUS_REG1_INT2 0x20
#define STATUS_REG1_INT1 0x10
#define STATUS_REG1_SC1 0x08
#define STATUS_REG1_SC0 0x04
#define STATUS_REG1_H1224 0x02
#define STATUS_REG1_RESET 0x01
static void reverse_bits(unsigned char* v, int size)
{
static const unsigned char flipnibble[] =
{0x00, 0x08, 0x04, 0x0C, 0x02, 0x0A, 0x06, 0x0E,
0x01, 0x09, 0x05, 0x0D, 0x03, 0x0B, 0x07, 0x0F};
int i;
for (i = 0; i < size; i++) {
v[i] = (flipnibble[v[i] & 0x0F] << 4) |
flipnibble[(v[i] >> 4) & 0x0F];
}
}
void rtc_init(void)
{
unsigned char status_reg;
i2c_read(I2C_IFACE_1, RTC_ADDR | (STATUS_REG1<<1), &status_reg, 1);
if ( (status_reg & STATUS_REG1_POC) ||
(status_reg & STATUS_REG1_BLD) )
{
/* perform rtc reset*/
status_reg |= STATUS_REG1_RESET;
i2c_write(I2C_IFACE_1, RTC_ADDR | (STATUS_REG1<<1), &status_reg, 1);
}
}
int rtc_read_datetime(struct tm *tm)
{
unsigned char buf[7];
unsigned int i;
int ret;
ret = i2c_read(I2C_IFACE_1, RTC_ADDR | (REALTIME_DATA1<<1), buf, sizeof(buf));
reverse_bits(buf, sizeof(buf));
buf[4] &= 0x3f; /* mask out p.m. flag */
for (i = 0; i < sizeof(buf); i++)
buf[i] = BCD2DEC(buf[i]);
tm->tm_sec = buf[6];
tm->tm_min = buf[5];
tm->tm_hour = buf[4];
tm->tm_wday = buf[3];
tm->tm_mday = buf[2];
tm->tm_mon = buf[1] - 1;
tm->tm_year = buf[0] + 100;
return ret;
}
int rtc_write_datetime(const struct tm *tm)
{
unsigned char buf[7];
unsigned int i;
int ret;
buf[6] = tm->tm_sec;
buf[5] = tm->tm_min;
buf[4] = tm->tm_hour;
buf[3] = tm->tm_wday;
buf[2] = tm->tm_mday;
buf[1] = tm->tm_mon + 1;
buf[0] = tm->tm_year - 100;
for (i = 0; i < sizeof(buf); i++)
buf[i] = DEC2BCD(buf[i]);
reverse_bits(buf, sizeof(buf));
ret = i2c_write(I2C_IFACE_1, RTC_ADDR | (REALTIME_DATA1<<1), buf, sizeof(buf));
return ret;
}

View file

@ -279,7 +279,8 @@ Lyre prototype 1 */
#define RTC_S35390A 15
#define RTC_JZ47XX 16 /* Ingenic Jz47XX */
#define RTC_NANO2G 17 /* This seems to be a PCF5063x */
#define RTC_D2 18 /* Either PCF50606 or PCF50635 */
#define RTC_D2 18 /* Either PCF50606 or PCF50635 */
#define RTC_S35380A 19
/* USB On-the-go */
#define USBOTG_M66591 6591 /* M:Robe 500 */

View file

@ -73,7 +73,7 @@
#define CONFIG_CODEC SWCODEC
/* Define this if you have RTC */
#define CONFIG_RTC RTC_S35390A
#define CONFIG_RTC RTC_S35380A
#define CONFIG_LCD LCD_S1D15E06