summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2006-08-15 22:54:06 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2006-08-15 22:54:06 +0000
commitc4a59a290b81cae137f8b3c2b709c9c565701eb9 (patch)
tree9d54832f14b8fe365e427152011b62026f61e898 /firmware/drivers
parent98c9f959e53536a0b63d0376fad198ef883c5c03 (diff)
downloadrockbox-c4a59a290b81cae137f8b3c2b709c9c565701eb9.zip
rockbox-c4a59a290b81cae137f8b3c2b709c9c565701eb9.tar.gz
rockbox-c4a59a290b81cae137f8b3c2b709c9c565701eb9.tar.bz2
rockbox-c4a59a290b81cae137f8b3c2b709c9c565701eb9.tar.xz
eeprom driver for the h3x0 series, cleaned up the h1x0 series driver a bit, added debug entry for h3x0 that allows to write to the eeprom
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10597 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/eeprom_24cxx.c55
-rw-r--r--firmware/drivers/pcf50606.c12
2 files changed, 38 insertions, 29 deletions
diff --git a/firmware/drivers/eeprom_24cxx.c b/firmware/drivers/eeprom_24cxx.c
index 9a8fa5d..66bc235 100644
--- a/firmware/drivers/eeprom_24cxx.c
+++ b/firmware/drivers/eeprom_24cxx.c
@@ -35,21 +35,24 @@
#define SW_I2C_WRITE 0
#define SW_I2C_READ 1
+/* h1x0 needs its own i2c driver,
+ h3x0 uses the pcf i2c driver */
+
+#ifdef IRIVER_H100_SERIES
+
/* cute little functions, atomic read-modify-write */
/* SCL is GPIO, 12 */
-#define SCL_LO and_l(~0x00001000, &GPIO_OUT) // and_b(~0x10, &PBDRL)
-#define SCL_HI or_l( 0x00001000, &GPIO_OUT) // or_b( 0x10, &PBDRL)
-#define SCL_INPUT and_l(~0x00001000, &GPIO_ENABLE) // and_b(~0x10, &PBIORL)
-#define SCL_OUTPUT or_l( 0x00001000, &GPIO_ENABLE) // or_b( 0x10, &PBIORL)
-#define SCL ( 0x00001000 & GPIO_READ) // (PBDR & 0x0010)
+#define SCL ( 0x00001000 & GPIO_READ)
+#define SCL_OUT_LO and_l(~0x00001000, &GPIO_OUT)
+#define SCL_LO or_l( 0x00001000, &GPIO_ENABLE)
+#define SCL_HI and_l(~0x00001000, &GPIO_ENABLE); while(!SCL);
/* SDA is GPIO1, 13 */
-#define SDA_LO and_l(~0x00002000, &GPIO1_OUT) // and_b(~0x02, &PBDRL)
-#define SDA_HI or_l( 0x00002000, &GPIO1_OUT) // or_b( 0x02, &PBDRL)
-#define SDA_INPUT and_l(~0x00002000, &GPIO1_ENABLE) // and_b(~0x02, &PBIORL)
-#define SDA_OUTPUT or_l( 0x00002000, &GPIO1_ENABLE) // or_b( 0x02, &PBIORL)
-#define SDA ( 0x00002000 & GPIO1_READ) // (PBDR & 0x0002)
+#define SDA ( 0x00002000 & GPIO1_READ)
+#define SDA_OUT_LO and_l(~0x00002000, &GPIO1_OUT)
+#define SDA_LO or_l( 0x00002000, &GPIO1_ENABLE)
+#define SDA_HI and_l(~0x00002000, &GPIO1_ENABLE)
/* delay loop to achieve 400kHz at 120MHz CPU frequency */
#define DELAY do { int _x; for(_x=0;_x<22;_x++);} while(0)
@@ -61,17 +64,15 @@ static void sw_i2c_init(void)
or_l(0x00002000, &GPIO1_FUNCTION);
SDA_HI;
SCL_HI;
- SDA_OUTPUT;
- SCL_OUTPUT;
+ SDA_OUT_LO;
+ SCL_OUT_LO;
}
static void sw_i2c_start(void)
{
SCL_LO;
- SCL_OUTPUT;
DELAY;
SDA_HI;
- SDA_OUTPUT;
DELAY;
SCL_HI;
DELAY;
@@ -88,7 +89,6 @@ static void sw_i2c_stop(void)
DELAY;
}
-
static void sw_i2c_ack(void)
{
SCL_LO;
@@ -105,7 +105,7 @@ static bool sw_i2c_getack(void)
int count = 10;
SCL_LO;
- SDA_INPUT; /* And set to input */
+ SDA_HI; /* sets to input */
DELAY;
SCL_HI;
DELAY;
@@ -118,10 +118,8 @@ static bool sw_i2c_getack(void)
ret = false;
SCL_LO;
- SCL_OUTPUT;
DELAY;
SDA_LO;
- SDA_OUTPUT;
return ret;
}
@@ -143,8 +141,6 @@ static void sw_i2c_outb(unsigned char byte)
SCL_HI;
DELAY;
}
-
- // SDA_LO;
}
static unsigned char sw_i2c_inb(void)
@@ -152,7 +148,7 @@ static unsigned char sw_i2c_inb(void)
int i;
unsigned char byte = 0;
- SDA_INPUT; /* And set to input */
+ SDA_HI; /* sets to input */
/* clock in each bit, MSB first */
for ( i=0x80; i; i>>=1 )
@@ -165,13 +161,26 @@ static unsigned char sw_i2c_inb(void)
DELAY;
}
- SDA_OUTPUT;
-
sw_i2c_ack();
return byte;
}
+#else
+
+#include "pcf50606.h"
+
+#define sw_i2c_init() /* no extra init required */
+#define sw_i2c_start() pcf50606_i2c_start()
+#define sw_i2c_stop() pcf50606_i2c_stop()
+#define sw_i2c_ack() pcf50606_i2c_ack(true)
+#define sw_i2c_getack() pcf50606_i2c_getack()
+#define sw_i2c_outb(x) pcf50606_i2c_outb(x)
+#define sw_i2c_inb() pcf50606_i2c_inb(false)
+
+#endif /* IRIVER_H100_SERIES */
+
+
int sw_i2c_write(int location, const unsigned char* buf, int count)
{
int i;
diff --git a/firmware/drivers/pcf50606.c b/firmware/drivers/pcf50606.c
index 0f2d736..28df295 100644
--- a/firmware/drivers/pcf50606.c
+++ b/firmware/drivers/pcf50606.c
@@ -52,7 +52,7 @@ void pcf50606_i2c_recalc_delay(int cpu_clock)
i2c_delay = MAX(cpu_clock / (400000*2*3) - 7, 1);
}
-static inline void pcf50606_i2c_start(void)
+inline void pcf50606_i2c_start(void)
{
#ifdef USE_ASM
asm (
@@ -101,7 +101,7 @@ static inline void pcf50606_i2c_start(void)
#endif
}
-static inline void pcf50606_i2c_stop(void)
+inline void pcf50606_i2c_stop(void)
{
#ifdef USE_ASM
asm (
@@ -141,7 +141,7 @@ static inline void pcf50606_i2c_stop(void)
#endif
}
-static inline void pcf50606_i2c_ack(bool ack)
+inline void pcf50606_i2c_ack(bool ack)
{
#ifdef USE_ASM
asm (
@@ -193,7 +193,7 @@ static inline void pcf50606_i2c_ack(bool ack)
#endif
}
-static inline bool pcf50606_i2c_getack(void)
+inline bool pcf50606_i2c_getack(void)
{
bool ret;
@@ -251,7 +251,7 @@ static inline bool pcf50606_i2c_getack(void)
return ret;
}
-static void pcf50606_i2c_outb(unsigned char byte)
+void pcf50606_i2c_outb(unsigned char byte)
{
#ifdef USE_ASM
asm volatile (
@@ -321,7 +321,7 @@ static void pcf50606_i2c_outb(unsigned char byte)
#endif
}
-static unsigned char pcf50606_i2c_inb(bool ack)
+unsigned char pcf50606_i2c_inb(bool ack)
{
unsigned char byte = 0;