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 struct irq_domain;
16 struct property_entry;
17
18 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
19 struct mfd_cell_acpi_match {
20 const char *pnpid;
21 const unsigned long long adr;
22 };
23
24 /*
25 * This struct describes the MFD part ("cell").
26 * After registration the copy of this structure will become the platform data
27 * of the resulting platform_device
28 */
29 struct mfd_cell {
30 const char *name;
31 int id;
32
33 /* refcounting for multiple drivers to use a single cell */
34 atomic_t *usage_count;
35 int (*enable)(struct platform_device *dev);
36 int (*disable)(struct platform_device *dev);
37
38 int (*suspend)(struct platform_device *dev);
39 int (*resume)(struct platform_device *dev);
40
41 /* platform data passed to the sub devices drivers */
42 void *platform_data;
43 size_t pdata_size;
44
45 /* device properties passed to the sub devices drivers */
46 struct property_entry *properties;
47
48 /*
49 * Device Tree compatible string
50 * See: Documentation/devicetree/usage-model.txt Chapter 2.2 for details
51 */
52 const char *of_compatible;
53
54 /* Matches ACPI */
55 const struct mfd_cell_acpi_match *acpi_match;
56
57 /*
58 * These resources can be specified relative to the parent device.
59 * For accessing hardware you should use resources from the platform dev
60 */
61 int num_resources;
62 const struct resource *resources;
63
64 /* don't check for resource conflicts */
65 bool ignore_resource_conflicts;
66
67 /*
68 * Disable runtime PM callbacks for this subdevice - see
69 * pm_runtime_no_callbacks().
70 */
71 bool pm_runtime_no_callbacks;
72
73 /* A list of regulator supplies that should be mapped to the MFD
74 * device rather than the child device when requested
75 */
76 const char * const *parent_supplies;
77 int num_parent_supplies;
78 };
79
80 /*
81 * Convenience functions for clients using shared cells. Refcounting
82 * happens automatically, with the cell's enable/disable callbacks
83 * being called only when a device is first being enabled or no other
84 * clients are making use of it.
85 */
86 extern int mfd_cell_enable(struct platform_device *pdev);
87 extern int mfd_cell_disable(struct platform_device *pdev);
88
89 /*
90 * "Clone" multiple platform devices for a single cell. This is to be used
91 * for devices that have multiple users of a cell. For example, if an mfd
92 * driver wants the cell "foo" to be used by a GPIO driver, an MTD driver,
93 * and a platform driver, the following bit of code would be use after first
94 * calling mfd_add_devices():
95 *
96 * const char *fclones[] = { "foo-gpio", "foo-mtd" };
97 * err = mfd_clone_cells("foo", fclones, ARRAY_SIZE(fclones));
98 *
99 * Each driver (MTD, GPIO, and platform driver) would then register
100 * platform_drivers for "foo-mtd", "foo-gpio", and "foo", respectively.
101 * The cell's .enable/.disable hooks should be used to deal with hardware
102 * resource contention.
103 */
104 extern int mfd_clone_cell(const char *cell, const char **clones,
105 size_t n_clones);
106
107 /*
108 * Given a platform device that's been created by mfd_add_devices(), fetch
109 * the mfd_cell that created it.
110 */
mfd_get_cell(struct platform_device * pdev)111 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
112 {
113 return pdev->mfd_cell;
114 }
115
116 extern int mfd_add_devices(struct device *parent, int id,
117 const struct mfd_cell *cells, int n_devs,
118 struct resource *mem_base,
119 int irq_base, struct irq_domain *irq_domain);
120
mfd_add_hotplug_devices(struct device * parent,const struct mfd_cell * cells,int n_devs)121 static inline int mfd_add_hotplug_devices(struct device *parent,
122 const struct mfd_cell *cells, int n_devs)
123 {
124 return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
125 NULL, 0, NULL);
126 }
127
128 extern void mfd_remove_devices(struct device *parent);
129
130 extern int devm_mfd_add_devices(struct device *dev, int id,
131 const struct mfd_cell *cells, int n_devs,
132 struct resource *mem_base,
133 int irq_base, struct irq_domain *irq_domain);
134 #endif
135