Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
aa613de6 DB |
2 | /* |
3 | * drivers/mfd/mfd-core.h | |
4 | * | |
5 | * core MFD support | |
6 | * Copyright (c) 2006 Ian Molton | |
7 | * Copyright (c) 2007 Dmitry Baryshkov | |
aa613de6 DB |
8 | */ |
9 | ||
7f71ac93 BD |
10 | #ifndef MFD_CORE_H |
11 | #define MFD_CORE_H | |
12 | ||
aa613de6 DB |
13 | #include <linux/platform_device.h> |
14 | ||
393f05f1 LJ |
15 | #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource)) |
16 | ||
44e6171e | 17 | #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \ |
393f05f1 LJ |
18 | { \ |
19 | .name = (_name), \ | |
20 | .resources = (_res), \ | |
21 | .num_resources = MFD_RES_SIZE((_res)), \ | |
22 | .platform_data = (_pdata), \ | |
23 | .pdata_size = (_pdsize), \ | |
24 | .of_compatible = (_compat), \ | |
44e6171e LJ |
25 | .of_reg = (_of_reg), \ |
26 | .use_of_reg = (_use_of_reg), \ | |
393f05f1 LJ |
27 | .acpi_match = (_match), \ |
28 | .id = (_id), \ | |
29 | } | |
30 | ||
db783e76 | 31 | #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \ |
44e6171e LJ |
32 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL) |
33 | ||
db783e76 | 34 | #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \ |
44e6171e | 35 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL) |
393f05f1 | 36 | |
db783e76 | 37 | #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \ |
44e6171e | 38 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match) |
393f05f1 | 39 | |
d097965b | 40 | #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \ |
44e6171e | 41 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL) |
393f05f1 | 42 | |
d097965b | 43 | #define MFD_CELL_RES(_name, _res) \ |
44e6171e | 44 | MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL) |
393f05f1 | 45 | |
d097965b | 46 | #define MFD_CELL_NAME(_name) \ |
44e6171e | 47 | MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL) |
393f05f1 | 48 | |
114294d2 CK |
49 | #define MFD_DEP_LEVEL_NORMAL 0 |
50 | #define MFD_DEP_LEVEL_HIGH 1 | |
51 | ||
0848c94f | 52 | struct irq_domain; |
42e59982 | 53 | struct software_node; |
0848c94f | 54 | |
98a3be44 AS |
55 | /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */ |
56 | struct mfd_cell_acpi_match { | |
57 | const char *pnpid; | |
58 | const unsigned long long adr; | |
59 | }; | |
60 | ||
aa613de6 DB |
61 | /* |
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 | |
65 | */ | |
66 | struct mfd_cell { | |
67 | const char *name; | |
3bed6e41 | 68 | int id; |
114294d2 | 69 | int level; |
aa613de6 | 70 | |
aa613de6 DB |
71 | int (*suspend)(struct platform_device *dev); |
72 | int (*resume)(struct platform_device *dev); | |
73 | ||
eb895607 SO |
74 | /* platform data passed to the sub devices drivers */ |
75 | void *platform_data; | |
76 | size_t pdata_size; | |
4d215cab | 77 | |
86c6bb0e CJ |
78 | /* Matches ACPI */ |
79 | const struct mfd_cell_acpi_match *acpi_match; | |
80 | ||
42e59982 HK |
81 | /* Software node for the device. */ |
82 | const struct software_node *swnode; | |
83 | ||
2968ab13 LJ |
84 | /* |
85 | * Device Tree compatible string | |
d8e81bc3 | 86 | * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details |
2968ab13 | 87 | */ |
c94bb233 | 88 | const char *of_compatible; |
eb895607 | 89 | |
466a62d7 | 90 | /* |
88a32c2c | 91 | * Address as defined in Device Tree. Used to complement 'of_compatible' |
466a62d7 LJ |
92 | * (above) when matching OF nodes with devices that have identical |
93 | * compatible strings | |
94 | */ | |
95 | const u64 of_reg; | |
96 | ||
97 | /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */ | |
98 | bool use_of_reg; | |
99 | ||
aa613de6 | 100 | /* |
2798e226 AS |
101 | * These resources can be specified relative to the parent device. |
102 | * For accessing hardware you should use resources from the platform dev | |
aa613de6 DB |
103 | */ |
104 | int num_resources; | |
105 | const struct resource *resources; | |
5f2545fa DD |
106 | |
107 | /* don't check for resource conflicts */ | |
108 | bool ignore_resource_conflicts; | |
4c90aa94 MB |
109 | |
110 | /* | |
111 | * Disable runtime PM callbacks for this subdevice - see | |
112 | * pm_runtime_no_callbacks(). | |
113 | */ | |
114 | bool pm_runtime_no_callbacks; | |
7fcd4274 CK |
115 | |
116 | /* A list of regulator supplies that should be mapped to the MFD | |
117 | * device rather than the child device when requested | |
118 | */ | |
7fcd4274 | 119 | int num_parent_supplies; |
86c6bb0e | 120 | const char * const *parent_supplies; |
aa613de6 DB |
121 | }; |
122 | ||
fe891a00 AS |
123 | /* |
124 | * Given a platform device that's been created by mfd_add_devices(), fetch | |
125 | * the mfd_cell that created it. | |
126 | */ | |
127 | static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev) | |
128 | { | |
e710d7d5 | 129 | return pdev->mfd_cell; |
fe891a00 AS |
130 | } |
131 | ||
424f525a | 132 | extern int mfd_add_devices(struct device *parent, int id, |
03e361b2 | 133 | const struct mfd_cell *cells, int n_devs, |
7f71ac93 | 134 | struct resource *mem_base, |
0848c94f | 135 | int irq_base, struct irq_domain *irq_domain); |
aa613de6 | 136 | |
a7975473 JH |
137 | static inline int mfd_add_hotplug_devices(struct device *parent, |
138 | const struct mfd_cell *cells, int n_devs) | |
139 | { | |
140 | return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs, | |
141 | NULL, 0, NULL); | |
142 | } | |
143 | ||
424f525a | 144 | extern void mfd_remove_devices(struct device *parent); |
114294d2 | 145 | extern void mfd_remove_devices_late(struct device *parent); |
aa613de6 | 146 | |
a8f447be LD |
147 | extern int devm_mfd_add_devices(struct device *dev, int id, |
148 | const struct mfd_cell *cells, int n_devs, | |
149 | struct resource *mem_base, | |
150 | int irq_base, struct irq_domain *irq_domain); | |
aa613de6 | 151 | #endif |