Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * drivers/mfd/mfd-core.h
0004  *
0005  * core MFD support
0006  * Copyright (c) 2006 Ian Molton
0007  * Copyright (c) 2007 Dmitry Baryshkov
0008  */
0009 
0010 #ifndef MFD_CORE_H
0011 #define MFD_CORE_H
0012 
0013 #include <linux/platform_device.h>
0014 
0015 #define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
0016 
0017 #define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, _use_of_reg, _match) \
0018     {                               \
0019         .name = (_name),                    \
0020         .resources = (_res),                    \
0021         .num_resources = MFD_RES_SIZE((_res)),          \
0022         .platform_data = (_pdata),              \
0023         .pdata_size = (_pdsize),                \
0024         .of_compatible = (_compat),             \
0025         .of_reg = (_of_reg),                    \
0026         .use_of_reg = (_use_of_reg),                \
0027         .acpi_match = (_match),                 \
0028         .id = (_id),                        \
0029     }
0030 
0031 #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \
0032     MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL)
0033 
0034 #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \
0035     MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL)
0036 
0037 #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \
0038     MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match)
0039 
0040 #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \
0041     MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL)
0042 
0043 #define MFD_CELL_RES(_name, _res) \
0044     MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL)
0045 
0046 #define MFD_CELL_NAME(_name) \
0047     MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL)
0048 
0049 #define MFD_DEP_LEVEL_NORMAL 0
0050 #define MFD_DEP_LEVEL_HIGH 1
0051 
0052 struct irq_domain;
0053 struct software_node;
0054 
0055 /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
0056 struct mfd_cell_acpi_match {
0057     const char          *pnpid;
0058     const unsigned long long    adr;
0059 };
0060 
0061 /*
0062  * This struct describes the MFD part ("cell").
0063  * After registration the copy of this structure will become the platform data
0064  * of the resulting platform_device
0065  */
0066 struct mfd_cell {
0067     const char      *name;
0068     int         id;
0069     int         level;
0070 
0071     int         (*enable)(struct platform_device *dev);
0072     int         (*disable)(struct platform_device *dev);
0073 
0074     int         (*suspend)(struct platform_device *dev);
0075     int         (*resume)(struct platform_device *dev);
0076 
0077     /* platform data passed to the sub devices drivers */
0078     void            *platform_data;
0079     size_t          pdata_size;
0080 
0081     /* Software node for the device. */
0082     const struct software_node *swnode;
0083 
0084     /*
0085      * Device Tree compatible string
0086      * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
0087      */
0088     const char      *of_compatible;
0089 
0090     /*
0091      * Address as defined in Device Tree.  Used to compement 'of_compatible'
0092      * (above) when matching OF nodes with devices that have identical
0093      * compatible strings
0094      */
0095     const u64 of_reg;
0096 
0097     /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */
0098     bool use_of_reg;
0099 
0100     /* Matches ACPI */
0101     const struct mfd_cell_acpi_match    *acpi_match;
0102 
0103     /*
0104      * These resources can be specified relative to the parent device.
0105      * For accessing hardware you should use resources from the platform dev
0106      */
0107     int         num_resources;
0108     const struct resource   *resources;
0109 
0110     /* don't check for resource conflicts */
0111     bool            ignore_resource_conflicts;
0112 
0113     /*
0114      * Disable runtime PM callbacks for this subdevice - see
0115      * pm_runtime_no_callbacks().
0116      */
0117     bool            pm_runtime_no_callbacks;
0118 
0119     /* A list of regulator supplies that should be mapped to the MFD
0120      * device rather than the child device when requested
0121      */
0122     const char * const  *parent_supplies;
0123     int         num_parent_supplies;
0124 };
0125 
0126 /*
0127  * Convenience functions for clients using shared cells.  Refcounting
0128  * happens automatically, with the cell's enable/disable callbacks
0129  * being called only when a device is first being enabled or no other
0130  * clients are making use of it.
0131  */
0132 extern int mfd_cell_enable(struct platform_device *pdev);
0133 extern int mfd_cell_disable(struct platform_device *pdev);
0134 
0135 /*
0136  * Given a platform device that's been created by mfd_add_devices(), fetch
0137  * the mfd_cell that created it.
0138  */
0139 static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
0140 {
0141     return pdev->mfd_cell;
0142 }
0143 
0144 extern int mfd_add_devices(struct device *parent, int id,
0145                const struct mfd_cell *cells, int n_devs,
0146                struct resource *mem_base,
0147                int irq_base, struct irq_domain *irq_domain);
0148 
0149 static inline int mfd_add_hotplug_devices(struct device *parent,
0150         const struct mfd_cell *cells, int n_devs)
0151 {
0152     return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
0153             NULL, 0, NULL);
0154 }
0155 
0156 extern void mfd_remove_devices(struct device *parent);
0157 extern void mfd_remove_devices_late(struct device *parent);
0158 
0159 extern int devm_mfd_add_devices(struct device *dev, int id,
0160                 const struct mfd_cell *cells, int n_devs,
0161                 struct resource *mem_base,
0162                 int irq_base, struct irq_domain *irq_domain);
0163 #endif