regulator: max77693: Support different register configurations
Add support for different configurations of charger's registers so the same driver could be used on other devices (e.g. MAX77843). Signed-off-by: Krzysztof Kozlowski <k.kozlowski.k@gmail.com> Acked-by: Mark Brown <broonie@kernel.org> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
b3b58cee8a
commit
5b5e771fb7
1 changed files with 27 additions and 12 deletions
|
@ -33,7 +33,13 @@
|
||||||
#include <linux/regulator/of_regulator.h>
|
#include <linux/regulator/of_regulator.h>
|
||||||
#include <linux/regmap.h>
|
#include <linux/regmap.h>
|
||||||
|
|
||||||
#define CHGIN_ILIM_STEP_20mA 20000
|
/* Charger regulator differences between MAX77693 and MAX77843 */
|
||||||
|
struct chg_reg_data {
|
||||||
|
unsigned int linear_reg;
|
||||||
|
unsigned int linear_mask;
|
||||||
|
unsigned int uA_step;
|
||||||
|
unsigned int min_sel;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
|
* CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
|
||||||
|
@ -42,25 +48,26 @@
|
||||||
*/
|
*/
|
||||||
static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
|
static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
|
||||||
{
|
{
|
||||||
|
const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
|
||||||
unsigned int chg_min_uA = rdev->constraints->min_uA;
|
unsigned int chg_min_uA = rdev->constraints->min_uA;
|
||||||
unsigned int chg_max_uA = rdev->constraints->max_uA;
|
unsigned int chg_max_uA = rdev->constraints->max_uA;
|
||||||
unsigned int reg, sel;
|
unsigned int reg, sel;
|
||||||
unsigned int val;
|
unsigned int val;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = regmap_read(rdev->regmap, MAX77693_CHG_REG_CHG_CNFG_09, ®);
|
ret = regmap_read(rdev->regmap, reg_data->linear_reg, ®);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
sel = reg & CHG_CNFG_09_CHGIN_ILIM_MASK;
|
sel = reg & reg_data->linear_mask;
|
||||||
|
|
||||||
/* the first four codes for charger current are all 60mA */
|
/* the first four codes for charger current are all 60mA */
|
||||||
if (sel <= 3)
|
if (sel <= reg_data->min_sel)
|
||||||
sel = 0;
|
sel = 0;
|
||||||
else
|
else
|
||||||
sel -= 3;
|
sel -= reg_data->min_sel;
|
||||||
|
|
||||||
val = chg_min_uA + CHGIN_ILIM_STEP_20mA * sel;
|
val = chg_min_uA + reg_data->uA_step * sel;
|
||||||
if (val > chg_max_uA)
|
if (val > chg_max_uA)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -70,20 +77,20 @@ static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
|
||||||
static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
|
static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
|
||||||
int min_uA, int max_uA)
|
int min_uA, int max_uA)
|
||||||
{
|
{
|
||||||
|
const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
|
||||||
unsigned int chg_min_uA = rdev->constraints->min_uA;
|
unsigned int chg_min_uA = rdev->constraints->min_uA;
|
||||||
int sel = 0;
|
int sel = 0;
|
||||||
|
|
||||||
while (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel < min_uA)
|
while (chg_min_uA + reg_data->uA_step * sel < min_uA)
|
||||||
sel++;
|
sel++;
|
||||||
|
|
||||||
if (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel > max_uA)
|
if (chg_min_uA + reg_data->uA_step * sel > max_uA)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
/* the first four codes for charger current are all 60mA */
|
/* the first four codes for charger current are all 60mA */
|
||||||
sel += 3;
|
sel += reg_data->min_sel;
|
||||||
|
|
||||||
return regmap_write(rdev->regmap,
|
return regmap_write(rdev->regmap, reg_data->linear_reg, sel);
|
||||||
MAX77693_CHG_REG_CHG_CNFG_09, sel);
|
|
||||||
}
|
}
|
||||||
/* end of CHARGER regulator ops */
|
/* end of CHARGER regulator ops */
|
||||||
|
|
||||||
|
@ -145,6 +152,13 @@ static const struct regulator_desc regulators[] = {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static const struct chg_reg_data max77693_chg_reg_data = {
|
||||||
|
.linear_reg = MAX77693_CHG_REG_CHG_CNFG_09,
|
||||||
|
.linear_mask = CHG_CNFG_09_CHGIN_ILIM_MASK,
|
||||||
|
.uA_step = 20000,
|
||||||
|
.min_sel = 3,
|
||||||
|
};
|
||||||
|
|
||||||
static int max77693_pmic_probe(struct platform_device *pdev)
|
static int max77693_pmic_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
|
struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
|
||||||
|
@ -153,6 +167,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
|
||||||
|
|
||||||
config.dev = iodev->dev;
|
config.dev = iodev->dev;
|
||||||
config.regmap = iodev->regmap;
|
config.regmap = iodev->regmap;
|
||||||
|
config.driver_data = (void *)&max77693_chg_reg_data;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
|
for (i = 0; i < ARRAY_SIZE(regulators); i++) {
|
||||||
struct regulator_dev *rdev;
|
struct regulator_dev *rdev;
|
||||||
|
@ -170,7 +185,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
|
||||||
}
|
}
|
||||||
|
|
||||||
static const struct platform_device_id max77693_pmic_id[] = {
|
static const struct platform_device_id max77693_pmic_id[] = {
|
||||||
{"max77693-pmic", 0},
|
{ "max77693-pmic", TYPE_MAX77693 },
|
||||||
{},
|
{},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue