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 | }, |
| 168 | }; |
| 169 | |
| 170 | #define SMPS_CTRL_MODE_OFF 0x00 |
| 171 | #define SMPS_CTRL_MODE_ON 0x01 |
| 172 | #define SMPS_CTRL_MODE_ECO 0x02 |
| 173 | #define SMPS_CTRL_MODE_PWM 0x03 |
| 174 | |
| 175 | /* These values are derived from the data sheet. And are the number of steps |
| 176 | * where there is a voltage change, the ranges at beginning and end of register |
| 177 | * max/min values where there are no change are ommitted. |
| 178 | * |
| 179 | * So they are basically (maxV-minV)/stepV |
| 180 | */ |
| 181 | #define PALMAS_SMPS_NUM_VOLTAGES 116 |
| 182 | #define PALMAS_SMPS10_NUM_VOLTAGES 2 |
| 183 | #define PALMAS_LDO_NUM_VOLTAGES 50 |
| 184 | |
| 185 | #define SMPS10_VSEL (1<<3) |
| 186 | #define SMPS10_BOOST_EN (1<<2) |
| 187 | #define SMPS10_BYPASS_EN (1<<1) |
| 188 | #define SMPS10_SWITCH_EN (1<<0) |
| 189 | |
| 190 | #define REGULATOR_SLAVE 0 |
| 191 | |
| 192 | static int palmas_smps_read(struct palmas *palmas, unsigned int reg, |
| 193 | unsigned int *dest) |
| 194 | { |
| 195 | unsigned int addr; |
| 196 | |
| 197 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 198 | |
| 199 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 200 | } |
| 201 | |
| 202 | static int palmas_smps_write(struct palmas *palmas, unsigned int reg, |
| 203 | unsigned int value) |
| 204 | { |
| 205 | unsigned int addr; |
| 206 | |
| 207 | addr = PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, reg); |
| 208 | |
| 209 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 210 | } |
| 211 | |
| 212 | static int palmas_ldo_read(struct palmas *palmas, unsigned int reg, |
| 213 | unsigned int *dest) |
| 214 | { |
| 215 | unsigned int addr; |
| 216 | |
| 217 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 218 | |
| 219 | return regmap_read(palmas->regmap[REGULATOR_SLAVE], addr, dest); |
| 220 | } |
| 221 | |
| 222 | static int palmas_ldo_write(struct palmas *palmas, unsigned int reg, |
| 223 | unsigned int value) |
| 224 | { |
| 225 | unsigned int addr; |
| 226 | |
| 227 | addr = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, reg); |
| 228 | |
| 229 | return regmap_write(palmas->regmap[REGULATOR_SLAVE], addr, value); |
| 230 | } |
| 231 | |
| 232 | static int palmas_is_enabled_smps(struct regulator_dev *dev) |
| 233 | { |
| 234 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 235 | int id = rdev_get_id(dev); |
| 236 | unsigned int reg; |
| 237 | |
| 238 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 239 | |
| 240 | reg &= PALMAS_SMPS12_CTRL_STATUS_MASK; |
| 241 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; |
| 242 | |
| 243 | return !!(reg); |
| 244 | } |
| 245 | |
| 246 | static int palmas_enable_smps(struct regulator_dev *dev) |
| 247 | { |
| 248 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 249 | int id = rdev_get_id(dev); |
| 250 | unsigned int reg; |
| 251 | |
| 252 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 253 | |
| 254 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 255 | reg |= SMPS_CTRL_MODE_ON; |
| 256 | |
| 257 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | static int palmas_disable_smps(struct regulator_dev *dev) |
| 263 | { |
| 264 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 265 | int id = rdev_get_id(dev); |
| 266 | unsigned int reg; |
| 267 | |
| 268 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 269 | |
| 270 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
| 271 | |
| 272 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); |
| 273 | |
| 274 | return 0; |
| 275 | } |
| 276 | |
| 277 | |
| 278 | static int palmas_set_mode_smps(struct regulator_dev *dev, unsigned int mode) |
| 279 | { |
| 280 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 281 | int id = rdev_get_id(dev); |
| 282 | unsigned int reg; |
| 283 | |
| 284 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
Axel Lin | 999f0c7 | 2012-06-07 17:08:21 +0800 | [diff] [blame] | 285 | reg &= ~PALMAS_SMPS12_CTRL_MODE_ACTIVE_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 286 | |
| 287 | switch (mode) { |
| 288 | case REGULATOR_MODE_NORMAL: |
| 289 | reg |= SMPS_CTRL_MODE_ON; |
| 290 | break; |
| 291 | case REGULATOR_MODE_IDLE: |
| 292 | reg |= SMPS_CTRL_MODE_ECO; |
| 293 | break; |
| 294 | case REGULATOR_MODE_FAST: |
| 295 | reg |= SMPS_CTRL_MODE_PWM; |
| 296 | break; |
| 297 | default: |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | palmas_smps_write(pmic->palmas, palmas_regs_info[id].ctrl_addr, reg); |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static unsigned int palmas_get_mode_smps(struct regulator_dev *dev) |
| 306 | { |
| 307 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 308 | int id = rdev_get_id(dev); |
| 309 | unsigned int reg; |
| 310 | |
| 311 | palmas_smps_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 312 | reg &= PALMAS_SMPS12_CTRL_STATUS_MASK; |
| 313 | reg >>= PALMAS_SMPS12_CTRL_STATUS_SHIFT; |
| 314 | |
| 315 | switch (reg) { |
| 316 | case SMPS_CTRL_MODE_ON: |
| 317 | return REGULATOR_MODE_NORMAL; |
| 318 | case SMPS_CTRL_MODE_ECO: |
| 319 | return REGULATOR_MODE_IDLE; |
| 320 | case SMPS_CTRL_MODE_PWM: |
| 321 | return REGULATOR_MODE_FAST; |
| 322 | } |
| 323 | |
| 324 | return 0; |
| 325 | } |
| 326 | |
| 327 | static int palmas_list_voltage_smps(struct regulator_dev *dev, |
| 328 | unsigned selector) |
| 329 | { |
| 330 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 331 | int id = rdev_get_id(dev); |
| 332 | int mult = 1; |
| 333 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 334 | /* Read the multiplier set in VSEL register to return |
| 335 | * the correct voltage. |
| 336 | */ |
| 337 | if (pmic->range[id]) |
| 338 | mult = 2; |
| 339 | |
Axel Lin | ad02e84 | 2012-11-29 09:59:16 +0800 | [diff] [blame] | 340 | if (selector == 0) |
| 341 | return 0; |
| 342 | else if (selector < 6) |
| 343 | return 500000 * mult; |
| 344 | else |
| 345 | /* Voltage is linear mapping starting from selector 6, |
| 346 | * volt = (0.49V + ((selector - 5) * 0.01V)) * RANGE |
| 347 | * RANGE is either x1 or x2 |
| 348 | */ |
| 349 | return (490000 + ((selector - 5) * 10000)) * mult; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | static int palmas_map_voltage_smps(struct regulator_dev *rdev, |
| 353 | int min_uV, int max_uV) |
| 354 | { |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 355 | struct palmas_pmic *pmic = rdev_get_drvdata(rdev); |
| 356 | int id = rdev_get_id(rdev); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 357 | int ret, voltage; |
| 358 | |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 359 | if (min_uV == 0) |
| 360 | return 0; |
| 361 | |
| 362 | if (pmic->range[id]) { /* RANGE is x2 */ |
| 363 | if (min_uV < 1000000) |
| 364 | min_uV = 1000000; |
Axel Lin | ad02e84 | 2012-11-29 09:59:16 +0800 | [diff] [blame] | 365 | ret = DIV_ROUND_UP(min_uV - 1000000, 20000) + 6; |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 366 | } else { /* RANGE is x1 */ |
| 367 | if (min_uV < 500000) |
| 368 | min_uV = 500000; |
Axel Lin | ad02e84 | 2012-11-29 09:59:16 +0800 | [diff] [blame] | 369 | ret = DIV_ROUND_UP(min_uV - 500000, 10000) + 6; |
Axel Lin | 8a165df | 2012-07-17 11:29:03 +0800 | [diff] [blame] | 370 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 371 | |
| 372 | /* Map back into a voltage to verify we're still in bounds */ |
| 373 | voltage = palmas_list_voltage_smps(rdev, ret); |
| 374 | if (voltage < min_uV || voltage > max_uV) |
| 375 | return -EINVAL; |
| 376 | |
| 377 | return ret; |
| 378 | } |
| 379 | |
| 380 | static struct regulator_ops palmas_ops_smps = { |
| 381 | .is_enabled = palmas_is_enabled_smps, |
| 382 | .enable = palmas_enable_smps, |
| 383 | .disable = palmas_disable_smps, |
| 384 | .set_mode = palmas_set_mode_smps, |
| 385 | .get_mode = palmas_get_mode_smps, |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 386 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 387 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 388 | .list_voltage = palmas_list_voltage_smps, |
| 389 | .map_voltage = palmas_map_voltage_smps, |
| 390 | }; |
| 391 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 392 | static struct regulator_ops palmas_ops_smps10 = { |
| 393 | .is_enabled = regulator_is_enabled_regmap, |
| 394 | .enable = regulator_enable_regmap, |
| 395 | .disable = regulator_disable_regmap, |
| 396 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 397 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 398 | .list_voltage = regulator_list_voltage_linear, |
| 399 | .map_voltage = regulator_map_voltage_linear, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 400 | }; |
| 401 | |
| 402 | static int palmas_is_enabled_ldo(struct regulator_dev *dev) |
| 403 | { |
| 404 | struct palmas_pmic *pmic = rdev_get_drvdata(dev); |
| 405 | int id = rdev_get_id(dev); |
| 406 | unsigned int reg; |
| 407 | |
| 408 | palmas_ldo_read(pmic->palmas, palmas_regs_info[id].ctrl_addr, ®); |
| 409 | |
| 410 | reg &= PALMAS_LDO1_CTRL_STATUS; |
| 411 | |
| 412 | return !!(reg); |
| 413 | } |
| 414 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 415 | static struct regulator_ops palmas_ops_ldo = { |
| 416 | .is_enabled = palmas_is_enabled_ldo, |
| 417 | .enable = regulator_enable_regmap, |
| 418 | .disable = regulator_disable_regmap, |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 419 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 420 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | 9119ff6 | 2012-11-27 10:27:34 +0800 | [diff] [blame] | 421 | .list_voltage = regulator_list_voltage_linear, |
| 422 | .map_voltage = regulator_map_voltage_linear, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 423 | }; |
| 424 | |
| 425 | /* |
| 426 | * setup the hardware based sleep configuration of the SMPS/LDO regulators |
| 427 | * from the platform data. This is different to the software based control |
| 428 | * supported by the regulator framework as it is controlled by toggling |
| 429 | * pins on the PMIC such as PREQ, SYSEN, ... |
| 430 | */ |
| 431 | static int palmas_smps_init(struct palmas *palmas, int id, |
| 432 | struct palmas_reg_init *reg_init) |
| 433 | { |
| 434 | unsigned int reg; |
| 435 | unsigned int addr; |
| 436 | int ret; |
| 437 | |
| 438 | addr = palmas_regs_info[id].ctrl_addr; |
| 439 | |
| 440 | ret = palmas_smps_read(palmas, addr, ®); |
| 441 | if (ret) |
| 442 | return ret; |
| 443 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 444 | switch (id) { |
| 445 | case PALMAS_REG_SMPS10: |
| 446 | if (reg_init->mode_sleep) { |
| 447 | reg &= ~PALMAS_SMPS10_CTRL_MODE_SLEEP_MASK; |
| 448 | reg |= reg_init->mode_sleep << |
| 449 | PALMAS_SMPS10_CTRL_MODE_SLEEP_SHIFT; |
| 450 | } |
| 451 | break; |
| 452 | default: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 453 | if (reg_init->warm_reset) |
| 454 | reg |= PALMAS_SMPS12_CTRL_WR_S; |
| 455 | |
| 456 | if (reg_init->roof_floor) |
| 457 | reg |= PALMAS_SMPS12_CTRL_ROOF_FLOOR_EN; |
| 458 | |
| 459 | if (reg_init->mode_sleep) { |
| 460 | reg &= ~PALMAS_SMPS12_CTRL_MODE_SLEEP_MASK; |
| 461 | reg |= reg_init->mode_sleep << |
| 462 | PALMAS_SMPS12_CTRL_MODE_SLEEP_SHIFT; |
| 463 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 464 | } |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 465 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 466 | ret = palmas_smps_write(palmas, addr, reg); |
| 467 | if (ret) |
| 468 | return ret; |
| 469 | |
| 470 | if (palmas_regs_info[id].tstep_addr && reg_init->tstep) { |
| 471 | addr = palmas_regs_info[id].tstep_addr; |
| 472 | |
| 473 | reg = reg_init->tstep & PALMAS_SMPS12_TSTEP_TSTEP_MASK; |
| 474 | |
| 475 | ret = palmas_smps_write(palmas, addr, reg); |
| 476 | if (ret) |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | if (palmas_regs_info[id].vsel_addr && reg_init->vsel) { |
| 481 | addr = palmas_regs_info[id].vsel_addr; |
| 482 | |
| 483 | reg = reg_init->vsel; |
| 484 | |
| 485 | ret = palmas_smps_write(palmas, addr, reg); |
| 486 | if (ret) |
| 487 | return ret; |
| 488 | } |
| 489 | |
| 490 | |
| 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static int palmas_ldo_init(struct palmas *palmas, int id, |
| 495 | struct palmas_reg_init *reg_init) |
| 496 | { |
| 497 | unsigned int reg; |
| 498 | unsigned int addr; |
| 499 | int ret; |
| 500 | |
| 501 | addr = palmas_regs_info[id].ctrl_addr; |
| 502 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 503 | ret = palmas_ldo_read(palmas, addr, ®); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 504 | if (ret) |
| 505 | return ret; |
| 506 | |
| 507 | if (reg_init->warm_reset) |
| 508 | reg |= PALMAS_LDO1_CTRL_WR_S; |
| 509 | |
| 510 | if (reg_init->mode_sleep) |
| 511 | reg |= PALMAS_LDO1_CTRL_MODE_SLEEP; |
| 512 | |
Axel Lin | 2735dae | 2012-07-18 12:31:59 +0800 | [diff] [blame] | 513 | ret = palmas_ldo_write(palmas, addr, reg); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 514 | if (ret) |
| 515 | return ret; |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 520 | static struct of_regulator_match palmas_matches[] = { |
| 521 | { .name = "smps12", }, |
| 522 | { .name = "smps123", }, |
| 523 | { .name = "smps3", }, |
| 524 | { .name = "smps45", }, |
| 525 | { .name = "smps457", }, |
| 526 | { .name = "smps6", }, |
| 527 | { .name = "smps7", }, |
| 528 | { .name = "smps8", }, |
| 529 | { .name = "smps9", }, |
| 530 | { .name = "smps10", }, |
| 531 | { .name = "ldo1", }, |
| 532 | { .name = "ldo2", }, |
| 533 | { .name = "ldo3", }, |
| 534 | { .name = "ldo4", }, |
| 535 | { .name = "ldo5", }, |
| 536 | { .name = "ldo6", }, |
| 537 | { .name = "ldo7", }, |
| 538 | { .name = "ldo8", }, |
| 539 | { .name = "ldo9", }, |
| 540 | { .name = "ldoln", }, |
| 541 | { .name = "ldousb", }, |
| 542 | }; |
| 543 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 544 | static void palmas_dt_to_pdata(struct device *dev, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 545 | struct device_node *node, |
| 546 | struct palmas_pmic_platform_data *pdata) |
| 547 | { |
| 548 | struct device_node *regulators; |
| 549 | u32 prop; |
| 550 | int idx, ret; |
| 551 | |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 552 | node = of_node_get(node); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 553 | regulators = of_find_node_by_name(node, "regulators"); |
| 554 | if (!regulators) { |
| 555 | dev_info(dev, "regulator node not found\n"); |
| 556 | return; |
| 557 | } |
| 558 | |
| 559 | ret = of_regulator_match(dev, regulators, palmas_matches, |
| 560 | PALMAS_NUM_REGS); |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 561 | of_node_put(regulators); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 562 | if (ret < 0) { |
| 563 | dev_err(dev, "Error parsing regulator init data: %d\n", ret); |
| 564 | return; |
| 565 | } |
| 566 | |
| 567 | for (idx = 0; idx < PALMAS_NUM_REGS; idx++) { |
| 568 | if (!palmas_matches[idx].init_data || |
| 569 | !palmas_matches[idx].of_node) |
| 570 | continue; |
| 571 | |
| 572 | pdata->reg_data[idx] = palmas_matches[idx].init_data; |
| 573 | |
| 574 | pdata->reg_init[idx] = devm_kzalloc(dev, |
| 575 | sizeof(struct palmas_reg_init), GFP_KERNEL); |
| 576 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 577 | pdata->reg_init[idx]->warm_reset = |
Axel Lin | 71f2146 | 2013-03-12 23:40:19 +0800 | [diff] [blame] | 578 | of_property_read_bool(palmas_matches[idx].of_node, |
| 579 | "ti,warm-reset"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 580 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 581 | pdata->reg_init[idx]->roof_floor = |
| 582 | of_property_read_bool(palmas_matches[idx].of_node, |
| 583 | "ti,roof-floor"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 584 | |
| 585 | ret = of_property_read_u32(palmas_matches[idx].of_node, |
J Keerthy | 3c870e3 | 2013-02-18 10:44:20 +0530 | [diff] [blame] | 586 | "ti,mode-sleep", &prop); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 587 | if (!ret) |
| 588 | pdata->reg_init[idx]->mode_sleep = prop; |
| 589 | |
| 590 | ret = of_property_read_u32(palmas_matches[idx].of_node, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 591 | "ti,tstep", &prop); |
| 592 | if (!ret) |
| 593 | pdata->reg_init[idx]->tstep = prop; |
| 594 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 595 | ret = of_property_read_bool(palmas_matches[idx].of_node, |
| 596 | "ti,smps-range"); |
| 597 | if (ret) |
| 598 | pdata->reg_init[idx]->vsel = |
| 599 | PALMAS_SMPS12_VOLTAGE_RANGE; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 600 | } |
| 601 | |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 602 | pdata->ldo6_vibrator = of_property_read_bool(node, "ti,ldo6-vibrator"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 603 | } |
| 604 | |
| 605 | |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 606 | static int palmas_regulators_probe(struct platform_device *pdev) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 607 | { |
| 608 | struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); |
| 609 | struct palmas_pmic_platform_data *pdata = pdev->dev.platform_data; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 610 | struct device_node *node = pdev->dev.of_node; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 611 | struct regulator_dev *rdev; |
| 612 | struct regulator_config config = { }; |
| 613 | struct palmas_pmic *pmic; |
| 614 | struct palmas_reg_init *reg_init; |
| 615 | int id = 0, ret; |
| 616 | unsigned int addr, reg; |
| 617 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 618 | if (node && !pdata) { |
| 619 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 620 | |
| 621 | if (!pdata) |
| 622 | return -ENOMEM; |
| 623 | |
| 624 | palmas_dt_to_pdata(&pdev->dev, node, pdata); |
| 625 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 626 | |
| 627 | pmic = devm_kzalloc(&pdev->dev, sizeof(*pmic), GFP_KERNEL); |
| 628 | if (!pmic) |
| 629 | return -ENOMEM; |
| 630 | |
| 631 | pmic->dev = &pdev->dev; |
| 632 | pmic->palmas = palmas; |
| 633 | palmas->pmic = pmic; |
| 634 | platform_set_drvdata(pdev, pmic); |
| 635 | |
| 636 | ret = palmas_smps_read(palmas, PALMAS_SMPS_CTRL, ®); |
| 637 | if (ret) |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 638 | return ret; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 639 | |
| 640 | if (reg & PALMAS_SMPS_CTRL_SMPS12_SMPS123_EN) |
| 641 | pmic->smps123 = 1; |
| 642 | |
| 643 | if (reg & PALMAS_SMPS_CTRL_SMPS45_SMPS457_EN) |
| 644 | pmic->smps457 = 1; |
| 645 | |
| 646 | config.regmap = palmas->regmap[REGULATOR_SLAVE]; |
| 647 | config.dev = &pdev->dev; |
| 648 | config.driver_data = pmic; |
| 649 | |
| 650 | for (id = 0; id < PALMAS_REG_LDO1; id++) { |
| 651 | |
| 652 | /* |
| 653 | * Miss out regulators which are not available due |
| 654 | * to slaving configurations. |
| 655 | */ |
| 656 | switch (id) { |
| 657 | case PALMAS_REG_SMPS12: |
| 658 | case PALMAS_REG_SMPS3: |
| 659 | if (pmic->smps123) |
| 660 | continue; |
| 661 | break; |
| 662 | case PALMAS_REG_SMPS123: |
| 663 | if (!pmic->smps123) |
| 664 | continue; |
| 665 | break; |
| 666 | case PALMAS_REG_SMPS45: |
| 667 | case PALMAS_REG_SMPS7: |
| 668 | if (pmic->smps457) |
| 669 | continue; |
| 670 | break; |
| 671 | case PALMAS_REG_SMPS457: |
| 672 | if (!pmic->smps457) |
| 673 | continue; |
| 674 | } |
| 675 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 676 | /* Initialise sleep/init values from platform data */ |
| 677 | if (pdata && pdata->reg_init[id]) { |
| 678 | reg_init = pdata->reg_init[id]; |
| 679 | ret = palmas_smps_init(palmas, id, reg_init); |
| 680 | if (ret) |
| 681 | goto err_unregister_regulator; |
| 682 | } |
| 683 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 684 | /* Register the regulators */ |
| 685 | pmic->desc[id].name = palmas_regs_info[id].name; |
| 686 | pmic->desc[id].id = id; |
| 687 | |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 688 | switch (id) { |
| 689 | case PALMAS_REG_SMPS10: |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 690 | pmic->desc[id].n_voltages = PALMAS_SMPS10_NUM_VOLTAGES; |
| 691 | pmic->desc[id].ops = &palmas_ops_smps10; |
Axel Lin | 12565b1 | 2012-07-18 12:31:03 +0800 | [diff] [blame] | 692 | pmic->desc[id].vsel_reg = |
| 693 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 694 | PALMAS_SMPS10_CTRL); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 695 | pmic->desc[id].vsel_mask = SMPS10_VSEL; |
Graeme Gregory | a68de07 | 2012-06-22 13:36:20 +0100 | [diff] [blame] | 696 | pmic->desc[id].enable_reg = |
| 697 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 698 | PALMAS_SMPS10_STATUS); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 699 | pmic->desc[id].enable_mask = SMPS10_BOOST_EN; |
Axel Lin | 8029a00 | 2012-05-22 12:26:42 +0800 | [diff] [blame] | 700 | pmic->desc[id].min_uV = 3750000; |
| 701 | pmic->desc[id].uV_step = 1250000; |
Axel Lin | fedd89b | 2012-06-06 20:01:38 +0800 | [diff] [blame] | 702 | break; |
| 703 | default: |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 704 | /* |
| 705 | * Read and store the RANGE bit for later use |
| 706 | * This must be done before regulator is probed, |
| 707 | * otherwise we error in probe with unsupportable ranges. |
| 708 | */ |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 709 | addr = palmas_regs_info[id].vsel_addr; |
| 710 | |
| 711 | ret = palmas_smps_read(pmic->palmas, addr, ®); |
| 712 | if (ret) |
| 713 | goto err_unregister_regulator; |
| 714 | if (reg & PALMAS_SMPS12_VOLTAGE_RANGE) |
| 715 | pmic->range[id] = 1; |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 716 | |
| 717 | pmic->desc[id].ops = &palmas_ops_smps; |
| 718 | pmic->desc[id].n_voltages = PALMAS_SMPS_NUM_VOLTAGES; |
| 719 | pmic->desc[id].vsel_reg = |
| 720 | PALMAS_BASE_TO_REG(PALMAS_SMPS_BASE, |
| 721 | palmas_regs_info[id].vsel_addr); |
| 722 | pmic->desc[id].vsel_mask = |
| 723 | PALMAS_SMPS12_VOLTAGE_VSEL_MASK; |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 724 | } |
| 725 | |
Axel Lin | bdc4baa | 2012-11-29 10:01:44 +0800 | [diff] [blame] | 726 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
| 727 | pmic->desc[id].owner = THIS_MODULE; |
| 728 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 729 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 730 | config.init_data = pdata->reg_data[id]; |
| 731 | else |
| 732 | config.init_data = NULL; |
| 733 | |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame^] | 734 | pmic->desc[id].supply_name = palmas_regs_info[id].sname; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 735 | config.of_node = palmas_matches[id].of_node; |
| 736 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 737 | rdev = regulator_register(&pmic->desc[id], &config); |
| 738 | if (IS_ERR(rdev)) { |
| 739 | dev_err(&pdev->dev, |
| 740 | "failed to register %s regulator\n", |
| 741 | pdev->name); |
| 742 | ret = PTR_ERR(rdev); |
| 743 | goto err_unregister_regulator; |
| 744 | } |
| 745 | |
| 746 | /* Save regulator for cleanup */ |
| 747 | pmic->rdev[id] = rdev; |
| 748 | } |
| 749 | |
| 750 | /* Start this loop from the id left from previous loop */ |
| 751 | for (; id < PALMAS_NUM_REGS; id++) { |
| 752 | |
| 753 | /* Miss out regulators which are not available due |
| 754 | * to alternate functions. |
| 755 | */ |
| 756 | |
| 757 | /* Register the regulators */ |
| 758 | pmic->desc[id].name = palmas_regs_info[id].name; |
| 759 | pmic->desc[id].id = id; |
| 760 | pmic->desc[id].n_voltages = PALMAS_LDO_NUM_VOLTAGES; |
| 761 | |
| 762 | pmic->desc[id].ops = &palmas_ops_ldo; |
| 763 | |
| 764 | pmic->desc[id].type = REGULATOR_VOLTAGE; |
| 765 | pmic->desc[id].owner = THIS_MODULE; |
Axel Lin | 9119ff6 | 2012-11-27 10:27:34 +0800 | [diff] [blame] | 766 | pmic->desc[id].min_uV = 900000; |
| 767 | pmic->desc[id].uV_step = 50000; |
| 768 | pmic->desc[id].linear_min_sel = 1; |
Axel Lin | 4a247a9 | 2012-07-18 12:34:08 +0800 | [diff] [blame] | 769 | pmic->desc[id].vsel_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
| 770 | palmas_regs_info[id].vsel_addr); |
| 771 | pmic->desc[id].vsel_mask = PALMAS_LDO1_VOLTAGE_VSEL_MASK; |
Graeme Gregory | a68de07 | 2012-06-22 13:36:20 +0100 | [diff] [blame] | 772 | pmic->desc[id].enable_reg = PALMAS_BASE_TO_REG(PALMAS_LDO_BASE, |
| 773 | palmas_regs_info[id].ctrl_addr); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 774 | pmic->desc[id].enable_mask = PALMAS_LDO1_CTRL_MODE_ACTIVE; |
| 775 | |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 776 | if (pdata) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 777 | config.init_data = pdata->reg_data[id]; |
| 778 | else |
| 779 | config.init_data = NULL; |
| 780 | |
Laxman Dewangan | 504382c | 2013-03-20 19:26:37 +0530 | [diff] [blame^] | 781 | pmic->desc[id].supply_name = palmas_regs_info[id].sname; |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 782 | config.of_node = palmas_matches[id].of_node; |
| 783 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 784 | rdev = regulator_register(&pmic->desc[id], &config); |
| 785 | if (IS_ERR(rdev)) { |
| 786 | dev_err(&pdev->dev, |
| 787 | "failed to register %s regulator\n", |
| 788 | pdev->name); |
| 789 | ret = PTR_ERR(rdev); |
| 790 | goto err_unregister_regulator; |
| 791 | } |
| 792 | |
| 793 | /* Save regulator for cleanup */ |
| 794 | pmic->rdev[id] = rdev; |
| 795 | |
| 796 | /* Initialise sleep/init values from platform data */ |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 797 | if (pdata) { |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 798 | reg_init = pdata->reg_init[id]; |
| 799 | if (reg_init) { |
| 800 | ret = palmas_ldo_init(palmas, id, reg_init); |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 801 | if (ret) { |
| 802 | regulator_unregister(pmic->rdev[id]); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 803 | goto err_unregister_regulator; |
Axel Lin | 1c9d2d7 | 2012-07-18 12:33:20 +0800 | [diff] [blame] | 804 | } |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 805 | } |
| 806 | } |
| 807 | } |
| 808 | |
| 809 | return 0; |
| 810 | |
| 811 | err_unregister_regulator: |
| 812 | while (--id >= 0) |
| 813 | regulator_unregister(pmic->rdev[id]); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 814 | return ret; |
| 815 | } |
| 816 | |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 817 | static int palmas_regulators_remove(struct platform_device *pdev) |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 818 | { |
| 819 | struct palmas_pmic *pmic = platform_get_drvdata(pdev); |
| 820 | int id; |
| 821 | |
| 822 | for (id = 0; id < PALMAS_NUM_REGS; id++) |
| 823 | regulator_unregister(pmic->rdev[id]); |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 824 | return 0; |
| 825 | } |
| 826 | |
Greg Kroah-Hartman | 3d68dfe | 2012-12-21 13:26:06 -0800 | [diff] [blame] | 827 | static struct of_device_id of_palmas_match_tbl[] = { |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 828 | { .compatible = "ti,palmas-pmic", }, |
Graeme Gregory | 7be859f | 2013-03-07 13:17:48 +0000 | [diff] [blame] | 829 | { .compatible = "ti,twl6035-pmic", }, |
| 830 | { .compatible = "ti,twl6036-pmic", }, |
| 831 | { .compatible = "ti,twl6037-pmic", }, |
| 832 | { .compatible = "ti,tps65913-pmic", }, |
| 833 | { .compatible = "ti,tps65914-pmic", }, |
| 834 | { .compatible = "ti,tps80036-pmic", }, |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 835 | { /* end */ } |
| 836 | }; |
| 837 | |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 838 | static struct platform_driver palmas_driver = { |
| 839 | .driver = { |
| 840 | .name = "palmas-pmic", |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 841 | .of_match_table = of_palmas_match_tbl, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 842 | .owner = THIS_MODULE, |
| 843 | }, |
Laxman Dewangan | bbcf50b | 2013-03-18 14:59:49 +0530 | [diff] [blame] | 844 | .probe = palmas_regulators_probe, |
| 845 | .remove = palmas_regulators_remove, |
Graeme Gregory | e5ce420 | 2012-05-18 16:53:57 +0100 | [diff] [blame] | 846 | }; |
| 847 | |
| 848 | static int __init palmas_init(void) |
| 849 | { |
| 850 | return platform_driver_register(&palmas_driver); |
| 851 | } |
| 852 | subsys_initcall(palmas_init); |
| 853 | |
| 854 | static void __exit palmas_exit(void) |
| 855 | { |
| 856 | platform_driver_unregister(&palmas_driver); |
| 857 | } |
| 858 | module_exit(palmas_exit); |
| 859 | |
| 860 | MODULE_AUTHOR("Graeme Gregory <gg@slimlogic.co.uk>"); |
| 861 | MODULE_DESCRIPTION("Palmas voltage regulator driver"); |
| 862 | MODULE_LICENSE("GPL"); |
| 863 | MODULE_ALIAS("platform:palmas-pmic"); |
Graeme Gregory | a361cd9 | 2012-08-28 13:47:40 +0200 | [diff] [blame] | 864 | MODULE_DEVICE_TABLE(of, of_palmas_match_tbl); |