2 * drivers/mfd/mfd-core.h
5 * Copyright (c) 2006 Ian Molton
6 * Copyright (c) 2007 Dmitry Baryshkov
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
17 #include <linux/platform_device.h>
19 #define MFD_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
21 #define MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, _match) \
24 .resources = (_res), \
25 .num_resources = MFD_ARRAY_SIZE((_res)), \
26 .platform_data = (_pdata), \
27 .pdata_size = MFD_ARRAY_SIZE((_pdata)), \
28 .of_compatible = (_compat), \
29 .acpi_match = (_match), \
33 #define OF_MFD_CELL(_name, _res, _pdata, _id, _compat) \
34 MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, NULL) \
36 #define ACPI_MFD_CELL(_name, _res, _pdata, _id, _match) \
37 MFD_CELL_ALL(_name, _res, _pdata, _id, NULL, _match) \
39 #define MFD_CELL_BASIC(_name, _res, _pdata, _id) \
40 MFD_CELL_ALL(_name, _res, _pdata, _id, NULL, NULL) \
42 #define MFD_CELL_NAME(_name) \
43 MFD_CELL_ALL(_name, NULL, NULL, 0, NULL, NULL) \
48 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
49 struct mfd_cell_acpi_match {
51 const unsigned long long adr;
55 * This struct describes the MFD part ("cell").
56 * After registration the copy of this structure will become the platform data
57 * of the resulting platform_device
63 /* refcounting for multiple drivers to use a single cell */
64 atomic_t *usage_count;
65 int (*enable)(struct platform_device *dev);
66 int (*disable)(struct platform_device *dev);
68 int (*suspend)(struct platform_device *dev);
69 int (*resume)(struct platform_device *dev);
71 /* platform data passed to the sub devices drivers */
75 /* device properties passed to the sub devices drivers */
76 const struct property_set *pset;
79 * Device Tree compatible string
80 * See: Documentation/devicetree/usage-model.txt Chapter 2.2 for details
82 const char *of_compatible;
85 const struct mfd_cell_acpi_match *acpi_match;
88 * These resources can be specified relative to the parent device.
89 * For accessing hardware you should use resources from the platform dev
92 const struct resource *resources;
94 /* don't check for resource conflicts */
95 bool ignore_resource_conflicts;
98 * Disable runtime PM callbacks for this subdevice - see
99 * pm_runtime_no_callbacks().
101 bool pm_runtime_no_callbacks;
103 /* A list of regulator supplies that should be mapped to the MFD
104 * device rather than the child device when requested
106 const char * const *parent_supplies;
107 int num_parent_supplies;
111 * Convenience functions for clients using shared cells. Refcounting
112 * happens automatically, with the cell's enable/disable callbacks
113 * being called only when a device is first being enabled or no other
114 * clients are making use of it.
116 extern int mfd_cell_enable(struct platform_device *pdev);
117 extern int mfd_cell_disable(struct platform_device *pdev);
120 * "Clone" multiple platform devices for a single cell. This is to be used
121 * for devices that have multiple users of a cell. For example, if an mfd
122 * driver wants the cell "foo" to be used by a GPIO driver, an MTD driver,
123 * and a platform driver, the following bit of code would be use after first
124 * calling mfd_add_devices():
126 * const char *fclones[] = { "foo-gpio", "foo-mtd" };
127 * err = mfd_clone_cells("foo", fclones, ARRAY_SIZE(fclones));
129 * Each driver (MTD, GPIO, and platform driver) would then register
130 * platform_drivers for "foo-mtd", "foo-gpio", and "foo", respectively.
131 * The cell's .enable/.disable hooks should be used to deal with hardware
132 * resource contention.
134 extern int mfd_clone_cell(const char *cell, const char **clones,
138 * Given a platform device that's been created by mfd_add_devices(), fetch
139 * the mfd_cell that created it.
141 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
143 return pdev->mfd_cell;
146 extern int mfd_add_devices(struct device *parent, int id,
147 const struct mfd_cell *cells, int n_devs,
148 struct resource *mem_base,
149 int irq_base, struct irq_domain *irq_domain);
151 static inline int mfd_add_hotplug_devices(struct device *parent,
152 const struct mfd_cell *cells, int n_devs)
154 return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
158 extern void mfd_remove_devices(struct device *parent);