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

Configure Feed

Select the types of activity you want to include in your feed.

regulator: ltc3589: Convert enum->pointer for data in the match tables

Convert enum->pointer for data in the match tables, so that the hw
differences can be stored in pointer and there by simpily the code.

Add struct ltc3589_info for hw differences between the devices and replace
ltc3589_variant->ltc3589_info for data in the match table. Simplify the
probe() by replacing of_device_get_match_data() and ID lookup for
retrieving data by i2c_get_match_data(). Drop enum ltc3589_variant and
variant from struct ltc3589_info as there are no users.

While at it, dropped trailing comma in the terminator entries for ID
table.

Signed-off-by: Biju Das <biju.das.jz@bp.renesas.com>
Link: https://lore.kernel.org/r/20230828162830.97881-1-biju.das.jz@bp.renesas.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Biju Das and committed by
Mark Brown
7169654c 24d95bb0

+26 -35
+26 -35
drivers/regulator/ltc3589.c
··· 58 58 #define LTC3589_VRRCR_SW3_RAMP_MASK GENMASK(5, 4) 59 59 #define LTC3589_VRRCR_LDO2_RAMP_MASK GENMASK(7, 6) 60 60 61 - enum ltc3589_variant { 62 - LTC3589, 63 - LTC3589_1, 64 - LTC3589_2, 65 - }; 66 - 67 61 enum ltc3589_reg { 68 62 LTC3589_SW1, 69 63 LTC3589_SW2, ··· 70 76 LTC3589_NUM_REGULATORS, 71 77 }; 72 78 79 + struct ltc3589_info { 80 + const unsigned int *volt_table; 81 + int fixed_uV; 82 + }; 83 + 73 84 struct ltc3589 { 74 85 struct regmap *regmap; 75 86 struct device *dev; 76 - enum ltc3589_variant variant; 77 87 struct regulator_desc regulator_descs[LTC3589_NUM_REGULATORS]; 78 88 struct regulator_dev *regulators[LTC3589_NUM_REGULATORS]; 79 89 }; ··· 377 379 378 380 static int ltc3589_probe(struct i2c_client *client) 379 381 { 380 - const struct i2c_device_id *id = i2c_client_get_device_id(client); 381 382 struct device *dev = &client->dev; 383 + const struct ltc3589_info *info; 382 384 struct regulator_desc *descs; 383 385 struct ltc3589 *ltc3589; 384 386 int i, ret; ··· 388 390 return -ENOMEM; 389 391 390 392 i2c_set_clientdata(client, ltc3589); 391 - if (client->dev.of_node) 392 - ltc3589->variant = (uintptr_t)of_device_get_match_data(&client->dev); 393 - else 394 - ltc3589->variant = id->driver_data; 393 + info = i2c_get_match_data(client); 395 394 ltc3589->dev = dev; 396 395 397 396 descs = ltc3589->regulator_descs; 398 397 memcpy(descs, ltc3589_regulators, sizeof(ltc3589_regulators)); 399 - if (ltc3589->variant == LTC3589) { 400 - descs[LTC3589_LDO3].fixed_uV = 1800000; 401 - descs[LTC3589_LDO4].volt_table = ltc3589_ldo4; 402 - } else { 403 - descs[LTC3589_LDO3].fixed_uV = 2800000; 404 - descs[LTC3589_LDO4].volt_table = ltc3589_12_ldo4; 405 - } 398 + descs[LTC3589_LDO3].fixed_uV = info->fixed_uV; 399 + descs[LTC3589_LDO4].volt_table = info->volt_table; 406 400 407 401 ltc3589->regmap = devm_regmap_init_i2c(client, &ltc3589_regmap_config); 408 402 if (IS_ERR(ltc3589->regmap)) { ··· 434 444 return 0; 435 445 } 436 446 447 + static const struct ltc3589_info ltc3589_info = { 448 + .fixed_uV = 1800000, 449 + .volt_table = ltc3589_ldo4, 450 + }; 451 + 452 + static const struct ltc3589_info ltc3589_12_info = { 453 + .fixed_uV = 2800000, 454 + .volt_table = ltc3589_12_ldo4, 455 + }; 456 + 437 457 static const struct i2c_device_id ltc3589_i2c_id[] = { 438 - { "ltc3589", LTC3589 }, 439 - { "ltc3589-1", LTC3589_1 }, 440 - { "ltc3589-2", LTC3589_2 }, 458 + { "ltc3589", (kernel_ulong_t)&ltc3589_info }, 459 + { "ltc3589-1", (kernel_ulong_t)&ltc3589_12_info }, 460 + { "ltc3589-2", (kernel_ulong_t)&ltc3589_12_info }, 441 461 { } 442 462 }; 443 463 MODULE_DEVICE_TABLE(i2c, ltc3589_i2c_id); 444 464 445 465 static const struct of_device_id __maybe_unused ltc3589_of_match[] = { 446 - { 447 - .compatible = "lltc,ltc3589", 448 - .data = (void *)LTC3589, 449 - }, 450 - { 451 - .compatible = "lltc,ltc3589-1", 452 - .data = (void *)LTC3589_1, 453 - }, 454 - { 455 - .compatible = "lltc,ltc3589-2", 456 - .data = (void *)LTC3589_2, 457 - }, 458 - { }, 466 + { .compatible = "lltc,ltc3589", .data = &ltc3589_info }, 467 + { .compatible = "lltc,ltc3589-1", .data = &ltc3589_12_info }, 468 + { .compatible = "lltc,ltc3589-2", .data = &ltc3589_12_info }, 469 + { } 459 470 }; 460 471 MODULE_DEVICE_TABLE(of, ltc3589_of_match); 461 472