Skip to content

Commit

Permalink
regulator: Few constifications of static data
Browse files Browse the repository at this point in the history
Merge series from Krzysztof Kozlowski <[email protected]>:

Few cleanups (safer code), built tested.  Last two patches should
probably be tested.
  • Loading branch information
broonie committed Sep 11, 2024
2 parents 886fee3 + c4d6a80 commit 5faf6da
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 105 deletions.
22 changes: 11 additions & 11 deletions drivers/regulator/da9052-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ struct da9052_regulator_info {

struct da9052_regulator {
struct da9052 *da9052;
struct da9052_regulator_info *info;
const struct da9052_regulator_info *info;
struct regulator_dev *rdev;
};

static int verify_range(struct da9052_regulator_info *info,
static int verify_range(const struct da9052_regulator_info *info,
int min_uV, int max_uV)
{
if (min_uV > info->max_uV || max_uV < info->min_uV)
Expand Down Expand Up @@ -151,7 +151,7 @@ static int da9052_list_voltage(struct regulator_dev *rdev,
unsigned int selector)
{
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
struct da9052_regulator_info *info = regulator->info;
const struct da9052_regulator_info *info = regulator->info;
int id = rdev_get_id(rdev);
int volt_uV;

Expand All @@ -175,7 +175,7 @@ static int da9052_map_voltage(struct regulator_dev *rdev,
int min_uV, int max_uV)
{
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
struct da9052_regulator_info *info = regulator->info;
const struct da9052_regulator_info *info = regulator->info;
int id = rdev_get_id(rdev);
int ret, sel;

Expand Down Expand Up @@ -206,7 +206,7 @@ static int da9052_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned int selector)
{
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
struct da9052_regulator_info *info = regulator->info;
const struct da9052_regulator_info *info = regulator->info;
int id = rdev_get_id(rdev);
int ret;

Expand Down Expand Up @@ -237,7 +237,7 @@ static int da9052_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
unsigned int new_sel)
{
struct da9052_regulator *regulator = rdev_get_drvdata(rdev);
struct da9052_regulator_info *info = regulator->info;
const struct da9052_regulator_info *info = regulator->info;
int id = rdev_get_id(rdev);
int ret = 0;

Expand Down Expand Up @@ -327,7 +327,7 @@ static const struct regulator_ops da9052_ldo_ops = {
.activate_bit = (abits),\
}

static struct da9052_regulator_info da9052_regulator_info[] = {
static const struct da9052_regulator_info da9052_regulator_info[] = {
DA9052_DCDC(BUCK1, buck1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO),
DA9052_DCDC(BUCK2, buck2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO),
DA9052_DCDC(BUCK3, buck3, 25, 950, 2525, 6, 6, DA9052_SUPPLY_VBMEMGO),
Expand All @@ -344,7 +344,7 @@ static struct da9052_regulator_info da9052_regulator_info[] = {
DA9052_LDO(LDO10, ldo10, 50, 1200, 3600, 6, 6, 0),
};

static struct da9052_regulator_info da9053_regulator_info[] = {
static const struct da9052_regulator_info da9053_regulator_info[] = {
DA9052_DCDC(BUCK1, buck1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO),
DA9052_DCDC(BUCK2, buck2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO),
DA9052_DCDC(BUCK3, buck3, 25, 950, 2525, 6, 6, DA9052_SUPPLY_VBMEMGO),
Expand All @@ -361,10 +361,10 @@ static struct da9052_regulator_info da9053_regulator_info[] = {
DA9052_LDO(LDO10, ldo10, 50, 1200, 3600, 6, 6, 0),
};

static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id,
int id)
static inline const struct da9052_regulator_info *find_regulator_info(u8 chip_id,
int id)
{
struct da9052_regulator_info *info;
const struct da9052_regulator_info *info;
int i;

switch (chip_id) {
Expand Down
28 changes: 14 additions & 14 deletions drivers/regulator/da9055-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ struct da9055_regulator_info {

struct da9055_regulator {
struct da9055 *da9055;
struct da9055_regulator_info *info;
const struct da9055_regulator_info *info;
struct regulator_dev *rdev;
enum gpio_select reg_rselect;
};

static unsigned int da9055_buck_get_mode(struct regulator_dev *rdev)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
int ret, mode = 0;

ret = da9055_reg_read(regulator->da9055, info->mode.reg);
Expand All @@ -107,7 +107,7 @@ static int da9055_buck_set_mode(struct regulator_dev *rdev,
unsigned int mode)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
int val = 0;

switch (mode) {
Expand All @@ -129,7 +129,7 @@ static int da9055_buck_set_mode(struct regulator_dev *rdev,
static unsigned int da9055_ldo_get_mode(struct regulator_dev *rdev)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
int ret;

ret = da9055_reg_read(regulator->da9055, info->volt.reg_b);
Expand All @@ -145,7 +145,7 @@ static unsigned int da9055_ldo_get_mode(struct regulator_dev *rdev)
static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
struct da9055_volt_reg volt = info->volt;
int val = 0;

Expand All @@ -167,7 +167,7 @@ static int da9055_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode)
static int da9055_regulator_get_voltage_sel(struct regulator_dev *rdev)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
struct da9055_volt_reg volt = info->volt;
int ret, sel;

Expand Down Expand Up @@ -199,7 +199,7 @@ static int da9055_regulator_set_voltage_sel(struct regulator_dev *rdev,
unsigned int selector)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
int ret;

/*
Expand Down Expand Up @@ -242,7 +242,7 @@ static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
int uV)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
int ret;

/* Select register set B for suspend voltage ramping. */
Expand All @@ -264,7 +264,7 @@ static int da9055_regulator_set_suspend_voltage(struct regulator_dev *rdev,
static int da9055_suspend_enable(struct regulator_dev *rdev)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;

/* Select register set B for voltage ramping. */
if (regulator->reg_rselect == NO_GPIO)
Expand All @@ -277,7 +277,7 @@ static int da9055_suspend_enable(struct regulator_dev *rdev)
static int da9055_suspend_disable(struct regulator_dev *rdev)
{
struct da9055_regulator *regulator = rdev_get_drvdata(rdev);
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;

/* Diselect register set B. */
if (regulator->reg_rselect == NO_GPIO)
Expand Down Expand Up @@ -396,7 +396,7 @@ static const struct regulator_ops da9055_ldo_ops = {
},\
}

static struct da9055_regulator_info da9055_regulator_info[] = {
static const struct da9055_regulator_info da9055_regulator_info[] = {
DA9055_BUCK(BUCK1, 25, 725, 2075, 6, 9, 0xc, 2),
DA9055_BUCK(BUCK2, 25, 925, 2500, 6, 0, 3, 0),
DA9055_LDO(LDO1, 50, 900, 3300, 6, 2),
Expand All @@ -417,7 +417,7 @@ static int da9055_gpio_init(struct device *dev,
struct regulator_config *config,
struct da9055_pdata *pdata, int id)
{
struct da9055_regulator_info *info = regulator->info;
const struct da9055_regulator_info *info = regulator->info;
struct gpio_desc *ren;
struct gpio_desc *ena;
struct gpio_desc *rsel;
Expand Down Expand Up @@ -491,9 +491,9 @@ static irqreturn_t da9055_ldo5_6_oc_irq(int irq, void *data)
return IRQ_HANDLED;
}

static inline struct da9055_regulator_info *find_regulator_info(int id)
static inline const struct da9055_regulator_info *find_regulator_info(int id)
{
struct da9055_regulator_info *info;
const struct da9055_regulator_info *info;
int i;

for (i = 0; i < ARRAY_SIZE(da9055_regulator_info); i++) {
Expand Down
2 changes: 1 addition & 1 deletion drivers/regulator/da9063-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ static const struct da9063_regulator_info da9063_regulator_info[] = {
};

/* Link chip model with regulators info table */
static struct da9063_dev_model regulators_models[] = {
static const struct da9063_dev_model regulators_models[] = {
{
.regulator_info = da9063_regulator_info,
.n_regulators = ARRAY_SIZE(da9063_regulator_info),
Expand Down
20 changes: 10 additions & 10 deletions drivers/regulator/da9121-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,47 +53,47 @@ struct da9121_range {
int reg_max;
};

static struct da9121_range da9121_10A_2phase_current = {
static const struct da9121_range da9121_10A_2phase_current = {
.val_min = 7000000,
.val_max = 20000000,
.val_stp = 1000000,
.reg_min = 1,
.reg_max = 14,
};

static struct da9121_range da9121_6A_2phase_current = {
static const struct da9121_range da9121_6A_2phase_current = {
.val_min = 7000000,
.val_max = 12000000,
.val_stp = 1000000,
.reg_min = 1,
.reg_max = 6,
};

static struct da9121_range da9121_5A_1phase_current = {
static const struct da9121_range da9121_5A_1phase_current = {
.val_min = 3500000,
.val_max = 10000000,
.val_stp = 500000,
.reg_min = 1,
.reg_max = 14,
};

static struct da9121_range da9121_3A_1phase_current = {
static const struct da9121_range da9121_3A_1phase_current = {
.val_min = 3500000,
.val_max = 6000000,
.val_stp = 500000,
.reg_min = 1,
.reg_max = 6,
};

static struct da9121_range da914x_40A_4phase_current = {
static const struct da9121_range da914x_40A_4phase_current = {
.val_min = 26000000,
.val_max = 78000000,
.val_stp = 4000000,
.reg_min = 1,
.reg_max = 14,
};

static struct da9121_range da914x_20A_2phase_current = {
static const struct da9121_range da914x_20A_2phase_current = {
.val_min = 13000000,
.val_max = 39000000,
.val_stp = 2000000,
Expand All @@ -104,7 +104,7 @@ static struct da9121_range da914x_20A_2phase_current = {
struct da9121_variant_info {
int num_bucks;
int num_phases;
struct da9121_range *current_range;
const struct da9121_range *current_range;
};

static const struct da9121_variant_info variant_parameters[] = {
Expand Down Expand Up @@ -188,7 +188,7 @@ static int da9121_get_current_limit(struct regulator_dev *rdev)
{
struct da9121 *chip = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
struct da9121_range *range =
const struct da9121_range *range =
variant_parameters[chip->variant_id].current_range;
unsigned int val = 0;
int ret = 0;
Expand Down Expand Up @@ -219,7 +219,7 @@ static int da9121_ceiling_selector(struct regulator_dev *rdev,
unsigned int *selector)
{
struct da9121 *chip = rdev_get_drvdata(rdev);
struct da9121_range *range =
const struct da9121_range *range =
variant_parameters[chip->variant_id].current_range;
unsigned int level;
unsigned int i = 0;
Expand Down Expand Up @@ -259,7 +259,7 @@ static int da9121_set_current_limit(struct regulator_dev *rdev,
{
struct da9121 *chip = rdev_get_drvdata(rdev);
int id = rdev_get_id(rdev);
struct da9121_range *range =
const struct da9121_range *range =
variant_parameters[chip->variant_id].current_range;
unsigned int sel = 0;
int ret = 0;
Expand Down
14 changes: 7 additions & 7 deletions drivers/regulator/hi6421-regulator.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ static const struct regulator_ops hi6421_buck345_ops;
}

/* HI6421 regulator information */
static struct hi6421_regulator_info
static const struct hi6421_regulator_info
hi6421_regulator_info[HI6421_NUM_REGULATORS] = {
HI6421_LDO(LDO0, hi6421_vout0, ldo_0_voltages, 0x20, 0x07, 0x20, 0x10,
10000, 0x20, 8000),
Expand Down Expand Up @@ -384,7 +384,7 @@ static int hi6421_regulator_enable(struct regulator_dev *rdev)

static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev)
{
struct hi6421_regulator_info *info;
const struct hi6421_regulator_info *info;
unsigned int reg_val;

info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
Expand All @@ -397,7 +397,7 @@ static unsigned int hi6421_regulator_ldo_get_mode(struct regulator_dev *rdev)

static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev)
{
struct hi6421_regulator_info *info;
const struct hi6421_regulator_info *info;
unsigned int reg_val;

info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
Expand All @@ -411,7 +411,7 @@ static unsigned int hi6421_regulator_buck_get_mode(struct regulator_dev *rdev)
static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev,
unsigned int mode)
{
struct hi6421_regulator_info *info;
const struct hi6421_regulator_info *info;
unsigned int new_mode;

info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
Expand All @@ -436,7 +436,7 @@ static int hi6421_regulator_ldo_set_mode(struct regulator_dev *rdev,
static int hi6421_regulator_buck_set_mode(struct regulator_dev *rdev,
unsigned int mode)
{
struct hi6421_regulator_info *info;
const struct hi6421_regulator_info *info;
unsigned int new_mode;

info = container_of(rdev->desc, struct hi6421_regulator_info, desc);
Expand All @@ -462,7 +462,7 @@ static unsigned int
hi6421_regulator_ldo_get_optimum_mode(struct regulator_dev *rdev,
int input_uV, int output_uV, int load_uA)
{
struct hi6421_regulator_info *info;
const struct hi6421_regulator_info *info;

info = container_of(rdev->desc, struct hi6421_regulator_info, desc);

Expand Down Expand Up @@ -539,7 +539,7 @@ static int hi6421_regulator_probe(struct platform_device *pdev)
{
struct hi6421_pmic *pmic = dev_get_drvdata(pdev->dev.parent);
struct hi6421_regulator_pdata *pdata;
struct hi6421_regulator_info *info;
const struct hi6421_regulator_info *info;
struct regulator_config config = { };
struct regulator_dev *rdev;
int i;
Expand Down
Loading

0 comments on commit 5faf6da

Please sign in to comment.