]> git.karo-electronics.de Git - karo-tx-linux.git/blob - include/linux/mfd/core.h
Merge remote-tracking branch 'tty/tty-next'
[karo-tx-linux.git] / include / linux / mfd / core.h
1 /*
2  * drivers/mfd/mfd-core.h
3  *
4  * core MFD support
5  * Copyright (c) 2006 Ian Molton
6  * Copyright (c) 2007 Dmitry Baryshkov
7  *
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.
11  *
12  */
13
14 #ifndef MFD_CORE_H
15 #define MFD_CORE_H
16
17 #include <linux/platform_device.h>
18
19 #define MFD_ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
20
21 #define MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, _match)         \
22         {                                                               \
23                 .name = (_name),                                        \
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),                                 \
30                 .id = _id,                                              \
31         }
32
33 #define OF_MFD_CELL(_name, _res, _pdata, _id, _compat)                  \
34                 MFD_CELL_ALL(_name, _res, _pdata, _id, _compat, NULL)   \
35
36 #define ACPI_MFD_CELL(_name, _res, _pdata, _id, _match)                 \
37                 MFD_CELL_ALL(_name, _res, _pdata, _id, NULL, _match)    \
38
39 #define MFD_CELL_BASIC(_name, _res, _pdata, _id)                        \
40                 MFD_CELL_ALL(_name, _res, _pdata, _id, NULL, NULL)      \
41
42 #define MFD_CELL_NAME(_name)                                            \
43                 MFD_CELL_ALL(_name, NULL, NULL, 0, NULL, NULL)          \
44
45 struct irq_domain;
46 struct property_set;
47
48 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
49 struct mfd_cell_acpi_match {
50         const char                      *pnpid;
51         const unsigned long long        adr;
52 };
53
54 /*
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
58  */
59 struct mfd_cell {
60         const char              *name;
61         int                     id;
62
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);
67
68         int                     (*suspend)(struct platform_device *dev);
69         int                     (*resume)(struct platform_device *dev);
70
71         /* platform data passed to the sub devices drivers */
72         void                    *platform_data;
73         size_t                  pdata_size;
74
75         /* device properties passed to the sub devices drivers */
76         const struct property_set *pset;
77
78         /*
79          * Device Tree compatible string
80          * See: Documentation/devicetree/usage-model.txt Chapter 2.2 for details
81          */
82         const char              *of_compatible;
83
84         /* Matches ACPI */
85         const struct mfd_cell_acpi_match        *acpi_match;
86
87         /*
88          * These resources can be specified relative to the parent device.
89          * For accessing hardware you should use resources from the platform dev
90          */
91         int                     num_resources;
92         const struct resource   *resources;
93
94         /* don't check for resource conflicts */
95         bool                    ignore_resource_conflicts;
96
97         /*
98          * Disable runtime PM callbacks for this subdevice - see
99          * pm_runtime_no_callbacks().
100          */
101         bool                    pm_runtime_no_callbacks;
102
103         /* A list of regulator supplies that should be mapped to the MFD
104          * device rather than the child device when requested
105          */
106         const char * const      *parent_supplies;
107         int                     num_parent_supplies;
108 };
109
110 /*
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.
115  */
116 extern int mfd_cell_enable(struct platform_device *pdev);
117 extern int mfd_cell_disable(struct platform_device *pdev);
118
119 /*
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():
125  *
126  * const char *fclones[] = { "foo-gpio", "foo-mtd" };
127  * err = mfd_clone_cells("foo", fclones, ARRAY_SIZE(fclones));
128  *
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.
133  */
134 extern int mfd_clone_cell(const char *cell, const char **clones,
135                 size_t n_clones);
136
137 /*
138  * Given a platform device that's been created by mfd_add_devices(), fetch
139  * the mfd_cell that created it.
140  */
141 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
142 {
143         return pdev->mfd_cell;
144 }
145
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);
150
151 static inline int mfd_add_hotplug_devices(struct device *parent,
152                 const struct mfd_cell *cells, int n_devs)
153 {
154         return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
155                         NULL, 0, NULL);
156 }
157
158 extern void mfd_remove_devices(struct device *parent);
159
160 #endif