hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/mfd/sm501.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* linux/drivers/mfd/sm501.c
23 *
34 * Copyright (C) 2006 Simtec Electronics
45 * Ben Dooks <ben@simtec.co.uk>
56 * Vincent Sanders <vince@simtec.co.uk>
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 *
118 * SM501 MFD driver
129 */
....@@ -20,6 +17,7 @@
2017 #include <linux/platform_device.h>
2118 #include <linux/pci.h>
2219 #include <linux/platform_data/i2c-gpio.h>
20
+#include <linux/gpio/driver.h>
2321 #include <linux/gpio/machine.h>
2422 #include <linux/slab.h>
2523
....@@ -1088,8 +1086,7 @@
10881086 iounmap(gpio->regs);
10891087
10901088 err_claimed:
1091
- release_resource(gpio->regs_res);
1092
- kfree(gpio->regs_res);
1089
+ release_mem_region(iobase, 0x20);
10931090
10941091 return ret;
10951092 }
....@@ -1097,6 +1094,7 @@
10971094 static void sm501_gpio_remove(struct sm501_devdata *sm)
10981095 {
10991096 struct sm501_gpio *gpio = &sm->gpio;
1097
+ resource_size_t iobase = sm->io_res->start + SM501_GPIO;
11001098
11011099 if (!sm->gpio.registered)
11021100 return;
....@@ -1105,8 +1103,7 @@
11051103 gpiochip_remove(&gpio->high.gpio);
11061104
11071105 iounmap(gpio->regs);
1108
- release_resource(gpio->regs_res);
1109
- kfree(gpio->regs_res);
1106
+ release_mem_region(iobase, 0x20);
11101107 }
11111108
11121109 static inline int sm501_gpio_isregistered(struct sm501_devdata *sm)
....@@ -1142,29 +1139,20 @@
11421139 return -ENOMEM;
11431140
11441141 /* Create a gpiod lookup using gpiochip-local offsets */
1145
- lookup = devm_kzalloc(&pdev->dev,
1146
- sizeof(*lookup) + 3 * sizeof(struct gpiod_lookup),
1142
+ lookup = devm_kzalloc(&pdev->dev, struct_size(lookup, table, 3),
11471143 GFP_KERNEL);
11481144 if (!lookup)
11491145 return -ENOMEM;
11501146
11511147 lookup->dev_id = "i2c-gpio";
1152
- if (iic->pin_sda < 32)
1153
- lookup->table[0].chip_label = "SM501-LOW";
1154
- else
1155
- lookup->table[0].chip_label = "SM501-HIGH";
1156
- lookup->table[0].chip_hwnum = iic->pin_sda % 32;
1157
- lookup->table[0].con_id = NULL;
1158
- lookup->table[0].idx = 0;
1159
- lookup->table[0].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN;
1160
- if (iic->pin_scl < 32)
1161
- lookup->table[1].chip_label = "SM501-LOW";
1162
- else
1163
- lookup->table[1].chip_label = "SM501-HIGH";
1164
- lookup->table[1].chip_hwnum = iic->pin_scl % 32;
1165
- lookup->table[1].con_id = NULL;
1166
- lookup->table[1].idx = 1;
1167
- lookup->table[1].flags = GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN;
1148
+ lookup->table[0] = (struct gpiod_lookup)
1149
+ GPIO_LOOKUP_IDX(iic->pin_sda < 32 ? "SM501-LOW" : "SM501-HIGH",
1150
+ iic->pin_sda % 32, NULL, 0,
1151
+ GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN);
1152
+ lookup->table[1] = (struct gpiod_lookup)
1153
+ GPIO_LOOKUP_IDX(iic->pin_scl < 32 ? "SM501-LOW" : "SM501-HIGH",
1154
+ iic->pin_scl % 32, NULL, 1,
1155
+ GPIO_ACTIVE_HIGH | GPIO_OPEN_DRAIN);
11681156 gpiod_add_lookup_table(lookup);
11691157
11701158 icd = dev_get_platdata(&pdev->dev);
....@@ -1398,10 +1386,8 @@
13981386 sm->platdata = dev_get_platdata(&dev->dev);
13991387
14001388 ret = platform_get_irq(dev, 0);
1401
- if (ret < 0) {
1402
- dev_err(&dev->dev, "failed to get irq resource\n");
1389
+ if (ret < 0)
14031390 goto err_res;
1404
- }
14051391 sm->irq = ret;
14061392
14071393 sm->io_res = platform_get_resource(dev, IORESOURCE_MEM, 1);
....@@ -1438,8 +1424,7 @@
14381424 err_unmap:
14391425 iounmap(sm->regs);
14401426 err_claim:
1441
- release_resource(sm->regs_claim);
1442
- kfree(sm->regs_claim);
1427
+ release_mem_region(sm->io_res->start, 0x100);
14431428 err_res:
14441429 kfree(sm);
14451430 err1:
....@@ -1648,8 +1633,7 @@
16481633 return 0;
16491634
16501635 err4:
1651
- release_resource(sm->regs_claim);
1652
- kfree(sm->regs_claim);
1636
+ release_mem_region(sm->io_res->start, 0x100);
16531637 err3:
16541638 pci_disable_device(dev);
16551639 err2:
....@@ -1684,8 +1668,7 @@
16841668 sm501_dev_remove(sm);
16851669 iounmap(sm->regs);
16861670
1687
- release_resource(sm->regs_claim);
1688
- kfree(sm->regs_claim);
1671
+ release_mem_region(sm->io_res->start, 0x100);
16891672
16901673 pci_disable_device(dev);
16911674 }
....@@ -1697,8 +1680,7 @@
16971680 sm501_dev_remove(sm);
16981681 iounmap(sm->regs);
16991682
1700
- release_resource(sm->regs_claim);
1701
- kfree(sm->regs_claim);
1683
+ release_mem_region(sm->io_res->start, 0x100);
17021684
17031685 return 0;
17041686 }
....@@ -1738,7 +1720,12 @@
17381720
17391721 static int __init sm501_base_init(void)
17401722 {
1741
- platform_driver_register(&sm501_plat_driver);
1723
+ int ret;
1724
+
1725
+ ret = platform_driver_register(&sm501_plat_driver);
1726
+ if (ret < 0)
1727
+ return ret;
1728
+
17421729 return pci_register_driver(&sm501_pci_driver);
17431730 }
17441731