summaryrefslogtreecommitdiff
path: root/firmware/drivers/i2c-pp5020.c
diff options
context:
space:
mode:
authorBrandon Low <lostlogic@rockbox.org>2006-03-09 19:47:12 +0000
committerBrandon Low <lostlogic@rockbox.org>2006-03-09 19:47:12 +0000
commit19f4c2a093698940482aad6df0bd8478a82f2a9d (patch)
tree66de55749bcaaf45d95b828423ffca8c715b7112 /firmware/drivers/i2c-pp5020.c
parent5ecac908a2738e7a83dc0227daef3aaf16787dbc (diff)
downloadrockbox-19f4c2a093698940482aad6df0bd8478a82f2a9d.tar.gz
rockbox-19f4c2a093698940482aad6df0bd8478a82f2a9d.zip
Improve ipod i2c driver somewhat by at least taking advantage of the in-device addressing in the pcf50605, also switch to a 10bit resistive divider for the ipod battery reading, this is easily configurable if it needs changing, or even to become a user/runtime setting
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8980 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/drivers/i2c-pp5020.c')
-rw-r--r--firmware/drivers/i2c-pp5020.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/firmware/drivers/i2c-pp5020.c b/firmware/drivers/i2c-pp5020.c
index 232de9cb5a..8b48375e3d 100644
--- a/firmware/drivers/i2c-pp5020.c
+++ b/firmware/drivers/i2c-pp5020.c
@@ -63,7 +63,6 @@ static int ipod_i2c_wait_not_busy(void)
63 return -1; 63 return -1;
64} 64}
65 65
66
67static int ipod_i2c_read_byte(unsigned int addr, unsigned int *data) 66static int ipod_i2c_read_byte(unsigned int addr, unsigned int *data)
68{ 67{
69 if (ipod_i2c_wait_not_busy() < 0) 68 if (ipod_i2c_wait_not_busy() < 0)
@@ -72,6 +71,7 @@ static int ipod_i2c_read_byte(unsigned int addr, unsigned int *data)
72 } 71 }
73 72
74 { 73 {
74 unsigned int byte;
75 int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); 75 int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
76 76
77 /* clear top 15 bits, left shift 1, or in 0x1 for a read */ 77 /* clear top 15 bits, left shift 1, or in 0x1 for a read */
@@ -81,15 +81,18 @@ static int ipod_i2c_read_byte(unsigned int addr, unsigned int *data)
81 81
82 outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL); 82 outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL);
83 83
84 if (data) 84 set_irq_level(old_irq_level);
85 if (ipod_i2c_wait_not_busy() < 0)
85 { 86 {
86 if (ipod_i2c_wait_not_busy() < 0) 87 return -1;
87 {
88 set_irq_level(old_irq_level);
89 return -1;
90 }
91 *data = inb(IPOD_I2C_DATA0);
92 } 88 }
89 old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL);
90
91 byte = inb(IPOD_I2C_DATA0);
92
93 if (data)
94 *data = byte;
95
93 set_irq_level(old_irq_level); 96 set_irq_level(old_irq_level);
94 } 97 }
95 98
@@ -148,6 +151,19 @@ static int ipod_i2c_send_byte(unsigned int addr, int data0)
148/* Public functions */ 151/* Public functions */
149static struct mutex i2c_mutex; 152static struct mutex i2c_mutex;
150 153
154int i2c_readbytes(unsigned int dev_addr, int addr, int len, unsigned char *data) {
155 unsigned int temp;
156 int i;
157 mutex_lock(&i2c_mutex);
158 ipod_i2c_send_byte(dev_addr, addr);
159 for (i = 0; i < len; i++) {
160 ipod_i2c_read_byte(dev_addr, &temp);
161 data[i] = temp;
162 }
163 mutex_unlock(&i2c_mutex);
164 return i;
165}
166
151int i2c_readbyte(unsigned int dev_addr, int addr) 167int i2c_readbyte(unsigned int dev_addr, int addr)
152{ 168{
153 int data; 169 int data;