Blame view
drivers/regulator/da9063-regulator.c
23.2 KB
5de219ccc regulator: da9063... |
1 2 3 4 5 6 7 8 |
// SPDX-License-Identifier: GPL-2.0+ // // Regulator driver for DA9063 PMIC series // // Copyright 2012 Dialog Semiconductors Ltd. // Copyright 2013 Philipp Zabel, Pengutronix // // Author: Krystian Garbaciak <krystian.garbaciak@diasemi.com> |
ebf6dad0d regulator: da9063... |
9 |
|
69ca3e58d regulator: da9063... |
10 11 12 13 14 15 16 17 18 19 20 21 |
#include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/err.h> #include <linux/slab.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <linux/regulator/driver.h> #include <linux/regulator/machine.h> #include <linux/regulator/of_regulator.h> #include <linux/mfd/da9063/core.h> |
69ca3e58d regulator: da9063... |
22 23 24 25 26 27 28 |
#include <linux/mfd/da9063/registers.h> /* Definition for registering regmap bit fields using a mask */ #define BFIELD(_reg, _mask) \ REG_FIELD(_reg, __builtin_ffs((int)_mask) - 1, \ sizeof(unsigned int) * 8 - __builtin_clz((_mask)) - 1) |
824bd1be3 regulator: da9063... |
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
/* DA9063 and DA9063L regulator IDs */ enum { /* BUCKs */ DA9063_ID_BCORE1, DA9063_ID_BCORE2, DA9063_ID_BPRO, DA9063_ID_BMEM, DA9063_ID_BIO, DA9063_ID_BPERI, /* BCORE1 and BCORE2 in merged mode */ DA9063_ID_BCORES_MERGED, /* BMEM and BIO in merged mode */ DA9063_ID_BMEM_BIO_MERGED, /* When two BUCKs are merged, they cannot be reused separately */ /* LDOs on both DA9063 and DA9063L */ DA9063_ID_LDO3, DA9063_ID_LDO7, DA9063_ID_LDO8, DA9063_ID_LDO9, DA9063_ID_LDO11, /* DA9063-only LDOs */ DA9063_ID_LDO1, DA9063_ID_LDO2, DA9063_ID_LDO4, DA9063_ID_LDO5, DA9063_ID_LDO6, DA9063_ID_LDO10, }; /* Old regulator platform data */ struct da9063_regulator_data { int id; struct regulator_init_data *initdata; }; struct da9063_regulators_pdata { |
a33b25f57 regulator: da9063... |
68 |
unsigned int n_regulators; |
824bd1be3 regulator: da9063... |
69 70 |
struct da9063_regulator_data *regulator_data; }; |
69ca3e58d regulator: da9063... |
71 72 73 |
/* Regulator capabilities and registers description */ struct da9063_regulator_info { struct regulator_desc desc; |
69ca3e58d regulator: da9063... |
74 75 76 77 78 79 |
/* DA9063 main register fields */ struct reg_field mode; /* buck mode of operation */ struct reg_field suspend; struct reg_field sleep; struct reg_field suspend_sleep; unsigned int suspend_vsel_reg; |
69ca3e58d regulator: da9063... |
80 81 82 83 84 85 86 87 88 89 90 91 |
/* DA9063 event detection bit */ struct reg_field oc_event; }; /* Macros for LDO */ #define DA9063_LDO(chip, regl_name, min_mV, step_mV, max_mV) \ .desc.id = chip##_ID_##regl_name, \ .desc.name = __stringify(chip##_##regl_name), \ .desc.ops = &da9063_ldo_ops, \ .desc.min_uV = (min_mV) * 1000, \ .desc.uV_step = (step_mV) * 1000, \ |
ebf6dad0d regulator: da9063... |
92 93 |
.desc.n_voltages = (((max_mV) - (min_mV))/(step_mV) + 1 \ + (DA9063_V##regl_name##_BIAS)), \ |
69ca3e58d regulator: da9063... |
94 95 96 97 98 99 |
.desc.enable_reg = DA9063_REG_##regl_name##_CONT, \ .desc.enable_mask = DA9063_LDO_EN, \ .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \ .desc.vsel_mask = DA9063_V##regl_name##_MASK, \ .desc.linear_min_sel = DA9063_V##regl_name##_BIAS, \ .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_LDO_SL), \ |
99f75ce66 regulator: da9063... |
100 |
.suspend = BFIELD(DA9063_REG_##regl_name##_CONT, DA9063_LDO_CONF), \ |
69ca3e58d regulator: da9063... |
101 102 103 104 |
.suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_LDO_SL), \ .suspend_vsel_reg = DA9063_REG_V##regl_name##_B /* Macros for voltage DC/DC converters (BUCKs) */ |
5b1f537e4 regulator: da9063... |
105 106 |
#define DA9063_BUCK(chip, regl_name, min_mV, step_mV, max_mV, limits_array, \ creg, cmask) \ |
69ca3e58d regulator: da9063... |
107 108 109 110 111 112 |
.desc.id = chip##_ID_##regl_name, \ .desc.name = __stringify(chip##_##regl_name), \ .desc.ops = &da9063_buck_ops, \ .desc.min_uV = (min_mV) * 1000, \ .desc.uV_step = (step_mV) * 1000, \ .desc.n_voltages = ((max_mV) - (min_mV))/(step_mV) + 1, \ |
5b1f537e4 regulator: da9063... |
113 114 115 116 |
.desc.csel_reg = (creg), \ .desc.csel_mask = (cmask), \ .desc.curr_table = limits_array, \ .desc.n_current_limits = ARRAY_SIZE(limits_array) |
69ca3e58d regulator: da9063... |
117 118 119 120 121 122 123 124 |
#define DA9063_BUCK_COMMON_FIELDS(regl_name) \ .desc.enable_reg = DA9063_REG_##regl_name##_CONT, \ .desc.enable_mask = DA9063_BUCK_EN, \ .desc.vsel_reg = DA9063_REG_V##regl_name##_A, \ .desc.vsel_mask = DA9063_VBUCK_MASK, \ .desc.linear_min_sel = DA9063_VBUCK_BIAS, \ .sleep = BFIELD(DA9063_REG_V##regl_name##_A, DA9063_BUCK_SL), \ |
99f75ce66 regulator: da9063... |
125 |
.suspend = BFIELD(DA9063_REG_##regl_name##_CONT, DA9063_BUCK_CONF), \ |
69ca3e58d regulator: da9063... |
126 127 128 129 130 131 132 |
.suspend_sleep = BFIELD(DA9063_REG_V##regl_name##_B, DA9063_BUCK_SL), \ .suspend_vsel_reg = DA9063_REG_V##regl_name##_B, \ .mode = BFIELD(DA9063_REG_##regl_name##_CFG, DA9063_BUCK_MODE_MASK) /* Defines asignment of regulators info table to chip model */ struct da9063_dev_model { const struct da9063_regulator_info *regulator_info; |
a33b25f57 regulator: da9063... |
133 |
unsigned int n_regulators; |
492510dd7 mfd: da9063: Repl... |
134 |
enum da9063_type type; |
69ca3e58d regulator: da9063... |
135 136 137 138 139 140 141 142 143 144 145 146 147 |
}; /* Single regulator settings */ struct da9063_regulator { struct regulator_desc desc; struct regulator_dev *rdev; struct da9063 *hw; const struct da9063_regulator_info *info; struct regmap_field *mode; struct regmap_field *suspend; struct regmap_field *sleep; struct regmap_field *suspend_sleep; |
69ca3e58d regulator: da9063... |
148 149 150 151 |
}; /* Encapsulates all information for the regulators driver */ struct da9063_regulators { |
a33b25f57 regulator: da9063... |
152 |
unsigned int n_regulators; |
69ca3e58d regulator: da9063... |
153 |
/* Array size to be defined during init. Keep at end. */ |
23a653eb1 regulator: da9063... |
154 |
struct da9063_regulator regulator[]; |
69ca3e58d regulator: da9063... |
155 156 157 158 159 160 161 162 163 164 165 |
}; /* BUCK modes for DA9063 */ enum { BUCK_MODE_MANUAL, /* 0 */ BUCK_MODE_SLEEP, /* 1 */ BUCK_MODE_SYNC, /* 2 */ BUCK_MODE_AUTO /* 3 */ }; /* Regulator operations */ |
a33b25f57 regulator: da9063... |
166 167 168 169 |
/* * Current limits array (in uA) for BCORE1, BCORE2, BPRO. * Entry indexes corresponds to register values. */ |
5b1f537e4 regulator: da9063... |
170 |
static const unsigned int da9063_buck_a_limits[] = { |
69ca3e58d regulator: da9063... |
171 172 173 |
500000, 600000, 700000, 800000, 900000, 1000000, 1100000, 1200000, 1300000, 1400000, 1500000, 1600000, 1700000, 1800000, 1900000, 2000000 }; |
a33b25f57 regulator: da9063... |
174 175 176 177 |
/* * Current limits array (in uA) for BMEM, BIO, BPERI. * Entry indexes corresponds to register values. */ |
5b1f537e4 regulator: da9063... |
178 |
static const unsigned int da9063_buck_b_limits[] = { |
69ca3e58d regulator: da9063... |
179 180 181 |
1500000, 1600000, 1700000, 1800000, 1900000, 2000000, 2100000, 2200000, 2300000, 2400000, 2500000, 2600000, 2700000, 2800000, 2900000, 3000000 }; |
a33b25f57 regulator: da9063... |
182 183 184 185 |
/* * Current limits array (in uA) for merged BCORE1 and BCORE2. * Entry indexes corresponds to register values. */ |
5b1f537e4 regulator: da9063... |
186 |
static const unsigned int da9063_bcores_merged_limits[] = { |
69ca3e58d regulator: da9063... |
187 188 189 |
1000000, 1200000, 1400000, 1600000, 1800000, 2000000, 2200000, 2400000, 2600000, 2800000, 3000000, 3200000, 3400000, 3600000, 3800000, 4000000 }; |
a33b25f57 regulator: da9063... |
190 191 192 193 |
/* * Current limits array (in uA) for merged BMEM and BIO. * Entry indexes corresponds to register values. */ |
5b1f537e4 regulator: da9063... |
194 |
static const unsigned int da9063_bmem_bio_merged_limits[] = { |
69ca3e58d regulator: da9063... |
195 196 197 |
3000000, 3200000, 3400000, 3600000, 3800000, 4000000, 4200000, 4400000, 4600000, 4800000, 5000000, 5200000, 5400000, 5600000, 5800000, 6000000 }; |
a33b25f57 regulator: da9063... |
198 |
static int da9063_buck_set_mode(struct regulator_dev *rdev, unsigned int mode) |
69ca3e58d regulator: da9063... |
199 200 |
{ struct da9063_regulator *regl = rdev_get_drvdata(rdev); |
a33b25f57 regulator: da9063... |
201 |
unsigned int val; |
69ca3e58d regulator: da9063... |
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
switch (mode) { case REGULATOR_MODE_FAST: val = BUCK_MODE_SYNC; break; case REGULATOR_MODE_NORMAL: val = BUCK_MODE_AUTO; break; case REGULATOR_MODE_STANDBY: val = BUCK_MODE_SLEEP; break; default: return -EINVAL; } return regmap_field_write(regl->mode, val); } /* * Bucks use single mode register field for normal operation * and suspend state. * There are 3 modes to map to: FAST, NORMAL, and STANDBY. */ |
a33b25f57 regulator: da9063... |
225 |
static unsigned int da9063_buck_get_mode(struct regulator_dev *rdev) |
69ca3e58d regulator: da9063... |
226 227 |
{ struct da9063_regulator *regl = rdev_get_drvdata(rdev); |
e62cb0e00 regulator: da9063... |
228 |
unsigned int val; |
69ca3e58d regulator: da9063... |
229 230 231 232 233 234 235 236 237 |
int ret; ret = regmap_field_read(regl->mode, &val); if (ret < 0) return ret; switch (val) { default: case BUCK_MODE_MANUAL: |
69ca3e58d regulator: da9063... |
238 239 240 241 242 243 244 245 246 |
/* Sleep flag bit decides the mode */ break; case BUCK_MODE_SLEEP: return REGULATOR_MODE_STANDBY; case BUCK_MODE_SYNC: return REGULATOR_MODE_FAST; case BUCK_MODE_AUTO: return REGULATOR_MODE_NORMAL; } |
fc69bab1e regulator: da9063... |
247 |
ret = regmap_field_read(regl->sleep, &val); |
69ca3e58d regulator: da9063... |
248 249 250 251 |
if (ret < 0) return 0; if (val) |
e62cb0e00 regulator: da9063... |
252 |
return REGULATOR_MODE_STANDBY; |
69ca3e58d regulator: da9063... |
253 |
else |
e62cb0e00 regulator: da9063... |
254 |
return REGULATOR_MODE_FAST; |
69ca3e58d regulator: da9063... |
255 256 257 258 259 260 |
} /* * LDOs use sleep flags - one for normal and one for suspend state. * There are 2 modes to map to: NORMAL and STANDBY (sleep) for each state. */ |
a33b25f57 regulator: da9063... |
261 |
static int da9063_ldo_set_mode(struct regulator_dev *rdev, unsigned int mode) |
69ca3e58d regulator: da9063... |
262 263 |
{ struct da9063_regulator *regl = rdev_get_drvdata(rdev); |
a33b25f57 regulator: da9063... |
264 |
unsigned int val; |
69ca3e58d regulator: da9063... |
265 266 267 268 269 270 271 272 273 274 275 276 277 278 |
switch (mode) { case REGULATOR_MODE_NORMAL: val = 0; break; case REGULATOR_MODE_STANDBY: val = 1; break; default: return -EINVAL; } return regmap_field_write(regl->sleep, val); } |
a33b25f57 regulator: da9063... |
279 |
static unsigned int da9063_ldo_get_mode(struct regulator_dev *rdev) |
69ca3e58d regulator: da9063... |
280 281 |
{ struct da9063_regulator *regl = rdev_get_drvdata(rdev); |
69ca3e58d regulator: da9063... |
282 |
int ret, val; |
fc69bab1e regulator: da9063... |
283 |
ret = regmap_field_read(regl->sleep, &val); |
69ca3e58d regulator: da9063... |
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
if (ret < 0) return 0; if (val) return REGULATOR_MODE_STANDBY; else return REGULATOR_MODE_NORMAL; } static int da9063_buck_get_status(struct regulator_dev *rdev) { int ret = regulator_is_enabled_regmap(rdev); if (ret == 0) { ret = REGULATOR_STATUS_OFF; } else if (ret > 0) { ret = da9063_buck_get_mode(rdev); if (ret > 0) ret = regulator_mode_to_status(ret); else if (ret == 0) ret = -EIO; } return ret; } static int da9063_ldo_get_status(struct regulator_dev *rdev) { int ret = regulator_is_enabled_regmap(rdev); if (ret == 0) { ret = REGULATOR_STATUS_OFF; } else if (ret > 0) { ret = da9063_ldo_get_mode(rdev); if (ret > 0) ret = regulator_mode_to_status(ret); else if (ret == 0) ret = -EIO; } return ret; } static int da9063_set_suspend_voltage(struct regulator_dev *rdev, int uV) { struct da9063_regulator *regl = rdev_get_drvdata(rdev); const struct da9063_regulator_info *rinfo = regl->info; int ret, sel; sel = regulator_map_voltage_linear(rdev, uV, uV); if (sel < 0) |
8a7963d55 regulator: da9063... |
335 |
return sel; |
69ca3e58d regulator: da9063... |
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 |
sel <<= ffs(rdev->desc->vsel_mask) - 1; ret = regmap_update_bits(regl->hw->regmap, rinfo->suspend_vsel_reg, rdev->desc->vsel_mask, sel); return ret; } static int da9063_suspend_enable(struct regulator_dev *rdev) { struct da9063_regulator *regl = rdev_get_drvdata(rdev); return regmap_field_write(regl->suspend, 1); } static int da9063_suspend_disable(struct regulator_dev *rdev) { struct da9063_regulator *regl = rdev_get_drvdata(rdev); return regmap_field_write(regl->suspend, 0); } |
a33b25f57 regulator: da9063... |
358 359 |
static int da9063_buck_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode) |
69ca3e58d regulator: da9063... |
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 |
{ struct da9063_regulator *regl = rdev_get_drvdata(rdev); int val; switch (mode) { case REGULATOR_MODE_FAST: val = BUCK_MODE_SYNC; break; case REGULATOR_MODE_NORMAL: val = BUCK_MODE_AUTO; break; case REGULATOR_MODE_STANDBY: val = BUCK_MODE_SLEEP; break; default: return -EINVAL; } return regmap_field_write(regl->mode, val); } |
a33b25f57 regulator: da9063... |
380 381 |
static int da9063_ldo_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode) |
69ca3e58d regulator: da9063... |
382 383 |
{ struct da9063_regulator *regl = rdev_get_drvdata(rdev); |
a33b25f57 regulator: da9063... |
384 |
unsigned int val; |
69ca3e58d regulator: da9063... |
385 386 387 388 389 390 391 392 393 394 395 396 397 398 |
switch (mode) { case REGULATOR_MODE_NORMAL: val = 0; break; case REGULATOR_MODE_STANDBY: val = 1; break; default: return -EINVAL; } return regmap_field_write(regl->suspend_sleep, val); } |
71242b49a regulator: da9*: ... |
399 |
static const struct regulator_ops da9063_buck_ops = { |
69ca3e58d regulator: da9063... |
400 401 402 403 404 405 |
.enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .list_voltage = regulator_list_voltage_linear, |
5b1f537e4 regulator: da9063... |
406 407 |
.set_current_limit = regulator_set_current_limit_regmap, .get_current_limit = regulator_get_current_limit_regmap, |
69ca3e58d regulator: da9063... |
408 409 410 411 412 413 414 415 |
.set_mode = da9063_buck_set_mode, .get_mode = da9063_buck_get_mode, .get_status = da9063_buck_get_status, .set_suspend_voltage = da9063_set_suspend_voltage, .set_suspend_enable = da9063_suspend_enable, .set_suspend_disable = da9063_suspend_disable, .set_suspend_mode = da9063_buck_set_suspend_mode, }; |
71242b49a regulator: da9*: ... |
416 |
static const struct regulator_ops da9063_ldo_ops = { |
69ca3e58d regulator: da9063... |
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
.enable = regulator_enable_regmap, .disable = regulator_disable_regmap, .is_enabled = regulator_is_enabled_regmap, .get_voltage_sel = regulator_get_voltage_sel_regmap, .set_voltage_sel = regulator_set_voltage_sel_regmap, .list_voltage = regulator_list_voltage_linear, .set_mode = da9063_ldo_set_mode, .get_mode = da9063_ldo_get_mode, .get_status = da9063_ldo_get_status, .set_suspend_voltage = da9063_set_suspend_voltage, .set_suspend_enable = da9063_suspend_enable, .set_suspend_disable = da9063_suspend_disable, .set_suspend_mode = da9063_ldo_set_suspend_mode, }; /* Info of regulators for DA9063 */ static const struct da9063_regulator_info da9063_regulator_info[] = { { DA9063_BUCK(DA9063, BCORE1, 300, 10, 1570, |
5b1f537e4 regulator: da9063... |
436 437 |
da9063_buck_a_limits, DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK), |
69ca3e58d regulator: da9063... |
438 |
DA9063_BUCK_COMMON_FIELDS(BCORE1), |
69ca3e58d regulator: da9063... |
439 440 441 |
}, { DA9063_BUCK(DA9063, BCORE2, 300, 10, 1570, |
5b1f537e4 regulator: da9063... |
442 443 |
da9063_buck_a_limits, DA9063_REG_BUCK_ILIM_C, DA9063_BCORE2_ILIM_MASK), |
69ca3e58d regulator: da9063... |
444 |
DA9063_BUCK_COMMON_FIELDS(BCORE2), |
69ca3e58d regulator: da9063... |
445 446 447 |
}, { DA9063_BUCK(DA9063, BPRO, 530, 10, 1800, |
5b1f537e4 regulator: da9063... |
448 449 |
da9063_buck_a_limits, DA9063_REG_BUCK_ILIM_B, DA9063_BPRO_ILIM_MASK), |
69ca3e58d regulator: da9063... |
450 |
DA9063_BUCK_COMMON_FIELDS(BPRO), |
69ca3e58d regulator: da9063... |
451 452 453 |
}, { DA9063_BUCK(DA9063, BMEM, 800, 20, 3340, |
5b1f537e4 regulator: da9063... |
454 455 |
da9063_buck_b_limits, DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK), |
69ca3e58d regulator: da9063... |
456 |
DA9063_BUCK_COMMON_FIELDS(BMEM), |
69ca3e58d regulator: da9063... |
457 458 459 |
}, { DA9063_BUCK(DA9063, BIO, 800, 20, 3340, |
5b1f537e4 regulator: da9063... |
460 461 |
da9063_buck_b_limits, DA9063_REG_BUCK_ILIM_A, DA9063_BIO_ILIM_MASK), |
69ca3e58d regulator: da9063... |
462 |
DA9063_BUCK_COMMON_FIELDS(BIO), |
69ca3e58d regulator: da9063... |
463 464 465 |
}, { DA9063_BUCK(DA9063, BPERI, 800, 20, 3340, |
5b1f537e4 regulator: da9063... |
466 467 |
da9063_buck_b_limits, DA9063_REG_BUCK_ILIM_B, DA9063_BPERI_ILIM_MASK), |
69ca3e58d regulator: da9063... |
468 |
DA9063_BUCK_COMMON_FIELDS(BPERI), |
69ca3e58d regulator: da9063... |
469 470 471 |
}, { DA9063_BUCK(DA9063, BCORES_MERGED, 300, 10, 1570, |
5b1f537e4 regulator: da9063... |
472 473 |
da9063_bcores_merged_limits, DA9063_REG_BUCK_ILIM_C, DA9063_BCORE1_ILIM_MASK), |
69ca3e58d regulator: da9063... |
474 475 |
/* BCORES_MERGED uses the same register fields as BCORE1 */ DA9063_BUCK_COMMON_FIELDS(BCORE1), |
69ca3e58d regulator: da9063... |
476 477 478 |
}, { DA9063_BUCK(DA9063, BMEM_BIO_MERGED, 800, 20, 3340, |
5b1f537e4 regulator: da9063... |
479 480 |
da9063_bmem_bio_merged_limits, DA9063_REG_BUCK_ILIM_A, DA9063_BMEM_ILIM_MASK), |
69ca3e58d regulator: da9063... |
481 482 |
/* BMEM_BIO_MERGED uses the same register fields as BMEM */ DA9063_BUCK_COMMON_FIELDS(BMEM), |
69ca3e58d regulator: da9063... |
483 484 |
}, { |
1c892e38c regulator: da9063... |
485 |
DA9063_LDO(DA9063, LDO3, 900, 20, 3440), |
1c892e38c regulator: da9063... |
486 487 488 489 |
.oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO3_LIM), }, { DA9063_LDO(DA9063, LDO7, 900, 50, 3600), |
1c892e38c regulator: da9063... |
490 491 492 493 |
.oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO7_LIM), }, { DA9063_LDO(DA9063, LDO8, 900, 50, 3600), |
1c892e38c regulator: da9063... |
494 495 496 497 |
.oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO8_LIM), }, { DA9063_LDO(DA9063, LDO9, 950, 50, 3600), |
1c892e38c regulator: da9063... |
498 499 500 |
}, { DA9063_LDO(DA9063, LDO11, 900, 50, 3600), |
1c892e38c regulator: da9063... |
501 502 503 504 505 |
.oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO11_LIM), }, /* The following LDOs are present only on DA9063, not on DA9063L */ { |
69ca3e58d regulator: da9063... |
506 |
DA9063_LDO(DA9063, LDO1, 600, 20, 1860), |
69ca3e58d regulator: da9063... |
507 508 509 |
}, { DA9063_LDO(DA9063, LDO2, 600, 20, 1860), |
69ca3e58d regulator: da9063... |
510 511 |
}, { |
69ca3e58d regulator: da9063... |
512 |
DA9063_LDO(DA9063, LDO4, 900, 20, 3440), |
69ca3e58d regulator: da9063... |
513 514 515 516 |
.oc_event = BFIELD(DA9063_REG_STATUS_D, DA9063_LDO4_LIM), }, { DA9063_LDO(DA9063, LDO5, 900, 50, 3600), |
69ca3e58d regulator: da9063... |
517 518 519 |
}, { DA9063_LDO(DA9063, LDO6, 900, 50, 3600), |
69ca3e58d regulator: da9063... |
520 |
}, |
1c892e38c regulator: da9063... |
521 |
|
69ca3e58d regulator: da9063... |
522 523 |
{ DA9063_LDO(DA9063, LDO10, 900, 50, 3600), |
69ca3e58d regulator: da9063... |
524 |
}, |
69ca3e58d regulator: da9063... |
525 526 527 528 529 530 531 |
}; /* Link chip model with regulators info table */ static struct da9063_dev_model regulators_models[] = { { .regulator_info = da9063_regulator_info, .n_regulators = ARRAY_SIZE(da9063_regulator_info), |
492510dd7 mfd: da9063: Repl... |
532 |
.type = PMIC_TYPE_DA9063, |
69ca3e58d regulator: da9063... |
533 |
}, |
1c892e38c regulator: da9063... |
534 535 536 537 538 |
{ .regulator_info = da9063_regulator_info, .n_regulators = ARRAY_SIZE(da9063_regulator_info) - 6, .type = PMIC_TYPE_DA9063L, }, |
69ca3e58d regulator: da9063... |
539 540 541 542 |
{ } }; /* Regulator interrupt handlers */ |
632b3d62b regulator: da9063... |
543 |
static irqreturn_t da9063_ldo_lim_event(int irq, void *data) |
69ca3e58d regulator: da9063... |
544 545 546 547 |
{ struct da9063_regulators *regulators = data; struct da9063 *hw = regulators->regulator[0].hw; struct da9063_regulator *regl; |
a33b25f57 regulator: da9063... |
548 |
int bits, i, ret; |
69ca3e58d regulator: da9063... |
549 550 551 552 553 554 555 556 557 |
ret = regmap_read(hw->regmap, DA9063_REG_STATUS_D, &bits); if (ret < 0) return IRQ_NONE; for (i = regulators->n_regulators - 1; i >= 0; i--) { regl = ®ulators->regulator[i]; if (regl->info->oc_event.reg != DA9063_REG_STATUS_D) continue; |
29d40b4a5 regulator: da9063... |
558 |
if (BIT(regl->info->oc_event.lsb) & bits) { |
69ca3e58d regulator: da9063... |
559 560 |
regulator_notifier_call_chain(regl->rdev, REGULATOR_EVENT_OVER_CURRENT, NULL); |
29d40b4a5 regulator: da9063... |
561 |
} |
69ca3e58d regulator: da9063... |
562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 |
} return IRQ_HANDLED; } /* * Probing and Initialisation functions */ static const struct regulator_init_data *da9063_get_regulator_initdata( const struct da9063_regulators_pdata *regl_pdata, int id) { int i; for (i = 0; i < regl_pdata->n_regulators; i++) { if (id == regl_pdata->regulator_data[i].id) return regl_pdata->regulator_data[i].initdata; } return NULL; } |
69ca3e58d regulator: da9063... |
582 583 584 585 586 587 588 589 590 |
static struct of_regulator_match da9063_matches[] = { [DA9063_ID_BCORE1] = { .name = "bcore1" }, [DA9063_ID_BCORE2] = { .name = "bcore2" }, [DA9063_ID_BPRO] = { .name = "bpro", }, [DA9063_ID_BMEM] = { .name = "bmem", }, [DA9063_ID_BIO] = { .name = "bio", }, [DA9063_ID_BPERI] = { .name = "bperi", }, [DA9063_ID_BCORES_MERGED] = { .name = "bcores-merged" }, [DA9063_ID_BMEM_BIO_MERGED] = { .name = "bmem-bio-merged", }, |
1c892e38c regulator: da9063... |
591 592 593 594 595 596 |
[DA9063_ID_LDO3] = { .name = "ldo3", }, [DA9063_ID_LDO7] = { .name = "ldo7", }, [DA9063_ID_LDO8] = { .name = "ldo8", }, [DA9063_ID_LDO9] = { .name = "ldo9", }, [DA9063_ID_LDO11] = { .name = "ldo11", }, /* The following LDOs are present only on DA9063, not on DA9063L */ |
69ca3e58d regulator: da9063... |
597 598 |
[DA9063_ID_LDO1] = { .name = "ldo1", }, [DA9063_ID_LDO2] = { .name = "ldo2", }, |
69ca3e58d regulator: da9063... |
599 600 601 |
[DA9063_ID_LDO4] = { .name = "ldo4", }, [DA9063_ID_LDO5] = { .name = "ldo5", }, [DA9063_ID_LDO6] = { .name = "ldo6", }, |
69ca3e58d regulator: da9063... |
602 |
[DA9063_ID_LDO10] = { .name = "ldo10", }, |
69ca3e58d regulator: da9063... |
603 604 605 606 607 608 |
}; static struct da9063_regulators_pdata *da9063_parse_regulators_dt( struct platform_device *pdev, struct of_regulator_match **da9063_reg_matches) { |
1c892e38c regulator: da9063... |
609 |
struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); |
69ca3e58d regulator: da9063... |
610 611 612 |
struct da9063_regulators_pdata *pdata; struct da9063_regulator_data *rdata; struct device_node *node; |
1c892e38c regulator: da9063... |
613 |
int da9063_matches_len = ARRAY_SIZE(da9063_matches); |
69ca3e58d regulator: da9063... |
614 |
int i, n, num; |
1c892e38c regulator: da9063... |
615 616 |
if (da9063->type == PMIC_TYPE_DA9063L) da9063_matches_len -= 6; |
25cc275a8 regulator: da9063... |
617 |
node = of_get_child_by_name(pdev->dev.parent->of_node, "regulators"); |
69ca3e58d regulator: da9063... |
618 619 620 621 622 623 624 |
if (!node) { dev_err(&pdev->dev, "Regulators device node not found "); return ERR_PTR(-ENODEV); } num = of_regulator_match(&pdev->dev, node, da9063_matches, |
1c892e38c regulator: da9063... |
625 |
da9063_matches_len); |
2da8215ce regulator: da9063... |
626 |
of_node_put(node); |
69ca3e58d regulator: da9063... |
627 628 629 630 631 632 633 634 635 |
if (num < 0) { dev_err(&pdev->dev, "Failed to match regulators "); return ERR_PTR(-EINVAL); } pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); if (!pdata) return ERR_PTR(-ENOMEM); |
a86854d0c treewide: devm_kz... |
636 637 |
pdata->regulator_data = devm_kcalloc(&pdev->dev, num, sizeof(*pdata->regulator_data), |
69ca3e58d regulator: da9063... |
638 639 640 641 642 643 |
GFP_KERNEL); if (!pdata->regulator_data) return ERR_PTR(-ENOMEM); pdata->n_regulators = num; n = 0; |
1c892e38c regulator: da9063... |
644 |
for (i = 0; i < da9063_matches_len; i++) { |
69ca3e58d regulator: da9063... |
645 646 647 648 649 650 651 652 |
if (!da9063_matches[i].init_data) continue; rdata = &pdata->regulator_data[n]; rdata->id = i; rdata->initdata = da9063_matches[i].init_data; n++; |
424fb281d regulator: da9063... |
653 |
} |
69ca3e58d regulator: da9063... |
654 655 656 657 |
*da9063_reg_matches = da9063_matches; return pdata; } |
69ca3e58d regulator: da9063... |
658 659 660 661 |
static int da9063_regulator_probe(struct platform_device *pdev) { struct da9063 *da9063 = dev_get_drvdata(pdev->dev.parent); |
0fdfd40ac regulator: da9063... |
662 |
struct of_regulator_match *da9063_reg_matches = NULL; |
69ca3e58d regulator: da9063... |
663 664 665 666 667 668 669 |
struct da9063_regulators_pdata *regl_pdata; const struct da9063_dev_model *model; struct da9063_regulators *regulators; struct da9063_regulator *regl; struct regulator_config config; bool bcores_merged, bmem_bio_merged; int id, irq, n, n_regulators, ret, val; |
69ca3e58d regulator: da9063... |
670 |
|
662307294 regulator: da9063... |
671 |
regl_pdata = da9063_parse_regulators_dt(pdev, &da9063_reg_matches); |
69ca3e58d regulator: da9063... |
672 673 674 675 676 |
if (IS_ERR(regl_pdata) || regl_pdata->n_regulators == 0) { dev_err(&pdev->dev, "No regulators defined for the platform "); |
b66156598 regulator: da9063... |
677 |
return -ENODEV; |
69ca3e58d regulator: da9063... |
678 679 680 681 |
} /* Find regulators set for particular device model */ for (model = regulators_models; model->regulator_info; model++) { |
492510dd7 mfd: da9063: Repl... |
682 |
if (model->type == da9063->type) |
69ca3e58d regulator: da9063... |
683 684 685 686 687 |
break; } if (!model->regulator_info) { dev_err(&pdev->dev, "Chip model not recognised (%u) ", |
492510dd7 mfd: da9063: Repl... |
688 |
da9063->type); |
69ca3e58d regulator: da9063... |
689 690 691 692 693 694 695 696 |
return -ENODEV; } ret = regmap_read(da9063->regmap, DA9063_REG_CONFIG_H, &val); if (ret < 0) { dev_err(&pdev->dev, "Error while reading BUCKs configuration "); |
8a7963d55 regulator: da9063... |
697 |
return ret; |
69ca3e58d regulator: da9063... |
698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 |
} bcores_merged = val & DA9063_BCORE_MERGE; bmem_bio_merged = val & DA9063_BUCK_MERGE; n_regulators = model->n_regulators; if (bcores_merged) n_regulators -= 2; /* remove BCORE1, BCORE2 */ else n_regulators--; /* remove BCORES_MERGED */ if (bmem_bio_merged) n_regulators -= 2; /* remove BMEM, BIO */ else n_regulators--; /* remove BMEM_BIO_MERGED */ /* Allocate memory required by usable regulators */ |
ac227fb5b regulator: da9063... |
713 714 |
regulators = devm_kzalloc(&pdev->dev, struct_size(regulators, regulator, n_regulators), GFP_KERNEL); |
8b5baa56f regulator: da9063... |
715 |
if (!regulators) |
69ca3e58d regulator: da9063... |
716 |
return -ENOMEM; |
69ca3e58d regulator: da9063... |
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
regulators->n_regulators = n_regulators; platform_set_drvdata(pdev, regulators); /* Register all regulators declared in platform information */ n = 0; id = 0; while (n < regulators->n_regulators) { /* Skip regulator IDs depending on merge mode configuration */ switch (id) { case DA9063_ID_BCORE1: case DA9063_ID_BCORE2: if (bcores_merged) { id++; continue; } break; case DA9063_ID_BMEM: case DA9063_ID_BIO: if (bmem_bio_merged) { id++; continue; } break; case DA9063_ID_BCORES_MERGED: if (!bcores_merged) { id++; continue; } break; case DA9063_ID_BMEM_BIO_MERGED: if (!bmem_bio_merged) { id++; continue; } break; } /* Initialise regulator structure */ regl = ®ulators->regulator[n]; regl->hw = da9063; regl->info = &model->regulator_info[id]; regl->desc = regl->info->desc; regl->desc.type = REGULATOR_VOLTAGE; regl->desc.owner = THIS_MODULE; |
845920394 regulator: da9063... |
762 |
if (regl->info->mode.reg) { |
69ca3e58d regulator: da9063... |
763 764 |
regl->mode = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->mode); |
845920394 regulator: da9063... |
765 766 767 768 769 |
if (IS_ERR(regl->mode)) return PTR_ERR(regl->mode); } if (regl->info->suspend.reg) { |
69ca3e58d regulator: da9063... |
770 771 |
regl->suspend = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->suspend); |
845920394 regulator: da9063... |
772 773 774 775 776 |
if (IS_ERR(regl->suspend)) return PTR_ERR(regl->suspend); } if (regl->info->sleep.reg) { |
69ca3e58d regulator: da9063... |
777 778 |
regl->sleep = devm_regmap_field_alloc(&pdev->dev, da9063->regmap, regl->info->sleep); |
845920394 regulator: da9063... |
779 780 781 782 783 |
if (IS_ERR(regl->sleep)) return PTR_ERR(regl->sleep); } if (regl->info->suspend_sleep.reg) { |
69ca3e58d regulator: da9063... |
784 |
regl->suspend_sleep = devm_regmap_field_alloc(&pdev->dev, |
a33b25f57 regulator: da9063... |
785 |
da9063->regmap, regl->info->suspend_sleep); |
845920394 regulator: da9063... |
786 787 788 |
if (IS_ERR(regl->suspend_sleep)) return PTR_ERR(regl->suspend_sleep); } |
69ca3e58d regulator: da9063... |
789 790 791 792 793 794 795 796 |
/* Register regulator */ memset(&config, 0, sizeof(config)); config.dev = &pdev->dev; config.init_data = da9063_get_regulator_initdata(regl_pdata, id); config.driver_data = regl; if (da9063_reg_matches) config.of_node = da9063_reg_matches[id].of_node; config.regmap = da9063->regmap; |
e97bba912 regulator: da9063... |
797 798 |
regl->rdev = devm_regulator_register(&pdev->dev, ®l->desc, &config); |
e515800b7 regulator: da9063... |
799 |
if (IS_ERR(regl->rdev)) { |
69ca3e58d regulator: da9063... |
800 801 802 803 |
dev_err(&pdev->dev, "Failed to register %s regulator ", regl->desc.name); |
e97bba912 regulator: da9063... |
804 |
return PTR_ERR(regl->rdev); |
69ca3e58d regulator: da9063... |
805 806 807 808 809 810 811 |
} id++; n++; } /* LDOs overcurrent event support */ irq = platform_get_irq_byname(pdev, "LDO_LIM"); |
47241933b regulator: Remove... |
812 |
if (irq < 0) |
e97bba912 regulator: da9063... |
813 |
return irq; |
69ca3e58d regulator: da9063... |
814 |
|
d87aef916 regulator: da9063... |
815 |
ret = devm_request_threaded_irq(&pdev->dev, irq, |
8ad365c94 regulator: da9063... |
816 817 818 |
NULL, da9063_ldo_lim_event, IRQF_TRIGGER_LOW | IRQF_ONESHOT, "LDO_LIM", regulators); |
6d8d840b2 regulator: da9063... |
819 |
if (ret) |
d87aef916 regulator: da9063... |
820 821 |
dev_err(&pdev->dev, "Failed to request LDO_LIM IRQ. "); |
69ca3e58d regulator: da9063... |
822 |
|
6d8d840b2 regulator: da9063... |
823 |
return ret; |
69ca3e58d regulator: da9063... |
824 |
} |
69ca3e58d regulator: da9063... |
825 826 827 |
static struct platform_driver da9063_regulator_driver = { .driver = { .name = DA9063_DRVNAME_REGULATORS, |
69ca3e58d regulator: da9063... |
828 829 |
}, .probe = da9063_regulator_probe, |
69ca3e58d regulator: da9063... |
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 |
}; static int __init da9063_regulator_init(void) { return platform_driver_register(&da9063_regulator_driver); } subsys_initcall(da9063_regulator_init); static void __exit da9063_regulator_cleanup(void) { platform_driver_unregister(&da9063_regulator_driver); } module_exit(da9063_regulator_cleanup); /* Module information */ MODULE_AUTHOR("Krystian Garbaciak <krystian.garbaciak@diasemi.com>"); MODULE_DESCRIPTION("DA9063 regulators driver"); MODULE_LICENSE("GPL"); |
ac40b4417 regulator: da9063... |
849 |
MODULE_ALIAS("platform:" DA9063_DRVNAME_REGULATORS); |