Commit 4cf12735 authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

regulator: lp8755: Get rid of lp8755_read/lp8755_write/lp8755_update_bits

Just use regmap_read/regmap_write/regmap_update_bits instead.
Signed-off-by: default avatarAxel Lin <axel.lin@ingics.com>
Link: https://lore.kernel.org/r/20200802090638.380589-1-axel.lin@ingics.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 6f4ac284
...@@ -49,53 +49,15 @@ struct lp8755_chip { ...@@ -49,53 +49,15 @@ struct lp8755_chip {
struct regulator_dev *rdev[LP8755_BUCK_MAX]; struct regulator_dev *rdev[LP8755_BUCK_MAX];
}; };
/**
*lp8755_read : read a single register value from lp8755.
*@pchip : device to read from
*@reg : register to read from
*@val : pointer to store read value
*/
static int lp8755_read(struct lp8755_chip *pchip, unsigned int reg,
unsigned int *val)
{
return regmap_read(pchip->regmap, reg, val);
}
/**
*lp8755_write : write a single register value to lp8755.
*@pchip : device to write to
*@reg : register to write to
*@val : value to be written
*/
static int lp8755_write(struct lp8755_chip *pchip, unsigned int reg,
unsigned int val)
{
return regmap_write(pchip->regmap, reg, val);
}
/**
*lp8755_update_bits : set the values of bit fields in lp8755 register.
*@pchip : device to read from
*@reg : register to update
*@mask : bitmask to be changed
*@val : value for bitmask
*/
static int lp8755_update_bits(struct lp8755_chip *pchip, unsigned int reg,
unsigned int mask, unsigned int val)
{
return regmap_update_bits(pchip->regmap, reg, mask, val);
}
static int lp8755_buck_enable_time(struct regulator_dev *rdev) static int lp8755_buck_enable_time(struct regulator_dev *rdev)
{ {
int ret; int ret;
unsigned int regval; unsigned int regval;
enum lp8755_bucks id = rdev_get_id(rdev); enum lp8755_bucks id = rdev_get_id(rdev);
struct lp8755_chip *pchip = rdev_get_drvdata(rdev);
ret = lp8755_read(pchip, 0x12 + id, &regval); ret = regmap_read(rdev->regmap, 0x12 + id, &regval);
if (ret < 0) { if (ret < 0) {
dev_err(pchip->dev, "i2c access error %s\n", __func__); dev_err(&rdev->dev, "i2c access error %s\n", __func__);
return ret; return ret;
} }
return (regval & 0xff) * 100; return (regval & 0xff) * 100;
...@@ -115,17 +77,17 @@ static int lp8755_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) ...@@ -115,17 +77,17 @@ static int lp8755_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
break; break;
case REGULATOR_MODE_NORMAL: case REGULATOR_MODE_NORMAL:
/* enable automatic pwm/pfm mode */ /* enable automatic pwm/pfm mode */
ret = lp8755_update_bits(pchip, 0x08 + id, 0x20, 0x00); ret = regmap_update_bits(rdev->regmap, 0x08 + id, 0x20, 0x00);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
break; break;
case REGULATOR_MODE_IDLE: case REGULATOR_MODE_IDLE:
/* enable automatic pwm/pfm/lppfm mode */ /* enable automatic pwm/pfm/lppfm mode */
ret = lp8755_update_bits(pchip, 0x08 + id, 0x20, 0x20); ret = regmap_update_bits(rdev->regmap, 0x08 + id, 0x20, 0x20);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
ret = lp8755_update_bits(pchip, 0x10, 0x01, 0x01); ret = regmap_update_bits(rdev->regmap, 0x10, 0x01, 0x01);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
break; break;
...@@ -135,12 +97,12 @@ static int lp8755_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) ...@@ -135,12 +97,12 @@ static int lp8755_buck_set_mode(struct regulator_dev *rdev, unsigned int mode)
regbval = (0x01 << id); regbval = (0x01 << id);
} }
ret = lp8755_update_bits(pchip, 0x06, 0x01 << id, regbval); ret = regmap_update_bits(rdev->regmap, 0x06, 0x01 << id, regbval);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
return ret; return ret;
err_i2c: err_i2c:
dev_err(pchip->dev, "i2c access error %s\n", __func__); dev_err(&rdev->dev, "i2c access error %s\n", __func__);
return ret; return ret;
} }
...@@ -149,9 +111,8 @@ static unsigned int lp8755_buck_get_mode(struct regulator_dev *rdev) ...@@ -149,9 +111,8 @@ static unsigned int lp8755_buck_get_mode(struct regulator_dev *rdev)
int ret; int ret;
unsigned int regval; unsigned int regval;
enum lp8755_bucks id = rdev_get_id(rdev); enum lp8755_bucks id = rdev_get_id(rdev);
struct lp8755_chip *pchip = rdev_get_drvdata(rdev);
ret = lp8755_read(pchip, 0x06, &regval); ret = regmap_read(rdev->regmap, 0x06, &regval);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
...@@ -159,7 +120,7 @@ static unsigned int lp8755_buck_get_mode(struct regulator_dev *rdev) ...@@ -159,7 +120,7 @@ static unsigned int lp8755_buck_get_mode(struct regulator_dev *rdev)
if (regval & (0x01 << id)) if (regval & (0x01 << id))
return REGULATOR_MODE_FAST; return REGULATOR_MODE_FAST;
ret = lp8755_read(pchip, 0x08 + id, &regval); ret = regmap_read(rdev->regmap, 0x08 + id, &regval);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
...@@ -171,7 +132,7 @@ static unsigned int lp8755_buck_get_mode(struct regulator_dev *rdev) ...@@ -171,7 +132,7 @@ static unsigned int lp8755_buck_get_mode(struct regulator_dev *rdev)
return REGULATOR_MODE_NORMAL; return REGULATOR_MODE_NORMAL;
err_i2c: err_i2c:
dev_err(pchip->dev, "i2c access error %s\n", __func__); dev_err(&rdev->dev, "i2c access error %s\n", __func__);
return 0; return 0;
} }
...@@ -180,7 +141,6 @@ static int lp8755_buck_set_ramp(struct regulator_dev *rdev, int ramp) ...@@ -180,7 +141,6 @@ static int lp8755_buck_set_ramp(struct regulator_dev *rdev, int ramp)
int ret; int ret;
unsigned int regval = 0x00; unsigned int regval = 0x00;
enum lp8755_bucks id = rdev_get_id(rdev); enum lp8755_bucks id = rdev_get_id(rdev);
struct lp8755_chip *pchip = rdev_get_drvdata(rdev);
/* uV/us */ /* uV/us */
switch (ramp) { switch (ramp) {
...@@ -209,17 +169,17 @@ static int lp8755_buck_set_ramp(struct regulator_dev *rdev, int ramp) ...@@ -209,17 +169,17 @@ static int lp8755_buck_set_ramp(struct regulator_dev *rdev, int ramp)
regval = 0x00; regval = 0x00;
break; break;
default: default:
dev_err(pchip->dev, dev_err(&rdev->dev,
"Not supported ramp value %d %s\n", ramp, __func__); "Not supported ramp value %d %s\n", ramp, __func__);
return -EINVAL; return -EINVAL;
} }
ret = lp8755_update_bits(pchip, 0x07 + id, 0x07, regval); ret = regmap_update_bits(rdev->regmap, 0x07 + id, 0x07, regval);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
return ret; return ret;
err_i2c: err_i2c:
dev_err(pchip->dev, "i2c access error %s\n", __func__); dev_err(&rdev->dev, "i2c access error %s\n", __func__);
return ret; return ret;
} }
...@@ -278,7 +238,7 @@ static int lp8755_init_data(struct lp8755_chip *pchip) ...@@ -278,7 +238,7 @@ static int lp8755_init_data(struct lp8755_chip *pchip)
struct lp8755_platform_data *pdata = pchip->pdata; struct lp8755_platform_data *pdata = pchip->pdata;
/* read back muti-phase configuration */ /* read back muti-phase configuration */
ret = lp8755_read(pchip, 0x3D, &regval); ret = regmap_read(pchip->regmap, 0x3D, &regval);
if (ret < 0) if (ret < 0)
goto out_i2c_error; goto out_i2c_error;
pchip->mphase = regval & 0x0F; pchip->mphase = regval & 0x0F;
...@@ -356,11 +316,11 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data) ...@@ -356,11 +316,11 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data)
struct lp8755_chip *pchip = data; struct lp8755_chip *pchip = data;
/* read flag0 register */ /* read flag0 register */
ret = lp8755_read(pchip, 0x0D, &flag0); ret = regmap_read(pchip->regmap, 0x0D, &flag0);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
/* clear flag register to pull up int. pin */ /* clear flag register to pull up int. pin */
ret = lp8755_write(pchip, 0x0D, 0x00); ret = regmap_write(pchip->regmap, 0x0D, 0x00);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
...@@ -377,11 +337,11 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data) ...@@ -377,11 +337,11 @@ static irqreturn_t lp8755_irq_handler(int irq, void *data)
} }
/* read flag1 register */ /* read flag1 register */
ret = lp8755_read(pchip, 0x0E, &flag1); ret = regmap_read(pchip->regmap, 0x0E, &flag1);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
/* clear flag register to pull up int. pin */ /* clear flag register to pull up int. pin */
ret = lp8755_write(pchip, 0x0E, 0x00); ret = regmap_write(pchip->regmap, 0x0E, 0x00);
if (ret < 0) if (ret < 0)
goto err_i2c; goto err_i2c;
...@@ -423,7 +383,7 @@ static int lp8755_int_config(struct lp8755_chip *pchip) ...@@ -423,7 +383,7 @@ static int lp8755_int_config(struct lp8755_chip *pchip)
return 0; return 0;
} }
ret = lp8755_read(pchip, 0x0F, &regval); ret = regmap_read(pchip->regmap, 0x0F, &regval);
if (ret < 0) { if (ret < 0) {
dev_err(pchip->dev, "i2c access error %s\n", __func__); dev_err(pchip->dev, "i2c access error %s\n", __func__);
return ret; return ret;
...@@ -502,7 +462,7 @@ static int lp8755_probe(struct i2c_client *client, ...@@ -502,7 +462,7 @@ static int lp8755_probe(struct i2c_client *client,
err: err:
/* output disable */ /* output disable */
for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
lp8755_write(pchip, icnt, 0x00); regmap_write(pchip->regmap, icnt, 0x00);
return ret; return ret;
} }
...@@ -513,7 +473,7 @@ static int lp8755_remove(struct i2c_client *client) ...@@ -513,7 +473,7 @@ static int lp8755_remove(struct i2c_client *client)
struct lp8755_chip *pchip = i2c_get_clientdata(client); struct lp8755_chip *pchip = i2c_get_clientdata(client);
for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++) for (icnt = 0; icnt < LP8755_BUCK_MAX; icnt++)
lp8755_write(pchip, icnt, 0x00); regmap_write(pchip->regmap, icnt, 0x00);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment