Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Machine interface for the pinctrl subsystem.
0004  *
0005  * Copyright (C) 2011 ST-Ericsson SA
0006  * Written on behalf of Linaro for ST-Ericsson
0007  * Based on bits of regulator core, gpio core and clk core
0008  *
0009  * Author: Linus Walleij <linus.walleij@linaro.org>
0010  */
0011 #ifndef __LINUX_PINCTRL_MACHINE_H
0012 #define __LINUX_PINCTRL_MACHINE_H
0013 
0014 #include <linux/bug.h>
0015 
0016 #include <linux/pinctrl/pinctrl-state.h>
0017 
0018 enum pinctrl_map_type {
0019     PIN_MAP_TYPE_INVALID,
0020     PIN_MAP_TYPE_DUMMY_STATE,
0021     PIN_MAP_TYPE_MUX_GROUP,
0022     PIN_MAP_TYPE_CONFIGS_PIN,
0023     PIN_MAP_TYPE_CONFIGS_GROUP,
0024 };
0025 
0026 /**
0027  * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP
0028  * @group: the name of the group whose mux function is to be configured. This
0029  *  field may be left NULL, and the first applicable group for the function
0030  *  will be used.
0031  * @function: the mux function to select for the group
0032  */
0033 struct pinctrl_map_mux {
0034     const char *group;
0035     const char *function;
0036 };
0037 
0038 /**
0039  * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_*
0040  * @group_or_pin: the name of the pin or group whose configuration parameters
0041  *  are to be configured.
0042  * @configs: a pointer to an array of config parameters/values to program into
0043  *  hardware. Each individual pin controller defines the format and meaning
0044  *  of config parameters.
0045  * @num_configs: the number of entries in array @configs
0046  */
0047 struct pinctrl_map_configs {
0048     const char *group_or_pin;
0049     unsigned long *configs;
0050     unsigned num_configs;
0051 };
0052 
0053 /**
0054  * struct pinctrl_map - boards/machines shall provide this map for devices
0055  * @dev_name: the name of the device using this specific mapping, the name
0056  *  must be the same as in your struct device*. If this name is set to the
0057  *  same name as the pin controllers own dev_name(), the map entry will be
0058  *  hogged by the driver itself upon registration
0059  * @name: the name of this specific map entry for the particular machine.
0060  *  This is the parameter passed to pinmux_lookup_state()
0061  * @type: the type of mapping table entry
0062  * @ctrl_dev_name: the name of the device controlling this specific mapping,
0063  *  the name must be the same as in your struct device*. This field is not
0064  *  used for PIN_MAP_TYPE_DUMMY_STATE
0065  * @data: Data specific to the mapping type
0066  */
0067 struct pinctrl_map {
0068     const char *dev_name;
0069     const char *name;
0070     enum pinctrl_map_type type;
0071     const char *ctrl_dev_name;
0072     union {
0073         struct pinctrl_map_mux mux;
0074         struct pinctrl_map_configs configs;
0075     } data;
0076 };
0077 
0078 /* Convenience macros to create mapping table entries */
0079 
0080 #define PIN_MAP_DUMMY_STATE(dev, state) \
0081     {                               \
0082         .dev_name = dev,                    \
0083         .name = state,                      \
0084         .type = PIN_MAP_TYPE_DUMMY_STATE,           \
0085     }
0086 
0087 #define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func)       \
0088     {                               \
0089         .dev_name = dev,                    \
0090         .name = state,                      \
0091         .type = PIN_MAP_TYPE_MUX_GROUP,             \
0092         .ctrl_dev_name = pinctrl,               \
0093         .data.mux = {                       \
0094             .group = grp,                   \
0095             .function = func,               \
0096         },                          \
0097     }
0098 
0099 #define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func)      \
0100     PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func)
0101 
0102 #define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func)            \
0103     PIN_MAP_MUX_GROUP(dev, state, dev, grp, func)
0104 
0105 #define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func)           \
0106     PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func)
0107 
0108 #define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs)     \
0109     {                               \
0110         .dev_name = dev,                    \
0111         .name = state,                      \
0112         .type = PIN_MAP_TYPE_CONFIGS_PIN,           \
0113         .ctrl_dev_name = pinctrl,               \
0114         .data.configs = {                   \
0115             .group_or_pin = pin,                \
0116             .configs = cfgs,                \
0117             .num_configs = ARRAY_SIZE(cfgs),        \
0118         },                          \
0119     }
0120 
0121 #define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs)        \
0122     PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs)
0123 
0124 #define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs)          \
0125     PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs)
0126 
0127 #define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs)         \
0128     PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs)
0129 
0130 #define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs)       \
0131     {                               \
0132         .dev_name = dev,                    \
0133         .name = state,                      \
0134         .type = PIN_MAP_TYPE_CONFIGS_GROUP,         \
0135         .ctrl_dev_name = pinctrl,               \
0136         .data.configs = {                   \
0137             .group_or_pin = grp,                \
0138             .configs = cfgs,                \
0139             .num_configs = ARRAY_SIZE(cfgs),        \
0140         },                          \
0141     }
0142 
0143 #define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs)      \
0144     PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs)
0145 
0146 #define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs)        \
0147     PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs)
0148 
0149 #define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs)       \
0150     PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs)
0151 
0152 #ifdef CONFIG_PINCTRL
0153 
0154 extern int pinctrl_register_mappings(const struct pinctrl_map *map,
0155                 unsigned num_maps);
0156 extern void pinctrl_unregister_mappings(const struct pinctrl_map *map);
0157 extern void pinctrl_provide_dummies(void);
0158 #else
0159 
0160 static inline int pinctrl_register_mappings(const struct pinctrl_map *map,
0161                        unsigned num_maps)
0162 {
0163     return 0;
0164 }
0165 
0166 static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map)
0167 {
0168 }
0169 
0170 static inline void pinctrl_provide_dummies(void)
0171 {
0172 }
0173 #endif /* !CONFIG_PINCTRL */
0174 #endif