summaryrefslogtreecommitdiffstats
path: root/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-01 21:00:31 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2009-06-01 21:00:31 +0000
commitfd11471a3f9bfbb5f5bdf22866e861bae56ad8ea (patch)
tree8a61f852ef81a9dd5950e9ebc9ffb8ac41bf3390 /firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c
parent5212f03124c486239479d75cafb8017d84f63ee9 (diff)
downloadrockbox-fd11471a3f9bfbb5f5bdf22866e861bae56ad8ea.tar.gz
rockbox-fd11471a3f9bfbb5f5bdf22866e861bae56ad8ea.tar.bz2
rockbox-fd11471a3f9bfbb5f5bdf22866e861bae56ad8ea.zip
Onda VX747: try at implementing FM tuner support
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21160 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c')
-rw-r--r--firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c b/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c
index 5df0e90683..79968889b9 100644
--- a/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c
+++ b/firmware/target/mips/ingenic_jz47xx/i2c-jz4740.c
@@ -20,6 +20,10 @@
* KIND, either express or implied.
*
****************************************************************************/
+#include "config.h"
+#include "system.h"
+#include "jz4740.h"
+#include "logf.h"
/*
* Jz4740 I2C routines.
@@ -42,15 +46,9 @@
*
*/
-#include "config.h"
-#include "system.h"
-#include "jz4740.h"
-#include "logf.h"
-
-
/* I2C protocol */
#define I2C_READ 1
-#define I2C_WRITE 0
+#define I2C_WRITE 0
#define TIMEOUT 1000
@@ -84,7 +82,7 @@ static int i2c_put_data_nack(unsigned char data)
while (__i2c_check_drf() != 0);
while (!__i2c_transmit_ended());
while (timeout--);
-
+
return 0;
}
#endif
@@ -121,13 +119,13 @@ void i2c_setclk(unsigned int i2cclk)
/*
* I2C interface
*/
-void i2c_open(void)
+static void i2c_open(void)
{
i2c_setclk(10000); /* default 10 KHz */
__i2c_enable();
}
-void i2c_close(void)
+static void i2c_close(void)
{
udelay(300); /* wait for STOP goes over. */
__i2c_disable();
@@ -137,21 +135,23 @@ int i2c_read(int device, unsigned char *buf, int count)
{
int cnt = count;
int timeout = 5;
-
+
device &= 0xFF;
+ i2c_open();
+
L_try_again:
if (timeout < 0)
goto L_timeout;
__i2c_send_nack(); /* Master does not send ACK, slave sends it */
-
+
__i2c_send_start();
if (i2c_put_data( (device << 1) | I2C_READ ) < 0)
goto device_err;
-
+
__i2c_send_ack(); /* Master sends ACK for continue reading */
-
+
while (cnt)
{
if (cnt == 1)
@@ -170,7 +170,7 @@ L_try_again:
__i2c_send_stop();
return count - cnt;
-
+
device_err:
timeout--;
__i2c_send_stop();
@@ -179,6 +179,7 @@ device_err:
L_timeout:
__i2c_send_stop();
logf("Read I2C device 0x%2x failed.", device);
+ i2c_close();
return -1;
}
@@ -186,9 +187,11 @@ int i2c_write(int device, unsigned char *buf, int count)
{
int cnt = count;
int timeout = 5;
-
+
device &= 0xFF;
+ i2c_open();
+
__i2c_send_nack(); /* Master does not send ACK, slave sends it */
W_try_again:
@@ -200,7 +203,7 @@ W_try_again:
__i2c_send_start();
if (i2c_put_data( (device << 1) | I2C_WRITE ) < 0)
goto device_err;
-
+
#if 0 //CONFIG_JZ_TPANEL_ATA2508
if (address == 0xff)
{
@@ -226,7 +229,7 @@ W_try_again:
__i2c_send_stop();
return count - cnt;
-
+
device_err:
timeout--;
__i2c_send_stop();
@@ -235,6 +238,7 @@ device_err:
W_timeout:
logf("Write I2C device 0x%2x failed.", device);
__i2c_send_stop();
+ i2c_close();
return -1;
}