1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 3 * Internal interface between the core pin control system and the 4 * pinmux portions 5 * 6 * Copyright (C) 2011 ST-Ericsson SA 7 * Written on behalf of Linaro for ST-Ericsson 8 * Based on bits of regulator core, gpio core and clk core 9 * 10 * Author: Linus Walleij <linus.walleij@linaro.org> 11 */ 12 13 #include <linux/types.h> 14 15 struct dentry; 16 struct seq_file; 17 18 struct pinctrl_dev; 19 struct pinctrl_gpio_range; 20 struct pinctrl_map; 21 struct pinctrl_setting; 22 23 #ifdef CONFIG_PINMUX 24 25 int pinmux_check_ops(struct pinctrl_dev *pctldev); 26 27 int pinmux_validate_map(const struct pinctrl_map *map, int i); 28 29 bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned int pin); 30 31 int pinmux_request_gpio(struct pinctrl_dev *pctldev, 32 struct pinctrl_gpio_range *range, 33 unsigned int pin, unsigned int gpio); 34 void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned int pin, 35 struct pinctrl_gpio_range *range); 36 int pinmux_gpio_direction(struct pinctrl_dev *pctldev, 37 struct pinctrl_gpio_range *range, 38 unsigned int pin, bool input); 39 40 int pinmux_map_to_setting(const struct pinctrl_map *map, 41 struct pinctrl_setting *setting); 42 void pinmux_free_setting(const struct pinctrl_setting *setting); 43 int pinmux_enable_setting(const struct pinctrl_setting *setting); 44 void pinmux_disable_setting(const struct pinctrl_setting *setting); 45 46 #else 47 48 static inline int pinmux_check_ops(struct pinctrl_dev *pctldev) 49 { 50 return 0; 51 } 52 53 static inline int pinmux_validate_map(const struct pinctrl_map *map, int i) 54 { 55 return 0; 56 } 57 58 static inline bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, 59 unsigned int pin) 60 { 61 return true; 62 } 63 64 static inline int pinmux_request_gpio(struct pinctrl_dev *pctldev, 65 struct pinctrl_gpio_range *range, 66 unsigned int pin, unsigned int gpio) 67 { 68 return 0; 69 } 70 71 static inline void pinmux_free_gpio(struct pinctrl_dev *pctldev, 72 unsigned int pin, 73 struct pinctrl_gpio_range *range) 74 { 75 } 76 77 static inline int pinmux_gpio_direction(struct pinctrl_dev *pctldev, 78 struct pinctrl_gpio_range *range, 79 unsigned int pin, bool input) 80 { 81 return 0; 82 } 83 84 static inline int pinmux_map_to_setting(const struct pinctrl_map *map, 85 struct pinctrl_setting *setting) 86 { 87 return 0; 88 } 89 90 static inline void pinmux_free_setting(const struct pinctrl_setting *setting) 91 { 92 } 93 94 static inline int pinmux_enable_setting(const struct pinctrl_setting *setting) 95 { 96 return 0; 97 } 98 99 static inline void pinmux_disable_setting(const struct pinctrl_setting *setting) 100 { 101 } 102 103 #endif 104 105 #if defined(CONFIG_PINMUX) && defined(CONFIG_DEBUG_FS) 106 107 void pinmux_show_map(struct seq_file *s, const struct pinctrl_map *map); 108 void pinmux_show_setting(struct seq_file *s, 109 const struct pinctrl_setting *setting); 110 void pinmux_init_device_debugfs(struct dentry *devroot, 111 struct pinctrl_dev *pctldev); 112 113 #else 114 115 static inline void pinmux_show_map(struct seq_file *s, 116 const struct pinctrl_map *map) 117 { 118 } 119 120 static inline void pinmux_show_setting(struct seq_file *s, 121 const struct pinctrl_setting *setting) 122 { 123 } 124 125 static inline void pinmux_init_device_debugfs(struct dentry *devroot, 126 struct pinctrl_dev *pctldev) 127 { 128 } 129 130 #endif 131 132 #ifdef CONFIG_GENERIC_PINMUX_FUNCTIONS 133 134 /** 135 * struct function_desc - generic function descriptor 136 * @func: generic data of the pin function (name and groups of pins) 137 * @data: pin controller driver specific data 138 */ 139 struct function_desc { 140 struct pinfunction func; 141 void *data; 142 }; 143 144 /* Convenient macro to define a generic pin function descriptor */ 145 #define PINCTRL_FUNCTION_DESC(_name, _grps, _num_grps, _data) \ 146 (struct function_desc) { \ 147 .func = PINCTRL_PINFUNCTION(_name, _grps, _num_grps), \ 148 .data = _data, \ 149 } 150 151 int pinmux_generic_get_function_count(struct pinctrl_dev *pctldev); 152 153 const char * 154 pinmux_generic_get_function_name(struct pinctrl_dev *pctldev, 155 unsigned int selector); 156 157 int pinmux_generic_get_function_groups(struct pinctrl_dev *pctldev, 158 unsigned int selector, 159 const char * const **groups, 160 unsigned int * const ngroups); 161 162 struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev, 163 unsigned int selector); 164 165 int pinmux_generic_add_function(struct pinctrl_dev *pctldev, 166 const char *name, 167 const char * const *groups, 168 unsigned int const ngroups, 169 void *data); 170 171 int pinmux_generic_remove_function(struct pinctrl_dev *pctldev, 172 unsigned int selector); 173 174 void pinmux_generic_free_functions(struct pinctrl_dev *pctldev); 175 176 #else 177 178 static inline void pinmux_generic_free_functions(struct pinctrl_dev *pctldev) 179 { 180 } 181 182 #endif /* CONFIG_GENERIC_PINMUX_FUNCTIONS */ 183