1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * drivers/mfd/mfd-core.h
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * core MFD support
6*4882a593Smuzhiyun * Copyright (c) 2006 Ian Molton
7*4882a593Smuzhiyun * Copyright (c) 2007 Dmitry Baryshkov
8*4882a593Smuzhiyun */
9*4882a593Smuzhiyun
10*4882a593Smuzhiyun #ifndef MFD_CORE_H
11*4882a593Smuzhiyun #define MFD_CORE_H
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun #include <linux/platform_device.h>
14*4882a593Smuzhiyun
15*4882a593Smuzhiyun #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
18*4882a593Smuzhiyun { \
19*4882a593Smuzhiyun .name = (_name), \
20*4882a593Smuzhiyun .resources = (_res), \
21*4882a593Smuzhiyun .num_resources = MFD_RES_SIZE((_res)), \
22*4882a593Smuzhiyun .platform_data = (_pdata), \
23*4882a593Smuzhiyun .pdata_size = (_pdsize), \
24*4882a593Smuzhiyun .of_compatible = (_compat), \
25*4882a593Smuzhiyun .of_reg = (_of_reg), \
26*4882a593Smuzhiyun .use_of_reg = (_use_of_reg), \
27*4882a593Smuzhiyun .acpi_match = (_match), \
28*4882a593Smuzhiyun .id = (_id), \
29*4882a593Smuzhiyun }
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun #define OF_MFD_CELL_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \
32*4882a593Smuzhiyun MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL)
33*4882a593Smuzhiyun
34*4882a593Smuzhiyun #define OF_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _compat) \
35*4882a593Smuzhiyun MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL)
36*4882a593Smuzhiyun
37*4882a593Smuzhiyun #define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match) \
38*4882a593Smuzhiyun MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match)
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
41*4882a593Smuzhiyun MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL)
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun #define MFD_CELL_RES(_name, _res) \
44*4882a593Smuzhiyun MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL)
45*4882a593Smuzhiyun
46*4882a593Smuzhiyun #define MFD_CELL_NAME(_name) \
47*4882a593Smuzhiyun MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL)
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun #define MFD_DEP_LEVEL_NORMAL 0
50*4882a593Smuzhiyun #define MFD_DEP_LEVEL_HIGH 1
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun struct irq_domain;
53*4882a593Smuzhiyun struct property_entry;
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
56*4882a593Smuzhiyun struct mfd_cell_acpi_match {
57*4882a593Smuzhiyun const char *pnpid;
58*4882a593Smuzhiyun const unsigned long long adr;
59*4882a593Smuzhiyun };
60*4882a593Smuzhiyun
61*4882a593Smuzhiyun /*
62*4882a593Smuzhiyun * This struct describes the MFD part ("cell").
63*4882a593Smuzhiyun * After registration the copy of this structure will become the platform data
64*4882a593Smuzhiyun * of the resulting platform_device
65*4882a593Smuzhiyun */
66*4882a593Smuzhiyun struct mfd_cell {
67*4882a593Smuzhiyun const char *name;
68*4882a593Smuzhiyun int id;
69*4882a593Smuzhiyun int level;
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun int (*enable)(struct platform_device *dev);
72*4882a593Smuzhiyun int (*disable)(struct platform_device *dev);
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun int (*suspend)(struct platform_device *dev);
75*4882a593Smuzhiyun int (*resume)(struct platform_device *dev);
76*4882a593Smuzhiyun
77*4882a593Smuzhiyun /* platform data passed to the sub devices drivers */
78*4882a593Smuzhiyun void *platform_data;
79*4882a593Smuzhiyun size_t pdata_size;
80*4882a593Smuzhiyun
81*4882a593Smuzhiyun /* device properties passed to the sub devices drivers */
82*4882a593Smuzhiyun const struct property_entry *properties;
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun * Device Tree compatible string
86*4882a593Smuzhiyun * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
87*4882a593Smuzhiyun */
88*4882a593Smuzhiyun const char *of_compatible;
89*4882a593Smuzhiyun
90*4882a593Smuzhiyun /*
91*4882a593Smuzhiyun * Address as defined in Device Tree. Used to compement 'of_compatible'
92*4882a593Smuzhiyun * (above) when matching OF nodes with devices that have identical
93*4882a593Smuzhiyun * compatible strings
94*4882a593Smuzhiyun */
95*4882a593Smuzhiyun const u64 of_reg;
96*4882a593Smuzhiyun
97*4882a593Smuzhiyun /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */
98*4882a593Smuzhiyun bool use_of_reg;
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun /* Matches ACPI */
101*4882a593Smuzhiyun const struct mfd_cell_acpi_match *acpi_match;
102*4882a593Smuzhiyun
103*4882a593Smuzhiyun /*
104*4882a593Smuzhiyun * These resources can be specified relative to the parent device.
105*4882a593Smuzhiyun * For accessing hardware you should use resources from the platform dev
106*4882a593Smuzhiyun */
107*4882a593Smuzhiyun int num_resources;
108*4882a593Smuzhiyun const struct resource *resources;
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun /* don't check for resource conflicts */
111*4882a593Smuzhiyun bool ignore_resource_conflicts;
112*4882a593Smuzhiyun
113*4882a593Smuzhiyun /*
114*4882a593Smuzhiyun * Disable runtime PM callbacks for this subdevice - see
115*4882a593Smuzhiyun * pm_runtime_no_callbacks().
116*4882a593Smuzhiyun */
117*4882a593Smuzhiyun bool pm_runtime_no_callbacks;
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /* A list of regulator supplies that should be mapped to the MFD
120*4882a593Smuzhiyun * device rather than the child device when requested
121*4882a593Smuzhiyun */
122*4882a593Smuzhiyun const char * const *parent_supplies;
123*4882a593Smuzhiyun int num_parent_supplies;
124*4882a593Smuzhiyun };
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun /*
127*4882a593Smuzhiyun * Convenience functions for clients using shared cells. Refcounting
128*4882a593Smuzhiyun * happens automatically, with the cell's enable/disable callbacks
129*4882a593Smuzhiyun * being called only when a device is first being enabled or no other
130*4882a593Smuzhiyun * clients are making use of it.
131*4882a593Smuzhiyun */
132*4882a593Smuzhiyun extern int mfd_cell_enable(struct platform_device *pdev);
133*4882a593Smuzhiyun extern int mfd_cell_disable(struct platform_device *pdev);
134*4882a593Smuzhiyun
135*4882a593Smuzhiyun /*
136*4882a593Smuzhiyun * Given a platform device that's been created by mfd_add_devices(), fetch
137*4882a593Smuzhiyun * the mfd_cell that created it.
138*4882a593Smuzhiyun */
mfd_get_cell(struct platform_device * pdev)139*4882a593Smuzhiyun static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
140*4882a593Smuzhiyun {
141*4882a593Smuzhiyun return pdev->mfd_cell;
142*4882a593Smuzhiyun }
143*4882a593Smuzhiyun
144*4882a593Smuzhiyun extern int mfd_add_devices(struct device *parent, int id,
145*4882a593Smuzhiyun const struct mfd_cell *cells, int n_devs,
146*4882a593Smuzhiyun struct resource *mem_base,
147*4882a593Smuzhiyun int irq_base, struct irq_domain *irq_domain);
148*4882a593Smuzhiyun
mfd_add_hotplug_devices(struct device * parent,const struct mfd_cell * cells,int n_devs)149*4882a593Smuzhiyun static inline int mfd_add_hotplug_devices(struct device *parent,
150*4882a593Smuzhiyun const struct mfd_cell *cells, int n_devs)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
153*4882a593Smuzhiyun NULL, 0, NULL);
154*4882a593Smuzhiyun }
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun extern void mfd_remove_devices(struct device *parent);
157*4882a593Smuzhiyun extern void mfd_remove_devices_late(struct device *parent);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun extern int devm_mfd_add_devices(struct device *dev, int id,
160*4882a593Smuzhiyun const struct mfd_cell *cells, int n_devs,
161*4882a593Smuzhiyun struct resource *mem_base,
162*4882a593Smuzhiyun int irq_base, struct irq_domain *irq_domain);
163*4882a593Smuzhiyun #endif
164