Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 2 | /* |
| 3 | * drivers/mfd/mfd-core.c |
| 4 | * |
| 5 | * core MFD support |
| 6 | * Copyright (c) 2006 Ian Molton |
| 7 | * Copyright (c) 2007,2008 Dmitry Baryshkov |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/platform_device.h> |
Samuel Ortiz | 91feded | 2010-02-19 11:07:59 +0100 | [diff] [blame] | 12 | #include <linux/acpi.h> |
Andy Shevchenko | 4d215ca | 2015-11-30 17:11:40 +0200 | [diff] [blame] | 13 | #include <linux/property.h> |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 14 | #include <linux/mfd/core.h> |
Mark Brown | 4c90aa9 | 2010-11-26 17:19:34 +0000 | [diff] [blame] | 15 | #include <linux/pm_runtime.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 16 | #include <linux/slab.h> |
Paul Gortmaker | 4e36dd3 | 2011-07-03 15:13:27 -0400 | [diff] [blame] | 17 | #include <linux/module.h> |
Lee Jones | c94bb23 | 2012-06-29 19:01:03 +0200 | [diff] [blame] | 18 | #include <linux/irqdomain.h> |
| 19 | #include <linux/of.h> |
Charles Keepax | 7fcd427 | 2013-10-15 20:14:21 +0100 | [diff] [blame] | 20 | #include <linux/regulator/consumer.h> |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 21 | |
Charles Keepax | b9fbb62 | 2012-11-09 16:15:28 +0000 | [diff] [blame] | 22 | static struct device_type mfd_dev_type = { |
| 23 | .name = "mfd_device", |
| 24 | }; |
| 25 | |
Andres Salomon | f77289a | 2011-03-03 09:51:58 -0800 | [diff] [blame] | 26 | int mfd_cell_enable(struct platform_device *pdev) |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 27 | { |
| 28 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 29 | |
Lee Jones | b195e101 | 2019-10-21 10:16:34 +0100 | [diff] [blame] | 30 | if (!cell->enable) { |
| 31 | dev_dbg(&pdev->dev, "No .enable() call-back registered\n"); |
| 32 | return 0; |
| 33 | } |
| 34 | |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 35 | return cell->enable(pdev); |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 36 | } |
Andres Salomon | f77289a | 2011-03-03 09:51:58 -0800 | [diff] [blame] | 37 | EXPORT_SYMBOL(mfd_cell_enable); |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 38 | |
Andres Salomon | f77289a | 2011-03-03 09:51:58 -0800 | [diff] [blame] | 39 | int mfd_cell_disable(struct platform_device *pdev) |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 40 | { |
| 41 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 42 | |
Lee Jones | b195e101 | 2019-10-21 10:16:34 +0100 | [diff] [blame] | 43 | if (!cell->disable) { |
| 44 | dev_dbg(&pdev->dev, "No .disable() call-back registered\n"); |
| 45 | return 0; |
| 46 | } |
| 47 | |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 48 | return cell->disable(pdev); |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 49 | } |
Andres Salomon | f77289a | 2011-03-03 09:51:58 -0800 | [diff] [blame] | 50 | EXPORT_SYMBOL(mfd_cell_disable); |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 51 | |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_ACPI) |
| 53 | static void mfd_acpi_add_device(const struct mfd_cell *cell, |
| 54 | struct platform_device *pdev) |
| 55 | { |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 56 | const struct mfd_cell_acpi_match *match = cell->acpi_match; |
| 57 | struct acpi_device *parent, *child; |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 58 | struct acpi_device *adev; |
| 59 | |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 60 | parent = ACPI_COMPANION(pdev->dev.parent); |
| 61 | if (!parent) |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 62 | return; |
| 63 | |
| 64 | /* |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 65 | * MFD child device gets its ACPI handle either from the ACPI device |
| 66 | * directly under the parent that matches the either _HID or _CID, or |
| 67 | * _ADR or it will use the parent handle if is no ID is given. |
| 68 | * |
| 69 | * Note that use of _ADR is a grey area in the ACPI specification, |
| 70 | * though Intel Galileo Gen2 is using it to distinguish the children |
| 71 | * devices. |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 72 | */ |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 73 | adev = parent; |
| 74 | if (match) { |
| 75 | if (match->pnpid) { |
| 76 | struct acpi_device_id ids[2] = {}; |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 77 | |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 78 | strlcpy(ids[0].id, match->pnpid, sizeof(ids[0].id)); |
| 79 | list_for_each_entry(child, &parent->children, node) { |
Irina Tirdea | ee414de | 2016-03-13 03:02:58 +0200 | [diff] [blame] | 80 | if (!acpi_match_device_ids(child, ids)) { |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 81 | adev = child; |
| 82 | break; |
| 83 | } |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 84 | } |
Andy Shevchenko | 98a3be4 | 2015-10-23 12:16:41 +0300 | [diff] [blame] | 85 | } else { |
| 86 | unsigned long long adr; |
| 87 | acpi_status status; |
| 88 | |
| 89 | list_for_each_entry(child, &parent->children, node) { |
| 90 | status = acpi_evaluate_integer(child->handle, |
| 91 | "_ADR", NULL, |
| 92 | &adr); |
| 93 | if (ACPI_SUCCESS(status) && match->adr == adr) { |
| 94 | adev = child; |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | } |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | ACPI_COMPANION_SET(&pdev->dev, adev); |
| 102 | } |
| 103 | #else |
| 104 | static inline void mfd_acpi_add_device(const struct mfd_cell *cell, |
| 105 | struct platform_device *pdev) |
| 106 | { |
| 107 | } |
| 108 | #endif |
| 109 | |
Dmitry Baryshkov | 424f525 | 2008-07-29 01:30:26 +0200 | [diff] [blame] | 110 | static int mfd_add_device(struct device *parent, int id, |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 111 | const struct mfd_cell *cell, |
Ben Dooks | 7f71ac9 | 2008-07-28 18:29:09 +0200 | [diff] [blame] | 112 | struct resource *mem_base, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 113 | int irq_base, struct irq_domain *domain) |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 114 | { |
Ian Molton | a87903f | 2008-07-25 22:59:29 +0100 | [diff] [blame] | 115 | struct resource *res; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 116 | struct platform_device *pdev; |
Lee Jones | c94bb23 | 2012-06-29 19:01:03 +0200 | [diff] [blame] | 117 | struct device_node *np = NULL; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 118 | int ret = -ENOMEM; |
Johan Hovold | 6e3f62f | 2014-09-26 12:55:33 +0200 | [diff] [blame] | 119 | int platform_id; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 120 | int r; |
| 121 | |
Johan Hovold | a77c50b | 2015-03-25 12:07:05 +0100 | [diff] [blame] | 122 | if (id == PLATFORM_DEVID_AUTO) |
Johan Hovold | 6e3f62f | 2014-09-26 12:55:33 +0200 | [diff] [blame] | 123 | platform_id = id; |
| 124 | else |
| 125 | platform_id = id + cell->id; |
| 126 | |
| 127 | pdev = platform_device_alloc(cell->name, platform_id); |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 128 | if (!pdev) |
| 129 | goto fail_alloc; |
| 130 | |
Lee Jones | b944a68 | 2019-10-21 10:55:23 +0100 | [diff] [blame] | 131 | pdev->mfd_cell = kmemdup(cell, sizeof(*cell), GFP_KERNEL); |
| 132 | if (!pdev->mfd_cell) |
| 133 | goto fail_device; |
| 134 | |
Kees Cook | 6396bb2 | 2018-06-12 14:03:40 -0700 | [diff] [blame] | 135 | res = kcalloc(cell->num_resources, sizeof(*res), GFP_KERNEL); |
Ian Molton | a87903f | 2008-07-25 22:59:29 +0100 | [diff] [blame] | 136 | if (!res) |
| 137 | goto fail_device; |
| 138 | |
Dmitry Baryshkov | 424f525 | 2008-07-29 01:30:26 +0200 | [diff] [blame] | 139 | pdev->dev.parent = parent; |
Charles Keepax | b9fbb62 | 2012-11-09 16:15:28 +0000 | [diff] [blame] | 140 | pdev->dev.type = &mfd_dev_type; |
Benedikt Spranger | b018e13 | 2013-08-13 11:08:38 +0200 | [diff] [blame] | 141 | pdev->dev.dma_mask = parent->dma_mask; |
| 142 | pdev->dev.dma_parms = parent->dma_parms; |
Boris BREZILLON | 4f08df1 | 2014-09-22 21:37:55 +0200 | [diff] [blame] | 143 | pdev->dev.coherent_dma_mask = parent->coherent_dma_mask; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 144 | |
Charles Keepax | d137be0 | 2014-04-24 18:27:25 +0100 | [diff] [blame] | 145 | ret = regulator_bulk_register_supply_alias( |
Charles Keepax | 7fcd427 | 2013-10-15 20:14:21 +0100 | [diff] [blame] | 146 | &pdev->dev, cell->parent_supplies, |
| 147 | parent, cell->parent_supplies, |
| 148 | cell->num_parent_supplies); |
| 149 | if (ret < 0) |
| 150 | goto fail_res; |
| 151 | |
Lee Jones | c94bb23 | 2012-06-29 19:01:03 +0200 | [diff] [blame] | 152 | if (parent->of_node && cell->of_compatible) { |
| 153 | for_each_child_of_node(parent->of_node, np) { |
| 154 | if (of_device_is_compatible(np, cell->of_compatible)) { |
Lee Jones | 6b5c350 | 2019-11-07 11:19:50 +0000 | [diff] [blame] | 155 | if (!of_device_is_available(np)) { |
| 156 | /* Ignore disabled devices error free */ |
| 157 | ret = 0; |
| 158 | goto fail_alias; |
| 159 | } |
Lee Jones | c94bb23 | 2012-06-29 19:01:03 +0200 | [diff] [blame] | 160 | pdev->dev.of_node = np; |
Robert Hancock | c176c6d | 2019-06-04 16:35:43 -0600 | [diff] [blame] | 161 | pdev->dev.fwnode = &np->fwnode; |
Lee Jones | c94bb23 | 2012-06-29 19:01:03 +0200 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | |
Mika Westerberg | 6ab3430 | 2014-09-16 14:52:36 +0300 | [diff] [blame] | 167 | mfd_acpi_add_device(cell, pdev); |
| 168 | |
Samuel Ortiz | eb89560 | 2011-04-06 16:52:52 +0200 | [diff] [blame] | 169 | if (cell->pdata_size) { |
| 170 | ret = platform_device_add_data(pdev, |
| 171 | cell->platform_data, cell->pdata_size); |
| 172 | if (ret) |
Charles Keepax | 7fcd427 | 2013-10-15 20:14:21 +0100 | [diff] [blame] | 173 | goto fail_alias; |
Samuel Ortiz | eb89560 | 2011-04-06 16:52:52 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Heikki Krogerus | f4d0526 | 2016-03-29 14:52:23 +0300 | [diff] [blame] | 176 | if (cell->properties) { |
| 177 | ret = platform_device_add_properties(pdev, cell->properties); |
Andy Shevchenko | 4d215ca | 2015-11-30 17:11:40 +0200 | [diff] [blame] | 178 | if (ret) |
| 179 | goto fail_alias; |
| 180 | } |
| 181 | |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 182 | for (r = 0; r < cell->num_resources; r++) { |
| 183 | res[r].name = cell->resources[r].name; |
| 184 | res[r].flags = cell->resources[r].flags; |
| 185 | |
| 186 | /* Find out base to use */ |
Samuel Ortiz | f03cfcb | 2010-03-26 01:09:04 +0100 | [diff] [blame] | 187 | if ((cell->resources[r].flags & IORESOURCE_MEM) && mem_base) { |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 188 | res[r].parent = mem_base; |
| 189 | res[r].start = mem_base->start + |
| 190 | cell->resources[r].start; |
| 191 | res[r].end = mem_base->start + |
| 192 | cell->resources[r].end; |
| 193 | } else if (cell->resources[r].flags & IORESOURCE_IRQ) { |
Lee Jones | c94bb23 | 2012-06-29 19:01:03 +0200 | [diff] [blame] | 194 | if (domain) { |
| 195 | /* Unable to create mappings for IRQ ranges. */ |
| 196 | WARN_ON(cell->resources[r].start != |
| 197 | cell->resources[r].end); |
| 198 | res[r].start = res[r].end = irq_create_mapping( |
| 199 | domain, cell->resources[r].start); |
| 200 | } else { |
| 201 | res[r].start = irq_base + |
| 202 | cell->resources[r].start; |
| 203 | res[r].end = irq_base + |
| 204 | cell->resources[r].end; |
| 205 | } |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 206 | } else { |
| 207 | res[r].parent = cell->resources[r].parent; |
| 208 | res[r].start = cell->resources[r].start; |
| 209 | res[r].end = cell->resources[r].end; |
| 210 | } |
Samuel Ortiz | 91feded | 2010-02-19 11:07:59 +0100 | [diff] [blame] | 211 | |
Daniel Drake | 5f2545f | 2010-09-30 21:55:36 +0100 | [diff] [blame] | 212 | if (!cell->ignore_resource_conflicts) { |
Lorenzo Pieralisi | ec40c60 | 2015-05-01 10:41:10 +0100 | [diff] [blame] | 213 | if (has_acpi_companion(&pdev->dev)) { |
| 214 | ret = acpi_check_resource_conflict(&res[r]); |
| 215 | if (ret) |
| 216 | goto fail_alias; |
| 217 | } |
Daniel Drake | 5f2545f | 2010-09-30 21:55:36 +0100 | [diff] [blame] | 218 | } |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Axel Lin | 8af5fe3 | 2010-05-31 17:30:55 +0800 | [diff] [blame] | 221 | ret = platform_device_add_resources(pdev, res, cell->num_resources); |
| 222 | if (ret) |
Charles Keepax | 7fcd427 | 2013-10-15 20:14:21 +0100 | [diff] [blame] | 223 | goto fail_alias; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 224 | |
| 225 | ret = platform_device_add(pdev); |
| 226 | if (ret) |
Charles Keepax | 7fcd427 | 2013-10-15 20:14:21 +0100 | [diff] [blame] | 227 | goto fail_alias; |
Ian Molton | a87903f | 2008-07-25 22:59:29 +0100 | [diff] [blame] | 228 | |
Mark Brown | 4c90aa9 | 2010-11-26 17:19:34 +0000 | [diff] [blame] | 229 | if (cell->pm_runtime_no_callbacks) |
| 230 | pm_runtime_no_callbacks(&pdev->dev); |
| 231 | |
Ian Molton | a87903f | 2008-07-25 22:59:29 +0100 | [diff] [blame] | 232 | kfree(res); |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 233 | |
| 234 | return 0; |
| 235 | |
Charles Keepax | 7fcd427 | 2013-10-15 20:14:21 +0100 | [diff] [blame] | 236 | fail_alias: |
Charles Keepax | d137be0 | 2014-04-24 18:27:25 +0100 | [diff] [blame] | 237 | regulator_bulk_unregister_supply_alias(&pdev->dev, |
| 238 | cell->parent_supplies, |
| 239 | cell->num_parent_supplies); |
Ian Molton | a87903f | 2008-07-25 22:59:29 +0100 | [diff] [blame] | 240 | fail_res: |
| 241 | kfree(res); |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 242 | fail_device: |
| 243 | platform_device_put(pdev); |
| 244 | fail_alloc: |
| 245 | return ret; |
| 246 | } |
| 247 | |
Bartosz Golaszewski | 1946f996 | 2019-04-23 11:04:45 +0200 | [diff] [blame] | 248 | /** |
| 249 | * mfd_add_devices - register child devices |
| 250 | * |
| 251 | * @parent: Pointer to parent device. |
| 252 | * @id: Can be PLATFORM_DEVID_AUTO to let the Platform API take care |
| 253 | * of device numbering, or will be added to a device's cell_id. |
| 254 | * @cells: Array of (struct mfd_cell)s describing child devices. |
| 255 | * @n_devs: Number of child devices to register. |
| 256 | * @mem_base: Parent register range resource for child devices. |
| 257 | * @irq_base: Base of the range of virtual interrupt numbers allocated for |
| 258 | * this MFD device. Unused if @domain is specified. |
| 259 | * @domain: Interrupt domain to create mappings for hardware interrupts. |
| 260 | */ |
Dmitry Baryshkov | 424f525 | 2008-07-29 01:30:26 +0200 | [diff] [blame] | 261 | int mfd_add_devices(struct device *parent, int id, |
Geert Uytterhoeven | 03e361b | 2013-10-29 10:03:04 +0100 | [diff] [blame] | 262 | const struct mfd_cell *cells, int n_devs, |
Ben Dooks | 7f71ac9 | 2008-07-28 18:29:09 +0200 | [diff] [blame] | 263 | struct resource *mem_base, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 264 | int irq_base, struct irq_domain *domain) |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 265 | { |
| 266 | int i; |
Geert Uytterhoeven | 0b208e4 | 2013-10-29 15:47:22 +0100 | [diff] [blame] | 267 | int ret; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 268 | |
| 269 | for (i = 0; i < n_devs; i++) { |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 270 | ret = mfd_add_device(parent, id, cells + i, mem_base, |
Mark Brown | 0848c94 | 2012-09-11 15:16:36 +0800 | [diff] [blame] | 271 | irq_base, domain); |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 272 | if (ret) |
Geert Uytterhoeven | 0b208e4 | 2013-10-29 15:47:22 +0100 | [diff] [blame] | 273 | goto fail; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Geert Uytterhoeven | 0b208e4 | 2013-10-29 15:47:22 +0100 | [diff] [blame] | 276 | return 0; |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 277 | |
Geert Uytterhoeven | 0b208e4 | 2013-10-29 15:47:22 +0100 | [diff] [blame] | 278 | fail: |
| 279 | if (i) |
| 280 | mfd_remove_devices(parent); |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 281 | |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 282 | return ret; |
| 283 | } |
| 284 | EXPORT_SYMBOL(mfd_add_devices); |
| 285 | |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 286 | static int mfd_remove_devices_fn(struct device *dev, void *data) |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 287 | { |
Charles Keepax | b9fbb62 | 2012-11-09 16:15:28 +0000 | [diff] [blame] | 288 | struct platform_device *pdev; |
| 289 | const struct mfd_cell *cell; |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 290 | |
Charles Keepax | b9fbb62 | 2012-11-09 16:15:28 +0000 | [diff] [blame] | 291 | if (dev->type != &mfd_dev_type) |
| 292 | return 0; |
| 293 | |
| 294 | pdev = to_platform_device(dev); |
| 295 | cell = mfd_get_cell(pdev); |
| 296 | |
Charles Keepax | d137be0 | 2014-04-24 18:27:25 +0100 | [diff] [blame] | 297 | regulator_bulk_unregister_supply_alias(dev, cell->parent_supplies, |
| 298 | cell->num_parent_supplies); |
| 299 | |
Andres Salomon | 1e29af6 | 2011-02-17 19:07:34 -0800 | [diff] [blame] | 300 | platform_device_unregister(pdev); |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 301 | return 0; |
| 302 | } |
| 303 | |
Dmitry Baryshkov | 424f525 | 2008-07-29 01:30:26 +0200 | [diff] [blame] | 304 | void mfd_remove_devices(struct device *parent) |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 305 | { |
Lee Jones | 5a47c0f | 2019-10-21 10:47:37 +0100 | [diff] [blame] | 306 | device_for_each_child_reverse(parent, NULL, mfd_remove_devices_fn); |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 307 | } |
| 308 | EXPORT_SYMBOL(mfd_remove_devices); |
| 309 | |
Laxman Dewangan | a8f447be | 2016-04-08 00:12:55 +0530 | [diff] [blame] | 310 | static void devm_mfd_dev_release(struct device *dev, void *res) |
| 311 | { |
| 312 | mfd_remove_devices(dev); |
| 313 | } |
| 314 | |
| 315 | /** |
| 316 | * devm_mfd_add_devices - Resource managed version of mfd_add_devices() |
| 317 | * |
| 318 | * Returns 0 on success or an appropriate negative error number on failure. |
| 319 | * All child-devices of the MFD will automatically be removed when it gets |
| 320 | * unbinded. |
| 321 | */ |
| 322 | int devm_mfd_add_devices(struct device *dev, int id, |
| 323 | const struct mfd_cell *cells, int n_devs, |
| 324 | struct resource *mem_base, |
| 325 | int irq_base, struct irq_domain *domain) |
| 326 | { |
| 327 | struct device **ptr; |
| 328 | int ret; |
| 329 | |
| 330 | ptr = devres_alloc(devm_mfd_dev_release, sizeof(*ptr), GFP_KERNEL); |
| 331 | if (!ptr) |
| 332 | return -ENOMEM; |
| 333 | |
| 334 | ret = mfd_add_devices(dev, id, cells, n_devs, mem_base, |
| 335 | irq_base, domain); |
| 336 | if (ret < 0) { |
| 337 | devres_free(ptr); |
| 338 | return ret; |
| 339 | } |
| 340 | |
| 341 | *ptr = dev; |
| 342 | devres_add(dev, ptr); |
| 343 | |
| 344 | return ret; |
| 345 | } |
| 346 | EXPORT_SYMBOL(devm_mfd_add_devices); |
| 347 | |
Dmitry Baryshkov | aa613de | 2008-06-27 10:37:19 +0100 | [diff] [blame] | 348 | MODULE_LICENSE("GPL"); |
| 349 | MODULE_AUTHOR("Ian Molton, Dmitry Baryshkov"); |