// SPDX-License-Identifier: GPL-2.0-or-later /* * gpio-regulator.c * * Copyright 2011 Heiko Stuebner <heiko@sntech.de> * * based on fixed.c * * Copyright 2008 Wolfson Microelectronics PLC. * * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> * * Copyright (c) 2009 Nokia Corporation * Roger Quadros <ext-roger.quadros@nokia.com> * * This is useful for systems with mixed controllable and * non-controllable regulators, as well as for allowing testing on * systems with no controllable regulators.
*/
if (config->init_data->constraints.boot_on)
config->enabled_at_boot = true;
/* * Do not use: undocumented device tree property. * This is kept around solely for device tree ABI stability.
*/ if (of_property_read_bool(np, "enable-at-boot"))
config->enabled_at_boot = true;
ret = of_property_read_u32_index(np, "gpios-states", i,
&val);
/* Default to high per specification */ if (ret)
config->gflags[i] = GPIOD_OUT_HIGH; else
config->gflags[i] =
val ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW;
}
}
config->ngpios = ngpios;
/* Fetch states. */
proplen = of_property_count_u32_elems(np, "states"); if (proplen < 0) {
dev_err(dev, "No 'states' property found\n"); return ERR_PTR(-EINVAL);
}
if (config->input_supply) {
drvdata->desc.supply_name = devm_kstrdup(&pdev->dev,
config->input_supply,
GFP_KERNEL); if (!drvdata->desc.supply_name) {
dev_err(&pdev->dev, "Failed to allocate input supply\n"); return -ENOMEM;
}
}
for (i = 0; i < config->ngpios; i++) {
drvdata->gpiods[i] = devm_gpiod_get_index(dev,
NULL,
i,
config->gflags[i]); if (IS_ERR(drvdata->gpiods[i])) return PTR_ERR(drvdata->gpiods[i]); /* This is good to know */
gpiod_set_consumer_name(drvdata->gpiods[i], drvdata->desc.name);
}
drvdata->nr_gpios = config->ngpios;
drvdata->states = devm_kmemdup(dev,
config->states,
config->nr_states * sizeof(struct gpio_regulator_state),
GFP_KERNEL); if (drvdata->states == NULL) {
dev_err(dev, "Failed to allocate state data\n"); return -ENOMEM;
}
drvdata->nr_states = config->nr_states;
/* * The signal will be inverted by the GPIO core if flagged so in the * descriptor.
*/ if (config->enabled_at_boot)
gflags = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_NONEXCLUSIVE; else
gflags = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE;
cfg.ena_gpiod = gpiod_get_optional(dev, "enable", gflags); if (IS_ERR(cfg.ena_gpiod)) return PTR_ERR(cfg.ena_gpiod);
rdev = devm_regulator_register(dev, &drvdata->desc, &cfg); if (IS_ERR(rdev)) return dev_err_probe(dev, PTR_ERR(rdev), "Failed to register regulator\n");
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.