aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-omap.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-05-06 18:40:55 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-05-06 18:40:55 -0400
commit30c67e93c526639aaac90fa873800104b7c16d16 (patch)
tree6d8d0fd248d4e60bdc175dacbd196fc44f23ce11 /drivers/gpio/gpio-omap.c
parentf87bb9ee62700fa11713c630ac5671f253233b94 (diff)
parent08ffb2229fafc2c3a696b325a74bf4198d6b91d7 (diff)
Merge tag 'gpio-for-linus' of git://git.secretlab.ca/git/linux
Pull GPIO changes from Grant Likely: "The usual selection of bug fixes and driver updates for GPIO. Nothing really stands out except the addition of the GRGPIO driver and some enhacements to ACPI support" I'm pulling this despite the earlier mess. Let's hope it compiles these days. * tag 'gpio-for-linus' of git://git.secretlab.ca/git/linux: (46 commits) gpio: grgpio: Add irq support gpio: grgpio: Add device driver for GRGPIO cores gpiolib-acpi: introduce acpi_get_gpio_by_index() helper GPIO: gpio-generic: remove kfree() from bgpio_remove call gpio / ACPI: Handle ACPI events in accordance with the spec gpio: lpc32xx: Fix off-by-one valid range checking for bank gpio: mcp23s08: convert driver to DT gpio/omap: force restore if context loss is not detectable gpio/omap: optimise interrupt service routine gpio/omap: remove extra context restores in *_runtime_resume() gpio/omap: free irq domain in probe() failure paths gpio: gpio-generic: Add 16 and 32 bit big endian byte order support gpio: samsung: Add terminating entry for exynos_pinctrl_ids gpio: mvebu: add dbg_show function MAX7301 GPIO: Do not force SPI speed when using OF Platform gpio: gpio-tps65910.c: fix checkpatch error gpio: gpio-timberdale.c: fix checkpatch error gpio: gpio-tc3589x.c: fix checkpatch errors gpio: gpio-stp-xway.c: fix checkpatch error gpio: gpio-sch.c: fix checkpatch error ...
Diffstat (limited to 'drivers/gpio/gpio-omap.c')
-rw-r--r--drivers/gpio/gpio-omap.c116
1 files changed, 58 insertions, 58 deletions
diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
index a612ea1c53cb..2050891d9c65 100644
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -52,7 +52,6 @@ struct gpio_bank {
52 struct list_head node; 52 struct list_head node;
53 void __iomem *base; 53 void __iomem *base;
54 u16 irq; 54 u16 irq;
55 int irq_base;
56 struct irq_domain *domain; 55 struct irq_domain *domain;
57 u32 non_wakeup_gpios; 56 u32 non_wakeup_gpios;
58 u32 enabled_non_wakeup_gpios; 57 u32 enabled_non_wakeup_gpios;
@@ -88,7 +87,14 @@ struct gpio_bank {
88 87
89static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq) 88static int irq_to_gpio(struct gpio_bank *bank, unsigned int gpio_irq)
90{ 89{
91 return gpio_irq - bank->irq_base + bank->chip.base; 90 return bank->chip.base + gpio_irq;
91}
92
93static int omap_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
94{
95 struct gpio_bank *bank = container_of(chip, struct gpio_bank, chip);
96
97 return irq_find_mapping(bank->domain, offset);
92} 98}
93 99
94static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input) 100static void _set_gpio_direction(struct gpio_bank *bank, int gpio, int is_input)
@@ -420,13 +426,16 @@ static int gpio_irq_type(struct irq_data *d, unsigned type)
420 int retval; 426 int retval;
421 unsigned long flags; 427 unsigned long flags;
422 428
429 if (WARN_ON(!bank->mod_usage))
430 return -EINVAL;
431
423#ifdef CONFIG_ARCH_OMAP1 432#ifdef CONFIG_ARCH_OMAP1
424 if (d->irq > IH_MPUIO_BASE) 433 if (d->irq > IH_MPUIO_BASE)
425 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE); 434 gpio = OMAP_MPUIO(d->irq - IH_MPUIO_BASE);
426#endif 435#endif
427 436
428 if (!gpio) 437 if (!gpio)
429 gpio = irq_to_gpio(bank, d->irq); 438 gpio = irq_to_gpio(bank, d->hwirq);
430 439
431 if (type & ~IRQ_TYPE_SENSE_MASK) 440 if (type & ~IRQ_TYPE_SENSE_MASK)
432 return -EINVAL; 441 return -EINVAL;
@@ -579,7 +588,7 @@ static void _reset_gpio(struct gpio_bank *bank, int gpio)
579static int gpio_wake_enable(struct irq_data *d, unsigned int enable) 588static int gpio_wake_enable(struct irq_data *d, unsigned int enable)
580{ 589{
581 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 590 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
582 unsigned int gpio = irq_to_gpio(bank, d->irq); 591 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
583 592
584 return _set_gpio_wakeup(bank, gpio, enable); 593 return _set_gpio_wakeup(bank, gpio, enable);
585} 594}
@@ -679,7 +688,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
679{ 688{
680 void __iomem *isr_reg = NULL; 689 void __iomem *isr_reg = NULL;
681 u32 isr; 690 u32 isr;
682 unsigned int gpio_irq, gpio_index; 691 unsigned int bit;
683 struct gpio_bank *bank; 692 struct gpio_bank *bank;
684 int unmasked = 0; 693 int unmasked = 0;
685 struct irq_chip *chip = irq_desc_get_chip(desc); 694 struct irq_chip *chip = irq_desc_get_chip(desc);
@@ -693,7 +702,7 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
693 if (WARN_ON(!isr_reg)) 702 if (WARN_ON(!isr_reg))
694 goto exit; 703 goto exit;
695 704
696 while(1) { 705 while (1) {
697 u32 isr_saved, level_mask = 0; 706 u32 isr_saved, level_mask = 0;
698 u32 enabled; 707 u32 enabled;
699 708
@@ -720,14 +729,9 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
720 if (!isr) 729 if (!isr)
721 break; 730 break;
722 731
723 gpio_irq = bank->irq_base; 732 while (isr) {
724 for (; isr != 0; isr >>= 1, gpio_irq++) { 733 bit = __ffs(isr);
725 int gpio = irq_to_gpio(bank, gpio_irq); 734 isr &= ~(1 << bit);
726
727 if (!(isr & 1))
728 continue;
729
730 gpio_index = GPIO_INDEX(bank, gpio);
731 735
732 /* 736 /*
733 * Some chips can't respond to both rising and falling 737 * Some chips can't respond to both rising and falling
@@ -736,10 +740,10 @@ static void gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
736 * to respond to the IRQ for the opposite direction. 740 * to respond to the IRQ for the opposite direction.
737 * This will be indicated in the bank toggle_mask. 741 * This will be indicated in the bank toggle_mask.
738 */ 742 */
739 if (bank->toggle_mask & (1 << gpio_index)) 743 if (bank->toggle_mask & (1 << bit))
740 _toggle_gpio_edge_triggering(bank, gpio_index); 744 _toggle_gpio_edge_triggering(bank, bit);
741 745
742 generic_handle_irq(gpio_irq); 746 generic_handle_irq(irq_find_mapping(bank->domain, bit));
743 } 747 }
744 } 748 }
745 /* if bank has any level sensitive GPIO pin interrupt 749 /* if bank has any level sensitive GPIO pin interrupt
@@ -755,7 +759,7 @@ exit:
755static void gpio_irq_shutdown(struct irq_data *d) 759static void gpio_irq_shutdown(struct irq_data *d)
756{ 760{
757 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 761 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
758 unsigned int gpio = irq_to_gpio(bank, d->irq); 762 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
759 unsigned long flags; 763 unsigned long flags;
760 764
761 spin_lock_irqsave(&bank->lock, flags); 765 spin_lock_irqsave(&bank->lock, flags);
@@ -766,7 +770,7 @@ static void gpio_irq_shutdown(struct irq_data *d)
766static void gpio_ack_irq(struct irq_data *d) 770static void gpio_ack_irq(struct irq_data *d)
767{ 771{
768 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 772 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
769 unsigned int gpio = irq_to_gpio(bank, d->irq); 773 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
770 774
771 _clear_gpio_irqstatus(bank, gpio); 775 _clear_gpio_irqstatus(bank, gpio);
772} 776}
@@ -774,7 +778,7 @@ static void gpio_ack_irq(struct irq_data *d)
774static void gpio_mask_irq(struct irq_data *d) 778static void gpio_mask_irq(struct irq_data *d)
775{ 779{
776 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 780 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
777 unsigned int gpio = irq_to_gpio(bank, d->irq); 781 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
778 unsigned long flags; 782 unsigned long flags;
779 783
780 spin_lock_irqsave(&bank->lock, flags); 784 spin_lock_irqsave(&bank->lock, flags);
@@ -786,7 +790,7 @@ static void gpio_mask_irq(struct irq_data *d)
786static void gpio_unmask_irq(struct irq_data *d) 790static void gpio_unmask_irq(struct irq_data *d)
787{ 791{
788 struct gpio_bank *bank = irq_data_get_irq_chip_data(d); 792 struct gpio_bank *bank = irq_data_get_irq_chip_data(d);
789 unsigned int gpio = irq_to_gpio(bank, d->irq); 793 unsigned int gpio = irq_to_gpio(bank, d->hwirq);
790 unsigned int irq_mask = GPIO_BIT(bank, gpio); 794 unsigned int irq_mask = GPIO_BIT(bank, gpio);
791 u32 trigger = irqd_get_trigger_type(d); 795 u32 trigger = irqd_get_trigger_type(d);
792 unsigned long flags; 796 unsigned long flags;
@@ -952,14 +956,6 @@ static void gpio_set(struct gpio_chip *chip, unsigned offset, int value)
952 spin_unlock_irqrestore(&bank->lock, flags); 956 spin_unlock_irqrestore(&bank->lock, flags);
953} 957}
954 958
955static int gpio_2irq(struct gpio_chip *chip, unsigned offset)
956{
957 struct gpio_bank *bank;
958
959 bank = container_of(chip, struct gpio_bank, chip);
960 return bank->irq_base + offset;
961}
962
963/*---------------------------------------------------------------------*/ 959/*---------------------------------------------------------------------*/
964 960
965static void __init omap_gpio_show_rev(struct gpio_bank *bank) 961static void __init omap_gpio_show_rev(struct gpio_bank *bank)
@@ -1056,7 +1052,7 @@ static void omap_gpio_chip_init(struct gpio_bank *bank)
1056 bank->chip.direction_output = gpio_output; 1052 bank->chip.direction_output = gpio_output;
1057 bank->chip.set_debounce = gpio_debounce; 1053 bank->chip.set_debounce = gpio_debounce;
1058 bank->chip.set = gpio_set; 1054 bank->chip.set = gpio_set;
1059 bank->chip.to_irq = gpio_2irq; 1055 bank->chip.to_irq = omap_gpio_to_irq;
1060 if (bank->is_mpuio) { 1056 if (bank->is_mpuio) {
1061 bank->chip.label = "mpuio"; 1057 bank->chip.label = "mpuio";
1062 if (bank->regs->wkup_en) 1058 if (bank->regs->wkup_en)
@@ -1071,15 +1067,16 @@ static void omap_gpio_chip_init(struct gpio_bank *bank)
1071 1067
1072 gpiochip_add(&bank->chip); 1068 gpiochip_add(&bank->chip);
1073 1069
1074 for (j = bank->irq_base; j < bank->irq_base + bank->width; j++) { 1070 for (j = 0; j < bank->width; j++) {
1075 irq_set_lockdep_class(j, &gpio_lock_class); 1071 int irq = irq_create_mapping(bank->domain, j);
1076 irq_set_chip_data(j, bank); 1072 irq_set_lockdep_class(irq, &gpio_lock_class);
1073 irq_set_chip_data(irq, bank);
1077 if (bank->is_mpuio) { 1074 if (bank->is_mpuio) {
1078 omap_mpuio_alloc_gc(bank, j, bank->width); 1075 omap_mpuio_alloc_gc(bank, irq, bank->width);
1079 } else { 1076 } else {
1080 irq_set_chip(j, &gpio_irq_chip); 1077 irq_set_chip_and_handler(irq, &gpio_irq_chip,
1081 irq_set_handler(j, handle_simple_irq); 1078 handle_simple_irq);
1082 set_irq_flags(j, IRQF_VALID); 1079 set_irq_flags(irq, IRQF_VALID);
1083 } 1080 }
1084 } 1081 }
1085 irq_set_chained_handler(bank->irq, gpio_irq_handler); 1082 irq_set_chained_handler(bank->irq, gpio_irq_handler);
@@ -1096,7 +1093,6 @@ static int omap_gpio_probe(struct platform_device *pdev)
1096 const struct omap_gpio_platform_data *pdata; 1093 const struct omap_gpio_platform_data *pdata;
1097 struct resource *res; 1094 struct resource *res;
1098 struct gpio_bank *bank; 1095 struct gpio_bank *bank;
1099 int ret = 0;
1100 1096
1101 match = of_match_device(of_match_ptr(omap_gpio_match), dev); 1097 match = of_match_device(of_match_ptr(omap_gpio_match), dev);
1102 1098
@@ -1123,20 +1119,22 @@ static int omap_gpio_probe(struct platform_device *pdev)
1123 bank->width = pdata->bank_width; 1119 bank->width = pdata->bank_width;
1124 bank->is_mpuio = pdata->is_mpuio; 1120 bank->is_mpuio = pdata->is_mpuio;
1125 bank->non_wakeup_gpios = pdata->non_wakeup_gpios; 1121 bank->non_wakeup_gpios = pdata->non_wakeup_gpios;
1126 bank->loses_context = pdata->loses_context;
1127 bank->regs = pdata->regs; 1122 bank->regs = pdata->regs;
1128#ifdef CONFIG_OF_GPIO 1123#ifdef CONFIG_OF_GPIO
1129 bank->chip.of_node = of_node_get(node); 1124 bank->chip.of_node = of_node_get(node);
1130#endif 1125#endif
1131 1126 if (node) {
1132 bank->irq_base = irq_alloc_descs(-1, 0, bank->width, 0); 1127 if (!of_property_read_bool(node, "ti,gpio-always-on"))
1133 if (bank->irq_base < 0) { 1128 bank->loses_context = true;
1134 dev_err(dev, "Couldn't allocate IRQ numbers\n"); 1129 } else {
1135 return -ENODEV; 1130 bank->loses_context = pdata->loses_context;
1136 } 1131 }
1137 1132
1138 bank->domain = irq_domain_add_legacy(node, bank->width, bank->irq_base, 1133
1139 0, &irq_domain_simple_ops, NULL); 1134 bank->domain = irq_domain_add_linear(node, bank->width,
1135 &irq_domain_simple_ops, NULL);
1136 if (!bank->domain)
1137 return -ENODEV;
1140 1138
1141 if (bank->regs->set_dataout && bank->regs->clr_dataout) 1139 if (bank->regs->set_dataout && bank->regs->clr_dataout)
1142 bank->set_dataout = _set_gpio_dataout_reg; 1140 bank->set_dataout = _set_gpio_dataout_reg;
@@ -1149,18 +1147,21 @@ static int omap_gpio_probe(struct platform_device *pdev)
1149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1147 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1150 if (unlikely(!res)) { 1148 if (unlikely(!res)) {
1151 dev_err(dev, "Invalid mem resource\n"); 1149 dev_err(dev, "Invalid mem resource\n");
1150 irq_domain_remove(bank->domain);
1152 return -ENODEV; 1151 return -ENODEV;
1153 } 1152 }
1154 1153
1155 if (!devm_request_mem_region(dev, res->start, resource_size(res), 1154 if (!devm_request_mem_region(dev, res->start, resource_size(res),
1156 pdev->name)) { 1155 pdev->name)) {
1157 dev_err(dev, "Region already claimed\n"); 1156 dev_err(dev, "Region already claimed\n");
1157 irq_domain_remove(bank->domain);
1158 return -EBUSY; 1158 return -EBUSY;
1159 } 1159 }
1160 1160
1161 bank->base = devm_ioremap(dev, res->start, resource_size(res)); 1161 bank->base = devm_ioremap(dev, res->start, resource_size(res));
1162 if (!bank->base) { 1162 if (!bank->base) {
1163 dev_err(dev, "Could not ioremap\n"); 1163 dev_err(dev, "Could not ioremap\n");
1164 irq_domain_remove(bank->domain);
1164 return -ENOMEM; 1165 return -ENOMEM;
1165 } 1166 }
1166 1167
@@ -1184,7 +1185,7 @@ static int omap_gpio_probe(struct platform_device *pdev)
1184 1185
1185 list_add_tail(&bank->node, &omap_gpio_list); 1186 list_add_tail(&bank->node, &omap_gpio_list);
1186 1187
1187 return ret; 1188 return 0;
1188} 1189}
1189 1190
1190#ifdef CONFIG_ARCH_OMAP2PLUS 1191#ifdef CONFIG_ARCH_OMAP2PLUS
@@ -1262,9 +1263,9 @@ static int omap_gpio_runtime_resume(struct device *dev)
1262{ 1263{
1263 struct platform_device *pdev = to_platform_device(dev); 1264 struct platform_device *pdev = to_platform_device(dev);
1264 struct gpio_bank *bank = platform_get_drvdata(pdev); 1265 struct gpio_bank *bank = platform_get_drvdata(pdev);
1265 int context_lost_cnt_after;
1266 u32 l = 0, gen, gen0, gen1; 1266 u32 l = 0, gen, gen0, gen1;
1267 unsigned long flags; 1267 unsigned long flags;
1268 int c;
1268 1269
1269 spin_lock_irqsave(&bank->lock, flags); 1270 spin_lock_irqsave(&bank->lock, flags);
1270 _gpio_dbck_enable(bank); 1271 _gpio_dbck_enable(bank);
@@ -1280,14 +1281,17 @@ static int omap_gpio_runtime_resume(struct device *dev)
1280 __raw_writel(bank->context.risingdetect, 1281 __raw_writel(bank->context.risingdetect,
1281 bank->base + bank->regs->risingdetect); 1282 bank->base + bank->regs->risingdetect);
1282 1283
1283 if (bank->get_context_loss_count) { 1284 if (bank->loses_context) {
1284 context_lost_cnt_after = 1285 if (!bank->get_context_loss_count) {
1285 bank->get_context_loss_count(bank->dev);
1286 if (context_lost_cnt_after != bank->context_loss_count) {
1287 omap_gpio_restore_context(bank); 1286 omap_gpio_restore_context(bank);
1288 } else { 1287 } else {
1289 spin_unlock_irqrestore(&bank->lock, flags); 1288 c = bank->get_context_loss_count(bank->dev);
1290 return 0; 1289 if (c != bank->context_loss_count) {
1290 omap_gpio_restore_context(bank);
1291 } else {
1292 spin_unlock_irqrestore(&bank->lock, flags);
1293 return 0;
1294 }
1291 } 1295 }
1292 } 1296 }
1293 1297
@@ -1296,10 +1300,6 @@ static int omap_gpio_runtime_resume(struct device *dev)
1296 return 0; 1300 return 0;
1297 } 1301 }
1298 1302
1299 __raw_writel(bank->context.fallingdetect,
1300 bank->base + bank->regs->fallingdetect);
1301 __raw_writel(bank->context.risingdetect,
1302 bank->base + bank->regs->risingdetect);
1303 l = __raw_readl(bank->base + bank->regs->datain); 1303 l = __raw_readl(bank->base + bank->regs->datain);
1304 1304
1305 /* 1305 /*