diff options
-rw-r--r-- | drivers/regulator/tps65217-regulator.c | 106 |
1 files changed, 29 insertions, 77 deletions
diff --git a/drivers/regulator/tps65217-regulator.c b/drivers/regulator/tps65217-regulator.c index 42315468ec68..adbe4fc5cf07 100644 --- a/drivers/regulator/tps65217-regulator.c +++ b/drivers/regulator/tps65217-regulator.c | |||
@@ -27,10 +27,13 @@ | |||
27 | #include <linux/regulator/machine.h> | 27 | #include <linux/regulator/machine.h> |
28 | #include <linux/mfd/tps65217.h> | 28 | #include <linux/mfd/tps65217.h> |
29 | 29 | ||
30 | #define TPS65217_REGULATOR(_name, _id, _ops, _n, _vr, _vm, _em, _t, _lr, _nlr) \ | 30 | #define TPS65217_REGULATOR(_name, _id, _of_match, _ops, _n, _vr, _vm, _em, \ |
31 | _t, _lr, _nlr) \ | ||
31 | { \ | 32 | { \ |
32 | .name = _name, \ | 33 | .name = _name, \ |
33 | .id = _id, \ | 34 | .id = _id, \ |
35 | .of_match = of_match_ptr(_of_match), \ | ||
36 | .regulators_node= of_match_ptr("regulators"), \ | ||
34 | .ops = &_ops, \ | 37 | .ops = &_ops, \ |
35 | .n_voltages = _n, \ | 38 | .n_voltages = _n, \ |
36 | .type = REGULATOR_VOLTAGE, \ | 39 | .type = REGULATOR_VOLTAGE, \ |
@@ -138,87 +141,40 @@ static struct regulator_ops tps65217_pmic_ldo1_ops = { | |||
138 | }; | 141 | }; |
139 | 142 | ||
140 | static const struct regulator_desc regulators[] = { | 143 | static const struct regulator_desc regulators[] = { |
141 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, tps65217_pmic_ops, 64, | 144 | TPS65217_REGULATOR("DCDC1", TPS65217_DCDC_1, "dcdc1", |
142 | TPS65217_REG_DEFDCDC1, TPS65217_DEFDCDCX_DCDC_MASK, | 145 | tps65217_pmic_ops, 64, TPS65217_REG_DEFDCDC1, |
143 | TPS65217_ENABLE_DC1_EN, NULL, tps65217_uv1_ranges, | 146 | TPS65217_DEFDCDCX_DCDC_MASK, TPS65217_ENABLE_DC1_EN, |
144 | 2), /* DCDC1 voltage range: 900000 ~ 1800000 */ | 147 | NULL, tps65217_uv1_ranges, 2), |
145 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, tps65217_pmic_ops, 64, | 148 | TPS65217_REGULATOR("DCDC2", TPS65217_DCDC_2, "dcdc2", |
146 | TPS65217_REG_DEFDCDC2, TPS65217_DEFDCDCX_DCDC_MASK, | 149 | tps65217_pmic_ops, 64, TPS65217_REG_DEFDCDC2, |
147 | TPS65217_ENABLE_DC2_EN, NULL, tps65217_uv1_ranges, | 150 | TPS65217_DEFDCDCX_DCDC_MASK, TPS65217_ENABLE_DC2_EN, |
151 | NULL, tps65217_uv1_ranges, | ||
148 | ARRAY_SIZE(tps65217_uv1_ranges)), | 152 | ARRAY_SIZE(tps65217_uv1_ranges)), |
149 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, tps65217_pmic_ops, 64, | 153 | TPS65217_REGULATOR("DCDC3", TPS65217_DCDC_3, "dcdc3", |
150 | TPS65217_REG_DEFDCDC3, TPS65217_DEFDCDCX_DCDC_MASK, | 154 | tps65217_pmic_ops, 64, TPS65217_REG_DEFDCDC3, |
151 | TPS65217_ENABLE_DC3_EN, NULL, tps65217_uv1_ranges, | 155 | TPS65217_DEFDCDCX_DCDC_MASK, TPS65217_ENABLE_DC3_EN, |
152 | 1), /* DCDC3 voltage range: 900000 ~ 1500000 */ | 156 | NULL, tps65217_uv1_ranges, 1), |
153 | TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, tps65217_pmic_ldo1_ops, 16, | 157 | TPS65217_REGULATOR("LDO1", TPS65217_LDO_1, "ldo1", |
154 | TPS65217_REG_DEFLDO1, TPS65217_DEFLDO1_LDO1_MASK, | 158 | tps65217_pmic_ldo1_ops, 16, TPS65217_REG_DEFLDO1, |
155 | TPS65217_ENABLE_LDO1_EN, LDO1_VSEL_table, NULL, 0), | 159 | TPS65217_DEFLDO1_LDO1_MASK, TPS65217_ENABLE_LDO1_EN, |
156 | TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, tps65217_pmic_ops, 64, | 160 | LDO1_VSEL_table, NULL, 0), |
157 | TPS65217_REG_DEFLDO2, TPS65217_DEFLDO2_LDO2_MASK, | 161 | TPS65217_REGULATOR("LDO2", TPS65217_LDO_2, "ldo2", tps65217_pmic_ops, |
158 | TPS65217_ENABLE_LDO2_EN, NULL, tps65217_uv1_ranges, | 162 | 64, TPS65217_REG_DEFLDO2, |
163 | TPS65217_DEFLDO2_LDO2_MASK, TPS65217_ENABLE_LDO2_EN, | ||
164 | NULL, tps65217_uv1_ranges, | ||
159 | ARRAY_SIZE(tps65217_uv1_ranges)), | 165 | ARRAY_SIZE(tps65217_uv1_ranges)), |
160 | TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, tps65217_pmic_ops, 32, | 166 | TPS65217_REGULATOR("LDO3", TPS65217_LDO_3, "ldo3", tps65217_pmic_ops, |
161 | TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK, | 167 | 32, TPS65217_REG_DEFLS1, TPS65217_DEFLDO3_LDO3_MASK, |
162 | TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, | 168 | TPS65217_ENABLE_LS1_EN | TPS65217_DEFLDO3_LDO3_EN, |
163 | NULL, tps65217_uv2_ranges, | 169 | NULL, tps65217_uv2_ranges, |
164 | ARRAY_SIZE(tps65217_uv2_ranges)), | 170 | ARRAY_SIZE(tps65217_uv2_ranges)), |
165 | TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, tps65217_pmic_ops, 32, | 171 | TPS65217_REGULATOR("LDO4", TPS65217_LDO_4, "ldo4", tps65217_pmic_ops, |
166 | TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK, | 172 | 32, TPS65217_REG_DEFLS2, TPS65217_DEFLDO4_LDO4_MASK, |
167 | TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, | 173 | TPS65217_ENABLE_LS2_EN | TPS65217_DEFLDO4_LDO4_EN, |
168 | NULL, tps65217_uv2_ranges, | 174 | NULL, tps65217_uv2_ranges, |
169 | ARRAY_SIZE(tps65217_uv2_ranges)), | 175 | ARRAY_SIZE(tps65217_uv2_ranges)), |
170 | }; | 176 | }; |
171 | 177 | ||
172 | #ifdef CONFIG_OF | ||
173 | static struct of_regulator_match reg_matches[] = { | ||
174 | { .name = "dcdc1" }, | ||
175 | { .name = "dcdc2" }, | ||
176 | { .name = "dcdc3" }, | ||
177 | { .name = "ldo1" }, | ||
178 | { .name = "ldo2" }, | ||
179 | { .name = "ldo3" }, | ||
180 | { .name = "ldo4" }, | ||
181 | }; | ||
182 | |||
183 | static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev) | ||
184 | { | ||
185 | struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent); | ||
186 | struct device_node *node = tps->dev->of_node; | ||
187 | struct tps65217_board *pdata; | ||
188 | struct device_node *regs; | ||
189 | int i, count; | ||
190 | |||
191 | regs = of_get_child_by_name(node, "regulators"); | ||
192 | if (!regs) | ||
193 | return NULL; | ||
194 | |||
195 | count = of_regulator_match(&pdev->dev, regs, reg_matches, | ||
196 | TPS65217_NUM_REGULATOR); | ||
197 | of_node_put(regs); | ||
198 | if ((count < 0) || (count > TPS65217_NUM_REGULATOR)) | ||
199 | return NULL; | ||
200 | |||
201 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); | ||
202 | if (!pdata) | ||
203 | return NULL; | ||
204 | |||
205 | for (i = 0; i < count; i++) { | ||
206 | if (!reg_matches[i].of_node) | ||
207 | continue; | ||
208 | |||
209 | pdata->tps65217_init_data[i] = reg_matches[i].init_data; | ||
210 | pdata->of_node[i] = reg_matches[i].of_node; | ||
211 | } | ||
212 | |||
213 | return pdata; | ||
214 | } | ||
215 | #else | ||
216 | static struct tps65217_board *tps65217_parse_dt(struct platform_device *pdev) | ||
217 | { | ||
218 | return NULL; | ||
219 | } | ||
220 | #endif | ||
221 | |||
222 | static int tps65217_regulator_probe(struct platform_device *pdev) | 178 | static int tps65217_regulator_probe(struct platform_device *pdev) |
223 | { | 179 | { |
224 | struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent); | 180 | struct tps65217 *tps = dev_get_drvdata(pdev->dev.parent); |
@@ -227,9 +183,6 @@ static int tps65217_regulator_probe(struct platform_device *pdev) | |||
227 | struct regulator_config config = { }; | 183 | struct regulator_config config = { }; |
228 | int i; | 184 | int i; |
229 | 185 | ||
230 | if (tps->dev->of_node) | ||
231 | pdata = tps65217_parse_dt(pdev); | ||
232 | |||
233 | if (tps65217_chip_id(tps) != TPS65217) { | 186 | if (tps65217_chip_id(tps) != TPS65217) { |
234 | dev_err(&pdev->dev, "Invalid tps chip version\n"); | 187 | dev_err(&pdev->dev, "Invalid tps chip version\n"); |
235 | return -ENODEV; | 188 | return -ENODEV; |
@@ -244,8 +197,6 @@ static int tps65217_regulator_probe(struct platform_device *pdev) | |||
244 | config.init_data = pdata->tps65217_init_data[i]; | 197 | config.init_data = pdata->tps65217_init_data[i]; |
245 | config.driver_data = tps; | 198 | config.driver_data = tps; |
246 | config.regmap = tps->regmap; | 199 | config.regmap = tps->regmap; |
247 | if (tps->dev->of_node) | ||
248 | config.of_node = pdata->of_node[i]; | ||
249 | 200 | ||
250 | rdev = devm_regulator_register(&pdev->dev, ®ulators[i], | 201 | rdev = devm_regulator_register(&pdev->dev, ®ulators[i], |
251 | &config); | 202 | &config); |
@@ -255,6 +206,7 @@ static int tps65217_regulator_probe(struct platform_device *pdev) | |||
255 | return PTR_ERR(rdev); | 206 | return PTR_ERR(rdev); |
256 | } | 207 | } |
257 | } | 208 | } |
209 | |||
258 | return 0; | 210 | return 0; |
259 | } | 211 | } |
260 | 212 | ||