| 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, _of_reg, _use_of_reg, _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 | .of_reg = (_of_reg), \ |
| 26 | .use_of_reg = (_use_of_reg), \ |
| 27 | .acpi_match = (_match), \ |
| 28 | .id = (_id), \ |
| 29 | } |
| 30 | |
| 31 | #define MFD_CELL_OF_REG(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg) \ |
| 32 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, _of_reg, true, NULL) |
| 33 | |
| 34 | #define MFD_CELL_OF(_name, _res, _pdata, _pdsize, _id, _compat) \ |
| 35 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, _compat, 0, false, NULL) |
| 36 | |
| 37 | #define MFD_CELL_ACPI(_name, _res, _pdata, _pdsize, _id, _match) \ |
| 38 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, _match) |
| 39 | |
| 40 | #define MFD_CELL_BASIC(_name, _res, _pdata, _pdsize, _id) \ |
| 41 | MFD_CELL_ALL(_name, _res, _pdata, _pdsize, _id, NULL, 0, false, NULL) |
| 42 | |
| 43 | #define MFD_CELL_RES(_name, _res) \ |
| 44 | MFD_CELL_ALL(_name, _res, NULL, 0, 0, NULL, 0, false, NULL) |
| 45 | |
| 46 | #define MFD_CELL_NAME(_name) \ |
| 47 | MFD_CELL_ALL(_name, NULL, NULL, 0, 0, NULL, 0, false, NULL) |
| 48 | |
| 49 | #define MFD_DEP_LEVEL_NORMAL 0 |
| 50 | #define MFD_DEP_LEVEL_HIGH 1 |
| 51 | |
| 52 | struct irq_domain; |
| 53 | struct software_node; |
| 54 | |
| 55 | /* Matches ACPI PNP id, either _HID or _CID, or ACPI _ADR */ |
| 56 | struct mfd_cell_acpi_match { |
| 57 | const char *pnpid; |
| 58 | const unsigned long long adr; |
| 59 | }; |
| 60 | |
| 61 | /* |
| 62 | * This struct describes the MFD part ("cell"). |
| 63 | * After registration the copy of this structure will become the platform data |
| 64 | * of the resulting platform_device |
| 65 | */ |
| 66 | struct mfd_cell { |
| 67 | const char *name; |
| 68 | int id; |
| 69 | int level; |
| 70 | |
| 71 | int (*suspend)(struct platform_device *dev); |
| 72 | int (*resume)(struct platform_device *dev); |
| 73 | |
| 74 | /* platform data passed to the sub devices drivers */ |
| 75 | const void *platform_data; |
| 76 | size_t pdata_size; |
| 77 | |
| 78 | /* Matches ACPI */ |
| 79 | const struct mfd_cell_acpi_match *acpi_match; |
| 80 | |
| 81 | /* Software node for the device. */ |
| 82 | const struct software_node *swnode; |
| 83 | |
| 84 | /* |
| 85 | * Device Tree compatible string |
| 86 | * See: Documentation/devicetree/usage-model.rst Chapter 2.2 for details |
| 87 | */ |
| 88 | const char *of_compatible; |
| 89 | |
| 90 | /* |
| 91 | * Address as defined in Device Tree. Used to complement 'of_compatible' |
| 92 | * (above) when matching OF nodes with devices that have identical |
| 93 | * compatible strings |
| 94 | */ |
| 95 | u64 of_reg; |
| 96 | |
| 97 | /* Set to 'true' to use 'of_reg' (above) - allows for of_reg=0 */ |
| 98 | bool use_of_reg; |
| 99 | |
| 100 | /* |
| 101 | * These resources can be specified relative to the parent device. |
| 102 | * For accessing hardware you should use resources from the platform dev |
| 103 | */ |
| 104 | int num_resources; |
| 105 | const struct resource *resources; |
| 106 | |
| 107 | /* don't check for resource conflicts */ |
| 108 | bool ignore_resource_conflicts; |
| 109 | |
| 110 | /* |
| 111 | * Disable runtime PM callbacks for this subdevice - see |
| 112 | * pm_runtime_no_callbacks(). |
| 113 | */ |
| 114 | bool pm_runtime_no_callbacks; |
| 115 | |
| 116 | /* A list of regulator supplies that should be mapped to the MFD |
| 117 | * device rather than the child device when requested |
| 118 | */ |
| 119 | int num_parent_supplies; |
| 120 | const char * const *parent_supplies; |
| 121 | }; |
| 122 | |
| 123 | /* |
| 124 | * Given a platform device that's been created by mfd_add_devices(), fetch |
| 125 | * the mfd_cell that created it. |
| 126 | */ |
| 127 | static inline const struct mfd_cell *mfd_get_cell(struct platform_device *pdev) |
| 128 | { |
| 129 | return pdev->mfd_cell; |
| 130 | } |
| 131 | |
| 132 | extern int mfd_add_devices(struct device *parent, int id, |
| 133 | const struct mfd_cell *cells, int n_devs, |
| 134 | struct resource *mem_base, |
| 135 | int irq_base, struct irq_domain *irq_domain); |
| 136 | |
| 137 | static inline int mfd_add_hotplug_devices(struct device *parent, |
| 138 | const struct mfd_cell *cells, int n_devs) |
| 139 | { |
| 140 | return mfd_add_devices(parent, PLATFORM_DEVID_AUTO, cells, n_devs, |
| 141 | NULL, 0, NULL); |
| 142 | } |
| 143 | |
| 144 | extern void mfd_remove_devices(struct device *parent); |
| 145 | extern void mfd_remove_devices_late(struct device *parent); |
| 146 | |
| 147 | extern int devm_mfd_add_devices(struct device *dev, int id, |
| 148 | const struct mfd_cell *cells, int n_devs, |
| 149 | struct resource *mem_base, |
| 150 | int irq_base, struct irq_domain *irq_domain); |
| 151 | #endif |