| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * act8865-regulator.c - Voltage regulation for active-semi ACT88xx PMUs |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * http://www.active-semi.com/products/power-management-units/act88xx/ |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Copyright (C) 2013 Atmel Corporation |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 10 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 11 | | - * (at your option) any later version. |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 14 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 15 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 16 | | - * GNU General Public License for more details. |
|---|
| 17 | 8 | */ |
|---|
| 18 | 9 | |
|---|
| 19 | 10 | #include <linux/module.h> |
|---|
| .. | .. |
|---|
| 25 | 16 | #include <linux/regulator/act8865.h> |
|---|
| 26 | 17 | #include <linux/of.h> |
|---|
| 27 | 18 | #include <linux/of_device.h> |
|---|
| 19 | +#include <linux/power_supply.h> |
|---|
| 28 | 20 | #include <linux/regulator/of_regulator.h> |
|---|
| 29 | 21 | #include <linux/regmap.h> |
|---|
| 22 | +#include <dt-bindings/regulator/active-semi,8865-regulator.h> |
|---|
| 30 | 23 | |
|---|
| 31 | 24 | /* |
|---|
| 32 | 25 | * ACT8600 Global Register Map. |
|---|
| .. | .. |
|---|
| 98 | 91 | */ |
|---|
| 99 | 92 | #define ACT8865_SYS_MODE 0x00 |
|---|
| 100 | 93 | #define ACT8865_SYS_CTRL 0x01 |
|---|
| 94 | +#define ACT8865_SYS_UNLK_REGS 0x0b |
|---|
| 101 | 95 | #define ACT8865_DCDC1_VSET1 0x20 |
|---|
| 102 | 96 | #define ACT8865_DCDC1_VSET2 0x21 |
|---|
| 103 | 97 | #define ACT8865_DCDC1_CTRL 0x22 |
|---|
| 98 | +#define ACT8865_DCDC1_SUS 0x24 |
|---|
| 104 | 99 | #define ACT8865_DCDC2_VSET1 0x30 |
|---|
| 105 | 100 | #define ACT8865_DCDC2_VSET2 0x31 |
|---|
| 106 | 101 | #define ACT8865_DCDC2_CTRL 0x32 |
|---|
| 102 | +#define ACT8865_DCDC2_SUS 0x34 |
|---|
| 107 | 103 | #define ACT8865_DCDC3_VSET1 0x40 |
|---|
| 108 | 104 | #define ACT8865_DCDC3_VSET2 0x41 |
|---|
| 109 | 105 | #define ACT8865_DCDC3_CTRL 0x42 |
|---|
| 106 | +#define ACT8865_DCDC3_SUS 0x44 |
|---|
| 110 | 107 | #define ACT8865_LDO1_VSET 0x50 |
|---|
| 111 | 108 | #define ACT8865_LDO1_CTRL 0x51 |
|---|
| 109 | +#define ACT8865_LDO1_SUS 0x52 |
|---|
| 112 | 110 | #define ACT8865_LDO2_VSET 0x54 |
|---|
| 113 | 111 | #define ACT8865_LDO2_CTRL 0x55 |
|---|
| 112 | +#define ACT8865_LDO2_SUS 0x56 |
|---|
| 114 | 113 | #define ACT8865_LDO3_VSET 0x60 |
|---|
| 115 | 114 | #define ACT8865_LDO3_CTRL 0x61 |
|---|
| 115 | +#define ACT8865_LDO3_SUS 0x62 |
|---|
| 116 | 116 | #define ACT8865_LDO4_VSET 0x64 |
|---|
| 117 | 117 | #define ACT8865_LDO4_CTRL 0x65 |
|---|
| 118 | +#define ACT8865_LDO4_SUS 0x66 |
|---|
| 118 | 119 | #define ACT8865_MSTROFF 0x20 |
|---|
| 119 | 120 | |
|---|
| 120 | 121 | /* |
|---|
| 121 | 122 | * Field Definitions. |
|---|
| 122 | 123 | */ |
|---|
| 123 | 124 | #define ACT8865_ENA 0x80 /* ON - [7] */ |
|---|
| 125 | +#define ACT8865_DIS 0x40 /* DIS - [6] */ |
|---|
| 126 | + |
|---|
| 124 | 127 | #define ACT8865_VSEL_MASK 0x3F /* VSET - [5:0] */ |
|---|
| 125 | 128 | |
|---|
| 126 | 129 | |
|---|
| 127 | 130 | #define ACT8600_LDO10_ENA 0x40 /* ON - [6] */ |
|---|
| 128 | 131 | #define ACT8600_SUDCDC_VSEL_MASK 0xFF /* SUDCDC VSET - [7:0] */ |
|---|
| 132 | + |
|---|
| 133 | +#define ACT8600_APCH_CHG_ACIN BIT(7) |
|---|
| 134 | +#define ACT8600_APCH_CHG_USB BIT(6) |
|---|
| 135 | +#define ACT8600_APCH_CSTATE0 BIT(5) |
|---|
| 136 | +#define ACT8600_APCH_CSTATE1 BIT(4) |
|---|
| 129 | 137 | |
|---|
| 130 | 138 | /* |
|---|
| 131 | 139 | * ACT8865 voltage number |
|---|
| .. | .. |
|---|
| 212 | 220 | .val_bits = 8, |
|---|
| 213 | 221 | }; |
|---|
| 214 | 222 | |
|---|
| 215 | | -static const struct regulator_linear_range act8865_voltage_ranges[] = { |
|---|
| 223 | +static const struct linear_range act8865_voltage_ranges[] = { |
|---|
| 216 | 224 | REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000), |
|---|
| 217 | 225 | REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000), |
|---|
| 218 | 226 | REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), |
|---|
| 219 | 227 | }; |
|---|
| 220 | 228 | |
|---|
| 221 | | -static const struct regulator_linear_range act8600_sudcdc_voltage_ranges[] = { |
|---|
| 229 | +static const struct linear_range act8600_sudcdc_voltage_ranges[] = { |
|---|
| 222 | 230 | REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0), |
|---|
| 223 | 231 | REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000), |
|---|
| 224 | 232 | REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000), |
|---|
| .. | .. |
|---|
| 226 | 234 | REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0), |
|---|
| 227 | 235 | }; |
|---|
| 228 | 236 | |
|---|
| 229 | | -static struct regulator_ops act8865_ops = { |
|---|
| 237 | +static int act8865_set_suspend_state(struct regulator_dev *rdev, bool enable) |
|---|
| 238 | +{ |
|---|
| 239 | + struct regmap *regmap = rdev->regmap; |
|---|
| 240 | + int id = rdev->desc->id, reg, val; |
|---|
| 241 | + |
|---|
| 242 | + switch (id) { |
|---|
| 243 | + case ACT8865_ID_DCDC1: |
|---|
| 244 | + reg = ACT8865_DCDC1_SUS; |
|---|
| 245 | + val = 0xa8; |
|---|
| 246 | + break; |
|---|
| 247 | + case ACT8865_ID_DCDC2: |
|---|
| 248 | + reg = ACT8865_DCDC2_SUS; |
|---|
| 249 | + val = 0xa8; |
|---|
| 250 | + break; |
|---|
| 251 | + case ACT8865_ID_DCDC3: |
|---|
| 252 | + reg = ACT8865_DCDC3_SUS; |
|---|
| 253 | + val = 0xa8; |
|---|
| 254 | + break; |
|---|
| 255 | + case ACT8865_ID_LDO1: |
|---|
| 256 | + reg = ACT8865_LDO1_SUS; |
|---|
| 257 | + val = 0xe8; |
|---|
| 258 | + break; |
|---|
| 259 | + case ACT8865_ID_LDO2: |
|---|
| 260 | + reg = ACT8865_LDO2_SUS; |
|---|
| 261 | + val = 0xe8; |
|---|
| 262 | + break; |
|---|
| 263 | + case ACT8865_ID_LDO3: |
|---|
| 264 | + reg = ACT8865_LDO3_SUS; |
|---|
| 265 | + val = 0xe8; |
|---|
| 266 | + break; |
|---|
| 267 | + case ACT8865_ID_LDO4: |
|---|
| 268 | + reg = ACT8865_LDO4_SUS; |
|---|
| 269 | + val = 0xe8; |
|---|
| 270 | + break; |
|---|
| 271 | + default: |
|---|
| 272 | + return -EINVAL; |
|---|
| 273 | + } |
|---|
| 274 | + |
|---|
| 275 | + if (enable) |
|---|
| 276 | + val |= BIT(4); |
|---|
| 277 | + |
|---|
| 278 | + /* |
|---|
| 279 | + * Ask the PMIC to enable/disable this output when entering hibernate |
|---|
| 280 | + * mode. |
|---|
| 281 | + */ |
|---|
| 282 | + return regmap_write(regmap, reg, val); |
|---|
| 283 | +} |
|---|
| 284 | + |
|---|
| 285 | +static int act8865_set_suspend_enable(struct regulator_dev *rdev) |
|---|
| 286 | +{ |
|---|
| 287 | + return act8865_set_suspend_state(rdev, true); |
|---|
| 288 | +} |
|---|
| 289 | + |
|---|
| 290 | +static int act8865_set_suspend_disable(struct regulator_dev *rdev) |
|---|
| 291 | +{ |
|---|
| 292 | + return act8865_set_suspend_state(rdev, false); |
|---|
| 293 | +} |
|---|
| 294 | + |
|---|
| 295 | +static unsigned int act8865_of_map_mode(unsigned int mode) |
|---|
| 296 | +{ |
|---|
| 297 | + switch (mode) { |
|---|
| 298 | + case ACT8865_REGULATOR_MODE_FIXED: |
|---|
| 299 | + return REGULATOR_MODE_FAST; |
|---|
| 300 | + case ACT8865_REGULATOR_MODE_NORMAL: |
|---|
| 301 | + return REGULATOR_MODE_NORMAL; |
|---|
| 302 | + case ACT8865_REGULATOR_MODE_LOWPOWER: |
|---|
| 303 | + return REGULATOR_MODE_STANDBY; |
|---|
| 304 | + default: |
|---|
| 305 | + return REGULATOR_MODE_INVALID; |
|---|
| 306 | + } |
|---|
| 307 | +} |
|---|
| 308 | + |
|---|
| 309 | +static int act8865_set_mode(struct regulator_dev *rdev, unsigned int mode) |
|---|
| 310 | +{ |
|---|
| 311 | + struct regmap *regmap = rdev->regmap; |
|---|
| 312 | + int id = rdev_get_id(rdev); |
|---|
| 313 | + int reg, val = 0; |
|---|
| 314 | + |
|---|
| 315 | + switch (id) { |
|---|
| 316 | + case ACT8865_ID_DCDC1: |
|---|
| 317 | + reg = ACT8865_DCDC1_CTRL; |
|---|
| 318 | + break; |
|---|
| 319 | + case ACT8865_ID_DCDC2: |
|---|
| 320 | + reg = ACT8865_DCDC2_CTRL; |
|---|
| 321 | + break; |
|---|
| 322 | + case ACT8865_ID_DCDC3: |
|---|
| 323 | + reg = ACT8865_DCDC3_CTRL; |
|---|
| 324 | + break; |
|---|
| 325 | + case ACT8865_ID_LDO1: |
|---|
| 326 | + reg = ACT8865_LDO1_CTRL; |
|---|
| 327 | + break; |
|---|
| 328 | + case ACT8865_ID_LDO2: |
|---|
| 329 | + reg = ACT8865_LDO2_CTRL; |
|---|
| 330 | + break; |
|---|
| 331 | + case ACT8865_ID_LDO3: |
|---|
| 332 | + reg = ACT8865_LDO3_CTRL; |
|---|
| 333 | + break; |
|---|
| 334 | + case ACT8865_ID_LDO4: |
|---|
| 335 | + reg = ACT8865_LDO4_CTRL; |
|---|
| 336 | + break; |
|---|
| 337 | + default: |
|---|
| 338 | + return -EINVAL; |
|---|
| 339 | + } |
|---|
| 340 | + |
|---|
| 341 | + switch (mode) { |
|---|
| 342 | + case REGULATOR_MODE_FAST: |
|---|
| 343 | + case REGULATOR_MODE_NORMAL: |
|---|
| 344 | + if (id <= ACT8865_ID_DCDC3) |
|---|
| 345 | + val = BIT(5); |
|---|
| 346 | + break; |
|---|
| 347 | + case REGULATOR_MODE_STANDBY: |
|---|
| 348 | + if (id > ACT8865_ID_DCDC3) |
|---|
| 349 | + val = BIT(5); |
|---|
| 350 | + break; |
|---|
| 351 | + default: |
|---|
| 352 | + return -EINVAL; |
|---|
| 353 | + } |
|---|
| 354 | + |
|---|
| 355 | + return regmap_update_bits(regmap, reg, BIT(5), val); |
|---|
| 356 | +} |
|---|
| 357 | + |
|---|
| 358 | +static unsigned int act8865_get_mode(struct regulator_dev *rdev) |
|---|
| 359 | +{ |
|---|
| 360 | + struct regmap *regmap = rdev->regmap; |
|---|
| 361 | + int id = rdev_get_id(rdev); |
|---|
| 362 | + int reg, ret, val = 0; |
|---|
| 363 | + |
|---|
| 364 | + switch (id) { |
|---|
| 365 | + case ACT8865_ID_DCDC1: |
|---|
| 366 | + reg = ACT8865_DCDC1_CTRL; |
|---|
| 367 | + break; |
|---|
| 368 | + case ACT8865_ID_DCDC2: |
|---|
| 369 | + reg = ACT8865_DCDC2_CTRL; |
|---|
| 370 | + break; |
|---|
| 371 | + case ACT8865_ID_DCDC3: |
|---|
| 372 | + reg = ACT8865_DCDC3_CTRL; |
|---|
| 373 | + break; |
|---|
| 374 | + case ACT8865_ID_LDO1: |
|---|
| 375 | + reg = ACT8865_LDO1_CTRL; |
|---|
| 376 | + break; |
|---|
| 377 | + case ACT8865_ID_LDO2: |
|---|
| 378 | + reg = ACT8865_LDO2_CTRL; |
|---|
| 379 | + break; |
|---|
| 380 | + case ACT8865_ID_LDO3: |
|---|
| 381 | + reg = ACT8865_LDO3_CTRL; |
|---|
| 382 | + break; |
|---|
| 383 | + case ACT8865_ID_LDO4: |
|---|
| 384 | + reg = ACT8865_LDO4_CTRL; |
|---|
| 385 | + break; |
|---|
| 386 | + default: |
|---|
| 387 | + return -EINVAL; |
|---|
| 388 | + } |
|---|
| 389 | + |
|---|
| 390 | + ret = regmap_read(regmap, reg, &val); |
|---|
| 391 | + if (ret) |
|---|
| 392 | + return ret; |
|---|
| 393 | + |
|---|
| 394 | + if (id <= ACT8865_ID_DCDC3 && (val & BIT(5))) |
|---|
| 395 | + return REGULATOR_MODE_FAST; |
|---|
| 396 | + else if (id > ACT8865_ID_DCDC3 && !(val & BIT(5))) |
|---|
| 397 | + return REGULATOR_MODE_NORMAL; |
|---|
| 398 | + else |
|---|
| 399 | + return REGULATOR_MODE_STANDBY; |
|---|
| 400 | +} |
|---|
| 401 | + |
|---|
| 402 | +static const struct regulator_ops act8865_ops = { |
|---|
| 230 | 403 | .list_voltage = regulator_list_voltage_linear_range, |
|---|
| 231 | 404 | .map_voltage = regulator_map_voltage_linear_range, |
|---|
| 232 | 405 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| 233 | 406 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
|---|
| 234 | 407 | .enable = regulator_enable_regmap, |
|---|
| 235 | 408 | .disable = regulator_disable_regmap, |
|---|
| 409 | + .set_mode = act8865_set_mode, |
|---|
| 410 | + .get_mode = act8865_get_mode, |
|---|
| 236 | 411 | .is_enabled = regulator_is_enabled_regmap, |
|---|
| 412 | + .set_suspend_enable = act8865_set_suspend_enable, |
|---|
| 413 | + .set_suspend_disable = act8865_set_suspend_disable, |
|---|
| 237 | 414 | }; |
|---|
| 238 | 415 | |
|---|
| 239 | | -static struct regulator_ops act8865_ldo_ops = { |
|---|
| 416 | +static const struct regulator_ops act8865_ldo_ops = { |
|---|
| 417 | + .list_voltage = regulator_list_voltage_linear_range, |
|---|
| 418 | + .map_voltage = regulator_map_voltage_linear_range, |
|---|
| 419 | + .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| 420 | + .set_voltage_sel = regulator_set_voltage_sel_regmap, |
|---|
| 421 | + .enable = regulator_enable_regmap, |
|---|
| 422 | + .disable = regulator_disable_regmap, |
|---|
| 423 | + .set_mode = act8865_set_mode, |
|---|
| 424 | + .get_mode = act8865_get_mode, |
|---|
| 425 | + .is_enabled = regulator_is_enabled_regmap, |
|---|
| 426 | + .set_suspend_enable = act8865_set_suspend_enable, |
|---|
| 427 | + .set_suspend_disable = act8865_set_suspend_disable, |
|---|
| 428 | + .set_pull_down = regulator_set_pull_down_regmap, |
|---|
| 429 | +}; |
|---|
| 430 | + |
|---|
| 431 | +static const struct regulator_ops act8865_fixed_ldo_ops = { |
|---|
| 240 | 432 | .enable = regulator_enable_regmap, |
|---|
| 241 | 433 | .disable = regulator_disable_regmap, |
|---|
| 242 | 434 | .is_enabled = regulator_is_enabled_regmap, |
|---|
| 243 | 435 | }; |
|---|
| 244 | 436 | |
|---|
| 245 | | -#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \ |
|---|
| 437 | +#define ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, _ops) \ |
|---|
| 246 | 438 | [_family##_ID_##_id] = { \ |
|---|
| 247 | 439 | .name = _name, \ |
|---|
| 440 | + .of_match = of_match_ptr(_name), \ |
|---|
| 441 | + .of_map_mode = act8865_of_map_mode, \ |
|---|
| 442 | + .regulators_node = of_match_ptr("regulators"), \ |
|---|
| 248 | 443 | .supply_name = _supply, \ |
|---|
| 249 | 444 | .id = _family##_ID_##_id, \ |
|---|
| 250 | 445 | .type = REGULATOR_VOLTAGE, \ |
|---|
| 251 | | - .ops = &act8865_ops, \ |
|---|
| 446 | + .ops = _ops, \ |
|---|
| 252 | 447 | .n_voltages = ACT8865_VOLTAGE_NUM, \ |
|---|
| 253 | 448 | .linear_ranges = act8865_voltage_ranges, \ |
|---|
| 254 | 449 | .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \ |
|---|
| .. | .. |
|---|
| 256 | 451 | .vsel_mask = ACT8865_VSEL_MASK, \ |
|---|
| 257 | 452 | .enable_reg = _family##_##_id##_CTRL, \ |
|---|
| 258 | 453 | .enable_mask = ACT8865_ENA, \ |
|---|
| 454 | + .pull_down_reg = _family##_##_id##_CTRL, \ |
|---|
| 455 | + .pull_down_mask = ACT8865_DIS, \ |
|---|
| 259 | 456 | .owner = THIS_MODULE, \ |
|---|
| 260 | 457 | } |
|---|
| 458 | + |
|---|
| 459 | +#define ACT88xx_REG(_name, _family, _id, _vsel_reg, _supply) \ |
|---|
| 460 | + ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, &act8865_ops) |
|---|
| 461 | + |
|---|
| 462 | +#define ACT88xx_LDO(_name, _family, _id, _vsel_reg, _supply) \ |
|---|
| 463 | + ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, &act8865_ldo_ops) |
|---|
| 261 | 464 | |
|---|
| 262 | 465 | static const struct regulator_desc act8600_regulators[] = { |
|---|
| 263 | 466 | ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"), |
|---|
| .. | .. |
|---|
| 265 | 468 | ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"), |
|---|
| 266 | 469 | { |
|---|
| 267 | 470 | .name = "SUDCDC_REG4", |
|---|
| 471 | + .of_match = of_match_ptr("SUDCDC_REG4"), |
|---|
| 472 | + .regulators_node = of_match_ptr("regulators"), |
|---|
| 268 | 473 | .id = ACT8600_ID_SUDCDC4, |
|---|
| 269 | 474 | .ops = &act8865_ops, |
|---|
| 270 | 475 | .type = REGULATOR_VOLTAGE, |
|---|
| .. | .. |
|---|
| 283 | 488 | ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"), |
|---|
| 284 | 489 | { |
|---|
| 285 | 490 | .name = "LDO_REG9", |
|---|
| 491 | + .of_match = of_match_ptr("LDO_REG9"), |
|---|
| 492 | + .regulators_node = of_match_ptr("regulators"), |
|---|
| 286 | 493 | .id = ACT8600_ID_LDO9, |
|---|
| 287 | | - .ops = &act8865_ldo_ops, |
|---|
| 494 | + .ops = &act8865_fixed_ldo_ops, |
|---|
| 288 | 495 | .type = REGULATOR_VOLTAGE, |
|---|
| 289 | 496 | .n_voltages = 1, |
|---|
| 290 | 497 | .fixed_uV = 3300000, |
|---|
| .. | .. |
|---|
| 294 | 501 | }, |
|---|
| 295 | 502 | { |
|---|
| 296 | 503 | .name = "LDO_REG10", |
|---|
| 504 | + .of_match = of_match_ptr("LDO_REG10"), |
|---|
| 505 | + .regulators_node = of_match_ptr("regulators"), |
|---|
| 297 | 506 | .id = ACT8600_ID_LDO10, |
|---|
| 298 | | - .ops = &act8865_ldo_ops, |
|---|
| 507 | + .ops = &act8865_fixed_ldo_ops, |
|---|
| 299 | 508 | .type = REGULATOR_VOLTAGE, |
|---|
| 300 | 509 | .n_voltages = 1, |
|---|
| 301 | 510 | .fixed_uV = 1200000, |
|---|
| .. | .. |
|---|
| 324 | 533 | ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1, "vp1"), |
|---|
| 325 | 534 | ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1, "vp2"), |
|---|
| 326 | 535 | ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1, "vp3"), |
|---|
| 327 | | - ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"), |
|---|
| 328 | | - ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"), |
|---|
| 329 | | - ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"), |
|---|
| 330 | | - ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"), |
|---|
| 536 | + ACT88xx_LDO("LDO_REG1", ACT8865, LDO1, VSET, "inl45"), |
|---|
| 537 | + ACT88xx_LDO("LDO_REG2", ACT8865, LDO2, VSET, "inl45"), |
|---|
| 538 | + ACT88xx_LDO("LDO_REG3", ACT8865, LDO3, VSET, "inl67"), |
|---|
| 539 | + ACT88xx_LDO("LDO_REG4", ACT8865, LDO4, VSET, "inl67"), |
|---|
| 331 | 540 | }; |
|---|
| 332 | 541 | |
|---|
| 333 | 542 | static const struct regulator_desc act8865_alt_regulators[] = { |
|---|
| 334 | 543 | ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"), |
|---|
| 335 | 544 | ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"), |
|---|
| 336 | 545 | ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"), |
|---|
| 337 | | - ACT88xx_REG("LDO_REG1", ACT8865, LDO1, VSET, "inl45"), |
|---|
| 338 | | - ACT88xx_REG("LDO_REG2", ACT8865, LDO2, VSET, "inl45"), |
|---|
| 339 | | - ACT88xx_REG("LDO_REG3", ACT8865, LDO3, VSET, "inl67"), |
|---|
| 340 | | - ACT88xx_REG("LDO_REG4", ACT8865, LDO4, VSET, "inl67"), |
|---|
| 546 | + ACT88xx_LDO("LDO_REG1", ACT8865, LDO1, VSET, "inl45"), |
|---|
| 547 | + ACT88xx_LDO("LDO_REG2", ACT8865, LDO2, VSET, "inl45"), |
|---|
| 548 | + ACT88xx_LDO("LDO_REG3", ACT8865, LDO3, VSET, "inl67"), |
|---|
| 549 | + ACT88xx_LDO("LDO_REG4", ACT8865, LDO4, VSET, "inl67"), |
|---|
| 341 | 550 | }; |
|---|
| 342 | 551 | |
|---|
| 343 | 552 | #ifdef CONFIG_OF |
|---|
| .. | .. |
|---|
| 348 | 557 | { } |
|---|
| 349 | 558 | }; |
|---|
| 350 | 559 | MODULE_DEVICE_TABLE(of, act8865_dt_ids); |
|---|
| 351 | | - |
|---|
| 352 | | -static struct of_regulator_match act8846_matches[] = { |
|---|
| 353 | | - [ACT8846_ID_REG1] = { .name = "REG1" }, |
|---|
| 354 | | - [ACT8846_ID_REG2] = { .name = "REG2" }, |
|---|
| 355 | | - [ACT8846_ID_REG3] = { .name = "REG3" }, |
|---|
| 356 | | - [ACT8846_ID_REG4] = { .name = "REG4" }, |
|---|
| 357 | | - [ACT8846_ID_REG5] = { .name = "REG5" }, |
|---|
| 358 | | - [ACT8846_ID_REG6] = { .name = "REG6" }, |
|---|
| 359 | | - [ACT8846_ID_REG7] = { .name = "REG7" }, |
|---|
| 360 | | - [ACT8846_ID_REG8] = { .name = "REG8" }, |
|---|
| 361 | | - [ACT8846_ID_REG9] = { .name = "REG9" }, |
|---|
| 362 | | - [ACT8846_ID_REG10] = { .name = "REG10" }, |
|---|
| 363 | | - [ACT8846_ID_REG11] = { .name = "REG11" }, |
|---|
| 364 | | - [ACT8846_ID_REG12] = { .name = "REG12" }, |
|---|
| 365 | | -}; |
|---|
| 366 | | - |
|---|
| 367 | | -static struct of_regulator_match act8865_matches[] = { |
|---|
| 368 | | - [ACT8865_ID_DCDC1] = { .name = "DCDC_REG1"}, |
|---|
| 369 | | - [ACT8865_ID_DCDC2] = { .name = "DCDC_REG2"}, |
|---|
| 370 | | - [ACT8865_ID_DCDC3] = { .name = "DCDC_REG3"}, |
|---|
| 371 | | - [ACT8865_ID_LDO1] = { .name = "LDO_REG1"}, |
|---|
| 372 | | - [ACT8865_ID_LDO2] = { .name = "LDO_REG2"}, |
|---|
| 373 | | - [ACT8865_ID_LDO3] = { .name = "LDO_REG3"}, |
|---|
| 374 | | - [ACT8865_ID_LDO4] = { .name = "LDO_REG4"}, |
|---|
| 375 | | -}; |
|---|
| 376 | | - |
|---|
| 377 | | -static struct of_regulator_match act8600_matches[] = { |
|---|
| 378 | | - [ACT8600_ID_DCDC1] = { .name = "DCDC_REG1"}, |
|---|
| 379 | | - [ACT8600_ID_DCDC2] = { .name = "DCDC_REG2"}, |
|---|
| 380 | | - [ACT8600_ID_DCDC3] = { .name = "DCDC_REG3"}, |
|---|
| 381 | | - [ACT8600_ID_SUDCDC4] = { .name = "SUDCDC_REG4"}, |
|---|
| 382 | | - [ACT8600_ID_LDO5] = { .name = "LDO_REG5"}, |
|---|
| 383 | | - [ACT8600_ID_LDO6] = { .name = "LDO_REG6"}, |
|---|
| 384 | | - [ACT8600_ID_LDO7] = { .name = "LDO_REG7"}, |
|---|
| 385 | | - [ACT8600_ID_LDO8] = { .name = "LDO_REG8"}, |
|---|
| 386 | | - [ACT8600_ID_LDO9] = { .name = "LDO_REG9"}, |
|---|
| 387 | | - [ACT8600_ID_LDO10] = { .name = "LDO_REG10"}, |
|---|
| 388 | | -}; |
|---|
| 389 | | - |
|---|
| 390 | | -static int act8865_pdata_from_dt(struct device *dev, |
|---|
| 391 | | - struct act8865_platform_data *pdata, |
|---|
| 392 | | - unsigned long type) |
|---|
| 393 | | -{ |
|---|
| 394 | | - int matched, i, num_matches; |
|---|
| 395 | | - struct device_node *np; |
|---|
| 396 | | - struct act8865_regulator_data *regulator; |
|---|
| 397 | | - struct of_regulator_match *matches; |
|---|
| 398 | | - |
|---|
| 399 | | - switch (type) { |
|---|
| 400 | | - case ACT8600: |
|---|
| 401 | | - matches = act8600_matches; |
|---|
| 402 | | - num_matches = ARRAY_SIZE(act8600_matches); |
|---|
| 403 | | - break; |
|---|
| 404 | | - case ACT8846: |
|---|
| 405 | | - matches = act8846_matches; |
|---|
| 406 | | - num_matches = ARRAY_SIZE(act8846_matches); |
|---|
| 407 | | - break; |
|---|
| 408 | | - case ACT8865: |
|---|
| 409 | | - matches = act8865_matches; |
|---|
| 410 | | - num_matches = ARRAY_SIZE(act8865_matches); |
|---|
| 411 | | - break; |
|---|
| 412 | | - default: |
|---|
| 413 | | - dev_err(dev, "invalid device id %lu\n", type); |
|---|
| 414 | | - return -EINVAL; |
|---|
| 415 | | - } |
|---|
| 416 | | - |
|---|
| 417 | | - np = of_get_child_by_name(dev->of_node, "regulators"); |
|---|
| 418 | | - if (!np) { |
|---|
| 419 | | - dev_err(dev, "missing 'regulators' subnode in DT\n"); |
|---|
| 420 | | - return -EINVAL; |
|---|
| 421 | | - } |
|---|
| 422 | | - |
|---|
| 423 | | - matched = of_regulator_match(dev, np, matches, num_matches); |
|---|
| 424 | | - of_node_put(np); |
|---|
| 425 | | - if (matched <= 0) |
|---|
| 426 | | - return matched; |
|---|
| 427 | | - |
|---|
| 428 | | - pdata->regulators = devm_kcalloc(dev, |
|---|
| 429 | | - num_matches, |
|---|
| 430 | | - sizeof(struct act8865_regulator_data), |
|---|
| 431 | | - GFP_KERNEL); |
|---|
| 432 | | - if (!pdata->regulators) |
|---|
| 433 | | - return -ENOMEM; |
|---|
| 434 | | - |
|---|
| 435 | | - pdata->num_regulators = num_matches; |
|---|
| 436 | | - regulator = pdata->regulators; |
|---|
| 437 | | - |
|---|
| 438 | | - for (i = 0; i < num_matches; i++) { |
|---|
| 439 | | - regulator->id = i; |
|---|
| 440 | | - regulator->name = matches[i].name; |
|---|
| 441 | | - regulator->init_data = matches[i].init_data; |
|---|
| 442 | | - regulator->of_node = matches[i].of_node; |
|---|
| 443 | | - regulator++; |
|---|
| 444 | | - } |
|---|
| 445 | | - |
|---|
| 446 | | - return 0; |
|---|
| 447 | | -} |
|---|
| 448 | | -#else |
|---|
| 449 | | -static inline int act8865_pdata_from_dt(struct device *dev, |
|---|
| 450 | | - struct act8865_platform_data *pdata, |
|---|
| 451 | | - unsigned long type) |
|---|
| 452 | | -{ |
|---|
| 453 | | - return 0; |
|---|
| 454 | | -} |
|---|
| 455 | 560 | #endif |
|---|
| 456 | 561 | |
|---|
| 457 | 562 | static struct act8865_regulator_data *act8865_get_regulator_data( |
|---|
| 458 | 563 | int id, struct act8865_platform_data *pdata) |
|---|
| 459 | 564 | { |
|---|
| 460 | 565 | int i; |
|---|
| 461 | | - |
|---|
| 462 | | - if (!pdata) |
|---|
| 463 | | - return NULL; |
|---|
| 464 | 566 | |
|---|
| 465 | 567 | for (i = 0; i < pdata->num_regulators; i++) { |
|---|
| 466 | 568 | if (pdata->regulators[i].id == id) |
|---|
| .. | .. |
|---|
| 480 | 582 | while (1); |
|---|
| 481 | 583 | } |
|---|
| 482 | 584 | |
|---|
| 585 | +static int act8600_charger_get_status(struct regmap *map) |
|---|
| 586 | +{ |
|---|
| 587 | + unsigned int val; |
|---|
| 588 | + int ret; |
|---|
| 589 | + u8 state0, state1; |
|---|
| 590 | + |
|---|
| 591 | + ret = regmap_read(map, ACT8600_APCH_STAT, &val); |
|---|
| 592 | + if (ret < 0) |
|---|
| 593 | + return ret; |
|---|
| 594 | + |
|---|
| 595 | + state0 = val & ACT8600_APCH_CSTATE0; |
|---|
| 596 | + state1 = val & ACT8600_APCH_CSTATE1; |
|---|
| 597 | + |
|---|
| 598 | + if (state0 && !state1) |
|---|
| 599 | + return POWER_SUPPLY_STATUS_CHARGING; |
|---|
| 600 | + if (!state0 && state1) |
|---|
| 601 | + return POWER_SUPPLY_STATUS_NOT_CHARGING; |
|---|
| 602 | + if (!state0 && !state1) |
|---|
| 603 | + return POWER_SUPPLY_STATUS_DISCHARGING; |
|---|
| 604 | + |
|---|
| 605 | + return POWER_SUPPLY_STATUS_UNKNOWN; |
|---|
| 606 | +} |
|---|
| 607 | + |
|---|
| 608 | +static int act8600_charger_get_property(struct power_supply *psy, |
|---|
| 609 | + enum power_supply_property psp, union power_supply_propval *val) |
|---|
| 610 | +{ |
|---|
| 611 | + struct regmap *map = power_supply_get_drvdata(psy); |
|---|
| 612 | + int ret; |
|---|
| 613 | + |
|---|
| 614 | + switch (psp) { |
|---|
| 615 | + case POWER_SUPPLY_PROP_STATUS: |
|---|
| 616 | + ret = act8600_charger_get_status(map); |
|---|
| 617 | + if (ret < 0) |
|---|
| 618 | + return ret; |
|---|
| 619 | + |
|---|
| 620 | + val->intval = ret; |
|---|
| 621 | + break; |
|---|
| 622 | + default: |
|---|
| 623 | + return -EINVAL; |
|---|
| 624 | + } |
|---|
| 625 | + |
|---|
| 626 | + return 0; |
|---|
| 627 | +} |
|---|
| 628 | + |
|---|
| 629 | +static enum power_supply_property act8600_charger_properties[] = { |
|---|
| 630 | + POWER_SUPPLY_PROP_STATUS, |
|---|
| 631 | +}; |
|---|
| 632 | + |
|---|
| 633 | +static const struct power_supply_desc act8600_charger_desc = { |
|---|
| 634 | + .name = "act8600-charger", |
|---|
| 635 | + .type = POWER_SUPPLY_TYPE_BATTERY, |
|---|
| 636 | + .properties = act8600_charger_properties, |
|---|
| 637 | + .num_properties = ARRAY_SIZE(act8600_charger_properties), |
|---|
| 638 | + .get_property = act8600_charger_get_property, |
|---|
| 639 | +}; |
|---|
| 640 | + |
|---|
| 641 | +static int act8600_charger_probe(struct device *dev, struct regmap *regmap) |
|---|
| 642 | +{ |
|---|
| 643 | + struct power_supply *charger; |
|---|
| 644 | + struct power_supply_config cfg = { |
|---|
| 645 | + .drv_data = regmap, |
|---|
| 646 | + .of_node = dev->of_node, |
|---|
| 647 | + }; |
|---|
| 648 | + |
|---|
| 649 | + charger = devm_power_supply_register(dev, &act8600_charger_desc, &cfg); |
|---|
| 650 | + |
|---|
| 651 | + return PTR_ERR_OR_ZERO(charger); |
|---|
| 652 | +} |
|---|
| 653 | + |
|---|
| 483 | 654 | static int act8865_pmic_probe(struct i2c_client *client, |
|---|
| 484 | 655 | const struct i2c_device_id *i2c_id) |
|---|
| 485 | 656 | { |
|---|
| 486 | 657 | const struct regulator_desc *regulators; |
|---|
| 487 | | - struct act8865_platform_data pdata_of, *pdata; |
|---|
| 658 | + struct act8865_platform_data *pdata = NULL; |
|---|
| 488 | 659 | struct device *dev = &client->dev; |
|---|
| 489 | 660 | int i, ret, num_regulators; |
|---|
| 490 | 661 | struct act8865 *act8865; |
|---|
| .. | .. |
|---|
| 493 | 664 | int off_reg, off_mask; |
|---|
| 494 | 665 | int voltage_select = 0; |
|---|
| 495 | 666 | |
|---|
| 496 | | - pdata = dev_get_platdata(dev); |
|---|
| 497 | | - |
|---|
| 498 | | - if (dev->of_node && !pdata) { |
|---|
| 667 | + if (dev->of_node) { |
|---|
| 499 | 668 | const struct of_device_id *id; |
|---|
| 500 | 669 | |
|---|
| 501 | 670 | id = of_match_device(of_match_ptr(act8865_dt_ids), dev); |
|---|
| .. | .. |
|---|
| 509 | 678 | NULL); |
|---|
| 510 | 679 | } else { |
|---|
| 511 | 680 | type = i2c_id->driver_data; |
|---|
| 681 | + pdata = dev_get_platdata(dev); |
|---|
| 512 | 682 | } |
|---|
| 513 | 683 | |
|---|
| 514 | 684 | switch (type) { |
|---|
| .. | .. |
|---|
| 543 | 713 | return -EINVAL; |
|---|
| 544 | 714 | } |
|---|
| 545 | 715 | |
|---|
| 546 | | - if (dev->of_node && !pdata) { |
|---|
| 547 | | - ret = act8865_pdata_from_dt(dev, &pdata_of, type); |
|---|
| 548 | | - if (ret < 0) |
|---|
| 549 | | - return ret; |
|---|
| 550 | | - |
|---|
| 551 | | - pdata = &pdata_of; |
|---|
| 552 | | - } |
|---|
| 553 | | - |
|---|
| 554 | 716 | act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL); |
|---|
| 555 | 717 | if (!act8865) |
|---|
| 556 | 718 | return -ENOMEM; |
|---|
| .. | .. |
|---|
| 577 | 739 | for (i = 0; i < num_regulators; i++) { |
|---|
| 578 | 740 | const struct regulator_desc *desc = ®ulators[i]; |
|---|
| 579 | 741 | struct regulator_config config = { }; |
|---|
| 580 | | - struct act8865_regulator_data *rdata; |
|---|
| 581 | 742 | struct regulator_dev *rdev; |
|---|
| 582 | 743 | |
|---|
| 583 | 744 | config.dev = dev; |
|---|
| 584 | 745 | config.driver_data = act8865; |
|---|
| 585 | 746 | config.regmap = act8865->regmap; |
|---|
| 586 | 747 | |
|---|
| 587 | | - rdata = act8865_get_regulator_data(desc->id, pdata); |
|---|
| 588 | | - if (rdata) { |
|---|
| 589 | | - config.init_data = rdata->init_data; |
|---|
| 590 | | - config.of_node = rdata->of_node; |
|---|
| 748 | + if (pdata) { |
|---|
| 749 | + struct act8865_regulator_data *rdata; |
|---|
| 750 | + |
|---|
| 751 | + rdata = act8865_get_regulator_data(desc->id, pdata); |
|---|
| 752 | + if (rdata) { |
|---|
| 753 | + config.init_data = rdata->init_data; |
|---|
| 754 | + config.of_node = rdata->of_node; |
|---|
| 755 | + } |
|---|
| 591 | 756 | } |
|---|
| 592 | 757 | |
|---|
| 593 | 758 | rdev = devm_regulator_register(dev, desc, &config); |
|---|
| .. | .. |
|---|
| 597 | 762 | } |
|---|
| 598 | 763 | } |
|---|
| 599 | 764 | |
|---|
| 765 | + if (type == ACT8600) { |
|---|
| 766 | + ret = act8600_charger_probe(dev, act8865->regmap); |
|---|
| 767 | + if (ret < 0) { |
|---|
| 768 | + if (ret != -EPROBE_DEFER) |
|---|
| 769 | + dev_err(dev, "Failed to probe charger"); |
|---|
| 770 | + return ret; |
|---|
| 771 | + } |
|---|
| 772 | + } |
|---|
| 773 | + |
|---|
| 600 | 774 | i2c_set_clientdata(client, act8865); |
|---|
| 601 | 775 | |
|---|
| 602 | | - return 0; |
|---|
| 776 | + /* Unlock expert registers for ACT8865. */ |
|---|
| 777 | + return type != ACT8865 ? 0 : regmap_write(act8865->regmap, |
|---|
| 778 | + ACT8865_SYS_UNLK_REGS, 0xef); |
|---|
| 603 | 779 | } |
|---|
| 604 | 780 | |
|---|
| 605 | 781 | static const struct i2c_device_id act8865_ids[] = { |
|---|