| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0 |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * AS3711 PMIC regulator driver, using DCDC Step Down and LDO supplies |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2012 Renesas Electronics Corporation |
|---|
| 5 | 6 | * Author: Guennadi Liakhovetski, <g.liakhovetski@gmx.de> |
|---|
| 6 | | - * |
|---|
| 7 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 8 | | - * it under the terms of the version 2 of the GNU General Public License as |
|---|
| 9 | | - * published by the Free Software Foundation |
|---|
| 10 | 7 | */ |
|---|
| 11 | 8 | |
|---|
| 12 | 9 | #include <linux/err.h> |
|---|
| .. | .. |
|---|
| 19 | 16 | #include <linux/regulator/driver.h> |
|---|
| 20 | 17 | #include <linux/regulator/of_regulator.h> |
|---|
| 21 | 18 | #include <linux/slab.h> |
|---|
| 22 | | - |
|---|
| 23 | | -struct as3711_regulator_info { |
|---|
| 24 | | - struct regulator_desc desc; |
|---|
| 25 | | -}; |
|---|
| 26 | | - |
|---|
| 27 | | -struct as3711_regulator { |
|---|
| 28 | | - struct as3711_regulator_info *reg_info; |
|---|
| 29 | | -}; |
|---|
| 30 | 19 | |
|---|
| 31 | 20 | /* |
|---|
| 32 | 21 | * The regulator API supports 4 modes of operataion: FAST, NORMAL, IDLE and |
|---|
| .. | .. |
|---|
| 114 | 103 | .map_voltage = regulator_map_voltage_linear_range, |
|---|
| 115 | 104 | }; |
|---|
| 116 | 105 | |
|---|
| 117 | | -static const struct regulator_linear_range as3711_sd_ranges[] = { |
|---|
| 106 | +static const struct linear_range as3711_sd_ranges[] = { |
|---|
| 118 | 107 | REGULATOR_LINEAR_RANGE(612500, 0x1, 0x40, 12500), |
|---|
| 119 | 108 | REGULATOR_LINEAR_RANGE(1425000, 0x41, 0x70, 25000), |
|---|
| 120 | 109 | REGULATOR_LINEAR_RANGE(2650000, 0x71, 0x7f, 50000), |
|---|
| 121 | 110 | }; |
|---|
| 122 | 111 | |
|---|
| 123 | | -static const struct regulator_linear_range as3711_aldo_ranges[] = { |
|---|
| 112 | +static const struct linear_range as3711_aldo_ranges[] = { |
|---|
| 124 | 113 | REGULATOR_LINEAR_RANGE(1200000, 0, 0xf, 50000), |
|---|
| 125 | 114 | REGULATOR_LINEAR_RANGE(1800000, 0x10, 0x1f, 100000), |
|---|
| 126 | 115 | }; |
|---|
| 127 | 116 | |
|---|
| 128 | | -static const struct regulator_linear_range as3711_dldo_ranges[] = { |
|---|
| 117 | +static const struct linear_range as3711_dldo_ranges[] = { |
|---|
| 129 | 118 | REGULATOR_LINEAR_RANGE(900000, 0, 0x10, 50000), |
|---|
| 130 | 119 | REGULATOR_LINEAR_RANGE(1750000, 0x20, 0x3f, 50000), |
|---|
| 131 | 120 | }; |
|---|
| 132 | 121 | |
|---|
| 133 | 122 | #define AS3711_REG(_id, _en_reg, _en_bit, _vmask, _sfx) \ |
|---|
| 134 | 123 | [AS3711_REGULATOR_ ## _id] = { \ |
|---|
| 135 | | - .desc = { \ |
|---|
| 136 | 124 | .name = "as3711-regulator-" # _id, \ |
|---|
| 137 | 125 | .id = AS3711_REGULATOR_ ## _id, \ |
|---|
| 138 | 126 | .n_voltages = (_vmask + 1), \ |
|---|
| .. | .. |
|---|
| 145 | 133 | .enable_mask = BIT(_en_bit), \ |
|---|
| 146 | 134 | .linear_ranges = as3711_ ## _sfx ## _ranges, \ |
|---|
| 147 | 135 | .n_linear_ranges = ARRAY_SIZE(as3711_ ## _sfx ## _ranges), \ |
|---|
| 148 | | - }, \ |
|---|
| 149 | 136 | } |
|---|
| 150 | 137 | |
|---|
| 151 | | -static struct as3711_regulator_info as3711_reg_info[] = { |
|---|
| 138 | +static const struct regulator_desc as3711_reg_desc[] = { |
|---|
| 152 | 139 | AS3711_REG(SD_1, SD_CONTROL, 0, 0x7f, sd), |
|---|
| 153 | 140 | AS3711_REG(SD_2, SD_CONTROL, 1, 0x7f, sd), |
|---|
| 154 | 141 | AS3711_REG(SD_3, SD_CONTROL, 2, 0x7f, sd), |
|---|
| .. | .. |
|---|
| 164 | 151 | /* StepUp output voltage depends on supplying regulator */ |
|---|
| 165 | 152 | }; |
|---|
| 166 | 153 | |
|---|
| 167 | | -#define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_info) |
|---|
| 154 | +#define AS3711_REGULATOR_NUM ARRAY_SIZE(as3711_reg_desc) |
|---|
| 168 | 155 | |
|---|
| 169 | 156 | static struct of_regulator_match |
|---|
| 170 | 157 | as3711_regulator_matches[AS3711_REGULATOR_NUM] = { |
|---|
| .. | .. |
|---|
| 218 | 205 | struct as3711_regulator_pdata *pdata = dev_get_platdata(&pdev->dev); |
|---|
| 219 | 206 | struct as3711 *as3711 = dev_get_drvdata(pdev->dev.parent); |
|---|
| 220 | 207 | struct regulator_config config = {.dev = &pdev->dev,}; |
|---|
| 221 | | - struct as3711_regulator *reg = NULL; |
|---|
| 222 | | - struct as3711_regulator *regs; |
|---|
| 223 | 208 | struct device_node *of_node[AS3711_REGULATOR_NUM] = {}; |
|---|
| 224 | 209 | struct regulator_dev *rdev; |
|---|
| 225 | | - struct as3711_regulator_info *ri; |
|---|
| 226 | 210 | int ret; |
|---|
| 227 | 211 | int id; |
|---|
| 228 | 212 | |
|---|
| .. | .. |
|---|
| 239 | 223 | } |
|---|
| 240 | 224 | } |
|---|
| 241 | 225 | |
|---|
| 242 | | - regs = devm_kcalloc(&pdev->dev, |
|---|
| 243 | | - AS3711_REGULATOR_NUM, |
|---|
| 244 | | - sizeof(struct as3711_regulator), |
|---|
| 245 | | - GFP_KERNEL); |
|---|
| 246 | | - if (!regs) |
|---|
| 247 | | - return -ENOMEM; |
|---|
| 248 | | - |
|---|
| 249 | | - for (id = 0, ri = as3711_reg_info; id < AS3711_REGULATOR_NUM; ++id, ri++) { |
|---|
| 250 | | - reg = ®s[id]; |
|---|
| 251 | | - reg->reg_info = ri; |
|---|
| 252 | | - |
|---|
| 226 | + for (id = 0; id < AS3711_REGULATOR_NUM; id++) { |
|---|
| 253 | 227 | config.init_data = pdata->init_data[id]; |
|---|
| 254 | | - config.driver_data = reg; |
|---|
| 255 | 228 | config.regmap = as3711->regmap; |
|---|
| 256 | 229 | config.of_node = of_node[id]; |
|---|
| 257 | 230 | |
|---|
| 258 | | - rdev = devm_regulator_register(&pdev->dev, &ri->desc, &config); |
|---|
| 231 | + rdev = devm_regulator_register(&pdev->dev, &as3711_reg_desc[id], |
|---|
| 232 | + &config); |
|---|
| 259 | 233 | if (IS_ERR(rdev)) { |
|---|
| 260 | 234 | dev_err(&pdev->dev, "Failed to register regulator %s\n", |
|---|
| 261 | | - ri->desc.name); |
|---|
| 235 | + as3711_reg_desc[id].name); |
|---|
| 262 | 236 | return PTR_ERR(rdev); |
|---|
| 263 | 237 | } |
|---|
| 264 | 238 | } |
|---|
| 265 | | - platform_set_drvdata(pdev, regs); |
|---|
| 239 | + |
|---|
| 266 | 240 | return 0; |
|---|
| 267 | 241 | } |
|---|
| 268 | 242 | |
|---|