^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * fixed.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2008 Wolfson Microelectronics PLC.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Copyright (c) 2009 Nokia Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Roger Quadros <ext-roger.quadros@nokia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This is useful for systems with mixed controllable and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * non-controllable regulators, as well as for allowing testing on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * systems with no controllable regulators.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/regulator/fixed.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/clk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct fixed_voltage_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct regulator_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct regulator_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct clk *enable_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) unsigned int clk_enable_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct fixed_dev_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) bool has_enable_clock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) static int reg_clock_enable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) ret = clk_prepare_enable(priv->enable_clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) priv->clk_enable_counter++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static int reg_clock_disable(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) clk_disable_unprepare(priv->enable_clock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) priv->clk_enable_counter--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int reg_clock_is_enabled(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct fixed_voltage_data *priv = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) return priv->clk_enable_counter > 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) * of_get_fixed_voltage_config - extract fixed_voltage_config structure info
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) * @dev: device requesting for fixed_voltage_config
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) * @desc: regulator description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * Populates fixed_voltage_config structure by extracting data from device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * tree node, returns a pointer to the populated structure of NULL if memory
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * alloc fails.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static struct fixed_voltage_config *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) of_get_fixed_voltage_config(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) const struct regulator_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct fixed_voltage_config *config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) struct regulator_init_data *init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) config = devm_kzalloc(dev, sizeof(struct fixed_voltage_config),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) if (!config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) config->init_data = of_get_regulator_init_data(dev, dev->of_node, desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) if (!config->init_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) init_data = config->init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) init_data->constraints.apply_uV = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) config->supply_name = init_data->constraints.name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (init_data->constraints.min_uV == init_data->constraints.max_uV) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) config->microvolts = init_data->constraints.min_uV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dev_err(dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) "Fixed regulator specified with variable voltages\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return ERR_PTR(-EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (init_data->constraints.boot_on)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) config->enabled_at_boot = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) of_property_read_u32(np, "startup-delay-us", &config->startup_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) of_property_read_u32(np, "off-on-delay-us", &config->off_on_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (of_find_property(np, "vin-supply", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) config->input_supply = "vin";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static const struct regulator_ops fixed_voltage_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) static const struct regulator_ops fixed_voltage_clkenabled_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .enable = reg_clock_enable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .disable = reg_clock_disable,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .is_enabled = reg_clock_is_enabled,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) static int reg_fixed_voltage_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) struct device *dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct fixed_voltage_config *config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct fixed_voltage_data *drvdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) const struct fixed_dev_type *drvtype = of_device_get_match_data(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct regulator_config cfg = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) enum gpiod_flags gflags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) drvdata = devm_kzalloc(&pdev->dev, sizeof(struct fixed_voltage_data),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (!drvdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (pdev->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) config = of_get_fixed_voltage_config(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) &drvdata->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (IS_ERR(config))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) return PTR_ERR(config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) config = dev_get_platdata(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) if (!config)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) drvdata->desc.name = devm_kstrdup(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) config->supply_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) if (drvdata->desc.name == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) dev_err(&pdev->dev, "Failed to allocate supply name\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) drvdata->desc.type = REGULATOR_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) drvdata->desc.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (drvtype && drvtype->has_enable_clock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) drvdata->desc.ops = &fixed_voltage_clkenabled_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) drvdata->enable_clock = devm_clk_get(dev, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) if (IS_ERR(drvdata->enable_clock)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) dev_err(dev, "Can't get enable-clock from devicetree\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) drvdata->desc.ops = &fixed_voltage_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) drvdata->desc.enable_time = config->startup_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) drvdata->desc.off_on_delay = config->off_on_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (config->input_supply) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) drvdata->desc.supply_name = devm_kstrdup(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) config->input_supply,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (!drvdata->desc.supply_name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) dev_err(&pdev->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) "Failed to allocate input supply\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (config->microvolts)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) drvdata->desc.n_voltages = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) drvdata->desc.fixed_uV = config->microvolts;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * The signal will be inverted by the GPIO core if flagged so in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) * descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (config->enabled_at_boot)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) gflags = GPIOD_OUT_HIGH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) gflags = GPIOD_OUT_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) * Some fixed regulators share the enable line between two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) * regulators which makes it necessary to get a handle on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) * same descriptor for two different consumers. This will get
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) * the GPIO descriptor, but only the first call will initialize
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) * it so any flags such as inversion or open drain will only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) * be set up by the first caller and assumed identical on the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) * next caller.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * FIXME: find a better way to deal with this.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) gflags |= GPIOD_FLAGS_BIT_NONEXCLUSIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) * Do not use devm* here: the regulator core takes over the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) * lifecycle management of the GPIO descriptor.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) cfg.ena_gpiod = gpiod_get_optional(&pdev->dev, NULL, gflags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) if (IS_ERR(cfg.ena_gpiod))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) return PTR_ERR(cfg.ena_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) cfg.dev = &pdev->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) cfg.init_data = config->init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) cfg.driver_data = drvdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) cfg.of_node = pdev->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) drvdata->dev = devm_regulator_register(&pdev->dev, &drvdata->desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) &cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) if (IS_ERR(drvdata->dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ret = PTR_ERR(drvdata->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) platform_set_drvdata(pdev, drvdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) dev_dbg(&pdev->dev, "%s supplying %duV\n", drvdata->desc.name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) drvdata->desc.fixed_uV);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) #if defined(CONFIG_OF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) static const struct fixed_dev_type fixed_voltage_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) .has_enable_clock = false,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) static const struct fixed_dev_type fixed_clkenable_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .has_enable_clock = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct of_device_id fixed_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .compatible = "regulator-fixed",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) .data = &fixed_voltage_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) .compatible = "regulator-fixed-clock",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) .data = &fixed_clkenable_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) MODULE_DEVICE_TABLE(of, fixed_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) static struct platform_driver regulator_fixed_voltage_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .probe = reg_fixed_voltage_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .name = "reg-fixed-voltage",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) .of_match_table = of_match_ptr(fixed_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) static int __init regulator_fixed_voltage_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return platform_driver_register(®ulator_fixed_voltage_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) subsys_initcall(regulator_fixed_voltage_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static void __exit regulator_fixed_voltage_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) platform_driver_unregister(®ulator_fixed_voltage_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) module_exit(regulator_fixed_voltage_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MODULE_DESCRIPTION("Fixed voltage regulator");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) MODULE_ALIAS("platform:reg-fixed-voltage");