aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2011-02-14 12:08:51 -0500
committerGrant Likely <grant.likely@secretlab.ca>2011-02-22 16:59:53 -0500
commit0ff56cd85a2c5104a36d84662b9180c219e8604e (patch)
tree2d8826a9743143402a8028a3a1c36f21ff5df755 /drivers
parent0b782531c038d4a4bded3fc1069c961b1f14f0de (diff)
gpio/sx150x: Do not access I2C from mask/unmask functions
irq_chip->irq_mask/unmask are called with interrupts disabled and irq_desc->lock held. So we cannot access i2c from this context. That's what irq_bus_sync_unlock() is for. Store the masked information in the chip data structure and update the i2c bus from the irq_bus_sync_unlock() callback. This does not need a while(pending) loop because the update to this is always serialized via the bus lock, so we never have more than one pin update pending. Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Gregory Bean <gbean@codeaurora.org> Cc: Jean Delvare <khali@linux-fr.org> Cc: Lennert Buytenhek <buytenh@secretlab.ca> Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/gpio/sx150x.c54
1 files changed, 37 insertions, 17 deletions
diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/sx150x.c
index e60be0015c9b..d2f874c3d3d5 100644
--- a/drivers/gpio/sx150x.c
+++ b/drivers/gpio/sx150x.c
@@ -25,6 +25,8 @@
25#include <linux/workqueue.h> 25#include <linux/workqueue.h>
26#include <linux/i2c/sx150x.h> 26#include <linux/i2c/sx150x.h>
27 27
28#define NO_UPDATE_PENDING -1
29
28struct sx150x_device_data { 30struct sx150x_device_data {
29 u8 reg_pullup; 31 u8 reg_pullup;
30 u8 reg_pulldn; 32 u8 reg_pulldn;
@@ -47,8 +49,11 @@ struct sx150x_chip {
47 const struct sx150x_device_data *dev_cfg; 49 const struct sx150x_device_data *dev_cfg;
48 int irq_summary; 50 int irq_summary;
49 int irq_base; 51 int irq_base;
52 int irq_update;
50 u32 irq_sense; 53 u32 irq_sense;
51 unsigned long irq_set_type_pending; 54 u32 irq_masked;
55 u32 dev_sense;
56 u32 dev_masked;
52 struct irq_chip irq_chip; 57 struct irq_chip irq_chip;
53 struct mutex lock; 58 struct mutex lock;
54}; 59};
@@ -312,9 +317,8 @@ static void sx150x_irq_mask(struct irq_data *d)
312 317
313 chip = container_of(ic, struct sx150x_chip, irq_chip); 318 chip = container_of(ic, struct sx150x_chip, irq_chip);
314 n = d->irq - chip->irq_base; 319 n = d->irq - chip->irq_base;
315 320 chip->irq_masked |= (1 << n);
316 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 1); 321 chip->irq_update = n;
317 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 0);
318} 322}
319 323
320static void sx150x_irq_unmask(struct irq_data *d) 324static void sx150x_irq_unmask(struct irq_data *d)
@@ -326,9 +330,8 @@ static void sx150x_irq_unmask(struct irq_data *d)
326 chip = container_of(ic, struct sx150x_chip, irq_chip); 330 chip = container_of(ic, struct sx150x_chip, irq_chip);
327 n = d->irq - chip->irq_base; 331 n = d->irq - chip->irq_base;
328 332
329 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 0); 333 chip->irq_masked &= ~(1 << n);
330 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 334 chip->irq_update = n;
331 chip->irq_sense >> (n * 2));
332} 335}
333 336
334static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type) 337static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
@@ -350,7 +353,7 @@ static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
350 353
351 chip->irq_sense &= ~(3UL << (n * 2)); 354 chip->irq_sense &= ~(3UL << (n * 2));
352 chip->irq_sense |= val << (n * 2); 355 chip->irq_sense |= val << (n * 2);
353 chip->irq_set_type_pending |= BIT(n); 356 chip->irq_update = n;
354 return 0; 357 return 0;
355} 358}
356 359
@@ -404,15 +407,29 @@ static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
404 407
405 chip = container_of(ic, struct sx150x_chip, irq_chip); 408 chip = container_of(ic, struct sx150x_chip, irq_chip);
406 409
407 while (chip->irq_set_type_pending) { 410 if (chip->irq_update == NO_UPDATE_PENDING)
408 n = __ffs(chip->irq_set_type_pending); 411 goto out;
409 chip->irq_set_type_pending &= ~BIT(n); 412
410 if (!(irq_to_desc(n + chip->irq_base)->status & IRQ_MASKED)) 413 n = chip->irq_update;
411 sx150x_write_cfg(chip, n, 2, 414 chip->irq_update = NO_UPDATE_PENDING;
412 chip->dev_cfg->reg_sense,
413 chip->irq_sense >> (n * 2));
414 }
415 415
416 /* Avoid updates if nothing changed */
417 if (chip->dev_sense == chip->irq_sense &&
418 chip->dev_sense == chip->irq_masked)
419 goto out;
420
421 chip->dev_sense = chip->irq_sense;
422 chip->dev_masked = chip->irq_masked;
423
424 if (chip->irq_masked & (1 << n)) {
425 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 1);
426 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense, 0);
427 } else {
428 sx150x_write_cfg(chip, n, 1, chip->dev_cfg->reg_irq_mask, 0);
429 sx150x_write_cfg(chip, n, 2, chip->dev_cfg->reg_sense,
430 chip->irq_sense >> (n * 2));
431 }
432out:
416 mutex_unlock(&chip->lock); 433 mutex_unlock(&chip->lock);
417} 434}
418 435
@@ -445,8 +462,11 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
445 chip->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock; 462 chip->irq_chip.irq_bus_sync_unlock = sx150x_irq_bus_sync_unlock;
446 chip->irq_summary = -1; 463 chip->irq_summary = -1;
447 chip->irq_base = -1; 464 chip->irq_base = -1;
465 chip->irq_masked = ~0;
448 chip->irq_sense = 0; 466 chip->irq_sense = 0;
449 chip->irq_set_type_pending = 0; 467 chip->dev_masked = ~0;
468 chip->dev_sense = 0;
469 chip->irq_update = NO_UPDATE_PENDING;
450} 470}
451 471
452static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg) 472static int sx150x_init_io(struct sx150x_chip *chip, u8 base, u16 cfg)