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 const struct property_entry
*properties
;
76 * Device Tree compatible string
77 * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
79 const char *of_compatible
;
82 * Address as defined in Device Tree. Used to compement 'of_compatible'
83 * (above) when matching OF nodes with devices that have identical
88 /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */
92 const struct mfd_cell_acpi_match
*acpi_match
;
95 * These resources can be specified relative to the parent device.
96 * For accessing hardware you should use resources from the platform dev
99 const struct resource
*resources
;
101 /* don't check for resource conflicts */
102 bool ignore_resource_conflicts
;
105 * Disable runtime PM callbacks for this subdevice - see
106 * pm_runtime_no_callbacks().
108 bool pm_runtime_no_callbacks
;
110 /* A list of regulator supplies that should be mapped to the MFD
111 * device rather than the child device when requested
113 const char * const *parent_supplies
;
114 int num_parent_supplies
;
118 * Convenience functions for clients using shared cells. Refcounting
119 * happens automatically, with the cell's enable/disable callbacks
120 * being called only when a device is first being enabled or no other
121 * clients are making use of it.
123 extern int mfd_cell_enable(struct platform_device
*pdev
);
124 extern int mfd_cell_disable(struct platform_device
*pdev
);
127 * Given a platform device that's been created by mfd_add_devices(), fetch
128 * the mfd_cell that created it.
130 static inline const struct mfd_cell
*mfd_get_cell(struct platform_device
*pdev
)
132 return pdev
->mfd_cell
;
135 extern int mfd_add_devices(struct device
*parent
, int id
,
136 const struct mfd_cell
*cells
, int n_devs
,
137 struct resource
*mem_base
,
138 int irq_base
, struct irq_domain
*irq_domain
);
140 static inline int mfd_add_hotplug_devices(struct device
*parent
,
141 const struct mfd_cell
*cells
, int n_devs
)
143 return mfd_add_devices(parent
, PLATFORM_DEVID_AUTO
, cells
, n_devs
,
147 extern void mfd_remove_devices(struct device
*parent
);
149 extern int devm_mfd_add_devices(struct device
*dev
, int id
,
150 const struct mfd_cell
*cells
, int n_devs
,
151 struct resource
*mem_base
,
152 int irq_base
, struct irq_domain
*irq_domain
);