diff options
author | Michael Sparmann <theseven@rockbox.org> | 2011-02-07 18:43:05 +0000 |
---|---|---|
committer | Michael Sparmann <theseven@rockbox.org> | 2011-02-07 18:43:05 +0000 |
commit | 87da25c87cca6927d81bec2bf5c75b719f7d062f (patch) | |
tree | e354a81ee0afd2847338f64bf0bba54e547dd6eb /firmware | |
parent | 37e2c9c313e889c1873011c8ca144e4821417e4e (diff) | |
download | rockbox-87da25c87cca6927d81bec2bf5c75b719f7d062f.tar.gz rockbox-87da25c87cca6927d81bec2bf5c75b719f7d062f.zip |
S5L8702: Power down I2C while it's unused
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29241 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/target/arm/s5l8702/i2c-s5l8702.c | 46 |
1 files changed, 28 insertions, 18 deletions
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 @@ | |||
41 | 41 | ||
42 | static struct mutex i2c_mtx[2]; | 42 | static struct mutex i2c_mtx[2]; |
43 | 43 | ||
44 | void i2c_init(void) | 44 | static void i2c_on(int bus) |
45 | { | 45 | { |
46 | mutex_init(&i2c_mtx[0]); | 46 | /* enable I2C clock */ |
47 | mutex_init(&i2c_mtx[1]); | 47 | PWRCON(1) &= ~(1 << 4); |
48 | 48 | ||
49 | /* initial config */ | 49 | IICCON(bus) = (1 << 7) | /* ACK_GEN */ |
50 | IICADD(0) = 0; | 50 | (0 << 6) | /* CLKSEL = PCLK/16 */ |
51 | IICADD(1) = 0; | 51 | (1 << 5) | /* INT_EN */ |
52 | IICCON(0) = (1 << 7) | /* ACK_GEN */ | 52 | (1 << 4) | /* IRQ clear */ |
53 | (0 << 6) | /* CLKSEL = PCLK/16 */ | 53 | (7 << 0); /* CK_REG */ |
54 | (1 << 5) | /* INT_EN */ | ||
55 | (1 << 4) | /* IRQ clear */ | ||
56 | (3 << 0); /* CK_REG */ | ||
57 | IICCON(1) = (1 << 7) | /* ACK_GEN */ | ||
58 | (0 << 6) | /* CLKSEL = PCLK/16 */ | ||
59 | (1 << 5) | /* INT_EN */ | ||
60 | (1 << 4) | /* IRQ clear */ | ||
61 | (3 << 0); /* CK_REG */ | ||
62 | 54 | ||
63 | /* serial output on */ | 55 | /* serial output on */ |
64 | IICSTAT(0) = (1 << 4); | 56 | IICSTAT(bus) = (1 << 4); |
65 | IICSTAT(1) = (1 << 4); | 57 | } |
58 | |||
59 | static void i2c_off(int bus) | ||
60 | { | ||
61 | /* serial output off */ | ||
62 | IICSTAT(bus) = 0; | ||
63 | |||
64 | /* disable I2C clock */ | ||
65 | PWRCON(1) |= (1 << 4); | ||
66 | } | ||
67 | |||
68 | void i2c_init() | ||
69 | { | ||
70 | mutex_init(&i2c_mtx[0]); | ||
71 | mutex_init(&i2c_mtx[1]); | ||
66 | } | 72 | } |
67 | 73 | ||
68 | int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned char *data) | 74 | int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned char *data) |
69 | { | 75 | { |
70 | mutex_lock(&i2c_mtx[bus]); | 76 | mutex_lock(&i2c_mtx[bus]); |
77 | i2c_on(bus); | ||
71 | long timeout = current_tick + HZ / 50; | 78 | long timeout = current_tick + HZ / 50; |
72 | 79 | ||
73 | /* START */ | 80 | /* START */ |
@@ -116,6 +123,7 @@ int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned | |||
116 | return 5; | 123 | return 5; |
117 | } | 124 | } |
118 | 125 | ||
126 | i2c_off(bus); | ||
119 | mutex_unlock(&i2c_mtx[bus]); | 127 | mutex_unlock(&i2c_mtx[bus]); |
120 | return 0; | 128 | return 0; |
121 | } | 129 | } |
@@ -123,6 +131,7 @@ int i2c_write(int bus, unsigned char slave, int address, int len, const unsigned | |||
123 | int i2c_read(int bus, unsigned char slave, int address, int len, unsigned char *data) | 131 | int i2c_read(int bus, unsigned char slave, int address, int len, unsigned char *data) |
124 | { | 132 | { |
125 | mutex_lock(&i2c_mtx[bus]); | 133 | mutex_lock(&i2c_mtx[bus]); |
134 | i2c_on(bus); | ||
126 | long timeout = current_tick + HZ / 50; | 135 | long timeout = current_tick + HZ / 50; |
127 | 136 | ||
128 | if (address >= 0) { | 137 | if (address >= 0) { |
@@ -180,6 +189,7 @@ int i2c_read(int bus, unsigned char slave, int address, int len, unsigned char * | |||
180 | return 5; | 189 | return 5; |
181 | } | 190 | } |
182 | 191 | ||
192 | i2c_off(bus); | ||
183 | mutex_unlock(&i2c_mtx[bus]); | 193 | mutex_unlock(&i2c_mtx[bus]); |
184 | return 0; | 194 | return 0; |
185 | } | 195 | } |