Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Driver for Regulator part of Palmas PMIC Chips |
| 3 | * |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 4 | * Copyright 2011-2013 Texas Instruments Inc. |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 5 | * |
| 6 | * Author: Graeme Gregory <gg@slimlogic.co.uk> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/machine.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/regmap.h> |
| 24 | #include <linux/mfd/palmas.h> |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 25 | #include <linux/of.h> |
| 26 | #include <linux/of_platform.h> |
| 27 | #include <linux/regulator/of_regulator.h> |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 28 | |
| 29 | struct regs_info { |
| 30 | char *name; |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 31 | char *sname; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 32 | u8 vsel_addr; |
| 33 | u8 ctrl_addr; |
| 34 | u8 tstep_addr; |
| 35 | }; |
| 36 | |
| 37 | static const struct regs_info palmas_regs_info[] = { |
| 38 | { |
| 39 | .name = "SMPS12", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 40 | .sname = "smps1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 41 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, |
| 42 | .ctrl_addr = PALMAS_SMPS12_CTRL, |
| 43 | .tstep_addr = PALMAS_SMPS12_TSTEP, |
| 44 | }, |
| 45 | { |
| 46 | .name = "SMPS123", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 47 | .sname = "smps1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 48 | .vsel_addr = PALMAS_SMPS12_VOLTAGE, |
| 49 | .ctrl_addr = PALMAS_SMPS12_CTRL, |
| 50 | .tstep_addr = PALMAS_SMPS12_TSTEP, |
| 51 | }, |
| 52 | { |
| 53 | .name = "SMPS3", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 54 | .sname = "smps3-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 55 | .vsel_addr = PALMAS_SMPS3_VOLTAGE, |
| 56 | .ctrl_addr = PALMAS_SMPS3_CTRL, |
| 57 | }, |
| 58 | { |
| 59 | .name = "SMPS45", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 60 | .sname = "smps4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 61 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, |
| 62 | .ctrl_addr = PALMAS_SMPS45_CTRL, |
| 63 | .tstep_addr = PALMAS_SMPS45_TSTEP, |
| 64 | }, |
| 65 | { |
| 66 | .name = "SMPS457", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 67 | .sname = "smps4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 68 | .vsel_addr = PALMAS_SMPS45_VOLTAGE, |
| 69 | .ctrl_addr = PALMAS_SMPS45_CTRL, |
| 70 | .tstep_addr = PALMAS_SMPS45_TSTEP, |
| 71 | }, |
| 72 | { |
| 73 | .name = "SMPS6", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 74 | .sname = "smps6-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 75 | .vsel_addr = PALMAS_SMPS6_VOLTAGE, |
| 76 | .ctrl_addr = PALMAS_SMPS6_CTRL, |
| 77 | .tstep_addr = PALMAS_SMPS6_TSTEP, |
| 78 | }, |
| 79 | { |
| 80 | .name = "SMPS7", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 81 | .sname = "smps7-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 82 | .vsel_addr = PALMAS_SMPS7_VOLTAGE, |
| 83 | .ctrl_addr = PALMAS_SMPS7_CTRL, |
| 84 | }, |
| 85 | { |
| 86 | .name = "SMPS8", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 87 | .sname = "smps8-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 88 | .vsel_addr = PALMAS_SMPS8_VOLTAGE, |
| 89 | .ctrl_addr = PALMAS_SMPS8_CTRL, |
| 90 | .tstep_addr = PALMAS_SMPS8_TSTEP, |
| 91 | }, |
| 92 | { |
| 93 | .name = "SMPS9", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 94 | .sname = "smps9-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 95 | .vsel_addr = PALMAS_SMPS9_VOLTAGE, |
| 96 | .ctrl_addr = PALMAS_SMPS9_CTRL, |
| 97 | }, |
| 98 | { |
| 99 | .name = "SMPS10", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 100 | .sname = "smps10-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 101 | }, |
| 102 | { |
| 103 | .name = "LDO1", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 104 | .sname = "ldo1-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 105 | .vsel_addr = PALMAS_LDO1_VOLTAGE, |
| 106 | .ctrl_addr = PALMAS_LDO1_CTRL, |
| 107 | }, |
| 108 | { |
| 109 | .name = "LDO2", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 110 | .sname = "ldo2-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 111 | .vsel_addr = PALMAS_LDO2_VOLTAGE, |
| 112 | .ctrl_addr = PALMAS_LDO2_CTRL, |
| 113 | }, |
| 114 | { |
| 115 | .name = "LDO3", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 116 | .sname = "ldo3-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 117 | .vsel_addr = PALMAS_LDO3_VOLTAGE, |
| 118 | .ctrl_addr = PALMAS_LDO3_CTRL, |
| 119 | }, |
| 120 | { |
| 121 | .name = "LDO4", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 122 | .sname = "ldo4-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 123 | .vsel_addr = PALMAS_LDO4_VOLTAGE, |
| 124 | .ctrl_addr = PALMAS_LDO4_CTRL, |
| 125 | }, |
| 126 | { |
| 127 | .name = "LDO5", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 128 | .sname = "ldo5-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 129 | .vsel_addr = PALMAS_LDO5_VOLTAGE, |
| 130 | .ctrl_addr = PALMAS_LDO5_CTRL, |
| 131 | }, |
| 132 | { |
| 133 | .name = "LDO6", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 134 | .sname = "ldo6-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 135 | .vsel_addr = PALMAS_LDO6_VOLTAGE, |
| 136 | .ctrl_addr = PALMAS_LDO6_CTRL, |
| 137 | }, |
| 138 | { |
| 139 | .name = "LDO7", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 140 | .sname = "ldo7-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 141 | .vsel_addr = PALMAS_LDO7_VOLTAGE, |
| 142 | .ctrl_addr = PALMAS_LDO7_CTRL, |
| 143 | }, |
| 144 | { |
| 145 | .name = "LDO8", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 146 | .sname = "ldo8-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 147 | .vsel_addr = PALMAS_LDO8_VOLTAGE, |
| 148 | .ctrl_addr = PALMAS_LDO8_CTRL, |
| 149 | }, |
| 150 | { |
| 151 | .name = "LDO9", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 152 | .sname = "ldo9-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 153 | .vsel_addr = PALMAS_LDO9_VOLTAGE, |
| 154 | .ctrl_addr = PALMAS_LDO9_CTRL, |
| 155 | }, |
| 156 | { |
| 157 | .name = "LDOLN", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 158 | .sname = "ldoln-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 159 | .vsel_addr = PALMAS_LDOLN_VOLTAGE, |
| 160 | .ctrl_addr = PALMAS_LDOLN_CTRL, |
| 161 | }, |
| 162 | { |
| 163 | .name = "LDOUSB", |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 164 | .sname = "ldousb-in", |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 165 | .vsel_addr = PALMAS_LDOUSB_VOLTAGE, |
| 166 | .ctrl_addr = PALMAS_LDOUSB_CTRL, |
| 167 | }, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 168 | { |
| 169 | .name = "REGEN1", |
| 170 | .ctrl_addr = PALMAS_REGEN1_CTRL, |
| 171 | }, |
| 172 | { |
| 173 | .name = "REGEN2", |
| 174 | .ctrl_addr = PALMAS_REGEN2_CTRL, |
| 175 | }, |
| 176 | { |
| 177 | .name = "REGEN3", |
| 178 | .ctrl_addr = PALMAS_REGEN3_CTRL, |
| 179 | }, |
| 180 | { |
| 181 | .name = "SYSEN1", |
| 182 | .ctrl_addr = PALMAS_SYSEN1_CTRL, |
| 183 | }, |
| 184 | { |
| 185 | .name = "SYSEN2", |
| 186 | .ctrl_addr = PALMAS_SYSEN2_CTRL, |
| 187 | }, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | #define SMPS_CTRL_MODE_OFF 0x00 |
| 191 | #define SMPS_CTRL_MODE_ON 0x01 |
| 192 | #define SMPS_CTRL_MODE_ECO 0x02 |
| 193 | #define SMPS_CTRL_MODE_PWM 0x03 |
| 194 | |
| 195 | /* These values are derived from the data sheet. And are the number of steps |
| 196 | * where there is a voltage change, the ranges at beginning and end of register |
| 197 | * max/min values where there are no change are ommitted. |
| 198 | * |
| 199 | * So they are basically (maxV-minV)/stepV |
| 200 | */ |
| 201 | #define PALMAS_SMPS_NUM_VOLTAGES 116 |
| 202 | #define PALMAS_SMPS10_NUM_VOLTAGES 2 |
| 203 | #define PALMAS_LDO_NUM_VOLTAGES 50 |
| 204 | |
| 205 | #define SMPS10_VSEL (1<<3) |
| 206 | #define SMPS10_BOOST_EN (1<<2) |
| 207 | #define SMPS10_BYPASS_EN (1<<1) |
| 208 | #define SMPS10_SWITCH_EN (1<<0) |
| 209 | |
| 210 | #define REGULATOR_SLAVE 0 |
| 211 | |
| 212 | static int palmas_smps_read(struct palmas *palmas, unsigned int reg, |
| 213 | unsigned int *dest) |
| 214 | { |
| 215 | unsigned int addr; |
| 216 | |
| 217 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 218 | |
| 219 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 220 | } |
| 221 | |
| 222 | static int palmas_smps_write(struct palmas *palmas, unsigned int reg, |
| 223 | unsigned int value) |
| 224 | { |
| 225 | unsigned int addr; |
| 226 | |
| 227 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 228 | |
| 229 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 230 | } |
| 231 | |
| 232 | static int palmas_ldo_read(struct palmas *palmas, unsigned int reg, |
| 233 | unsigned int *dest) |
| 234 | { |
| 235 | unsigned int addr; |
| 236 | |
| 237 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 238 | |
| 239 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 240 | } |
| 241 | |
| 242 | static int palmas_ldo_write(struct palmas *palmas, unsigned int reg, |
| 243 | unsigned int value) |
| 244 | { |
| 245 | unsigned int addr; |
| 246 | |
| 247 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 248 | |
| 249 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 250 | } |
| 251 | |
| 252 | static int palmas_is_enabled_smps(struct regulator_dev *dev) |
| 253 | { |
| 254 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 255 | int id = rdev_get_id(dev); |
| 256 | unsigned int reg; |
| 257 | |
| 258 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 259 | |
| 260 | reg &= PALMAS_SMPS12_CTRL_STATUS_MASK; |
| 261 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; |
| 262 | |
| 263 | return !!(reg); |
| 264 | } |
| 265 | |
| 266 | static int palmas_enable_smps(struct regulator_dev *dev) |
| 267 | { |
| 268 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 269 | int id = rdev_get_id(dev); |
| 270 | unsigned int reg; |
| 271 | |
| 272 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 273 | |
| 274 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 275 | reg |= SMPS_CTRL_MODE_ON; |
| 276 | |
| 277 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static int palmas_disable_smps(struct regulator_dev *dev) |
| 283 | { |
| 284 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 285 | int id = rdev_get_id(dev); |
| 286 | unsigned int reg; |
| 287 | |
| 288 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 289 | |
| 290 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 291 | |
| 292 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | |
| 298 | static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode) |
| 299 | { |
| 300 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 301 | int id = rdev_get_id(dev); |
| 302 | unsigned int reg; |
| 303 | |
| 304 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
Axel Lin | 999f0c7 | 2012-06-07 17:08:21 +0800 | [diff] [blame] | 305 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 306 | |
| 307 | switch (mode) { |
| 308 | case REGULATOR_MODE_NORMAL: |
| 309 | reg |= SMPS_CTRL_MODE_ON; |
| 310 | break; |
| 311 | case REGULATOR_MODE_IDLE: |
| 312 | reg |= SMPS_CTRL_MODE_ECO; |
| 313 | break; |
| 314 | case REGULATOR_MODE_FAST: |
| 315 | reg |= SMPS_CTRL_MODE_PWM; |
| 316 | break; |
| 317 | default: |
| 318 | return -EINVAL; |
| 319 | } |
| 320 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); |
| 321 | |
| 322 | return 0; |
| 323 | } |
| 324 | |
| 325 | static unsigned int palmas_get_mode_smps(struct regulator_dev *dev) |
| 326 | { |
| 327 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 328 | int id = rdev_get_id(dev); |
| 329 | unsigned int reg; |
| 330 | |
| 331 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 332 | reg &= PALMAS_SMPS12_CTRL_STATUS_MASK; |
| 333 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; |
| 334 | |
| 335 | switch (reg) { |
| 336 | case SMPS_CTRL_MODE_ON: |
| 337 | return REGULATOR_MODE_NORMAL; |
| 338 | case SMPS_CTRL_MODE_ECO: |
| 339 | return REGULATOR_MODE_IDLE; |
| 340 | case SMPS_CTRL_MODE_PWM: |
| 341 | return REGULATOR_MODE_FAST; |
| 342 | } |
| 343 | |
| 344 | return 0; |
| 345 | } |
| 346 | |
| 347 | static int palmas_list_voltage_smps(struct regulator_dev *dev, |
| 348 | unsigned selector) |
| 349 | { |
| 350 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 351 | int id = rdev_get_id(dev); |
| 352 | int mult = 1; |
| 353 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 354 | /* Read the multiplier set in VSEL register to return |
| 355 | * the correct voltage. |
| 356 | */ |
| 357 | if (pmic->range[id]) |
| 358 | mult = 2; |
| 359 | |
Axel Lin | ad02e84 | 2012-11-29 09:59:16 +0800 | [diff] [blame] | 360 | if (selector == 0) |
| 361 | return 0; |
| 362 | else if (selector < 6) |
| 363 | return 500000 * mult; |
| 364 | else |
| 365 | /* Voltage is linear mapping starting from selector 6, |
| 366 | * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE |
| 367 | * RANGE is either x1 or x2 |
| 368 | */ |
| 369 | return (490000 + ((selector - 5) * 10000)) * mult; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 370 | } |
| 371 | |
| 372 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, |
| 373 | int min_uV, int max_uV) |
| 374 | { |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 375 | struct palmas_pmic *pmic = rdev_get_drvdata(rdev); |
| 376 | int id = rdev_get_id(rdev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 377 | int ret, voltage; |
| 378 | |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 379 | if (min_uV == 0) |
| 380 | return 0; |
| 381 | |
| 382 | if (pmic->range[id]) { /* RANGE is x2 */ |
| 383 | if (min_uV < 1000000) |
| 384 | min_uV = 1000000; |
Axel Lin | ad02e84 | 2012-11-29 09:59:16 +0800 | [diff] [blame] | 385 | ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6; |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 386 | } else { /* RANGE is x1 */ |
| 387 | if (min_uV < 500000) |
| 388 | min_uV = 500000; |
Axel Lin | ad02e84 | 2012-11-29 09:59:16 +0800 | [diff] [blame] | 389 | ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6; |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 390 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 391 | |
| 392 | /* Map back into a voltage to verify we're still in bounds */ |
| 393 | voltage = palmas_list_voltage_smps(rdev, ret); |
| 394 | if (voltage < min_uV || voltage > max_uV) |
| 395 | return -EINVAL; |
| 396 | |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | static struct regulator_ops palmas_ops_smps = { |
| 401 | .is_enabled = palmas_is_enabled_smps, |
| 402 | .enable = palmas_enable_smps, |
| 403 | .disable = palmas_disable_smps, |
| 404 | .set_mode = palmas_set_mode_smps, |
| 405 | .get_mode = palmas_get_mode_smps, |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 406 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 407 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 408 | .list_voltage = palmas_list_voltage_smps, |
| 409 | .map_voltage = palmas_map_voltage_smps, |
| 410 | }; |
| 411 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 412 | static struct regulator_ops palmas_ops_smps10 = { |
| 413 | .is_enabled = regulator_is_enabled_regmap, |
| 414 | .enable = regulator_enable_regmap, |
| 415 | .disable = regulator_disable_regmap, |
| 416 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 417 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 418 | .list_voltage = regulator_list_voltage_linear, |
| 419 | .map_voltage = regulator_map_voltage_linear, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 420 | }; |
| 421 | |
| 422 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) |
| 423 | { |
| 424 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 425 | int id = rdev_get_id(dev); |
| 426 | unsigned int reg; |
| 427 | |
| 428 | palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 429 | |
| 430 | reg &= PALMAS_LDO1_CTRL_STATUS; |
| 431 | |
| 432 | return !!(reg); |
| 433 | } |
| 434 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 435 | static struct regulator_ops palmas_ops_ldo = { |
| 436 | .is_enabled = palmas_is_enabled_ldo, |
| 437 | .enable = regulator_enable_regmap, |
| 438 | .disable = regulator_disable_regmap, |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 439 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 440 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 9119ff6 | 2012-11-27 10:27:34 +0800 | [diff] [blame] | 441 | .list_voltage = regulator_list_voltage_linear, |
| 442 | .map_voltage = regulator_map_voltage_linear, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 443 | }; |
| 444 | |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 445 | static struct regulator_ops palmas_ops_extreg = { |
| 446 | .is_enabled = regulator_is_enabled_regmap, |
| 447 | .enable = regulator_enable_regmap, |
| 448 | .disable = regulator_disable_regmap, |
| 449 | }; |
| 450 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 451 | /* |
| 452 | * setup the hardware based sleep configuration of the SMPS/LDO regulators |
| 453 | * from the platform data. This is different to the software based control |
| 454 | * supported by the regulator framework as it is controlled by toggling |
| 455 | * pins on the PMIC such as PREQ, SYSEN, ... |
| 456 | */ |
| 457 | static int palmas_smps_init(struct palmas *palmas, int id, |
| 458 | struct palmas_reg_init *reg_init) |
| 459 | { |
| 460 | unsigned int reg; |
| 461 | unsigned int addr; |
| 462 | int ret; |
| 463 | |
| 464 | addr = palmas_regs_info[id].ctrl_addr; |
| 465 | |
| 466 | ret = palmas_smps_read(palmas, addr, ®); |
| 467 | if (ret) |
| 468 | return ret; |
| 469 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 470 | switch (id) { |
| 471 | case PALMAS_REG_SMPS10: |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 472 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; |
| 473 | if (reg_init->mode_sleep) |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 474 | reg |= reg_init->mode_sleep << |
| 475 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 476 | break; |
| 477 | default: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 478 | if (reg_init->warm_reset) |
| 479 | reg |= PALMAS_SMPS12_CTRL_WR_S; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 480 | else |
| 481 | reg &= ~PALMAS_SMPS12_CTRL_WR_S; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 482 | |
| 483 | if (reg_init->roof_floor) |
| 484 | reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 485 | else |
| 486 | reg &= ~PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 487 | |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 488 | reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK; |
| 489 | if (reg_init->mode_sleep) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 490 | reg |= reg_init->mode_sleep << |
| 491 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 492 | } |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 493 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 494 | ret = palmas_smps_write(palmas, addr, reg); |
| 495 | if (ret) |
| 496 | return ret; |
| 497 | |
| 498 | if (palmas_regs_info[id].tstep_addr && reg_init->tstep) { |
| 499 | addr = palmas_regs_info[id].tstep_addr; |
| 500 | |
| 501 | reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK; |
| 502 | |
| 503 | ret = palmas_smps_write(palmas, addr, reg); |
| 504 | if (ret) |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | if (palmas_regs_info[id].vsel_addr && reg_init->vsel) { |
| 509 | addr = palmas_regs_info[id].vsel_addr; |
| 510 | |
| 511 | reg = reg_init->vsel; |
| 512 | |
| 513 | ret = palmas_smps_write(palmas, addr, reg); |
| 514 | if (ret) |
| 515 | return ret; |
| 516 | } |
| 517 | |
| 518 | |
| 519 | return 0; |
| 520 | } |
| 521 | |
| 522 | static int palmas_ldo_init(struct palmas *palmas, int id, |
| 523 | struct palmas_reg_init *reg_init) |
| 524 | { |
| 525 | unsigned int reg; |
| 526 | unsigned int addr; |
| 527 | int ret; |
| 528 | |
| 529 | addr = palmas_regs_info[id].ctrl_addr; |
| 530 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 531 | ret = palmas_ldo_read(palmas, addr, ®); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 532 | if (ret) |
| 533 | return ret; |
| 534 | |
| 535 | if (reg_init->warm_reset) |
| 536 | reg |= PALMAS_LDO1_CTRL_WR_S; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 537 | else |
| 538 | reg &= ~PALMAS_LDO1_CTRL_WR_S; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 539 | |
| 540 | if (reg_init->mode_sleep) |
| 541 | reg |= PALMAS_LDO1_CTRL_MODE_SLEEP; |
Laxman Dewangan | 30590d0 | 2013-04-17 15:13:11 +0530 | [diff] [blame] | 542 | else |
| 543 | reg &= ~PALMAS_LDO1_CTRL_MODE_SLEEP; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 544 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 545 | ret = palmas_ldo_write(palmas, addr, reg); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 546 | if (ret) |
| 547 | return ret; |
| 548 | |
| 549 | return 0; |
| 550 | } |
| 551 | |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 552 | static int palmas_extreg_init(struct palmas *palmas, int id, |
| 553 | struct palmas_reg_init *reg_init) |
| 554 | { |
| 555 | unsigned int addr; |
| 556 | int ret; |
| 557 | unsigned int val = 0; |
| 558 | |
| 559 | addr = palmas_regs_info[id].ctrl_addr; |
| 560 | |
| 561 | if (reg_init->mode_sleep) |
| 562 | val = PALMAS_REGEN1_CTRL_MODE_SLEEP; |
| 563 | |
| 564 | ret = palmas_update_bits(palmas, PALMAS_RESOURCE_BASE, |
| 565 | addr, PALMAS_REGEN1_CTRL_MODE_SLEEP, val); |
| 566 | if (ret < 0) { |
| 567 | dev_err(palmas->dev, "Resource reg 0x%02x update failed %d\n", |
| 568 | addr, ret); |
| 569 | return ret; |
| 570 | } |
| 571 | return 0; |
| 572 | } |
| 573 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 574 | static struct of_regulator_match palmas_matches[] = { |
| 575 | { .name = "smps12", }, |
| 576 | { .name = "smps123", }, |
| 577 | { .name = "smps3", }, |
| 578 | { .name = "smps45", }, |
| 579 | { .name = "smps457", }, |
| 580 | { .name = "smps6", }, |
| 581 | { .name = "smps7", }, |
| 582 | { .name = "smps8", }, |
| 583 | { .name = "smps9", }, |
| 584 | { .name = "smps10", }, |
| 585 | { .name = "ldo1", }, |
| 586 | { .name = "ldo2", }, |
| 587 | { .name = "ldo3", }, |
| 588 | { .name = "ldo4", }, |
| 589 | { .name = "ldo5", }, |
| 590 | { .name = "ldo6", }, |
| 591 | { .name = "ldo7", }, |
| 592 | { .name = "ldo8", }, |
| 593 | { .name = "ldo9", }, |
| 594 | { .name = "ldoln", }, |
| 595 | { .name = "ldousb", }, |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 596 | { .name = "regen1", }, |
| 597 | { .name = "regen2", }, |
| 598 | { .name = "regen3", }, |
| 599 | { .name = "sysen1", }, |
| 600 | { .name = "sysen2", }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 601 | }; |
| 602 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 603 | static void palmas_dt_to_pdata(struct device *dev, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 604 | struct device_node *node, |
| 605 | struct palmas_pmic_platform_data *pdata) |
| 606 | { |
| 607 | struct device_node *regulators; |
| 608 | u32 prop; |
| 609 | int idx, ret; |
| 610 | |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 611 | node = of_node_get(node); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 612 | regulators = of_find_node_by_name(node, "regulators"); |
| 613 | if (!regulators) { |
| 614 | dev_info(dev, "regulator node not found\n"); |
| 615 | return; |
| 616 | } |
| 617 | |
| 618 | ret = of_regulator_match(dev, regulators, palmas_matches, |
| 619 | PALMAS_NUM_REGS); |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 620 | of_node_put(regulators); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 621 | if (ret < 0) { |
| 622 | dev_err(dev, "Error parsing regulator init data: %d\n", ret); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | for (idx = 0; idx < PALMAS_NUM_REGS; idx++) { |
| 627 | if (!palmas_matches[idx].init_data || |
| 628 | !palmas_matches[idx].of_node) |
| 629 | continue; |
| 630 | |
| 631 | pdata->reg_data[idx] = palmas_matches[idx].init_data; |
| 632 | |
| 633 | pdata->reg_init[idx] = devm_kzalloc(dev, |
| 634 | sizeof(struct palmas_reg_init), GFP_KERNEL); |
| 635 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 636 | pdata->reg_init[idx]->warm_reset = |
Axel Lin | 71f2146 | 2013-03-12 23:40:19 +0800 | [diff] [blame] | 637 | of_property_read_bool(palmas_matches[idx].of_node, |
| 638 | "ti,warm-reset"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 639 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 640 | pdata->reg_init[idx]->roof_floor = |
| 641 | of_property_read_bool(palmas_matches[idx].of_node, |
| 642 | "ti,roof-floor"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 643 | |
| 644 | ret = of_property_read_u32(palmas_matches[idx].of_node, |
J Keerthy | 3c870e3 | 2013-02-18 10:44:20 +0530 | [diff] [blame] | 645 | "ti,mode-sleep", &prop); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 646 | if (!ret) |
| 647 | pdata->reg_init[idx]->mode_sleep = prop; |
| 648 | |
| 649 | ret = of_property_read_u32(palmas_matches[idx].of_node, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 650 | "ti,tstep", &prop); |
| 651 | if (!ret) |
| 652 | pdata->reg_init[idx]->tstep = prop; |
| 653 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 654 | ret = of_property_read_bool(palmas_matches[idx].of_node, |
| 655 | "ti,smps-range"); |
| 656 | if (ret) |
| 657 | pdata->reg_init[idx]->vsel = |
| 658 | PALMAS_SMPS12_VOLTAGE_RANGE; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 659 | } |
| 660 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 661 | pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 662 | } |
| 663 | |
| 664 | |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 665 | static int palmas_regulators_probe(struct platform_device *pdev) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 666 | { |
| 667 | struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); |
| 668 | struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 669 | struct device_node *node = pdev->dev.of_node; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 670 | struct regulator_dev *rdev; |
| 671 | struct regulator_config config = { }; |
| 672 | struct palmas_pmic *pmic; |
| 673 | struct palmas_reg_init *reg_init; |
| 674 | int id = 0, ret; |
| 675 | unsigned int addr, reg; |
| 676 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 677 | if (node && !pdata) { |
| 678 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 679 | |
| 680 | if (!pdata) |
| 681 | return -ENOMEM; |
| 682 | |
| 683 | palmas_dt_to_pdata(&pdev->dev, node, pdata); |
| 684 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 685 | |
| 686 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
| 687 | if (!pmic) |
| 688 | return -ENOMEM; |
| 689 | |
| 690 | pmic->dev = &pdev->dev; |
| 691 | pmic->palmas = palmas; |
| 692 | palmas->pmic = pmic; |
| 693 | platform_set_drvdata(pdev, pmic); |
| 694 | |
| 695 | ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, ®); |
| 696 | if (ret) |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 697 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 698 | |
| 699 | if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) |
| 700 | pmic->smps123 = 1; |
| 701 | |
| 702 | if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN) |
| 703 | pmic->smps457 = 1; |
| 704 | |
| 705 | config.regmap = palmas->regmap[REGULATOR_SLAVE]; |
| 706 | config.dev = &pdev->dev; |
| 707 | config.driver_data = pmic; |
| 708 | |
| 709 | for (id = 0; id < PALMAS_REG_LDO1; id++) { |
| 710 | |
| 711 | /* |
| 712 | * Miss out regulators which are not available due |
| 713 | * to slaving configurations. |
| 714 | */ |
| 715 | switch (id) { |
| 716 | case PALMAS_REG_SMPS12: |
| 717 | case PALMAS_REG_SMPS3: |
| 718 | if (pmic->smps123) |
| 719 | continue; |
| 720 | break; |
| 721 | case PALMAS_REG_SMPS123: |
| 722 | if (!pmic->smps123) |
| 723 | continue; |
| 724 | break; |
| 725 | case PALMAS_REG_SMPS45: |
| 726 | case PALMAS_REG_SMPS7: |
| 727 | if (pmic->smps457) |
| 728 | continue; |
| 729 | break; |
| 730 | case PALMAS_REG_SMPS457: |
| 731 | if (!pmic->smps457) |
| 732 | continue; |
| 733 | } |
| 734 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 735 | /* Initialise sleep/init values from platform data */ |
| 736 | if (pdata && pdata->reg_init[id]) { |
| 737 | reg_init = pdata->reg_init[id]; |
| 738 | ret = palmas_smps_init(palmas, id, reg_init); |
| 739 | if (ret) |
| 740 | goto err_unregister_regulator; |
| 741 | } |
| 742 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 743 | /* Register the regulators */ |
| 744 | pmic->desc[id].name = palmas_regs_info[id].name; |
| 745 | pmic->desc[id].id = id; |
| 746 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 747 | switch (id) { |
| 748 | case PALMAS_REG_SMPS10: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 749 | pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; |
| 750 | pmic->desc[id].ops = &palmas_ops_smps10; |
Axel Lin | 12565b1 | 2012-07-18 12:31:03 +0800 | [diff] [blame] | 751 | pmic->desc[id].vsel_reg = |
| 752 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 753 | PALMAS_SMPS10_CTRL); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 754 | pmic->desc[id].vsel_mask = SMPS10_VSEL; |
Graeme Gregory | a68de07 | 2012-06-22 13:36:20 +0100 | [diff] [blame] | 755 | pmic->desc[id].enable_reg = |
| 756 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 757 | PALMAS_SMPS10_STATUS); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 758 | pmic->desc[id].enable_mask = SMPS10_BOOST_EN; |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 759 | pmic->desc[id].min_uV = 3750000; |
| 760 | pmic->desc[id].uV_step = 1250000; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 761 | break; |
| 762 | default: |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 763 | /* |
| 764 | * Read and store the RANGE bit for later use |
| 765 | * This must be done before regulator is probed, |
| 766 | * otherwise we error in probe with unsupportable ranges. |
| 767 | */ |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 768 | addr = palmas_regs_info[id].vsel_addr; |
| 769 | |
| 770 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 771 | if (ret) |
| 772 | goto err_unregister_regulator; |
| 773 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) |
| 774 | pmic->range[id] = 1; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 775 | |
| 776 | pmic->desc[id].ops = &palmas_ops_smps; |
| 777 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; |
| 778 | pmic->desc[id].vsel_reg = |
| 779 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 780 | palmas_regs_info[id].vsel_addr); |
| 781 | pmic->desc[id].vsel_mask = |
| 782 | PALMAS_SMPS12_VOLTAGE_VSEL_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 783 | } |
| 784 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 785 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
| 786 | pmic->desc[id].owner = THIS_MODULE; |
| 787 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 788 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 789 | config.init_data = pdata->reg_data[id]; |
| 790 | else |
| 791 | config.init_data = NULL; |
| 792 | |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 793 | pmic->desc[id].supply_name = palmas_regs_info[id].sname; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 794 | config.of_node = palmas_matches[id].of_node; |
| 795 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 796 | rdev = regulator_register(&pmic->desc[id], &config); |
| 797 | if (IS_ERR(rdev)) { |
| 798 | dev_err(&pdev->dev, |
| 799 | "failed to register %s regulator\n", |
| 800 | pdev->name); |
| 801 | ret = PTR_ERR(rdev); |
| 802 | goto err_unregister_regulator; |
| 803 | } |
| 804 | |
| 805 | /* Save regulator for cleanup */ |
| 806 | pmic->rdev[id] = rdev; |
| 807 | } |
| 808 | |
| 809 | /* Start this loop from the id left from previous loop */ |
| 810 | for (; id < PALMAS_NUM_REGS; id++) { |
| 811 | |
| 812 | /* Miss out regulators which are not available due |
| 813 | * to alternate functions. |
| 814 | */ |
| 815 | |
| 816 | /* Register the regulators */ |
| 817 | pmic->desc[id].name = palmas_regs_info[id].name; |
| 818 | pmic->desc[id].id = id; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 819 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
| 820 | pmic->desc[id].owner = THIS_MODULE; |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 821 | |
| 822 | if (id < PALMAS_REG_REGEN1) { |
| 823 | pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES; |
| 824 | pmic->desc[id].ops = &palmas_ops_ldo; |
| 825 | pmic->desc[id].min_uV = 900000; |
| 826 | pmic->desc[id].uV_step = 50000; |
| 827 | pmic->desc[id].linear_min_sel = 1; |
| 828 | pmic->desc[id].vsel_reg = |
| 829 | PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 830 | palmas_regs_info[id].vsel_addr); |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 831 | pmic->desc[id].vsel_mask = |
| 832 | PALMAS_LDO1_VOLTAGE_VSEL_MASK; |
| 833 | pmic->desc[id].enable_reg = |
| 834 | PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
Graeme Gregory | a68de07 | 2012-06-22 13:36:20 +0100 | [diff] [blame] | 835 | palmas_regs_info[id].ctrl_addr); |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 836 | pmic->desc[id].enable_mask = |
| 837 | PALMAS_LDO1_CTRL_MODE_ACTIVE; |
| 838 | } else { |
| 839 | pmic->desc[id].n_voltages = 1; |
| 840 | pmic->desc[id].ops = &palmas_ops_extreg; |
| 841 | pmic->desc[id].enable_reg = |
| 842 | PALMAS_BASE_TO_REG(PALMAS_RESOURCE_BASE, |
| 843 | palmas_regs_info[id].ctrl_addr); |
| 844 | pmic->desc[id].enable_mask = |
| 845 | PALMAS_REGEN1_CTRL_MODE_ACTIVE; |
| 846 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 847 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 848 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 849 | config.init_data = pdata->reg_data[id]; |
| 850 | else |
| 851 | config.init_data = NULL; |
| 852 | |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame] | 853 | pmic->desc[id].supply_name = palmas_regs_info[id].sname; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 854 | config.of_node = palmas_matches[id].of_node; |
| 855 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 856 | rdev = regulator_register(&pmic->desc[id], &config); |
| 857 | if (IS_ERR(rdev)) { |
| 858 | dev_err(&pdev->dev, |
| 859 | "failed to register %s regulator\n", |
| 860 | pdev->name); |
| 861 | ret = PTR_ERR(rdev); |
| 862 | goto err_unregister_regulator; |
| 863 | } |
| 864 | |
| 865 | /* Save regulator for cleanup */ |
| 866 | pmic->rdev[id] = rdev; |
| 867 | |
| 868 | /* Initialise sleep/init values from platform data */ |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 869 | if (pdata) { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 870 | reg_init = pdata->reg_init[id]; |
| 871 | if (reg_init) { |
Laxman Dewangan | aa07f02 | 2013-04-17 15:13:12 +0530 | [diff] [blame^] | 872 | if (id < PALMAS_REG_REGEN1) |
| 873 | ret = palmas_ldo_init(palmas, |
| 874 | id, reg_init); |
| 875 | else |
| 876 | ret = palmas_extreg_init(palmas, |
| 877 | id, reg_init); |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 878 | if (ret) { |
| 879 | regulator_unregister(pmic->rdev[id]); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 880 | goto err_unregister_regulator; |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 881 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | return 0; |
| 887 | |
| 888 | err_unregister_regulator: |
| 889 | while (--id >= 0) |
| 890 | regulator_unregister(pmic->rdev[id]); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 891 | return ret; |
| 892 | } |
| 893 | |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 894 | static int palmas_regulators_remove(struct platform_device *pdev) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 895 | { |
| 896 | struct palmas_pmic *pmic = platform_get_drvdata(pdev); |
| 897 | int id; |
| 898 | |
| 899 | for (id = 0; id < PALMAS_NUM_REGS; id++) |
| 900 | regulator_unregister(pmic->rdev[id]); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 901 | return 0; |
| 902 | } |
| 903 | |
Greg Kroah-Hartman | 3d68dfe | 2012-12-21 13:26:06 -0800 | [diff] [blame] | 904 | static struct of_device_id of_palmas_match_tbl[] = { |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 905 | { .compatible = "ti,palmas-pmic", }, |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 906 | { .compatible = "ti,twl6035-pmic", }, |
| 907 | { .compatible = "ti,twl6036-pmic", }, |
| 908 | { .compatible = "ti,twl6037-pmic", }, |
| 909 | { .compatible = "ti,tps65913-pmic", }, |
| 910 | { .compatible = "ti,tps65914-pmic", }, |
| 911 | { .compatible = "ti,tps80036-pmic", }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 912 | { /* end */ } |
| 913 | }; |
| 914 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 915 | static struct platform_driver palmas_driver = { |
| 916 | .driver = { |
| 917 | .name = "palmas-pmic", |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 918 | .of_match_table = of_palmas_match_tbl, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 919 | .owner = THIS_MODULE, |
| 920 | }, |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 921 | .probe = palmas_regulators_probe, |
| 922 | .remove = palmas_regulators_remove, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 923 | }; |
| 924 | |
| 925 | static int __init palmas_init(void) |
| 926 | { |
| 927 | return platform_driver_register(&palmas_driver); |
| 928 | } |
| 929 | subsys_initcall(palmas_init); |
| 930 | |
| 931 | static void __exit palmas_exit(void) |
| 932 | { |
| 933 | platform_driver_unregister(&palmas_driver); |
| 934 | } |
| 935 | module_exit(palmas_exit); |
| 936 | |
| 937 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
| 938 | MODULE_DESCRIPTION("Palmas voltage regulator driver"); |
| 939 | MODULE_LICENSE("GPL"); |
| 940 | MODULE_ALIAS("platform:palmas-pmic"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 941 | MODULE_DEVICE_TABLE(of, of_palmas_match_tbl); |