regulator: mcp16502: Remove unneeded fields from struct mcp16502

At the context with rdev, we can use rdev->regmap instead of mcp->rmap.
The *rdev[NUM_REGULATORS] is not required because current code uses
devm_regulator_register() so we don't need to store *rdev for clean up
paths.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
Axel Lin 2019-04-11 09:59:22 +08:00 committed by Mark Brown
parent ab54a4d7b0
commit 4cf469539b
No known key found for this signature in database
GPG Key ID: 24D68B725D5487D0
1 changed files with 16 additions and 24 deletions

View File

@ -119,8 +119,6 @@ enum {
* @lpm: LPM GPIO descriptor
*/
struct mcp16502 {
struct regulator_dev *rdev[NUM_REGULATORS];
struct regmap *rmap;
struct gpio_desc *lpm;
};
@ -179,13 +177,12 @@ static unsigned int mcp16502_get_mode(struct regulator_dev *rdev)
{
unsigned int val;
int ret, reg;
struct mcp16502 *mcp = rdev_get_drvdata(rdev);
reg = mcp16502_get_reg(rdev, MCP16502_OPMODE_ACTIVE);
if (reg < 0)
return reg;
ret = regmap_read(mcp->rmap, reg, &val);
ret = regmap_read(rdev->regmap, reg, &val);
if (ret)
return ret;
@ -211,7 +208,6 @@ static int _mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode,
{
int val;
int reg;
struct mcp16502 *mcp = rdev_get_drvdata(rdev);
reg = mcp16502_get_reg(rdev, op_mode);
if (reg < 0)
@ -228,7 +224,7 @@ static int _mcp16502_set_mode(struct regulator_dev *rdev, unsigned int mode,
return -EINVAL;
}
reg = regmap_update_bits(mcp->rmap, reg, MCP16502_MODE, val);
reg = regmap_update_bits(rdev->regmap, reg, MCP16502_MODE, val);
return reg;
}
@ -247,9 +243,8 @@ static int mcp16502_get_status(struct regulator_dev *rdev)
{
int ret;
unsigned int val;
struct mcp16502 *mcp = rdev_get_drvdata(rdev);
ret = regmap_read(mcp->rmap, MCP16502_STAT_BASE(rdev_get_id(rdev)),
ret = regmap_read(rdev->regmap, MCP16502_STAT_BASE(rdev_get_id(rdev)),
&val);
if (ret)
return ret;
@ -290,7 +285,6 @@ static int mcp16502_suspend_get_target_reg(struct regulator_dev *rdev)
*/
static int mcp16502_set_suspend_voltage(struct regulator_dev *rdev, int uV)
{
struct mcp16502 *mcp = rdev_get_drvdata(rdev);
int sel = regulator_map_voltage_linear_range(rdev, uV, uV);
int reg = mcp16502_suspend_get_target_reg(rdev);
@ -300,7 +294,7 @@ static int mcp16502_set_suspend_voltage(struct regulator_dev *rdev, int uV)
if (reg < 0)
return reg;
return regmap_update_bits(mcp->rmap, reg, MCP16502_VSEL, sel);
return regmap_update_bits(rdev->regmap, reg, MCP16502_VSEL, sel);
}
/*
@ -328,13 +322,12 @@ static int mcp16502_set_suspend_mode(struct regulator_dev *rdev,
*/
static int mcp16502_set_suspend_enable(struct regulator_dev *rdev)
{
struct mcp16502 *mcp = rdev_get_drvdata(rdev);
int reg = mcp16502_suspend_get_target_reg(rdev);
if (reg < 0)
return reg;
return regmap_update_bits(mcp->rmap, reg, MCP16502_EN, MCP16502_EN);
return regmap_update_bits(rdev->regmap, reg, MCP16502_EN, MCP16502_EN);
}
/*
@ -342,13 +335,12 @@ static int mcp16502_set_suspend_enable(struct regulator_dev *rdev)
*/
static int mcp16502_set_suspend_disable(struct regulator_dev *rdev)
{
struct mcp16502 *mcp = rdev_get_drvdata(rdev);
int reg = mcp16502_suspend_get_target_reg(rdev);
if (reg < 0)
return reg;
return regmap_update_bits(mcp->rmap, reg, MCP16502_EN, 0);
return regmap_update_bits(rdev->regmap, reg, MCP16502_EN, 0);
}
#endif /* CONFIG_SUSPEND */
@ -441,17 +433,16 @@ static const struct regmap_config mcp16502_regmap_config = {
static int setup_regulators(struct mcp16502 *mcp, struct device *dev,
struct regulator_config config)
{
struct regulator_dev *rdev;
int i;
for (i = 0; i < NUM_REGULATORS; i++) {
mcp->rdev[i] = devm_regulator_register(dev,
&mcp16502_desc[i],
&config);
if (IS_ERR(mcp->rdev[i])) {
rdev = devm_regulator_register(dev, &mcp16502_desc[i], &config);
if (IS_ERR(rdev)) {
dev_err(dev,
"failed to register %s regulator %ld\n",
mcp16502_desc[i].name, PTR_ERR(mcp->rdev[i]));
return PTR_ERR(mcp->rdev[i]);
mcp16502_desc[i].name, PTR_ERR(rdev));
return PTR_ERR(rdev);
}
}
@ -464,6 +455,7 @@ static int mcp16502_probe(struct i2c_client *client,
struct regulator_config config = { };
struct device *dev;
struct mcp16502 *mcp;
struct regmap *rmap;
int ret = 0;
dev = &client->dev;
@ -473,15 +465,15 @@ static int mcp16502_probe(struct i2c_client *client,
if (!mcp)
return -ENOMEM;
mcp->rmap = devm_regmap_init_i2c(client, &mcp16502_regmap_config);
if (IS_ERR(mcp->rmap)) {
ret = PTR_ERR(mcp->rmap);
rmap = devm_regmap_init_i2c(client, &mcp16502_regmap_config);
if (IS_ERR(rmap)) {
ret = PTR_ERR(rmap);
dev_err(dev, "regmap init failed: %d\n", ret);
return ret;
}
i2c_set_clientdata(client, mcp);
config.regmap = mcp->rmap;
config.regmap = rmap;
config.driver_data = mcp;
mcp->lpm = devm_gpiod_get(dev, "lpm", GPIOD_OUT_LOW);