hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/pinctrl/nomadik/pinctrl-nomadik.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Generic GPIO driver for logic cells found in the Nomadik SoC
34 *
....@@ -5,10 +6,6 @@
56 * Copyright (C) 2009 Alessandro Rubini <rubini@unipv.it>
67 * Rewritten based on work by Prafulla WADASKAR <prafulla.wadaskar@st.com>
78 * Copyright (C) 2011-2013 Linus Walleij <linus.walleij@linaro.org>
8
- *
9
- * This program is free software; you can redistribute it and/or modify
10
- * it under the terms of the GNU General Public License version 2 as
11
- * published by the Free Software Foundation.
129 */
1310 #include <linux/kernel.h>
1411 #include <linux/init.h>
....@@ -17,7 +14,7 @@
1714 #include <linux/io.h>
1815 #include <linux/clk.h>
1916 #include <linux/err.h>
20
-#include <linux/gpio.h>
17
+#include <linux/gpio/driver.h>
2118 #include <linux/spinlock.h>
2219 #include <linux/interrupt.h>
2320 #include <linux/slab.h>
....@@ -203,7 +200,7 @@
203200
204201 #define GPIO_BLOCK_SHIFT 5
205202 #define NMK_GPIO_PER_CHIP (1 << GPIO_BLOCK_SHIFT)
206
-#define NMK_MAX_BANKS DIV_ROUND_UP(ARCH_NR_GPIOS, NMK_GPIO_PER_CHIP)
203
+#define NMK_MAX_BANKS DIV_ROUND_UP(512, NMK_GPIO_PER_CHIP)
207204
208205 /* Register in the logic block */
209206 #define NMK_GPIO_DAT 0x00
....@@ -251,9 +248,6 @@
251248 void __iomem *addr;
252249 struct clk *clk;
253250 unsigned int bank;
254
- unsigned int parent_irq;
255
- int latent_parent_irq;
256
- u32 (*get_latent_status)(unsigned int bank);
257251 void (*set_ioforce)(bool enable);
258252 spinlock_t lock;
259253 bool sleepmode;
....@@ -805,12 +799,18 @@
805799 clk_disable(nmk_chip->clk);
806800 }
807801
808
-static void __nmk_gpio_irq_handler(struct irq_desc *desc, u32 status)
802
+static void nmk_gpio_irq_handler(struct irq_desc *desc)
809803 {
810804 struct irq_chip *host_chip = irq_desc_get_chip(desc);
811805 struct gpio_chip *chip = irq_desc_get_handler_data(desc);
806
+ struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip);
807
+ u32 status;
812808
813809 chained_irq_enter(host_chip, desc);
810
+
811
+ clk_enable(nmk_chip->clk);
812
+ status = readl(nmk_chip->addr + NMK_GPIO_IS);
813
+ clk_disable(nmk_chip->clk);
814814
815815 while (status) {
816816 int bit = __ffs(status);
....@@ -822,28 +822,6 @@
822822 chained_irq_exit(host_chip, desc);
823823 }
824824
825
-static void nmk_gpio_irq_handler(struct irq_desc *desc)
826
-{
827
- struct gpio_chip *chip = irq_desc_get_handler_data(desc);
828
- struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip);
829
- u32 status;
830
-
831
- clk_enable(nmk_chip->clk);
832
- status = readl(nmk_chip->addr + NMK_GPIO_IS);
833
- clk_disable(nmk_chip->clk);
834
-
835
- __nmk_gpio_irq_handler(desc, status);
836
-}
837
-
838
-static void nmk_gpio_latent_irq_handler(struct irq_desc *desc)
839
-{
840
- struct gpio_chip *chip = irq_desc_get_handler_data(desc);
841
- struct nmk_gpio_chip *nmk_chip = gpiochip_get_data(chip);
842
- u32 status = nmk_chip->get_latent_status(nmk_chip->bank);
843
-
844
- __nmk_gpio_irq_handler(desc, status);
845
-}
846
-
847825 /* I/O Functions */
848826
849827 static int nmk_gpio_get_dir(struct gpio_chip *chip, unsigned offset)
....@@ -853,11 +831,14 @@
853831
854832 clk_enable(nmk_chip->clk);
855833
856
- dir = !(readl(nmk_chip->addr + NMK_GPIO_DIR) & BIT(offset));
834
+ dir = readl(nmk_chip->addr + NMK_GPIO_DIR) & BIT(offset);
857835
858836 clk_disable(nmk_chip->clk);
859837
860
- return dir;
838
+ if (dir)
839
+ return GPIO_LINE_DIRECTION_OUT;
840
+
841
+ return GPIO_LINE_DIRECTION_IN;
861842 }
862843
863844 static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
....@@ -950,11 +931,6 @@
950931 [NMK_GPIO_ALT_C+3] = "altC3",
951932 [NMK_GPIO_ALT_C+4] = "altC4",
952933 };
953
- const char *pulls[] = {
954
- "none ",
955
- "pull down",
956
- "pull up ",
957
- };
958934
959935 clk_enable(nmk_chip->clk);
960936 is_out = !!(readl(nmk_chip->addr + NMK_GPIO_DIR) & BIT(offset));
....@@ -965,19 +941,20 @@
965941 mode = nmk_prcm_gpiocr_get_mode(pctldev, gpio);
966942
967943 if (is_out) {
968
- seq_printf(s, " gpio-%-3d (%-20.20s) out %s %s",
944
+ seq_printf(s, " gpio-%-3d (%-20.20s) out %s %s",
969945 gpio,
970946 label ?: "(none)",
971947 data_out ? "hi" : "lo",
972948 (mode < 0) ? "unknown" : modes[mode]);
973949 } else {
974
- int irq = gpio_to_irq(gpio);
950
+ int irq = chip->to_irq(chip, offset);
975951 struct irq_desc *desc = irq_to_desc(irq);
976
- int pullidx = 0;
952
+ const int pullidx = pull ? 1 : 0;
977953 int val;
978
-
979
- if (pull)
980
- pullidx = data_out ? 2 : 1;
954
+ static const char * const pulls[] = {
955
+ "none ",
956
+ "pull enabled",
957
+ };
981958
982959 seq_printf(s, " gpio-%-3d (%-20.20s) in %s %s",
983960 gpio,
....@@ -1051,22 +1028,27 @@
10511028
10521029 gpio_pdev = of_find_device_by_node(np);
10531030 if (!gpio_pdev) {
1054
- pr_err("populate \"%s\": device not found\n", np->name);
1031
+ pr_err("populate \"%pOFn\": device not found\n", np);
10551032 return ERR_PTR(-ENODEV);
10561033 }
10571034 if (of_property_read_u32(np, "gpio-bank", &id)) {
10581035 dev_err(&pdev->dev, "populate: gpio-bank property not found\n");
1036
+ platform_device_put(gpio_pdev);
10591037 return ERR_PTR(-EINVAL);
10601038 }
10611039
10621040 /* Already populated? */
10631041 nmk_chip = nmk_gpio_chips[id];
1064
- if (nmk_chip)
1042
+ if (nmk_chip) {
1043
+ platform_device_put(gpio_pdev);
10651044 return nmk_chip;
1045
+ }
10661046
10671047 nmk_chip = devm_kzalloc(&pdev->dev, sizeof(*nmk_chip), GFP_KERNEL);
1068
- if (!nmk_chip)
1048
+ if (!nmk_chip) {
1049
+ platform_device_put(gpio_pdev);
10691050 return ERR_PTR(-ENOMEM);
1051
+ }
10701052
10711053 nmk_chip->bank = id;
10721054 chip = &nmk_chip->chip;
....@@ -1077,13 +1059,17 @@
10771059
10781060 res = platform_get_resource(gpio_pdev, IORESOURCE_MEM, 0);
10791061 base = devm_ioremap_resource(&pdev->dev, res);
1080
- if (IS_ERR(base))
1062
+ if (IS_ERR(base)) {
1063
+ platform_device_put(gpio_pdev);
10811064 return ERR_CAST(base);
1065
+ }
10821066 nmk_chip->addr = base;
10831067
10841068 clk = clk_get(&gpio_pdev->dev, NULL);
1085
- if (IS_ERR(clk))
1069
+ if (IS_ERR(clk)) {
1070
+ platform_device_put(gpio_pdev);
10861071 return (void *) clk;
1072
+ }
10871073 clk_prepare(clk);
10881074 nmk_chip->clk = clk;
10891075
....@@ -1097,8 +1083,8 @@
10971083 struct device_node *np = dev->dev.of_node;
10981084 struct nmk_gpio_chip *nmk_chip;
10991085 struct gpio_chip *chip;
1086
+ struct gpio_irq_chip *girq;
11001087 struct irq_chip *irqchip;
1101
- int latent_irq;
11021088 bool supports_sleepmode;
11031089 int irq;
11041090 int ret;
....@@ -1119,15 +1105,10 @@
11191105 if (irq < 0)
11201106 return irq;
11211107
1122
- /* It's OK for this IRQ not to be present */
1123
- latent_irq = platform_get_irq(dev, 1);
1124
-
11251108 /*
11261109 * The virt address in nmk_chip->addr is in the nomadik register space,
11271110 * so we can simply convert the resource address, without remapping
11281111 */
1129
- nmk_chip->parent_irq = irq;
1130
- nmk_chip->latent_parent_irq = latent_irq;
11311112 nmk_chip->sleepmode = supports_sleepmode;
11321113 spin_lock_init(&nmk_chip->lock);
11331114
....@@ -1157,6 +1138,19 @@
11571138 chip->base,
11581139 chip->base + chip->ngpio - 1);
11591140
1141
+ girq = &chip->irq;
1142
+ girq->chip = irqchip;
1143
+ girq->parent_handler = nmk_gpio_irq_handler;
1144
+ girq->num_parents = 1;
1145
+ girq->parents = devm_kcalloc(&dev->dev, 1,
1146
+ sizeof(*girq->parents),
1147
+ GFP_KERNEL);
1148
+ if (!girq->parents)
1149
+ return -ENOMEM;
1150
+ girq->parents[0] = irq;
1151
+ girq->default_type = IRQ_TYPE_NONE;
1152
+ girq->handler = handle_edge_irq;
1153
+
11601154 clk_enable(nmk_chip->clk);
11611155 nmk_chip->lowemi = readl_relaxed(nmk_chip->addr + NMK_GPIO_LOWEMI);
11621156 clk_disable(nmk_chip->clk);
....@@ -1168,33 +1162,7 @@
11681162
11691163 platform_set_drvdata(dev, nmk_chip);
11701164
1171
- /*
1172
- * Let the generic code handle this edge IRQ, the the chained
1173
- * handler will perform the actual work of handling the parent
1174
- * interrupt.
1175
- */
1176
- ret = gpiochip_irqchip_add(chip,
1177
- irqchip,
1178
- 0,
1179
- handle_edge_irq,
1180
- IRQ_TYPE_NONE);
1181
- if (ret) {
1182
- dev_err(&dev->dev, "could not add irqchip\n");
1183
- gpiochip_remove(&nmk_chip->chip);
1184
- return -ENODEV;
1185
- }
1186
- /* Then register the chain on the parent IRQ */
1187
- gpiochip_set_chained_irqchip(chip,
1188
- irqchip,
1189
- nmk_chip->parent_irq,
1190
- nmk_gpio_irq_handler);
1191
- if (nmk_chip->latent_parent_irq > 0)
1192
- gpiochip_set_chained_irqchip(chip,
1193
- irqchip,
1194
- nmk_chip->latent_parent_irq,
1195
- nmk_gpio_latent_irq_handler);
1196
-
1197
- dev_info(&dev->dev, "at address %p\n", nmk_chip->addr);
1165
+ dev_info(&dev->dev, "chip registered\n");
11981166
11991167 return 0;
12001168 }
....@@ -1371,8 +1339,6 @@
13711339
13721340 static int nmk_dt_pin_config(int index, int val, unsigned long *config)
13731341 {
1374
- int ret = 0;
1375
-
13761342 if (nmk_cfg_params[index].choice == NULL)
13771343 *config = nmk_cfg_params[index].config;
13781344 else {
....@@ -1382,7 +1348,7 @@
13821348 nmk_cfg_params[index].choice[val];
13831349 }
13841350 }
1385
- return ret;
1351
+ return 0;
13861352 }
13871353
13881354 static const char *nmk_find_pin_name(struct pinctrl_dev *pctldev, const char *pin_name)
....@@ -1455,8 +1421,10 @@
14551421
14561422 has_config = nmk_pinctrl_dt_get_config(np, &configs);
14571423 np_config = of_parse_phandle(np, "ste,config", 0);
1458
- if (np_config)
1424
+ if (np_config) {
14591425 has_config |= nmk_pinctrl_dt_get_config(np_config, &configs);
1426
+ of_node_put(np_config);
1427
+ }
14601428 if (has_config) {
14611429 const char *gpio_name;
14621430 const char *pin;
....@@ -1502,6 +1470,7 @@
15021470 &reserved_maps, num_maps);
15031471 if (ret < 0) {
15041472 pinctrl_utils_free_map(pctldev, *map, *num_maps);
1473
+ of_node_put(np);
15051474 return ret;
15061475 }
15071476 }
....@@ -1904,8 +1873,8 @@
19041873 gpio_np = of_parse_phandle(np, "nomadik-gpio-chips", i);
19051874 if (gpio_np) {
19061875 dev_info(&pdev->dev,
1907
- "populate NMK GPIO %d \"%s\"\n",
1908
- i, gpio_np->name);
1876
+ "populate NMK GPIO %d \"%pOFn\"\n",
1877
+ i, gpio_np);
19091878 nmk_chip = nmk_gpio_populate_chip(gpio_np, pdev);
19101879 if (IS_ERR(nmk_chip))
19111880 dev_err(&pdev->dev,
....@@ -1916,8 +1885,10 @@
19161885 }
19171886
19181887 prcm_np = of_parse_phandle(np, "prcm", 0);
1919
- if (prcm_np)
1888
+ if (prcm_np) {
19201889 npct->prcm_base = of_iomap(prcm_np, 0);
1890
+ of_node_put(prcm_np);
1891
+ }
19211892 if (!npct->prcm_base) {
19221893 if (version == PINCTRL_NMK_STN8815) {
19231894 dev_info(&pdev->dev,