Skip to content

Commit 1ff35e6

Browse files
wensbroonie
authored andcommitted
regulator: mt6358: Const-ify mt6358_regulator_info data structures
In the MT6358 regulator driver, each regulator is described by a |struct regulator_desc| wrapped by a |struct mt6358_regulator_info|. The latter was tied to the regulator device using the config's driver_data field, which meant that the variables could not be constant. Since each regulator device has a pointer to its regulator_desc, and mt6358_regulator_info wraps that, the driver could use container_of() to retrieve it instead. Switch to using container_of(), drop tha driver_data setting, and const-ify all the regulator descriptions. Signed-off-by: Chen-Yu Tsai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 04ba665 commit 1ff35e6

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

drivers/regulator/mt6358-regulator.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ struct mt6358_regulator_info {
3434
u32 modeset_mask;
3535
};
3636

37+
#define to_regulator_info(x) container_of((x), struct mt6358_regulator_info, desc)
38+
3739
#define MT6358_BUCK(match, vreg, min, max, step, \
3840
volt_ranges, vosel_mask, _da_vsel_reg, _da_vsel_mask, \
3941
_modeset_reg, _modeset_shift) \
@@ -342,9 +344,9 @@ static unsigned int mt6358_map_mode(unsigned int mode)
342344
static int mt6358_set_voltage_sel(struct regulator_dev *rdev,
343345
unsigned int selector)
344346
{
347+
const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
345348
int idx, ret;
346349
const u32 *pvol;
347-
struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
348350

349351
pvol = info->index_table;
350352

@@ -358,9 +360,9 @@ static int mt6358_set_voltage_sel(struct regulator_dev *rdev,
358360

359361
static int mt6358_get_voltage_sel(struct regulator_dev *rdev)
360362
{
363+
const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
361364
int idx, ret;
362365
u32 selector;
363-
struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
364366
const u32 *pvol;
365367

366368
ret = regmap_read(rdev->regmap, info->desc.vsel_reg, &selector);
@@ -384,8 +386,8 @@ static int mt6358_get_voltage_sel(struct regulator_dev *rdev)
384386

385387
static int mt6358_get_buck_voltage_sel(struct regulator_dev *rdev)
386388
{
389+
const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
387390
int ret, regval;
388-
struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
389391

390392
ret = regmap_read(rdev->regmap, info->da_vsel_reg, &regval);
391393
if (ret != 0) {
@@ -402,9 +404,9 @@ static int mt6358_get_buck_voltage_sel(struct regulator_dev *rdev)
402404

403405
static int mt6358_get_status(struct regulator_dev *rdev)
404406
{
407+
const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
405408
int ret;
406409
u32 regval;
407-
struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
408410

409411
ret = regmap_read(rdev->regmap, info->status_reg, &regval);
410412
if (ret != 0) {
@@ -418,7 +420,7 @@ static int mt6358_get_status(struct regulator_dev *rdev)
418420
static int mt6358_regulator_set_mode(struct regulator_dev *rdev,
419421
unsigned int mode)
420422
{
421-
struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
423+
const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
422424
int val;
423425

424426
switch (mode) {
@@ -443,7 +445,7 @@ static int mt6358_regulator_set_mode(struct regulator_dev *rdev,
443445

444446
static unsigned int mt6358_regulator_get_mode(struct regulator_dev *rdev)
445447
{
446-
struct mt6358_regulator_info *info = rdev_get_drvdata(rdev);
448+
const struct mt6358_regulator_info *info = to_regulator_info(rdev->desc);
447449
int ret, regval;
448450

449451
ret = regmap_read(rdev->regmap, info->modeset_reg, &regval);
@@ -498,7 +500,7 @@ static const struct regulator_ops mt6358_volt_fixed_ops = {
498500
};
499501

500502
/* The array is indexed by id(MT6358_ID_XXX) */
501-
static struct mt6358_regulator_info mt6358_regulators[] = {
503+
static const struct mt6358_regulator_info mt6358_regulators[] = {
502504
MT6358_BUCK("buck_vdram1", VDRAM1, 500000, 2087500, 12500,
503505
buck_volt_range2, 0x7f, MT6358_BUCK_VDRAM1_DBG0, 0x7f,
504506
MT6358_VDRAM1_ANA_CON0, 8),
@@ -589,7 +591,7 @@ static struct mt6358_regulator_info mt6358_regulators[] = {
589591
};
590592

591593
/* The array is indexed by id(MT6366_ID_XXX) */
592-
static struct mt6358_regulator_info mt6366_regulators[] = {
594+
static const struct mt6358_regulator_info mt6366_regulators[] = {
593595
MT6366_BUCK("buck_vdram1", VDRAM1, 500000, 2087500, 12500,
594596
buck_volt_range2, 0x7f, MT6358_BUCK_VDRAM1_DBG0, 0x7f,
595597
MT6358_VDRAM1_ANA_CON0, 8),
@@ -712,7 +714,7 @@ static int mt6358_regulator_probe(struct platform_device *pdev)
712714
struct mt6397_chip *mt6397 = dev_get_drvdata(pdev->dev.parent);
713715
struct regulator_config config = {};
714716
struct regulator_dev *rdev;
715-
struct mt6358_regulator_info *mt6358_info;
717+
const struct mt6358_regulator_info *mt6358_info;
716718
int i, max_regulator, ret;
717719

718720
ret = mt6358_sync_vcn33_setting(&pdev->dev);
@@ -729,7 +731,6 @@ static int mt6358_regulator_probe(struct platform_device *pdev)
729731

730732
for (i = 0; i < max_regulator; i++) {
731733
config.dev = &pdev->dev;
732-
config.driver_data = &mt6358_info[i];
733734
config.regmap = mt6397->regmap;
734735

735736
rdev = devm_regulator_register(&pdev->dev,

0 commit comments

Comments
 (0)