| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Regulators driver for Maxim max8925 |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2009 Marvell International Ltd. |
|---|
| 5 | 6 | * Haojian Zhuang <haojian.zhuang@marvell.com> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 9 | | - * published by the Free Software Foundation. |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | #include <linux/kernel.h> |
|---|
| 12 | 9 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 159 | 156 | { \ |
|---|
| 160 | 157 | .desc = { \ |
|---|
| 161 | 158 | .name = "SDV" #_id, \ |
|---|
| 159 | + .of_match = of_match_ptr("SDV" #_id), \ |
|---|
| 160 | + .regulators_node = of_match_ptr("regulators"), \ |
|---|
| 162 | 161 | .ops = &max8925_regulator_sdv_ops, \ |
|---|
| 163 | 162 | .type = REGULATOR_VOLTAGE, \ |
|---|
| 164 | 163 | .id = MAX8925_ID_SD##_id, \ |
|---|
| .. | .. |
|---|
| 175 | 174 | { \ |
|---|
| 176 | 175 | .desc = { \ |
|---|
| 177 | 176 | .name = "LDO" #_id, \ |
|---|
| 177 | + .of_match = of_match_ptr("LDO" #_id), \ |
|---|
| 178 | + .regulators_node = of_match_ptr("regulators"), \ |
|---|
| 178 | 179 | .ops = &max8925_regulator_ldo_ops, \ |
|---|
| 179 | 180 | .type = REGULATOR_VOLTAGE, \ |
|---|
| 180 | 181 | .id = MAX8925_ID_LDO##_id, \ |
|---|
| .. | .. |
|---|
| 186 | 187 | .vol_reg = MAX8925_LDOVOUT##_id, \ |
|---|
| 187 | 188 | .enable_reg = MAX8925_LDOCTL##_id, \ |
|---|
| 188 | 189 | } |
|---|
| 189 | | - |
|---|
| 190 | | -#ifdef CONFIG_OF |
|---|
| 191 | | -static struct of_regulator_match max8925_regulator_matches[] = { |
|---|
| 192 | | - { .name = "SDV1",}, |
|---|
| 193 | | - { .name = "SDV2",}, |
|---|
| 194 | | - { .name = "SDV3",}, |
|---|
| 195 | | - { .name = "LDO1",}, |
|---|
| 196 | | - { .name = "LDO2",}, |
|---|
| 197 | | - { .name = "LDO3",}, |
|---|
| 198 | | - { .name = "LDO4",}, |
|---|
| 199 | | - { .name = "LDO5",}, |
|---|
| 200 | | - { .name = "LDO6",}, |
|---|
| 201 | | - { .name = "LDO7",}, |
|---|
| 202 | | - { .name = "LDO8",}, |
|---|
| 203 | | - { .name = "LDO9",}, |
|---|
| 204 | | - { .name = "LDO10",}, |
|---|
| 205 | | - { .name = "LDO11",}, |
|---|
| 206 | | - { .name = "LDO12",}, |
|---|
| 207 | | - { .name = "LDO13",}, |
|---|
| 208 | | - { .name = "LDO14",}, |
|---|
| 209 | | - { .name = "LDO15",}, |
|---|
| 210 | | - { .name = "LDO16",}, |
|---|
| 211 | | - { .name = "LDO17",}, |
|---|
| 212 | | - { .name = "LDO18",}, |
|---|
| 213 | | - { .name = "LDO19",}, |
|---|
| 214 | | - { .name = "LDO20",}, |
|---|
| 215 | | -}; |
|---|
| 216 | | -#endif |
|---|
| 217 | 190 | |
|---|
| 218 | 191 | static struct max8925_regulator_info max8925_regulator_info[] = { |
|---|
| 219 | 192 | MAX8925_SDV(1, 637.5, 1425, 12.5), |
|---|
| .. | .. |
|---|
| 242 | 215 | MAX8925_LDO(20, 750, 3900, 50), |
|---|
| 243 | 216 | }; |
|---|
| 244 | 217 | |
|---|
| 245 | | -#ifdef CONFIG_OF |
|---|
| 246 | | -static int max8925_regulator_dt_init(struct platform_device *pdev, |
|---|
| 247 | | - struct regulator_config *config, |
|---|
| 248 | | - int ridx) |
|---|
| 249 | | -{ |
|---|
| 250 | | - struct device_node *nproot, *np; |
|---|
| 251 | | - int rcount; |
|---|
| 252 | | - |
|---|
| 253 | | - nproot = pdev->dev.parent->of_node; |
|---|
| 254 | | - if (!nproot) |
|---|
| 255 | | - return -ENODEV; |
|---|
| 256 | | - np = of_get_child_by_name(nproot, "regulators"); |
|---|
| 257 | | - if (!np) { |
|---|
| 258 | | - dev_err(&pdev->dev, "failed to find regulators node\n"); |
|---|
| 259 | | - return -ENODEV; |
|---|
| 260 | | - } |
|---|
| 261 | | - |
|---|
| 262 | | - rcount = of_regulator_match(&pdev->dev, np, |
|---|
| 263 | | - &max8925_regulator_matches[ridx], 1); |
|---|
| 264 | | - of_node_put(np); |
|---|
| 265 | | - if (rcount < 0) |
|---|
| 266 | | - return rcount; |
|---|
| 267 | | - config->init_data = max8925_regulator_matches[ridx].init_data; |
|---|
| 268 | | - config->of_node = max8925_regulator_matches[ridx].of_node; |
|---|
| 269 | | - |
|---|
| 270 | | - return 0; |
|---|
| 271 | | -} |
|---|
| 272 | | -#else |
|---|
| 273 | | -#define max8925_regulator_dt_init(x, y, z) (-1) |
|---|
| 274 | | -#endif |
|---|
| 275 | | - |
|---|
| 276 | 218 | static int max8925_regulator_probe(struct platform_device *pdev) |
|---|
| 277 | 219 | { |
|---|
| 278 | 220 | struct max8925_chip *chip = dev_get_drvdata(pdev->dev.parent); |
|---|
| .. | .. |
|---|
| 281 | 223 | struct max8925_regulator_info *ri; |
|---|
| 282 | 224 | struct resource *res; |
|---|
| 283 | 225 | struct regulator_dev *rdev; |
|---|
| 284 | | - int i, regulator_idx; |
|---|
| 226 | + int i; |
|---|
| 285 | 227 | |
|---|
| 286 | 228 | res = platform_get_resource(pdev, IORESOURCE_REG, 0); |
|---|
| 287 | 229 | if (!res) { |
|---|
| .. | .. |
|---|
| 290 | 232 | } |
|---|
| 291 | 233 | for (i = 0; i < ARRAY_SIZE(max8925_regulator_info); i++) { |
|---|
| 292 | 234 | ri = &max8925_regulator_info[i]; |
|---|
| 293 | | - if (ri->vol_reg == res->start) { |
|---|
| 294 | | - regulator_idx = i; |
|---|
| 235 | + if (ri->vol_reg == res->start) |
|---|
| 295 | 236 | break; |
|---|
| 296 | | - } |
|---|
| 297 | 237 | } |
|---|
| 298 | 238 | |
|---|
| 299 | 239 | if (i == ARRAY_SIZE(max8925_regulator_info)) { |
|---|
| .. | .. |
|---|
| 303 | 243 | } |
|---|
| 304 | 244 | ri->i2c = chip->i2c; |
|---|
| 305 | 245 | |
|---|
| 306 | | - config.dev = &pdev->dev; |
|---|
| 246 | + config.dev = chip->dev; |
|---|
| 307 | 247 | config.driver_data = ri; |
|---|
| 308 | 248 | |
|---|
| 309 | | - if (max8925_regulator_dt_init(pdev, &config, regulator_idx)) |
|---|
| 310 | | - if (pdata) |
|---|
| 311 | | - config.init_data = pdata; |
|---|
| 249 | + if (pdata) |
|---|
| 250 | + config.init_data = pdata; |
|---|
| 312 | 251 | |
|---|
| 313 | 252 | rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config); |
|---|
| 314 | 253 | if (IS_ERR(rdev)) { |
|---|