diff options
| -rw-r--r-- | drivers/regulator/max77693.c | 93 |
1 files changed, 9 insertions, 84 deletions
diff --git a/drivers/regulator/max77693.c b/drivers/regulator/max77693.c index 07b313e51b21..9665a488e2f1 100644 --- a/drivers/regulator/max77693.c +++ b/drivers/regulator/max77693.c | |||
| @@ -128,6 +128,8 @@ static struct regulator_ops max77693_charger_ops = { | |||
| 128 | #define regulator_desc_esafeout(_num) { \ | 128 | #define regulator_desc_esafeout(_num) { \ |
| 129 | .name = "ESAFEOUT"#_num, \ | 129 | .name = "ESAFEOUT"#_num, \ |
| 130 | .id = MAX77693_ESAFEOUT##_num, \ | 130 | .id = MAX77693_ESAFEOUT##_num, \ |
| 131 | .of_match = of_match_ptr("ESAFEOUT"#_num), \ | ||
| 132 | .regulators_node = of_match_ptr("regulators"), \ | ||
| 131 | .n_voltages = 4, \ | 133 | .n_voltages = 4, \ |
| 132 | .ops = &max77693_safeout_ops, \ | 134 | .ops = &max77693_safeout_ops, \ |
| 133 | .type = REGULATOR_VOLTAGE, \ | 135 | .type = REGULATOR_VOLTAGE, \ |
| @@ -145,6 +147,8 @@ static const struct regulator_desc regulators[] = { | |||
| 145 | { | 147 | { |
| 146 | .name = "CHARGER", | 148 | .name = "CHARGER", |
| 147 | .id = MAX77693_CHARGER, | 149 | .id = MAX77693_CHARGER, |
| 150 | .of_match = of_match_ptr("CHARGER"), | ||
| 151 | .regulators_node = of_match_ptr("regulators"), | ||
| 148 | .ops = &max77693_charger_ops, | 152 | .ops = &max77693_charger_ops, |
| 149 | .type = REGULATOR_CURRENT, | 153 | .type = REGULATOR_CURRENT, |
| 150 | .owner = THIS_MODULE, | 154 | .owner = THIS_MODULE, |
| @@ -154,102 +158,23 @@ static const struct regulator_desc regulators[] = { | |||
| 154 | }, | 158 | }, |
| 155 | }; | 159 | }; |
| 156 | 160 | ||
| 157 | #ifdef CONFIG_OF | ||
| 158 | static int max77693_pmic_dt_parse_rdata(struct device *dev, | ||
| 159 | struct max77693_regulator_data **rdata) | ||
| 160 | { | ||
| 161 | struct device_node *np; | ||
| 162 | struct of_regulator_match *rmatch; | ||
| 163 | struct max77693_regulator_data *tmp; | ||
| 164 | int i, matched = 0; | ||
| 165 | |||
| 166 | np = of_get_child_by_name(dev->parent->of_node, "regulators"); | ||
| 167 | if (!np) | ||
| 168 | return -EINVAL; | ||
| 169 | |||
| 170 | rmatch = devm_kzalloc(dev, | ||
| 171 | sizeof(*rmatch) * ARRAY_SIZE(regulators), GFP_KERNEL); | ||
| 172 | if (!rmatch) { | ||
| 173 | of_node_put(np); | ||
| 174 | return -ENOMEM; | ||
| 175 | } | ||
| 176 | |||
| 177 | for (i = 0; i < ARRAY_SIZE(regulators); i++) | ||
| 178 | rmatch[i].name = regulators[i].name; | ||
| 179 | |||
| 180 | matched = of_regulator_match(dev, np, rmatch, ARRAY_SIZE(regulators)); | ||
| 181 | of_node_put(np); | ||
| 182 | if (matched <= 0) | ||
| 183 | return matched; | ||
| 184 | *rdata = devm_kzalloc(dev, sizeof(**rdata) * matched, GFP_KERNEL); | ||
| 185 | if (!(*rdata)) | ||
| 186 | return -ENOMEM; | ||
| 187 | |||
| 188 | tmp = *rdata; | ||
| 189 | |||
| 190 | for (i = 0; i < matched; i++) { | ||
| 191 | tmp->initdata = rmatch[i].init_data; | ||
| 192 | tmp->of_node = rmatch[i].of_node; | ||
| 193 | tmp->id = regulators[i].id; | ||
| 194 | tmp++; | ||
| 195 | } | ||
| 196 | |||
| 197 | return matched; | ||
| 198 | } | ||
| 199 | #else | ||
| 200 | static int max77693_pmic_dt_parse_rdata(struct device *dev, | ||
| 201 | struct max77693_regulator_data **rdata) | ||
| 202 | { | ||
| 203 | return 0; | ||
| 204 | } | ||
| 205 | #endif /* CONFIG_OF */ | ||
| 206 | |||
| 207 | static int max77693_pmic_init_rdata(struct device *dev, | ||
| 208 | struct max77693_regulator_data **rdata) | ||
| 209 | { | ||
| 210 | struct max77693_platform_data *pdata; | ||
| 211 | int num_regulators = 0; | ||
| 212 | |||
| 213 | pdata = dev_get_platdata(dev->parent); | ||
| 214 | if (pdata) { | ||
| 215 | *rdata = pdata->regulators; | ||
| 216 | num_regulators = pdata->num_regulators; | ||
| 217 | } | ||
| 218 | |||
| 219 | if (!(*rdata) && dev->parent->of_node) | ||
| 220 | num_regulators = max77693_pmic_dt_parse_rdata(dev, rdata); | ||
| 221 | |||
| 222 | return num_regulators; | ||
| 223 | } | ||
| 224 | |||
| 225 | static int max77693_pmic_probe(struct platform_device *pdev) | 161 | static int max77693_pmic_probe(struct platform_device *pdev) |
| 226 | { | 162 | { |
| 227 | struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); | 163 | struct max77693_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
| 228 | struct max77693_regulator_data *rdata = NULL; | 164 | int i; |
| 229 | int num_rdata, i; | ||
| 230 | struct regulator_config config = { }; | 165 | struct regulator_config config = { }; |
| 231 | 166 | ||
| 232 | num_rdata = max77693_pmic_init_rdata(&pdev->dev, &rdata); | 167 | config.dev = iodev->dev; |
| 233 | if (!rdata || num_rdata <= 0) { | ||
| 234 | dev_err(&pdev->dev, "No init data supplied.\n"); | ||
| 235 | return -ENODEV; | ||
| 236 | } | ||
| 237 | |||
| 238 | config.dev = &pdev->dev; | ||
| 239 | config.regmap = iodev->regmap; | 168 | config.regmap = iodev->regmap; |
| 240 | 169 | ||
| 241 | for (i = 0; i < num_rdata; i++) { | 170 | for (i = 0; i < ARRAY_SIZE(regulators); i++) { |
| 242 | int id = rdata[i].id; | ||
| 243 | struct regulator_dev *rdev; | 171 | struct regulator_dev *rdev; |
| 244 | 172 | ||
| 245 | config.init_data = rdata[i].initdata; | ||
| 246 | config.of_node = rdata[i].of_node; | ||
| 247 | |||
| 248 | rdev = devm_regulator_register(&pdev->dev, | 173 | rdev = devm_regulator_register(&pdev->dev, |
| 249 | ®ulators[id], &config); | 174 | ®ulators[i], &config); |
| 250 | if (IS_ERR(rdev)) { | 175 | if (IS_ERR(rdev)) { |
| 251 | dev_err(&pdev->dev, | 176 | dev_err(&pdev->dev, |
| 252 | "Failed to initialize regulator-%d\n", id); | 177 | "Failed to initialize regulator-%d\n", i); |
| 253 | return PTR_ERR(rdev); | 178 | return PTR_ERR(rdev); |
| 254 | } | 179 | } |
| 255 | } | 180 | } |
