aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2006-04-18 00:11:53 -0400
committerPaul Mackerras <paulus@samba.org>2006-04-21 08:29:46 -0400
commit60162e498e220d1f03bbee5bac0a9ddd6de60ae7 (patch)
tree8cbcbea6060eb2b9f7d39784385efdfc6e947b52 /arch
parent28897731318dc8f63f683eed9091e446916ad706 (diff)
[PATCH] powermac: Fix i2c on keywest based chips
The new i2c implementation for PowerMac has a regression that causes the hardware to go out of state when probing non-existent devices. While fixing that, I also found & fixed a couple of other corner cases. This fixes booting with a pbbuttons version that scans the i2c bus for an LMU controller among others. Tested on a dual G5 with thermal control (which has heavy i2c activity) with no problem so far. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Paul Mackerras <paulus@samba.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/platforms/powermac/low_i2c.c78
1 files changed, 35 insertions, 43 deletions
diff --git a/arch/powerpc/platforms/powermac/low_i2c.c b/arch/powerpc/platforms/powermac/low_i2c.c
index e14f9ac55cf4..df2343e1956b 100644
--- a/arch/powerpc/platforms/powermac/low_i2c.c
+++ b/arch/powerpc/platforms/powermac/low_i2c.c
@@ -231,6 +231,14 @@ static u8 kw_i2c_wait_interrupt(struct pmac_i2c_host_kw *host)
231 return isr; 231 return isr;
232} 232}
233 233
234static void kw_i2c_do_stop(struct pmac_i2c_host_kw *host, int result)
235{
236 kw_write_reg(reg_control, KW_I2C_CTL_STOP);
237 host->state = state_stop;
238 host->result = result;
239}
240
241
234static void kw_i2c_handle_interrupt(struct pmac_i2c_host_kw *host, u8 isr) 242static void kw_i2c_handle_interrupt(struct pmac_i2c_host_kw *host, u8 isr)
235{ 243{
236 u8 ack; 244 u8 ack;
@@ -246,42 +254,36 @@ static void kw_i2c_handle_interrupt(struct pmac_i2c_host_kw *host, u8 isr)
246 } 254 }
247 255
248 if (isr == 0) { 256 if (isr == 0) {
257 printk(KERN_WARNING "low_i2c: Timeout in i2c transfer"
258 " on keywest !\n");
249 if (host->state != state_stop) { 259 if (host->state != state_stop) {
250 DBG_LOW("KW: Timeout !\n"); 260 kw_i2c_do_stop(host, -EIO);
251 host->result = -EIO; 261 return;
252 goto stop;
253 }
254 if (host->state == state_stop) {
255 ack = kw_read_reg(reg_status);
256 if (ack & KW_I2C_STAT_BUSY)
257 kw_write_reg(reg_status, 0);
258 host->state = state_idle;
259 kw_write_reg(reg_ier, 0x00);
260 if (!host->polled)
261 complete(&host->complete);
262 } 262 }
263 ack = kw_read_reg(reg_status);
264 if (ack & KW_I2C_STAT_BUSY)
265 kw_write_reg(reg_status, 0);
266 host->state = state_idle;
267 kw_write_reg(reg_ier, 0x00);
268 if (!host->polled)
269 complete(&host->complete);
263 return; 270 return;
264 } 271 }
265 272
266 if (isr & KW_I2C_IRQ_ADDR) { 273 if (isr & KW_I2C_IRQ_ADDR) {
267 ack = kw_read_reg(reg_status); 274 ack = kw_read_reg(reg_status);
268 if (host->state != state_addr) { 275 if (host->state != state_addr) {
269 kw_write_reg(reg_isr, KW_I2C_IRQ_ADDR);
270 WRONG_STATE("KW_I2C_IRQ_ADDR"); 276 WRONG_STATE("KW_I2C_IRQ_ADDR");
271 host->result = -EIO; 277 kw_i2c_do_stop(host, -EIO);
272 goto stop;
273 } 278 }
274 if ((ack & KW_I2C_STAT_LAST_AAK) == 0) { 279 if ((ack & KW_I2C_STAT_LAST_AAK) == 0) {
275 host->result = -ENODEV; 280 host->result = -ENXIO;
276 DBG_LOW("KW: NAK on address\n");
277 host->state = state_stop; 281 host->state = state_stop;
278 return; 282 DBG_LOW("KW: NAK on address\n");
279 } else { 283 } else {
280 if (host->len == 0) { 284 if (host->len == 0)
281 kw_write_reg(reg_isr, KW_I2C_IRQ_ADDR); 285 kw_i2c_do_stop(host, 0);
282 goto stop; 286 else if (host->rw) {
283 }
284 if (host->rw) {
285 host->state = state_read; 287 host->state = state_read;
286 if (host->len > 1) 288 if (host->len > 1)
287 kw_write_reg(reg_control, 289 kw_write_reg(reg_control,
@@ -308,25 +310,19 @@ static void kw_i2c_handle_interrupt(struct pmac_i2c_host_kw *host, u8 isr)
308 ack = kw_read_reg(reg_status); 310 ack = kw_read_reg(reg_status);
309 if ((ack & KW_I2C_STAT_LAST_AAK) == 0) { 311 if ((ack & KW_I2C_STAT_LAST_AAK) == 0) {
310 DBG_LOW("KW: nack on data write\n"); 312 DBG_LOW("KW: nack on data write\n");
311 host->result = -EIO; 313 host->result = -EFBIG;
312 goto stop; 314 host->state = state_stop;
313 } else if (host->len) { 315 } else if (host->len) {
314 kw_write_reg(reg_data, *(host->data++)); 316 kw_write_reg(reg_data, *(host->data++));
315 host->len--; 317 host->len--;
316 } else { 318 } else
317 kw_write_reg(reg_control, KW_I2C_CTL_STOP); 319 kw_i2c_do_stop(host, 0);
318 host->state = state_stop;
319 host->result = 0;
320 }
321 kw_write_reg(reg_isr, KW_I2C_IRQ_DATA);
322 } else { 320 } else {
323 kw_write_reg(reg_isr, KW_I2C_IRQ_DATA);
324 WRONG_STATE("KW_I2C_IRQ_DATA"); 321 WRONG_STATE("KW_I2C_IRQ_DATA");
325 if (host->state != state_stop) { 322 if (host->state != state_stop)
326 host->result = -EIO; 323 kw_i2c_do_stop(host, -EIO);
327 goto stop;
328 }
329 } 324 }
325 kw_write_reg(reg_isr, KW_I2C_IRQ_DATA);
330 } 326 }
331 327
332 if (isr & KW_I2C_IRQ_STOP) { 328 if (isr & KW_I2C_IRQ_STOP) {
@@ -340,14 +336,10 @@ static void kw_i2c_handle_interrupt(struct pmac_i2c_host_kw *host, u8 isr)
340 complete(&host->complete); 336 complete(&host->complete);
341 } 337 }
342 338
339 /* Below should only happen in manual mode which we don't use ... */
343 if (isr & KW_I2C_IRQ_START) 340 if (isr & KW_I2C_IRQ_START)
344 kw_write_reg(reg_isr, KW_I2C_IRQ_START); 341 kw_write_reg(reg_isr, KW_I2C_IRQ_START);
345 342
346 return;
347 stop:
348 kw_write_reg(reg_control, KW_I2C_CTL_STOP);
349 host->state = state_stop;
350 return;
351} 343}
352 344
353/* Interrupt handler */ 345/* Interrupt handler */
@@ -544,11 +536,11 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
544 return NULL; 536 return NULL;
545 } 537 }
546 538
547 /* Make sure IRA is disabled */ 539 /* Make sure IRQ is disabled */
548 kw_write_reg(reg_ier, 0); 540 kw_write_reg(reg_ier, 0);
549 541
550 /* Request chip interrupt */ 542 /* Request chip interrupt */
551 if (request_irq(host->irq, kw_i2c_irq, SA_SHIRQ, "keywest i2c", host)) 543 if (request_irq(host->irq, kw_i2c_irq, 0, "keywest i2c", host))
552 host->irq = NO_IRQ; 544 host->irq = NO_IRQ;
553 545
554 printk(KERN_INFO "KeyWest i2c @0x%08x irq %d %s\n", 546 printk(KERN_INFO "KeyWest i2c @0x%08x irq %d %s\n",