// SPDX-License-Identifier: GPL-2.0-or-later /* * 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.
*/
/** * reg_fixed_get_irqs - Get and register the optional IRQ for fixed voltage * regulator. * @dev: Pointer to the device structure. * @priv: Pointer to fixed_voltage_data structure containing private data. * * This function tries to get the IRQ from the device firmware node. * If it's an optional IRQ and not found, it returns 0. * Otherwise, it attempts to request the threaded IRQ. * * Return: 0 on success, or a negative error number on failure.
*/ staticint reg_fixed_get_irqs(struct device *dev, struct fixed_voltage_data *priv)
{ int ret;
ret = fwnode_irq_get(dev_fwnode(dev), 0); /* This is optional IRQ. If not found we will get -EINVAL */ if (ret == -EINVAL) return 0; if (ret < 0) return dev_err_probe(dev, ret, "Failed to get IRQ\n");
ret = devm_request_threaded_irq(dev, ret, NULL,
reg_fixed_under_voltage_irq_handler,
IRQF_ONESHOT, "under-voltage", priv); if (ret) return dev_err_probe(dev, ret, "Failed to request IRQ\n");
return 0;
}
/** * of_get_fixed_voltage_config - extract fixed_voltage_config structure info * @dev: device requesting for fixed_voltage_config * @desc: regulator description * * Populates fixed_voltage_config structure by extracting data from device * tree node. * * Return: Pointer to a populated &struct fixed_voltage_config or %NULL if * memory allocation fails.
*/ staticstruct fixed_voltage_config *
of_get_fixed_voltage_config(struct device *dev, conststruct regulator_desc *desc)
{ struct fixed_voltage_config *config; struct device_node *np = dev->of_node; struct regulator_init_data *init_data;
config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config),
GFP_KERNEL); if (!config) return ERR_PTR(-ENOMEM);
config->init_data = of_get_regulator_init_data(dev, dev->of_node, desc); if (!config->init_data) 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) return -ENOMEM;
}
if (config->microvolts)
drvdata->desc.n_voltages = 1;
drvdata->desc.fixed_uV = config->microvolts;
/* * The signal will be inverted by the GPIO core if flagged so in the * descriptor.
*/ if (config->enabled_at_boot)
gflags = GPIOD_OUT_HIGH; else
gflags = GPIOD_OUT_LOW;
/* * Some fixed regulators share the enable line between two * regulators which makes it necessary to get a handle on the * same descriptor for two different consumers. This will get * the GPIO descriptor, but only the first call will initialize * it so any flags such as inversion or open drain will only * be set up by the first caller and assumed identical on the * next caller. * * FIXME: find a better way to deal with this.
*/
gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE;
/* * Do not use devm* here: the regulator core takes over the * lifecycle management of the GPIO descriptor.
*/
cfg.ena_gpiod = gpiod_get_optional(&pdev->dev, NULL, gflags); if (IS_ERR(cfg.ena_gpiod)) return dev_err_probe(&pdev->dev, PTR_ERR(cfg.ena_gpiod), "can't get GPIO\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.