From cc029eecf97ffbc1c276706ee7910b8b7c1206d7 Mon Sep 17 00:00:00 2001 From: rob Date: Fri, 4 Apr 2008 20:24:08 +0000 Subject: [PATCH] Split out the PCF5060x register defines into a common header and create a generic pcf50606.c using standard i2c read/writes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16966 a1c6a512-1295-4272-9138-f99709370657 --- firmware/SOURCES | 1 + firmware/drivers/pcf50605.c | 70 ++++++---------------------------- firmware/drivers/pcf50606.c | 45 ++++++++++++++++++++++ firmware/export/pcf50606.h | 6 +++ firmware/export/pcf5060x.h | 93 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 157 insertions(+), 58 deletions(-) create mode 100644 firmware/drivers/pcf50606.c create mode 100644 firmware/export/pcf5060x.h diff --git a/firmware/SOURCES b/firmware/SOURCES index 19b160d8d..fa2222e7d 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES @@ -901,6 +901,7 @@ target/arm/tcc77x/iaudio7/power-iaudio7.c #ifdef COWON_D2 #ifndef SIMULATOR +drivers/pcf50606.c target/arm/lcd-as-memframe.S target/arm/tcc780x/adc-tcc780x.c target/arm/tcc780x/ata-nand-tcc780x.c diff --git a/firmware/drivers/pcf50605.c b/firmware/drivers/pcf50605.c index afa0a5ca1..7d88e46aa 100644 --- a/firmware/drivers/pcf50605.c +++ b/firmware/drivers/pcf50605.c @@ -29,54 +29,7 @@ #include "i2c-pp.h" #endif #include "rtc.h" - -#define OOCS 0x01 -#define INT1 0x02 -#define INT2 0x03 -#define INT3 0x04 -#define INT1M 0x05 -#define INT2M 0x06 -#define INT3M 0x07 -#define OOCC1 0x08 - #define GOSTDBY 0x1 - #define TOTRST (0x1 << 1) - #define CLK32ON (0x1 << 2) - #define WDTRST (0x1 << 3) - #define RTCWAK (0x1 << 4) - #define CHGWAK (0x1 << 5) - #define EXTONWAK (0x01 << 6) -#define OOCC2 0x09 -#define RTCSC 0x0a -#define RTCMN 0x0b -#define RTCHR 0x0c -#define RTCWD 0x0d -#define RTCDT 0x0e -#define RTCMT 0x0f -#define RTCYR 0x10 -#define RTCSCA 0x11 -#define RTCMNA 0x12 -#define RTCHRA 0x13 -#define RTCWDA 0x14 -#define RTCDTA 0x15 -#define RTCMTA 0x16 -#define RTCYRA 0x17 -#define PSSC 0x18 -#define PWROKM 0x19 -#define PWROKS 0x1a -#define DCDC1 0x1b -#define DCDC2 0x1c -#define DCDC3 0x1d -#define DCDC4 0x1e -#define DCDEC1 0x1f -#define DCDEC2 0x20 -#define DCUDC1 0x21 -#define DCUDC2 0x22 -#define IOREGC 0x23 -#define D1REGC1 0x24 -#define D2REGC1 0x25 -#define D3REGC1 0x26 -#define LPREG1C 0x27 - +#include "pcf5060x.h" unsigned char pcf50605_wakeup_flags = 0; @@ -117,7 +70,8 @@ int pcf50605_write_multiple(int address, const unsigned char* buf, int count) power on your iPod again. */ void pcf50605_standby_mode(void) { - pcf50605_write(OOCC1, GOSTDBY | CHGWAK | EXTONWAK | pcf50605_wakeup_flags); + pcf50605_write(PCF5060X_OOCC1, + GOSTDBY | CHGWAK | EXTONWAK | pcf50605_wakeup_flags); } void pcf50605_init(void) @@ -125,27 +79,27 @@ void pcf50605_init(void) #if defined (IPOD_VIDEO) /* I/O and GPO voltage supply (default: 0xf8 = 3.3V ON) */ /* ECO not allowed regarding data sheet */ - pcf50605_write(IOREGC, 0xf8); /* 3.3V ON */ + pcf50605_write(PCF5060X_IOREGC, 0xf8); /* 3.3V ON */ /* core voltage supply (default DCDC1/DCDC2: 0xec = 1.2V ON) */ /* ECO not stable, assumed due to less precision of voltage in ECO mode */ - pcf50605_write(DCDC1, 0xec); /* 1.2V ON */ - pcf50605_write(DCDC2, 0x0c); /* OFF */ + pcf50605_write(PCF5060X_DCDC1, 0xec); /* 1.2V ON */ + pcf50605_write(PCF5060X_DCDC2, 0x0c); /* OFF */ /* unknown (default: 0xe3 = 1.8V ON) */ - pcf50605_write(DCUDC1, 0xe3); /* 1.8V ON */ + pcf50605_write(PCF5060X_DCUDC1, 0xe3); /* 1.8V ON */ /* WM8758 voltage supply (default: 0xf5 = 3.0V ON) */ /* ECO not allowed as max. current of 5mA is not sufficient */ - pcf50605_write(D1REGC1, 0xf0); /* 2.5V ON */ + pcf50605_write(PCF5060X_D1REGC1, 0xf0); /* 2.5V ON */ /* LCD voltage supply (default: 0xf5 = 3.0V ON) */ - pcf50605_write(D3REGC1, 0xf1); /* 2.6V ON */ + pcf50605_write(PCF5060X_D3REGC1, 0xf1); /* 2.6V ON */ #else /* keep initialization from svn for other iPods */ - pcf50605_write(D1REGC1, 0xf5); /* 3.0V ON */ - pcf50605_write(D3REGC1, 0xf5); /* 3.0V ON */ + pcf50605_write(PCF5060X_D1REGC1, 0xf5); /* 3.0V ON */ + pcf50605_write(PCF5060X_D3REGC1, 0xf5); /* 3.0V ON */ #endif /* Dock Connector pin 17 (default: OFF) */ - pcf50605_write(D2REGC1, 0xf8); /* 3.3V ON */ + pcf50605_write(PCF5060X_D2REGC1, 0xf8); /* 3.3V ON */ } diff --git a/firmware/drivers/pcf50606.c b/firmware/drivers/pcf50606.c new file mode 100644 index 000000000..a93b94399 --- /dev/null +++ b/firmware/drivers/pcf50606.c @@ -0,0 +1,45 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Rob Purchase + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include "pcf50606.h" +#include "i2c.h" + +#define PCF50606_ADDR 0x10 + +int pcf50606_write(int address, unsigned char val) +{ + unsigned char data[] = { address, val }; + return i2c_write(PCF50606_ADDR, data, 2); +} + +int pcf50606_read(int address) +{ + unsigned char val = -1; + i2c_readmem(PCF50606_ADDR, address, &val, 1); + return val; +} + +int pcf50606_read_multiple(int address, unsigned char* buf, int count) +{ + return i2c_readmem(PCF50606_ADDR, address, buf, count); +} + +void pcf50606_init(void) +{ + // TODO +} diff --git a/firmware/export/pcf50606.h b/firmware/export/pcf50606.h index fab7e987d..44ca24f66 100644 --- a/firmware/export/pcf50606.h +++ b/firmware/export/pcf50606.h @@ -19,6 +19,12 @@ #ifndef PCF50606_H #define PCF50606_H +#include "pcf5060x.h" +#include "system.h" + +/* The following functions may either be implemented by an optimised driver + in the target tree, or by the generic drivers/pcf50606.c */ + void pcf50606_init(void); int pcf50606_write_multiple(int address, const unsigned char* buf, int count); int pcf50606_write(int address, unsigned char val); diff --git a/firmware/export/pcf5060x.h b/firmware/export/pcf5060x.h new file mode 100644 index 000000000..c05ab283e --- /dev/null +++ b/firmware/export/pcf5060x.h @@ -0,0 +1,93 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2008 by Rob Purchase + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#ifndef PCF5060X_H +#define PCF5060X_H + +/* PCF50605/6 Registers from datasheet rev2.2 */ + +#define PCF5060X_ID 0x00 +#define PCF5060X_OOCS 0x01 +#define PCF5060X_INT1 0x02 +#define PCF5060X_INT2 0x03 +#define PCF5060X_INT3 0x04 +#define PCF5060X_INT1M 0x05 +#define PCF5060X_INT2M 0x06 +#define PCF5060X_INT3M 0x07 +#define PCF5060X_OOCC1 0x08 + #define GOSTDBY 0x1 + #define TOTRST (0x1 << 1) + #define CLK32ON (0x1 << 2) + #define WDTRST (0x1 << 3) + #define RTCWAK (0x1 << 4) + #define CHGWAK (0x1 << 5) + #define EXTONWAK (0x01 << 6) +#define PCF5060X_OOCC2 0x09 +#define PCF5060X_RTCSC 0x0a +#define PCF5060X_RTCMN 0x0b +#define PCF5060X_RTCHR 0x0c +#define PCF5060X_RTCWD 0x0d +#define PCF5060X_RTCDT 0x0e +#define PCF5060X_RTCMT 0x0f +#define PCF5060X_RTCYR 0x10 +#define PCF5060X_RTCSCA 0x11 +#define PCF5060X_RTCMNA 0x12 +#define PCF5060X_RTCHRA 0x13 +#define PCF5060X_RTCWDA 0x14 +#define PCF5060X_RTCDTA 0x15 +#define PCF5060X_RTCMTA 0x16 +#define PCF5060X_RTCYRA 0x17 +#define PCF5060X_PSSC 0x18 +#define PCF5060X_PWROKM 0x19 +#define PCF5060X_PWROKS 0x1a +#define PCF5060X_DCDC1 0x1b +#define PCF5060X_DCDC2 0x1c +#define PCF5060X_DCDC3 0x1d +#define PCF5060X_DCDC4 0x1e +#define PCF5060X_DCDEC1 0x1f +#define PCF5060X_DCDEC2 0x20 +#define PCF5060X_DCUDC1 0x21 +#define PCF5060X_DCUDC2 0x22 +#define PCF5060X_IOREGC 0x23 +#define PCF5060X_D1REGC1 0x24 +#define PCF5060X_D2REGC1 0x25 +#define PCF5060X_D3REGC1 0x26 +#define PCF5060X_LPREGC1 0x27 +#define PCF5060X_LPREGC2 0x28 +#define PCF5060X_MBCC1 0x29 +#define PCF5060X_MBCC2 0x2a +#define PCF5060X_MBCC3 0x2b +#define PCF5060X_MBCS1 0x2c +#define PCF5060X_BBCC 0x2d +#define PCF5060X_ADCC1 0x2e +#define PCF5060X_ADCC2 0x2f +#define PCF5060X_ADCS1 0x30 +#define PCF5060X_ADCS2 0x31 +#define PCF5060X_ADCS3 0x32 +#define PCF5060X_ACDC1 0x33 +#define PCF5060X_BVMC 0x34 +#define PCF5060X_PWMC1 0x35 +#define PCF5060X_LEDC1 0x36 +#define PCF5060X_LEDC2 0x37 +#define PCF5060X_GPOC1 0x38 +#define PCF5060X_GPOC2 0x39 +#define PCF5060X_GPOC3 0x3a +#define PCF5060X_GPOC4 0x3b +#define PCF5060X_GPOC5 0x3c + +#endif /* PCF5060X_H */ -- 2.11.4.GIT