1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * drivers/mfd/mfd-core.h
6 * Copyright (c) 2006 Ian Molton
7 * Copyright (c) 2007 Dmitry Baryshkov
13 #include <linux/platform_device.h>
15 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
17 #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
20 .resources = (_res), \
21 .num_resources = MFD_RES_SIZE((_res)), \
22 .platform_data = (_pdata), \
23 .pdata_size = (_pdsize), \
24 .of_compatible = (_compat), \
25 .of_reg = (_of_reg), \
26 .use_of_reg = (_use_of_reg), \
27 .acpi_match = (_match), \
31 #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \
32 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL)
34 #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \
35 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL)
37 #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \
38 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match)
40 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
41 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL)
43 #define MFD_CELL_RES(_name, _res) \
44 MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL)
46 #define MFD_CELL_NAME(_name) \
47 MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL)
49 #define MFD_DEP_LEVEL_NORMAL 0
50 #define MFD_DEP_LEVEL_HIGH 1
55 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
56 struct mfd_cell_acpi_match {
58 const unsigned long long adr;
62 * This struct describes the MFD part ("cell").
63 * After registration the copy of this structure will become the platform data
64 * of the resulting platform_device
71 int (*enable)(struct platform_device *dev);
72 int (*disable)(struct platform_device *dev);
74 int (*suspend)(struct platform_device *dev);
75 int (*resume)(struct platform_device *dev);
77 /* platform data passed to the sub devices drivers */
81 /* Software node for the device. */
82 const struct software_node *swnode;
85 * Device Tree compatible string
86 * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
88 const char *of_compatible;
91 * Address as defined in Device Tree. Used to compement 'of_compatible'
92 * (above) when matching OF nodes with devices that have identical
97 /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */
101 const struct mfd_cell_acpi_match *acpi_match;
104 * These resources can be specified relative to the parent device.
105 * For accessing hardware you should use resources from the platform dev
108 const struct resource *resources;
110 /* don't check for resource conflicts */
111 bool ignore_resource_conflicts;
114 * Disable runtime PM callbacks for this subdevice - see
115 * pm_runtime_no_callbacks().
117 bool pm_runtime_no_callbacks;
119 /* A list of regulator supplies that should be mapped to the MFD
120 * device rather than the child device when requested
122 const char * const *parent_supplies;
123 int num_parent_supplies;
127 * Convenience functions for clients using shared cells. Refcounting
128 * happens automatically, with the cell's enable/disable callbacks
129 * being called only when a device is first being enabled or no other
130 * clients are making use of it.
132 extern int mfd_cell_enable(struct platform_device *pdev);
133 extern int mfd_cell_disable(struct platform_device *pdev);
136 * Given a platform device that's been created by mfd_add_devices(), fetch
137 * the mfd_cell that created it.
139 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
141 return pdev->mfd_cell;
144 extern int mfd_add_devices(struct device *parent, int id,
145 const struct mfd_cell *cells, int n_devs,
146 struct resource *mem_base,
147 int irq_base, struct irq_domain *irq_domain);
149 static inline int mfd_add_hotplug_devices(struct device *parent,
150 const struct mfd_cell *cells, int n_devs)
152 return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
156 extern void mfd_remove_devices(struct device *parent);
157 extern void mfd_remove_devices_late(struct device *parent);
159 extern int devm_mfd_add_devices(struct device *dev, int id,
160 const struct mfd_cell *cells, int n_devs,
161 struct resource *mem_base,
162 int irq_base, struct irq_domain *irq_domain);