aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKrzysztof Kozlowski <k.kozlowski.k@gmail.com>2015-07-15 08:59:49 -0400
committerMark Brown <broonie@kernel.org>2015-07-16 16:39:29 -0400
commit5b5e771fb711f95da859bf6be9fba4bc9919b5d5 (patch)
treecd0d623bcf9724bb2d44cf87cc8f88e64f589861
parentb3b58cee8aced52e3d7fdb387f40c782a4511198 (diff)
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>
-rw-r--r--drivers/regulator/max77693.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c
index 38722c8311a5..236851ab575a 100644
--- a/drivers/regulator/max77693.c
+++ b/drivers/regulator/max77693.c
@@ -33,7 +33,13 @@
33#include <linux/regulator/of_regulator.h> 33#include <linux/regulator/of_regulator.h>
34#include <linux/regmap.h> 34#include <linux/regmap.h>
35 35
36#define CHGIN_ILIM_STEP_20mA 20000 36/* Charger regulator differences between MAX77693 and MAX77843 */
37struct chg_reg_data {
38 unsigned int linear_reg;
39 unsigned int linear_mask;
40 unsigned int uA_step;
41 unsigned int min_sel;
42};
37 43
38/* 44/*
39 * CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA 45 * CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
@@ -42,25 +48,26 @@
42 */ 48 */
43static int max77693_chg_get_current_limit(struct regulator_dev *rdev) 49static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
44{ 50{
51 const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
45 unsigned int chg_min_uA = rdev->constraints->min_uA; 52 unsigned int chg_min_uA = rdev->constraints->min_uA;
46 unsigned int chg_max_uA = rdev->constraints->max_uA; 53 unsigned int chg_max_uA = rdev->constraints->max_uA;
47 unsigned int reg, sel; 54 unsigned int reg, sel;
48 unsigned int val; 55 unsigned int val;
49 int ret; 56 int ret;
50 57
51 ret = regmap_read(rdev->regmap, MAX77693_CHG_REG_CHG_CNFG_09, &reg); 58 ret = regmap_read(rdev->regmap, reg_data->linear_reg, &reg);
52 if (ret < 0) 59 if (ret < 0)
53 return ret; 60 return ret;
54 61
55 sel = reg & CHG_CNFG_09_CHGIN_ILIM_MASK; 62 sel = reg & reg_data->linear_mask;
56 63
57 /* the first four codes for charger current are all 60mA */ 64 /* the first four codes for charger current are all 60mA */
58 if (sel <= 3) 65 if (sel <= reg_data->min_sel)
59 sel = 0; 66 sel = 0;
60 else 67 else
61 sel -= 3; 68 sel -= reg_data->min_sel;
62 69
63 val = chg_min_uA + CHGIN_ILIM_STEP_20mA * sel; 70 val = chg_min_uA + reg_data->uA_step * sel;
64 if (val > chg_max_uA) 71 if (val > chg_max_uA)
65 return -EINVAL; 72 return -EINVAL;
66 73
@@ -70,20 +77,20 @@ static int max77693_chg_get_current_limit(struct regulator_dev *rdev)
70static int max77693_chg_set_current_limit(struct regulator_dev *rdev, 77static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
71 int min_uA, int max_uA) 78 int min_uA, int max_uA)
72{ 79{
80 const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
73 unsigned int chg_min_uA = rdev->constraints->min_uA; 81 unsigned int chg_min_uA = rdev->constraints->min_uA;
74 int sel = 0; 82 int sel = 0;
75 83
76 while (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel < min_uA) 84 while (chg_min_uA + reg_data->uA_step * sel < min_uA)
77 sel++; 85 sel++;
78 86
79 if (chg_min_uA + CHGIN_ILIM_STEP_20mA * sel > max_uA) 87 if (chg_min_uA + reg_data->uA_step * sel > max_uA)
80 return -EINVAL; 88 return -EINVAL;
81 89
82 /* the first four codes for charger current are all 60mA */ 90 /* the first four codes for charger current are all 60mA */
83 sel += 3; 91 sel += reg_data->min_sel;
84 92
85 return regmap_write(rdev->regmap, 93 return regmap_write(rdev->regmap, reg_data->linear_reg, sel);
86 MAX77693_CHG_REG_CHG_CNFG_09, sel);
87} 94}
88/* end of CHARGER regulator ops */ 95/* end of CHARGER regulator ops */
89 96
@@ -145,6 +152,13 @@ static const struct regulator_desc regulators[] = {
145 }, 152 },
146}; 153};
147 154
155static const struct chg_reg_data max77693_chg_reg_data = {
156 .linear_reg = MAX77693_CHG_REG_CHG_CNFG_09,
157 .linear_mask = CHG_CNFG_09_CHGIN_ILIM_MASK,
158 .uA_step = 20000,
159 .min_sel = 3,
160};
161
148static int max77693_pmic_probe(struct platform_device *pdev) 162static int max77693_pmic_probe(struct platform_device *pdev)
149{ 163{
150 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); 164 struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent);
@@ -153,6 +167,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
153 167
154 config.dev = iodev->dev; 168 config.dev = iodev->dev;
155 config.regmap = iodev->regmap; 169 config.regmap = iodev->regmap;
170 config.driver_data = (void *)&max77693_chg_reg_data;
156 171
157 for (i = 0; i < ARRAY_SIZE(regulators); i++) { 172 for (i = 0; i < ARRAY_SIZE(regulators); i++) {
158 struct regulator_dev *rdev; 173 struct regulator_dev *rdev;
@@ -170,7 +185,7 @@ static int max77693_pmic_probe(struct platform_device *pdev)
170} 185}
171 186
172static const struct platform_device_id max77693_pmic_id[] = { 187static const struct platform_device_id max77693_pmic_id[] = {
173 {"max77693-pmic", 0}, 188 { "max77693-pmic", TYPE_MAX77693 },
174 {}, 189 {},
175}; 190};
176 191