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

regulator: tps65217: Add device tree support

This commit adds device tree support for tps65217 pmic. And usage
details are added to device tree documentation. Driver is tested
by using kernel module with regulator set and get APIs.

Signed-off-by: AnilKumar Ch <anilkumar@ti.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by

AnilKumar Ch and committed by
Mark Brown
a7f1b63e 257ee3c6

+159 -3
+91
Documentation/devicetree/bindings/regulator/tps65217.txt
··· 1 + TPS65217 family of regulators 2 + 3 + Required properties: 4 + - compatible: "ti,tps65217" 5 + - reg: I2C slave address 6 + - regulators: list of regulators provided by this controller, must be named 7 + after their hardware counterparts: dcdc[1-3] and ldo[1-4] 8 + - regulators: This is the list of child nodes that specify the regulator 9 + initialization data for defined regulators. Not all regulators for the given 10 + device need to be present. The definition for each of these nodes is defined 11 + using the standard binding for regulators found at 12 + Documentation/devicetree/bindings/regulator/regulator.txt. 13 + 14 + The valid names for regulators are: 15 + tps65217: dcdc1, dcdc2, dcdc3, ldo1, ldo2, ldo3 and ldo4 16 + 17 + Each regulator is defined using the standard binding for regulators. 18 + 19 + Example: 20 + 21 + tps: tps@24 { 22 + compatible = "ti,tps65217"; 23 + 24 + regulators { 25 + #address-cells = <1>; 26 + #size-cells = <0>; 27 + 28 + dcdc1_reg: regulator@0 { 29 + reg = <0>; 30 + regulator-compatible = "dcdc1"; 31 + regulator-min-microvolt = <900000>; 32 + regulator-max-microvolt = <1800000>; 33 + regulator-boot-on; 34 + regulator-always-on; 35 + }; 36 + 37 + dcdc2_reg: regulator@1 { 38 + reg = <1>; 39 + regulator-compatible = "dcdc2"; 40 + regulator-min-microvolt = <900000>; 41 + regulator-max-microvolt = <3300000>; 42 + regulator-boot-on; 43 + regulator-always-on; 44 + }; 45 + 46 + dcdc3_reg: regulator@2 { 47 + reg = <2>; 48 + regulator-compatible = "dcdc3"; 49 + regulator-min-microvolt = <900000>; 50 + regulator-max-microvolt = <1500000>; 51 + regulator-boot-on; 52 + regulator-always-on; 53 + }; 54 + 55 + ldo1_reg: regulator@3 { 56 + reg = <3>; 57 + regulator-compatible = "ldo1"; 58 + regulator-min-microvolt = <1000000>; 59 + regulator-max-microvolt = <3300000>; 60 + regulator-boot-on; 61 + regulator-always-on; 62 + }; 63 + 64 + ldo2_reg: regulator@4 { 65 + reg = <4>; 66 + regulator-compatible = "ldo2"; 67 + regulator-min-microvolt = <900000>; 68 + regulator-max-microvolt = <3300000>; 69 + regulator-boot-on; 70 + regulator-always-on; 71 + }; 72 + 73 + ldo3_reg: regulator@5 { 74 + reg = <5>; 75 + regulator-compatible = "ldo3"; 76 + regulator-min-microvolt = <1800000>; 77 + regulator-max-microvolt = <3300000>; 78 + regulator-boot-on; 79 + regulator-always-on; 80 + }; 81 + 82 + ldo4_reg: regulator@6 { 83 + reg = <6>; 84 + regulator-compatible = "ldo4"; 85 + regulator-min-microvolt = <1800000>; 86 + regulator-max-microvolt = <3300000>; 87 + regulator-boot-on; 88 + regulator-always-on; 89 + }; 90 + }; 91 + };
+65 -2
drivers/mfd/tps65217.c
··· 24 24 #include <linux/slab.h> 25 25 #include <linux/regmap.h> 26 26 #include <linux/err.h> 27 + #include <linux/regulator/of_regulator.h> 27 28 28 29 #include <linux/mfd/core.h> 29 30 #include <linux/mfd/tps65217.h> ··· 133 132 } 134 133 EXPORT_SYMBOL_GPL(tps65217_clear_bits); 135 134 135 + #ifdef CONFIG_OF 136 + static struct of_regulator_match reg_matches[] = { 137 + { .name = "dcdc1", .driver_data = (void *)TPS65217_DCDC_1 }, 138 + { .name = "dcdc2", .driver_data = (void *)TPS65217_DCDC_2 }, 139 + { .name = "dcdc3", .driver_data = (void *)TPS65217_DCDC_3 }, 140 + { .name = "ldo1", .driver_data = (void *)TPS65217_LDO_1 }, 141 + { .name = "ldo2", .driver_data = (void *)TPS65217_LDO_2 }, 142 + { .name = "ldo3", .driver_data = (void *)TPS65217_LDO_3 }, 143 + { .name = "ldo4", .driver_data = (void *)TPS65217_LDO_4 }, 144 + }; 145 + 146 + static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client) 147 + { 148 + struct device_node *node = client->dev.of_node; 149 + struct tps65217_board *pdata; 150 + struct device_node *regs; 151 + int count = ARRAY_SIZE(reg_matches); 152 + int ret, i; 153 + 154 + regs = of_find_node_by_name(node, "regulators"); 155 + if (!regs) 156 + return NULL; 157 + 158 + ret = of_regulator_match(&client->dev, regs, reg_matches, count); 159 + of_node_put(regs); 160 + if ((ret < 0) || (ret > count)) 161 + return NULL; 162 + 163 + count = ret; 164 + pdata = devm_kzalloc(&client->dev, count * sizeof(*pdata), GFP_KERNEL); 165 + if (!pdata) 166 + return NULL; 167 + 168 + for (i = 0; i < count; i++) { 169 + if (!reg_matches[i].init_data || !reg_matches[i].of_node) 170 + continue; 171 + 172 + pdata->tps65217_init_data[i] = reg_matches[i].init_data; 173 + pdata->of_node[i] = reg_matches[i].of_node; 174 + } 175 + 176 + return pdata; 177 + } 178 + 179 + static struct of_device_id tps65217_of_match[] = { 180 + { .compatible = "ti,tps65217", }, 181 + { }, 182 + }; 183 + #else 184 + static struct tps65217_board *tps65217_parse_dt(struct i2c_client *client) 185 + { 186 + return NULL; 187 + } 188 + #endif 189 + 136 190 static struct regmap_config tps65217_regmap_config = { 137 191 .reg_bits = 8, 138 192 .val_bits = 8, ··· 197 141 const struct i2c_device_id *ids) 198 142 { 199 143 struct tps65217 *tps; 144 + struct regulator_init_data *reg_data; 200 145 struct tps65217_board *pdata = client->dev.platform_data; 201 146 int i, ret; 202 147 unsigned int version; 148 + 149 + if (!pdata && client->dev.of_node) 150 + pdata = tps65217_parse_dt(client); 203 151 204 152 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 205 153 if (!tps) ··· 242 182 } 243 183 244 184 pdev->dev.parent = tps->dev; 245 - platform_device_add_data(pdev, &pdata->tps65217_init_data[i], 246 - sizeof(pdata->tps65217_init_data[i])); 185 + pdev->dev.of_node = pdata->of_node[i]; 186 + reg_data = pdata->tps65217_init_data[i]; 187 + platform_device_add_data(pdev, reg_data, sizeof(*reg_data)); 247 188 tps->regulator_pdev[i] = pdev; 248 189 249 190 platform_device_add(pdev); ··· 273 212 static struct i2c_driver tps65217_driver = { 274 213 .driver = { 275 214 .name = "tps65217", 215 + .owner = THIS_MODULE, 216 + .of_match_table = of_match_ptr(tps65217_of_match), 276 217 }, 277 218 .id_table = tps65217_id_table, 278 219 .probe = tps65217_probe,
+1
drivers/regulator/tps65217-regulator.c
··· 293 293 tps->info[pdev->id] = info; 294 294 295 295 config.dev = &pdev->dev; 296 + config.of_node = pdev->dev.of_node; 296 297 config.init_data = pdev->dev.platform_data; 297 298 config.driver_data = tps; 298 299
+2 -1
include/linux/mfd/tps65217.h
··· 217 217 * Board data may be used to initialize regulator. 218 218 */ 219 219 struct tps65217_board { 220 - struct regulator_init_data *tps65217_init_data; 220 + struct regulator_init_data *tps65217_init_data[TPS65217_NUM_REGULATOR]; 221 + struct device_node *of_node[TPS65217_NUM_REGULATOR]; 221 222 }; 222 223 223 224 /**