diff options
| author | Beomho Seo <beomho.seo@samsung.com> | 2014-12-19 04:04:46 -0500 |
|---|---|---|
| committer | Mark Brown <broonie@kernel.org> | 2014-12-22 07:11:43 -0500 |
| commit | e951ceef65f76d6c611a4afa65dfc9420a3123f4 (patch) | |
| tree | 100494ff52730830c839fe4b6c4283f825c1d8f6 /drivers/regulator | |
| parent | 97bf6af1f928216fd6c5a66e8a57bfa95a659672 (diff) | |
regulator: max14577: Use regulator_nodes/of_match in the descriptor
This patch is add regulator_nodes/ofmatch in the regulator descriptor
for using information from DT instead of specific codes.
That will be used regulation_of_get_init_data function for get regulator
property on device tree. Using that make driver simpler.
Signed-off-by: Beomho Seo <beomho.seo@samsung.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'drivers/regulator')
| -rw-r--r-- | drivers/regulator/max14577.c | 62 |
1 files changed, 14 insertions, 48 deletions
diff --git a/drivers/regulator/max14577.c b/drivers/regulator/max14577.c index bf9a44c5fdd2..b3678d289619 100644 --- a/drivers/regulator/max14577.c +++ b/drivers/regulator/max14577.c | |||
| @@ -103,6 +103,8 @@ static struct regulator_ops max14577_charger_ops = { | |||
| 103 | static const struct regulator_desc max14577_supported_regulators[] = { | 103 | static const struct regulator_desc max14577_supported_regulators[] = { |
| 104 | [MAX14577_SAFEOUT] = { | 104 | [MAX14577_SAFEOUT] = { |
| 105 | .name = "SAFEOUT", | 105 | .name = "SAFEOUT", |
| 106 | .of_match = of_match_ptr("SAFEOUT"), | ||
| 107 | .regulators_node = of_match_ptr("regulators"), | ||
| 106 | .id = MAX14577_SAFEOUT, | 108 | .id = MAX14577_SAFEOUT, |
| 107 | .ops = &max14577_safeout_ops, | 109 | .ops = &max14577_safeout_ops, |
| 108 | .type = REGULATOR_VOLTAGE, | 110 | .type = REGULATOR_VOLTAGE, |
| @@ -114,6 +116,8 @@ static const struct regulator_desc max14577_supported_regulators[] = { | |||
| 114 | }, | 116 | }, |
| 115 | [MAX14577_CHARGER] = { | 117 | [MAX14577_CHARGER] = { |
| 116 | .name = "CHARGER", | 118 | .name = "CHARGER", |
| 119 | .of_match = of_match_ptr("CHARGER"), | ||
| 120 | .regulators_node = of_match_ptr("regulators"), | ||
| 117 | .id = MAX14577_CHARGER, | 121 | .id = MAX14577_CHARGER, |
| 118 | .ops = &max14577_charger_ops, | 122 | .ops = &max14577_charger_ops, |
| 119 | .type = REGULATOR_CURRENT, | 123 | .type = REGULATOR_CURRENT, |
| @@ -137,6 +141,8 @@ static struct regulator_ops max77836_ldo_ops = { | |||
| 137 | static const struct regulator_desc max77836_supported_regulators[] = { | 141 | static const struct regulator_desc max77836_supported_regulators[] = { |
| 138 | [MAX14577_SAFEOUT] = { | 142 | [MAX14577_SAFEOUT] = { |
| 139 | .name = "SAFEOUT", | 143 | .name = "SAFEOUT", |
| 144 | .of_match = of_match_ptr("SAFEOUT"), | ||
| 145 | .regulators_node = of_match_ptr("regulators"), | ||
| 140 | .id = MAX14577_SAFEOUT, | 146 | .id = MAX14577_SAFEOUT, |
| 141 | .ops = &max14577_safeout_ops, | 147 | .ops = &max14577_safeout_ops, |
| 142 | .type = REGULATOR_VOLTAGE, | 148 | .type = REGULATOR_VOLTAGE, |
| @@ -148,6 +154,8 @@ static const struct regulator_desc max77836_supported_regulators[] = { | |||
| 148 | }, | 154 | }, |
| 149 | [MAX14577_CHARGER] = { | 155 | [MAX14577_CHARGER] = { |
| 150 | .name = "CHARGER", | 156 | .name = "CHARGER", |
| 157 | .of_match = of_match_ptr("CHARGER"), | ||
| 158 | .regulators_node = of_match_ptr("regulators"), | ||
| 151 | .id = MAX14577_CHARGER, | 159 | .id = MAX14577_CHARGER, |
| 152 | .ops = &max14577_charger_ops, | 160 | .ops = &max14577_charger_ops, |
| 153 | .type = REGULATOR_CURRENT, | 161 | .type = REGULATOR_CURRENT, |
| @@ -157,6 +165,8 @@ static const struct regulator_desc max77836_supported_regulators[] = { | |||
| 157 | }, | 165 | }, |
| 158 | [MAX77836_LDO1] = { | 166 | [MAX77836_LDO1] = { |
| 159 | .name = "LDO1", | 167 | .name = "LDO1", |
| 168 | .of_match = of_match_ptr("LDO1"), | ||
| 169 | .regulators_node = of_match_ptr("regulators"), | ||
| 160 | .id = MAX77836_LDO1, | 170 | .id = MAX77836_LDO1, |
| 161 | .ops = &max77836_ldo_ops, | 171 | .ops = &max77836_ldo_ops, |
| 162 | .type = REGULATOR_VOLTAGE, | 172 | .type = REGULATOR_VOLTAGE, |
| @@ -171,6 +181,8 @@ static const struct regulator_desc max77836_supported_regulators[] = { | |||
| 171 | }, | 181 | }, |
| 172 | [MAX77836_LDO2] = { | 182 | [MAX77836_LDO2] = { |
| 173 | .name = "LDO2", | 183 | .name = "LDO2", |
| 184 | .of_match = of_match_ptr("LDO2"), | ||
| 185 | .regulators_node = of_match_ptr("regulators"), | ||
| 174 | .id = MAX77836_LDO2, | 186 | .id = MAX77836_LDO2, |
| 175 | .ops = &max77836_ldo_ops, | 187 | .ops = &max77836_ldo_ops, |
| 176 | .type = REGULATOR_VOLTAGE, | 188 | .type = REGULATOR_VOLTAGE, |
| @@ -198,43 +210,6 @@ static struct of_regulator_match max77836_regulator_matches[] = { | |||
| 198 | { .name = "LDO2", }, | 210 | { .name = "LDO2", }, |
| 199 | }; | 211 | }; |
| 200 | 212 | ||
| 201 | static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev, | ||
| 202 | enum maxim_device_type dev_type) | ||
| 203 | { | ||
| 204 | int ret; | ||
| 205 | struct device_node *np; | ||
| 206 | struct of_regulator_match *regulator_matches; | ||
| 207 | unsigned int regulator_matches_size; | ||
| 208 | |||
| 209 | np = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); | ||
| 210 | if (!np) { | ||
| 211 | dev_err(&pdev->dev, "Failed to get child OF node for regulators\n"); | ||
| 212 | return -EINVAL; | ||
| 213 | } | ||
| 214 | |||
| 215 | switch (dev_type) { | ||
| 216 | case MAXIM_DEVICE_TYPE_MAX77836: | ||
| 217 | regulator_matches = max77836_regulator_matches; | ||
| 218 | regulator_matches_size = ARRAY_SIZE(max77836_regulator_matches); | ||
| 219 | break; | ||
| 220 | case MAXIM_DEVICE_TYPE_MAX14577: | ||
| 221 | default: | ||
| 222 | regulator_matches = max14577_regulator_matches; | ||
| 223 | regulator_matches_size = ARRAY_SIZE(max14577_regulator_matches); | ||
| 224 | } | ||
| 225 | |||
| 226 | ret = of_regulator_match(&pdev->dev, np, regulator_matches, | ||
| 227 | regulator_matches_size); | ||
| 228 | if (ret < 0) | ||
| 229 | dev_err(&pdev->dev, "Error parsing regulator init data: %d\n", ret); | ||
| 230 | else | ||
| 231 | ret = 0; | ||
| 232 | |||
| 233 | of_node_put(np); | ||
| 234 | |||
| 235 | return ret; | ||
| 236 | } | ||
| 237 | |||
| 238 | static inline struct regulator_init_data *match_init_data(int index, | 213 | static inline struct regulator_init_data *match_init_data(int index, |
| 239 | enum maxim_device_type dev_type) | 214 | enum maxim_device_type dev_type) |
| 240 | { | 215 | { |
| @@ -261,11 +236,6 @@ static inline struct device_node *match_of_node(int index, | |||
| 261 | } | 236 | } |
| 262 | } | 237 | } |
| 263 | #else /* CONFIG_OF */ | 238 | #else /* CONFIG_OF */ |
| 264 | static int max14577_regulator_dt_parse_pdata(struct platform_device *pdev, | ||
| 265 | enum maxim_device_type dev_type) | ||
| 266 | { | ||
| 267 | return 0; | ||
| 268 | } | ||
| 269 | static inline struct regulator_init_data *match_init_data(int index, | 239 | static inline struct regulator_init_data *match_init_data(int index, |
| 270 | enum maxim_device_type dev_type) | 240 | enum maxim_device_type dev_type) |
| 271 | { | 241 | { |
| @@ -308,16 +278,12 @@ static int max14577_regulator_probe(struct platform_device *pdev) | |||
| 308 | { | 278 | { |
| 309 | struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); | 279 | struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); |
| 310 | struct max14577_platform_data *pdata = dev_get_platdata(max14577->dev); | 280 | struct max14577_platform_data *pdata = dev_get_platdata(max14577->dev); |
| 311 | int i, ret; | 281 | int i, ret = 0; |
| 312 | struct regulator_config config = {}; | 282 | struct regulator_config config = {}; |
| 313 | const struct regulator_desc *supported_regulators; | 283 | const struct regulator_desc *supported_regulators; |
| 314 | unsigned int supported_regulators_size; | 284 | unsigned int supported_regulators_size; |
| 315 | enum maxim_device_type dev_type = max14577->dev_type; | 285 | enum maxim_device_type dev_type = max14577->dev_type; |
| 316 | 286 | ||
| 317 | ret = max14577_regulator_dt_parse_pdata(pdev, dev_type); | ||
| 318 | if (ret) | ||
| 319 | return ret; | ||
| 320 | |||
| 321 | switch (dev_type) { | 287 | switch (dev_type) { |
| 322 | case MAXIM_DEVICE_TYPE_MAX77836: | 288 | case MAXIM_DEVICE_TYPE_MAX77836: |
| 323 | supported_regulators = max77836_supported_regulators; | 289 | supported_regulators = max77836_supported_regulators; |
| @@ -329,7 +295,7 @@ static int max14577_regulator_probe(struct platform_device *pdev) | |||
| 329 | supported_regulators_size = ARRAY_SIZE(max14577_supported_regulators); | 295 | supported_regulators_size = ARRAY_SIZE(max14577_supported_regulators); |
| 330 | } | 296 | } |
| 331 | 297 | ||
| 332 | config.dev = &pdev->dev; | 298 | config.dev = max14577->dev; |
| 333 | config.driver_data = max14577; | 299 | config.driver_data = max14577; |
| 334 | 300 | ||
| 335 | for (i = 0; i < supported_regulators_size; i++) { | 301 | for (i = 0; i < supported_regulators_size; i++) { |
