aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/sx150x.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpio/sx150x.c')
-rw-r--r--drivers/gpio/sx150x.c107
1 files changed, 63 insertions, 44 deletions
diff --git a/drivers/gpio/sx150x.c b/drivers/gpio/sx150x.c
index 823559ab0e24..a4f73534394e 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};
@@ -304,36 +309,34 @@ static int sx150x_gpio_to_irq(struct gpio_chip *gc, unsigned offset)
304 return chip->irq_base + offset; 309 return chip->irq_base + offset;
305} 310}
306 311
307static void sx150x_irq_mask(unsigned int irq) 312static void sx150x_irq_mask(struct irq_data *d)
308{ 313{
309 struct irq_chip *ic = get_irq_chip(irq); 314 struct irq_chip *ic = irq_data_get_irq_chip(d);
310 struct sx150x_chip *chip; 315 struct sx150x_chip *chip;
311 unsigned n; 316 unsigned n;
312 317
313 chip = container_of(ic, struct sx150x_chip, irq_chip); 318 chip = container_of(ic, struct sx150x_chip, irq_chip);
314 n = 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(unsigned int irq) 324static void sx150x_irq_unmask(struct irq_data *d)
321{ 325{
322 struct irq_chip *ic = get_irq_chip(irq); 326 struct irq_chip *ic = irq_data_get_irq_chip(d);
323 struct sx150x_chip *chip; 327 struct sx150x_chip *chip;
324 unsigned n; 328 unsigned n;
325 329
326 chip = container_of(ic, struct sx150x_chip, irq_chip); 330 chip = container_of(ic, struct sx150x_chip, irq_chip);
327 n = 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(unsigned int irq, unsigned int flow_type) 337static int sx150x_irq_set_type(struct irq_data *d, unsigned int flow_type)
335{ 338{
336 struct irq_chip *ic = get_irq_chip(irq); 339 struct irq_chip *ic = irq_data_get_irq_chip(d);
337 struct sx150x_chip *chip; 340 struct sx150x_chip *chip;
338 unsigned n, val = 0; 341 unsigned n, val = 0;
339 342
@@ -341,7 +344,7 @@ static int sx150x_irq_set_type(unsigned int irq, unsigned int flow_type)
341 return -EINVAL; 344 return -EINVAL;
342 345
343 chip = container_of(ic, struct sx150x_chip, irq_chip); 346 chip = container_of(ic, struct sx150x_chip, irq_chip);
344 n = irq - chip->irq_base; 347 n = d->irq - chip->irq_base;
345 348
346 if (flow_type & IRQ_TYPE_EDGE_RISING) 349 if (flow_type & IRQ_TYPE_EDGE_RISING)
347 val |= 0x1; 350 val |= 0x1;
@@ -350,7 +353,7 @@ static int sx150x_irq_set_type(unsigned int irq, 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
@@ -386,9 +389,9 @@ static irqreturn_t sx150x_irq_thread_fn(int irq, void *dev_id)
386 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE); 389 return (nhandled > 0 ? IRQ_HANDLED : IRQ_NONE);
387} 390}
388 391
389static void sx150x_irq_bus_lock(unsigned int irq) 392static void sx150x_irq_bus_lock(struct irq_data *d)
390{ 393{
391 struct irq_chip *ic = get_irq_chip(irq); 394 struct irq_chip *ic = irq_data_get_irq_chip(d);
392 struct sx150x_chip *chip; 395 struct sx150x_chip *chip;
393 396
394 chip = container_of(ic, struct sx150x_chip, irq_chip); 397 chip = container_of(ic, struct sx150x_chip, irq_chip);
@@ -396,23 +399,37 @@ static void sx150x_irq_bus_lock(unsigned int irq)
396 mutex_lock(&chip->lock); 399 mutex_lock(&chip->lock);
397} 400}
398 401
399static void sx150x_irq_bus_sync_unlock(unsigned int irq) 402static void sx150x_irq_bus_sync_unlock(struct irq_data *d)
400{ 403{
401 struct irq_chip *ic = get_irq_chip(irq); 404 struct irq_chip *ic = irq_data_get_irq_chip(d);
402 struct sx150x_chip *chip; 405 struct sx150x_chip *chip;
403 unsigned n; 406 unsigned n;
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
@@ -437,16 +454,19 @@ static void sx150x_init_chip(struct sx150x_chip *chip,
437 if (pdata->oscio_is_gpo) 454 if (pdata->oscio_is_gpo)
438 ++chip->gpio_chip.ngpio; 455 ++chip->gpio_chip.ngpio;
439 456
440 chip->irq_chip.name = client->name; 457 chip->irq_chip.name = client->name;
441 chip->irq_chip.mask = sx150x_irq_mask; 458 chip->irq_chip.irq_mask = sx150x_irq_mask;
442 chip->irq_chip.unmask = sx150x_irq_unmask; 459 chip->irq_chip.irq_unmask = sx150x_irq_unmask;
443 chip->irq_chip.set_type = sx150x_irq_set_type; 460 chip->irq_chip.irq_set_type = sx150x_irq_set_type;
444 chip->irq_chip.bus_lock = sx150x_irq_bus_lock; 461 chip->irq_chip.irq_bus_lock = sx150x_irq_bus_lock;
445 chip->irq_chip.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;
448 chip->irq_sense = 0; 465 chip->irq_masked = ~0;
449 chip->irq_set_type_pending = 0; 466 chip->irq_sense = 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)
@@ -531,12 +551,12 @@ static int sx150x_install_irq_chip(struct sx150x_chip *chip,
531 551
532 for (n = 0; n < chip->dev_cfg->ngpios; ++n) { 552 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
533 irq = irq_base + n; 553 irq = irq_base + n;
534 set_irq_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq); 554 irq_set_chip_and_handler(irq, &chip->irq_chip, handle_edge_irq);
535 set_irq_nested_thread(irq, 1); 555 irq_set_nested_thread(irq, 1);
536#ifdef CONFIG_ARM 556#ifdef CONFIG_ARM
537 set_irq_flags(irq, IRQF_VALID); 557 set_irq_flags(irq, IRQF_VALID);
538#else 558#else
539 set_irq_noprobe(irq); 559 irq_set_noprobe(irq);
540#endif 560#endif
541 } 561 }
542 562
@@ -563,8 +583,7 @@ static void sx150x_remove_irq_chip(struct sx150x_chip *chip)
563 583
564 for (n = 0; n < chip->dev_cfg->ngpios; ++n) { 584 for (n = 0; n < chip->dev_cfg->ngpios; ++n) {
565 irq = chip->irq_base + n; 585 irq = chip->irq_base + n;
566 set_irq_handler(irq, NULL); 586 irq_set_chip_and_handler(irq, NULL, NULL);
567 set_irq_chip(irq, NULL);
568 } 587 }
569} 588}
570 589