Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* |
Amy Maloche | 4c994c9 | 2012-02-15 09:56:15 -0800 | [diff] [blame] | 2 | * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | */ |
| 13 | |
| 14 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 15 | |
| 16 | #include <linux/kernel.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 17 | #include <linux/module.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 18 | #include <linux/slab.h> |
| 19 | #include <linux/spinlock.h> |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | #include <linux/platform_device.h> |
Anirudh Ghayal | 1fd48c6 | 2011-12-13 12:39:43 +0530 | [diff] [blame] | 22 | #include <linux/delay.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <linux/mfd/pm8xxx/core.h> |
| 24 | #include <linux/mfd/pm8xxx/misc.h> |
| 25 | |
| 26 | /* PON CTRL 1 register */ |
Anirudh Ghayal | a23c1ca | 2011-11-01 14:36:24 +0530 | [diff] [blame] | 27 | #define REG_PM8XXX_PON_CTRL_1 0x01C |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | |
| 29 | #define PON_CTRL_1_PULL_UP_MASK 0xE0 |
| 30 | #define PON_CTRL_1_USB_PWR_EN 0x10 |
| 31 | |
| 32 | #define PON_CTRL_1_WD_EN_MASK 0x08 |
| 33 | #define PON_CTRL_1_WD_EN_RESET 0x08 |
| 34 | #define PON_CTRL_1_WD_EN_PWR_OFF 0x00 |
| 35 | |
Anirudh Ghayal | a4262a3 | 2011-11-10 00:02:18 +0530 | [diff] [blame] | 36 | /* PON CNTL registers */ |
| 37 | #define REG_PM8058_PON_CNTL_4 0x098 |
| 38 | #define REG_PM8901_PON_CNTL_4 0x099 |
| 39 | #define REG_PM8018_PON_CNTL_4 0x01E |
| 40 | #define REG_PM8921_PON_CNTL_4 0x01E |
| 41 | #define REG_PM8058_PON_CNTL_5 0x07B |
| 42 | #define REG_PM8901_PON_CNTL_5 0x09A |
| 43 | #define REG_PM8018_PON_CNTL_5 0x01F |
| 44 | #define REG_PM8921_PON_CNTL_5 0x01F |
| 45 | |
| 46 | #define PON_CTRL_4_RESET_EN_MASK 0x01 |
| 47 | #define PON_CTRL_4_SHUTDOWN_ON_RESET 0x0 |
| 48 | #define PON_CTRL_4_RESTART_ON_RESET 0x1 |
| 49 | #define PON_CTRL_5_HARD_RESET_EN_MASK 0x08 |
| 50 | #define PON_CTRL_5_HARD_RESET_EN 0x08 |
| 51 | #define PON_CTRL_5_HARD_RESET_DIS 0x00 |
| 52 | |
Anirudh Ghayal | 9e1bd64 | 2011-11-01 13:57:40 +0530 | [diff] [blame] | 53 | /* Regulator master enable addresses */ |
| 54 | #define REG_PM8058_VREG_EN_MSM 0x018 |
| 55 | #define REG_PM8058_VREG_EN_GRP_5_4 0x1C8 |
| 56 | |
| 57 | /* Regulator control registers for shutdown/reset */ |
| 58 | #define REG_PM8058_S0_CTRL 0x004 |
| 59 | #define REG_PM8058_S1_CTRL 0x005 |
| 60 | #define REG_PM8058_S3_CTRL 0x111 |
| 61 | #define REG_PM8058_L21_CTRL 0x120 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 62 | #define REG_PM8058_L22_CTRL 0x121 |
| 63 | |
Anirudh Ghayal | 9e1bd64 | 2011-11-01 13:57:40 +0530 | [diff] [blame] | 64 | #define PM8058_REGULATOR_ENABLE_MASK 0x80 |
| 65 | #define PM8058_REGULATOR_ENABLE 0x80 |
| 66 | #define PM8058_REGULATOR_DISABLE 0x00 |
| 67 | #define PM8058_REGULATOR_PULL_DOWN_MASK 0x40 |
| 68 | #define PM8058_REGULATOR_PULL_DOWN_EN 0x40 |
| 69 | |
| 70 | /* Buck CTRL register */ |
| 71 | #define PM8058_SMPS_LEGACY_VREF_SEL 0x20 |
| 72 | #define PM8058_SMPS_LEGACY_VPROG_MASK 0x1F |
| 73 | #define PM8058_SMPS_ADVANCED_BAND_MASK 0xC0 |
| 74 | #define PM8058_SMPS_ADVANCED_BAND_SHIFT 6 |
| 75 | #define PM8058_SMPS_ADVANCED_VPROG_MASK 0x3F |
| 76 | |
| 77 | /* Buck TEST2 registers for shutdown/reset */ |
| 78 | #define REG_PM8058_S0_TEST2 0x084 |
| 79 | #define REG_PM8058_S1_TEST2 0x085 |
| 80 | #define REG_PM8058_S3_TEST2 0x11A |
| 81 | |
| 82 | #define PM8058_REGULATOR_BANK_WRITE 0x80 |
| 83 | #define PM8058_REGULATOR_BANK_MASK 0x70 |
| 84 | #define PM8058_REGULATOR_BANK_SHIFT 4 |
| 85 | #define PM8058_REGULATOR_BANK_SEL(n) ((n) << PM8058_REGULATOR_BANK_SHIFT) |
| 86 | |
| 87 | /* Buck TEST2 register bank 1 */ |
| 88 | #define PM8058_SMPS_LEGACY_VLOW_SEL 0x01 |
| 89 | |
| 90 | /* Buck TEST2 register bank 7 */ |
| 91 | #define PM8058_SMPS_ADVANCED_MODE_MASK 0x02 |
| 92 | #define PM8058_SMPS_ADVANCED_MODE 0x02 |
| 93 | #define PM8058_SMPS_LEGACY_MODE 0x00 |
| 94 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 95 | /* SLEEP CTRL register */ |
| 96 | #define REG_PM8058_SLEEP_CTRL 0x02B |
| 97 | #define REG_PM8921_SLEEP_CTRL 0x10A |
Jay Chokshi | 86580f2 | 2011-10-17 12:27:52 -0700 | [diff] [blame] | 98 | #define REG_PM8018_SLEEP_CTRL 0x10A |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 99 | |
| 100 | #define SLEEP_CTRL_SMPL_EN_MASK 0x04 |
| 101 | #define SLEEP_CTRL_SMPL_EN_RESET 0x04 |
| 102 | #define SLEEP_CTRL_SMPL_EN_PWR_OFF 0x00 |
| 103 | |
Anirudh Ghayal | bfbaf82 | 2011-11-01 14:28:34 +0530 | [diff] [blame] | 104 | #define SLEEP_CTRL_SMPL_SEL_MASK 0x03 |
| 105 | #define SLEEP_CTRL_SMPL_SEL_MIN 0 |
| 106 | #define SLEEP_CTRL_SMPL_SEL_MAX 3 |
| 107 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | /* FTS regulator PMR registers */ |
| 109 | #define REG_PM8901_REGULATOR_S1_PMR 0xA7 |
| 110 | #define REG_PM8901_REGULATOR_S2_PMR 0xA8 |
| 111 | #define REG_PM8901_REGULATOR_S3_PMR 0xA9 |
| 112 | #define REG_PM8901_REGULATOR_S4_PMR 0xAA |
| 113 | |
| 114 | #define PM8901_REGULATOR_PMR_STATE_MASK 0x60 |
| 115 | #define PM8901_REGULATOR_PMR_STATE_OFF 0x20 |
| 116 | |
Anirudh Ghayal | 7b38229 | 2011-11-01 14:08:34 +0530 | [diff] [blame] | 117 | /* COINCELL CHG registers */ |
| 118 | #define REG_PM8058_COIN_CHG 0x02F |
| 119 | #define REG_PM8921_COIN_CHG 0x09C |
| 120 | #define REG_PM8018_COIN_CHG 0x09C |
| 121 | |
| 122 | #define COINCELL_RESISTOR_SHIFT 0x2 |
| 123 | |
Anirudh Ghayal | 51e947f | 2011-11-01 14:49:45 +0530 | [diff] [blame] | 124 | /* GP TEST register */ |
| 125 | #define REG_PM8XXX_GP_TEST_1 0x07A |
| 126 | |
| 127 | /* Stay on configuration */ |
| 128 | #define PM8XXX_STAY_ON_CFG 0x92 |
| 129 | |
Anirudh Ghayal | 5213eb8 | 2011-10-24 14:44:58 +0530 | [diff] [blame] | 130 | /* GPIO UART MUX CTRL registers */ |
| 131 | #define REG_PM8XXX_GPIO_MUX_CTRL 0x1CC |
| 132 | |
| 133 | #define UART_PATH_SEL_MASK 0x60 |
| 134 | #define UART_PATH_SEL_SHIFT 0x5 |
| 135 | |
Willie Ruan | 5db1f24 | 2012-01-30 22:08:04 -0800 | [diff] [blame] | 136 | #define USB_ID_PU_EN_MASK 0x10 /* PM8921 family only */ |
| 137 | #define USB_ID_PU_EN_SHIFT 4 |
| 138 | |
Anirudh Ghayal | 1fd48c6 | 2011-12-13 12:39:43 +0530 | [diff] [blame] | 139 | /* Shutdown/restart delays to allow for LDO 7/dVdd regulator load settling. */ |
| 140 | #define PM8901_DELAY_AFTER_REG_DISABLE_MS 4 |
| 141 | #define PM8901_DELAY_BEFORE_SHUTDOWN_MS 8 |
| 142 | |
Amy Maloche | 4c994c9 | 2012-02-15 09:56:15 -0800 | [diff] [blame] | 143 | #define REG_PM8XXX_XO_CNTRL_2 0x114 |
| 144 | #define MP3_1_MASK 0xE0 |
| 145 | #define MP3_2_MASK 0x1C |
| 146 | #define MP3_1_SHIFT 5 |
| 147 | #define MP3_2_SHIFT 2 |
| 148 | |
Anirudh Ghayal | ba4ea6e | 2012-05-09 15:59:28 +0530 | [diff] [blame] | 149 | #define REG_HSED_BIAS0_CNTL2 0xA1 |
| 150 | #define REG_HSED_BIAS1_CNTL2 0x135 |
| 151 | #define REG_HSED_BIAS2_CNTL2 0x138 |
| 152 | #define HSED_EN_MASK 0xC0 |
| 153 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 154 | struct pm8xxx_misc_chip { |
| 155 | struct list_head link; |
| 156 | struct pm8xxx_misc_platform_data pdata; |
| 157 | struct device *dev; |
| 158 | enum pm8xxx_version version; |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 159 | u64 osc_halt_count; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static LIST_HEAD(pm8xxx_misc_chips); |
| 163 | static DEFINE_SPINLOCK(pm8xxx_misc_chips_lock); |
| 164 | |
| 165 | static int pm8xxx_misc_masked_write(struct pm8xxx_misc_chip *chip, u16 addr, |
| 166 | u8 mask, u8 val) |
| 167 | { |
| 168 | int rc; |
| 169 | u8 reg; |
| 170 | |
| 171 | rc = pm8xxx_readb(chip->dev->parent, addr, ®); |
| 172 | if (rc) { |
| 173 | pr_err("pm8xxx_readb(0x%03X) failed, rc=%d\n", addr, rc); |
| 174 | return rc; |
| 175 | } |
| 176 | reg &= ~mask; |
| 177 | reg |= val & mask; |
| 178 | rc = pm8xxx_writeb(chip->dev->parent, addr, reg); |
| 179 | if (rc) |
| 180 | pr_err("pm8xxx_writeb(0x%03X)=0x%02X failed, rc=%d\n", addr, |
| 181 | reg, rc); |
| 182 | return rc; |
| 183 | } |
| 184 | |
Anirudh Ghayal | 9e1bd64 | 2011-11-01 13:57:40 +0530 | [diff] [blame] | 185 | /* |
| 186 | * Set an SMPS regulator to be disabled in its CTRL register, but enabled |
| 187 | * in the master enable register. Also set it's pull down enable bit. |
| 188 | * Take care to make sure that the output voltage doesn't change if switching |
| 189 | * from advanced mode to legacy mode. |
| 190 | */ |
| 191 | static int |
| 192 | __pm8058_disable_smps_locally_set_pull_down(struct pm8xxx_misc_chip *chip, |
| 193 | u16 ctrl_addr, u16 test2_addr, u16 master_enable_addr, |
| 194 | u8 master_enable_bit) |
| 195 | { |
| 196 | int rc = 0; |
| 197 | u8 vref_sel, vlow_sel, band, vprog, bank, reg; |
| 198 | |
| 199 | bank = PM8058_REGULATOR_BANK_SEL(7); |
| 200 | rc = pm8xxx_writeb(chip->dev->parent, test2_addr, bank); |
| 201 | if (rc) { |
| 202 | pr_err("%s: pm8xxx_writeb(0x%03X) failed: rc=%d\n", __func__, |
| 203 | test2_addr, rc); |
| 204 | goto done; |
| 205 | } |
| 206 | |
| 207 | rc = pm8xxx_readb(chip->dev->parent, test2_addr, ®); |
| 208 | if (rc) { |
| 209 | pr_err("%s: FAIL pm8xxx_readb(0x%03X): rc=%d\n", |
| 210 | __func__, test2_addr, rc); |
| 211 | goto done; |
| 212 | } |
| 213 | |
| 214 | /* Check if in advanced mode. */ |
| 215 | if ((reg & PM8058_SMPS_ADVANCED_MODE_MASK) == |
| 216 | PM8058_SMPS_ADVANCED_MODE) { |
| 217 | /* Determine current output voltage. */ |
| 218 | rc = pm8xxx_readb(chip->dev->parent, ctrl_addr, ®); |
| 219 | if (rc) { |
| 220 | pr_err("%s: FAIL pm8xxx_readb(0x%03X): rc=%d\n", |
| 221 | __func__, ctrl_addr, rc); |
| 222 | goto done; |
| 223 | } |
| 224 | |
| 225 | band = (reg & PM8058_SMPS_ADVANCED_BAND_MASK) |
| 226 | >> PM8058_SMPS_ADVANCED_BAND_SHIFT; |
| 227 | switch (band) { |
| 228 | case 3: |
| 229 | vref_sel = 0; |
| 230 | vlow_sel = 0; |
| 231 | break; |
| 232 | case 2: |
| 233 | vref_sel = PM8058_SMPS_LEGACY_VREF_SEL; |
| 234 | vlow_sel = 0; |
| 235 | break; |
| 236 | case 1: |
| 237 | vref_sel = PM8058_SMPS_LEGACY_VREF_SEL; |
| 238 | vlow_sel = PM8058_SMPS_LEGACY_VLOW_SEL; |
| 239 | break; |
| 240 | default: |
| 241 | pr_err("%s: regulator already disabled\n", __func__); |
| 242 | return -EPERM; |
| 243 | } |
| 244 | vprog = (reg & PM8058_SMPS_ADVANCED_VPROG_MASK); |
| 245 | /* Round up if fine step is in use. */ |
| 246 | vprog = (vprog + 1) >> 1; |
| 247 | if (vprog > PM8058_SMPS_LEGACY_VPROG_MASK) |
| 248 | vprog = PM8058_SMPS_LEGACY_VPROG_MASK; |
| 249 | |
| 250 | /* Set VLOW_SEL bit. */ |
| 251 | bank = PM8058_REGULATOR_BANK_SEL(1); |
| 252 | rc = pm8xxx_writeb(chip->dev->parent, test2_addr, bank); |
| 253 | if (rc) { |
| 254 | pr_err("%s: FAIL pm8xxx_writeb(0x%03X): rc=%d\n", |
| 255 | __func__, test2_addr, rc); |
| 256 | goto done; |
| 257 | } |
| 258 | |
| 259 | rc = pm8xxx_misc_masked_write(chip, test2_addr, |
| 260 | PM8058_REGULATOR_BANK_WRITE | PM8058_REGULATOR_BANK_MASK |
| 261 | | PM8058_SMPS_LEGACY_VLOW_SEL, |
| 262 | PM8058_REGULATOR_BANK_WRITE | |
| 263 | PM8058_REGULATOR_BANK_SEL(1) | vlow_sel); |
| 264 | if (rc) |
| 265 | goto done; |
| 266 | |
| 267 | /* Switch to legacy mode */ |
| 268 | bank = PM8058_REGULATOR_BANK_SEL(7); |
| 269 | rc = pm8xxx_writeb(chip->dev->parent, test2_addr, bank); |
| 270 | if (rc) { |
| 271 | pr_err("%s: FAIL pm8xxx_writeb(0x%03X): rc=%d\n", |
| 272 | __func__, test2_addr, rc); |
| 273 | goto done; |
| 274 | } |
| 275 | rc = pm8xxx_misc_masked_write(chip, test2_addr, |
| 276 | PM8058_REGULATOR_BANK_WRITE | |
| 277 | PM8058_REGULATOR_BANK_MASK | |
| 278 | PM8058_SMPS_ADVANCED_MODE_MASK, |
| 279 | PM8058_REGULATOR_BANK_WRITE | |
| 280 | PM8058_REGULATOR_BANK_SEL(7) | |
| 281 | PM8058_SMPS_LEGACY_MODE); |
| 282 | if (rc) |
| 283 | goto done; |
| 284 | |
| 285 | /* Enable locally, enable pull down, keep voltage the same. */ |
| 286 | rc = pm8xxx_misc_masked_write(chip, ctrl_addr, |
| 287 | PM8058_REGULATOR_ENABLE_MASK | |
| 288 | PM8058_REGULATOR_PULL_DOWN_MASK | |
| 289 | PM8058_SMPS_LEGACY_VREF_SEL | |
| 290 | PM8058_SMPS_LEGACY_VPROG_MASK, |
| 291 | PM8058_REGULATOR_ENABLE | PM8058_REGULATOR_PULL_DOWN_EN |
| 292 | | vref_sel | vprog); |
| 293 | if (rc) |
| 294 | goto done; |
| 295 | } |
| 296 | |
| 297 | /* Enable in master control register. */ |
| 298 | rc = pm8xxx_misc_masked_write(chip, master_enable_addr, |
| 299 | master_enable_bit, master_enable_bit); |
| 300 | if (rc) |
| 301 | goto done; |
| 302 | |
| 303 | /* Disable locally and enable pull down. */ |
| 304 | rc = pm8xxx_misc_masked_write(chip, ctrl_addr, |
| 305 | PM8058_REGULATOR_ENABLE_MASK | PM8058_REGULATOR_PULL_DOWN_MASK, |
| 306 | PM8058_REGULATOR_DISABLE | PM8058_REGULATOR_PULL_DOWN_EN); |
| 307 | |
| 308 | done: |
| 309 | return rc; |
| 310 | } |
| 311 | |
| 312 | static int |
| 313 | __pm8058_disable_ldo_locally_set_pull_down(struct pm8xxx_misc_chip *chip, |
| 314 | u16 ctrl_addr, u16 master_enable_addr, u8 master_enable_bit) |
| 315 | { |
| 316 | int rc; |
| 317 | |
| 318 | /* Enable LDO in master control register. */ |
| 319 | rc = pm8xxx_misc_masked_write(chip, master_enable_addr, |
| 320 | master_enable_bit, master_enable_bit); |
| 321 | if (rc) |
| 322 | goto done; |
| 323 | |
| 324 | /* Disable LDO in CTRL register and set pull down */ |
| 325 | rc = pm8xxx_misc_masked_write(chip, ctrl_addr, |
| 326 | PM8058_REGULATOR_ENABLE_MASK | PM8058_REGULATOR_PULL_DOWN_MASK, |
| 327 | PM8058_REGULATOR_DISABLE | PM8058_REGULATOR_PULL_DOWN_EN); |
| 328 | |
| 329 | done: |
| 330 | return rc; |
| 331 | } |
| 332 | |
Jay Chokshi | 86580f2 | 2011-10-17 12:27:52 -0700 | [diff] [blame] | 333 | static int __pm8018_reset_pwr_off(struct pm8xxx_misc_chip *chip, int reset) |
| 334 | { |
| 335 | int rc; |
| 336 | |
| 337 | /* Enable SMPL if resetting is desired. */ |
| 338 | rc = pm8xxx_misc_masked_write(chip, REG_PM8018_SLEEP_CTRL, |
| 339 | SLEEP_CTRL_SMPL_EN_MASK, |
| 340 | (reset ? SLEEP_CTRL_SMPL_EN_RESET : SLEEP_CTRL_SMPL_EN_PWR_OFF)); |
| 341 | if (rc) { |
| 342 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 343 | return rc; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Select action to perform (reset or shutdown) when PS_HOLD goes low. |
| 348 | * Also ensure that KPD, CBL0, and CBL1 pull ups are enabled and that |
| 349 | * USB charging is enabled. |
| 350 | */ |
Anirudh Ghayal | a23c1ca | 2011-11-01 14:36:24 +0530 | [diff] [blame] | 351 | rc = pm8xxx_misc_masked_write(chip, REG_PM8XXX_PON_CTRL_1, |
Jay Chokshi | 86580f2 | 2011-10-17 12:27:52 -0700 | [diff] [blame] | 352 | PON_CTRL_1_PULL_UP_MASK | PON_CTRL_1_USB_PWR_EN |
| 353 | | PON_CTRL_1_WD_EN_MASK, |
| 354 | PON_CTRL_1_PULL_UP_MASK | PON_CTRL_1_USB_PWR_EN |
| 355 | | (reset ? PON_CTRL_1_WD_EN_RESET : PON_CTRL_1_WD_EN_PWR_OFF)); |
| 356 | if (rc) |
| 357 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 358 | |
| 359 | return rc; |
| 360 | } |
| 361 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 362 | static int __pm8058_reset_pwr_off(struct pm8xxx_misc_chip *chip, int reset) |
| 363 | { |
| 364 | int rc; |
| 365 | |
Anirudh Ghayal | 9e1bd64 | 2011-11-01 13:57:40 +0530 | [diff] [blame] | 366 | /* When shutting down, enable active pulldowns on important rails. */ |
| 367 | if (!reset) { |
| 368 | /* Disable SMPS's 0,1,3 locally and set pulldown enable bits. */ |
| 369 | __pm8058_disable_smps_locally_set_pull_down(chip, |
| 370 | REG_PM8058_S0_CTRL, REG_PM8058_S0_TEST2, |
| 371 | REG_PM8058_VREG_EN_MSM, BIT(7)); |
| 372 | __pm8058_disable_smps_locally_set_pull_down(chip, |
| 373 | REG_PM8058_S1_CTRL, REG_PM8058_S1_TEST2, |
| 374 | REG_PM8058_VREG_EN_MSM, BIT(6)); |
| 375 | __pm8058_disable_smps_locally_set_pull_down(chip, |
| 376 | REG_PM8058_S3_CTRL, REG_PM8058_S3_TEST2, |
| 377 | REG_PM8058_VREG_EN_GRP_5_4, BIT(7) | BIT(4)); |
| 378 | /* Disable LDO 21 locally and set pulldown enable bit. */ |
| 379 | __pm8058_disable_ldo_locally_set_pull_down(chip, |
| 380 | REG_PM8058_L21_CTRL, REG_PM8058_VREG_EN_GRP_5_4, |
| 381 | BIT(1)); |
| 382 | } |
| 383 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 384 | /* |
| 385 | * Fix-up: Set regulator LDO22 to 1.225 V in high power mode. Leave its |
| 386 | * pull-down state intact. This ensures a safe shutdown. |
| 387 | */ |
| 388 | rc = pm8xxx_misc_masked_write(chip, REG_PM8058_L22_CTRL, 0xBF, 0x93); |
| 389 | if (rc) { |
| 390 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 391 | goto read_write_err; |
| 392 | } |
| 393 | |
| 394 | /* Enable SMPL if resetting is desired. */ |
| 395 | rc = pm8xxx_misc_masked_write(chip, REG_PM8058_SLEEP_CTRL, |
| 396 | SLEEP_CTRL_SMPL_EN_MASK, |
| 397 | (reset ? SLEEP_CTRL_SMPL_EN_RESET : SLEEP_CTRL_SMPL_EN_PWR_OFF)); |
| 398 | if (rc) { |
| 399 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 400 | goto read_write_err; |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Select action to perform (reset or shutdown) when PS_HOLD goes low. |
| 405 | * Also ensure that KPD, CBL0, and CBL1 pull ups are enabled and that |
| 406 | * USB charging is enabled. |
| 407 | */ |
Anirudh Ghayal | a23c1ca | 2011-11-01 14:36:24 +0530 | [diff] [blame] | 408 | rc = pm8xxx_misc_masked_write(chip, REG_PM8XXX_PON_CTRL_1, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 409 | PON_CTRL_1_PULL_UP_MASK | PON_CTRL_1_USB_PWR_EN |
| 410 | | PON_CTRL_1_WD_EN_MASK, |
| 411 | PON_CTRL_1_PULL_UP_MASK | PON_CTRL_1_USB_PWR_EN |
| 412 | | (reset ? PON_CTRL_1_WD_EN_RESET : PON_CTRL_1_WD_EN_PWR_OFF)); |
| 413 | if (rc) { |
| 414 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 415 | goto read_write_err; |
| 416 | } |
| 417 | |
| 418 | read_write_err: |
| 419 | return rc; |
| 420 | } |
| 421 | |
| 422 | static int __pm8901_reset_pwr_off(struct pm8xxx_misc_chip *chip, int reset) |
| 423 | { |
| 424 | int rc = 0, i; |
| 425 | u8 pmr_addr[4] = { |
| 426 | REG_PM8901_REGULATOR_S2_PMR, |
| 427 | REG_PM8901_REGULATOR_S3_PMR, |
| 428 | REG_PM8901_REGULATOR_S4_PMR, |
| 429 | REG_PM8901_REGULATOR_S1_PMR, |
| 430 | }; |
| 431 | |
| 432 | /* Fix-up: Turn off regulators S1, S2, S3, S4 when shutting down. */ |
| 433 | if (!reset) { |
| 434 | for (i = 0; i < 4; i++) { |
| 435 | rc = pm8xxx_misc_masked_write(chip, pmr_addr[i], |
| 436 | PM8901_REGULATOR_PMR_STATE_MASK, |
| 437 | PM8901_REGULATOR_PMR_STATE_OFF); |
| 438 | if (rc) { |
| 439 | pr_err("pm8xxx_misc_masked_write failed, " |
| 440 | "rc=%d\n", rc); |
| 441 | goto read_write_err; |
| 442 | } |
Anirudh Ghayal | 1fd48c6 | 2011-12-13 12:39:43 +0530 | [diff] [blame] | 443 | mdelay(PM8901_DELAY_AFTER_REG_DISABLE_MS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 444 | } |
| 445 | } |
| 446 | |
| 447 | read_write_err: |
Anirudh Ghayal | 1fd48c6 | 2011-12-13 12:39:43 +0530 | [diff] [blame] | 448 | mdelay(PM8901_DELAY_BEFORE_SHUTDOWN_MS); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 449 | return rc; |
| 450 | } |
| 451 | |
| 452 | static int __pm8921_reset_pwr_off(struct pm8xxx_misc_chip *chip, int reset) |
| 453 | { |
| 454 | int rc; |
| 455 | |
| 456 | /* Enable SMPL if resetting is desired. */ |
| 457 | rc = pm8xxx_misc_masked_write(chip, REG_PM8921_SLEEP_CTRL, |
| 458 | SLEEP_CTRL_SMPL_EN_MASK, |
| 459 | (reset ? SLEEP_CTRL_SMPL_EN_RESET : SLEEP_CTRL_SMPL_EN_PWR_OFF)); |
| 460 | if (rc) { |
| 461 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 462 | goto read_write_err; |
| 463 | } |
| 464 | |
| 465 | /* |
| 466 | * Select action to perform (reset or shutdown) when PS_HOLD goes low. |
| 467 | * Also ensure that KPD, CBL0, and CBL1 pull ups are enabled and that |
| 468 | * USB charging is enabled. |
| 469 | */ |
Anirudh Ghayal | a23c1ca | 2011-11-01 14:36:24 +0530 | [diff] [blame] | 470 | rc = pm8xxx_misc_masked_write(chip, REG_PM8XXX_PON_CTRL_1, |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 471 | PON_CTRL_1_PULL_UP_MASK | PON_CTRL_1_USB_PWR_EN |
| 472 | | PON_CTRL_1_WD_EN_MASK, |
| 473 | PON_CTRL_1_PULL_UP_MASK | PON_CTRL_1_USB_PWR_EN |
| 474 | | (reset ? PON_CTRL_1_WD_EN_RESET : PON_CTRL_1_WD_EN_PWR_OFF)); |
| 475 | if (rc) { |
| 476 | pr_err("pm8xxx_misc_masked_write failed, rc=%d\n", rc); |
| 477 | goto read_write_err; |
| 478 | } |
| 479 | |
| 480 | read_write_err: |
| 481 | return rc; |
| 482 | } |
| 483 | |
| 484 | /** |
| 485 | * pm8xxx_reset_pwr_off - switch all PM8XXX PMIC chips attached to the system to |
| 486 | * either reset or shutdown when they are turned off |
| 487 | * @reset: 0 = shudown the PMICs, 1 = shutdown and then restart the PMICs |
| 488 | * |
| 489 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 490 | */ |
| 491 | int pm8xxx_reset_pwr_off(int reset) |
| 492 | { |
| 493 | struct pm8xxx_misc_chip *chip; |
| 494 | unsigned long flags; |
| 495 | int rc = 0; |
| 496 | |
| 497 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 498 | |
| 499 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 500 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 501 | switch (chip->version) { |
Jay Chokshi | 86580f2 | 2011-10-17 12:27:52 -0700 | [diff] [blame] | 502 | case PM8XXX_VERSION_8018: |
| 503 | rc = __pm8018_reset_pwr_off(chip, reset); |
| 504 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 505 | case PM8XXX_VERSION_8058: |
| 506 | rc = __pm8058_reset_pwr_off(chip, reset); |
| 507 | break; |
| 508 | case PM8XXX_VERSION_8901: |
| 509 | rc = __pm8901_reset_pwr_off(chip, reset); |
| 510 | break; |
David Keitel | 4256483 | 2012-05-02 13:58:02 -0700 | [diff] [blame] | 511 | case PM8XXX_VERSION_8038: |
| 512 | case PM8XXX_VERSION_8917: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 513 | case PM8XXX_VERSION_8921: |
| 514 | rc = __pm8921_reset_pwr_off(chip, reset); |
| 515 | break; |
| 516 | default: |
| 517 | /* PMIC doesn't have reset_pwr_off; do nothing. */ |
| 518 | break; |
| 519 | } |
| 520 | if (rc) { |
| 521 | pr_err("reset_pwr_off failed, rc=%d\n", rc); |
| 522 | break; |
| 523 | } |
| 524 | } |
| 525 | |
| 526 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 527 | |
| 528 | return rc; |
| 529 | } |
| 530 | EXPORT_SYMBOL_GPL(pm8xxx_reset_pwr_off); |
| 531 | |
Anirudh Ghayal | 7b38229 | 2011-11-01 14:08:34 +0530 | [diff] [blame] | 532 | /** |
Anirudh Ghayal | bfbaf82 | 2011-11-01 14:28:34 +0530 | [diff] [blame] | 533 | * pm8xxx_smpl_control - enables/disables SMPL detection |
| 534 | * @enable: 0 = shutdown PMIC on power loss, 1 = reset PMIC on power loss |
| 535 | * |
| 536 | * This function enables or disables the Sudden Momentary Power Loss detection |
| 537 | * module. If SMPL detection is enabled, then when a sufficiently long power |
| 538 | * loss event occurs, the PMIC will automatically reset itself. If SMPL |
| 539 | * detection is disabled, then the PMIC will shutdown when power loss occurs. |
| 540 | * |
| 541 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 542 | */ |
| 543 | int pm8xxx_smpl_control(int enable) |
| 544 | { |
| 545 | struct pm8xxx_misc_chip *chip; |
| 546 | unsigned long flags; |
| 547 | int rc = 0; |
| 548 | |
| 549 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 550 | |
| 551 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 552 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 553 | switch (chip->version) { |
| 554 | case PM8XXX_VERSION_8018: |
| 555 | rc = pm8xxx_misc_masked_write(chip, |
| 556 | REG_PM8018_SLEEP_CTRL, SLEEP_CTRL_SMPL_EN_MASK, |
David Collins | c06e0d6 | 2012-02-13 14:42:09 -0800 | [diff] [blame] | 557 | (enable ? SLEEP_CTRL_SMPL_EN_RESET |
Anirudh Ghayal | bfbaf82 | 2011-11-01 14:28:34 +0530 | [diff] [blame] | 558 | : SLEEP_CTRL_SMPL_EN_PWR_OFF)); |
| 559 | break; |
| 560 | case PM8XXX_VERSION_8058: |
| 561 | rc = pm8xxx_misc_masked_write(chip, |
| 562 | REG_PM8058_SLEEP_CTRL, SLEEP_CTRL_SMPL_EN_MASK, |
| 563 | (enable ? SLEEP_CTRL_SMPL_EN_RESET |
| 564 | : SLEEP_CTRL_SMPL_EN_PWR_OFF)); |
| 565 | break; |
| 566 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 567 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | bfbaf82 | 2011-11-01 14:28:34 +0530 | [diff] [blame] | 568 | rc = pm8xxx_misc_masked_write(chip, |
| 569 | REG_PM8921_SLEEP_CTRL, SLEEP_CTRL_SMPL_EN_MASK, |
David Collins | c06e0d6 | 2012-02-13 14:42:09 -0800 | [diff] [blame] | 570 | (enable ? SLEEP_CTRL_SMPL_EN_RESET |
Anirudh Ghayal | bfbaf82 | 2011-11-01 14:28:34 +0530 | [diff] [blame] | 571 | : SLEEP_CTRL_SMPL_EN_PWR_OFF)); |
| 572 | break; |
| 573 | default: |
| 574 | /* PMIC doesn't have reset_pwr_off; do nothing. */ |
| 575 | break; |
| 576 | } |
| 577 | if (rc) { |
| 578 | pr_err("setting smpl control failed, rc=%d\n", rc); |
| 579 | break; |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 584 | |
| 585 | return rc; |
| 586 | } |
| 587 | EXPORT_SYMBOL(pm8xxx_smpl_control); |
| 588 | |
| 589 | |
| 590 | /** |
| 591 | * pm8xxx_smpl_set_delay - sets the SMPL detection time delay |
| 592 | * @delay: enum value corresponding to delay time |
| 593 | * |
| 594 | * This function sets the time delay of the SMPL detection module. If power |
| 595 | * is reapplied within this interval, then the PMIC reset automatically. The |
| 596 | * SMPL detection module must be enabled for this delay time to take effect. |
| 597 | * |
| 598 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 599 | */ |
| 600 | int pm8xxx_smpl_set_delay(enum pm8xxx_smpl_delay delay) |
| 601 | { |
| 602 | struct pm8xxx_misc_chip *chip; |
| 603 | unsigned long flags; |
| 604 | int rc = 0; |
| 605 | |
| 606 | if (delay < SLEEP_CTRL_SMPL_SEL_MIN |
| 607 | || delay > SLEEP_CTRL_SMPL_SEL_MAX) { |
| 608 | pr_err("%s: invalid delay specified: %d\n", __func__, delay); |
| 609 | return -EINVAL; |
| 610 | } |
| 611 | |
| 612 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 613 | |
| 614 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 615 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 616 | switch (chip->version) { |
| 617 | case PM8XXX_VERSION_8018: |
| 618 | rc = pm8xxx_misc_masked_write(chip, |
| 619 | REG_PM8018_SLEEP_CTRL, SLEEP_CTRL_SMPL_SEL_MASK, |
| 620 | delay); |
| 621 | break; |
| 622 | case PM8XXX_VERSION_8058: |
| 623 | rc = pm8xxx_misc_masked_write(chip, |
| 624 | REG_PM8058_SLEEP_CTRL, SLEEP_CTRL_SMPL_SEL_MASK, |
| 625 | delay); |
| 626 | break; |
| 627 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 628 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | bfbaf82 | 2011-11-01 14:28:34 +0530 | [diff] [blame] | 629 | rc = pm8xxx_misc_masked_write(chip, |
| 630 | REG_PM8921_SLEEP_CTRL, SLEEP_CTRL_SMPL_SEL_MASK, |
| 631 | delay); |
| 632 | break; |
| 633 | default: |
| 634 | /* PMIC doesn't have reset_pwr_off; do nothing. */ |
| 635 | break; |
| 636 | } |
| 637 | if (rc) { |
| 638 | pr_err("setting smpl delay failed, rc=%d\n", rc); |
| 639 | break; |
| 640 | } |
| 641 | } |
| 642 | |
| 643 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 644 | |
| 645 | return rc; |
| 646 | } |
| 647 | EXPORT_SYMBOL(pm8xxx_smpl_set_delay); |
| 648 | |
| 649 | /** |
Anirudh Ghayal | 7b38229 | 2011-11-01 14:08:34 +0530 | [diff] [blame] | 650 | * pm8xxx_coincell_chg_config - Disables or enables the coincell charger, and |
| 651 | * configures its voltage and resistor settings. |
| 652 | * @chg_config: Holds both voltage and resistor values, and a |
| 653 | * switch to change the state of charger. |
| 654 | * If state is to disable the charger then |
| 655 | * both voltage and resistor are disregarded. |
| 656 | * |
| 657 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 658 | */ |
| 659 | int pm8xxx_coincell_chg_config(struct pm8xxx_coincell_chg *chg_config) |
| 660 | { |
| 661 | struct pm8xxx_misc_chip *chip; |
| 662 | unsigned long flags; |
| 663 | u8 reg = 0, voltage, resistor; |
| 664 | int rc = 0; |
| 665 | |
| 666 | if (chg_config == NULL) { |
| 667 | pr_err("chg_config is NULL\n"); |
| 668 | return -EINVAL; |
| 669 | } |
| 670 | |
| 671 | voltage = chg_config->voltage; |
| 672 | resistor = chg_config->resistor; |
| 673 | |
Willie Ruan | 243f495 | 2012-11-15 16:17:29 -0800 | [diff] [blame] | 674 | if (resistor > PM8XXX_COINCELL_RESISTOR_800_OHMS) { |
Anirudh Ghayal | 7b38229 | 2011-11-01 14:08:34 +0530 | [diff] [blame] | 675 | pr_err("Invalid resistor value provided\n"); |
| 676 | return -EINVAL; |
| 677 | } |
| 678 | |
| 679 | if (voltage < PM8XXX_COINCELL_VOLTAGE_3p2V || |
| 680 | (voltage > PM8XXX_COINCELL_VOLTAGE_3p0V && |
| 681 | voltage != PM8XXX_COINCELL_VOLTAGE_2p5V)) { |
| 682 | pr_err("Invalid voltage value provided\n"); |
| 683 | return -EINVAL; |
| 684 | } |
| 685 | |
| 686 | if (chg_config->state == PM8XXX_COINCELL_CHG_DISABLE) { |
| 687 | reg = 0; |
| 688 | } else { |
| 689 | reg |= voltage; |
| 690 | reg |= (resistor << COINCELL_RESISTOR_SHIFT); |
| 691 | } |
| 692 | |
| 693 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 694 | |
| 695 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 696 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 697 | switch (chip->version) { |
| 698 | case PM8XXX_VERSION_8018: |
| 699 | rc = pm8xxx_writeb(chip->dev->parent, |
| 700 | REG_PM8018_COIN_CHG, reg); |
| 701 | break; |
| 702 | case PM8XXX_VERSION_8058: |
| 703 | rc = pm8xxx_writeb(chip->dev->parent, |
| 704 | REG_PM8058_COIN_CHG, reg); |
| 705 | break; |
| 706 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 707 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | 7b38229 | 2011-11-01 14:08:34 +0530 | [diff] [blame] | 708 | rc = pm8xxx_writeb(chip->dev->parent, |
| 709 | REG_PM8921_COIN_CHG, reg); |
| 710 | break; |
| 711 | default: |
| 712 | /* PMIC doesn't have reset_pwr_off; do nothing. */ |
| 713 | break; |
| 714 | } |
| 715 | if (rc) { |
| 716 | pr_err("coincell chg. config failed, rc=%d\n", rc); |
| 717 | break; |
| 718 | } |
| 719 | } |
| 720 | |
| 721 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 722 | |
| 723 | return rc; |
| 724 | } |
| 725 | EXPORT_SYMBOL(pm8xxx_coincell_chg_config); |
| 726 | |
Anirudh Ghayal | a23c1ca | 2011-11-01 14:36:24 +0530 | [diff] [blame] | 727 | /** |
| 728 | * pm8xxx_watchdog_reset_control - enables/disables watchdog reset detection |
| 729 | * @enable: 0 = shutdown when PS_HOLD goes low, 1 = reset when PS_HOLD goes low |
| 730 | * |
| 731 | * This function enables or disables the PMIC watchdog reset detection feature. |
| 732 | * If watchdog reset detection is enabled, then the PMIC will reset itself |
| 733 | * when PS_HOLD goes low. If it is not enabled, then the PMIC will shutdown |
| 734 | * when PS_HOLD goes low. |
| 735 | * |
| 736 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 737 | */ |
| 738 | int pm8xxx_watchdog_reset_control(int enable) |
| 739 | { |
| 740 | struct pm8xxx_misc_chip *chip; |
| 741 | unsigned long flags; |
| 742 | int rc = 0; |
| 743 | |
| 744 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 745 | |
| 746 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 747 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 748 | switch (chip->version) { |
| 749 | case PM8XXX_VERSION_8018: |
| 750 | case PM8XXX_VERSION_8058: |
| 751 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 752 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | a23c1ca | 2011-11-01 14:36:24 +0530 | [diff] [blame] | 753 | rc = pm8xxx_misc_masked_write(chip, |
| 754 | REG_PM8XXX_PON_CTRL_1, PON_CTRL_1_WD_EN_MASK, |
| 755 | (enable ? PON_CTRL_1_WD_EN_RESET |
| 756 | : PON_CTRL_1_WD_EN_PWR_OFF)); |
| 757 | break; |
| 758 | default: |
| 759 | /* WD reset control not supported */ |
| 760 | break; |
| 761 | } |
| 762 | if (rc) { |
| 763 | pr_err("setting WD reset control failed, rc=%d\n", rc); |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 769 | |
| 770 | return rc; |
| 771 | } |
| 772 | EXPORT_SYMBOL(pm8xxx_watchdog_reset_control); |
| 773 | |
Anirudh Ghayal | 51e947f | 2011-11-01 14:49:45 +0530 | [diff] [blame] | 774 | /** |
| 775 | * pm8xxx_stay_on - enables stay_on feature |
| 776 | * |
| 777 | * PMIC stay-on feature allows PMIC to ignore MSM PS_HOLD=low |
| 778 | * signal so that some special functions like debugging could be |
| 779 | * performed. |
| 780 | * |
| 781 | * This feature should not be used in any product release. |
| 782 | * |
| 783 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 784 | */ |
| 785 | int pm8xxx_stay_on(void) |
| 786 | { |
| 787 | struct pm8xxx_misc_chip *chip; |
| 788 | unsigned long flags; |
| 789 | int rc = 0; |
| 790 | |
| 791 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 792 | |
| 793 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 794 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 795 | switch (chip->version) { |
| 796 | case PM8XXX_VERSION_8018: |
| 797 | case PM8XXX_VERSION_8058: |
| 798 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 799 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | 51e947f | 2011-11-01 14:49:45 +0530 | [diff] [blame] | 800 | rc = pm8xxx_writeb(chip->dev->parent, |
| 801 | REG_PM8XXX_GP_TEST_1, PM8XXX_STAY_ON_CFG); |
| 802 | break; |
| 803 | default: |
| 804 | /* stay on not supported */ |
| 805 | break; |
| 806 | } |
| 807 | if (rc) { |
| 808 | pr_err("stay_on failed failed, rc=%d\n", rc); |
| 809 | break; |
| 810 | } |
| 811 | } |
| 812 | |
| 813 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 814 | |
| 815 | return rc; |
| 816 | } |
| 817 | EXPORT_SYMBOL(pm8xxx_stay_on); |
| 818 | |
Anirudh Ghayal | a4262a3 | 2011-11-10 00:02:18 +0530 | [diff] [blame] | 819 | static int |
| 820 | __pm8xxx_hard_reset_config(struct pm8xxx_misc_chip *chip, |
| 821 | enum pm8xxx_pon_config config, u16 pon4_addr, u16 pon5_addr) |
| 822 | { |
| 823 | int rc = 0; |
| 824 | |
| 825 | switch (config) { |
| 826 | case PM8XXX_DISABLE_HARD_RESET: |
| 827 | rc = pm8xxx_misc_masked_write(chip, pon5_addr, |
| 828 | PON_CTRL_5_HARD_RESET_EN_MASK, |
| 829 | PON_CTRL_5_HARD_RESET_DIS); |
| 830 | break; |
| 831 | case PM8XXX_SHUTDOWN_ON_HARD_RESET: |
| 832 | rc = pm8xxx_misc_masked_write(chip, pon5_addr, |
| 833 | PON_CTRL_5_HARD_RESET_EN_MASK, |
| 834 | PON_CTRL_5_HARD_RESET_EN); |
| 835 | if (!rc) { |
| 836 | rc = pm8xxx_misc_masked_write(chip, pon4_addr, |
| 837 | PON_CTRL_4_RESET_EN_MASK, |
| 838 | PON_CTRL_4_SHUTDOWN_ON_RESET); |
| 839 | } |
| 840 | break; |
| 841 | case PM8XXX_RESTART_ON_HARD_RESET: |
| 842 | rc = pm8xxx_misc_masked_write(chip, pon5_addr, |
| 843 | PON_CTRL_5_HARD_RESET_EN_MASK, |
| 844 | PON_CTRL_5_HARD_RESET_EN); |
| 845 | if (!rc) { |
| 846 | rc = pm8xxx_misc_masked_write(chip, pon4_addr, |
| 847 | PON_CTRL_4_RESET_EN_MASK, |
| 848 | PON_CTRL_4_RESTART_ON_RESET); |
| 849 | } |
| 850 | break; |
| 851 | default: |
| 852 | rc = -EINVAL; |
| 853 | break; |
| 854 | } |
| 855 | return rc; |
| 856 | } |
| 857 | |
| 858 | /** |
| 859 | * pm8xxx_hard_reset_config - Allows different reset configurations |
| 860 | * |
| 861 | * config = PM8XXX_DISABLE_HARD_RESET to disable hard reset |
| 862 | * = PM8XXX_SHUTDOWN_ON_HARD_RESET to turn off the system on hard reset |
| 863 | * = PM8XXX_RESTART_ON_HARD_RESET to restart the system on hard reset |
| 864 | * |
| 865 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 866 | */ |
| 867 | int pm8xxx_hard_reset_config(enum pm8xxx_pon_config config) |
| 868 | { |
| 869 | struct pm8xxx_misc_chip *chip; |
| 870 | unsigned long flags; |
| 871 | int rc = 0; |
| 872 | |
| 873 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 874 | |
| 875 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 876 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 877 | switch (chip->version) { |
| 878 | case PM8XXX_VERSION_8018: |
| 879 | __pm8xxx_hard_reset_config(chip, config, |
| 880 | REG_PM8018_PON_CNTL_4, REG_PM8018_PON_CNTL_5); |
| 881 | break; |
| 882 | case PM8XXX_VERSION_8058: |
| 883 | __pm8xxx_hard_reset_config(chip, config, |
| 884 | REG_PM8058_PON_CNTL_4, REG_PM8058_PON_CNTL_5); |
| 885 | break; |
| 886 | case PM8XXX_VERSION_8901: |
| 887 | __pm8xxx_hard_reset_config(chip, config, |
| 888 | REG_PM8901_PON_CNTL_4, REG_PM8901_PON_CNTL_5); |
| 889 | break; |
| 890 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 891 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | a4262a3 | 2011-11-10 00:02:18 +0530 | [diff] [blame] | 892 | __pm8xxx_hard_reset_config(chip, config, |
| 893 | REG_PM8921_PON_CNTL_4, REG_PM8921_PON_CNTL_5); |
| 894 | break; |
| 895 | default: |
| 896 | /* hard reset config. no supported */ |
| 897 | break; |
| 898 | } |
| 899 | if (rc) { |
| 900 | pr_err("hard reset config. failed, rc=%d\n", rc); |
| 901 | break; |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 906 | |
| 907 | return rc; |
| 908 | } |
| 909 | EXPORT_SYMBOL(pm8xxx_hard_reset_config); |
| 910 | |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 911 | /* Handle the OSC_HALT interrupt: 32 kHz XTAL oscillator has stopped. */ |
| 912 | static irqreturn_t pm8xxx_osc_halt_isr(int irq, void *data) |
| 913 | { |
| 914 | struct pm8xxx_misc_chip *chip = data; |
| 915 | u64 count = 0; |
| 916 | |
| 917 | if (chip) { |
| 918 | chip->osc_halt_count++; |
| 919 | count = chip->osc_halt_count; |
| 920 | } |
| 921 | |
| 922 | pr_crit("%s: OSC_HALT interrupt has triggered, 32 kHz XTAL oscillator" |
| 923 | " has halted (%llu)!\n", __func__, count); |
| 924 | |
| 925 | return IRQ_HANDLED; |
| 926 | } |
| 927 | |
Anirudh Ghayal | 5213eb8 | 2011-10-24 14:44:58 +0530 | [diff] [blame] | 928 | /** |
| 929 | * pm8xxx_uart_gpio_mux_ctrl - Mux configuration to select the UART |
| 930 | * |
| 931 | * @uart_path_sel: Input argument to select either UART1/2/3 |
| 932 | * |
| 933 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 934 | */ |
| 935 | int pm8xxx_uart_gpio_mux_ctrl(enum pm8xxx_uart_path_sel uart_path_sel) |
| 936 | { |
| 937 | struct pm8xxx_misc_chip *chip; |
| 938 | unsigned long flags; |
| 939 | int rc = 0; |
| 940 | |
| 941 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 942 | |
| 943 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 944 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 945 | switch (chip->version) { |
| 946 | case PM8XXX_VERSION_8018: |
| 947 | case PM8XXX_VERSION_8058: |
| 948 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 949 | case PM8XXX_VERSION_8917: |
Anirudh Ghayal | 5213eb8 | 2011-10-24 14:44:58 +0530 | [diff] [blame] | 950 | rc = pm8xxx_misc_masked_write(chip, |
| 951 | REG_PM8XXX_GPIO_MUX_CTRL, UART_PATH_SEL_MASK, |
| 952 | uart_path_sel << UART_PATH_SEL_SHIFT); |
| 953 | break; |
| 954 | default: |
| 955 | /* Functionality not supported */ |
| 956 | break; |
| 957 | } |
| 958 | if (rc) { |
| 959 | pr_err("uart_gpio_mux_ctrl failed, rc=%d\n", rc); |
| 960 | break; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 965 | |
| 966 | return rc; |
| 967 | } |
| 968 | EXPORT_SYMBOL(pm8xxx_uart_gpio_mux_ctrl); |
| 969 | |
Willie Ruan | 5db1f24 | 2012-01-30 22:08:04 -0800 | [diff] [blame] | 970 | /** |
| 971 | * pm8xxx_usb_id_pullup - Control a pullup for USB ID |
| 972 | * |
| 973 | * @enable: enable (1) or disable (0) the pullup |
| 974 | * |
| 975 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 976 | */ |
| 977 | int pm8xxx_usb_id_pullup(int enable) |
| 978 | { |
| 979 | struct pm8xxx_misc_chip *chip; |
| 980 | unsigned long flags; |
| 981 | int rc = -ENXIO; |
| 982 | |
| 983 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 984 | |
| 985 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 986 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 987 | switch (chip->version) { |
| 988 | case PM8XXX_VERSION_8921: |
| 989 | case PM8XXX_VERSION_8922: |
| 990 | case PM8XXX_VERSION_8917: |
| 991 | case PM8XXX_VERSION_8038: |
| 992 | rc = pm8xxx_misc_masked_write(chip, |
| 993 | REG_PM8XXX_GPIO_MUX_CTRL, USB_ID_PU_EN_MASK, |
| 994 | enable << USB_ID_PU_EN_SHIFT); |
| 995 | |
| 996 | if (rc) |
| 997 | pr_err("Fail: reg=%x, rc=%d\n", |
| 998 | REG_PM8XXX_GPIO_MUX_CTRL, rc); |
| 999 | break; |
| 1000 | default: |
| 1001 | /* Functionality not supported */ |
| 1002 | break; |
| 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 1007 | |
| 1008 | return rc; |
| 1009 | } |
| 1010 | EXPORT_SYMBOL(pm8xxx_usb_id_pullup); |
| 1011 | |
David Collins | 4724272 | 2012-01-20 11:34:58 -0800 | [diff] [blame] | 1012 | static int __pm8901_preload_dVdd(struct pm8xxx_misc_chip *chip) |
| 1013 | { |
| 1014 | int rc; |
| 1015 | |
David Collins | 135f3e0 | 2012-04-05 10:15:23 -0700 | [diff] [blame] | 1016 | /* dVdd preloading is not needed for PMIC PM8901 rev 2.3 and beyond. */ |
| 1017 | if (pm8xxx_get_revision(chip->dev->parent) >= PM8XXX_REVISION_8901_2p3) |
| 1018 | return 0; |
| 1019 | |
David Collins | 4724272 | 2012-01-20 11:34:58 -0800 | [diff] [blame] | 1020 | rc = pm8xxx_writeb(chip->dev->parent, 0x0BD, 0x0F); |
| 1021 | if (rc) |
| 1022 | pr_err("pm8xxx_writeb failed for 0x0BD, rc=%d\n", rc); |
| 1023 | |
| 1024 | rc = pm8xxx_writeb(chip->dev->parent, 0x001, 0xB4); |
| 1025 | if (rc) |
| 1026 | pr_err("pm8xxx_writeb failed for 0x001, rc=%d\n", rc); |
| 1027 | |
| 1028 | pr_info("dVdd preloaded\n"); |
| 1029 | |
| 1030 | return rc; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
| 1034 | * pm8xxx_preload_dVdd - preload the dVdd regulator during off state. |
| 1035 | * |
| 1036 | * This can help to reduce fluctuations in the dVdd voltage during startup |
| 1037 | * at the cost of additional off state current draw. |
| 1038 | * |
| 1039 | * This API should only be called if dVdd startup issues are suspected. |
| 1040 | * |
| 1041 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 1042 | */ |
| 1043 | int pm8xxx_preload_dVdd(void) |
| 1044 | { |
| 1045 | struct pm8xxx_misc_chip *chip; |
| 1046 | unsigned long flags; |
| 1047 | int rc = 0; |
| 1048 | |
| 1049 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 1050 | |
| 1051 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 1052 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 1053 | switch (chip->version) { |
| 1054 | case PM8XXX_VERSION_8901: |
| 1055 | rc = __pm8901_preload_dVdd(chip); |
| 1056 | break; |
| 1057 | default: |
| 1058 | /* PMIC doesn't have preload_dVdd; do nothing. */ |
| 1059 | break; |
| 1060 | } |
| 1061 | if (rc) { |
| 1062 | pr_err("preload_dVdd failed, rc=%d\n", rc); |
| 1063 | break; |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 1068 | |
| 1069 | return rc; |
| 1070 | } |
| 1071 | EXPORT_SYMBOL_GPL(pm8xxx_preload_dVdd); |
| 1072 | |
Amy Maloche | 4c994c9 | 2012-02-15 09:56:15 -0800 | [diff] [blame] | 1073 | int pm8xxx_aux_clk_control(enum pm8xxx_aux_clk_id clk_id, |
| 1074 | enum pm8xxx_aux_clk_div divider, bool enable) |
| 1075 | { |
| 1076 | struct pm8xxx_misc_chip *chip; |
| 1077 | unsigned long flags; |
| 1078 | u8 clk_mask = 0, value = 0; |
| 1079 | |
| 1080 | if (clk_id == CLK_MP3_1) { |
| 1081 | clk_mask = MP3_1_MASK; |
| 1082 | value = divider << MP3_1_SHIFT; |
| 1083 | } else if (clk_id == CLK_MP3_2) { |
| 1084 | clk_mask = MP3_2_MASK; |
| 1085 | value = divider << MP3_2_SHIFT; |
| 1086 | } else { |
| 1087 | pr_err("Invalid clock id of %d\n", clk_id); |
| 1088 | return -EINVAL; |
| 1089 | } |
| 1090 | if (!enable) |
| 1091 | value = 0; |
| 1092 | |
| 1093 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 1094 | |
| 1095 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 1096 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 1097 | switch (chip->version) { |
| 1098 | case PM8XXX_VERSION_8038: |
| 1099 | case PM8XXX_VERSION_8921: |
Willie Ruan | a813d5f | 2012-05-31 10:21:33 -0700 | [diff] [blame] | 1100 | case PM8XXX_VERSION_8917: |
Amy Maloche | 4c994c9 | 2012-02-15 09:56:15 -0800 | [diff] [blame] | 1101 | pm8xxx_misc_masked_write(chip, |
| 1102 | REG_PM8XXX_XO_CNTRL_2, clk_mask, value); |
| 1103 | break; |
| 1104 | default: |
| 1105 | /* Functionality not supported */ |
| 1106 | break; |
| 1107 | } |
| 1108 | } |
| 1109 | |
| 1110 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 1111 | |
| 1112 | return 0; |
| 1113 | } |
| 1114 | EXPORT_SYMBOL_GPL(pm8xxx_aux_clk_control); |
| 1115 | |
Anirudh Ghayal | ba4ea6e | 2012-05-09 15:59:28 +0530 | [diff] [blame] | 1116 | int pm8xxx_hsed_bias_control(enum pm8xxx_hsed_bias bias, bool enable) |
| 1117 | { |
| 1118 | struct pm8xxx_misc_chip *chip; |
| 1119 | unsigned long flags; |
| 1120 | int rc = 0; |
| 1121 | u16 addr; |
| 1122 | |
| 1123 | switch (bias) { |
| 1124 | case PM8XXX_HSED_BIAS0: |
| 1125 | addr = REG_HSED_BIAS0_CNTL2; |
| 1126 | break; |
| 1127 | case PM8XXX_HSED_BIAS1: |
| 1128 | addr = REG_HSED_BIAS1_CNTL2; |
| 1129 | break; |
| 1130 | case PM8XXX_HSED_BIAS2: |
| 1131 | addr = REG_HSED_BIAS2_CNTL2; |
| 1132 | break; |
| 1133 | default: |
| 1134 | pr_err("Invalid BIAS line\n"); |
| 1135 | return -EINVAL; |
| 1136 | } |
| 1137 | |
| 1138 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 1139 | |
| 1140 | /* Loop over all attached PMICs and call specific functions for them. */ |
| 1141 | list_for_each_entry(chip, &pm8xxx_misc_chips, link) { |
| 1142 | switch (chip->version) { |
| 1143 | case PM8XXX_VERSION_8058: |
| 1144 | case PM8XXX_VERSION_8921: |
| 1145 | rc = pm8xxx_misc_masked_write(chip, addr, |
| 1146 | HSED_EN_MASK, enable ? HSED_EN_MASK : 0); |
| 1147 | if (rc < 0) |
| 1148 | pr_err("Enable HSED BIAS failed rc=%d\n", rc); |
| 1149 | break; |
| 1150 | default: |
| 1151 | /* Functionality not supported */ |
| 1152 | break; |
| 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 1157 | |
| 1158 | return rc; |
| 1159 | } |
| 1160 | EXPORT_SYMBOL(pm8xxx_hsed_bias_control); |
| 1161 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1162 | static int __devinit pm8xxx_misc_probe(struct platform_device *pdev) |
| 1163 | { |
| 1164 | const struct pm8xxx_misc_platform_data *pdata = pdev->dev.platform_data; |
| 1165 | struct pm8xxx_misc_chip *chip; |
| 1166 | struct pm8xxx_misc_chip *sibling; |
| 1167 | struct list_head *prev; |
| 1168 | unsigned long flags; |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 1169 | int rc = 0, irq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1170 | |
| 1171 | if (!pdata) { |
| 1172 | pr_err("missing platform data\n"); |
| 1173 | return -EINVAL; |
| 1174 | } |
| 1175 | |
| 1176 | chip = kzalloc(sizeof(struct pm8xxx_misc_chip), GFP_KERNEL); |
| 1177 | if (!chip) { |
| 1178 | pr_err("Cannot allocate %d bytes\n", |
| 1179 | sizeof(struct pm8xxx_misc_chip)); |
| 1180 | return -ENOMEM; |
| 1181 | } |
| 1182 | |
| 1183 | chip->dev = &pdev->dev; |
| 1184 | chip->version = pm8xxx_get_version(chip->dev->parent); |
| 1185 | memcpy(&(chip->pdata), pdata, sizeof(struct pm8xxx_misc_platform_data)); |
| 1186 | |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 1187 | irq = platform_get_irq_byname(pdev, "pm8xxx_osc_halt_irq"); |
| 1188 | if (irq > 0) { |
| 1189 | rc = request_any_context_irq(irq, pm8xxx_osc_halt_isr, |
| 1190 | IRQF_TRIGGER_RISING | IRQF_DISABLED, |
| 1191 | "pm8xxx_osc_halt_irq", chip); |
| 1192 | if (rc < 0) { |
| 1193 | pr_err("%s: request_any_context_irq(%d) FAIL: %d\n", |
| 1194 | __func__, irq, rc); |
| 1195 | goto fail_irq; |
| 1196 | } |
| 1197 | } |
| 1198 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1199 | /* Insert PMICs in priority order (lowest value first). */ |
| 1200 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 1201 | prev = &pm8xxx_misc_chips; |
| 1202 | list_for_each_entry(sibling, &pm8xxx_misc_chips, link) { |
| 1203 | if (chip->pdata.priority < sibling->pdata.priority) |
| 1204 | break; |
| 1205 | else |
| 1206 | prev = &sibling->link; |
| 1207 | } |
| 1208 | list_add(&chip->link, prev); |
| 1209 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 1210 | |
| 1211 | platform_set_drvdata(pdev, chip); |
| 1212 | |
| 1213 | return rc; |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 1214 | |
| 1215 | fail_irq: |
| 1216 | platform_set_drvdata(pdev, NULL); |
| 1217 | kfree(chip); |
| 1218 | return rc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1219 | } |
| 1220 | |
| 1221 | static int __devexit pm8xxx_misc_remove(struct platform_device *pdev) |
| 1222 | { |
| 1223 | struct pm8xxx_misc_chip *chip = platform_get_drvdata(pdev); |
| 1224 | unsigned long flags; |
Anirudh Ghayal | 8b8f189 | 2011-11-11 10:48:41 +0530 | [diff] [blame] | 1225 | int irq = platform_get_irq_byname(pdev, "pm8xxx_osc_halt_irq"); |
| 1226 | if (irq > 0) |
| 1227 | free_irq(irq, chip); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1228 | |
| 1229 | spin_lock_irqsave(&pm8xxx_misc_chips_lock, flags); |
| 1230 | list_del(&chip->link); |
| 1231 | spin_unlock_irqrestore(&pm8xxx_misc_chips_lock, flags); |
| 1232 | |
| 1233 | platform_set_drvdata(pdev, NULL); |
| 1234 | kfree(chip); |
| 1235 | |
| 1236 | return 0; |
| 1237 | } |
| 1238 | |
| 1239 | static struct platform_driver pm8xxx_misc_driver = { |
| 1240 | .probe = pm8xxx_misc_probe, |
| 1241 | .remove = __devexit_p(pm8xxx_misc_remove), |
| 1242 | .driver = { |
| 1243 | .name = PM8XXX_MISC_DEV_NAME, |
| 1244 | .owner = THIS_MODULE, |
| 1245 | }, |
| 1246 | }; |
| 1247 | |
| 1248 | static int __init pm8xxx_misc_init(void) |
| 1249 | { |
| 1250 | return platform_driver_register(&pm8xxx_misc_driver); |
| 1251 | } |
| 1252 | postcore_initcall(pm8xxx_misc_init); |
| 1253 | |
| 1254 | static void __exit pm8xxx_misc_exit(void) |
| 1255 | { |
| 1256 | platform_driver_unregister(&pm8xxx_misc_driver); |
| 1257 | } |
| 1258 | module_exit(pm8xxx_misc_exit); |
| 1259 | |
| 1260 | MODULE_LICENSE("GPL v2"); |
| 1261 | MODULE_DESCRIPTION("PMIC 8XXX misc driver"); |
| 1262 | MODULE_VERSION("1.0"); |
| 1263 | MODULE_ALIAS("platform:" PM8XXX_MISC_DEV_NAME); |