Thomas Gleixner | c942fdd | 2019-05-27 08:55:06 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 2 | /* |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 3 | * act8865-regulator.c - Voltage regulation for active-semi ACT88xx PMUs |
| 4 | * |
| 5 | * http://www.active-semi.com/products/power-management-units/act88xx/ |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 6 | * |
| 7 | * Copyright (C) 2013 Atmel Corporation |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
| 12 | #include <linux/i2c.h> |
| 13 | #include <linux/err.h> |
| 14 | #include <linux/platform_device.h> |
| 15 | #include <linux/regulator/driver.h> |
| 16 | #include <linux/regulator/act8865.h> |
| 17 | #include <linux/of.h> |
| 18 | #include <linux/of_device.h> |
Maarten ter Huurne | 2d09a79 | 2019-07-22 21:14:18 -0400 | [diff] [blame] | 19 | #include <linux/power_supply.h> |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 20 | #include <linux/regulator/of_regulator.h> |
| 21 | #include <linux/regmap.h> |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 22 | #include <dt-bindings/regulator/active-semi,8865-regulator.h> |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 23 | |
| 24 | /* |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 25 | * ACT8600 Global Register Map. |
| 26 | */ |
| 27 | #define ACT8600_SYS_MODE 0x00 |
| 28 | #define ACT8600_SYS_CTRL 0x01 |
| 29 | #define ACT8600_DCDC1_VSET 0x10 |
| 30 | #define ACT8600_DCDC1_CTRL 0x12 |
| 31 | #define ACT8600_DCDC2_VSET 0x20 |
| 32 | #define ACT8600_DCDC2_CTRL 0x22 |
| 33 | #define ACT8600_DCDC3_VSET 0x30 |
| 34 | #define ACT8600_DCDC3_CTRL 0x32 |
| 35 | #define ACT8600_SUDCDC4_VSET 0x40 |
| 36 | #define ACT8600_SUDCDC4_CTRL 0x41 |
| 37 | #define ACT8600_LDO5_VSET 0x50 |
| 38 | #define ACT8600_LDO5_CTRL 0x51 |
| 39 | #define ACT8600_LDO6_VSET 0x60 |
| 40 | #define ACT8600_LDO6_CTRL 0x61 |
| 41 | #define ACT8600_LDO7_VSET 0x70 |
| 42 | #define ACT8600_LDO7_CTRL 0x71 |
| 43 | #define ACT8600_LDO8_VSET 0x80 |
| 44 | #define ACT8600_LDO8_CTRL 0x81 |
| 45 | #define ACT8600_LDO910_CTRL 0x91 |
| 46 | #define ACT8600_APCH0 0xA1 |
| 47 | #define ACT8600_APCH1 0xA8 |
| 48 | #define ACT8600_APCH2 0xA9 |
| 49 | #define ACT8600_APCH_STAT 0xAA |
| 50 | #define ACT8600_OTG0 0xB0 |
| 51 | #define ACT8600_OTG1 0xB2 |
| 52 | |
| 53 | /* |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 54 | * ACT8846 Global Register Map. |
| 55 | */ |
| 56 | #define ACT8846_SYS0 0x00 |
| 57 | #define ACT8846_SYS1 0x01 |
| 58 | #define ACT8846_REG1_VSET 0x10 |
| 59 | #define ACT8846_REG1_CTRL 0x12 |
| 60 | #define ACT8846_REG2_VSET0 0x20 |
| 61 | #define ACT8846_REG2_VSET1 0x21 |
| 62 | #define ACT8846_REG2_CTRL 0x22 |
| 63 | #define ACT8846_REG3_VSET0 0x30 |
| 64 | #define ACT8846_REG3_VSET1 0x31 |
| 65 | #define ACT8846_REG3_CTRL 0x32 |
| 66 | #define ACT8846_REG4_VSET0 0x40 |
| 67 | #define ACT8846_REG4_VSET1 0x41 |
| 68 | #define ACT8846_REG4_CTRL 0x42 |
| 69 | #define ACT8846_REG5_VSET 0x50 |
| 70 | #define ACT8846_REG5_CTRL 0x51 |
| 71 | #define ACT8846_REG6_VSET 0x58 |
| 72 | #define ACT8846_REG6_CTRL 0x59 |
| 73 | #define ACT8846_REG7_VSET 0x60 |
| 74 | #define ACT8846_REG7_CTRL 0x61 |
| 75 | #define ACT8846_REG8_VSET 0x68 |
| 76 | #define ACT8846_REG8_CTRL 0x69 |
| 77 | #define ACT8846_REG9_VSET 0x70 |
| 78 | #define ACT8846_REG9_CTRL 0x71 |
| 79 | #define ACT8846_REG10_VSET 0x80 |
| 80 | #define ACT8846_REG10_CTRL 0x81 |
| 81 | #define ACT8846_REG11_VSET 0x90 |
| 82 | #define ACT8846_REG11_CTRL 0x91 |
| 83 | #define ACT8846_REG12_VSET 0xa0 |
| 84 | #define ACT8846_REG12_CTRL 0xa1 |
| 85 | #define ACT8846_REG13_CTRL 0xb1 |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 86 | #define ACT8846_GLB_OFF_CTRL 0xc3 |
| 87 | #define ACT8846_OFF_SYSMASK 0x18 |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 88 | |
| 89 | /* |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 90 | * ACT8865 Global Register Map. |
| 91 | */ |
| 92 | #define ACT8865_SYS_MODE 0x00 |
| 93 | #define ACT8865_SYS_CTRL 0x01 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 94 | #define ACT8865_SYS_UNLK_REGS 0x0b |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 95 | #define ACT8865_DCDC1_VSET1 0x20 |
| 96 | #define ACT8865_DCDC1_VSET2 0x21 |
| 97 | #define ACT8865_DCDC1_CTRL 0x22 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 98 | #define ACT8865_DCDC1_SUS 0x24 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 99 | #define ACT8865_DCDC2_VSET1 0x30 |
| 100 | #define ACT8865_DCDC2_VSET2 0x31 |
| 101 | #define ACT8865_DCDC2_CTRL 0x32 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 102 | #define ACT8865_DCDC2_SUS 0x34 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 103 | #define ACT8865_DCDC3_VSET1 0x40 |
| 104 | #define ACT8865_DCDC3_VSET2 0x41 |
| 105 | #define ACT8865_DCDC3_CTRL 0x42 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 106 | #define ACT8865_DCDC3_SUS 0x44 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 107 | #define ACT8865_LDO1_VSET 0x50 |
| 108 | #define ACT8865_LDO1_CTRL 0x51 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 109 | #define ACT8865_LDO1_SUS 0x52 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 110 | #define ACT8865_LDO2_VSET 0x54 |
| 111 | #define ACT8865_LDO2_CTRL 0x55 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 112 | #define ACT8865_LDO2_SUS 0x56 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 113 | #define ACT8865_LDO3_VSET 0x60 |
| 114 | #define ACT8865_LDO3_CTRL 0x61 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 115 | #define ACT8865_LDO3_SUS 0x62 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 116 | #define ACT8865_LDO4_VSET 0x64 |
| 117 | #define ACT8865_LDO4_CTRL 0x65 |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 118 | #define ACT8865_LDO4_SUS 0x66 |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 119 | #define ACT8865_MSTROFF 0x20 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 120 | |
| 121 | /* |
| 122 | * Field Definitions. |
| 123 | */ |
| 124 | #define ACT8865_ENA 0x80 /* ON - [7] */ |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 125 | #define ACT8865_DIS 0x40 /* DIS - [6] */ |
| 126 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 127 | #define ACT8865_VSEL_MASK 0x3F /* VSET - [5:0] */ |
| 128 | |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 129 | |
| 130 | #define ACT8600_LDO10_ENA 0x40 /* ON - [6] */ |
| 131 | #define ACT8600_SUDCDC_VSEL_MASK 0xFF /* SUDCDC VSET - [7:0] */ |
| 132 | |
Maarten ter Huurne | 2d09a79 | 2019-07-22 21:14:18 -0400 | [diff] [blame] | 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) |
| 137 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 138 | /* |
| 139 | * ACT8865 voltage number |
| 140 | */ |
| 141 | #define ACT8865_VOLTAGE_NUM 64 |
Axel Lin | f01a7be | 2019-01-10 17:26:16 +0800 | [diff] [blame] | 142 | #define ACT8600_SUDCDC_VOLTAGE_NUM 256 |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 143 | |
| 144 | struct act8865 { |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 145 | struct regmap *regmap; |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 146 | int off_reg; |
| 147 | int off_mask; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 148 | }; |
| 149 | |
Maarten ter Huurne | c5c9c2d | 2016-03-17 15:05:08 +0100 | [diff] [blame] | 150 | static const struct regmap_range act8600_reg_ranges[] = { |
| 151 | regmap_reg_range(0x00, 0x01), |
| 152 | regmap_reg_range(0x10, 0x10), |
| 153 | regmap_reg_range(0x12, 0x12), |
| 154 | regmap_reg_range(0x20, 0x20), |
| 155 | regmap_reg_range(0x22, 0x22), |
| 156 | regmap_reg_range(0x30, 0x30), |
| 157 | regmap_reg_range(0x32, 0x32), |
| 158 | regmap_reg_range(0x40, 0x41), |
| 159 | regmap_reg_range(0x50, 0x51), |
| 160 | regmap_reg_range(0x60, 0x61), |
| 161 | regmap_reg_range(0x70, 0x71), |
| 162 | regmap_reg_range(0x80, 0x81), |
| 163 | regmap_reg_range(0x91, 0x91), |
| 164 | regmap_reg_range(0xA1, 0xA1), |
| 165 | regmap_reg_range(0xA8, 0xAA), |
| 166 | regmap_reg_range(0xB0, 0xB0), |
| 167 | regmap_reg_range(0xB2, 0xB2), |
| 168 | regmap_reg_range(0xC1, 0xC1), |
| 169 | }; |
| 170 | |
| 171 | static const struct regmap_range act8600_reg_ro_ranges[] = { |
| 172 | regmap_reg_range(0xAA, 0xAA), |
| 173 | regmap_reg_range(0xC1, 0xC1), |
| 174 | }; |
| 175 | |
| 176 | static const struct regmap_range act8600_reg_volatile_ranges[] = { |
| 177 | regmap_reg_range(0x00, 0x01), |
| 178 | regmap_reg_range(0x12, 0x12), |
| 179 | regmap_reg_range(0x22, 0x22), |
| 180 | regmap_reg_range(0x32, 0x32), |
| 181 | regmap_reg_range(0x41, 0x41), |
| 182 | regmap_reg_range(0x51, 0x51), |
| 183 | regmap_reg_range(0x61, 0x61), |
| 184 | regmap_reg_range(0x71, 0x71), |
| 185 | regmap_reg_range(0x81, 0x81), |
| 186 | regmap_reg_range(0xA8, 0xA8), |
| 187 | regmap_reg_range(0xAA, 0xAA), |
| 188 | regmap_reg_range(0xB0, 0xB0), |
| 189 | regmap_reg_range(0xC1, 0xC1), |
| 190 | }; |
| 191 | |
| 192 | static const struct regmap_access_table act8600_write_ranges_table = { |
| 193 | .yes_ranges = act8600_reg_ranges, |
| 194 | .n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges), |
| 195 | .no_ranges = act8600_reg_ro_ranges, |
| 196 | .n_no_ranges = ARRAY_SIZE(act8600_reg_ro_ranges), |
| 197 | }; |
| 198 | |
| 199 | static const struct regmap_access_table act8600_read_ranges_table = { |
| 200 | .yes_ranges = act8600_reg_ranges, |
| 201 | .n_yes_ranges = ARRAY_SIZE(act8600_reg_ranges), |
| 202 | }; |
| 203 | |
| 204 | static const struct regmap_access_table act8600_volatile_ranges_table = { |
| 205 | .yes_ranges = act8600_reg_volatile_ranges, |
| 206 | .n_yes_ranges = ARRAY_SIZE(act8600_reg_volatile_ranges), |
| 207 | }; |
| 208 | |
| 209 | static const struct regmap_config act8600_regmap_config = { |
| 210 | .reg_bits = 8, |
| 211 | .val_bits = 8, |
| 212 | .max_register = 0xFF, |
| 213 | .wr_table = &act8600_write_ranges_table, |
| 214 | .rd_table = &act8600_read_ranges_table, |
| 215 | .volatile_table = &act8600_volatile_ranges_table, |
| 216 | }; |
| 217 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 218 | static const struct regmap_config act8865_regmap_config = { |
| 219 | .reg_bits = 8, |
| 220 | .val_bits = 8, |
| 221 | }; |
| 222 | |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 223 | static const struct linear_range act8865_voltage_ranges[] = { |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 224 | REGULATOR_LINEAR_RANGE(600000, 0, 23, 25000), |
| 225 | REGULATOR_LINEAR_RANGE(1200000, 24, 47, 50000), |
| 226 | REGULATOR_LINEAR_RANGE(2400000, 48, 63, 100000), |
| 227 | }; |
| 228 | |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 229 | static const struct linear_range act8600_sudcdc_voltage_ranges[] = { |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 230 | REGULATOR_LINEAR_RANGE(3000000, 0, 63, 0), |
| 231 | REGULATOR_LINEAR_RANGE(3000000, 64, 159, 100000), |
| 232 | REGULATOR_LINEAR_RANGE(12600000, 160, 191, 200000), |
Axel Lin | f01a7be | 2019-01-10 17:26:16 +0800 | [diff] [blame] | 233 | REGULATOR_LINEAR_RANGE(19000000, 192, 247, 400000), |
| 234 | REGULATOR_LINEAR_RANGE(41400000, 248, 255, 0), |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 235 | }; |
| 236 | |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 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 | |
Axel Lin | 7cae255 | 2019-03-22 14:38:20 +0800 | [diff] [blame] | 402 | static const struct regulator_ops act8865_ops = { |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 403 | .list_voltage = regulator_list_voltage_linear_range, |
| 404 | .map_voltage = regulator_map_voltage_linear_range, |
| 405 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 406 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 407 | .enable = regulator_enable_regmap, |
| 408 | .disable = regulator_disable_regmap, |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 409 | .set_mode = act8865_set_mode, |
| 410 | .get_mode = act8865_get_mode, |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 411 | .is_enabled = regulator_is_enabled_regmap, |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 412 | .set_suspend_enable = act8865_set_suspend_enable, |
| 413 | .set_suspend_disable = act8865_set_suspend_disable, |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 414 | }; |
| 415 | |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 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, |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 423 | .set_mode = act8865_set_mode, |
| 424 | .get_mode = act8865_get_mode, |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 425 | .is_enabled = regulator_is_enabled_regmap, |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 426 | .set_suspend_enable = act8865_set_suspend_enable, |
| 427 | .set_suspend_disable = act8865_set_suspend_disable, |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 428 | .set_pull_down = regulator_set_pull_down_regmap, |
| 429 | }; |
| 430 | |
Michał Mirosław | cd81a91d | 2019-07-23 18:32:06 +0200 | [diff] [blame] | 431 | static const struct regulator_ops act8865_fixed_ldo_ops = { |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 432 | .enable = regulator_enable_regmap, |
| 433 | .disable = regulator_disable_regmap, |
| 434 | .is_enabled = regulator_is_enabled_regmap, |
| 435 | }; |
| 436 | |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 437 | #define ACT88xx_REG_(_name, _family, _id, _vsel_reg, _supply, _ops) \ |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 438 | [_family##_ID_##_id] = { \ |
| 439 | .name = _name, \ |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 440 | .of_match = of_match_ptr(_name), \ |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 441 | .of_map_mode = act8865_of_map_mode, \ |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 442 | .regulators_node = of_match_ptr("regulators"), \ |
Heiko Stuebner | c8b263c | 2015-03-07 16:33:53 +0100 | [diff] [blame] | 443 | .supply_name = _supply, \ |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 444 | .id = _family##_ID_##_id, \ |
| 445 | .type = REGULATOR_VOLTAGE, \ |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 446 | .ops = _ops, \ |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 447 | .n_voltages = ACT8865_VOLTAGE_NUM, \ |
| 448 | .linear_ranges = act8865_voltage_ranges, \ |
| 449 | .n_linear_ranges = ARRAY_SIZE(act8865_voltage_ranges), \ |
| 450 | .vsel_reg = _family##_##_id##_##_vsel_reg, \ |
| 451 | .vsel_mask = ACT8865_VSEL_MASK, \ |
| 452 | .enable_reg = _family##_##_id##_CTRL, \ |
| 453 | .enable_mask = ACT8865_ENA, \ |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 454 | .pull_down_reg = _family##_##_id##_CTRL, \ |
| 455 | .pull_down_mask = ACT8865_DIS, \ |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 456 | .owner = THIS_MODULE, \ |
| 457 | } |
| 458 | |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 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) |
| 464 | |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 465 | static const struct regulator_desc act8600_regulators[] = { |
Heiko Stuebner | c8b263c | 2015-03-07 16:33:53 +0100 | [diff] [blame] | 466 | ACT88xx_REG("DCDC1", ACT8600, DCDC1, VSET, "vp1"), |
| 467 | ACT88xx_REG("DCDC2", ACT8600, DCDC2, VSET, "vp2"), |
| 468 | ACT88xx_REG("DCDC3", ACT8600, DCDC3, VSET, "vp3"), |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 469 | { |
| 470 | .name = "SUDCDC_REG4", |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 471 | .of_match = of_match_ptr("SUDCDC_REG4"), |
| 472 | .regulators_node = of_match_ptr("regulators"), |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 473 | .id = ACT8600_ID_SUDCDC4, |
| 474 | .ops = &act8865_ops, |
| 475 | .type = REGULATOR_VOLTAGE, |
| 476 | .n_voltages = ACT8600_SUDCDC_VOLTAGE_NUM, |
| 477 | .linear_ranges = act8600_sudcdc_voltage_ranges, |
| 478 | .n_linear_ranges = ARRAY_SIZE(act8600_sudcdc_voltage_ranges), |
| 479 | .vsel_reg = ACT8600_SUDCDC4_VSET, |
| 480 | .vsel_mask = ACT8600_SUDCDC_VSEL_MASK, |
| 481 | .enable_reg = ACT8600_SUDCDC4_CTRL, |
| 482 | .enable_mask = ACT8865_ENA, |
| 483 | .owner = THIS_MODULE, |
| 484 | }, |
Heiko Stuebner | c8b263c | 2015-03-07 16:33:53 +0100 | [diff] [blame] | 485 | ACT88xx_REG("LDO5", ACT8600, LDO5, VSET, "inl"), |
| 486 | ACT88xx_REG("LDO6", ACT8600, LDO6, VSET, "inl"), |
| 487 | ACT88xx_REG("LDO7", ACT8600, LDO7, VSET, "inl"), |
| 488 | ACT88xx_REG("LDO8", ACT8600, LDO8, VSET, "inl"), |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 489 | { |
| 490 | .name = "LDO_REG9", |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 491 | .of_match = of_match_ptr("LDO_REG9"), |
| 492 | .regulators_node = of_match_ptr("regulators"), |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 493 | .id = ACT8600_ID_LDO9, |
Michał Mirosław | cd81a91d | 2019-07-23 18:32:06 +0200 | [diff] [blame] | 494 | .ops = &act8865_fixed_ldo_ops, |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 495 | .type = REGULATOR_VOLTAGE, |
| 496 | .n_voltages = 1, |
Maarten ter Huurne | 79b5d02 | 2016-02-28 16:53:28 +0100 | [diff] [blame] | 497 | .fixed_uV = 3300000, |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 498 | .enable_reg = ACT8600_LDO910_CTRL, |
| 499 | .enable_mask = ACT8865_ENA, |
| 500 | .owner = THIS_MODULE, |
| 501 | }, |
| 502 | { |
| 503 | .name = "LDO_REG10", |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 504 | .of_match = of_match_ptr("LDO_REG10"), |
| 505 | .regulators_node = of_match_ptr("regulators"), |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 506 | .id = ACT8600_ID_LDO10, |
Michał Mirosław | cd81a91d | 2019-07-23 18:32:06 +0200 | [diff] [blame] | 507 | .ops = &act8865_fixed_ldo_ops, |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 508 | .type = REGULATOR_VOLTAGE, |
| 509 | .n_voltages = 1, |
| 510 | .fixed_uV = 1200000, |
| 511 | .enable_reg = ACT8600_LDO910_CTRL, |
| 512 | .enable_mask = ACT8600_LDO10_ENA, |
| 513 | .owner = THIS_MODULE, |
| 514 | }, |
| 515 | }; |
| 516 | |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 517 | static const struct regulator_desc act8846_regulators[] = { |
Heiko Stuebner | c8b263c | 2015-03-07 16:33:53 +0100 | [diff] [blame] | 518 | ACT88xx_REG("REG1", ACT8846, REG1, VSET, "vp1"), |
| 519 | ACT88xx_REG("REG2", ACT8846, REG2, VSET0, "vp2"), |
| 520 | ACT88xx_REG("REG3", ACT8846, REG3, VSET0, "vp3"), |
| 521 | ACT88xx_REG("REG4", ACT8846, REG4, VSET0, "vp4"), |
| 522 | ACT88xx_REG("REG5", ACT8846, REG5, VSET, "inl1"), |
| 523 | ACT88xx_REG("REG6", ACT8846, REG6, VSET, "inl1"), |
| 524 | ACT88xx_REG("REG7", ACT8846, REG7, VSET, "inl1"), |
| 525 | ACT88xx_REG("REG8", ACT8846, REG8, VSET, "inl2"), |
| 526 | ACT88xx_REG("REG9", ACT8846, REG9, VSET, "inl2"), |
| 527 | ACT88xx_REG("REG10", ACT8846, REG10, VSET, "inl3"), |
| 528 | ACT88xx_REG("REG11", ACT8846, REG11, VSET, "inl3"), |
| 529 | ACT88xx_REG("REG12", ACT8846, REG12, VSET, "inl3"), |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 530 | }; |
| 531 | |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 532 | static const struct regulator_desc act8865_regulators[] = { |
Heiko Stuebner | c8b263c | 2015-03-07 16:33:53 +0100 | [diff] [blame] | 533 | ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET1, "vp1"), |
| 534 | ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET1, "vp2"), |
| 535 | ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET1, "vp3"), |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 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"), |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 540 | }; |
| 541 | |
Wenyou Yang | c86dc03 | 2015-09-30 15:25:49 +0800 | [diff] [blame] | 542 | static const struct regulator_desc act8865_alt_regulators[] = { |
| 543 | ACT88xx_REG("DCDC_REG1", ACT8865, DCDC1, VSET2, "vp1"), |
| 544 | ACT88xx_REG("DCDC_REG2", ACT8865, DCDC2, VSET2, "vp2"), |
| 545 | ACT88xx_REG("DCDC_REG3", ACT8865, DCDC3, VSET2, "vp3"), |
Michał Mirosław | a5f888c | 2019-07-23 18:32:07 +0200 | [diff] [blame] | 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"), |
Wenyou Yang | c86dc03 | 2015-09-30 15:25:49 +0800 | [diff] [blame] | 550 | }; |
| 551 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 552 | #ifdef CONFIG_OF |
| 553 | static const struct of_device_id act8865_dt_ids[] = { |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 554 | { .compatible = "active-semi,act8600", .data = (void *)ACT8600 }, |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 555 | { .compatible = "active-semi,act8846", .data = (void *)ACT8846 }, |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 556 | { .compatible = "active-semi,act8865", .data = (void *)ACT8865 }, |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 557 | { } |
| 558 | }; |
| 559 | MODULE_DEVICE_TABLE(of, act8865_dt_ids); |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 560 | #endif |
| 561 | |
Maarten ter Huurne | 005e4685 | 2016-03-17 15:05:07 +0100 | [diff] [blame] | 562 | static struct act8865_regulator_data *act8865_get_regulator_data( |
| 563 | int id, struct act8865_platform_data *pdata) |
Beniamino Galvani | 48a1e1b | 2014-06-22 17:31:41 +0200 | [diff] [blame] | 564 | { |
| 565 | int i; |
| 566 | |
Beniamino Galvani | 48a1e1b | 2014-06-22 17:31:41 +0200 | [diff] [blame] | 567 | for (i = 0; i < pdata->num_regulators; i++) { |
| 568 | if (pdata->regulators[i].id == id) |
Maarten ter Huurne | 005e4685 | 2016-03-17 15:05:07 +0100 | [diff] [blame] | 569 | return &pdata->regulators[i]; |
Beniamino Galvani | 48a1e1b | 2014-06-22 17:31:41 +0200 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | return NULL; |
| 573 | } |
| 574 | |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 575 | static struct i2c_client *act8865_i2c_client; |
| 576 | static void act8865_power_off(void) |
| 577 | { |
| 578 | struct act8865 *act8865; |
| 579 | |
| 580 | act8865 = i2c_get_clientdata(act8865_i2c_client); |
| 581 | regmap_write(act8865->regmap, act8865->off_reg, act8865->off_mask); |
| 582 | while (1); |
| 583 | } |
| 584 | |
Maarten ter Huurne | 2d09a79 | 2019-07-22 21:14:18 -0400 | [diff] [blame] | 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 | |
kbuild test robot | 1889c6e | 2019-07-24 17:22:36 +0800 | [diff] [blame] | 651 | return PTR_ERR_OR_ZERO(charger); |
Maarten ter Huurne | 2d09a79 | 2019-07-22 21:14:18 -0400 | [diff] [blame] | 652 | } |
| 653 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 654 | static int act8865_pmic_probe(struct i2c_client *client, |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 655 | const struct i2c_device_id *i2c_id) |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 656 | { |
Maarten ter Huurne | abea1bb | 2016-02-28 16:53:25 +0100 | [diff] [blame] | 657 | const struct regulator_desc *regulators; |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 658 | struct act8865_platform_data *pdata = NULL; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 659 | struct device *dev = &client->dev; |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 660 | int i, ret, num_regulators; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 661 | struct act8865 *act8865; |
Maarten ter Huurne | c5c9c2d | 2016-03-17 15:05:08 +0100 | [diff] [blame] | 662 | const struct regmap_config *regmap_config; |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 663 | unsigned long type; |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 664 | int off_reg, off_mask; |
Wenyou Yang | c86dc03 | 2015-09-30 15:25:49 +0800 | [diff] [blame] | 665 | int voltage_select = 0; |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 666 | |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 667 | if (dev->of_node) { |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 668 | const struct of_device_id *id; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 669 | |
| 670 | id = of_match_device(of_match_ptr(act8865_dt_ids), dev); |
| 671 | if (!id) |
| 672 | return -ENODEV; |
| 673 | |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 674 | type = (unsigned long) id->data; |
Wenyou Yang | c86dc03 | 2015-09-30 15:25:49 +0800 | [diff] [blame] | 675 | |
| 676 | voltage_select = !!of_get_property(dev->of_node, |
| 677 | "active-semi,vsel-high", |
| 678 | NULL); |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 679 | } else { |
| 680 | type = i2c_id->driver_data; |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 681 | pdata = dev_get_platdata(dev); |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | switch (type) { |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 685 | case ACT8600: |
| 686 | regulators = act8600_regulators; |
| 687 | num_regulators = ARRAY_SIZE(act8600_regulators); |
Maarten ter Huurne | c5c9c2d | 2016-03-17 15:05:08 +0100 | [diff] [blame] | 688 | regmap_config = &act8600_regmap_config; |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 689 | off_reg = -1; |
| 690 | off_mask = -1; |
| 691 | break; |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 692 | case ACT8846: |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 693 | regulators = act8846_regulators; |
| 694 | num_regulators = ARRAY_SIZE(act8846_regulators); |
Maarten ter Huurne | c5c9c2d | 2016-03-17 15:05:08 +0100 | [diff] [blame] | 695 | regmap_config = &act8865_regmap_config; |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 696 | off_reg = ACT8846_GLB_OFF_CTRL; |
| 697 | off_mask = ACT8846_OFF_SYSMASK; |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 698 | break; |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 699 | case ACT8865: |
Wenyou Yang | c86dc03 | 2015-09-30 15:25:49 +0800 | [diff] [blame] | 700 | if (voltage_select) { |
| 701 | regulators = act8865_alt_regulators; |
| 702 | num_regulators = ARRAY_SIZE(act8865_alt_regulators); |
| 703 | } else { |
| 704 | regulators = act8865_regulators; |
| 705 | num_regulators = ARRAY_SIZE(act8865_regulators); |
| 706 | } |
Maarten ter Huurne | c5c9c2d | 2016-03-17 15:05:08 +0100 | [diff] [blame] | 707 | regmap_config = &act8865_regmap_config; |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 708 | off_reg = ACT8865_SYS_CTRL; |
| 709 | off_mask = ACT8865_MSTROFF; |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 710 | break; |
| 711 | default: |
| 712 | dev_err(dev, "invalid device id %lu\n", type); |
| 713 | return -EINVAL; |
| 714 | } |
| 715 | |
Wenyou Yang | f1de2c2 | 2013-12-26 14:52:43 +0800 | [diff] [blame] | 716 | act8865 = devm_kzalloc(dev, sizeof(struct act8865), GFP_KERNEL); |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 717 | if (!act8865) |
| 718 | return -ENOMEM; |
| 719 | |
Maarten ter Huurne | c5c9c2d | 2016-03-17 15:05:08 +0100 | [diff] [blame] | 720 | act8865->regmap = devm_regmap_init_i2c(client, regmap_config); |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 721 | if (IS_ERR(act8865->regmap)) { |
Axel Lin | 40d3bc1 | 2014-06-30 15:32:09 +0800 | [diff] [blame] | 722 | ret = PTR_ERR(act8865->regmap); |
Maarten ter Huurne | de14ba6 | 2016-03-17 15:05:05 +0100 | [diff] [blame] | 723 | dev_err(dev, "Failed to allocate register map: %d\n", ret); |
Axel Lin | 40d3bc1 | 2014-06-30 15:32:09 +0800 | [diff] [blame] | 724 | return ret; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 725 | } |
| 726 | |
Romain Perier | 8f73110 | 2014-11-25 12:28:25 +0000 | [diff] [blame] | 727 | if (of_device_is_system_power_controller(dev->of_node)) { |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 728 | if (!pm_power_off && (off_reg > 0)) { |
Romain Perier | 2b17fa2 | 2014-10-14 06:31:10 +0000 | [diff] [blame] | 729 | act8865_i2c_client = client; |
| 730 | act8865->off_reg = off_reg; |
| 731 | act8865->off_mask = off_mask; |
| 732 | pm_power_off = act8865_power_off; |
| 733 | } else { |
| 734 | dev_err(dev, "Failed to set poweroff capability, already defined\n"); |
| 735 | } |
| 736 | } |
| 737 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 738 | /* Finally register devices */ |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 739 | for (i = 0; i < num_regulators; i++) { |
| 740 | const struct regulator_desc *desc = ®ulators[i]; |
| 741 | struct regulator_config config = { }; |
| 742 | struct regulator_dev *rdev; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 743 | |
| 744 | config.dev = dev; |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 745 | config.driver_data = act8865; |
| 746 | config.regmap = act8865->regmap; |
| 747 | |
Axel Lin | 253c9c7 | 2019-03-22 14:38:19 +0800 | [diff] [blame] | 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 | } |
Maarten ter Huurne | 005e4685 | 2016-03-17 15:05:07 +0100 | [diff] [blame] | 756 | } |
| 757 | |
Maarten ter Huurne | de14ba6 | 2016-03-17 15:05:05 +0100 | [diff] [blame] | 758 | rdev = devm_regulator_register(dev, desc, &config); |
Axel Lin | fb8eb45 | 2014-03-08 21:19:07 +0800 | [diff] [blame] | 759 | if (IS_ERR(rdev)) { |
Beniamino Galvani | 48a1e1b | 2014-06-22 17:31:41 +0200 | [diff] [blame] | 760 | dev_err(dev, "failed to register %s\n", desc->name); |
Axel Lin | fb8eb45 | 2014-03-08 21:19:07 +0800 | [diff] [blame] | 761 | return PTR_ERR(rdev); |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Maarten ter Huurne | 2d09a79 | 2019-07-22 21:14:18 -0400 | [diff] [blame] | 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 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 774 | i2c_set_clientdata(client, act8865); |
| 775 | |
Raag Jadav | 955741a | 2019-08-14 00:02:55 +0530 | [diff] [blame] | 776 | /* Unlock expert registers for ACT8865. */ |
| 777 | return type != ACT8865 ? 0 : regmap_write(act8865->regmap, |
| 778 | ACT8865_SYS_UNLK_REGS, 0xef); |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 779 | } |
| 780 | |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 781 | static const struct i2c_device_id act8865_ids[] = { |
Zubair Lutfullah Kakakhel | df3a950 | 2015-02-27 17:04:04 +0000 | [diff] [blame] | 782 | { .name = "act8600", .driver_data = ACT8600 }, |
Beniamino Galvani | ac0c0ea | 2014-07-05 15:20:55 +0200 | [diff] [blame] | 783 | { .name = "act8846", .driver_data = ACT8846 }, |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 784 | { .name = "act8865", .driver_data = ACT8865 }, |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 785 | { }, |
| 786 | }; |
| 787 | MODULE_DEVICE_TABLE(i2c, act8865_ids); |
| 788 | |
| 789 | static struct i2c_driver act8865_pmic_driver = { |
| 790 | .driver = { |
| 791 | .name = "act8865", |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 792 | }, |
| 793 | .probe = act8865_pmic_probe, |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 794 | .id_table = act8865_ids, |
| 795 | }; |
| 796 | |
| 797 | module_i2c_driver(act8865_pmic_driver); |
| 798 | |
Beniamino Galvani | 50a03e3 | 2014-07-05 15:20:54 +0200 | [diff] [blame] | 799 | MODULE_DESCRIPTION("active-semi act88xx voltage regulator driver"); |
Wenyou Yang | 33036f4 | 2013-12-24 10:34:28 +0800 | [diff] [blame] | 800 | MODULE_AUTHOR("Wenyou Yang <wenyou.yang@atmel.com>"); |
| 801 | MODULE_LICENSE("GPL v2"); |