blob: aef23309a742334d9f3fb33d3f3b5af38b7f024d [file] [log] [blame]
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +01001/*
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
Ben Dooks7f71ac92008-07-28 18:29:09 +020014#ifndef MFD_CORE_H
15#define MFD_CORE_H
16
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010017#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 */
24struct mfd_cell {
25 const char *name;
Mark Brown3bed6e42009-07-27 14:45:51 +010026 int id;
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010027
Andres Salomon1e29af62011-02-17 19:07:34 -080028 /* refcounting for multiple drivers to use a single cell */
29 atomic_t *usage_count;
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010030 int (*enable)(struct platform_device *dev);
31 int (*disable)(struct platform_device *dev);
Andres Salomon1e29af62011-02-17 19:07:34 -080032
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010033 int (*suspend)(struct platform_device *dev);
34 int (*resume)(struct platform_device *dev);
35
Andres Salomon65e52352011-02-17 19:07:25 -080036 /* mfd_data can be used to pass data to client drivers */
37 void *mfd_data;
Andres Salomonfe891a02011-02-17 19:07:09 -080038
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010039 /*
Andres Salomon2798e222011-02-17 19:07:08 -080040 * These resources can be specified relative to the parent device.
41 * For accessing hardware you should use resources from the platform dev
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010042 */
43 int num_resources;
44 const struct resource *resources;
Daniel Drake5f2545f2010-09-30 21:55:36 +010045
46 /* don't check for resource conflicts */
47 bool ignore_resource_conflicts;
Mark Brown4c90aa92010-11-26 17:19:34 +000048
49 /*
50 * Disable runtime PM callbacks for this subdevice - see
51 * pm_runtime_no_callbacks().
52 */
53 bool pm_runtime_no_callbacks;
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +010054};
55
Andres Salomonfe891a02011-02-17 19:07:09 -080056/*
Andres Salomon1e29af62011-02-17 19:07:34 -080057 * 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 */
Andres Salomonf77289a2011-03-03 09:51:58 -080062extern int mfd_cell_enable(struct platform_device *pdev);
63extern int mfd_cell_disable(struct platform_device *pdev);
Andres Salomon1e29af62011-02-17 19:07:34 -080064
65/*
Andres Salomonfa1df692011-03-21 19:19:35 -070066 * "Clone" multiple platform devices for a single cell. This is to be used
67 * for devices that have multiple users of a cell. For example, if an mfd
68 * driver wants the cell "foo" to be used by a GPIO driver, an MTD driver,
69 * and a platform driver, the following bit of code would be use after first
70 * calling mfd_add_devices():
71 *
72 * const char *fclones[] = { "foo-gpio", "foo-mtd" };
73 * err = mfd_clone_cells("foo", fclones, ARRAY_SIZE(fclones));
74 *
75 * Each driver (MTD, GPIO, and platform driver) would then register
76 * platform_drivers for "foo-mtd", "foo-gpio", and "foo", respectively.
77 * The cell's .enable/.disable hooks should be used to deal with hardware
78 * resource contention.
79 */
80extern int mfd_clone_cell(const char *cell, const char **clones,
81 size_t n_clones);
82
83/*
Andres Salomonfe891a02011-02-17 19:07:09 -080084 * Given a platform device that's been created by mfd_add_devices(), fetch
85 * the mfd_cell that created it.
86 */
87static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
88{
Samuel Ortize710d7d2011-04-08 00:43:01 +020089 return pdev->mfd_cell;
Andres Salomonfe891a02011-02-17 19:07:09 -080090}
91
92/*
93 * Given a platform device that's been created by mfd_add_devices(), fetch
Andres Salomon65e52352011-02-17 19:07:25 -080094 * the .mfd_data entry from the mfd_cell that created it.
Samuel Ortize710d7d2011-04-08 00:43:01 +020095 * Otherwise just return the platform_data pointer.
96 * This maintains compatibility with platform drivers whose devices aren't
97 * created by the mfd layer, and expect platform_data to contain what would've
98 * otherwise been in mfd_data.
Andres Salomonfe891a02011-02-17 19:07:09 -080099 */
100static inline void *mfd_get_data(struct platform_device *pdev)
101{
Samuel Ortize710d7d2011-04-08 00:43:01 +0200102 const struct mfd_cell *cell = mfd_get_cell(pdev);
103
104 if (cell)
105 return cell->mfd_data;
106 else
107 return pdev->dev.platform_data;
Andres Salomonfe891a02011-02-17 19:07:09 -0800108}
109
Dmitry Baryshkov424f5252008-07-29 01:30:26 +0200110extern int mfd_add_devices(struct device *parent, int id,
Andres Salomon1e29af62011-02-17 19:07:34 -0800111 struct mfd_cell *cells, int n_devs,
Ben Dooks7f71ac92008-07-28 18:29:09 +0200112 struct resource *mem_base,
113 int irq_base);
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +0100114
Dmitry Baryshkov424f5252008-07-29 01:30:26 +0200115extern void mfd_remove_devices(struct device *parent);
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +0100116
Dmitry Baryshkovaa613de2008-06-27 10:37:19 +0100117#endif