hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/gpio/gpio-mxc.c
....@@ -15,6 +15,7 @@
1515 #include <linux/irq.h>
1616 #include <linux/irqdomain.h>
1717 #include <linux/irqchip/chained_irq.h>
18
+#include <linux/module.h>
1819 #include <linux/platform_device.h>
1920 #include <linux/slab.h>
2021 #include <linux/syscore_ops.h>
....@@ -158,6 +159,7 @@
158159 { .compatible = "fsl,imx7d-gpio", .data = &mxc_gpio_devtype[IMX35_GPIO], },
159160 { /* sentinel */ }
160161 };
162
+MODULE_DEVICE_TABLE(of, mxc_gpio_dt_ids);
161163
162164 /*
163165 * MX2 has one interrupt *for all* gpio ports. The list is used
....@@ -229,7 +231,7 @@
229231
230232 writel(1 << gpio_idx, port->base + GPIO_ISR);
231233
232
- return 0;
234
+ return port->gc.direction_input(&port->gc, gpio_idx);
233235 }
234236
235237 static void mxc_flip_edge(struct mxc_gpio_port *port, u32 gpio)
....@@ -359,7 +361,7 @@
359361 ct->chip.irq_unmask = irq_gc_mask_set_bit;
360362 ct->chip.irq_set_type = gpio_set_irq_type;
361363 ct->chip.irq_set_wake = gpio_set_wake_irq;
362
- ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND;
364
+ ct->chip.flags = IRQCHIP_MASK_ON_SUSPEND | IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND;
363365 ct->regs.ack = GPIO_ISR;
364366 ct->regs.mask = GPIO_IMR;
365367
....@@ -411,7 +413,7 @@
411413 {
412414 struct device_node *np = pdev->dev.of_node;
413415 struct mxc_gpio_port *port;
414
- struct resource *iores;
416
+ int irq_count;
415417 int irq_base;
416418 int err;
417419
....@@ -423,26 +425,28 @@
423425
424426 port->dev = &pdev->dev;
425427
426
- iores = platform_get_resource(pdev, IORESOURCE_MEM, 0);
427
- port->base = devm_ioremap_resource(&pdev->dev, iores);
428
+ port->base = devm_platform_ioremap_resource(pdev, 0);
428429 if (IS_ERR(port->base))
429430 return PTR_ERR(port->base);
430431
431
- port->irq_high = platform_get_irq(pdev, 1);
432
- if (port->irq_high < 0)
433
- port->irq_high = 0;
432
+ irq_count = platform_irq_count(pdev);
433
+ if (irq_count < 0)
434
+ return irq_count;
435
+
436
+ if (irq_count > 1) {
437
+ port->irq_high = platform_get_irq(pdev, 1);
438
+ if (port->irq_high < 0)
439
+ port->irq_high = 0;
440
+ }
434441
435442 port->irq = platform_get_irq(pdev, 0);
436443 if (port->irq < 0)
437444 return port->irq;
438445
439446 /* the controller clock is optional */
440
- port->clk = devm_clk_get(&pdev->dev, NULL);
441
- if (IS_ERR(port->clk)) {
442
- if (PTR_ERR(port->clk) == -EPROBE_DEFER)
443
- return -EPROBE_DEFER;
444
- port->clk = NULL;
445
- }
447
+ port->clk = devm_clk_get_optional(&pdev->dev, NULL);
448
+ if (IS_ERR(port->clk))
449
+ return PTR_ERR(port->clk);
446450
447451 err = clk_prepare_enable(port->clk);
448452 if (err) {
....@@ -483,11 +487,8 @@
483487 if (err)
484488 goto out_bgio;
485489
486
- if (of_property_read_bool(np, "gpio-ranges")) {
487
- port->gc.request = gpiochip_generic_request;
488
- port->gc.free = gpiochip_generic_free;
489
- }
490
-
490
+ port->gc.request = gpiochip_generic_request;
491
+ port->gc.free = gpiochip_generic_free;
491492 port->gc.to_irq = mxc_gpio_to_irq;
492493 port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 :
493494 pdev->id * 32;
....@@ -605,3 +606,7 @@
605606 return platform_driver_register(&mxc_gpio_driver);
606607 }
607608 subsys_initcall(gpio_mxc_init);
609
+
610
+MODULE_AUTHOR("Shawn Guo <shawn.guo@linaro.org>");
611
+MODULE_DESCRIPTION("i.MX GPIO Driver");
612
+MODULE_LICENSE("GPL");