diff options
author | Axel Lin <axel.lin@ingics.com> | 2015-11-18 03:22:52 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-11-18 08:19:47 -0500 |
commit | fad2ba681c74f785d56a2401bb9db615843a465a (patch) | |
tree | d13fe2d5ad8434d8bcb777ad0534f0bf24c3f8f4 /drivers/regulator | |
parent | 8005c49d9aea74d382f474ce11afbbc7d7130bec (diff) |
regulator: tps6105x: Convert to use regmap helper functions
Since commit 7e5071199355 ("mfd: tps6105x: Use i2c regmap to access
registers"), we can use regmap helper functions instead of open coded.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Tested-by: Denis Grigoryev <grigoryev@fastwel.ru>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/tps6105x-regulator.c | 95 |
1 files changed, 12 insertions, 83 deletions
diff --git a/drivers/regulator/tps6105x-regulator.c b/drivers/regulator/tps6105x-regulator.c index ddc4f10e268a..584ef3dedca6 100644 --- a/drivers/regulator/tps6105x-regulator.c +++ b/drivers/regulator/tps6105x-regulator.c | |||
@@ -27,90 +27,12 @@ static const unsigned int tps6105x_voltages[] = { | |||
27 | 5000000, /* There is an additional 5V */ | 27 | 5000000, /* There is an additional 5V */ |
28 | }; | 28 | }; |
29 | 29 | ||
30 | static int tps6105x_regulator_enable(struct regulator_dev *rdev) | ||
31 | { | ||
32 | struct tps6105x *tps6105x = rdev_get_drvdata(rdev); | ||
33 | int ret; | ||
34 | |||
35 | /* Activate voltage mode */ | ||
36 | ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, | ||
37 | TPS6105X_REG0_MODE_MASK, | ||
38 | TPS6105X_REG0_MODE_VOLTAGE << TPS6105X_REG0_MODE_SHIFT); | ||
39 | if (ret) | ||
40 | return ret; | ||
41 | |||
42 | return 0; | ||
43 | } | ||
44 | |||
45 | static int tps6105x_regulator_disable(struct regulator_dev *rdev) | ||
46 | { | ||
47 | struct tps6105x *tps6105x = rdev_get_drvdata(rdev); | ||
48 | int ret; | ||
49 | |||
50 | /* Set into shutdown mode */ | ||
51 | ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, | ||
52 | TPS6105X_REG0_MODE_MASK, | ||
53 | TPS6105X_REG0_MODE_SHUTDOWN << TPS6105X_REG0_MODE_SHIFT); | ||
54 | if (ret) | ||
55 | return ret; | ||
56 | |||
57 | return 0; | ||
58 | } | ||
59 | |||
60 | static int tps6105x_regulator_is_enabled(struct regulator_dev *rdev) | ||
61 | { | ||
62 | struct tps6105x *tps6105x = rdev_get_drvdata(rdev); | ||
63 | unsigned int regval; | ||
64 | int ret; | ||
65 | |||
66 | ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val); | ||
67 | if (ret) | ||
68 | return ret; | ||
69 | regval &= TPS6105X_REG0_MODE_MASK; | ||
70 | regval >>= TPS6105X_REG0_MODE_SHIFT; | ||
71 | |||
72 | if (regval == TPS6105X_REG0_MODE_VOLTAGE) | ||
73 | return 1; | ||
74 | |||
75 | return 0; | ||
76 | } | ||
77 | |||
78 | static int tps6105x_regulator_get_voltage_sel(struct regulator_dev *rdev) | ||
79 | { | ||
80 | struct tps6105x *tps6105x = rdev_get_drvdata(rdev); | ||
81 | unsigned int regval; | ||
82 | int ret; | ||
83 | |||
84 | ret = regmap_read(tps6105x->regmap, TPS6105X_REG_0, ®val); | ||
85 | if (ret) | ||
86 | return ret; | ||
87 | |||
88 | regval &= TPS6105X_REG0_VOLTAGE_MASK; | ||
89 | regval >>= TPS6105X_REG0_VOLTAGE_SHIFT; | ||
90 | return (int) regval; | ||
91 | } | ||
92 | |||
93 | static int tps6105x_regulator_set_voltage_sel(struct regulator_dev *rdev, | ||
94 | unsigned selector) | ||
95 | { | ||
96 | struct tps6105x *tps6105x = rdev_get_drvdata(rdev); | ||
97 | int ret; | ||
98 | |||
99 | ret = regmap_update_bits(tps6105x->regmap, TPS6105X_REG_0, | ||
100 | TPS6105X_REG0_VOLTAGE_MASK, | ||
101 | selector << TPS6105X_REG0_VOLTAGE_SHIFT); | ||
102 | if (ret) | ||
103 | return ret; | ||
104 | |||
105 | return 0; | ||
106 | } | ||
107 | |||
108 | static struct regulator_ops tps6105x_regulator_ops = { | 30 | static struct regulator_ops tps6105x_regulator_ops = { |
109 | .enable = tps6105x_regulator_enable, | 31 | .enable = regulator_enable_regmap, |
110 | .disable = tps6105x_regulator_disable, | 32 | .disable = regulator_disable_regmap, |
111 | .is_enabled = tps6105x_regulator_is_enabled, | 33 | .is_enabled = regulator_is_enabled_regmap, |
112 | .get_voltage_sel = tps6105x_regulator_get_voltage_sel, | 34 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
113 | .set_voltage_sel = tps6105x_regulator_set_voltage_sel, | 35 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
114 | .list_voltage = regulator_list_voltage_table, | 36 | .list_voltage = regulator_list_voltage_table, |
115 | }; | 37 | }; |
116 | 38 | ||
@@ -122,6 +44,12 @@ static const struct regulator_desc tps6105x_regulator_desc = { | |||
122 | .owner = THIS_MODULE, | 44 | .owner = THIS_MODULE, |
123 | .n_voltages = ARRAY_SIZE(tps6105x_voltages), | 45 | .n_voltages = ARRAY_SIZE(tps6105x_voltages), |
124 | .volt_table = tps6105x_voltages, | 46 | .volt_table = tps6105x_voltages, |
47 | .vsel_reg = TPS6105X_REG_0, | ||
48 | .vsel_mask = TPS6105X_REG0_VOLTAGE_MASK, | ||
49 | .enable_reg = TPS6105X_REG_0, | ||
50 | .enable_mask = TPS6105X_REG0_MODE_MASK, | ||
51 | .enable_val = TPS6105X_REG0_MODE_VOLTAGE << | ||
52 | TPS6105X_REG0_MODE_SHIFT, | ||
125 | }; | 53 | }; |
126 | 54 | ||
127 | /* | 55 | /* |
@@ -144,6 +72,7 @@ static int tps6105x_regulator_probe(struct platform_device *pdev) | |||
144 | config.dev = &tps6105x->client->dev; | 72 | config.dev = &tps6105x->client->dev; |
145 | config.init_data = pdata->regulator_data; | 73 | config.init_data = pdata->regulator_data; |
146 | config.driver_data = tps6105x; | 74 | config.driver_data = tps6105x; |
75 | config.regmap = tps6105x->regmap; | ||
147 | 76 | ||
148 | /* Register regulator with framework */ | 77 | /* Register regulator with framework */ |
149 | tps6105x->regulator = devm_regulator_register(&pdev->dev, | 78 | tps6105x->regulator = devm_regulator_register(&pdev->dev, |