^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) // arizona-ldo1.c -- LDO1 supply for Arizona devices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) //
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) // Copyright 2012 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) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/moduleparam.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/bitops.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/gpio/consumer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/regulator/arizona-ldo1.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/mfd/arizona/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/mfd/arizona/pdata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/mfd/arizona/registers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/mfd/madera/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/mfd/madera/pdata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/mfd/madera/registers.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct arizona_ldo1 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct regulator_dev *regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct regulator_consumer_supply supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct regulator_init_data init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct gpio_desc *ena_gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) static int arizona_ldo1_hc_set_voltage_sel(struct regulator_dev *rdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned sel)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct regmap *regmap = rdev_get_regmap(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) if (sel == rdev->desc->n_voltages - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) val = ARIZONA_LDO1_HI_PWR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) ret = regmap_update_bits(regmap, ARIZONA_LDO1_CONTROL_2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) ARIZONA_LDO1_HI_PWR, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) return regulator_set_voltage_sel_regmap(rdev, sel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) static int arizona_ldo1_hc_get_voltage_sel(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct regmap *regmap = rdev_get_regmap(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) unsigned int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ret = regmap_read(regmap, ARIZONA_LDO1_CONTROL_2, &val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) if (ret != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (val & ARIZONA_LDO1_HI_PWR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return rdev->desc->n_voltages - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) return regulator_get_voltage_sel_regmap(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static const struct regulator_ops arizona_ldo1_hc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .list_voltage = regulator_list_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) .map_voltage = regulator_map_voltage_linear_range,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .get_voltage_sel = arizona_ldo1_hc_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .set_voltage_sel = arizona_ldo1_hc_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .get_bypass = regulator_get_bypass_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .set_bypass = regulator_set_bypass_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) static const struct linear_range arizona_ldo1_hc_ranges[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) REGULATOR_LINEAR_RANGE(900000, 0, 0x6, 50000),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) REGULATOR_LINEAR_RANGE(1800000, 0x7, 0x7, 0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static const struct regulator_desc arizona_ldo1_hc = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .name = "LDO1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .supply_name = "LDOVDD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .ops = &arizona_ldo1_hc_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .vsel_reg = ARIZONA_LDO1_CONTROL_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .bypass_reg = ARIZONA_LDO1_CONTROL_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .bypass_mask = ARIZONA_LDO1_BYPASS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .linear_ranges = arizona_ldo1_hc_ranges,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) .n_linear_ranges = ARRAY_SIZE(arizona_ldo1_hc_ranges),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .n_voltages = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .enable_time = 1500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .ramp_delay = 24000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .owner = THIS_MODULE,
^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) static const struct regulator_ops arizona_ldo1_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) static const struct regulator_desc arizona_ldo1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .name = "LDO1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) .supply_name = "LDOVDD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) .ops = &arizona_ldo1_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) .vsel_reg = ARIZONA_LDO1_CONTROL_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) .vsel_mask = ARIZONA_LDO1_VSEL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) .min_uV = 900000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) .uV_step = 25000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) .n_voltages = 13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) .enable_time = 500,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) .ramp_delay = 24000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static const struct regulator_init_data arizona_ldo1_dvfs = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) .constraints = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) .min_uV = 1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) .max_uV = 1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) .valid_ops_mask = REGULATOR_CHANGE_STATUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) REGULATOR_CHANGE_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) .num_consumer_supplies = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) static const struct regulator_init_data arizona_ldo1_default = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) .constraints = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) .valid_ops_mask = REGULATOR_CHANGE_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) .num_consumer_supplies = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static const struct regulator_init_data arizona_ldo1_wm5110 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) .constraints = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) .min_uV = 1175000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) .max_uV = 1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) .valid_ops_mask = REGULATOR_CHANGE_STATUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) REGULATOR_CHANGE_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) .num_consumer_supplies = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static const struct regulator_desc madera_ldo1 = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .name = "LDO1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .supply_name = "LDOVDD",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .type = REGULATOR_VOLTAGE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .ops = &arizona_ldo1_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) .vsel_reg = MADERA_LDO1_CONTROL_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) .vsel_mask = MADERA_LDO1_VSEL_MASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) .min_uV = 900000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) .uV_step = 25000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) .n_voltages = 13,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) .enable_time = 3000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static const struct regulator_init_data madera_ldo1_default = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) .constraints = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) .min_uV = 1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) .max_uV = 1200000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) .valid_ops_mask = REGULATOR_CHANGE_STATUS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) .num_consumer_supplies = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int arizona_ldo1_of_get_pdata(struct arizona_ldo1_pdata *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) struct regulator_config *config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) const struct regulator_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) bool *external_dcvdd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct arizona_ldo1 *ldo1 = config->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct device_node *np = config->dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct device_node *init_node, *dcvdd_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct regulator_init_data *init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) init_node = of_get_child_by_name(np, "ldo1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) dcvdd_node = of_parse_phandle(np, "DCVDD-supply", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) if (init_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) config->of_node = init_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) init_data = of_get_regulator_init_data(config->dev, init_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (init_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) init_data->consumer_supplies = &ldo1->supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) init_data->num_consumer_supplies = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (dcvdd_node && dcvdd_node != init_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) *external_dcvdd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) pdata->init_data = init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) } else if (dcvdd_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) *external_dcvdd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) of_node_put(dcvdd_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) return 0;
^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) static int arizona_ldo1_common_init(struct platform_device *pdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct arizona_ldo1 *ldo1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) const struct regulator_desc *desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) struct arizona_ldo1_pdata *pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) bool *external_dcvdd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct device *parent_dev = pdev->dev.parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) *external_dcvdd = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) ldo1->supply.supply = "DCVDD";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) ldo1->init_data.consumer_supplies = &ldo1->supply;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) ldo1->supply.dev_name = dev_name(parent_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) config.dev = parent_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) config.driver_data = ldo1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) config.regmap = ldo1->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (IS_ENABLED(CONFIG_OF)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (!dev_get_platdata(parent_dev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) ret = arizona_ldo1_of_get_pdata(pdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) &config, desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) external_dcvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) /* We assume that high output = regulator off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) * Don't use devm, since we need to get against the parent device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) * so clean up would happen at the wrong time
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) config.ena_gpiod = gpiod_get_optional(parent_dev, "wlf,ldoena",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (IS_ERR(config.ena_gpiod))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return PTR_ERR(config.ena_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ldo1->ena_gpiod = config.ena_gpiod;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) if (pdata->init_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) config.init_data = pdata->init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) config.init_data = &ldo1->init_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) * LDO1 can only be used to supply DCVDD so if it has no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * consumers then DCVDD is supplied externally.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (config.init_data->num_consumer_supplies == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *external_dcvdd = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) ldo1->regulator = devm_regulator_register(&pdev->dev, desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) of_node_put(config.of_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (IS_ERR(ldo1->regulator)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) ret = PTR_ERR(ldo1->regulator);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) dev_err(&pdev->dev, "Failed to register LDO1 supply: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) platform_set_drvdata(pdev, ldo1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) static int arizona_ldo1_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) struct arizona *arizona = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) struct arizona_ldo1 *ldo1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) const struct regulator_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) bool external_dcvdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (!ldo1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) ldo1->regmap = arizona->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) * Since the chip usually supplies itself we provide some
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * default init_data for it. This will be overridden with
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * platform data if provided.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) switch (arizona->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) case WM5102:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) case WM8997:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) case WM8998:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) case WM1814:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) desc = &arizona_ldo1_hc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) ldo1->init_data = arizona_ldo1_dvfs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) case WM5110:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) case WM8280:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) desc = &arizona_ldo1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) ldo1->init_data = arizona_ldo1_wm5110;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) desc = &arizona_ldo1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) ldo1->init_data = arizona_ldo1_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) ret = arizona_ldo1_common_init(pdev, ldo1, desc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) &arizona->pdata.ldo1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) &external_dcvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if (ret == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) arizona->external_dcvdd = external_dcvdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int arizona_ldo1_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) struct arizona_ldo1 *ldo1 = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) if (ldo1->ena_gpiod)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) gpiod_put(ldo1->ena_gpiod);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static int madera_ldo1_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) struct madera *madera = dev_get_drvdata(pdev->dev.parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) struct arizona_ldo1 *ldo1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) bool external_dcvdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) ldo1 = devm_kzalloc(&pdev->dev, sizeof(*ldo1), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (!ldo1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) ldo1->regmap = madera->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) ldo1->init_data = madera_ldo1_default;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) ret = arizona_ldo1_common_init(pdev, ldo1, &madera_ldo1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) &madera->pdata.ldo1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) &external_dcvdd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) madera->internal_dcvdd = !external_dcvdd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) static struct platform_driver arizona_ldo1_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) .probe = arizona_ldo1_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) .remove = arizona_ldo1_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) .name = "arizona-ldo1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static struct platform_driver madera_ldo1_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) .probe = madera_ldo1_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) .remove = arizona_ldo1_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .name = "madera-ldo1",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) static struct platform_driver * const madera_ldo1_drivers[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) &arizona_ldo1_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) &madera_ldo1_driver,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) static int __init arizona_ldo1_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) return platform_register_drivers(madera_ldo1_drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) ARRAY_SIZE(madera_ldo1_drivers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) module_init(arizona_ldo1_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static void __exit madera_ldo1_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) platform_unregister_drivers(madera_ldo1_drivers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) ARRAY_SIZE(madera_ldo1_drivers));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) module_exit(madera_ldo1_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) /* Module information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) MODULE_DESCRIPTION("Arizona LDO1 driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) MODULE_ALIAS("platform:arizona-ldo1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) MODULE_ALIAS("platform:madera-ldo1");