···2121 number should be provided. If it is externally controlled and no GPIO2222 entry then driver will just configure this rails as external control2323 and will not provide any enable/disable APIs.2424+- ti,overcurrent-wait: This is applicable to FET registers, which have a2525+ poorly defined "overcurrent wait" field. If this property is present it2626+ should be between 0 - 3. If this property isn't present we won't touch the2727+ "overcurrent wait" field and we'll leave it to the BIOS/EC to deal with.24282529Each regulator is defined using the standard binding for regulators.2630
+12-25
drivers/regulator/s5m8767.c
···2828 struct device *dev;2929 struct sec_pmic_dev *iodev;3030 int num_regulators;3131- struct regulator_dev **rdev;3231 struct sec_opmode_data *opmode;33323433 int ramp_delay;···528529 return 0;529530}530531531531-static void s5m8767_pmic_dt_parse_ext_control_gpio(struct sec_pmic_dev *iodev,532532- struct sec_regulator_data *rdata,533533- struct device_node *reg_np)534534-{535535- rdata->ext_control_gpio = of_get_named_gpio(reg_np,536536- "s5m8767,pmic-ext-control-gpios", 0);537537- if (!gpio_is_valid(rdata->ext_control_gpio))538538- rdata->ext_control_gpio = 0;539539-}540540-541532static int s5m8767_pmic_dt_parse_pdata(struct platform_device *pdev,542533 struct sec_platform_data *pdata)543534{···576587 continue;577588 }578589579579- s5m8767_pmic_dt_parse_ext_control_gpio(iodev, rdata, reg_np);590590+ rdata->ext_control_gpio = of_get_named_gpio(reg_np,591591+ "s5m8767,pmic-ext-control-gpios", 0);580592581593 rdata->id = i;582594 rdata->initdata = of_get_regulator_init_data(···685695 struct sec_pmic_dev *iodev = dev_get_drvdata(pdev->dev.parent);686696 struct sec_platform_data *pdata = iodev->pdata;687697 struct regulator_config config = { };688688- struct regulator_dev **rdev;689698 struct s5m8767_info *s5m8767;690699 int i, ret, size, buck_init;691700···726737 return -ENOMEM;727738728739 size = sizeof(struct regulator_dev *) * (S5M8767_REG_MAX - 2);729729- s5m8767->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);730730- if (!s5m8767->rdev)731731- return -ENOMEM;732740733733- rdev = s5m8767->rdev;734741 s5m8767->dev = &pdev->dev;735742 s5m8767->iodev = iodev;736743 s5m8767->num_regulators = pdata->num_regulators;···923938 const struct sec_voltage_desc *desc;924939 int id = pdata->regulators[i].id;925940 int enable_reg, enable_val;941941+ struct regulator_dev *rdev;926942927943 desc = reg_voltage_map[id];928944 if (desc) {···950964 config.driver_data = s5m8767;951965 config.regmap = iodev->regmap_pmic;952966 config.of_node = pdata->regulators[i].reg_node;953953- config.ena_gpio = config.ena_gpio_flags = 0;954954- if (pdata->regulators[i].ext_control_gpio)967967+ config.ena_gpio = -EINVAL;968968+ config.ena_gpio_flags = 0;969969+ if (gpio_is_valid(pdata->regulators[i].ext_control_gpio))955970 s5m8767_regulator_config_ext_control(s5m8767,956971 &pdata->regulators[i], &config);957972958958- rdev[i] = devm_regulator_register(&pdev->dev, ®ulators[id],973973+ rdev = devm_regulator_register(&pdev->dev, ®ulators[id],959974 &config);960960- if (IS_ERR(rdev[i])) {961961- ret = PTR_ERR(rdev[i]);975975+ if (IS_ERR(rdev)) {976976+ ret = PTR_ERR(rdev);962977 dev_err(s5m8767->dev, "regulator init failed for %d\n",963978 id);964979 return ret;965980 }966981967967- if (pdata->regulators[i].ext_control_gpio) {968968- ret = s5m8767_enable_ext_control(s5m8767, rdev[i]);982982+ if (gpio_is_valid(pdata->regulators[i].ext_control_gpio)) {983983+ ret = s5m8767_enable_ext_control(s5m8767, rdev);969984 if (ret < 0) {970985 dev_err(s5m8767->dev,971986 "failed to enable gpio control over %s: %d\n",972972- rdev[i]->desc->name, ret);987987+ rdev->desc->name, ret);973988 return ret;974989 }975990 }
+199-15
drivers/regulator/tps65090-regulator.c
···1717 */18181919#include <linux/module.h>2020+#include <linux/delay.h>2021#include <linux/init.h>2122#include <linux/gpio.h>2223#include <linux/of_gpio.h>···2928#include <linux/regulator/of_regulator.h>3029#include <linux/mfd/tps65090.h>31303131+#define MAX_CTRL_READ_TRIES 53232+#define MAX_FET_ENABLE_TRIES 10003333+3434+#define CTRL_EN_BIT 0 /* Regulator enable bit, active high */3535+#define CTRL_WT_BIT 2 /* Regulator wait time 0 bit */3636+#define CTRL_PG_BIT 4 /* Regulator power good bit, 1=good */3737+#define CTRL_TO_BIT 7 /* Regulator timeout bit, 1=wait */3838+3939+#define MAX_OVERCURRENT_WAIT 3 /* Overcurrent wait must be <= this */4040+4141+/**4242+ * struct tps65090_regulator - Per-regulator data for a tps65090 regulator4343+ *4444+ * @dev: Pointer to our device.4545+ * @desc: The struct regulator_desc for the regulator.4646+ * @rdev: The struct regulator_dev for the regulator.4747+ * @overcurrent_wait_valid: True if overcurrent_wait is valid.4848+ * @overcurrent_wait: For FETs, the value to put in the WTFET bitfield.4949+ */5050+3251struct tps65090_regulator {3352 struct device *dev;3453 struct regulator_desc *desc;3554 struct regulator_dev *rdev;5555+ bool overcurrent_wait_valid;5656+ int overcurrent_wait;3657};37583859static struct regulator_ops tps65090_ext_control_ops = {3960};40614141-static struct regulator_ops tps65090_reg_contol_ops = {6262+/**6363+ * tps65090_reg_set_overcurrent_wait - Setup overcurrent wait6464+ *6565+ * This will set the overcurrent wait time based on what's in the regulator6666+ * info.6767+ *6868+ * @ri: Overall regulator data6969+ * @rdev: Regulator device7070+ *7171+ * Return: 0 if no error, non-zero if there was an error writing the register.7272+ */7373+static int tps65090_reg_set_overcurrent_wait(struct tps65090_regulator *ri,7474+ struct regulator_dev *rdev)7575+{7676+ int ret;7777+7878+ ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,7979+ MAX_OVERCURRENT_WAIT << CTRL_WT_BIT,8080+ ri->overcurrent_wait << CTRL_WT_BIT);8181+ if (ret) {8282+ dev_err(&rdev->dev, "Error updating overcurrent wait %#x\n",8383+ rdev->desc->enable_reg);8484+ }8585+8686+ return ret;8787+}8888+8989+/**9090+ * tps65090_try_enable_fet - Try to enable a FET9191+ *9292+ * @rdev: Regulator device9393+ *9494+ * Return: 0 if ok, -ENOTRECOVERABLE if the FET power good bit did not get9595+ * set, or some other -ve value if another error occurred (e.g. i2c error)9696+ */9797+static int tps65090_try_enable_fet(struct regulator_dev *rdev)9898+{9999+ unsigned int control;100100+ int ret, i;101101+102102+ ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,103103+ rdev->desc->enable_mask,104104+ rdev->desc->enable_mask);105105+ if (ret < 0) {106106+ dev_err(&rdev->dev, "Error in updating reg %#x\n",107107+ rdev->desc->enable_reg);108108+ return ret;109109+ }110110+111111+ for (i = 0; i < MAX_CTRL_READ_TRIES; i++) {112112+ ret = regmap_read(rdev->regmap, rdev->desc->enable_reg,113113+ &control);114114+ if (ret < 0)115115+ return ret;116116+117117+ if (!(control & BIT(CTRL_TO_BIT)))118118+ break;119119+120120+ usleep_range(1000, 1500);121121+ }122122+ if (!(control & BIT(CTRL_PG_BIT)))123123+ return -ENOTRECOVERABLE;124124+125125+ return 0;126126+}127127+128128+/**129129+ * tps65090_fet_enable - Enable a FET, trying a few times if it fails130130+ *131131+ * Some versions of the tps65090 have issues when turning on the FETs.132132+ * This function goes through several steps to ensure the best chance of the133133+ * FET going on. Specifically:134134+ * - We'll make sure that we bump the "overcurrent wait" to the maximum, which135135+ * increases the chances that we'll turn on properly.136136+ * - We'll retry turning the FET on multiple times (turning off in between).137137+ *138138+ * @rdev: Regulator device139139+ *140140+ * Return: 0 if ok, non-zero if it fails.141141+ */142142+static int tps65090_fet_enable(struct regulator_dev *rdev)143143+{144144+ int ret, tries;145145+146146+ /*147147+ * Try enabling multiple times until we succeed since sometimes the148148+ * first try times out.149149+ */150150+ tries = 0;151151+ while (true) {152152+ ret = tps65090_try_enable_fet(rdev);153153+ if (!ret)154154+ break;155155+ if (ret != -ENOTRECOVERABLE || tries == MAX_FET_ENABLE_TRIES)156156+ goto err;157157+158158+ /* Try turning the FET off (and then on again) */159159+ ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg,160160+ rdev->desc->enable_mask, 0);161161+ if (ret)162162+ goto err;163163+164164+ tries++;165165+ }166166+167167+ if (tries)168168+ dev_warn(&rdev->dev, "reg %#x enable ok after %d tries\n",169169+ rdev->desc->enable_reg, tries);170170+171171+ return 0;172172+err:173173+ dev_warn(&rdev->dev, "reg %#x enable failed\n", rdev->desc->enable_reg);174174+ WARN_ON(1);175175+176176+ return ret;177177+}178178+179179+static struct regulator_ops tps65090_reg_control_ops = {42180 .enable = regulator_enable_regmap,181181+ .disable = regulator_disable_regmap,182182+ .is_enabled = regulator_is_enabled_regmap,183183+};184184+185185+static struct regulator_ops tps65090_fet_control_ops = {186186+ .enable = tps65090_fet_enable,43187 .disable = regulator_disable_regmap,44188 .is_enabled = regulator_is_enabled_regmap,45189};···19246static struct regulator_ops tps65090_ldo_ops = {19347};19448195195-#define tps65090_REG_DESC(_id, _sname, _en_reg, _ops) \4949+#define tps65090_REG_DESC(_id, _sname, _en_reg, _en_bits, _ops) \19650{ \19751 .name = "TPS65090_RAILS"#_id, \19852 .supply_name = _sname, \19953 .id = TPS65090_REGULATOR_##_id, \20054 .ops = &_ops, \20155 .enable_reg = _en_reg, \202202- .enable_mask = BIT(0), \5656+ .enable_val = _en_bits, \5757+ .enable_mask = _en_bits, \20358 .type = REGULATOR_VOLTAGE, \20459 .owner = THIS_MODULE, \20560}2066120762static struct regulator_desc tps65090_regulator_desc[] = {208208- tps65090_REG_DESC(DCDC1, "vsys1", 0x0C, tps65090_reg_contol_ops),209209- tps65090_REG_DESC(DCDC2, "vsys2", 0x0D, tps65090_reg_contol_ops),210210- tps65090_REG_DESC(DCDC3, "vsys3", 0x0E, tps65090_reg_contol_ops),211211- tps65090_REG_DESC(FET1, "infet1", 0x0F, tps65090_reg_contol_ops),212212- tps65090_REG_DESC(FET2, "infet2", 0x10, tps65090_reg_contol_ops),213213- tps65090_REG_DESC(FET3, "infet3", 0x11, tps65090_reg_contol_ops),214214- tps65090_REG_DESC(FET4, "infet4", 0x12, tps65090_reg_contol_ops),215215- tps65090_REG_DESC(FET5, "infet5", 0x13, tps65090_reg_contol_ops),216216- tps65090_REG_DESC(FET6, "infet6", 0x14, tps65090_reg_contol_ops),217217- tps65090_REG_DESC(FET7, "infet7", 0x15, tps65090_reg_contol_ops),218218- tps65090_REG_DESC(LDO1, "vsys-l1", 0, tps65090_ldo_ops),219219- tps65090_REG_DESC(LDO2, "vsys-l2", 0, tps65090_ldo_ops),6363+ tps65090_REG_DESC(DCDC1, "vsys1", 0x0C, BIT(CTRL_EN_BIT),6464+ tps65090_reg_control_ops),6565+ tps65090_REG_DESC(DCDC2, "vsys2", 0x0D, BIT(CTRL_EN_BIT),6666+ tps65090_reg_control_ops),6767+ tps65090_REG_DESC(DCDC3, "vsys3", 0x0E, BIT(CTRL_EN_BIT),6868+ tps65090_reg_control_ops),6969+7070+ tps65090_REG_DESC(FET1, "infet1", 0x0F,7171+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),7272+ tps65090_fet_control_ops),7373+ tps65090_REG_DESC(FET2, "infet2", 0x10,7474+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),7575+ tps65090_fet_control_ops),7676+ tps65090_REG_DESC(FET3, "infet3", 0x11,7777+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),7878+ tps65090_fet_control_ops),7979+ tps65090_REG_DESC(FET4, "infet4", 0x12,8080+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),8181+ tps65090_fet_control_ops),8282+ tps65090_REG_DESC(FET5, "infet5", 0x13,8383+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),8484+ tps65090_fet_control_ops),8585+ tps65090_REG_DESC(FET6, "infet6", 0x14,8686+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),8787+ tps65090_fet_control_ops),8888+ tps65090_REG_DESC(FET7, "infet7", 0x15,8989+ BIT(CTRL_EN_BIT) | BIT(CTRL_PG_BIT),9090+ tps65090_fet_control_ops),9191+9292+ tps65090_REG_DESC(LDO1, "vsys-l1", 0, 0,9393+ tps65090_ldo_ops),9494+ tps65090_REG_DESC(LDO2, "vsys-l2", 0, 0,9595+ tps65090_ldo_ops),22096};2219722298static inline bool is_dcdc(int id)···377209 rpdata->gpio = of_get_named_gpio(np,378210 "dcdc-ext-control-gpios", 0);379211212212+ if (of_property_read_u32(tps65090_matches[idx].of_node,213213+ "ti,overcurrent-wait",214214+ &rpdata->overcurrent_wait) == 0)215215+ rpdata->overcurrent_wait_valid = true;216216+380217 tps65090_pdata->reg_pdata[idx] = rpdata;381218 }382219 return tps65090_pdata;···431258 ri = &pmic[num];432259 ri->dev = &pdev->dev;433260 ri->desc = &tps65090_regulator_desc[num];261261+ if (tps_pdata) {262262+ ri->overcurrent_wait_valid =263263+ tps_pdata->overcurrent_wait_valid;264264+ ri->overcurrent_wait = tps_pdata->overcurrent_wait;265265+ }434266435267 /*436268 * TPS5090 DCDC support the control from external digital input.···476298 return PTR_ERR(rdev);477299 }478300 ri->rdev = rdev;301301+302302+ if (ri->overcurrent_wait_valid) {303303+ ret = tps65090_reg_set_overcurrent_wait(ri, rdev);304304+ if (ret < 0)305305+ return ret;306306+ }479307480308 /* Enable external control if it is require */481309 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data &&
···9292 * DCDC1, DCDC2 and DCDC3.9393 * @gpio: Gpio number if external control is enabled and controlled through9494 * gpio.9595+ * @overcurrent_wait_valid: True if the overcurrent_wait should be applied.9696+ * @overcurrent_wait: Value to set as the overcurrent wait time. This is the9797+ * actual bitfield value, not a time in ms (valid value are 0 - 3).9598 */9699struct tps65090_regulator_plat_data {97100 struct regulator_init_data *reg_init_data;98101 bool enable_ext_control;99102 int gpio;103103+ bool overcurrent_wait_valid;104104+ int overcurrent_wait;100105};101106102107struct tps65090_platform_data {