···11+TPS51632 Voltage regulators22+33+Required properties:44+- compatible: Must be "ti,tps51632"55+- reg: I2C slave address66+77+Optional properties:88+- ti,enable-pwm-dvfs: Enable the DVFS voltage control through the PWM interface.99+- ti,dvfs-step-20mV: The 20mV step voltage when PWM DVFS enabled. Missing this1010+ will set 10mV step voltage in PWM DVFS mode. In normal mode, the voltage1111+ step is 10mV as per datasheet.1212+1313+Any property defined as part of the core regulator binding, defined in1414+regulator.txt, can also be used.1515+1616+Example:1717+1818+ tps51632 {1919+ compatible = "ti,tps51632";2020+ reg = <0x43>;2121+ regulator-name = "tps51632-vout";2222+ regulator-min-microvolt = <500000>;2323+ regulator-max-microvolt = <1500000>;2424+ regulator-boot-on;2525+ ti,enable-pwm-dvfs;2626+ ti,dvfs-step-20mV;2727+ };
+103-49
drivers/regulator/tps51632-regulator.c
···2828#include <linux/init.h>2929#include <linux/kernel.h>3030#include <linux/module.h>3131+#include <linux/of.h>3232+#include <linux/of_device.h>3133#include <linux/platform_device.h>3234#include <linux/regmap.h>3335#include <linux/regulator/driver.h>3436#include <linux/regulator/machine.h>3737+#include <linux/regulator/of_regulator.h>3538#include <linux/regulator/tps51632-regulator.h>3639#include <linux/slab.h>3740···8885 struct regulator_desc desc;8986 struct regulator_dev *rdev;9087 struct regmap *regmap;9191- bool enable_pwm_dvfs;9288};9393-9494-static int tps51632_dcdc_get_voltage_sel(struct regulator_dev *rdev)9595-{9696- struct tps51632_chip *tps = rdev_get_drvdata(rdev);9797- unsigned int data;9898- int ret;9999- unsigned int reg = TPS51632_VOLTAGE_SELECT_REG;100100- int vsel;101101-102102- if (tps->enable_pwm_dvfs)103103- reg = TPS51632_VOLTAGE_BASE_REG;104104-105105- ret = regmap_read(tps->regmap, reg, &data);106106- if (ret < 0) {107107- dev_err(tps->dev, "reg read failed, err %d\n", ret);108108- return ret;109109- }110110-111111- vsel = data & TPS51632_VOUT_MASK;112112- return vsel;113113-}114114-115115-static int tps51632_dcdc_set_voltage_sel(struct regulator_dev *rdev,116116- unsigned selector)117117-{118118- struct tps51632_chip *tps = rdev_get_drvdata(rdev);119119- int ret;120120- unsigned int reg = TPS51632_VOLTAGE_SELECT_REG;121121-122122- if (tps->enable_pwm_dvfs)123123- reg = TPS51632_VOLTAGE_BASE_REG;124124-125125- if (selector > TPS51632_MAX_VSEL)126126- return -EINVAL;127127-128128- ret = regmap_write(tps->regmap, reg, selector);129129- if (ret < 0)130130- dev_err(tps->dev, "reg write failed, err %d\n", ret);131131- return ret;132132-}1338913490static int tps51632_dcdc_set_ramp_delay(struct regulator_dev *rdev,13591 int ramp_delay)···106144}107145108146static struct regulator_ops tps51632_dcdc_ops = {109109- .get_voltage_sel = tps51632_dcdc_get_voltage_sel,110110- .set_voltage_sel = tps51632_dcdc_set_voltage_sel,147147+ .get_voltage_sel = regulator_get_voltage_sel_regmap,148148+ .set_voltage_sel = regulator_set_voltage_sel_regmap,111149 .list_voltage = regulator_list_voltage_linear,112150 .set_voltage_time_sel = regulator_set_voltage_time_sel,113151 .set_ramp_delay = tps51632_dcdc_set_ramp_delay,···124162 goto skip_pwm_config;125163126164 control |= TPS51632_DVFS_PWMEN;127127- tps->enable_pwm_dvfs = pdata->enable_pwm_dvfs;128165 vsel = TPS51632_VOLT_VSEL(pdata->base_voltage_uV);129166 ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_BASE_REG, vsel);130167 if (ret < 0) {···166205 return ret;167206}168207169169-static bool rd_wr_reg(struct device *dev, unsigned int reg)208208+static bool is_volatile_reg(struct device *dev, unsigned int reg)170209{171171- if ((reg >= 0x8) && (reg <= 0x10))210210+ switch (reg) {211211+ case TPS51632_OFFSET_REG:212212+ case TPS51632_FAULT_REG:213213+ case TPS51632_IMON_REG:214214+ return true;215215+ default:172216 return false;173173- return true;217217+ }218218+}219219+220220+static bool is_read_reg(struct device *dev, unsigned int reg)221221+{222222+ switch (reg) {223223+ case 0x08 ... 0x0F:224224+ return false;225225+ default:226226+ return true;227227+ }228228+}229229+230230+static bool is_write_reg(struct device *dev, unsigned int reg)231231+{232232+ switch (reg) {233233+ case TPS51632_VOLTAGE_SELECT_REG:234234+ case TPS51632_VOLTAGE_BASE_REG:235235+ case TPS51632_VMAX_REG:236236+ case TPS51632_DVFS_CONTROL_REG:237237+ case TPS51632_POWER_STATE_REG:238238+ case TPS51632_SLEW_REGS:239239+ return true;240240+ default:241241+ return false;242242+ }174243}175244176245static const struct regmap_config tps51632_regmap_config = {177246 .reg_bits = 8,178247 .val_bits = 8,179179- .writeable_reg = rd_wr_reg,180180- .readable_reg = rd_wr_reg,248248+ .writeable_reg = is_write_reg,249249+ .readable_reg = is_read_reg,250250+ .volatile_reg = is_volatile_reg,181251 .max_register = TPS51632_MAX_REG - 1,182252 .cache_type = REGCACHE_RBTREE,183253};254254+255255+#if defined(CONFIG_OF)256256+static const struct of_device_id tps51632_of_match[] = {257257+ { .compatible = "ti,tps51632",},258258+ {},259259+};260260+MODULE_DEVICE_TABLE(of, tps51632_of_match);261261+262262+static struct tps51632_regulator_platform_data *263263+ of_get_tps51632_platform_data(struct device *dev)264264+{265265+ struct tps51632_regulator_platform_data *pdata;266266+ struct device_node *np = dev->of_node;267267+268268+ pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);269269+ if (!pdata) {270270+ dev_err(dev, "Memory alloc failed for platform data\n");271271+ return NULL;272272+ }273273+274274+ pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);275275+ if (!pdata->reg_init_data) {276276+ dev_err(dev, "Not able to get OF regulator init data\n");277277+ return NULL;278278+ }279279+280280+ pdata->enable_pwm_dvfs =281281+ of_property_read_bool(np, "ti,enable-pwm-dvfs");282282+ pdata->dvfs_step_20mV = of_property_read_bool(np, "ti,dvfs-step-20mV");283283+284284+ pdata->base_voltage_uV = pdata->reg_init_data->constraints.min_uV ? :285285+ TPS51632_MIN_VOLATGE;286286+ pdata->max_voltage_uV = pdata->reg_init_data->constraints.max_uV ? :287287+ TPS51632_MAX_VOLATGE;288288+ return pdata;289289+}290290+#else291291+static struct tps51632_regulator_platform_data *292292+ of_get_tps51632_platform_data(struct device *dev)293293+{294294+ return NULL;295295+}296296+#endif184297185298static int tps51632_probe(struct i2c_client *client,186299 const struct i2c_device_id *id)···265230 int ret;266231 struct regulator_config config = { };267232233233+ if (client->dev.of_node) {234234+ const struct of_device_id *match;235235+ match = of_match_device(of_match_ptr(tps51632_of_match),236236+ &client->dev);237237+ if (!match) {238238+ dev_err(&client->dev, "Error: No device match found\n");239239+ return -ENODEV;240240+ }241241+ }242242+268243 pdata = client->dev.platform_data;244244+ if (!pdata && client->dev.of_node)245245+ pdata = of_get_tps51632_platform_data(&client->dev);269246 if (!pdata) {270247 dev_err(&client->dev, "No Platform data\n");271248 return -EINVAL;···315268 tps->desc.ops = &tps51632_dcdc_ops;316269 tps->desc.type = REGULATOR_VOLTAGE;317270 tps->desc.owner = THIS_MODULE;271271+272272+ if (pdata->enable_pwm_dvfs)273273+ tps->desc.vsel_reg = TPS51632_VOLTAGE_BASE_REG;274274+ else275275+ tps->desc.vsel_reg = TPS51632_VOLTAGE_SELECT_REG;276276+ tps->desc.vsel_mask = TPS51632_VOUT_MASK;318277319278 tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config);320279 if (IS_ERR(tps->regmap)) {···372319 .driver = {373320 .name = "tps51632",374321 .owner = THIS_MODULE,322322+ .of_match_table = of_match_ptr(tps51632_of_match),375323 },376324 .probe = tps51632_probe,377325 .remove = tps51632_remove,