Merge git://git.kernel.org/pub/scm/linux/kernel/git/agk/linux-2.6-dm
[pandora-kernel.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 /*
20  * This struct describes the MFD part ("cell").
21  * After registration the copy of this structure will become the platform data
22  * of the resulting platform_device
23  */
24 struct mfd_cell {
25         const char              *name;
26         int                     id;
27
28         /* refcounting for multiple drivers to use a single cell */
29         atomic_t                *usage_count;
30         int                     (*enable)(struct platform_device *dev);
31         int                     (*disable)(struct platform_device *dev);
32
33         int                     (*suspend)(struct platform_device *dev);
34         int                     (*resume)(struct platform_device *dev);
35
36         /* mfd_data can be used to pass data to client drivers */
37         void                    *mfd_data;
38
39         /*
40          * These resources can be specified relative to the parent device.
41          * For accessing hardware you should use resources from the platform dev
42          */
43         int                     num_resources;
44         const struct resource   *resources;
45
46         /* don't check for resource conflicts */
47         bool                    ignore_resource_conflicts;
48
49         /*
50          * Disable runtime PM callbacks for this subdevice - see
51          * pm_runtime_no_callbacks().
52          */
53         bool                    pm_runtime_no_callbacks;
54 };
55
56 /*
57  * Convenience functions for clients using shared cells.  Refcounting
58  * happens automatically, with the cell's enable/disable callbacks
59  * being called only when a device is first being enabled or no other
60  * clients are making use of it.
61  */
62 extern int mfd_cell_enable(struct platform_device *pdev);
63 extern int mfd_cell_disable(struct platform_device *pdev);
64
65 /*
66  * Given a platform device that's been created by mfd_add_devices(), fetch
67  * the mfd_cell that created it.
68  */
69 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
70 {
71         return pdev->dev.platform_data;
72 }
73
74 /*
75  * Given a platform device that's been created by mfd_add_devices(), fetch
76  * the .mfd_data entry from the mfd_cell that created it.
77  */
78 static inline void *mfd_get_data(struct platform_device *pdev)
79 {
80         return mfd_get_cell(pdev)->mfd_data;
81 }
82
83 extern int mfd_add_devices(struct device *parent, int id,
84                            struct mfd_cell *cells, int n_devs,
85                            struct resource *mem_base,
86                            int irq_base);
87
88 extern void mfd_remove_devices(struct device *parent);
89
90 /*
91  * For MFD drivers with clients sharing access to resources, these create
92  * multiple platform devices per cell.  Contention handling must still be
93  * handled via drivers (ie, with enable/disable hooks).
94  */
95 extern int mfd_shared_platform_driver_register(struct platform_driver *drv,
96                 const char *cellname);
97 extern void mfd_shared_platform_driver_unregister(struct platform_driver *drv);
98
99 #endif