^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * tps62360.c -- TI tps62360
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Driver for processor core supply tps62360, tps62361B, tps62362 and tps62363.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (c) 2012, NVIDIA Corporation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Author: Laxman Dewangan <ldewangan@nvidia.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * modify it under the terms of the GNU General Public License as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * published by the Free Software Foundation version 2.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * whether express or implied; without even the implied warranty of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * General Public License for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * You should have received a copy of the GNU General Public License
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * along with this program; if not, write to the Free Software
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) * 02111-1307, USA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <linux/of.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include <linux/of_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #include <linux/regulator/of_regulator.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/regulator/driver.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/regulator/machine.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/regulator/tps62360.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <linux/regmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* Register definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define REG_VSET0 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define REG_VSET1 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define REG_VSET2 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #define REG_VSET3 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define REG_CONTROL 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define REG_TEMP 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define REG_RAMPCTRL 6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define REG_CHIPID 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) #define FORCE_PWM_ENABLE BIT(7)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) enum chips {TPS62360, TPS62361, TPS62362, TPS62363};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define TPS62360_BASE_VOLTAGE 770000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define TPS62360_N_VOLTAGES 64
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #define TPS62361_BASE_VOLTAGE 500000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) #define TPS62361_N_VOLTAGES 128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* tps 62360 chip information */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct tps62360_chip {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct regulator_desc desc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct regmap *regmap;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int vsel0_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) int vsel1_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) u8 voltage_reg_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) bool en_internal_pulldn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) bool en_discharge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) bool valid_gpios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) int lru_index[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) int curr_vset_vsel[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) int curr_vset_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) * find_voltage_set_register: Find new voltage configuration register
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * (VSET) id.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * The finding of the new VSET register will be based on the LRU mechanism.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * Each VSET register will have different voltage configured . This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * Function will look if any of the VSET register have requested voltage set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * or not.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * - If it is already there then it will make that register as most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * recently used and return as found so that caller need not to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * the VSET register but need to set the proper gpios to select this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) * VSET register.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * - If requested voltage is not found then it will use the least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * recently mechanism to get new VSET register for new configuration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * and will return not_found so that caller need to set new VSET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * register and then gpios (both).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) static bool find_voltage_set_register(struct tps62360_chip *tps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int req_vsel, int *vset_reg_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int new_vset_reg = tps->lru_index[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int found_index = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) for (i = 0; i < 4; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) new_vset_reg = tps->lru_index[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) found_index = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) found = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) goto update_lru_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) update_lru_index:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) for (i = found_index; i > 0; i--)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) tps->lru_index[i] = tps->lru_index[i - 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) tps->lru_index[0] = new_vset_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) *vset_reg_id = new_vset_reg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return found;
^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 int tps62360_dcdc_get_voltage_sel(struct regulator_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct tps62360_chip *tps = rdev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int vsel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) unsigned int data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) __func__, REG_VSET0 + tps->curr_vset_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) vsel = (int)data & tps->voltage_reg_mask;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return vsel;
^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 int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) unsigned selector)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct tps62360_chip *tps = rdev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) bool found = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int new_vset_id = tps->curr_vset_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * If gpios are available to select the VSET register then least
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * recently used register for new configuration.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (tps->valid_gpios)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) found = find_voltage_set_register(tps, selector, &new_vset_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) tps->voltage_reg_mask, selector);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) "%s(): register %d update failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) __func__, REG_VSET0 + new_vset_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) tps->curr_vset_id = new_vset_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) tps->curr_vset_vsel[new_vset_id] = selector;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) /* Select proper VSET register vio gpios */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) if (tps->valid_gpios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) gpio_set_value_cansleep(tps->vsel1_gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) (new_vset_id >> 1) & 0x1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct tps62360_chip *tps = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) int val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* Enable force PWM mode in FAST mode only. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) case REGULATOR_MODE_FAST:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) val = FORCE_PWM_ENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case REGULATOR_MODE_NORMAL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!tps->valid_gpios) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) ret = regmap_update_bits(tps->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (ret < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) "%s(): register %d update failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) __func__, REG_VSET0 + tps->curr_vset_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* If gpios are valid then all register set need to be control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) for (i = 0; i < 4; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) ret = regmap_update_bits(tps->regmap,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) REG_VSET0 + i, FORCE_PWM_ENABLE, val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) "%s(): register %d update failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) __func__, REG_VSET0 + i, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static unsigned int tps62360_get_mode(struct regulator_dev *rdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct tps62360_chip *tps = rdev_get_drvdata(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) unsigned int data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) __func__, REG_VSET0 + tps->curr_vset_id, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) return (data & FORCE_PWM_ENABLE) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) static const struct regulator_ops tps62360_dcdc_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .list_voltage = regulator_list_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .map_voltage = regulator_map_voltage_linear,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) .set_voltage_time_sel = regulator_set_voltage_time_sel,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .set_mode = tps62360_set_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .get_mode = tps62360_get_mode,
^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) static int tps62360_init_dcdc(struct tps62360_chip *tps,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct tps62360_regulator_platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned int ramp_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) /* Initialize internal pull up/down control */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if (tps->en_internal_pulldn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) "%s(): register %d write failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) __func__, REG_CONTROL, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) /* Reset output discharge path to reduce power consumption */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) "%s(): register %d update failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) __func__, REG_RAMPCTRL, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return ret;
^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) /* Get ramp value from ramp control register */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) "%s(): register %d read failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) __func__, REG_RAMPCTRL, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) ramp_ctrl = (ramp_ctrl >> 5) & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) /* ramp mV/us = 32/(2^ramp_ctrl) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) tps->desc.ramp_delay = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static const struct regmap_config tps62360_regmap_config = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) .reg_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) .val_bits = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) .max_register = REG_CHIPID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) .cache_type = REGCACHE_RBTREE,
^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 struct tps62360_regulator_platform_data *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) of_get_tps62360_platform_data(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) const struct regulator_desc *desc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct tps62360_regulator_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) struct device_node *np = dev->of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (!pdata->reg_init_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) dev_err(dev, "Not able to get OF regulator init data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (of_find_property(np, "ti,vsel0-state-high", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) pdata->vsel0_def_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (of_find_property(np, "ti,vsel1-state-high", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) pdata->vsel1_def_state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) if (of_find_property(np, "ti,enable-pull-down", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) pdata->en_internal_pulldn = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (of_find_property(np, "ti,enable-vout-discharge", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) pdata->en_discharge = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) return pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) #if defined(CONFIG_OF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) static const struct of_device_id tps62360_of_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) { .compatible = "ti,tps62360", .data = (void *)TPS62360},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) { .compatible = "ti,tps62361", .data = (void *)TPS62361},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) { .compatible = "ti,tps62362", .data = (void *)TPS62362},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) { .compatible = "ti,tps62363", .data = (void *)TPS62363},
^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) MODULE_DEVICE_TABLE(of, tps62360_of_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) static int tps62360_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) struct regulator_config config = { };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) struct tps62360_regulator_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) struct regulator_dev *rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) struct tps62360_chip *tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) int chip_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) pdata = dev_get_platdata(&client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) if (!tps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) tps->desc.name = client->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) tps->desc.id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) tps->desc.ops = &tps62360_dcdc_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) tps->desc.type = REGULATOR_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) tps->desc.owner = THIS_MODULE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) tps->desc.uV_step = 10000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) if (client->dev.of_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) const struct of_device_id *match;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) match = of_match_device(of_match_ptr(tps62360_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) &client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) if (!match) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) dev_err(&client->dev, "Error: No device match found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) chip_id = (int)(long)match->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) pdata = of_get_tps62360_platform_data(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) &tps->desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) } else if (id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) chip_id = id->driver_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) dev_err(&client->dev, "No device tree match or id table match found\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) return -ENODEV;
^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) if (!pdata) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) dev_err(&client->dev, "%s(): Platform data not found\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) tps->en_discharge = pdata->en_discharge;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) tps->en_internal_pulldn = pdata->en_internal_pulldn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) tps->vsel0_gpio = pdata->vsel0_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) tps->vsel1_gpio = pdata->vsel1_gpio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) tps->dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) switch (chip_id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) case TPS62360:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) case TPS62362:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) tps->desc.min_uV = TPS62360_BASE_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) tps->voltage_reg_mask = 0x3F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) tps->desc.n_voltages = TPS62360_N_VOLTAGES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) case TPS62361:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) case TPS62363:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) tps->desc.min_uV = TPS62361_BASE_VOLTAGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) tps->voltage_reg_mask = 0x7F;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) tps->desc.n_voltages = TPS62361_N_VOLTAGES;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (IS_ERR(tps->regmap)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) ret = PTR_ERR(tps->regmap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) "%s(): regmap allocation failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) i2c_set_clientdata(client, tps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) (pdata->vsel0_def_state & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) tps->lru_index[0] = tps->curr_vset_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) tps->valid_gpios = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) int gpio_flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) gpio_flags = (pdata->vsel0_def_state) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) ret = devm_gpio_request_one(&client->dev, tps->vsel0_gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) gpio_flags, "tps62360-vsel0");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) "%s(): Could not obtain vsel0 GPIO %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) __func__, tps->vsel0_gpio, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) gpio_flags = (pdata->vsel1_def_state) ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) ret = devm_gpio_request_one(&client->dev, tps->vsel1_gpio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) gpio_flags, "tps62360-vsel1");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) dev_err(&client->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) "%s(): Could not obtain vsel1 GPIO %d: %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) __func__, tps->vsel1_gpio, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) tps->valid_gpios = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) * Initialize the lru index with vset_reg id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) * The index 0 will be most recently used and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) * set with the tps->curr_vset_id */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) for (i = 0; i < 4; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) tps->lru_index[i] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) tps->lru_index[0] = tps->curr_vset_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) tps->lru_index[tps->curr_vset_id] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) ret = tps62360_init_dcdc(tps, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) dev_err(tps->dev, "%s(): Init failed with err = %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) __func__, ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) config.dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) config.init_data = pdata->reg_init_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) config.driver_data = tps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) config.of_node = client->dev.of_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) /* Register the regulators */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) rdev = devm_regulator_register(&client->dev, &tps->desc, &config);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) if (IS_ERR(rdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) "%s(): regulator register failed with err %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) __func__, id->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) return PTR_ERR(rdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) tps->rdev = rdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) static void tps62360_shutdown(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) struct tps62360_chip *tps = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) int st;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) if (!tps->en_discharge)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /* Configure the output discharge path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) if (st < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) dev_err(tps->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) "%s(): register %d update failed with err %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) __func__, REG_RAMPCTRL, st);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) static const struct i2c_device_id tps62360_id[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) {.name = "tps62360", .driver_data = TPS62360},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) {.name = "tps62361", .driver_data = TPS62361},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) {.name = "tps62362", .driver_data = TPS62362},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) {.name = "tps62363", .driver_data = TPS62363},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) MODULE_DEVICE_TABLE(i2c, tps62360_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) static struct i2c_driver tps62360_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) .name = "tps62360",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) .of_match_table = of_match_ptr(tps62360_of_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) .probe = tps62360_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) .shutdown = tps62360_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) .id_table = tps62360_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) static int __init tps62360_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) return i2c_add_driver(&tps62360_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) subsys_initcall(tps62360_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) static void __exit tps62360_cleanup(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) i2c_del_driver(&tps62360_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) module_exit(tps62360_cleanup);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) MODULE_LICENSE("GPL v2");