Skip to content

Commit

Permalink
hwmon: ltc2991: remove device reference from state
Browse files Browse the repository at this point in the history
Remove device reference from struct ltc2991_state since it is used only
inside the init function.

Pass the struct device as parameter to the init function instead.

Link: https://lore.kernel.org/all/[email protected]/
Signed-off-by: Antoniu Miclaus <[email protected]>
  • Loading branch information
amiclaus authored and nunojsa committed Nov 3, 2023
1 parent f640915 commit 208ba5d
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions drivers/hwmon/ltc2991.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
#define LTC2991_VCC_CH_NR 0

struct ltc2991_state {
struct device *dev;
struct regmap *regmap;
u32 r_sense_uohm[LTC2991_MAX_CHANNEL];
bool temp_en[LTC2991_MAX_CHANNEL];
Expand Down Expand Up @@ -283,19 +282,19 @@ static const struct regmap_config ltc2991_regmap_config = {
.max_register = 0x1D,
};

static int ltc2991_init(struct ltc2991_state *st)
static int ltc2991_init(struct ltc2991_state *st, struct device *dev)
{
struct fwnode_handle *child;
int ret;
u32 val, addr;
u8 v5_v8_reg_data = 0, v1_v4_reg_data = 0;

ret = devm_regulator_get_enable(st->dev, "vcc");
ret = devm_regulator_get_enable(dev, "vcc");
if (ret)
return dev_err_probe(st->dev, ret,
return dev_err_probe(dev, ret,
"failed to enable regulator\n");

device_for_each_child_node(st->dev, child) {
device_for_each_child_node(dev, child) {
ret = fwnode_property_read_u32(child, "reg", &addr);
if (ret < 0) {
fwnode_handle_put(child);
Expand All @@ -312,7 +311,7 @@ static int ltc2991_init(struct ltc2991_state *st)
&val);
if (!ret) {
if (!val)
return dev_err_probe(st->dev, -EINVAL,
return dev_err_probe(dev, -EINVAL,
"shunt resistor value cannot be zero\n");

st->r_sense_uohm[addr] = val;
Expand Down Expand Up @@ -361,18 +360,18 @@ static int ltc2991_init(struct ltc2991_state *st)

ret = regmap_write(st->regmap, LTC2991_V5_V8_CTRL, v5_v8_reg_data);
if (ret)
return dev_err_probe(st->dev, ret,
return dev_err_probe(dev, ret,
"Error: Failed to set V5-V8 CTRL reg.\n");

ret = regmap_write(st->regmap, LTC2991_V1_V4_CTRL, v1_v4_reg_data);
if (ret)
return dev_err_probe(st->dev, ret,
return dev_err_probe(dev, ret,
"Error: Failed to set V1-V4 CTRL reg.\n");

ret = regmap_write(st->regmap, LTC2991_PWM_TH_LSB_T_INT,
LTC2991_REPEAT_ACQ_EN);
if (ret)
return dev_err_probe(st->dev, ret,
return dev_err_probe(dev, ret,
"Error: Failed to set contiuous mode.\n");

/* Enable all channels and trigger conversions */
Expand All @@ -394,12 +393,11 @@ static int ltc2991_i2c_probe(struct i2c_client *client,
if (!st)
return -ENOMEM;

st->dev = &client->dev;
st->regmap = devm_regmap_init_i2c(client, &ltc2991_regmap_config);
if (IS_ERR(st->regmap))
return PTR_ERR(st->regmap);

ret = ltc2991_init(st);
ret = ltc2991_init(st, &client->dev);
if (ret)
return ret;

Expand Down

0 comments on commit 208ba5d

Please sign in to comment.