xref: /linux-6.15/include/linux/mfd/core.h (revision fa52c04d)
1d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2aa613de6SDmitry Baryshkov /*
3aa613de6SDmitry Baryshkov  * drivers/mfd/mfd-core.h
4aa613de6SDmitry Baryshkov  *
5aa613de6SDmitry Baryshkov  * core MFD support
6aa613de6SDmitry Baryshkov  * Copyright (c) 2006 Ian Molton
7aa613de6SDmitry Baryshkov  * Copyright (c) 2007 Dmitry Baryshkov
8aa613de6SDmitry Baryshkov  */
9aa613de6SDmitry Baryshkov 
107f71ac93SBen Dooks #ifndef MFD_CORE_H
117f71ac93SBen Dooks #define MFD_CORE_H
127f71ac93SBen Dooks 
13aa613de6SDmitry Baryshkov #include <linux/platform_device.h>
14aa613de6SDmitry Baryshkov 
15393f05f1SLee Jones #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
16393f05f1SLee Jones 
1744e6171eSLee Jones #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
18393f05f1SLee Jones 	{								\
19393f05f1SLee Jones 		.name = (_name),					\
20393f05f1SLee Jones 		.resources = (_res),					\
21393f05f1SLee Jones 		.num_resources = MFD_RES_SIZE((_res)),			\
22393f05f1SLee Jones 		.platform_data = (_pdata),				\
23393f05f1SLee Jones 		.pdata_size = (_pdsize),				\
24393f05f1SLee Jones 		.of_compatible = (_compat),				\
2544e6171eSLee Jones 		.of_reg = (_of_reg),					\
2644e6171eSLee Jones 		.use_of_reg = (_use_of_reg),				\
27393f05f1SLee Jones 		.acpi_match = (_match),					\
28393f05f1SLee Jones 		.id = (_id),						\
29393f05f1SLee Jones 	}
30393f05f1SLee Jones 
31db783e76SLee Jones #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \
3244e6171eSLee Jones 	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL)
3344e6171eSLee Jones 
34db783e76SLee Jones #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \
3544e6171eSLee Jones 	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL)
36393f05f1SLee Jones 
37db783e76SLee Jones #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \
3844e6171eSLee Jones 	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match)
39393f05f1SLee Jones 
40393f05f1SLee Jones #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
4144e6171eSLee Jones 	MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL)
42393f05f1SLee Jones 
43393f05f1SLee Jones #define MFD_CELL_RES(_name, _res) \
4444e6171eSLee Jones 	MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL)
45393f05f1SLee Jones 
46393f05f1SLee Jones #define MFD_CELL_NAME(_name) \
4744e6171eSLee Jones 	MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL)
48393f05f1SLee Jones 
49114294d2SCharles Keepax #define MFD_DEP_LEVEL_NORMAL 0
50114294d2SCharles Keepax #define MFD_DEP_LEVEL_HIGH 1
51114294d2SCharles Keepax 
520848c94fSMark Brown struct irq_domain;
5342e59982SHeikki Krogerus struct software_node;
540848c94fSMark Brown 
5598a3be44SAndy Shevchenko /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
5698a3be44SAndy Shevchenko struct mfd_cell_acpi_match {
5798a3be44SAndy Shevchenko 	const char			*pnpid;
5898a3be44SAndy Shevchenko 	const unsigned long long	adr;
5998a3be44SAndy Shevchenko };
6098a3be44SAndy Shevchenko 
61aa613de6SDmitry Baryshkov /*
62aa613de6SDmitry Baryshkov  * This struct describes the MFD part ("cell").
63aa613de6SDmitry Baryshkov  * After registration the copy of this structure will become the platform data
64aa613de6SDmitry Baryshkov  * of the resulting platform_device
65aa613de6SDmitry Baryshkov  */
66aa613de6SDmitry Baryshkov struct mfd_cell {
67aa613de6SDmitry Baryshkov 	const char		*name;
683bed6e41SMark Brown 	int			id;
69114294d2SCharles Keepax 	int			level;
70aa613de6SDmitry Baryshkov 
71aa613de6SDmitry Baryshkov 	int			(*suspend)(struct platform_device *dev);
72aa613de6SDmitry Baryshkov 	int			(*resume)(struct platform_device *dev);
73aa613de6SDmitry Baryshkov 
74eb895607SSamuel Ortiz 	/* platform data passed to the sub devices drivers */
75*fa52c04dSHeiko Stuebner 	const void		*platform_data;
76eb895607SSamuel Ortiz 	size_t			pdata_size;
774d215cabSAndy Shevchenko 
7886c6bb0eSChristophe JAILLET 	/* Matches ACPI */
7986c6bb0eSChristophe JAILLET 	const struct mfd_cell_acpi_match	*acpi_match;
8086c6bb0eSChristophe JAILLET 
8142e59982SHeikki Krogerus 	/* Software node for the device. */
8242e59982SHeikki Krogerus 	const struct software_node *swnode;
8342e59982SHeikki Krogerus 
842968ab13SLee Jones 	/*
852968ab13SLee Jones 	 * Device Tree compatible string
86d8e81bc3SMauro Carvalho Chehab 	 * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
872968ab13SLee Jones 	 */
88c94bb233SLee Jones 	const char		*of_compatible;
89eb895607SSamuel Ortiz 
90466a62d7SLee Jones 	/*
9188a32c2cSGeert Uytterhoeven 	 * Address as defined in Device Tree.  Used to complement 'of_compatible'
92466a62d7SLee Jones 	 * (above) when matching OF nodes with devices that have identical
93466a62d7SLee Jones 	 * compatible strings
94466a62d7SLee Jones 	 */
953c70342fSMichał Mirosław 	u64 of_reg;
96466a62d7SLee Jones 
97466a62d7SLee Jones 	/* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */
98466a62d7SLee Jones 	bool use_of_reg;
99466a62d7SLee Jones 
100aa613de6SDmitry Baryshkov 	/*
1012798e226SAndres Salomon 	 * These resources can be specified relative to the parent device.
1022798e226SAndres Salomon 	 * For accessing hardware you should use resources from the platform dev
103aa613de6SDmitry Baryshkov 	 */
104aa613de6SDmitry Baryshkov 	int			num_resources;
105aa613de6SDmitry Baryshkov 	const struct resource	*resources;
1065f2545faSDaniel Drake 
1075f2545faSDaniel Drake 	/* don't check for resource conflicts */
1085f2545faSDaniel Drake 	bool			ignore_resource_conflicts;
1094c90aa94SMark Brown 
1104c90aa94SMark Brown 	/*
1114c90aa94SMark Brown 	 * Disable runtime PM callbacks for this subdevice - see
1124c90aa94SMark Brown 	 * pm_runtime_no_callbacks().
1134c90aa94SMark Brown 	 */
1144c90aa94SMark Brown 	bool			pm_runtime_no_callbacks;
1157fcd4274SCharles Keepax 
1167fcd4274SCharles Keepax 	/* A list of regulator supplies that should be mapped to the MFD
1177fcd4274SCharles Keepax 	 * device rather than the child device when requested
1187fcd4274SCharles Keepax 	 */
1197fcd4274SCharles Keepax 	int			num_parent_supplies;
12086c6bb0eSChristophe JAILLET 	const char * const	*parent_supplies;
121aa613de6SDmitry Baryshkov };
122aa613de6SDmitry Baryshkov 
123fe891a00SAndres Salomon /*
124fe891a00SAndres Salomon  * Given a platform device that's been created by mfd_add_devices(), fetch
125fe891a00SAndres Salomon  * the mfd_cell that created it.
126fe891a00SAndres Salomon  */
mfd_get_cell(struct platform_device * pdev)127fe891a00SAndres Salomon static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
128fe891a00SAndres Salomon {
129e710d7d5SSamuel Ortiz 	return pdev->mfd_cell;
130fe891a00SAndres Salomon }
131fe891a00SAndres Salomon 
132424f525aSDmitry Baryshkov extern int mfd_add_devices(struct device *parent, int id,
13303e361b2SGeert Uytterhoeven 			   const struct mfd_cell *cells, int n_devs,
134aa613de6SDmitry Baryshkov 			   struct resource *mem_base,
1350848c94fSMark Brown 			   int irq_base, struct irq_domain *irq_domain);
136aa613de6SDmitry Baryshkov 
mfd_add_hotplug_devices(struct device * parent,const struct mfd_cell * cells,int n_devs)137a7975473SJohan Hovold static inline int mfd_add_hotplug_devices(struct device *parent,
138a7975473SJohan Hovold 		const struct mfd_cell *cells, int n_devs)
139a7975473SJohan Hovold {
140a7975473SJohan Hovold 	return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
141a7975473SJohan Hovold 			NULL, 0, NULL);
142a7975473SJohan Hovold }
143a7975473SJohan Hovold 
144424f525aSDmitry Baryshkov extern void mfd_remove_devices(struct device *parent);
145114294d2SCharles Keepax extern void mfd_remove_devices_late(struct device *parent);
146aa613de6SDmitry Baryshkov 
147a8f447beSLaxman Dewangan extern int devm_mfd_add_devices(struct device *dev, int id,
148a8f447beSLaxman Dewangan 				const struct mfd_cell *cells, int n_devs,
149a8f447beSLaxman Dewangan 				struct resource *mem_base,
150a8f447beSLaxman Dewangan 				int irq_base, struct irq_domain *irq_domain);
151aa613de6SDmitry Baryshkov #endif
152