diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/SOURCES | 2 | ||||
-rw-r--r-- | firmware/export/i2c-pp5020.h | 11 | ||||
-rw-r--r-- | firmware/export/pp5020.h | 3 | ||||
-rw-r--r-- | firmware/target/arm/i2c-pp5020.c (renamed from firmware/drivers/i2c-pp5020.c) | 80 |
4 files changed, 46 insertions, 50 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES index 227eab1b6d..e393dc1678 100644 --- a/firmware/SOURCES +++ b/firmware/SOURCES | |||
@@ -255,7 +255,7 @@ common/strlen.c | |||
255 | target/arm/memset-arm.S | 255 | target/arm/memset-arm.S |
256 | target/arm/memset16-arm.S | 256 | target/arm/memset16-arm.S |
257 | #if CONFIG_I2C == I2C_PP5020 | 257 | #if CONFIG_I2C == I2C_PP5020 |
258 | drivers/i2c-pp5020.c | 258 | target/arm/i2c-pp5020.c |
259 | #elif CONFIG_I2C == I2C_PP5002 | 259 | #elif CONFIG_I2C == I2C_PP5002 |
260 | drivers/i2c-pp5002.c | 260 | drivers/i2c-pp5002.c |
261 | #elif CONFIG_I2C == I2C_PNX0101 | 261 | #elif CONFIG_I2C == I2C_PNX0101 |
diff --git a/firmware/export/i2c-pp5020.h b/firmware/export/i2c-pp5020.h index b8b10d6388..c52d07d24f 100644 --- a/firmware/export/i2c-pp5020.h +++ b/firmware/export/i2c-pp5020.h | |||
@@ -25,6 +25,17 @@ | |||
25 | #ifndef _I2C_PP5020_H | 25 | #ifndef _I2C_PP5020_H |
26 | #define _I2C_PP5020_H | 26 | #define _I2C_PP5020_H |
27 | 27 | ||
28 | #define I2C_CTRL (*(volatile unsigned char*)(I2C_BASE+0x00)) | ||
29 | #define I2C_ADDR (*(volatile unsigned char*)(I2C_BASE+0x04)) | ||
30 | #define I2C_DATA(X) (*(volatile unsigned char*)(I2C_BASE+0xc+(4*X))) | ||
31 | #define I2C_STATUS (*(volatile unsigned char*)(I2C_BASE+0x1c)) | ||
32 | |||
33 | /* I2C_CTRL bit definitions */ | ||
34 | #define I2C_SEND 0x80 | ||
35 | |||
36 | /* I2C_STATUS bit definitions */ | ||
37 | #define I2C_BUSY (1<<6) | ||
38 | |||
28 | /* TODO: Fully implement i2c driver */ | 39 | /* TODO: Fully implement i2c driver */ |
29 | 40 | ||
30 | void i2c_init(void); | 41 | void i2c_init(void); |
diff --git a/firmware/export/pp5020.h b/firmware/export/pp5020.h index cbae083913..a71ca7ef05 100644 --- a/firmware/export/pp5020.h +++ b/firmware/export/pp5020.h | |||
@@ -126,6 +126,7 @@ | |||
126 | #define DEV_EN (*(volatile unsigned long *)(0x6000600c)) | 126 | #define DEV_EN (*(volatile unsigned long *)(0x6000600c)) |
127 | 127 | ||
128 | #define DEV_SYSTEM 0x4 | 128 | #define DEV_SYSTEM 0x4 |
129 | #define DEV_I2C 0x1000 | ||
129 | #define DEV_USB 0x400000 | 130 | #define DEV_USB 0x400000 |
130 | 131 | ||
131 | #define DEV_INIT (*(volatile unsigned long *)(0x70000020)) | 132 | #define DEV_INIT (*(volatile unsigned long *)(0x70000020)) |
@@ -163,6 +164,8 @@ | |||
163 | #define SER1_MASK (1 << (SER1_IRQ-32)) | 164 | #define SER1_MASK (1 << (SER1_IRQ-32)) |
164 | #define I2C_MASK (1 << (I2C_IRQ-32)) | 165 | #define I2C_MASK (1 << (I2C_IRQ-32)) |
165 | 166 | ||
167 | #define I2C_BASE 0x7000c000 | ||
168 | |||
166 | #define IISCONFIG (*(volatile unsigned long*)(0x70002800)) | 169 | #define IISCONFIG (*(volatile unsigned long*)(0x70002800)) |
167 | 170 | ||
168 | #define IISFIFO_CFG (*(volatile unsigned long*)(0x7000280c)) | 171 | #define IISFIFO_CFG (*(volatile unsigned long*)(0x7000280c)) |
diff --git a/firmware/drivers/i2c-pp5020.c b/firmware/target/arm/i2c-pp5020.c index 2aeb11128d..95a677ea01 100644 --- a/firmware/drivers/i2c-pp5020.c +++ b/firmware/target/arm/i2c-pp5020.c | |||
@@ -32,21 +32,6 @@ | |||
32 | 32 | ||
33 | /* Local functions definitions */ | 33 | /* Local functions definitions */ |
34 | 34 | ||
35 | #define IPOD_I2C_BASE 0x7000c000 | ||
36 | #define IPOD_I2C_CTRL (IPOD_I2C_BASE+0x00) | ||
37 | #define IPOD_I2C_ADDR (IPOD_I2C_BASE+0x04) | ||
38 | #define IPOD_I2C_DATA0 (IPOD_I2C_BASE+0x0c) | ||
39 | #define IPOD_I2C_DATA1 (IPOD_I2C_BASE+0x10) | ||
40 | #define IPOD_I2C_DATA2 (IPOD_I2C_BASE+0x14) | ||
41 | #define IPOD_I2C_DATA3 (IPOD_I2C_BASE+0x18) | ||
42 | #define IPOD_I2C_STATUS (IPOD_I2C_BASE+0x1c) | ||
43 | |||
44 | /* IPOD_I2C_CTRL bit definitions */ | ||
45 | #define IPOD_I2C_SEND 0x80 | ||
46 | |||
47 | /* IPOD_I2C_STATUS bit definitions */ | ||
48 | #define IPOD_I2C_BUSY (1<<6) | ||
49 | |||
50 | #define POLL_TIMEOUT (HZ) | 35 | #define POLL_TIMEOUT (HZ) |
51 | 36 | ||
52 | static int pp_i2c_wait_not_busy(void) | 37 | static int pp_i2c_wait_not_busy(void) |
@@ -54,7 +39,7 @@ static int pp_i2c_wait_not_busy(void) | |||
54 | unsigned long timeout; | 39 | unsigned long timeout; |
55 | timeout = current_tick + POLL_TIMEOUT; | 40 | timeout = current_tick + POLL_TIMEOUT; |
56 | while (TIME_BEFORE(current_tick, timeout)) { | 41 | while (TIME_BEFORE(current_tick, timeout)) { |
57 | if (!(inb(IPOD_I2C_STATUS) & IPOD_I2C_BUSY)) { | 42 | if (!(I2C_STATUS & I2C_BUSY)) { |
58 | return 0; | 43 | return 0; |
59 | } | 44 | } |
60 | yield(); | 45 | yield(); |
@@ -75,11 +60,11 @@ static int pp_i2c_read_byte(unsigned int addr, unsigned int *data) | |||
75 | int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); | 60 | int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); |
76 | 61 | ||
77 | /* clear top 15 bits, left shift 1, or in 0x1 for a read */ | 62 | /* clear top 15 bits, left shift 1, or in 0x1 for a read */ |
78 | outb(((addr << 17) >> 16) | 0x1, IPOD_I2C_ADDR); | 63 | I2C_ADDR = ((addr << 17) >> 16) | 0x1 ; |
79 | 64 | ||
80 | outb(inb(IPOD_I2C_CTRL) | 0x20, IPOD_I2C_CTRL); | 65 | I2C_CTRL |= 0x20; |
81 | 66 | ||
82 | outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL); | 67 | I2C_CTRL |= I2C_SEND; |
83 | 68 | ||
84 | set_irq_level(old_irq_level); | 69 | set_irq_level(old_irq_level); |
85 | if (pp_i2c_wait_not_busy() < 0) | 70 | if (pp_i2c_wait_not_busy() < 0) |
@@ -88,7 +73,7 @@ static int pp_i2c_read_byte(unsigned int addr, unsigned int *data) | |||
88 | } | 73 | } |
89 | old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); | 74 | old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); |
90 | 75 | ||
91 | byte = inb(IPOD_I2C_DATA0); | 76 | byte = I2C_DATA(0); |
92 | 77 | ||
93 | if (data) | 78 | if (data) |
94 | *data = byte; | 79 | *data = byte; |
@@ -101,7 +86,6 @@ static int pp_i2c_read_byte(unsigned int addr, unsigned int *data) | |||
101 | 86 | ||
102 | static int pp_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char *data) | 87 | static int pp_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char *data) |
103 | { | 88 | { |
104 | int data_addr; | ||
105 | unsigned int i; | 89 | unsigned int i; |
106 | 90 | ||
107 | if (len < 1 || len > 4) | 91 | if (len < 1 || len > 4) |
@@ -118,20 +102,18 @@ static int pp_i2c_send_bytes(unsigned int addr, unsigned int len, unsigned char | |||
118 | int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); | 102 | int old_irq_level = set_irq_level(HIGHEST_IRQ_LEVEL); |
119 | 103 | ||
120 | /* clear top 15 bits, left shift 1 */ | 104 | /* clear top 15 bits, left shift 1 */ |
121 | outb((addr << 17) >> 16, IPOD_I2C_ADDR); | 105 | I2C_ADDR = (addr << 17) >> 16; |
122 | 106 | ||
123 | outb(inb(IPOD_I2C_CTRL) & ~0x20, IPOD_I2C_CTRL); | 107 | I2C_CTRL &= ~0x20; |
124 | 108 | ||
125 | data_addr = IPOD_I2C_DATA0; | ||
126 | for ( i = 0; i < len; i++ ) | 109 | for ( i = 0; i < len; i++ ) |
127 | { | 110 | { |
128 | outb(*data++, data_addr); | 111 | I2C_DATA(i) = *data++; |
129 | data_addr += 4; | ||
130 | } | 112 | } |
131 | 113 | ||
132 | outb((inb(IPOD_I2C_CTRL) & ~0x26) | ((len-1) << 1), IPOD_I2C_CTRL); | 114 | I2C_CTRL = (I2C_CTRL & ~0x26) | ((len-1) << 1); |
133 | 115 | ||
134 | outb(inb(IPOD_I2C_CTRL) | IPOD_I2C_SEND, IPOD_I2C_CTRL); | 116 | I2C_CTRL |= I2C_SEND; |
135 | 117 | ||
136 | set_irq_level(old_irq_level); | 118 | set_irq_level(old_irq_level); |
137 | } | 119 | } |
@@ -178,39 +160,39 @@ int i2c_readbyte(unsigned int dev_addr, int addr) | |||
178 | 160 | ||
179 | int pp_i2c_send(unsigned int addr, int data0, int data1) | 161 | int pp_i2c_send(unsigned int addr, int data0, int data1) |
180 | { | 162 | { |
181 | int retval; | 163 | int retval; |
182 | unsigned char data[2]; | 164 | unsigned char data[2]; |
183 | 165 | ||
184 | data[0] = data0; | 166 | data[0] = data0; |
185 | data[1] = data1; | 167 | data[1] = data1; |
186 | 168 | ||
187 | mutex_lock(&i2c_mutex); | 169 | mutex_lock(&i2c_mutex); |
188 | retval = pp_i2c_send_bytes(addr, 2, data); | 170 | retval = pp_i2c_send_bytes(addr, 2, data); |
189 | mutex_unlock(&i2c_mutex); | 171 | mutex_unlock(&i2c_mutex); |
190 | 172 | ||
191 | return retval; | 173 | return retval; |
192 | } | 174 | } |
193 | 175 | ||
194 | void i2c_init(void) | 176 | void i2c_init(void) |
195 | { | 177 | { |
196 | /* From ipodlinux */ | 178 | /* From ipodlinux */ |
197 | 179 | ||
198 | #ifdef IPOD_MINI | 180 | #ifdef IPOD_MINI |
199 | /* GPIO port C disable port 0x10 */ | 181 | /* GPIO port C disable port 0x10 */ |
200 | GPIOC_ENABLE &= ~0x10; | 182 | GPIOC_ENABLE &= ~0x10; |
201 | 183 | ||
202 | /* GPIO port C disable port 0x20 */ | 184 | /* GPIO port C disable port 0x20 */ |
203 | GPIOC_ENABLE &= ~0x20; | 185 | GPIOC_ENABLE &= ~0x20; |
204 | #endif | 186 | #endif |
205 | 187 | ||
206 | outl(inl(0x6000600c) | 0x1000, 0x6000600c); /* enable 12 */ | 188 | DEV_EN |= DEV_I2C; |
207 | outl(inl(0x60006004) | 0x1000, 0x60006004); /* start reset 12 */ | 189 | DEV_RS |= DEV_I2C; |
208 | outl(inl(0x60006004) & ~0x1000, 0x60006004); /* end reset 12 */ | 190 | DEV_RS &=~DEV_I2C; |
191 | |||
192 | outl(0x0, 0x600060a4); | ||
193 | outl(0x80 | (0 << 8), 0x600060a4); | ||
209 | 194 | ||
210 | outl(0x0, 0x600060a4); | 195 | mutex_init(&i2c_mutex); |
211 | outl(0x80 | (0 << 8), 0x600060a4); | ||
212 | 196 | ||
213 | mutex_init(&i2c_mutex); | 197 | i2c_readbyte(0x8, 0); |
214 | |||
215 | i2c_readbyte(0x8, 0); | ||
216 | } | 198 | } |