From 87da25c87cca6927d81bec2bf5c75b719f7d062f Mon Sep 17 00:00:00 2001 From: Michael Sparmann Date: Mon, 7 Feb 2011 18:43:05 +0000 Subject: S5L8702: Power down I2C while it's unused git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29241 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/s5l8702/i2c-s5l8702.c | 46 +++++++++++++++++++------------ 1 file changed, 28 insertions(+), 18 deletions(-) (limited to 'firmware/target/arm/s5l8702/i2c-s5l8702.c') diff --git a/firmware/target/arm/s5l8702/i2c-s5l8702.c b/firmware/target/arm/s5l8702/i2c-s5l8702.c index be286b34b7..954bacbd61 100644 --- a/firmware/target/arm/s5l8702/i2c-s5l8702.c +++ b/firmware/target/arm/s5l8702/i2c-s5l8702.c @@ -41,33 +41,40 @@ static struct mutex i2c_mtx[2]; -void i2c_init(void) +static void i2c_on(int bus) { - mutex_init(&i2c_mtx[0]); - mutex_init(&i2c_mtx[1]); + /* enable I2C clock */ + PWRCON(1) &= ~(1 << 4); - /* initial config */ - IICADD(0) = 0; - IICADD(1) = 0; - IICCON(0) = (1 << 7) | /* ACK_GEN */ - (0 << 6) | /* CLKSEL = PCLK/16 */ - (1 << 5) | /* INT_EN */ - (1 << 4) | /* IRQ clear */ - (3 << 0); /* CK_REG */ - IICCON(1) = (1 << 7) | /* ACK_GEN */ - (0 << 6) | /* CLKSEL = PCLK/16 */ - (1 << 5) | /* INT_EN */ - (1 << 4) | /* IRQ clear */ - (3 << 0); /* CK_REG */ + IICCON(bus) = (1 << 7) | /* ACK_GEN */ + (0 << 6) | /* CLKSEL = PCLK/16 */ + (1 << 5) | /* INT_EN */ + (1 << 4) | /* IRQ clear */ + (7 << 0); /* CK_REG */ /* serial output on */ - IICSTAT(0) = (1 << 4); - IICSTAT(1) = (1 << 4); + IICSTAT(bus) = (1 << 4); +} + +static void i2c_off(int bus) +{ + /* serial output off */ + IICSTAT(bus) = 0; + + /* disable I2C clock */ + PWRCON(1) |= (1 << 4); +} + +void i2c_init() +{ + mutex_init(&i2c_mtx[0]); + mutex_init(&i2c_mtx[1]); } int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned char *data) { mutex_lock(&i2c_mtx[bus]); + i2c_on(bus); long timeout = current_tick + HZ / 50; /* START */ @@ -116,6 +123,7 @@ int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned return 5; } + i2c_off(bus); mutex_unlock(&i2c_mtx[bus]); return 0; } @@ -123,6 +131,7 @@ int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned int i2c_read(int bus, unsigned char slave, int address, int len, unsigned char *data) { mutex_lock(&i2c_mtx[bus]); + i2c_on(bus); long timeout = current_tick + HZ / 50; if (address >= 0) { @@ -180,6 +189,7 @@ int i2c_read(int bus, unsigned char slave, int address, int len, unsigned char * return 5; } + i2c_off(bus); mutex_unlock(&i2c_mtx[bus]); return 0; } -- cgit v1.2.3