18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * tps51632-regulator.c -- TI TPS51632 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Regulator driver for TPS51632 3-2-1 Phase D-Cap Step Down Driverless 58c2ecf20Sopenharmony_ci * Controller with serial VID control and DVFS. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Copyright (c) 2012, NVIDIA Corporation. 88c2ecf20Sopenharmony_ci * 98c2ecf20Sopenharmony_ci * Author: Laxman Dewangan <ldewangan@nvidia.com> 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or 128c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License as 138c2ecf20Sopenharmony_ci * published by the Free Software Foundation version 2. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 168c2ecf20Sopenharmony_ci * whether express or implied; without even the implied warranty of 178c2ecf20Sopenharmony_ci * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 188c2ecf20Sopenharmony_ci * General Public License for more details. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * You should have received a copy of the GNU General Public License 218c2ecf20Sopenharmony_ci * along with this program; if not, write to the Free Software 228c2ecf20Sopenharmony_ci * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 238c2ecf20Sopenharmony_ci * 02111-1307, USA 248c2ecf20Sopenharmony_ci */ 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci#include <linux/err.h> 278c2ecf20Sopenharmony_ci#include <linux/i2c.h> 288c2ecf20Sopenharmony_ci#include <linux/init.h> 298c2ecf20Sopenharmony_ci#include <linux/kernel.h> 308c2ecf20Sopenharmony_ci#include <linux/module.h> 318c2ecf20Sopenharmony_ci#include <linux/of.h> 328c2ecf20Sopenharmony_ci#include <linux/of_device.h> 338c2ecf20Sopenharmony_ci#include <linux/platform_device.h> 348c2ecf20Sopenharmony_ci#include <linux/regmap.h> 358c2ecf20Sopenharmony_ci#include <linux/regulator/driver.h> 368c2ecf20Sopenharmony_ci#include <linux/regulator/machine.h> 378c2ecf20Sopenharmony_ci#include <linux/regulator/of_regulator.h> 388c2ecf20Sopenharmony_ci#include <linux/regulator/tps51632-regulator.h> 398c2ecf20Sopenharmony_ci#include <linux/slab.h> 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ci/* Register definitions */ 428c2ecf20Sopenharmony_ci#define TPS51632_VOLTAGE_SELECT_REG 0x0 438c2ecf20Sopenharmony_ci#define TPS51632_VOLTAGE_BASE_REG 0x1 448c2ecf20Sopenharmony_ci#define TPS51632_OFFSET_REG 0x2 458c2ecf20Sopenharmony_ci#define TPS51632_IMON_REG 0x3 468c2ecf20Sopenharmony_ci#define TPS51632_VMAX_REG 0x4 478c2ecf20Sopenharmony_ci#define TPS51632_DVFS_CONTROL_REG 0x5 488c2ecf20Sopenharmony_ci#define TPS51632_POWER_STATE_REG 0x6 498c2ecf20Sopenharmony_ci#define TPS51632_SLEW_REGS 0x7 508c2ecf20Sopenharmony_ci#define TPS51632_FAULT_REG 0x14 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define TPS51632_MAX_REG 0x15 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ci#define TPS51632_VOUT_MASK 0x7F 558c2ecf20Sopenharmony_ci#define TPS51632_VOUT_OFFSET_MASK 0x1F 568c2ecf20Sopenharmony_ci#define TPS51632_VMAX_MASK 0x7F 578c2ecf20Sopenharmony_ci#define TPS51632_VMAX_LOCK 0x80 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci/* TPS51632_DVFS_CONTROL_REG */ 608c2ecf20Sopenharmony_ci#define TPS51632_DVFS_PWMEN 0x1 618c2ecf20Sopenharmony_ci#define TPS51632_DVFS_STEP_20 0x2 628c2ecf20Sopenharmony_ci#define TPS51632_DVFS_VMAX_PG 0x4 638c2ecf20Sopenharmony_ci#define TPS51632_DVFS_PWMRST 0x8 648c2ecf20Sopenharmony_ci#define TPS51632_DVFS_OCA_EN 0x10 658c2ecf20Sopenharmony_ci#define TPS51632_DVFS_FCCM 0x20 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_ci/* TPS51632_POWER_STATE_REG */ 688c2ecf20Sopenharmony_ci#define TPS51632_POWER_STATE_MASK 0x03 698c2ecf20Sopenharmony_ci#define TPS51632_POWER_STATE_MULTI_PHASE_CCM 0x0 708c2ecf20Sopenharmony_ci#define TPS51632_POWER_STATE_SINGLE_PHASE_CCM 0x1 718c2ecf20Sopenharmony_ci#define TPS51632_POWER_STATE_SINGLE_PHASE_DCM 0x2 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_ci#define TPS51632_MIN_VOLTAGE 500000 748c2ecf20Sopenharmony_ci#define TPS51632_MAX_VOLTAGE 1520000 758c2ecf20Sopenharmony_ci#define TPS51632_VOLTAGE_STEP_10mV 10000 768c2ecf20Sopenharmony_ci#define TPS51632_VOLTAGE_STEP_20mV 20000 778c2ecf20Sopenharmony_ci#define TPS51632_MAX_VSEL 0x7F 788c2ecf20Sopenharmony_ci#define TPS51632_MIN_VSEL 0x19 798c2ecf20Sopenharmony_ci#define TPS51632_DEFAULT_RAMP_DELAY 6000 808c2ecf20Sopenharmony_ci#define TPS51632_VOLT_VSEL(uV) \ 818c2ecf20Sopenharmony_ci (DIV_ROUND_UP(uV - TPS51632_MIN_VOLTAGE, \ 828c2ecf20Sopenharmony_ci TPS51632_VOLTAGE_STEP_10mV) + \ 838c2ecf20Sopenharmony_ci TPS51632_MIN_VSEL) 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci/* TPS51632 chip information */ 868c2ecf20Sopenharmony_cistruct tps51632_chip { 878c2ecf20Sopenharmony_ci struct device *dev; 888c2ecf20Sopenharmony_ci struct regulator_desc desc; 898c2ecf20Sopenharmony_ci struct regulator_dev *rdev; 908c2ecf20Sopenharmony_ci struct regmap *regmap; 918c2ecf20Sopenharmony_ci}; 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistatic int tps51632_dcdc_set_ramp_delay(struct regulator_dev *rdev, 948c2ecf20Sopenharmony_ci int ramp_delay) 958c2ecf20Sopenharmony_ci{ 968c2ecf20Sopenharmony_ci struct tps51632_chip *tps = rdev_get_drvdata(rdev); 978c2ecf20Sopenharmony_ci int bit; 988c2ecf20Sopenharmony_ci int ret; 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci if (ramp_delay == 0) 1018c2ecf20Sopenharmony_ci bit = 0; 1028c2ecf20Sopenharmony_ci else 1038c2ecf20Sopenharmony_ci bit = DIV_ROUND_UP(ramp_delay, 6000) - 1; 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci ret = regmap_write(tps->regmap, TPS51632_SLEW_REGS, BIT(bit)); 1068c2ecf20Sopenharmony_ci if (ret < 0) 1078c2ecf20Sopenharmony_ci dev_err(tps->dev, "SLEW reg write failed, err %d\n", ret); 1088c2ecf20Sopenharmony_ci return ret; 1098c2ecf20Sopenharmony_ci} 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistatic const struct regulator_ops tps51632_dcdc_ops = { 1128c2ecf20Sopenharmony_ci .get_voltage_sel = regulator_get_voltage_sel_regmap, 1138c2ecf20Sopenharmony_ci .set_voltage_sel = regulator_set_voltage_sel_regmap, 1148c2ecf20Sopenharmony_ci .list_voltage = regulator_list_voltage_linear, 1158c2ecf20Sopenharmony_ci .set_voltage_time_sel = regulator_set_voltage_time_sel, 1168c2ecf20Sopenharmony_ci .set_ramp_delay = tps51632_dcdc_set_ramp_delay, 1178c2ecf20Sopenharmony_ci}; 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic int tps51632_init_dcdc(struct tps51632_chip *tps, 1208c2ecf20Sopenharmony_ci struct tps51632_regulator_platform_data *pdata) 1218c2ecf20Sopenharmony_ci{ 1228c2ecf20Sopenharmony_ci int ret; 1238c2ecf20Sopenharmony_ci uint8_t control = 0; 1248c2ecf20Sopenharmony_ci int vsel; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci if (!pdata->enable_pwm_dvfs) 1278c2ecf20Sopenharmony_ci goto skip_pwm_config; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci control |= TPS51632_DVFS_PWMEN; 1308c2ecf20Sopenharmony_ci vsel = TPS51632_VOLT_VSEL(pdata->base_voltage_uV); 1318c2ecf20Sopenharmony_ci ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_BASE_REG, vsel); 1328c2ecf20Sopenharmony_ci if (ret < 0) { 1338c2ecf20Sopenharmony_ci dev_err(tps->dev, "BASE reg write failed, err %d\n", ret); 1348c2ecf20Sopenharmony_ci return ret; 1358c2ecf20Sopenharmony_ci } 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_ci if (pdata->dvfs_step_20mV) 1388c2ecf20Sopenharmony_ci control |= TPS51632_DVFS_STEP_20; 1398c2ecf20Sopenharmony_ci 1408c2ecf20Sopenharmony_ci if (pdata->max_voltage_uV) { 1418c2ecf20Sopenharmony_ci unsigned int vmax; 1428c2ecf20Sopenharmony_ci /** 1438c2ecf20Sopenharmony_ci * TPS51632 hw behavior: VMAX register can be write only 1448c2ecf20Sopenharmony_ci * once as it get locked after first write. The lock get 1458c2ecf20Sopenharmony_ci * reset only when device is power-reset. 1468c2ecf20Sopenharmony_ci * Write register only when lock bit is not enabled. 1478c2ecf20Sopenharmony_ci */ 1488c2ecf20Sopenharmony_ci ret = regmap_read(tps->regmap, TPS51632_VMAX_REG, &vmax); 1498c2ecf20Sopenharmony_ci if (ret < 0) { 1508c2ecf20Sopenharmony_ci dev_err(tps->dev, "VMAX read failed, err %d\n", ret); 1518c2ecf20Sopenharmony_ci return ret; 1528c2ecf20Sopenharmony_ci } 1538c2ecf20Sopenharmony_ci if (!(vmax & TPS51632_VMAX_LOCK)) { 1548c2ecf20Sopenharmony_ci vsel = TPS51632_VOLT_VSEL(pdata->max_voltage_uV); 1558c2ecf20Sopenharmony_ci ret = regmap_write(tps->regmap, TPS51632_VMAX_REG, 1568c2ecf20Sopenharmony_ci vsel); 1578c2ecf20Sopenharmony_ci if (ret < 0) { 1588c2ecf20Sopenharmony_ci dev_err(tps->dev, 1598c2ecf20Sopenharmony_ci "VMAX write failed, err %d\n", ret); 1608c2ecf20Sopenharmony_ci return ret; 1618c2ecf20Sopenharmony_ci } 1628c2ecf20Sopenharmony_ci } 1638c2ecf20Sopenharmony_ci } 1648c2ecf20Sopenharmony_ci 1658c2ecf20Sopenharmony_ciskip_pwm_config: 1668c2ecf20Sopenharmony_ci ret = regmap_write(tps->regmap, TPS51632_DVFS_CONTROL_REG, control); 1678c2ecf20Sopenharmony_ci if (ret < 0) 1688c2ecf20Sopenharmony_ci dev_err(tps->dev, "DVFS reg write failed, err %d\n", ret); 1698c2ecf20Sopenharmony_ci return ret; 1708c2ecf20Sopenharmony_ci} 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistatic bool is_volatile_reg(struct device *dev, unsigned int reg) 1738c2ecf20Sopenharmony_ci{ 1748c2ecf20Sopenharmony_ci switch (reg) { 1758c2ecf20Sopenharmony_ci case TPS51632_OFFSET_REG: 1768c2ecf20Sopenharmony_ci case TPS51632_FAULT_REG: 1778c2ecf20Sopenharmony_ci case TPS51632_IMON_REG: 1788c2ecf20Sopenharmony_ci return true; 1798c2ecf20Sopenharmony_ci default: 1808c2ecf20Sopenharmony_ci return false; 1818c2ecf20Sopenharmony_ci } 1828c2ecf20Sopenharmony_ci} 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_cistatic bool is_read_reg(struct device *dev, unsigned int reg) 1858c2ecf20Sopenharmony_ci{ 1868c2ecf20Sopenharmony_ci switch (reg) { 1878c2ecf20Sopenharmony_ci case 0x08 ... 0x0F: 1888c2ecf20Sopenharmony_ci return false; 1898c2ecf20Sopenharmony_ci default: 1908c2ecf20Sopenharmony_ci return true; 1918c2ecf20Sopenharmony_ci } 1928c2ecf20Sopenharmony_ci} 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistatic bool is_write_reg(struct device *dev, unsigned int reg) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci switch (reg) { 1978c2ecf20Sopenharmony_ci case TPS51632_VOLTAGE_SELECT_REG: 1988c2ecf20Sopenharmony_ci case TPS51632_VOLTAGE_BASE_REG: 1998c2ecf20Sopenharmony_ci case TPS51632_VMAX_REG: 2008c2ecf20Sopenharmony_ci case TPS51632_DVFS_CONTROL_REG: 2018c2ecf20Sopenharmony_ci case TPS51632_POWER_STATE_REG: 2028c2ecf20Sopenharmony_ci case TPS51632_SLEW_REGS: 2038c2ecf20Sopenharmony_ci return true; 2048c2ecf20Sopenharmony_ci default: 2058c2ecf20Sopenharmony_ci return false; 2068c2ecf20Sopenharmony_ci } 2078c2ecf20Sopenharmony_ci} 2088c2ecf20Sopenharmony_ci 2098c2ecf20Sopenharmony_cistatic const struct regmap_config tps51632_regmap_config = { 2108c2ecf20Sopenharmony_ci .reg_bits = 8, 2118c2ecf20Sopenharmony_ci .val_bits = 8, 2128c2ecf20Sopenharmony_ci .writeable_reg = is_write_reg, 2138c2ecf20Sopenharmony_ci .readable_reg = is_read_reg, 2148c2ecf20Sopenharmony_ci .volatile_reg = is_volatile_reg, 2158c2ecf20Sopenharmony_ci .max_register = TPS51632_MAX_REG - 1, 2168c2ecf20Sopenharmony_ci .cache_type = REGCACHE_RBTREE, 2178c2ecf20Sopenharmony_ci}; 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci#if defined(CONFIG_OF) 2208c2ecf20Sopenharmony_cistatic const struct of_device_id tps51632_of_match[] = { 2218c2ecf20Sopenharmony_ci { .compatible = "ti,tps51632",}, 2228c2ecf20Sopenharmony_ci {}, 2238c2ecf20Sopenharmony_ci}; 2248c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(of, tps51632_of_match); 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistatic struct tps51632_regulator_platform_data * 2278c2ecf20Sopenharmony_ci of_get_tps51632_platform_data(struct device *dev, 2288c2ecf20Sopenharmony_ci const struct regulator_desc *desc) 2298c2ecf20Sopenharmony_ci{ 2308c2ecf20Sopenharmony_ci struct tps51632_regulator_platform_data *pdata; 2318c2ecf20Sopenharmony_ci struct device_node *np = dev->of_node; 2328c2ecf20Sopenharmony_ci 2338c2ecf20Sopenharmony_ci pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL); 2348c2ecf20Sopenharmony_ci if (!pdata) 2358c2ecf20Sopenharmony_ci return NULL; 2368c2ecf20Sopenharmony_ci 2378c2ecf20Sopenharmony_ci pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node, 2388c2ecf20Sopenharmony_ci desc); 2398c2ecf20Sopenharmony_ci if (!pdata->reg_init_data) { 2408c2ecf20Sopenharmony_ci dev_err(dev, "Not able to get OF regulator init data\n"); 2418c2ecf20Sopenharmony_ci return NULL; 2428c2ecf20Sopenharmony_ci } 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci pdata->enable_pwm_dvfs = 2458c2ecf20Sopenharmony_ci of_property_read_bool(np, "ti,enable-pwm-dvfs"); 2468c2ecf20Sopenharmony_ci pdata->dvfs_step_20mV = of_property_read_bool(np, "ti,dvfs-step-20mV"); 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci pdata->base_voltage_uV = pdata->reg_init_data->constraints.min_uV ? : 2498c2ecf20Sopenharmony_ci TPS51632_MIN_VOLTAGE; 2508c2ecf20Sopenharmony_ci pdata->max_voltage_uV = pdata->reg_init_data->constraints.max_uV ? : 2518c2ecf20Sopenharmony_ci TPS51632_MAX_VOLTAGE; 2528c2ecf20Sopenharmony_ci return pdata; 2538c2ecf20Sopenharmony_ci} 2548c2ecf20Sopenharmony_ci#else 2558c2ecf20Sopenharmony_cistatic struct tps51632_regulator_platform_data * 2568c2ecf20Sopenharmony_ci of_get_tps51632_platform_data(struct device *dev, 2578c2ecf20Sopenharmony_ci const struct regulator_desc *desc) 2588c2ecf20Sopenharmony_ci{ 2598c2ecf20Sopenharmony_ci return NULL; 2608c2ecf20Sopenharmony_ci} 2618c2ecf20Sopenharmony_ci#endif 2628c2ecf20Sopenharmony_ci 2638c2ecf20Sopenharmony_cistatic int tps51632_probe(struct i2c_client *client, 2648c2ecf20Sopenharmony_ci const struct i2c_device_id *id) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci struct tps51632_regulator_platform_data *pdata; 2678c2ecf20Sopenharmony_ci struct regulator_dev *rdev; 2688c2ecf20Sopenharmony_ci struct tps51632_chip *tps; 2698c2ecf20Sopenharmony_ci int ret; 2708c2ecf20Sopenharmony_ci struct regulator_config config = { }; 2718c2ecf20Sopenharmony_ci 2728c2ecf20Sopenharmony_ci if (client->dev.of_node) { 2738c2ecf20Sopenharmony_ci const struct of_device_id *match; 2748c2ecf20Sopenharmony_ci match = of_match_device(of_match_ptr(tps51632_of_match), 2758c2ecf20Sopenharmony_ci &client->dev); 2768c2ecf20Sopenharmony_ci if (!match) { 2778c2ecf20Sopenharmony_ci dev_err(&client->dev, "Error: No device match found\n"); 2788c2ecf20Sopenharmony_ci return -ENODEV; 2798c2ecf20Sopenharmony_ci } 2808c2ecf20Sopenharmony_ci } 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 2838c2ecf20Sopenharmony_ci if (!tps) 2848c2ecf20Sopenharmony_ci return -ENOMEM; 2858c2ecf20Sopenharmony_ci 2868c2ecf20Sopenharmony_ci tps->dev = &client->dev; 2878c2ecf20Sopenharmony_ci tps->desc.name = client->name; 2888c2ecf20Sopenharmony_ci tps->desc.id = 0; 2898c2ecf20Sopenharmony_ci tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY; 2908c2ecf20Sopenharmony_ci tps->desc.min_uV = TPS51632_MIN_VOLTAGE; 2918c2ecf20Sopenharmony_ci tps->desc.uV_step = TPS51632_VOLTAGE_STEP_10mV; 2928c2ecf20Sopenharmony_ci tps->desc.linear_min_sel = TPS51632_MIN_VSEL; 2938c2ecf20Sopenharmony_ci tps->desc.n_voltages = TPS51632_MAX_VSEL + 1; 2948c2ecf20Sopenharmony_ci tps->desc.ops = &tps51632_dcdc_ops; 2958c2ecf20Sopenharmony_ci tps->desc.type = REGULATOR_VOLTAGE; 2968c2ecf20Sopenharmony_ci tps->desc.owner = THIS_MODULE; 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci pdata = dev_get_platdata(&client->dev); 2998c2ecf20Sopenharmony_ci if (!pdata && client->dev.of_node) 3008c2ecf20Sopenharmony_ci pdata = of_get_tps51632_platform_data(&client->dev, &tps->desc); 3018c2ecf20Sopenharmony_ci if (!pdata) { 3028c2ecf20Sopenharmony_ci dev_err(&client->dev, "No Platform data\n"); 3038c2ecf20Sopenharmony_ci return -EINVAL; 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci if (pdata->enable_pwm_dvfs) { 3078c2ecf20Sopenharmony_ci if ((pdata->base_voltage_uV < TPS51632_MIN_VOLTAGE) || 3088c2ecf20Sopenharmony_ci (pdata->base_voltage_uV > TPS51632_MAX_VOLTAGE)) { 3098c2ecf20Sopenharmony_ci dev_err(&client->dev, "Invalid base_voltage_uV setting\n"); 3108c2ecf20Sopenharmony_ci return -EINVAL; 3118c2ecf20Sopenharmony_ci } 3128c2ecf20Sopenharmony_ci 3138c2ecf20Sopenharmony_ci if ((pdata->max_voltage_uV) && 3148c2ecf20Sopenharmony_ci ((pdata->max_voltage_uV < TPS51632_MIN_VOLTAGE) || 3158c2ecf20Sopenharmony_ci (pdata->max_voltage_uV > TPS51632_MAX_VOLTAGE))) { 3168c2ecf20Sopenharmony_ci dev_err(&client->dev, "Invalid max_voltage_uV setting\n"); 3178c2ecf20Sopenharmony_ci return -EINVAL; 3188c2ecf20Sopenharmony_ci } 3198c2ecf20Sopenharmony_ci } 3208c2ecf20Sopenharmony_ci 3218c2ecf20Sopenharmony_ci if (pdata->enable_pwm_dvfs) 3228c2ecf20Sopenharmony_ci tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG; 3238c2ecf20Sopenharmony_ci else 3248c2ecf20Sopenharmony_ci tps->desc.vsel_reg = TPS51632_VOLTAGE_SELECT_REG; 3258c2ecf20Sopenharmony_ci tps->desc.vsel_mask = TPS51632_VOUT_MASK; 3268c2ecf20Sopenharmony_ci 3278c2ecf20Sopenharmony_ci tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config); 3288c2ecf20Sopenharmony_ci if (IS_ERR(tps->regmap)) { 3298c2ecf20Sopenharmony_ci ret = PTR_ERR(tps->regmap); 3308c2ecf20Sopenharmony_ci dev_err(&client->dev, "regmap init failed, err %d\n", ret); 3318c2ecf20Sopenharmony_ci return ret; 3328c2ecf20Sopenharmony_ci } 3338c2ecf20Sopenharmony_ci i2c_set_clientdata(client, tps); 3348c2ecf20Sopenharmony_ci 3358c2ecf20Sopenharmony_ci ret = tps51632_init_dcdc(tps, pdata); 3368c2ecf20Sopenharmony_ci if (ret < 0) { 3378c2ecf20Sopenharmony_ci dev_err(tps->dev, "Init failed, err = %d\n", ret); 3388c2ecf20Sopenharmony_ci return ret; 3398c2ecf20Sopenharmony_ci } 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_ci /* Register the regulators */ 3428c2ecf20Sopenharmony_ci config.dev = &client->dev; 3438c2ecf20Sopenharmony_ci config.init_data = pdata->reg_init_data; 3448c2ecf20Sopenharmony_ci config.driver_data = tps; 3458c2ecf20Sopenharmony_ci config.regmap = tps->regmap; 3468c2ecf20Sopenharmony_ci config.of_node = client->dev.of_node; 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci rdev = devm_regulator_register(&client->dev, &tps->desc, &config); 3498c2ecf20Sopenharmony_ci if (IS_ERR(rdev)) { 3508c2ecf20Sopenharmony_ci dev_err(tps->dev, "regulator register failed\n"); 3518c2ecf20Sopenharmony_ci return PTR_ERR(rdev); 3528c2ecf20Sopenharmony_ci } 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci tps->rdev = rdev; 3558c2ecf20Sopenharmony_ci return 0; 3568c2ecf20Sopenharmony_ci} 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_cistatic const struct i2c_device_id tps51632_id[] = { 3598c2ecf20Sopenharmony_ci {.name = "tps51632",}, 3608c2ecf20Sopenharmony_ci {}, 3618c2ecf20Sopenharmony_ci}; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(i2c, tps51632_id); 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_cistatic struct i2c_driver tps51632_i2c_driver = { 3668c2ecf20Sopenharmony_ci .driver = { 3678c2ecf20Sopenharmony_ci .name = "tps51632", 3688c2ecf20Sopenharmony_ci .of_match_table = of_match_ptr(tps51632_of_match), 3698c2ecf20Sopenharmony_ci }, 3708c2ecf20Sopenharmony_ci .probe = tps51632_probe, 3718c2ecf20Sopenharmony_ci .id_table = tps51632_id, 3728c2ecf20Sopenharmony_ci}; 3738c2ecf20Sopenharmony_ci 3748c2ecf20Sopenharmony_cistatic int __init tps51632_init(void) 3758c2ecf20Sopenharmony_ci{ 3768c2ecf20Sopenharmony_ci return i2c_add_driver(&tps51632_i2c_driver); 3778c2ecf20Sopenharmony_ci} 3788c2ecf20Sopenharmony_cisubsys_initcall(tps51632_init); 3798c2ecf20Sopenharmony_ci 3808c2ecf20Sopenharmony_cistatic void __exit tps51632_cleanup(void) 3818c2ecf20Sopenharmony_ci{ 3828c2ecf20Sopenharmony_ci i2c_del_driver(&tps51632_i2c_driver); 3838c2ecf20Sopenharmony_ci} 3848c2ecf20Sopenharmony_cimodule_exit(tps51632_cleanup); 3858c2ecf20Sopenharmony_ci 3868c2ecf20Sopenharmony_ciMODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); 3878c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("TPS51632 voltage regulator driver"); 3888c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2"); 389