^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * tps65023-regulator.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Supports TPS65023 Regulator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2009 Texas Instrument Incorporated - https://www.ti.com/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * modify it under the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * published by the Free Software Foundation version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * whether express or implied; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/kernel.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/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) /* Register definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define TPS65023_REG_VERSION 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define TPS65023_REG_PGOODZ 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define TPS65023_REG_MASK 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define TPS65023_REG_REG_CTRL 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #define TPS65023_REG_CON_CTRL 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define TPS65023_REG_CON_CTRL2 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #define TPS65023_REG_DEF_CORE 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #define TPS65023_REG_DEFSLEW 7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #define TPS65023_REG_LDO_CTRL 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) /* PGOODZ bitfields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) #define TPS65023_PGOODZ_PWRFAILZ BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #define TPS65023_PGOODZ_LOWBATTZ BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define TPS65023_PGOODZ_VDCDC1 BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define TPS65023_PGOODZ_VDCDC2 BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define TPS65023_PGOODZ_VDCDC3 BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define TPS65023_PGOODZ_LDO2 BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define TPS65023_PGOODZ_LDO1 BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* MASK bitfields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define TPS65023_MASK_PWRFAILZ BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define TPS65023_MASK_LOWBATTZ BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define TPS65023_MASK_VDCDC1 BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define TPS65023_MASK_VDCDC2 BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define TPS65023_MASK_VDCDC3 BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #define TPS65023_MASK_LDO2 BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define TPS65023_MASK_LDO1 BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* REG_CTRL bitfields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define TPS65023_REG_CTRL_VDCDC1_EN BIT(5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define TPS65023_REG_CTRL_VDCDC2_EN BIT(4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) #define TPS65023_REG_CTRL_VDCDC3_EN BIT(3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) #define TPS65023_REG_CTRL_LDO2_EN BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) #define TPS65023_REG_CTRL_LDO1_EN BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) /* REG_CTRL2 bitfields */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #define TPS65023_REG_CTRL2_GO BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #define TPS65023_REG_CTRL2_CORE_ADJ BIT(6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define TPS65023_REG_CTRL2_DCDC2 BIT(2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #define TPS65023_REG_CTRL2_DCDC1 BIT(1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #define TPS65023_REG_CTRL2_DCDC3 BIT(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) /* Number of step-down converters available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #define TPS65023_NUM_DCDC 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* Number of LDO voltage regulators available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define TPS65023_NUM_LDO 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) /* Number of total regulators available */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #define TPS65023_NUM_REGULATOR (TPS65023_NUM_DCDC + TPS65023_NUM_LDO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /* DCDCs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define TPS65023_DCDC_1 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) #define TPS65023_DCDC_2 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #define TPS65023_DCDC_3 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* LDOs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define TPS65023_LDO_1 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) #define TPS65023_LDO_2 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #define TPS65023_MAX_REG_ID TPS65023_LDO_2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) #define TPS65023_REGULATOR_DCDC(_num, _t, _em) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) .name = "VDCDC"#_num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) .of_match = of_match_ptr("VDCDC"#_num), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) .id = TPS65023_DCDC_##_num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) .n_voltages = ARRAY_SIZE(_t), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) .ops = &tps65023_dcdc_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) .volt_table = _t, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) .vsel_reg = TPS65023_REG_DEF_CORE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .vsel_mask = ARRAY_SIZE(_t) - 1, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) .enable_mask = _em, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .enable_reg = TPS65023_REG_REG_CTRL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .apply_reg = TPS65023_REG_CON_CTRL2, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .apply_bit = TPS65023_REG_CTRL2_GO, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) #define TPS65023_REGULATOR_LDO(_num, _t, _vm) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) { \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) .name = "LDO"#_num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) .of_match = of_match_ptr("LDO"#_num), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) .regulators_node = of_match_ptr("regulators"), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) .id = TPS65023_LDO_##_num, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) .n_voltages = ARRAY_SIZE(_t), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) .ops = &tps65023_ldo_ops, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) .type = REGULATOR_VOLTAGE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) .owner = THIS_MODULE, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) .volt_table = _t, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .vsel_reg = TPS65023_REG_LDO_CTRL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .vsel_mask = _vm, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) .enable_mask = 1 << (_num), \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) .enable_reg = TPS65023_REG_REG_CTRL, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) } \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* Supported voltage values for regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) static const unsigned int VCORE_VSEL_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 800000, 825000, 850000, 875000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 900000, 925000, 950000, 975000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 1000000, 1025000, 1050000, 1075000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 1100000, 1125000, 1150000, 1175000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 1200000, 1225000, 1250000, 1275000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 1300000, 1325000, 1350000, 1375000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 1400000, 1425000, 1450000, 1475000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 1500000, 1525000, 1550000, 1600000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) static const unsigned int DCDC_FIXED_3300000_VSEL_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) /* Supported voltage values for LDO regulators for tps65020 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) static const unsigned int TPS65020_LDO_VSEL_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 1000000, 1050000, 1100000, 1300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 1800000, 2500000, 3000000, 3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /* Supported voltage values for LDO regulators
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * for tps65021 and tps65023 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static const unsigned int TPS65023_LDO1_VSEL_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 1000000, 1100000, 1300000, 1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 2200000, 2600000, 2800000, 3150000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) static const unsigned int TPS65023_LDO2_VSEL_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 1050000, 1200000, 1300000, 1800000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 2500000, 2800000, 3000000, 3300000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /* PMIC details */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct tps_pmic {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct regulator_dev *rdev[TPS65023_NUM_REGULATOR];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) const struct tps_driver_data *driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* Struct passed as driver data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) struct tps_driver_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) const struct regulator_desc *desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) u8 core_regulator;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static int tps65023_dcdc_get_voltage_sel(struct regulator_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct tps_pmic *tps = rdev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int dcdc = rdev_get_id(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) if (dcdc != tps->driver_data->core_regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return regulator_get_voltage_sel_regmap(dev);
^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 tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unsigned selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) struct tps_pmic *tps = rdev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int dcdc = rdev_get_id(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (dcdc != tps->driver_data->core_regulator)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return regulator_set_voltage_sel_regmap(dev, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Operations permitted on VDCDCx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) static const struct regulator_ops tps65023_dcdc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) .get_voltage_sel = tps65023_dcdc_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) .set_voltage_sel = tps65023_dcdc_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) .list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) .map_voltage = regulator_map_voltage_ascend,
^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) /* Operations permitted on LDOx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static const struct regulator_ops tps65023_ldo_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) .is_enabled = regulator_is_enabled_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) .enable = regulator_enable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .disable = regulator_disable_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .get_voltage_sel = regulator_get_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .set_voltage_sel = regulator_set_voltage_sel_regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) .list_voltage = regulator_list_voltage_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) .map_voltage = regulator_map_voltage_ascend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static const struct regmap_config tps65023_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) static const struct regulator_desc tps65020_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) TPS65023_REGULATOR_LDO(1, TPS65020_LDO_VSEL_table, 0x07),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) TPS65023_REGULATOR_LDO(2, TPS65020_LDO_VSEL_table, 0x70),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) static const struct regulator_desc tps65021_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) static const struct regulator_desc tps65023_regulators[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) TPS65023_REGULATOR_DCDC(1, VCORE_VSEL_table, 0x20),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_3300000_VSEL_table, 0x10),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) TPS65023_REGULATOR_DCDC(3, DCDC_FIXED_1800000_VSEL_table, 0x08),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static struct tps_driver_data tps65020_drv_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) .desc = tps65020_regulators,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) .core_regulator = TPS65023_DCDC_3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static struct tps_driver_data tps65021_drv_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .desc = tps65021_regulators,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .core_regulator = TPS65023_DCDC_3,
^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 struct tps_driver_data tps65023_drv_data = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .desc = tps65023_regulators,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) .core_regulator = TPS65023_DCDC_1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static int tps_65023_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) struct regulator_init_data *init_data = dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct tps_pmic *tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (!tps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) tps->driver_data = (struct tps_driver_data *)id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (IS_ERR(tps->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) error = PTR_ERR(tps->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) dev_err(&client->dev, "Failed to allocate register map: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) error);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* common for all regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) config.dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) config.driver_data = tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) config.regmap = tps->regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) for (i = 0; i < TPS65023_NUM_REGULATOR; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) if (init_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) config.init_data = &init_data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) /* Register the regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) tps->rdev[i] = devm_regulator_register(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) &tps->driver_data->desc[i], &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (IS_ERR(tps->rdev[i])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) dev_err(&client->dev, "failed to register %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) id->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) return PTR_ERR(tps->rdev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^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) i2c_set_clientdata(client, tps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) /* Enable setting output voltage by I2C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) TPS65023_REG_CTRL2_CORE_ADJ, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) static const struct of_device_id __maybe_unused tps65023_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) { .compatible = "ti,tps65020", .data = &tps65020_drv_data},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) { .compatible = "ti,tps65021", .data = &tps65021_drv_data},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) { .compatible = "ti,tps65023", .data = &tps65023_drv_data},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) MODULE_DEVICE_TABLE(of, tps65023_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) static const struct i2c_device_id tps_65023_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .name = "tps65023",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) .driver_data = (kernel_ulong_t)&tps65023_drv_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) .name = "tps65021",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) .driver_data = (kernel_ulong_t)&tps65021_drv_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) }, {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) .name = "tps65020",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) .driver_data = (kernel_ulong_t)&tps65020_drv_data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) { },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) MODULE_DEVICE_TABLE(i2c, tps_65023_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static struct i2c_driver tps_65023_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) .name = "tps65023",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .of_match_table = of_match_ptr(tps65023_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .probe = tps_65023_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .id_table = tps_65023_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static int __init tps_65023_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) return i2c_add_driver(&tps_65023_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) subsys_initcall(tps_65023_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) static void __exit tps_65023_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) i2c_del_driver(&tps_65023_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) module_exit(tps_65023_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) MODULE_AUTHOR("Texas Instruments");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) MODULE_DESCRIPTION("TPS65023 voltage regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) MODULE_LICENSE("GPL v2");