aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpio-davinci.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-08-16 00:35:38 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-16 00:35:38 -0400
commit6de4c691eab8f421e34c5250f63bf3f477d30eec (patch)
treedd3deaa163bb478b13778a712afdfccc8cf43f20 /drivers/gpio/gpio-davinci.c
parentc1c2ad82c772966d3cdb9a4852329fa2cf71853a (diff)
parenta5ec96ddfd55c501d451cb310566a1170c267ecb (diff)
Merge tag 'gpio-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio
Pull GPIO updates from Linus Walleij: "This is the bulk of GPIO changes for the v4.19 kernel cycle. I don't know if anything in particular stands out. Maybe the Aspeed coprocessor thing from Benji: Aspeed is doing baseboard management chips (BMC's) for servers etc. These Aspeed's are ARM processors that exist inside (I guess) Intel servers, and they are moving forward to using mainline Linux in those. This is one of the pieces of the puzzle to achive that. They are doing OpenBMC, it's pretty cool: https://lwn.net/Articles/683320/ Summary: Core changes: - Add a new API for explicitly naming GPIO consumers, when needed. - Don't let userspace set values on input lines. While we do not think anyone would do this crazy thing we better plug the hole before someone uses it and think it's a nifty feature. - Avoid calling chip->request() for unused GPIOs. New drivers/subdrivers: - The Mediatek MT7621 is supported which is a big win for OpenWRT and similar router distributions using this chip, as it seems every major router manufacturer on the planet has made products using this chip: https://wikidevi.com/wiki/MediaTek_MT7621 - The Tegra 194 is now supported. - The IT87 driver now supports IT8786E and IT8718F super-IO chips. - Add support for Rockchip RK3328 in the syscon GPIO driver. Driver changes: - Handle the get/set_multiple() properly on MMIO chips with inverted direction registers. We didn't have this problem until a new chip appear that has get/set registers AND inverted direction bits, OK now we handle it. - A patch series making more error codes percolate upward properly for different errors on gpiochip_lock_as_irq(). - Get/set multiple for the OMAP driver, accelerating these multiple line operations if possible. - A coprocessor interface for the Aspeed driver. Sometimes a few GPIO lines need to be grabbed by a co-processor for doing automated tasks, sometimes they are available as GPIO lines. By adding an explicit API in this driver we make it possible for the two line consumers to coexist. (This work was made available on the ib-aspeed branch, which may be appearing in other pull requests.) - Implemented .get_direction() and open drain in the SCH311x driver. - Continuing cleanup of included headers in GPIO drivers" * tag 'gpio-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (80 commits) gpio: it87: Add support for IT8613 gpio: it87: add support for IT8718F Super I/O. gpiolib: Avoid calling chip->request() for unused gpios gpio: tegra: Include the right header gpio: mmio: Fix up inverted direction registers gpio: xilinx: Use the right include gpio: timberdale: Include the right header gpio: tb10x: Use the right include gpiolib: Fix of_node inconsistency gpio: vr41xx: Bail out on gpiochip_lock_as_irq() error gpio: uniphier: Bail out on gpiochip_lock_as_irq() error gpio: xgene-sb: Don't shadow error code of gpiochip_lock_as_irq() gpio: em: Don't shadow error code of gpiochip_lock_as_irq() gpio: dwapb: Don't shadow error code of gpiochip_lock_as_irq() gpio: bcm-kona: Don't shadow error code of gpiochip_lock_as_irq() gpiolib: Don't shadow error code of gpiochip_lock_as_irq() gpio: syscon: rockchip: add GRF GPIO support for rk3328 gpio: omap: Add get/set_multiple() callbacks gpio: pxa: remove set but not used variable 'gpio_offset' gpio-it87: add support for IT8786E Super I/O ...
Diffstat (limited to 'drivers/gpio/gpio-davinci.c')
-rw-r--r--drivers/gpio/gpio-davinci.c70
1 files changed, 42 insertions, 28 deletions
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 035a454eca43..a5ece8ea79bc 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -167,8 +167,8 @@ of_err:
167static int davinci_gpio_probe(struct platform_device *pdev) 167static int davinci_gpio_probe(struct platform_device *pdev)
168{ 168{
169 static int ctrl_num, bank_base; 169 static int ctrl_num, bank_base;
170 int gpio, bank, ret = 0; 170 int gpio, bank, i, ret = 0;
171 unsigned ngpio, nbank; 171 unsigned int ngpio, nbank, nirq;
172 struct davinci_gpio_controller *chips; 172 struct davinci_gpio_controller *chips;
173 struct davinci_gpio_platform_data *pdata; 173 struct davinci_gpio_platform_data *pdata;
174 struct device *dev = &pdev->dev; 174 struct device *dev = &pdev->dev;
@@ -197,6 +197,16 @@ static int davinci_gpio_probe(struct platform_device *pdev)
197 if (WARN_ON(ARCH_NR_GPIOS < ngpio)) 197 if (WARN_ON(ARCH_NR_GPIOS < ngpio))
198 ngpio = ARCH_NR_GPIOS; 198 ngpio = ARCH_NR_GPIOS;
199 199
200 /*
201 * If there are unbanked interrupts then the number of
202 * interrupts is equal to number of gpios else all are banked so
203 * number of interrupts is equal to number of banks(each with 16 gpios)
204 */
205 if (pdata->gpio_unbanked)
206 nirq = pdata->gpio_unbanked;
207 else
208 nirq = DIV_ROUND_UP(ngpio, 16);
209
200 nbank = DIV_ROUND_UP(ngpio, 32); 210 nbank = DIV_ROUND_UP(ngpio, 32);
201 chips = devm_kcalloc(dev, 211 chips = devm_kcalloc(dev,
202 nbank, sizeof(struct davinci_gpio_controller), 212 nbank, sizeof(struct davinci_gpio_controller),
@@ -209,6 +219,15 @@ static int davinci_gpio_probe(struct platform_device *pdev)
209 if (IS_ERR(gpio_base)) 219 if (IS_ERR(gpio_base))
210 return PTR_ERR(gpio_base); 220 return PTR_ERR(gpio_base);
211 221
222 for (i = 0; i < nirq; i++) {
223 chips->irqs[i] = platform_get_irq(pdev, i);
224 if (chips->irqs[i] < 0) {
225 dev_info(dev, "IRQ not populated, err = %d\n",
226 chips->irqs[i]);
227 return chips->irqs[i];
228 }
229 }
230
212 snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++); 231 snprintf(label, MAX_LABEL_SIZE, "davinci_gpio.%d", ctrl_num++);
213 chips->chip.label = devm_kstrdup(dev, label, GFP_KERNEL); 232 chips->chip.label = devm_kstrdup(dev, label, GFP_KERNEL);
214 if (!chips->chip.label) 233 if (!chips->chip.label)
@@ -377,7 +396,7 @@ static int gpio_to_irq_unbanked(struct gpio_chip *chip, unsigned offset)
377 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs). 396 * can provide direct-mapped IRQs to AINTC (up to 32 GPIOs).
378 */ 397 */
379 if (offset < d->gpio_unbanked) 398 if (offset < d->gpio_unbanked)
380 return d->base_irq + offset; 399 return d->irqs[offset];
381 else 400 else
382 return -ENODEV; 401 return -ENODEV;
383} 402}
@@ -386,11 +405,18 @@ static int gpio_irq_type_unbanked(struct irq_data *data, unsigned trigger)
386{ 405{
387 struct davinci_gpio_controller *d; 406 struct davinci_gpio_controller *d;
388 struct davinci_gpio_regs __iomem *g; 407 struct davinci_gpio_regs __iomem *g;
389 u32 mask; 408 u32 mask, i;
390 409
391 d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data); 410 d = (struct davinci_gpio_controller *)irq_data_get_irq_handler_data(data);
392 g = (struct davinci_gpio_regs __iomem *)d->regs[0]; 411 g = (struct davinci_gpio_regs __iomem *)d->regs[0];
393 mask = __gpio_mask(data->irq - d->base_irq); 412 for (i = 0; i < MAX_INT_PER_BANK; i++)
413 if (data->irq == d->irqs[i])
414 break;
415
416 if (i == MAX_INT_PER_BANK)
417 return -EINVAL;
418
419 mask = __gpio_mask(i);
394 420
395 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING)) 421 if (trigger & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
396 return -EINVAL; 422 return -EINVAL;
@@ -459,9 +485,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
459 int ret; 485 int ret;
460 struct clk *clk; 486 struct clk *clk;
461 u32 binten = 0; 487 u32 binten = 0;
462 unsigned ngpio, bank_irq; 488 unsigned ngpio;
463 struct device *dev = &pdev->dev; 489 struct device *dev = &pdev->dev;
464 struct resource *res;
465 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev); 490 struct davinci_gpio_controller *chips = platform_get_drvdata(pdev);
466 struct davinci_gpio_platform_data *pdata = dev->platform_data; 491 struct davinci_gpio_platform_data *pdata = dev->platform_data;
467 struct davinci_gpio_regs __iomem *g; 492 struct davinci_gpio_regs __iomem *g;
@@ -481,24 +506,13 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
481 gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)match->data; 506 gpio_get_irq_chip = (gpio_get_irq_chip_cb_t)match->data;
482 507
483 ngpio = pdata->ngpio; 508 ngpio = pdata->ngpio;
484 res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
485 if (!res) {
486 dev_err(dev, "Invalid IRQ resource\n");
487 return -EBUSY;
488 }
489
490 bank_irq = res->start;
491
492 if (!bank_irq) {
493 dev_err(dev, "Invalid IRQ resource\n");
494 return -ENODEV;
495 }
496 509
497 clk = devm_clk_get(dev, "gpio"); 510 clk = devm_clk_get(dev, "gpio");
498 if (IS_ERR(clk)) { 511 if (IS_ERR(clk)) {
499 dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk)); 512 dev_err(dev, "Error %ld getting gpio clock\n", PTR_ERR(clk));
500 return PTR_ERR(clk); 513 return PTR_ERR(clk);
501 } 514 }
515
502 ret = clk_prepare_enable(clk); 516 ret = clk_prepare_enable(clk);
503 if (ret) 517 if (ret)
504 return ret; 518 return ret;
@@ -538,12 +552,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
538 if (pdata->gpio_unbanked) { 552 if (pdata->gpio_unbanked) {
539 /* pass "bank 0" GPIO IRQs to AINTC */ 553 /* pass "bank 0" GPIO IRQs to AINTC */
540 chips->chip.to_irq = gpio_to_irq_unbanked; 554 chips->chip.to_irq = gpio_to_irq_unbanked;
541 chips->base_irq = bank_irq;
542 chips->gpio_unbanked = pdata->gpio_unbanked; 555 chips->gpio_unbanked = pdata->gpio_unbanked;
543 binten = GENMASK(pdata->gpio_unbanked / 16, 0); 556 binten = GENMASK(pdata->gpio_unbanked / 16, 0);
544 557
545 /* AINTC handles mask/unmask; GPIO handles triggering */ 558 /* AINTC handles mask/unmask; GPIO handles triggering */
546 irq = bank_irq; 559 irq = chips->irqs[0];
547 irq_chip = gpio_get_irq_chip(irq); 560 irq_chip = gpio_get_irq_chip(irq);
548 irq_chip->name = "GPIO-AINTC"; 561 irq_chip->name = "GPIO-AINTC";
549 irq_chip->irq_set_type = gpio_irq_type_unbanked; 562 irq_chip->irq_set_type = gpio_irq_type_unbanked;
@@ -554,10 +567,11 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
554 writel_relaxed(~0, &g->set_rising); 567 writel_relaxed(~0, &g->set_rising);
555 568
556 /* set the direct IRQs up to use that irqchip */ 569 /* set the direct IRQs up to use that irqchip */
557 for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++, irq++) { 570 for (gpio = 0; gpio < pdata->gpio_unbanked; gpio++) {
558 irq_set_chip(irq, irq_chip); 571 irq_set_chip(chips->irqs[gpio], irq_chip);
559 irq_set_handler_data(irq, chips); 572 irq_set_handler_data(chips->irqs[gpio], chips);
560 irq_set_status_flags(irq, IRQ_TYPE_EDGE_BOTH); 573 irq_set_status_flags(chips->irqs[gpio],
574 IRQ_TYPE_EDGE_BOTH);
561 } 575 }
562 576
563 goto done; 577 goto done;
@@ -567,7 +581,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
567 * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we 581 * Or, AINTC can handle IRQs for banks of 16 GPIO IRQs, which we
568 * then chain through our own handler. 582 * then chain through our own handler.
569 */ 583 */
570 for (gpio = 0, bank = 0; gpio < ngpio; bank++, bank_irq++, gpio += 16) { 584 for (gpio = 0, bank = 0; gpio < ngpio; bank++, gpio += 16) {
571 /* disabled by default, enabled only as needed 585 /* disabled by default, enabled only as needed
572 * There are register sets for 32 GPIOs. 2 banks of 16 586 * There are register sets for 32 GPIOs. 2 banks of 16
573 * GPIOs are covered by each set of registers hence divide by 2 587 * GPIOs are covered by each set of registers hence divide by 2
@@ -594,8 +608,8 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
594 irqdata->bank_num = bank; 608 irqdata->bank_num = bank;
595 irqdata->chip = chips; 609 irqdata->chip = chips;
596 610
597 irq_set_chained_handler_and_data(bank_irq, gpio_irq_handler, 611 irq_set_chained_handler_and_data(chips->irqs[bank],
598 irqdata); 612 gpio_irq_handler, irqdata);
599 613
600 binten |= BIT(bank); 614 binten |= BIT(bank);
601 } 615 }