]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - include/linux/mfd/core.h
c437a73b43a3c025400c1af4f122262754cf09b7
[mirror_ubuntu-jammy-kernel.git] / include / linux / mfd / core.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3 * drivers/mfd/mfd-core.h
4 *
5 * core MFD support
6 * Copyright (c) 2006 Ian Molton
7 * Copyright (c) 2007 Dmitry Baryshkov
8 */
9
10 #ifndef MFD_CORE_H
11 #define MFD_CORE_H
12
13 #include <linux/platform_device.h>
14
15 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
16
17 #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _match)\
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), \
25 .acpi_match = (_match), \
26 .id = (_id), \
27 }
28
29 #define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat) \
30 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL) \
31
32 #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match) \
33 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match) \
34
35 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
36 MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL) \
37
38 #define MFD_CELL_RES(_name, _res) \
39 MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL) \
40
41 #define MFD_CELL_NAME(_name) \
42 MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL) \
43
44 struct irq_domain;
45 struct property_entry;
46
47 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
48 struct mfd_cell_acpi_match {
49 const char *pnpid;
50 const unsigned long long adr;
51 };
52
53 /*
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
57 */
58 struct mfd_cell {
59 const char *name;
60 int id;
61
62 int (*enable)(struct platform_device *dev);
63 int (*disable)(struct platform_device *dev);
64
65 int (*suspend)(struct platform_device *dev);
66 int (*resume)(struct platform_device *dev);
67
68 /* platform data passed to the sub devices drivers */
69 void *platform_data;
70 size_t pdata_size;
71
72 /* device properties passed to the sub devices drivers */
73 const struct property_entry *properties;
74
75 /*
76 * Device Tree compatible string
77 * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
78 */
79 const char *of_compatible;
80
81 /*
82 * Address as defined in Device Tree. Used to compement 'of_compatible'
83 * (above) when matching OF nodes with devices that have identical
84 * compatible strings
85 */
86 const u64 of_reg;
87
88 /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */
89 bool use_of_reg;
90
91 /* Matches ACPI */
92 const struct mfd_cell_acpi_match *acpi_match;
93
94 /*
95 * These resources can be specified relative to the parent device.
96 * For accessing hardware you should use resources from the platform dev
97 */
98 int num_resources;
99 const struct resource *resources;
100
101 /* don't check for resource conflicts */
102 bool ignore_resource_conflicts;
103
104 /*
105 * Disable runtime PM callbacks for this subdevice - see
106 * pm_runtime_no_callbacks().
107 */
108 bool pm_runtime_no_callbacks;
109
110 /* A list of regulator supplies that should be mapped to the MFD
111 * device rather than the child device when requested
112 */
113 const char * const *parent_supplies;
114 int num_parent_supplies;
115 };
116
117 /*
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.
122 */
123 extern int mfd_cell_enable(struct platform_device *pdev);
124 extern int mfd_cell_disable(struct platform_device *pdev);
125
126 /*
127 * Given a platform device that's been created by mfd_add_devices(), fetch
128 * the mfd_cell that created it.
129 */
130 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
131 {
132 return pdev->mfd_cell;
133 }
134
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);
139
140 static inline int mfd_add_hotplug_devices(struct device *parent,
141 const struct mfd_cell *cells, int n_devs)
142 {
143 return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
144 NULL, 0, NULL);
145 }
146
147 extern void mfd_remove_devices(struct device *parent);
148
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);
153 #endif