linux/include/linux/mfd/core.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0-only */
   2/*
   3 * drivers/mfd/mfd-core.h
   4 *
   5 * core MFD support
   6 * Copyright (c) 2006 Ian Molton
   7 * Copyright (c) 2007 Dmitry Baryshkov
   8 */
   9
  10#ifndef MFD_CORE_H
  11#define MFD_CORE_H
  12
  13#include <linux/platform_device.h>
  14
  15#define MFD_RES_SIZE(arr) (sizeof(arr) / sizeof(struct resource))
  16
  17#define MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _match)\
  18        {                                                               \
  19                .name = (_name),                                        \
  20                .resources = (_res),                                    \
  21                .num_resources = MFD_RES_SIZE((_res)),                  \
  22                .platform_data = (_pdata),                              \
  23                .pdata_size = (_pdsize),                                \
  24                .of_compatible = (_compat),                             \
  25                .acpi_match = (_match),                                 \
  26                .id = (_id),                                            \
  27        }
  28
  29#define OF_MFD_CELL(_name, _res, _pdata, _pdsize,_id, _compat)          \
  30        MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, NULL)  \
  31
  32#define ACPI_MFD_CELL(_name, _res, _pdata, _pdsize, _id, _match)        \
  33        MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, _match)   \
  34
  35#define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id)               \
  36        MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, NULL)     \
  37
  38#define MFD_CELL_RES(_name, _res)                                       \
  39        MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, NULL)               \
  40
  41#define MFD_CELL_NAME(_name)                                            \
  42        MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, NULL)               \
  43
  44struct irq_domain;
  45struct property_entry;
  46
  47/* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */
  48struct mfd_cell_acpi_match {
  49        const char                      *pnpid;
  50        const unsigned long long        adr;
  51};
  52
  53/*
  54 * This struct describes the MFD part ("cell").
  55 * After registration the copy of this structure will become the platform data
  56 * of the resulting platform_device
  57 */
  58struct mfd_cell {
  59        const char              *name;
  60        int                     id;
  61
  62        int                     (*enable)(struct platform_device *dev);
  63        int                     (*disable)(struct platform_device *dev);
  64
  65        int                     (*suspend)(struct platform_device *dev);
  66        int                     (*resume)(struct platform_device *dev);
  67
  68        /* platform data passed to the sub devices drivers */
  69        void                    *platform_data;
  70        size_t                  pdata_size;
  71
  72        /* device properties passed to the sub devices drivers */
  73        const struct property_entry *properties;
  74
  75        /*
  76         * Device Tree compatible string
  77         * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details
  78         */
  79        const char              *of_compatible;
  80
  81        /* Matches ACPI */
  82        const struct mfd_cell_acpi_match        *acpi_match;
  83
  84        /*
  85         * These resources can be specified relative to the parent device.
  86         * For accessing hardware you should use resources from the platform dev
  87         */
  88        int                     num_resources;
  89        const struct resource   *resources;
  90
  91        /* don't check for resource conflicts */
  92        bool                    ignore_resource_conflicts;
  93
  94        /*
  95         * Disable runtime PM callbacks for this subdevice - see
  96         * pm_runtime_no_callbacks().
  97         */
  98        bool                    pm_runtime_no_callbacks;
  99
 100        /* A list of regulator supplies that should be mapped to the MFD
 101         * device rather than the child device when requested
 102         */
 103        const char * const      *parent_supplies;
 104        int                     num_parent_supplies;
 105};
 106
 107/*
 108 * Convenience functions for clients using shared cells.  Refcounting
 109 * happens automatically, with the cell's enable/disable callbacks
 110 * being called only when a device is first being enabled or no other
 111 * clients are making use of it.
 112 */
 113extern int mfd_cell_enable(struct platform_device *pdev);
 114extern int mfd_cell_disable(struct platform_device *pdev);
 115
 116/*
 117 * Given a platform device that's been created by mfd_add_devices(), fetch
 118 * the mfd_cell that created it.
 119 */
 120static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev)
 121{
 122        return pdev->mfd_cell;
 123}
 124
 125extern int mfd_add_devices(struct device *parent, int id,
 126                           const struct mfd_cell *cells, int n_devs,
 127                           struct resource *mem_base,
 128                           int irq_base, struct irq_domain *irq_domain);
 129
 130static inline int mfd_add_hotplug_devices(struct device *parent,
 131                const struct mfd_cell *cells, int n_devs)
 132{
 133        return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs,
 134                        NULL, 0, NULL);
 135}
 136
 137extern void mfd_remove_devices(struct device *parent);
 138
 139extern int devm_mfd_add_devices(struct device *dev, int id,
 140                                const struct mfd_cell *cells, int n_devs,
 141                                struct resource *mem_base,
 142                                int irq_base, struct irq_domain *irq_domain);
 143#endif
 144