tree: https://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio.git gpio-descriptors-regulator head: a86195a2886ae58b7ad7499c8d3efeb9f5329ed4 commit: b123f987107a01c8deb3afeef0b3321e6af07da1 [4/8] regulator: fixed/gpio: Pull inversion/OD into gpiolib config: i386-randconfig-x077-201835 (attached as .config) compiler: gcc-7 (Debian 7.3.0-16) 7.3.0 reproduce: git checkout b123f987107a01c8deb3afeef0b3321e6af07da1 # save the attached .config to linux build tree make ARCH=i386 Note: the gpio/gpio-descriptors-regulator HEAD a86195a2886ae58b7ad7499c8d3efeb9f5329ed4 builds fine. It only hurts bisectibility. All error/warnings (new ones prefixed by >>): drivers/regulator/gpio-regulator.c: In function 'of_get_gpio_regulator_config': >> drivers/regulator/gpio-regulator.c:161:8: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); ^~ In file included from include/linux/err.h:5:0, from drivers/regulator/gpio-regulator.c:25: drivers/regulator/gpio-regulator.c:162:12: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^ include/linux/compiler.h:58:30: note: in definition of macro '__trace_if' if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ ^~~~ >> drivers/regulator/gpio-regulator.c:162:2: note: in expansion of macro 'if' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^~ drivers/regulator/gpio-regulator.c:162:39: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^ include/linux/compiler.h:58:30: note: in definition of macro '__trace_if' if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ ^~~~ >> drivers/regulator/gpio-regulator.c:162:2: note: in expansion of macro 'if' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^~ drivers/regulator/gpio-regulator.c:162:12: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^ include/linux/compiler.h:58:42: note: in definition of macro '__trace_if' if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ ^~~~ >> drivers/regulator/gpio-regulator.c:162:2: note: in expansion of macro 'if' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^~ drivers/regulator/gpio-regulator.c:162:39: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^ include/linux/compiler.h:58:42: note: in definition of macro '__trace_if' if (__builtin_constant_p(!!(cond)) ? !!(cond) : \ ^~~~ >> drivers/regulator/gpio-regulator.c:162:2: note: in expansion of macro 'if' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^~ drivers/regulator/gpio-regulator.c:162:12: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^ include/linux/compiler.h:69:16: note: in definition of macro '__trace_if' ______r = !!(cond); \ ^~~~ >> drivers/regulator/gpio-regulator.c:162:2: note: in expansion of macro 'if' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^~ drivers/regulator/gpio-regulator.c:162:39: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^ include/linux/compiler.h:69:16: note: in definition of macro '__trace_if' ______r = !!(cond); \ ^~~~ >> drivers/regulator/gpio-regulator.c:162:2: note: in expansion of macro 'if' if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) ^~ drivers/regulator/gpio-regulator.c:163:24: error: 'struct gpio_regulator_config' has no member named 'enable_gpio' return ERR_PTR(config->enable_gpio); ^~ drivers/regulator/gpio-regulator.c: In function 'gpio_regulator_probe': >> drivers/regulator/gpio-regulator.c:345:3: error: 'gflags' undeclared (first use in this function); did you mean 'mf_flags'? gflags = GPIOD_OUT_HIGH; ^~~~~~ mf_flags drivers/regulator/gpio-regulator.c:345:3: note: each undeclared identifier is reported only once for each function it appears in vim +161 drivers/regulator/gpio-regulator.c 3f0292ae8b Heiko Stübner 2011-10-05 @25 #include <linux/err.h> 3f0292ae8b Heiko Stübner 2011-10-05 26 #include <linux/mutex.h> ecc37edf7b Mark Brown 2011-10-11 27 #include <linux/module.h> 3f0292ae8b Heiko Stübner 2011-10-05 28 #include <linux/platform_device.h> 3f0292ae8b Heiko Stübner 2011-10-05 29 #include <linux/regulator/driver.h> 3f0292ae8b Heiko Stübner 2011-10-05 30 #include <linux/regulator/machine.h> 006694d099 Lee Jones 2012-10-15 31 #include <linux/regulator/of_regulator.h> 3f0292ae8b Heiko Stübner 2011-10-05 32 #include <linux/regulator/gpio-regulator.h> 3f0292ae8b Heiko Stübner 2011-10-05 33 #include <linux/gpio.h> 3f0292ae8b Heiko Stübner 2011-10-05 34 #include <linux/slab.h> 006694d099 Lee Jones 2012-10-15 35 #include <linux/of.h> 006694d099 Lee Jones 2012-10-15 36 #include <linux/of_gpio.h> 3f0292ae8b Heiko Stübner 2011-10-05 37 3f0292ae8b Heiko Stübner 2011-10-05 38 struct gpio_regulator_data { 3f0292ae8b Heiko Stübner 2011-10-05 39 struct regulator_desc desc; 3f0292ae8b Heiko Stübner 2011-10-05 40 struct regulator_dev *dev; 3f0292ae8b Heiko Stübner 2011-10-05 41 3f0292ae8b Heiko Stübner 2011-10-05 42 struct gpio *gpios; 3f0292ae8b Heiko Stübner 2011-10-05 43 int nr_gpios; 3f0292ae8b Heiko Stübner 2011-10-05 44 3f0292ae8b Heiko Stübner 2011-10-05 45 struct gpio_regulator_state *states; 3f0292ae8b Heiko Stübner 2011-10-05 46 int nr_states; 3f0292ae8b Heiko Stübner 2011-10-05 47 3f0292ae8b Heiko Stübner 2011-10-05 48 int state; 3f0292ae8b Heiko Stübner 2011-10-05 49 }; 3f0292ae8b Heiko Stübner 2011-10-05 50 3f0292ae8b Heiko Stübner 2011-10-05 51 static int gpio_regulator_get_value(struct regulator_dev *dev) 3f0292ae8b Heiko Stübner 2011-10-05 52 { 3f0292ae8b Heiko Stübner 2011-10-05 53 struct gpio_regulator_data *data = rdev_get_drvdata(dev); 3f0292ae8b Heiko Stübner 2011-10-05 54 int ptr; 3f0292ae8b Heiko Stübner 2011-10-05 55 3f0292ae8b Heiko Stübner 2011-10-05 56 for (ptr = 0; ptr < data->nr_states; ptr++) 3f0292ae8b Heiko Stübner 2011-10-05 57 if (data->states[ptr].gpios == data->state) 3f0292ae8b Heiko Stübner 2011-10-05 58 return data->states[ptr].value; 3f0292ae8b Heiko Stübner 2011-10-05 59 3f0292ae8b Heiko Stübner 2011-10-05 60 return -EINVAL; 3f0292ae8b Heiko Stübner 2011-10-05 61 } 3f0292ae8b Heiko Stübner 2011-10-05 62 eb0c5686b3 Heiko Stübner 2012-08-08 63 static int gpio_regulator_set_voltage(struct regulator_dev *dev, eb0c5686b3 Heiko Stübner 2012-08-08 64 int min_uV, int max_uV, eb0c5686b3 Heiko Stübner 2012-08-08 65 unsigned *selector) 3f0292ae8b Heiko Stübner 2011-10-05 66 { 3f0292ae8b Heiko Stübner 2011-10-05 67 struct gpio_regulator_data *data = rdev_get_drvdata(dev); 00926369b7 Heiko Stübner 2012-06-03 68 int ptr, target = 0, state, best_val = INT_MAX; 3f0292ae8b Heiko Stübner 2011-10-05 69 3f0292ae8b Heiko Stübner 2011-10-05 70 for (ptr = 0; ptr < data->nr_states; ptr++) 4dbd8f63f0 Axel Lin 2012-03-22 71 if (data->states[ptr].value < best_val && eb0c5686b3 Heiko Stübner 2012-08-08 72 data->states[ptr].value >= min_uV && eb0c5686b3 Heiko Stübner 2012-08-08 73 data->states[ptr].value <= max_uV) { 3f0292ae8b Heiko Stübner 2011-10-05 74 target = data->states[ptr].gpios; 00926369b7 Heiko Stübner 2012-06-03 75 best_val = data->states[ptr].value; b0e4d7bf8b Heiko Stübner 2012-06-03 76 if (selector) b0e4d7bf8b Heiko Stübner 2012-06-03 77 *selector = ptr; 00926369b7 Heiko Stübner 2012-06-03 78 } 3f0292ae8b Heiko Stübner 2011-10-05 79 4dbd8f63f0 Axel Lin 2012-03-22 80 if (best_val == INT_MAX) 3f0292ae8b Heiko Stübner 2011-10-05 81 return -EINVAL; 3f0292ae8b Heiko Stübner 2011-10-05 82 3f0292ae8b Heiko Stübner 2011-10-05 83 for (ptr = 0; ptr < data->nr_gpios; ptr++) { 3f0292ae8b Heiko Stübner 2011-10-05 84 state = (target & (1 << ptr)) >> ptr; 3708903ee6 Lee Jones 2012-12-10 85 gpio_set_value_cansleep(data->gpios[ptr].gpio, state); 3f0292ae8b Heiko Stübner 2011-10-05 86 } 3f0292ae8b Heiko Stübner 2011-10-05 87 data->state = target; 3f0292ae8b Heiko Stübner 2011-10-05 88 3f0292ae8b Heiko Stübner 2011-10-05 89 return 0; 3f0292ae8b Heiko Stübner 2011-10-05 90 } 3f0292ae8b Heiko Stübner 2011-10-05 91 3f0292ae8b Heiko Stübner 2011-10-05 92 static int gpio_regulator_list_voltage(struct regulator_dev *dev, 3f0292ae8b Heiko Stübner 2011-10-05 93 unsigned selector) 3f0292ae8b Heiko Stübner 2011-10-05 94 { 3f0292ae8b Heiko Stübner 2011-10-05 95 struct gpio_regulator_data *data = rdev_get_drvdata(dev); 3f0292ae8b Heiko Stübner 2011-10-05 96 3f0292ae8b Heiko Stübner 2011-10-05 97 if (selector >= data->nr_states) 3f0292ae8b Heiko Stübner 2011-10-05 98 return -EINVAL; 3f0292ae8b Heiko Stübner 2011-10-05 99 3f0292ae8b Heiko Stübner 2011-10-05 100 return data->states[selector].value; 3f0292ae8b Heiko Stübner 2011-10-05 101 } 3f0292ae8b Heiko Stübner 2011-10-05 102 3f0292ae8b Heiko Stübner 2011-10-05 103 static int gpio_regulator_set_current_limit(struct regulator_dev *dev, 3f0292ae8b Heiko Stübner 2011-10-05 104 int min_uA, int max_uA) 3f0292ae8b Heiko Stübner 2011-10-05 105 { eb0c5686b3 Heiko Stübner 2012-08-08 106 struct gpio_regulator_data *data = rdev_get_drvdata(dev); eb0c5686b3 Heiko Stübner 2012-08-08 107 int ptr, target = 0, state, best_val = 0; eb0c5686b3 Heiko Stübner 2012-08-08 108 eb0c5686b3 Heiko Stübner 2012-08-08 109 for (ptr = 0; ptr < data->nr_states; ptr++) eb0c5686b3 Heiko Stübner 2012-08-08 110 if (data->states[ptr].value > best_val && eb0c5686b3 Heiko Stübner 2012-08-08 111 data->states[ptr].value >= min_uA && eb0c5686b3 Heiko Stübner 2012-08-08 112 data->states[ptr].value <= max_uA) { eb0c5686b3 Heiko Stübner 2012-08-08 113 target = data->states[ptr].gpios; eb0c5686b3 Heiko Stübner 2012-08-08 114 best_val = data->states[ptr].value; eb0c5686b3 Heiko Stübner 2012-08-08 115 } eb0c5686b3 Heiko Stübner 2012-08-08 116 eb0c5686b3 Heiko Stübner 2012-08-08 117 if (best_val == 0) eb0c5686b3 Heiko Stübner 2012-08-08 118 return -EINVAL; eb0c5686b3 Heiko Stübner 2012-08-08 119 eb0c5686b3 Heiko Stübner 2012-08-08 120 for (ptr = 0; ptr < data->nr_gpios; ptr++) { eb0c5686b3 Heiko Stübner 2012-08-08 121 state = (target & (1 << ptr)) >> ptr; 3708903ee6 Lee Jones 2012-12-10 122 gpio_set_value_cansleep(data->gpios[ptr].gpio, state); eb0c5686b3 Heiko Stübner 2012-08-08 123 } eb0c5686b3 Heiko Stübner 2012-08-08 124 data->state = target; eb0c5686b3 Heiko Stübner 2012-08-08 125 eb0c5686b3 Heiko Stübner 2012-08-08 126 return 0; 3f0292ae8b Heiko Stübner 2011-10-05 127 } 3f0292ae8b Heiko Stübner 2011-10-05 128 3f0292ae8b Heiko Stübner 2011-10-05 129 static struct regulator_ops gpio_regulator_voltage_ops = { 3f0292ae8b Heiko Stübner 2011-10-05 130 .get_voltage = gpio_regulator_get_value, 3f0292ae8b Heiko Stübner 2011-10-05 131 .set_voltage = gpio_regulator_set_voltage, 3f0292ae8b Heiko Stübner 2011-10-05 132 .list_voltage = gpio_regulator_list_voltage, 3f0292ae8b Heiko Stübner 2011-10-05 133 }; 3f0292ae8b Heiko Stübner 2011-10-05 134 a451405fcd Axel Lin 2013-01-28 135 static struct gpio_regulator_config * 072e78b12b Javier Martinez Canillas 2014-11-10 136 of_get_gpio_regulator_config(struct device *dev, struct device_node *np, 072e78b12b Javier Martinez Canillas 2014-11-10 137 const struct regulator_desc *desc) 006694d099 Lee Jones 2012-10-15 138 { 006694d099 Lee Jones 2012-10-15 139 struct gpio_regulator_config *config; 006694d099 Lee Jones 2012-10-15 140 const char *regtype; 006694d099 Lee Jones 2012-10-15 141 int proplen, gpio, i; 251b9c21d2 Laurent Pinchart 2013-11-09 142 int ret; 006694d099 Lee Jones 2012-10-15 143 006694d099 Lee Jones 2012-10-15 144 config = devm_kzalloc(dev, 006694d099 Lee Jones 2012-10-15 145 sizeof(struct gpio_regulator_config), 006694d099 Lee Jones 2012-10-15 146 GFP_KERNEL); 006694d099 Lee Jones 2012-10-15 147 if (!config) 006694d099 Lee Jones 2012-10-15 148 return ERR_PTR(-ENOMEM); 006694d099 Lee Jones 2012-10-15 149 072e78b12b Javier Martinez Canillas 2014-11-10 150 config->init_data = of_get_regulator_init_data(dev, np, desc); 006694d099 Lee Jones 2012-10-15 151 if (!config->init_data) 006694d099 Lee Jones 2012-10-15 152 return ERR_PTR(-EINVAL); 006694d099 Lee Jones 2012-10-15 153 006694d099 Lee Jones 2012-10-15 154 config->supply_name = config->init_data->constraints.name; 006694d099 Lee Jones 2012-10-15 155 006694d099 Lee Jones 2012-10-15 156 if (of_property_read_bool(np, "enable-at-boot")) 006694d099 Lee Jones 2012-10-15 157 config->enabled_at_boot = true; 006694d099 Lee Jones 2012-10-15 158 006694d099 Lee Jones 2012-10-15 159 of_property_read_u32(np, "startup-delay-us", &config->startup_delay); 006694d099 Lee Jones 2012-10-15 160 006694d099 Lee Jones 2012-10-15 @161 config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); 09f2ba0b0b Jisheng Zhang 2016-11-10 @162 if (config->enable_gpio < 0 && config->enable_gpio != -ENOENT) 09f2ba0b0b Jisheng Zhang 2016-11-10 163 return ERR_PTR(config->enable_gpio); 006694d099 Lee Jones 2012-10-15 164 9f946099fe Richard Fitzgerald 2014-11-19 165 /* Fetch GPIOs. - optional property*/ 9f946099fe Richard Fitzgerald 2014-11-19 166 ret = of_gpio_count(np); 9f946099fe Richard Fitzgerald 2014-11-19 167 if ((ret < 0) && (ret != -ENOENT)) 9f946099fe Richard Fitzgerald 2014-11-19 168 return ERR_PTR(ret); 006694d099 Lee Jones 2012-10-15 169 9f946099fe Richard Fitzgerald 2014-11-19 170 if (ret > 0) { 9f946099fe Richard Fitzgerald 2014-11-19 171 config->nr_gpios = ret; a86854d0c5 Kees Cook 2018-06-12 172 config->gpios = devm_kcalloc(dev, a86854d0c5 Kees Cook 2018-06-12 173 config->nr_gpios, sizeof(struct gpio), 006694d099 Lee Jones 2012-10-15 174 GFP_KERNEL); 006694d099 Lee Jones 2012-10-15 175 if (!config->gpios) 006694d099 Lee Jones 2012-10-15 176 return ERR_PTR(-ENOMEM); 006694d099 Lee Jones 2012-10-15 177 1f5a9623eb Heiko Stuebner 2014-02-13 178 proplen = of_property_count_u32_elems(np, "gpios-states"); 1f5a9623eb Heiko Stuebner 2014-02-13 179 /* optional property */ 1f5a9623eb Heiko Stuebner 2014-02-13 180 if (proplen < 0) 1f5a9623eb Heiko Stuebner 2014-02-13 181 proplen = 0; 1f5a9623eb Heiko Stuebner 2014-02-13 182 1f5a9623eb Heiko Stuebner 2014-02-13 183 if (proplen > 0 && proplen != config->nr_gpios) { 5676ddc5c6 Kuninori Morimoto 2014-02-11 184 dev_warn(dev, "gpios <-> gpios-states mismatch\n"); 1f5a9623eb Heiko Stuebner 2014-02-13 185 proplen = 0; 0094050d78 Kuninori Morimoto 2014-01-30 186 } 0094050d78 Kuninori Morimoto 2014-01-30 187 ad0b8b9e82 Lee Jones 2012-12-10 188 for (i = 0; i < config->nr_gpios; i++) { 006694d099 Lee Jones 2012-10-15 189 gpio = of_get_named_gpio(np, "gpios", i); 09f2ba0b0b Jisheng Zhang 2016-11-10 190 if (gpio < 0) { 09f2ba0b0b Jisheng Zhang 2016-11-10 191 if (gpio != -ENOENT) 09f2ba0b0b Jisheng Zhang 2016-11-10 192 return ERR_PTR(gpio); 006694d099 Lee Jones 2012-10-15 193 break; 09f2ba0b0b Jisheng Zhang 2016-11-10 194 } 006694d099 Lee Jones 2012-10-15 195 config->gpios[i].gpio = gpio; 37ad490bab Nicholas Lowell 2018-03-19 196 config->gpios[i].label = config->supply_name; 1f5a9623eb Heiko Stuebner 2014-02-13 197 if (proplen > 0) { 9f946099fe Richard Fitzgerald 2014-11-19 198 of_property_read_u32_index(np, "gpios-states", 9f946099fe Richard Fitzgerald 2014-11-19 199 i, &ret); 1f5a9623eb Heiko Stuebner 2014-02-13 200 if (ret) 9f946099fe Richard Fitzgerald 2014-11-19 201 config->gpios[i].flags = 9f946099fe Richard Fitzgerald 2014-11-19 202 GPIOF_OUT_INIT_HIGH; 9f946099fe Richard Fitzgerald 2014-11-19 203 } 006694d099 Lee Jones 2012-10-15 204 } 1f5a9623eb Heiko Stuebner 2014-02-13 205 } 006694d099 Lee Jones 2012-10-15 206 006694d099 Lee Jones 2012-10-15 207 /* Fetch states. */ 934624d6e9 Heiko Stuebner 2014-02-12 208 proplen = of_property_count_u32_elems(np, "states"); 934624d6e9 Heiko Stuebner 2014-02-12 209 if (proplen < 0) { 216f2b9c95 Lee Jones 2012-11-14 210 dev_err(dev, "No 'states' property found\n"); 216f2b9c95 Lee Jones 2012-11-14 211 return ERR_PTR(-EINVAL); 216f2b9c95 Lee Jones 2012-11-14 212 } 216f2b9c95 Lee Jones 2012-11-14 213 a86854d0c5 Kees Cook 2018-06-12 214 config->states = devm_kcalloc(dev, a86854d0c5 Kees Cook 2018-06-12 215 proplen / 2, a86854d0c5 Kees Cook 2018-06-12 216 sizeof(struct gpio_regulator_state), 006694d099 Lee Jones 2012-10-15 217 GFP_KERNEL); 006694d099 Lee Jones 2012-10-15 218 if (!config->states) 006694d099 Lee Jones 2012-10-15 219 return ERR_PTR(-ENOMEM); 006694d099 Lee Jones 2012-10-15 220 006694d099 Lee Jones 2012-10-15 221 for (i = 0; i < proplen / 2; i++) { 934624d6e9 Heiko Stuebner 2014-02-12 222 of_property_read_u32_index(np, "states", i * 2, 934624d6e9 Heiko Stuebner 2014-02-12 223 &config->states[i].value); 934624d6e9 Heiko Stuebner 2014-02-12 224 of_property_read_u32_index(np, "states", i * 2 + 1, 934624d6e9 Heiko Stuebner 2014-02-12 225 &config->states[i].gpios); 006694d099 Lee Jones 2012-10-15 226 } 006694d099 Lee Jones 2012-10-15 227 config->nr_states = i; 006694d099 Lee Jones 2012-10-15 228 5b1ada83ba Mark Brown 2013-12-05 229 config->type = REGULATOR_VOLTAGE; 251b9c21d2 Laurent Pinchart 2013-11-09 230 ret = of_property_read_string(np, "regulator-type", ®type); 5b1ada83ba Mark Brown 2013-12-05 231 if (ret >= 0) { 006694d099 Lee Jones 2012-10-15 232 if (!strncmp("voltage", regtype, 7)) 006694d099 Lee Jones 2012-10-15 233 config->type = REGULATOR_VOLTAGE; 006694d099 Lee Jones 2012-10-15 234 else if (!strncmp("current", regtype, 7)) 006694d099 Lee Jones 2012-10-15 235 config->type = REGULATOR_CURRENT; 9eb9d3150b Mark Brown 2013-12-05 236 else 9eb9d3150b Mark Brown 2013-12-05 237 dev_warn(dev, "Unknown regulator-type '%s'\n", 9eb9d3150b Mark Brown 2013-12-05 238 regtype); 5b1ada83ba Mark Brown 2013-12-05 239 } 006694d099 Lee Jones 2012-10-15 240 006694d099 Lee Jones 2012-10-15 241 return config; 006694d099 Lee Jones 2012-10-15 242 } 006694d099 Lee Jones 2012-10-15 243 3f0292ae8b Heiko Stübner 2011-10-05 244 static struct regulator_ops gpio_regulator_current_ops = { 3f0292ae8b Heiko Stübner 2011-10-05 245 .get_current_limit = gpio_regulator_get_value, 3f0292ae8b Heiko Stübner 2011-10-05 246 .set_current_limit = gpio_regulator_set_current_limit, 3f0292ae8b Heiko Stübner 2011-10-05 247 }; 3f0292ae8b Heiko Stübner 2011-10-05 248 a5023574d1 Bill Pemberton 2012-11-19 249 static int gpio_regulator_probe(struct platform_device *pdev) 3f0292ae8b Heiko Stübner 2011-10-05 250 { dff91d0b72 Jingoo Han 2013-07-30 251 struct gpio_regulator_config *config = dev_get_platdata(&pdev->dev); 006694d099 Lee Jones 2012-10-15 252 struct device_node *np = pdev->dev.of_node; 3f0292ae8b Heiko Stübner 2011-10-05 253 struct gpio_regulator_data *drvdata; c172708d38 Mark Brown 2012-04-04 254 struct regulator_config cfg = { }; 3f0292ae8b Heiko Stübner 2011-10-05 255 int ptr, ret, state; 3f0292ae8b Heiko Stübner 2011-10-05 256 02b552160f Mark Brown 2012-04-03 257 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), 02b552160f Mark Brown 2012-04-03 258 GFP_KERNEL); 9c25960cbb Fabio Estevam 2014-01-24 259 if (drvdata == NULL) 3f0292ae8b Heiko Stübner 2011-10-05 260 return -ENOMEM; 3f0292ae8b Heiko Stübner 2011-10-05 261 072e78b12b Javier Martinez Canillas 2014-11-10 262 if (np) { 072e78b12b Javier Martinez Canillas 2014-11-10 263 config = of_get_gpio_regulator_config(&pdev->dev, np, 072e78b12b Javier Martinez Canillas 2014-11-10 264 &drvdata->desc); 072e78b12b Javier Martinez Canillas 2014-11-10 265 if (IS_ERR(config)) 072e78b12b Javier Martinez Canillas 2014-11-10 266 return PTR_ERR(config); 072e78b12b Javier Martinez Canillas 2014-11-10 267 } 072e78b12b Javier Martinez Canillas 2014-11-10 268 3f0292ae8b Heiko Stübner 2011-10-05 269 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 3f0292ae8b Heiko Stübner 2011-10-05 270 if (drvdata->desc.name == NULL) { 3f0292ae8b Heiko Stübner 2011-10-05 271 dev_err(&pdev->dev, "Failed to allocate supply name\n"); ed8cffda27 Christophe Jaillet 2018-03-13 272 return -ENOMEM; 3f0292ae8b Heiko Stübner 2011-10-05 273 } 3f0292ae8b Heiko Stübner 2011-10-05 274 9f946099fe Richard Fitzgerald 2014-11-19 275 if (config->nr_gpios != 0) { 3f0292ae8b Heiko Stübner 2011-10-05 276 drvdata->gpios = kmemdup(config->gpios, 3f0292ae8b Heiko Stübner 2011-10-05 277 config->nr_gpios * sizeof(struct gpio), 3f0292ae8b Heiko Stübner 2011-10-05 278 GFP_KERNEL); 3f0292ae8b Heiko Stübner 2011-10-05 279 if (drvdata->gpios == NULL) { 3f0292ae8b Heiko Stübner 2011-10-05 280 dev_err(&pdev->dev, "Failed to allocate gpio data\n"); 3f0292ae8b Heiko Stübner 2011-10-05 281 ret = -ENOMEM; 3f0292ae8b Heiko Stübner 2011-10-05 282 goto err_name; 3f0292ae8b Heiko Stübner 2011-10-05 283 } 3f0292ae8b Heiko Stübner 2011-10-05 284 9f946099fe Richard Fitzgerald 2014-11-19 285 drvdata->nr_gpios = config->nr_gpios; 9f946099fe Richard Fitzgerald 2014-11-19 286 ret = gpio_request_array(drvdata->gpios, drvdata->nr_gpios); 9f946099fe Richard Fitzgerald 2014-11-19 287 if (ret) { 0258382bf3 Rabin Vincent 2016-02-19 288 if (ret != -EPROBE_DEFER) 9f946099fe Richard Fitzgerald 2014-11-19 289 dev_err(&pdev->dev, 0258382bf3 Rabin Vincent 2016-02-19 290 "Could not obtain regulator setting GPIOs: %d\n", 0258382bf3 Rabin Vincent 2016-02-19 291 ret); ed8cffda27 Christophe Jaillet 2018-03-13 292 goto err_memgpio; 9f946099fe Richard Fitzgerald 2014-11-19 293 } 9f946099fe Richard Fitzgerald 2014-11-19 294 } 9f946099fe Richard Fitzgerald 2014-11-19 295 3f0292ae8b Heiko Stübner 2011-10-05 296 drvdata->states = kmemdup(config->states, 3f0292ae8b Heiko Stübner 2011-10-05 297 config->nr_states * 3f0292ae8b Heiko Stübner 2011-10-05 298 sizeof(struct gpio_regulator_state), 3f0292ae8b Heiko Stübner 2011-10-05 299 GFP_KERNEL); 3f0292ae8b Heiko Stübner 2011-10-05 300 if (drvdata->states == NULL) { 3f0292ae8b Heiko Stübner 2011-10-05 301 dev_err(&pdev->dev, "Failed to allocate state data\n"); 3f0292ae8b Heiko Stübner 2011-10-05 302 ret = -ENOMEM; ed8cffda27 Christophe Jaillet 2018-03-13 303 goto err_stategpio; 3f0292ae8b Heiko Stübner 2011-10-05 304 } 3f0292ae8b Heiko Stübner 2011-10-05 305 drvdata->nr_states = config->nr_states; 3f0292ae8b Heiko Stübner 2011-10-05 306 3f0292ae8b Heiko Stübner 2011-10-05 307 drvdata->desc.owner = THIS_MODULE; a2a8222be8 Axel Lin 2012-07-04 308 drvdata->desc.enable_time = config->startup_delay; 3f0292ae8b Heiko Stübner 2011-10-05 309 3f0292ae8b Heiko Stübner 2011-10-05 310 /* handle regulator type*/ 3f0292ae8b Heiko Stübner 2011-10-05 311 switch (config->type) { 3f0292ae8b Heiko Stübner 2011-10-05 312 case REGULATOR_VOLTAGE: 3f0292ae8b Heiko Stübner 2011-10-05 313 drvdata->desc.type = REGULATOR_VOLTAGE; 3f0292ae8b Heiko Stübner 2011-10-05 314 drvdata->desc.ops = &gpio_regulator_voltage_ops; 3f0292ae8b Heiko Stübner 2011-10-05 315 drvdata->desc.n_voltages = config->nr_states; 3f0292ae8b Heiko Stübner 2011-10-05 316 break; 3f0292ae8b Heiko Stübner 2011-10-05 317 case REGULATOR_CURRENT: 3f0292ae8b Heiko Stübner 2011-10-05 318 drvdata->desc.type = REGULATOR_CURRENT; 3f0292ae8b Heiko Stübner 2011-10-05 319 drvdata->desc.ops = &gpio_regulator_current_ops; 3f0292ae8b Heiko Stübner 2011-10-05 320 break; 3f0292ae8b Heiko Stübner 2011-10-05 321 default: 3f0292ae8b Heiko Stübner 2011-10-05 322 dev_err(&pdev->dev, "No regulator type set\n"); 3f0292ae8b Heiko Stübner 2011-10-05 323 ret = -EINVAL; ed8cffda27 Christophe Jaillet 2018-03-13 324 goto err_memstate; 3f0292ae8b Heiko Stübner 2011-10-05 325 } 3f0292ae8b Heiko Stübner 2011-10-05 326 3f0292ae8b Heiko Stübner 2011-10-05 327 /* build initial state from gpio init data. */ 3f0292ae8b Heiko Stübner 2011-10-05 328 state = 0; 3f0292ae8b Heiko Stübner 2011-10-05 329 for (ptr = 0; ptr < drvdata->nr_gpios; ptr++) { 3f0292ae8b Heiko Stübner 2011-10-05 330 if (config->gpios[ptr].flags & GPIOF_OUT_INIT_HIGH) 3f0292ae8b Heiko Stübner 2011-10-05 331 state |= (1 << ptr); 3f0292ae8b Heiko Stübner 2011-10-05 332 } 3f0292ae8b Heiko Stübner 2011-10-05 333 drvdata->state = state; 3f0292ae8b Heiko Stübner 2011-10-05 334 c172708d38 Mark Brown 2012-04-04 335 cfg.dev = &pdev->dev; c172708d38 Mark Brown 2012-04-04 336 cfg.init_data = config->init_data; 7d4be2f5ad Heiko Stübner 2012-06-03 337 cfg.driver_data = drvdata; f8a9f757cb Frank Li 2012-11-12 338 cfg.of_node = np; c172708d38 Mark Brown 2012-04-04 339 b123f98710 Linus Walleij 2017-12-31 340 /* b123f98710 Linus Walleij 2017-12-31 341 * The signal will be inverted by the GPIO core if flagged so in the b123f98710 Linus Walleij 2017-12-31 342 * decriptor. b123f98710 Linus Walleij 2017-12-31 343 */ b123f98710 Linus Walleij 2017-12-31 344 if (config->enabled_at_boot) b123f98710 Linus Walleij 2017-12-31 @345 gflags = GPIOD_OUT_HIGH; 4b7c948f55 Axel Lin 2012-07-04 346 else b123f98710 Linus Walleij 2017-12-31 347 gflags = GPIOD_OUT_LOW; b123f98710 Linus Walleij 2017-12-31 348 b123f98710 Linus Walleij 2017-12-31 349 cfg.ena_gpiod = devm_gpiod_get_optional(&pdev->dev, "enable", gflags); b123f98710 Linus Walleij 2017-12-31 350 if (IS_ERR(cfg.ena_gpiod)) { b123f98710 Linus Walleij 2017-12-31 351 ret = PTR_ERR(cfg.ena_gpiod); b123f98710 Linus Walleij 2017-12-31 352 goto err_stategpio; 4b7c948f55 Axel Lin 2012-07-04 353 } 4b7c948f55 Axel Lin 2012-07-04 354 c172708d38 Mark Brown 2012-04-04 355 drvdata->dev = regulator_register(&drvdata->desc, &cfg); 3f0292ae8b Heiko Stübner 2011-10-05 356 if (IS_ERR(drvdata->dev)) { 3f0292ae8b Heiko Stübner 2011-10-05 357 ret = PTR_ERR(drvdata->dev); 3f0292ae8b Heiko Stübner 2011-10-05 358 dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); ed8cffda27 Christophe Jaillet 2018-03-13 359 goto err_memstate; 3f0292ae8b Heiko Stübner 2011-10-05 360 } 3f0292ae8b Heiko Stübner 2011-10-05 361 3f0292ae8b Heiko Stübner 2011-10-05 362 platform_set_drvdata(pdev, drvdata); 3f0292ae8b Heiko Stübner 2011-10-05 363 3f0292ae8b Heiko Stübner 2011-10-05 364 return 0; 3f0292ae8b Heiko Stübner 2011-10-05 365 3f0292ae8b Heiko Stübner 2011-10-05 366 err_memstate: 3f0292ae8b Heiko Stübner 2011-10-05 367 kfree(drvdata->states); ed8cffda27 Christophe Jaillet 2018-03-13 368 err_stategpio: ed8cffda27 Christophe Jaillet 2018-03-13 369 gpio_free_array(drvdata->gpios, drvdata->nr_gpios); 3f0292ae8b Heiko Stübner 2011-10-05 370 err_memgpio: 3f0292ae8b Heiko Stübner 2011-10-05 371 kfree(drvdata->gpios); 3f0292ae8b Heiko Stübner 2011-10-05 372 err_name: 3f0292ae8b Heiko Stübner 2011-10-05 373 kfree(drvdata->desc.name); 3f0292ae8b Heiko Stübner 2011-10-05 374 return ret; 3f0292ae8b Heiko Stübner 2011-10-05 375 } 3f0292ae8b Heiko Stübner 2011-10-05 376 :::::: The code at line 161 was first introduced by commit :::::: 006694d099e86e5a928fb39bdea280ab42c9d59c regulator: gpio-regulator: Allow use of GPIO controlled regulators though DT :::::: TO: Lee Jones <lee.jones@xxxxxxxxxx> :::::: CC: Mark Brown <broonie@xxxxxxxxxxxxxxxxxxxxxxxxxxx> --- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
Attachment:
.config.gz
Description: application/gzip