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

regulator: tps65023: add device tree support

Add device tree based initialization support for tps65023 regulators.
Therefore add macros for regulator definition setting of_match and
regulators_node members. Add initialization of regulator_desc data
using these macros. Remove old regulator_desc initialization.

Add device tree binding document for tps65023 regulators.

Signed-off-by: Thomas Elste <thomas.elste@imms.de>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Thomas Elste and committed by
Mark Brown
2d3eda67 6ff33f39

+169 -175
+60
Documentation/devicetree/bindings/regulator/tps65023.txt
··· 1 + TPS65023 family of regulators 2 + 3 + Required properties: 4 + - compatible: Must be one of the following. 5 + "ti,tps65020", 6 + "ti,tps65021", 7 + "ti,tps65023", 8 + - reg: I2C slave address 9 + - regulators: list of regulators provided by this controller, must be named 10 + after their hardware counterparts: VDCDC[1-3] and LDO[1-2] 11 + - regulators: This is the list of child nodes that specify the regulator 12 + initialization data for defined regulators. The definition for each of 13 + these nodes is defined using the standard binding for regulators found at 14 + Documentation/devicetree/bindings/regulator/regulator.txt. 15 + 16 + Each regulator is defined using the standard binding for regulators. 17 + 18 + Example: 19 + 20 + tps65023@48 { 21 + compatible = "ti,tps65023"; 22 + reg = <0x48>; 23 + 24 + regulators { 25 + VDCDC1 { 26 + regulator-name = "vdd_mpu"; 27 + regulator-always-on; 28 + regulator-min-microvolt = <1200000>; 29 + regulator-max-microvolt = <1200000>; 30 + }; 31 + 32 + VDCDC2 { 33 + regulator-name = "vdd_core"; 34 + regulator-always-on; 35 + regulator-min-microvolt = <3300000>; 36 + regulator-max-microvolt = <3300000>; 37 + }; 38 + 39 + VDCDC3 { 40 + regulator-name = "vdd_io"; 41 + regulator-always-on; 42 + regulator-min-microvolt = <1800000>; 43 + regulator-max-microvolt = <1800000>; 44 + }; 45 + 46 + LDO1 { 47 + regulator-name = "vdd_usb18"; 48 + regulator-always-on; 49 + regulator-min-microvolt = <1800000>; 50 + regulator-max-microvolt = <1800000>; 51 + }; 52 + 53 + LDO2 { 54 + regulator-name = "vdd_usb33"; 55 + regulator-always-on; 56 + regulator-min-microvolt = <3300000>; 57 + regulator-max-microvolt = <3300000>; 58 + }; 59 + }; 60 + };
+109 -175
drivers/regulator/tps65023-regulator.c
··· 86 86 87 87 #define TPS65023_MAX_REG_ID TPS65023_LDO_2 88 88 89 + #define TPS65023_REGULATOR_DCDC(_num, _t, _em) \ 90 + { \ 91 + .name = "VDCDC"#_num, \ 92 + .of_match = of_match_ptr("VDCDC"#_num), \ 93 + .regulators_node = of_match_ptr("regulators"), \ 94 + .id = TPS65023_DCDC_##_num, \ 95 + .n_voltages = ARRAY_SIZE(_t), \ 96 + .ops = &tps65023_dcdc_ops, \ 97 + .type = REGULATOR_VOLTAGE, \ 98 + .owner = THIS_MODULE, \ 99 + .volt_table = _t, \ 100 + .vsel_reg = TPS65023_REG_DEF_CORE, \ 101 + .vsel_mask = ARRAY_SIZE(_t) - 1, \ 102 + .enable_mask = _em, \ 103 + .enable_reg = TPS65023_REG_REG_CTRL, \ 104 + .apply_reg = TPS65023_REG_CON_CTRL2, \ 105 + .apply_bit = TPS65023_REG_CTRL2_GO, \ 106 + } \ 107 + 108 + #define TPS65023_REGULATOR_LDO(_num, _t, _vm) \ 109 + { \ 110 + .name = "LDO"#_num, \ 111 + .of_match = of_match_ptr("LDO"#_num), \ 112 + .regulators_node = of_match_ptr("regulators"), \ 113 + .id = TPS65023_LDO_##_num, \ 114 + .n_voltages = ARRAY_SIZE(_t), \ 115 + .ops = &tps65023_ldo_ops, \ 116 + .type = REGULATOR_VOLTAGE, \ 117 + .owner = THIS_MODULE, \ 118 + .volt_table = _t, \ 119 + .vsel_reg = TPS65023_REG_LDO_CTRL, \ 120 + .vsel_mask = _vm, \ 121 + .enable_mask = 1 << (_num), \ 122 + .enable_reg = TPS65023_REG_REG_CTRL, \ 123 + } \ 124 + 89 125 /* Supported voltage values for regulators */ 90 126 static const unsigned int VCORE_VSEL_table[] = { 91 127 800000, 825000, 850000, 875000, ··· 160 124 2500000, 2800000, 3000000, 3300000, 161 125 }; 162 126 163 - /* Regulator specific details */ 164 - struct tps_info { 165 - const char *name; 166 - u8 table_len; 167 - const unsigned int *table; 168 - }; 169 - 170 127 /* PMIC details */ 171 128 struct tps_pmic { 172 - struct regulator_desc desc[TPS65023_NUM_REGULATOR]; 173 129 struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; 174 - const struct tps_info *info[TPS65023_NUM_REGULATOR]; 130 + const struct tps_driver_data *driver_data; 175 131 struct regmap *regmap; 176 - u8 core_regulator; 177 132 }; 178 133 179 134 /* Struct passed as driver data */ 180 135 struct tps_driver_data { 181 - const struct tps_info *info; 136 + const struct regulator_desc *desc; 182 137 u8 core_regulator; 183 138 }; 184 139 ··· 181 154 if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 182 155 return -EINVAL; 183 156 184 - if (dcdc != tps->core_regulator) 157 + if (dcdc != tps->driver_data->core_regulator) 185 158 return 0; 186 159 187 160 return regulator_get_voltage_sel_regmap(dev); ··· 193 166 struct tps_pmic *tps = rdev_get_drvdata(dev); 194 167 int dcdc = rdev_get_id(dev); 195 168 196 - if (dcdc != tps->core_regulator) 169 + if (dcdc != tps->driver_data->core_regulator) 197 170 return -EINVAL; 198 171 199 172 return regulator_set_voltage_sel_regmap(dev, selector); ··· 226 199 .val_bits = 8, 227 200 }; 228 201 202 + static const struct regulator_desc tps65020_regulators[] = { 203 + TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20), 204 + TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10), 205 + TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08), 206 + TPS65023_REGULATOR_LDO(1, TPS65020_LDO_VSEL_table, 0x07), 207 + TPS65023_REGULATOR_LDO(2, TPS65020_LDO_VSEL_table, 0x70), 208 + }; 209 + 210 + static const struct regulator_desc tps65021_regulators[] = { 211 + TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20), 212 + TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10), 213 + TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08), 214 + TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07), 215 + TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70), 216 + }; 217 + 218 + static const struct regulator_desc tps65023_regulators[] = { 219 + TPS65023_REGULATOR_DCDC(1, VCORE_VSEL_table, 0x20), 220 + TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_3300000_VSEL_table, 0x10), 221 + TPS65023_REGULATOR_DCDC(3, DCDC_FIXED_1800000_VSEL_table, 0x08), 222 + TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07), 223 + TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70), 224 + }; 225 + 226 + static struct tps_driver_data tps65020_drv_data = { 227 + .desc = tps65020_regulators, 228 + .core_regulator = TPS65023_DCDC_3, 229 + }; 230 + 231 + static struct tps_driver_data tps65021_drv_data = { 232 + .desc = tps65021_regulators, 233 + .core_regulator = TPS65023_DCDC_3, 234 + }; 235 + 236 + static struct tps_driver_data tps65023_drv_data = { 237 + .desc = tps65023_regulators, 238 + .core_regulator = TPS65023_DCDC_1, 239 + }; 240 + 229 241 static int tps_65023_probe(struct i2c_client *client, 230 242 const struct i2c_device_id *id) 231 243 { 232 - const struct tps_driver_data *drv_data = (void *)id->driver_data; 233 - const struct tps_info *info = drv_data->info; 244 + struct regulator_init_data *init_data = dev_get_platdata(&client->dev); 234 245 struct regulator_config config = { }; 235 - struct regulator_init_data *init_data; 236 - struct regulator_dev *rdev; 237 246 struct tps_pmic *tps; 238 247 int i; 239 248 int error; 240 249 241 - /** 242 - * init_data points to array of regulator_init structures 243 - * coming from the board-evm file. 244 - */ 245 - init_data = dev_get_platdata(&client->dev); 246 - if (!init_data) 247 - return -EIO; 248 - 249 250 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); 250 251 if (!tps) 251 252 return -ENOMEM; 253 + 254 + tps->driver_data = (struct tps_driver_data *)id->driver_data; 252 255 253 256 tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config); 254 257 if (IS_ERR(tps->regmap)) { ··· 289 232 } 290 233 291 234 /* common for all regulators */ 292 - tps->core_regulator = drv_data->core_regulator; 235 + config.dev = &client->dev; 236 + config.driver_data = tps; 237 + config.regmap = tps->regmap; 293 238 294 - for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { 295 - /* Store regulator specific information */ 296 - tps->info[i] = info; 297 - 298 - tps->desc[i].name = info->name; 299 - tps->desc[i].id = i; 300 - tps->desc[i].n_voltages = info->table_len; 301 - tps->desc[i].volt_table = info->table; 302 - tps->desc[i].ops = (i > TPS65023_DCDC_3 ? 303 - &tps65023_ldo_ops : &tps65023_dcdc_ops); 304 - tps->desc[i].type = REGULATOR_VOLTAGE; 305 - tps->desc[i].owner = THIS_MODULE; 306 - 307 - tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; 308 - switch (i) { 309 - case TPS65023_LDO_1: 310 - tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; 311 - tps->desc[i].vsel_mask = 0x07; 312 - tps->desc[i].enable_mask = 1 << 1; 313 - break; 314 - case TPS65023_LDO_2: 315 - tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; 316 - tps->desc[i].vsel_mask = 0x70; 317 - tps->desc[i].enable_mask = 1 << 2; 318 - break; 319 - default: /* DCDCx */ 320 - tps->desc[i].enable_mask = 321 - 1 << (TPS65023_NUM_REGULATOR - i); 322 - tps->desc[i].vsel_reg = TPS65023_REG_DEF_CORE; 323 - tps->desc[i].vsel_mask = info->table_len - 1; 324 - tps->desc[i].apply_reg = TPS65023_REG_CON_CTRL2; 325 - tps->desc[i].apply_bit = TPS65023_REG_CTRL2_GO; 326 - } 327 - 328 - config.dev = &client->dev; 329 - config.init_data = init_data; 330 - config.driver_data = tps; 331 - config.regmap = tps->regmap; 239 + for (i = 0; i < TPS65023_NUM_REGULATOR; i++) { 240 + if (init_data) 241 + config.init_data = &init_data[i]; 332 242 333 243 /* Register the regulators */ 334 - rdev = devm_regulator_register(&client->dev, &tps->desc[i], 335 - &config); 336 - if (IS_ERR(rdev)) { 244 + tps->rdev[i] = devm_regulator_register(&client->dev, 245 + &tps->driver_data->desc[i], &config); 246 + if (IS_ERR(tps->rdev[i])) { 337 247 dev_err(&client->dev, "failed to register %s\n", 338 248 id->name); 339 - return PTR_ERR(rdev); 249 + return PTR_ERR(tps->rdev[i]); 340 250 } 341 - 342 - /* Save regulator for cleanup */ 343 - tps->rdev[i] = rdev; 344 251 } 345 252 346 253 i2c_set_clientdata(client, tps); ··· 317 296 return 0; 318 297 } 319 298 320 - static const struct tps_info tps65020_regs[] = { 321 - { 322 - .name = "VDCDC1", 323 - .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), 324 - .table = DCDC_FIXED_3300000_VSEL_table, 325 - }, 326 - { 327 - .name = "VDCDC2", 328 - .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), 329 - .table = DCDC_FIXED_1800000_VSEL_table, 330 - }, 331 - { 332 - .name = "VDCDC3", 333 - .table_len = ARRAY_SIZE(VCORE_VSEL_table), 334 - .table = VCORE_VSEL_table, 335 - }, 336 - { 337 - .name = "LDO1", 338 - .table_len = ARRAY_SIZE(TPS65020_LDO_VSEL_table), 339 - .table = TPS65020_LDO_VSEL_table, 340 - }, 341 - { 342 - .name = "LDO2", 343 - .table_len = ARRAY_SIZE(TPS65020_LDO_VSEL_table), 344 - .table = TPS65020_LDO_VSEL_table, 345 - }, 299 + static const struct of_device_id tps65023_of_match[] = { 300 + { .compatible = "ti,tps65020", .data = &tps65020_drv_data}, 301 + { .compatible = "ti,tps65021", .data = &tps65021_drv_data}, 302 + { .compatible = "ti,tps65023", .data = &tps65023_drv_data}, 303 + {}, 346 304 }; 347 - 348 - static const struct tps_info tps65021_regs[] = { 349 - { 350 - .name = "VDCDC1", 351 - .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), 352 - .table = DCDC_FIXED_3300000_VSEL_table, 353 - }, 354 - { 355 - .name = "VDCDC2", 356 - .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), 357 - .table = DCDC_FIXED_1800000_VSEL_table, 358 - }, 359 - { 360 - .name = "VDCDC3", 361 - .table_len = ARRAY_SIZE(VCORE_VSEL_table), 362 - .table = VCORE_VSEL_table, 363 - }, 364 - { 365 - .name = "LDO1", 366 - .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 367 - .table = TPS65023_LDO1_VSEL_table, 368 - }, 369 - { 370 - .name = "LDO2", 371 - .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 372 - .table = TPS65023_LDO2_VSEL_table, 373 - }, 374 - }; 375 - 376 - static const struct tps_info tps65023_regs[] = { 377 - { 378 - .name = "VDCDC1", 379 - .table_len = ARRAY_SIZE(VCORE_VSEL_table), 380 - .table = VCORE_VSEL_table, 381 - }, 382 - { 383 - .name = "VDCDC2", 384 - .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), 385 - .table = DCDC_FIXED_3300000_VSEL_table, 386 - }, 387 - { 388 - .name = "VDCDC3", 389 - .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), 390 - .table = DCDC_FIXED_1800000_VSEL_table, 391 - }, 392 - { 393 - .name = "LDO1", 394 - .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), 395 - .table = TPS65023_LDO1_VSEL_table, 396 - }, 397 - { 398 - .name = "LDO2", 399 - .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), 400 - .table = TPS65023_LDO2_VSEL_table, 401 - }, 402 - }; 403 - 404 - static struct tps_driver_data tps65020_drv_data = { 405 - .info = tps65020_regs, 406 - .core_regulator = TPS65023_DCDC_3, 407 - }; 408 - 409 - static struct tps_driver_data tps65021_drv_data = { 410 - .info = tps65021_regs, 411 - .core_regulator = TPS65023_DCDC_3, 412 - }; 413 - 414 - static struct tps_driver_data tps65023_drv_data = { 415 - .info = tps65023_regs, 416 - .core_regulator = TPS65023_DCDC_1, 417 - }; 305 + MODULE_DEVICE_TABLE(of, tps65023_of_match); 418 306 419 307 static const struct i2c_device_id tps_65023_id[] = { 420 - {.name = "tps65023", 421 - .driver_data = (unsigned long) &tps65023_drv_data}, 422 - {.name = "tps65021", 423 - .driver_data = (unsigned long) &tps65021_drv_data,}, 424 - {.name = "tps65020", 425 - .driver_data = (unsigned long) &tps65020_drv_data}, 308 + { 309 + .name = "tps65023", 310 + .driver_data = (kernel_ulong_t)&tps65023_drv_data 311 + }, { 312 + .name = "tps65021", 313 + .driver_data = (kernel_ulong_t)&tps65021_drv_data 314 + }, { 315 + .name = "tps65020", 316 + .driver_data = (kernel_ulong_t)&tps65020_drv_data 317 + }, 426 318 { }, 427 319 }; 428 - 429 320 MODULE_DEVICE_TABLE(i2c, tps_65023_id); 430 321 431 322 static struct i2c_driver tps_65023_i2c_driver = { 432 323 .driver = { 433 324 .name = "tps65023", 325 + .of_match_table = of_match_ptr(tps65023_of_match), 434 326 }, 435 327 .probe = tps_65023_probe, 436 328 .id_table = tps_65023_id,