Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

regulator: lp872x: Add enable GPIO pin support

LP872x regulators are made active via the EN pin, which might be hooked to a
GPIO. This adds support for driving the GPIO high when the driver is in use.

Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Paul Kocialkowski and committed by
Mark Brown
7e6213f4 690f44ba

+40
+1
Documentation/devicetree/bindings/regulator/lp872x.txt
··· 28 28 - ti,dvs-gpio: GPIO specifier for external DVS pin control of LP872x devices. 29 29 - ti,dvs-vsel: DVS selector. 0 = SEL_V1, 1 = SEL_V2. 30 30 - ti,dvs-state: initial DVS pin state. 0 = DVS_LOW, 1 = DVS_HIGH. 31 + - enable-gpios: GPIO specifier for EN pin control of LP872x devices. 31 32 32 33 Sub nodes for regulator_init_data 33 34 LP8720 has maximum 6 nodes. (child name: ldo1 ~ 5 and buck)
+34
drivers/regulator/lp872x.c
··· 15 15 #include <linux/regmap.h> 16 16 #include <linux/err.h> 17 17 #include <linux/gpio.h> 18 + #include <linux/delay.h> 18 19 #include <linux/regulator/lp872x.h> 19 20 #include <linux/regulator/driver.h> 20 21 #include <linux/platform_device.h> ··· 758 757 default_dvs_mode[lp->chipid]); 759 758 } 760 759 760 + static int lp872x_hw_enable(struct lp872x *lp) 761 + { 762 + int ret, gpio; 763 + 764 + if (!lp->pdata) 765 + return -EINVAL; 766 + 767 + gpio = lp->pdata->enable_gpio; 768 + if (!gpio_is_valid(gpio)) 769 + return 0; 770 + 771 + /* Always set enable GPIO high. */ 772 + ret = devm_gpio_request_one(lp->dev, gpio, GPIOF_OUT_INIT_HIGH, "LP872X EN"); 773 + if (ret) { 774 + dev_err(lp->dev, "gpio request err: %d\n", ret); 775 + return ret; 776 + } 777 + 778 + /* Each chip has a different enable delay. */ 779 + if (lp->chipid == LP8720) 780 + usleep_range(LP8720_ENABLE_DELAY, 1.5 * LP8720_ENABLE_DELAY); 781 + else 782 + usleep_range(LP8725_ENABLE_DELAY, 1.5 * LP8725_ENABLE_DELAY); 783 + 784 + return 0; 785 + } 786 + 761 787 static int lp872x_config(struct lp872x *lp) 762 788 { 763 789 struct lp872x_platform_data *pdata = lp->pdata; ··· 903 875 of_property_read_u8(np, "ti,dvs-state", &dvs_state); 904 876 pdata->dvs->init_state = dvs_state ? DVS_HIGH : DVS_LOW; 905 877 878 + pdata->enable_gpio = of_get_named_gpio(np, "enable-gpios", 0); 879 + 906 880 if (of_get_child_count(np) == 0) 907 881 goto out; 908 882 ··· 977 947 lp->pdata = pdata; 978 948 lp->chipid = id->driver_data; 979 949 i2c_set_clientdata(cl, lp); 950 + 951 + ret = lp872x_hw_enable(lp); 952 + if (ret) 953 + return ret; 980 954 981 955 ret = lp872x_config(lp); 982 956 if (ret)
+5
include/linux/regulator/lp872x.h
··· 18 18 19 19 #define LP872X_MAX_REGULATORS 9 20 20 21 + #define LP8720_ENABLE_DELAY 200 22 + #define LP8725_ENABLE_DELAY 30000 23 + 21 24 enum lp872x_regulator_id { 22 25 LP8720_ID_BASE, 23 26 LP8720_ID_LDO1 = LP8720_ID_BASE, ··· 82 79 * @update_config : if LP872X_GENERAL_CFG register is updated, set true 83 80 * @regulator_data : platform regulator id and init data 84 81 * @dvs : dvs data for buck voltage control 82 + * @enable_gpio : gpio pin number for enable control 85 83 */ 86 84 struct lp872x_platform_data { 87 85 u8 general_config; 88 86 bool update_config; 89 87 struct lp872x_regulator_data regulator_data[LP872X_MAX_REGULATORS]; 90 88 struct lp872x_dvs *dvs; 89 + int enable_gpio; 91 90 }; 92 91 93 92 #endif