Lines Matching +full:gpio +full:- +full:cfg
1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Roger Quadros <ext-roger.quadros@nokia.com>
13 * non-controllable regulators, as well as for allowing testing on
25 #include <linux/gpio/consumer.h>
53 ret = clk_prepare_enable(priv->enable_clock); in reg_clock_enable()
57 priv->enable_counter++; in reg_clock_enable()
66 clk_disable_unprepare(priv->enable_clock); in reg_clock_disable()
67 priv->enable_counter--; in reg_clock_disable()
75 struct device *dev = rdev->dev.parent; in reg_domain_enable()
78 ret = dev_pm_genpd_set_performance_state(dev, priv->performance_state); in reg_domain_enable()
82 priv->enable_counter++; in reg_domain_enable()
90 struct device *dev = rdev->dev.parent; in reg_domain_disable()
97 priv->enable_counter--; in reg_domain_disable()
106 return priv->enable_counter > 0; in reg_is_enabled()
111 * of_get_fixed_voltage_config - extract fixed_voltage_config structure info
124 struct device_node *np = dev->of_node; in of_get_fixed_voltage_config()
130 return ERR_PTR(-ENOMEM); in of_get_fixed_voltage_config()
132 config->init_data = of_get_regulator_init_data(dev, dev->of_node, desc); in of_get_fixed_voltage_config()
133 if (!config->init_data) in of_get_fixed_voltage_config()
134 return ERR_PTR(-EINVAL); in of_get_fixed_voltage_config()
136 init_data = config->init_data; in of_get_fixed_voltage_config()
137 init_data->constraints.apply_uV = 0; in of_get_fixed_voltage_config()
139 config->supply_name = init_data->constraints.name; in of_get_fixed_voltage_config()
140 if (init_data->constraints.min_uV == init_data->constraints.max_uV) { in of_get_fixed_voltage_config()
141 config->microvolts = init_data->constraints.min_uV; in of_get_fixed_voltage_config()
145 return ERR_PTR(-EINVAL); in of_get_fixed_voltage_config()
148 if (init_data->constraints.boot_on) in of_get_fixed_voltage_config()
149 config->enabled_at_boot = true; in of_get_fixed_voltage_config()
151 of_property_read_u32(np, "startup-delay-us", &config->startup_delay); in of_get_fixed_voltage_config()
152 of_property_read_u32(np, "off-on-delay-us", &config->off_on_delay); in of_get_fixed_voltage_config()
154 if (of_find_property(np, "vin-supply", NULL)) in of_get_fixed_voltage_config()
155 config->input_supply = "vin"; in of_get_fixed_voltage_config()
177 struct device *dev = &pdev->dev; in reg_fixed_voltage_probe()
181 struct regulator_config cfg = { }; in reg_fixed_voltage_probe() local
185 drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data), in reg_fixed_voltage_probe()
188 return -ENOMEM; in reg_fixed_voltage_probe()
190 if (pdev->dev.of_node) { in reg_fixed_voltage_probe()
191 config = of_get_fixed_voltage_config(&pdev->dev, in reg_fixed_voltage_probe()
192 &drvdata->desc); in reg_fixed_voltage_probe()
196 config = dev_get_platdata(&pdev->dev); in reg_fixed_voltage_probe()
200 return -ENOMEM; in reg_fixed_voltage_probe()
202 drvdata->desc.name = devm_kstrdup(&pdev->dev, in reg_fixed_voltage_probe()
203 config->supply_name, in reg_fixed_voltage_probe()
205 if (drvdata->desc.name == NULL) { in reg_fixed_voltage_probe()
206 dev_err(&pdev->dev, "Failed to allocate supply name\n"); in reg_fixed_voltage_probe()
207 return -ENOMEM; in reg_fixed_voltage_probe()
209 drvdata->desc.type = REGULATOR_VOLTAGE; in reg_fixed_voltage_probe()
210 drvdata->desc.owner = THIS_MODULE; in reg_fixed_voltage_probe()
212 if (drvtype && drvtype->has_enable_clock) { in reg_fixed_voltage_probe()
213 drvdata->desc.ops = &fixed_voltage_clkenabled_ops; in reg_fixed_voltage_probe()
215 drvdata->enable_clock = devm_clk_get(dev, NULL); in reg_fixed_voltage_probe()
216 if (IS_ERR(drvdata->enable_clock)) { in reg_fixed_voltage_probe()
217 dev_err(dev, "Can't get enable-clock from devicetree\n"); in reg_fixed_voltage_probe()
218 return -ENOENT; in reg_fixed_voltage_probe()
220 } else if (drvtype && drvtype->has_performance_state) { in reg_fixed_voltage_probe()
221 drvdata->desc.ops = &fixed_voltage_domain_ops; in reg_fixed_voltage_probe()
223 drvdata->performance_state = of_get_required_opp_performance_state(dev->of_node, 0); in reg_fixed_voltage_probe()
224 if (drvdata->performance_state < 0) { in reg_fixed_voltage_probe()
226 return drvdata->performance_state; in reg_fixed_voltage_probe()
229 drvdata->desc.ops = &fixed_voltage_ops; in reg_fixed_voltage_probe()
232 drvdata->desc.enable_time = config->startup_delay; in reg_fixed_voltage_probe()
233 drvdata->desc.off_on_delay = config->off_on_delay; in reg_fixed_voltage_probe()
235 if (config->input_supply) { in reg_fixed_voltage_probe()
236 drvdata->desc.supply_name = devm_kstrdup(&pdev->dev, in reg_fixed_voltage_probe()
237 config->input_supply, in reg_fixed_voltage_probe()
239 if (!drvdata->desc.supply_name) in reg_fixed_voltage_probe()
240 return -ENOMEM; in reg_fixed_voltage_probe()
243 if (config->microvolts) in reg_fixed_voltage_probe()
244 drvdata->desc.n_voltages = 1; in reg_fixed_voltage_probe()
246 drvdata->desc.fixed_uV = config->microvolts; in reg_fixed_voltage_probe()
249 * The signal will be inverted by the GPIO core if flagged so in the in reg_fixed_voltage_probe()
252 if (config->enabled_at_boot) in reg_fixed_voltage_probe()
261 * the GPIO descriptor, but only the first call will initialize in reg_fixed_voltage_probe()
272 * lifecycle management of the GPIO descriptor. in reg_fixed_voltage_probe()
274 cfg.ena_gpiod = gpiod_get_optional(&pdev->dev, NULL, gflags); in reg_fixed_voltage_probe()
275 if (IS_ERR(cfg.ena_gpiod)) in reg_fixed_voltage_probe()
276 return dev_err_probe(&pdev->dev, PTR_ERR(cfg.ena_gpiod), in reg_fixed_voltage_probe()
277 "can't get GPIO\n"); in reg_fixed_voltage_probe()
279 cfg.dev = &pdev->dev; in reg_fixed_voltage_probe()
280 cfg.init_data = config->init_data; in reg_fixed_voltage_probe()
281 cfg.driver_data = drvdata; in reg_fixed_voltage_probe()
282 cfg.of_node = pdev->dev.of_node; in reg_fixed_voltage_probe()
284 drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc, in reg_fixed_voltage_probe()
285 &cfg); in reg_fixed_voltage_probe()
286 if (IS_ERR(drvdata->dev)) { in reg_fixed_voltage_probe()
287 ret = dev_err_probe(&pdev->dev, PTR_ERR(drvdata->dev), in reg_fixed_voltage_probe()
289 PTR_ERR(drvdata->dev)); in reg_fixed_voltage_probe()
295 dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name, in reg_fixed_voltage_probe()
296 drvdata->desc.fixed_uV); in reg_fixed_voltage_probe()
316 .compatible = "regulator-fixed",
320 .compatible = "regulator-fixed-clock",
324 .compatible = "regulator-fixed-domain",
336 .name = "reg-fixed-voltage",
356 MODULE_ALIAS("platform:reg-fixed-voltage");