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, _match)\
20 .resources = (_res), \
21 .num_resources = MFD_RES_SIZE((_res)), \
22 .platform_data = (_pdata), \
23 .pdata_size = (_pdsize), \
24 .of_compatible = (_compat), \
25 .acpi_match = (_match), \
29 #define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat) \
30 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL) \
32 #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match) \
33 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match) \
35 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
36 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL) \
38 #define MFD_CELL_RES(_name, _res) \
39 MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL) \
41 #define MFD_CELL_NAME(_name) \
42 MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL) \
45 struct property_entry;
47 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
48 struct mfd_cell_acpi_match {
50 const unsigned long long adr;
54 * This struct describes the MFD part ("cell").
55 * After registration the copy of this structure will become the platform data
56 * of the resulting platform_device
62 int (*enable)(struct platform_device *dev);
63 int (*disable)(struct platform_device *dev);
65 int (*suspend)(struct platform_device *dev);
66 int (*resume)(struct platform_device *dev);
68 /* platform data passed to the sub devices drivers */
72 /* device properties passed to the sub devices drivers */
73 struct property_entry *properties;
76 * Device Tree compatible string
77 * See: Documentation/devicetree/usage-model.txt Chapter 2.2 for details
79 const char *of_compatible;
82 const struct mfd_cell_acpi_match *acpi_match;
85 * These resources can be specified relative to the parent device.
86 * For accessing hardware you should use resources from the platform dev
89 const struct resource *resources;
91 /* don't check for resource conflicts */
92 bool ignore_resource_conflicts;
95 * Disable runtime PM callbacks for this subdevice - see
96 * pm_runtime_no_callbacks().
98 bool pm_runtime_no_callbacks;
100 /* A list of regulator supplies that should be mapped to the MFD
101 * device rather than the child device when requested
103 const char * const *parent_supplies;
104 int num_parent_supplies;
108 * Convenience functions for clients using shared cells. Refcounting
109 * happens automatically, with the cell's enable/disable callbacks
110 * being called only when a device is first being enabled or no other
111 * clients are making use of it.
113 extern int mfd_cell_enable(struct platform_device *pdev);
114 extern int mfd_cell_disable(struct platform_device *pdev);
117 * Given a platform device that's been created by mfd_add_devices(), fetch
118 * the mfd_cell that created it.
120 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
122 return pdev->mfd_cell;
125 extern int mfd_add_devices(struct device *parent, int id,
126 const struct mfd_cell *cells, int n_devs,
127 struct resource *mem_base,
128 int irq_base, struct irq_domain *irq_domain);
130 static inline int mfd_add_hotplug_devices(struct device *parent,
131 const struct mfd_cell *cells, int n_devs)
133 return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
137 extern void mfd_remove_devices(struct device *parent);
139 extern int devm_mfd_add_devices(struct device *dev, int id,
140 const struct mfd_cell *cells, int n_devs,
141 struct resource *mem_base,
142 int irq_base, struct irq_domain *irq_domain);