diff options
Diffstat (limited to 'drivers/regulator/rc5t583-regulator.c')
-rw-r--r-- | drivers/regulator/rc5t583-regulator.c | 96 |
1 files changed, 15 insertions, 81 deletions
diff --git a/drivers/regulator/rc5t583-regulator.c b/drivers/regulator/rc5t583-regulator.c index fb87c1b61b62..7951260e4cd4 100644 --- a/drivers/regulator/rc5t583-regulator.c +++ b/drivers/regulator/rc5t583-regulator.c @@ -36,12 +36,8 @@ struct rc5t583_regulator_info { int deepsleep_id; /* Regulator register address.*/ - uint8_t reg_en_reg; - uint8_t en_bit; uint8_t reg_disc_reg; uint8_t disc_bit; - uint8_t vout_reg; - uint8_t vout_mask; uint8_t deepsleep_reg; /* Chip constraints on regulator behavior */ @@ -66,56 +62,6 @@ struct rc5t583_regulator { struct regulator_dev *rdev; }; -static int rc5t583_reg_is_enabled(struct regulator_dev *rdev) -{ - struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); - struct rc5t583_regulator_info *ri = reg->reg_info; - uint8_t control; - int ret; - - ret = rc5t583_read(reg->mfd->dev, ri->reg_en_reg, &control); - if (ret < 0) { - dev_err(&rdev->dev, - "Error in reading the control register 0x%02x\n", - ri->reg_en_reg); - return ret; - } - return !!(control & BIT(ri->en_bit)); -} - -static int rc5t583_reg_enable(struct regulator_dev *rdev) -{ - struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); - struct rc5t583_regulator_info *ri = reg->reg_info; - int ret; - - ret = rc5t583_set_bits(reg->mfd->dev, ri->reg_en_reg, - (1 << ri->en_bit)); - if (ret < 0) { - dev_err(&rdev->dev, - "Error in setting bit of STATE register 0x%02x\n", - ri->reg_en_reg); - return ret; - } - return ret; -} - -static int rc5t583_reg_disable(struct regulator_dev *rdev) -{ - struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); - struct rc5t583_regulator_info *ri = reg->reg_info; - int ret; - - ret = rc5t583_clear_bits(reg->mfd->dev, ri->reg_en_reg, - (1 << ri->en_bit)); - if (ret < 0) - dev_err(&rdev->dev, - "Error in clearing bit of STATE register 0x%02x\n", - ri->reg_en_reg); - - return ret; -} - static int rc5t583_list_voltage(struct regulator_dev *rdev, unsigned selector) { struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); @@ -142,33 +88,20 @@ static int rc5t583_set_voltage(struct regulator_dev *rdev, *selector = sel; - ret = rc5t583_update(reg->mfd->dev, ri->vout_reg, sel, ri->vout_mask); + ret = rc5t583_update(reg->mfd->dev, rdev->desc->vsel_reg, sel, + rdev->desc->vsel_mask); if (ret < 0) - dev_err(&rdev->dev, - "Error in update voltage register 0x%02x\n", ri->vout_reg); + dev_err(&rdev->dev, "Error in update voltage register 0x%02x\n", + rdev->desc->vsel_reg); return ret; } -static int rc5t583_get_voltage_sel(struct regulator_dev *rdev) -{ - struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); - struct rc5t583_regulator_info *ri = reg->reg_info; - uint8_t vsel; - int ret; - ret = rc5t583_read(reg->mfd->dev, ri->vout_reg, &vsel); - if (ret < 0) { - dev_err(&rdev->dev, - "Error in reading voltage register 0x%02x\n", ri->vout_reg); - return ret; - } - return vsel & ri->vout_mask; -} - static int rc5t583_regulator_enable_time(struct regulator_dev *rdev) { struct rc5t583_regulator *reg = rdev_get_drvdata(rdev); - int vsel = rc5t583_get_voltage_sel(rdev); + int vsel = regulator_get_voltage_sel_regmap(rdev); int curr_uV = rc5t583_list_voltage(rdev, vsel); + return DIV_ROUND_UP(curr_uV, reg->reg_info->enable_uv_per_us); } @@ -192,11 +125,11 @@ static int rc5t583_set_voltage_time_sel(struct regulator_dev *rdev, static struct regulator_ops rc5t583_ops = { - .is_enabled = rc5t583_reg_is_enabled, - .enable = rc5t583_reg_enable, - .disable = rc5t583_reg_disable, + .is_enabled = regulator_is_enabled_regmap, + .enable = regulator_enable_regmap, + .disable = regulator_disable_regmap, .enable_time = rc5t583_regulator_enable_time, - .get_voltage_sel = rc5t583_get_voltage_sel, + .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage = rc5t583_set_voltage, .list_voltage = rc5t583_list_voltage, .set_voltage_time_sel = rc5t583_set_voltage_time_sel, @@ -205,12 +138,8 @@ static struct regulator_ops rc5t583_ops = { #define RC5T583_REG(_id, _en_reg, _en_bit, _disc_reg, _disc_bit, \ _vout_mask, _min_mv, _max_mv, _step_uV, _enable_mv) \ { \ - .reg_en_reg = RC5T583_REG_##_en_reg, \ - .en_bit = _en_bit, \ .reg_disc_reg = RC5T583_REG_##_disc_reg, \ .disc_bit = _disc_bit, \ - .vout_reg = RC5T583_REG_##_id##DAC, \ - .vout_mask = _vout_mask, \ .deepsleep_reg = RC5T583_REG_##_id##DAC_DS, \ .min_uV = _min_mv * 1000, \ .max_uV = _max_mv * 1000, \ @@ -225,6 +154,10 @@ static struct regulator_ops rc5t583_ops = { .ops = &rc5t583_ops, \ .type = REGULATOR_VOLTAGE, \ .owner = THIS_MODULE, \ + .vsel_reg = RC5T583_REG_##_id##DAC, \ + .vsel_mask = _vout_mask, \ + .enable_reg = RC5T583_REG_##_en_reg, \ + .enable_mask = BIT(_en_bit), \ }, \ } @@ -303,6 +236,7 @@ skip_ext_pwr_config: config.dev = &pdev->dev; config.init_data = reg_data; config.driver_data = reg; + config.regmap = rc5t583->regmap; rdev = regulator_register(&ri->desc, &config); if (IS_ERR(rdev)) { |