Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | /* |
| 14 | * Qualcomm PMIC8058 driver |
| 15 | * |
| 16 | */ |
| 17 | #include <linux/interrupt.h> |
| 18 | #include <linux/i2c.h> |
David Collins | 0a91160 | 2011-06-15 15:03:13 -0700 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 20 | #include <linux/slab.h> |
| 21 | #include <linux/ratelimit.h> |
| 22 | #include <linux/kthread.h> |
| 23 | #include <linux/mfd/core.h> |
| 24 | #include <linux/mfd/pmic8058.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/ratelimit.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/debugfs.h> |
| 29 | #include <linux/irq.h> |
Abhijeet Dharmapurikar | a3c0d94 | 2011-07-25 17:53:45 -0700 | [diff] [blame^] | 30 | #include <linux/syscore_ops.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 31 | |
| 32 | /* PMIC8058 Revision */ |
| 33 | #define SSBI_REG_REV 0x002 /* PMIC4 revision */ |
| 34 | |
| 35 | /* PMIC8058 IRQ */ |
| 36 | #define SSBI_REG_ADDR_IRQ_BASE 0x1BB |
| 37 | |
| 38 | #define SSBI_REG_ADDR_IRQ_ROOT (SSBI_REG_ADDR_IRQ_BASE + 0) |
| 39 | #define SSBI_REG_ADDR_IRQ_M_STATUS1 (SSBI_REG_ADDR_IRQ_BASE + 1) |
| 40 | #define SSBI_REG_ADDR_IRQ_M_STATUS2 (SSBI_REG_ADDR_IRQ_BASE + 2) |
| 41 | #define SSBI_REG_ADDR_IRQ_M_STATUS3 (SSBI_REG_ADDR_IRQ_BASE + 3) |
| 42 | #define SSBI_REG_ADDR_IRQ_M_STATUS4 (SSBI_REG_ADDR_IRQ_BASE + 4) |
| 43 | #define SSBI_REG_ADDR_IRQ_BLK_SEL (SSBI_REG_ADDR_IRQ_BASE + 5) |
| 44 | #define SSBI_REG_ADDR_IRQ_IT_STATUS (SSBI_REG_ADDR_IRQ_BASE + 6) |
| 45 | #define SSBI_REG_ADDR_IRQ_CONFIG (SSBI_REG_ADDR_IRQ_BASE + 7) |
| 46 | #define SSBI_REG_ADDR_IRQ_RT_STATUS (SSBI_REG_ADDR_IRQ_BASE + 8) |
| 47 | |
| 48 | #define PM8058_IRQF_LVL_SEL 0x01 /* level select */ |
| 49 | #define PM8058_IRQF_MASK_FE 0x02 /* mask falling edge */ |
| 50 | #define PM8058_IRQF_MASK_RE 0x04 /* mask rising edge */ |
| 51 | #define PM8058_IRQF_CLR 0x08 /* clear interrupt */ |
| 52 | #define PM8058_IRQF_BITS_MASK 0x70 |
| 53 | #define PM8058_IRQF_BITS_SHIFT 4 |
| 54 | #define PM8058_IRQF_WRITE 0x80 |
| 55 | |
| 56 | #define PM8058_IRQF_MASK_ALL (PM8058_IRQF_MASK_FE | \ |
| 57 | PM8058_IRQF_MASK_RE) |
| 58 | #define PM8058_IRQF_W_C_M (PM8058_IRQF_WRITE | \ |
| 59 | PM8058_IRQF_CLR | \ |
| 60 | PM8058_IRQF_MASK_ALL) |
| 61 | |
| 62 | /* MISC register */ |
| 63 | #define SSBI_REG_ADDR_MISC 0x1CC |
| 64 | |
| 65 | /* PON CNTL 1 register */ |
| 66 | #define SSBI_REG_ADDR_PON_CNTL_1 0x01C |
| 67 | |
| 68 | #define PM8058_PON_PUP_MASK 0xF0 |
| 69 | |
| 70 | #define PM8058_PON_WD_EN_MASK 0x08 |
| 71 | #define PM8058_PON_WD_EN_RESET 0x08 |
| 72 | #define PM8058_PON_WD_EN_PWR_OFF 0x00 |
| 73 | |
| 74 | /* PON CNTL 4 register */ |
| 75 | #define SSBI_REG_ADDR_PON_CNTL_4 0x98 |
| 76 | #define PM8058_PON_RESET_EN_MASK 0x01 |
| 77 | |
| 78 | /* PON CNTL 5 register */ |
| 79 | #define SSBI_REG_ADDR_PON_CNTL_5 0x7B |
| 80 | #define PM8058_HARD_RESET_EN_MASK 0x08 |
| 81 | |
David Collins | 0a91160 | 2011-06-15 15:03:13 -0700 | [diff] [blame] | 82 | /* Regulator master enable addresses */ |
| 83 | #define SSBI_REG_ADDR_VREG_EN_MSM 0x018 |
| 84 | #define SSBI_REG_ADDR_VREG_EN_GRP_5_4 0x1C8 |
| 85 | |
| 86 | /* Regulator control registers for shutdown/reset */ |
| 87 | #define SSBI_REG_ADDR_S0_CTRL 0x004 |
| 88 | #define SSBI_REG_ADDR_S1_CTRL 0x005 |
| 89 | #define SSBI_REG_ADDR_S3_CTRL 0x111 |
| 90 | #define SSBI_REG_ADDR_L21_CTRL 0x120 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | #define SSBI_REG_ADDR_L22_CTRL 0x121 |
| 92 | |
David Collins | 0a91160 | 2011-06-15 15:03:13 -0700 | [diff] [blame] | 93 | #define REGULATOR_ENABLE_MASK 0x80 |
| 94 | #define REGULATOR_ENABLE 0x80 |
| 95 | #define REGULATOR_DISABLE 0x00 |
| 96 | #define REGULATOR_PULL_DOWN_MASK 0x40 |
| 97 | #define REGULATOR_PULL_DOWN_EN 0x40 |
| 98 | #define REGULATOR_PULL_DOWN_DIS 0x00 |
| 99 | |
| 100 | /* Buck CTRL register */ |
| 101 | #define SMPS_LEGACY_VREF_SEL 0x20 |
| 102 | #define SMPS_LEGACY_VPROG_MASK 0x1F |
| 103 | #define SMPS_ADVANCED_BAND_MASK 0xC0 |
| 104 | #define SMPS_ADVANCED_BAND_SHIFT 6 |
| 105 | #define SMPS_ADVANCED_VPROG_MASK 0x3F |
| 106 | |
| 107 | /* Buck TEST2 registers for shutdown/reset */ |
| 108 | #define SSBI_REG_ADDR_S0_TEST2 0x084 |
| 109 | #define SSBI_REG_ADDR_S1_TEST2 0x085 |
| 110 | #define SSBI_REG_ADDR_S3_TEST2 0x11A |
| 111 | |
| 112 | #define REGULATOR_BANK_WRITE 0x80 |
| 113 | #define REGULATOR_BANK_MASK 0x70 |
| 114 | #define REGULATOR_BANK_SHIFT 4 |
| 115 | #define REGULATOR_BANK_SEL(n) ((n) << REGULATOR_BANK_SHIFT) |
| 116 | |
| 117 | /* Buck TEST2 register bank 1 */ |
| 118 | #define SMPS_LEGACY_VLOW_SEL 0x01 |
| 119 | |
| 120 | /* Buck TEST2 register bank 7 */ |
| 121 | #define SMPS_ADVANCED_MODE_MASK 0x02 |
| 122 | #define SMPS_ADVANCED_MODE 0x02 |
| 123 | #define SMPS_LEGACY_MODE 0x00 |
| 124 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 125 | /* SLEEP CNTL register */ |
| 126 | #define SSBI_REG_ADDR_SLEEP_CNTL 0x02B |
| 127 | |
| 128 | #define PM8058_SLEEP_SMPL_EN_MASK 0x04 |
| 129 | #define PM8058_SLEEP_SMPL_EN_RESET 0x04 |
| 130 | #define PM8058_SLEEP_SMPL_EN_PWR_OFF 0x00 |
| 131 | |
| 132 | #define PM8058_SLEEP_SMPL_SEL_MASK 0x03 |
| 133 | #define PM8058_SLEEP_SMPL_SEL_MIN 0 |
| 134 | #define PM8058_SLEEP_SMPL_SEL_MAX 3 |
| 135 | |
| 136 | #define MAX_PM_IRQ 256 |
| 137 | #define MAX_PM_BLOCKS (MAX_PM_IRQ / 8 + 1) |
| 138 | #define MAX_PM_MASTERS (MAX_PM_BLOCKS / 8 + 1) |
| 139 | |
| 140 | struct pm8058_chip { |
| 141 | struct pm8058_platform_data pdata; |
| 142 | |
| 143 | struct i2c_client *dev; |
| 144 | |
| 145 | u8 irqs_allowed[MAX_PM_BLOCKS]; |
| 146 | u8 blocks_allowed[MAX_PM_MASTERS]; |
| 147 | u8 masters_allowed; |
| 148 | int pm_max_irq; |
| 149 | int pm_max_blocks; |
| 150 | int pm_max_masters; |
| 151 | |
| 152 | u8 config[MAX_PM_IRQ]; |
| 153 | u8 bus_unlock_config[MAX_PM_IRQ]; |
| 154 | u8 wake_enable[MAX_PM_IRQ]; |
| 155 | u16 count_wakeable; |
| 156 | |
| 157 | u8 revision; |
| 158 | |
| 159 | struct mutex pm_lock; |
| 160 | }; |
| 161 | |
| 162 | #if defined(CONFIG_DEBUG_FS) |
| 163 | struct pm8058_dbg_device { |
| 164 | struct mutex dbg_mutex; |
| 165 | struct pm8058_chip *pm_chip; |
| 166 | struct dentry *dent; |
| 167 | int addr; |
| 168 | }; |
| 169 | |
| 170 | static struct pm8058_dbg_device *pmic_dbg_device; |
| 171 | #endif |
| 172 | |
| 173 | static struct pm8058_chip *pmic_chip; |
| 174 | |
| 175 | /* Helper Functions */ |
| 176 | DEFINE_RATELIMIT_STATE(pm8058_msg_ratelimit, 60 * HZ, 10); |
| 177 | |
| 178 | static inline int pm8058_can_print(void) |
| 179 | { |
| 180 | return __ratelimit(&pm8058_msg_ratelimit); |
| 181 | } |
| 182 | |
| 183 | static inline int |
| 184 | ssbi_write(struct i2c_client *client, u16 addr, const u8 *buf, size_t len) |
| 185 | { |
| 186 | int rc; |
| 187 | struct i2c_msg msg = { |
| 188 | .addr = addr, |
| 189 | .flags = 0x0, |
| 190 | .buf = (u8 *)buf, |
| 191 | .len = len, |
| 192 | }; |
| 193 | |
| 194 | rc = i2c_transfer(client->adapter, &msg, 1); |
| 195 | return (rc == 1) ? 0 : rc; |
| 196 | } |
| 197 | |
| 198 | static inline int |
| 199 | ssbi_read(struct i2c_client *client, u16 addr, u8 *buf, size_t len) |
| 200 | { |
| 201 | int rc; |
| 202 | struct i2c_msg msg = { |
| 203 | .addr = addr, |
| 204 | .flags = I2C_M_RD, |
| 205 | .buf = buf, |
| 206 | .len = len, |
| 207 | }; |
| 208 | |
| 209 | rc = i2c_transfer(client->adapter, &msg, 1); |
| 210 | return (rc == 1) ? 0 : rc; |
| 211 | } |
| 212 | |
| 213 | static int pm8058_masked_write(u16 addr, u8 val, u8 mask) |
| 214 | { |
| 215 | int rc; |
| 216 | u8 reg; |
| 217 | |
| 218 | if (pmic_chip == NULL) |
| 219 | return -ENODEV; |
| 220 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 221 | rc = ssbi_read(pmic_chip->dev, addr, ®, 1); |
| 222 | if (rc) { |
| 223 | pr_err("%s: ssbi_read(0x%03X) failed: rc=%d\n", __func__, addr, |
| 224 | rc); |
| 225 | goto done; |
| 226 | } |
| 227 | |
| 228 | reg &= ~mask; |
| 229 | reg |= val & mask; |
| 230 | |
| 231 | rc = ssbi_write(pmic_chip->dev, addr, ®, 1); |
| 232 | if (rc) |
| 233 | pr_err("%s: ssbi_write(0x%03X)=0x%02X failed: rc=%d\n", |
| 234 | __func__, addr, reg, rc); |
| 235 | done: |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 236 | return rc; |
| 237 | } |
| 238 | |
| 239 | /* External APIs */ |
| 240 | int pm8058_rev(struct pm8058_chip *chip) |
| 241 | { |
| 242 | if (chip == NULL) |
| 243 | return -EINVAL; |
| 244 | |
| 245 | return chip->revision; |
| 246 | } |
| 247 | EXPORT_SYMBOL(pm8058_rev); |
| 248 | |
| 249 | int pm8058_irq_get_rt_status(struct pm8058_chip *chip, int irq) |
| 250 | { |
| 251 | int rc; |
| 252 | u8 block, bits, bit; |
| 253 | |
| 254 | if (chip == NULL || irq < chip->pdata.irq_base || |
| 255 | irq >= chip->pdata.irq_base + MAX_PM_IRQ) |
| 256 | return -EINVAL; |
| 257 | |
| 258 | irq -= chip->pdata.irq_base; |
| 259 | |
| 260 | block = irq / 8; |
| 261 | bit = irq % 8; |
| 262 | |
| 263 | mutex_lock(&chip->pm_lock); |
| 264 | |
| 265 | rc = ssbi_write(chip->dev, SSBI_REG_ADDR_IRQ_BLK_SEL, &block, 1); |
| 266 | if (rc) { |
| 267 | pr_err("%s: FAIL ssbi_write(): rc=%d (Select Block)\n", |
| 268 | __func__, rc); |
| 269 | goto bail_out; |
| 270 | } |
| 271 | |
| 272 | rc = ssbi_read(chip->dev, SSBI_REG_ADDR_IRQ_RT_STATUS, &bits, 1); |
| 273 | if (rc) { |
| 274 | pr_err("%s: FAIL ssbi_read(): rc=%d (Read RT Status)\n", |
| 275 | __func__, rc); |
| 276 | goto bail_out; |
| 277 | } |
| 278 | |
| 279 | rc = (bits & (1 << bit)) ? 1 : 0; |
| 280 | |
| 281 | bail_out: |
| 282 | mutex_unlock(&chip->pm_lock); |
| 283 | |
| 284 | return rc; |
| 285 | } |
| 286 | EXPORT_SYMBOL(pm8058_irq_get_rt_status); |
| 287 | |
| 288 | int pm8058_read(struct pm8058_chip *chip, u16 addr, u8 *values, |
| 289 | unsigned int len) |
| 290 | { |
| 291 | if (chip == NULL) |
| 292 | return -EINVAL; |
| 293 | |
| 294 | return ssbi_read(chip->dev, addr, values, len); |
| 295 | } |
| 296 | EXPORT_SYMBOL(pm8058_read); |
| 297 | |
| 298 | int pm8058_write(struct pm8058_chip *chip, u16 addr, u8 *values, |
| 299 | unsigned int len) |
| 300 | { |
| 301 | if (chip == NULL) |
| 302 | return -EINVAL; |
| 303 | |
| 304 | return ssbi_write(chip->dev, addr, values, len); |
| 305 | } |
| 306 | EXPORT_SYMBOL(pm8058_write); |
| 307 | |
| 308 | int pm8058_misc_control(struct pm8058_chip *chip, int mask, int flag) |
| 309 | { |
| 310 | int rc; |
| 311 | u8 misc; |
| 312 | |
| 313 | if (chip == NULL) |
| 314 | chip = pmic_chip; /* for calls from non child */ |
| 315 | if (chip == NULL) |
| 316 | return -ENODEV; |
| 317 | |
| 318 | mutex_lock(&chip->pm_lock); |
| 319 | |
| 320 | rc = ssbi_read(chip->dev, SSBI_REG_ADDR_MISC, &misc, 1); |
| 321 | if (rc) { |
| 322 | pr_err("%s: FAIL ssbi_read(0x%x): rc=%d\n", |
| 323 | __func__, SSBI_REG_ADDR_MISC, rc); |
| 324 | goto get_out; |
| 325 | } |
| 326 | |
| 327 | misc &= ~mask; |
| 328 | misc |= flag; |
| 329 | |
| 330 | rc = ssbi_write(chip->dev, SSBI_REG_ADDR_MISC, &misc, 1); |
| 331 | if (rc) { |
| 332 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", |
| 333 | __func__, SSBI_REG_ADDR_MISC, misc, rc); |
| 334 | goto get_out; |
| 335 | } |
| 336 | |
| 337 | get_out: |
| 338 | mutex_unlock(&chip->pm_lock); |
| 339 | |
| 340 | return rc; |
| 341 | } |
| 342 | EXPORT_SYMBOL(pm8058_misc_control); |
| 343 | |
| 344 | /** |
| 345 | * pm8058_smpl_control - enables/disables SMPL detection |
| 346 | * @enable: 0 = shutdown PMIC on power loss, 1 = reset PMIC on power loss |
| 347 | * |
| 348 | * This function enables or disables the Sudden Momentary Power Loss detection |
| 349 | * module. If SMPL detection is enabled, then when a sufficiently long power |
| 350 | * loss event occurs, the PMIC will automatically reset itself. If SMPL |
| 351 | * detection is disabled, then the PMIC will shutdown when power loss occurs. |
| 352 | * |
| 353 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 354 | */ |
| 355 | int pm8058_smpl_control(int enable) |
| 356 | { |
| 357 | return pm8058_masked_write(SSBI_REG_ADDR_SLEEP_CNTL, |
| 358 | (enable ? PM8058_SLEEP_SMPL_EN_RESET |
| 359 | : PM8058_SLEEP_SMPL_EN_PWR_OFF), |
| 360 | PM8058_SLEEP_SMPL_EN_MASK); |
| 361 | } |
| 362 | EXPORT_SYMBOL(pm8058_smpl_control); |
| 363 | |
| 364 | /** |
| 365 | * pm8058_smpl_set_delay - sets the SMPL detection time delay |
| 366 | * @delay: enum value corresponding to delay time |
| 367 | * |
| 368 | * This function sets the time delay of the SMPL detection module. If power |
| 369 | * is reapplied within this interval, then the PMIC reset automatically. The |
| 370 | * SMPL detection module must be enabled for this delay time to take effect. |
| 371 | * |
| 372 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 373 | */ |
| 374 | int pm8058_smpl_set_delay(enum pm8058_smpl_delay delay) |
| 375 | { |
| 376 | if (delay < PM8058_SLEEP_SMPL_SEL_MIN |
| 377 | || delay > PM8058_SLEEP_SMPL_SEL_MAX) { |
| 378 | pr_err("%s: invalid delay specified: %d\n", __func__, delay); |
| 379 | return -EINVAL; |
| 380 | } |
| 381 | |
| 382 | return pm8058_masked_write(SSBI_REG_ADDR_SLEEP_CNTL, delay, |
| 383 | PM8058_SLEEP_SMPL_SEL_MASK); |
| 384 | } |
| 385 | EXPORT_SYMBOL(pm8058_smpl_set_delay); |
| 386 | |
| 387 | /** |
| 388 | * pm8058_watchdog_reset_control - enables/disables watchdog reset detection |
| 389 | * @enable: 0 = shutdown when PS_HOLD goes low, 1 = reset when PS_HOLD goes low |
| 390 | * |
| 391 | * This function enables or disables the PMIC watchdog reset detection feature. |
| 392 | * If watchdog reset detection is enabled, then the PMIC will reset itself |
| 393 | * when PS_HOLD goes low. If it is not enabled, then the PMIC will shutdown |
| 394 | * when PS_HOLD goes low. |
| 395 | * |
| 396 | * RETURNS: an appropriate -ERRNO error value on error, or zero for success. |
| 397 | */ |
| 398 | int pm8058_watchdog_reset_control(int enable) |
| 399 | { |
| 400 | return pm8058_masked_write(SSBI_REG_ADDR_PON_CNTL_1, |
| 401 | (enable ? PM8058_PON_WD_EN_RESET |
| 402 | : PM8058_PON_WD_EN_PWR_OFF), |
| 403 | PM8058_PON_WD_EN_MASK); |
| 404 | } |
| 405 | EXPORT_SYMBOL(pm8058_watchdog_reset_control); |
| 406 | |
David Collins | 0a91160 | 2011-06-15 15:03:13 -0700 | [diff] [blame] | 407 | /* |
| 408 | * Set an SMPS regulator to be disabled in its CTRL register, but enabled |
| 409 | * in the master enable register. Also set it's pull down enable bit. |
| 410 | * Take care to make sure that the output voltage doesn't change if switching |
| 411 | * from advanced mode to legacy mode. |
| 412 | */ |
| 413 | static int disable_smps_locally_set_pull_down(u16 ctrl_addr, u16 test2_addr, |
| 414 | u16 master_enable_addr, u8 master_enable_bit) |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 415 | { |
David Collins | 0a91160 | 2011-06-15 15:03:13 -0700 | [diff] [blame] | 416 | int rc = 0; |
| 417 | u8 vref_sel, vlow_sel, band, vprog, bank, reg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 418 | |
| 419 | if (pmic_chip == NULL) |
| 420 | return -ENODEV; |
| 421 | |
David Collins | 0a91160 | 2011-06-15 15:03:13 -0700 | [diff] [blame] | 422 | bank = REGULATOR_BANK_SEL(7); |
| 423 | rc = ssbi_write(pmic_chip->dev, test2_addr, &bank, 1); |
| 424 | if (rc) { |
| 425 | pr_err("%s: FAIL ssbi_write(0x%03X): rc=%d\n", __func__, |
| 426 | test2_addr, rc); |
| 427 | goto done; |
| 428 | } |
| 429 | |
| 430 | rc = ssbi_read(pmic_chip->dev, test2_addr, ®, 1); |
| 431 | if (rc) { |
| 432 | pr_err("%s: FAIL pm8058_read(0x%03X): rc=%d\n", |
| 433 | __func__, test2_addr, rc); |
| 434 | goto done; |
| 435 | } |
| 436 | |
| 437 | /* Check if in advanced mode. */ |
| 438 | if ((reg & SMPS_ADVANCED_MODE_MASK) == SMPS_ADVANCED_MODE) { |
| 439 | /* Determine current output voltage. */ |
| 440 | rc = ssbi_read(pmic_chip->dev, ctrl_addr, ®, 1); |
| 441 | if (rc) { |
| 442 | pr_err("%s: FAIL pm8058_read(0x%03X): rc=%d\n", |
| 443 | __func__, ctrl_addr, rc); |
| 444 | goto done; |
| 445 | } |
| 446 | |
| 447 | band = (reg & SMPS_ADVANCED_BAND_MASK) |
| 448 | >> SMPS_ADVANCED_BAND_SHIFT; |
| 449 | switch (band) { |
| 450 | case 3: |
| 451 | vref_sel = 0; |
| 452 | vlow_sel = 0; |
| 453 | break; |
| 454 | case 2: |
| 455 | vref_sel = SMPS_LEGACY_VREF_SEL; |
| 456 | vlow_sel = 0; |
| 457 | break; |
| 458 | case 1: |
| 459 | vref_sel = SMPS_LEGACY_VREF_SEL; |
| 460 | vlow_sel = SMPS_LEGACY_VLOW_SEL; |
| 461 | break; |
| 462 | default: |
| 463 | pr_err("%s: regulator already disabled\n", __func__); |
| 464 | return -EPERM; |
| 465 | } |
| 466 | vprog = (reg & SMPS_ADVANCED_VPROG_MASK); |
| 467 | /* Round up if fine step is in use. */ |
| 468 | vprog = (vprog + 1) >> 1; |
| 469 | if (vprog > SMPS_LEGACY_VPROG_MASK) |
| 470 | vprog = SMPS_LEGACY_VPROG_MASK; |
| 471 | |
| 472 | /* Set VLOW_SEL bit. */ |
| 473 | bank = REGULATOR_BANK_SEL(1); |
| 474 | rc = ssbi_write(pmic_chip->dev, test2_addr, &bank, 1); |
| 475 | if (rc) { |
| 476 | pr_err("%s: FAIL ssbi_write(0x%03X): rc=%d\n", |
| 477 | __func__, test2_addr, rc); |
| 478 | goto done; |
| 479 | } |
| 480 | rc = pm8058_masked_write(test2_addr, |
| 481 | REGULATOR_BANK_WRITE | REGULATOR_BANK_SEL(1) |
| 482 | | vlow_sel, |
| 483 | REGULATOR_BANK_WRITE | REGULATOR_BANK_MASK |
| 484 | | SMPS_LEGACY_VLOW_SEL); |
| 485 | if (rc) |
| 486 | goto done; |
| 487 | |
| 488 | /* Switch to legacy mode */ |
| 489 | bank = REGULATOR_BANK_SEL(7); |
| 490 | rc = ssbi_write(pmic_chip->dev, test2_addr, &bank, 1); |
| 491 | if (rc) { |
| 492 | pr_err("%s: FAIL ssbi_write(0x%03X): rc=%d\n", __func__, |
| 493 | test2_addr, rc); |
| 494 | goto done; |
| 495 | } |
| 496 | rc = pm8058_masked_write(test2_addr, |
| 497 | REGULATOR_BANK_WRITE | REGULATOR_BANK_SEL(7) |
| 498 | | SMPS_LEGACY_MODE, |
| 499 | REGULATOR_BANK_WRITE | REGULATOR_BANK_MASK |
| 500 | | SMPS_ADVANCED_MODE_MASK); |
| 501 | if (rc) |
| 502 | goto done; |
| 503 | |
| 504 | /* Enable locally, enable pull down, keep voltage the same. */ |
| 505 | rc = pm8058_masked_write(ctrl_addr, |
| 506 | REGULATOR_ENABLE | REGULATOR_PULL_DOWN_EN |
| 507 | | vref_sel | vprog, |
| 508 | REGULATOR_ENABLE_MASK | REGULATOR_PULL_DOWN_MASK |
| 509 | | SMPS_LEGACY_VREF_SEL | SMPS_LEGACY_VPROG_MASK); |
| 510 | if (rc) |
| 511 | goto done; |
| 512 | } |
| 513 | |
| 514 | /* Enable in master control register. */ |
| 515 | rc = pm8058_masked_write(master_enable_addr, master_enable_bit, |
| 516 | master_enable_bit); |
| 517 | if (rc) |
| 518 | goto done; |
| 519 | |
| 520 | /* Disable locally and enable pull down. */ |
| 521 | rc = pm8058_masked_write(ctrl_addr, |
| 522 | REGULATOR_DISABLE | REGULATOR_PULL_DOWN_EN, |
| 523 | REGULATOR_ENABLE_MASK | REGULATOR_PULL_DOWN_MASK); |
| 524 | |
| 525 | done: |
| 526 | return rc; |
| 527 | } |
| 528 | |
| 529 | static int disable_ldo_locally_set_pull_down(u16 ctrl_addr, |
| 530 | u16 master_enable_addr, u8 master_enable_bit) |
| 531 | { |
| 532 | int rc; |
| 533 | |
| 534 | /* Enable LDO in master control register. */ |
| 535 | rc = pm8058_masked_write(master_enable_addr, master_enable_bit, |
| 536 | master_enable_bit); |
| 537 | if (rc) |
| 538 | goto done; |
| 539 | |
| 540 | /* Disable LDO in CTRL register and set pull down */ |
| 541 | rc = pm8058_masked_write(ctrl_addr, |
| 542 | REGULATOR_DISABLE | REGULATOR_PULL_DOWN_EN, |
| 543 | REGULATOR_ENABLE_MASK | REGULATOR_PULL_DOWN_MASK); |
| 544 | |
| 545 | done: |
| 546 | return rc; |
| 547 | } |
| 548 | |
| 549 | int pm8058_reset_pwr_off(int reset) |
| 550 | { |
| 551 | int rc; |
| 552 | u8 pon, ctrl, smpl; |
| 553 | |
| 554 | if (pmic_chip == NULL) |
| 555 | return -ENODEV; |
| 556 | |
| 557 | /* When shutting down, enable active pulldowns on important rails. */ |
| 558 | if (!reset) { |
| 559 | /* Disable SMPS's 0,1,3 locally and set pulldown enable bits. */ |
| 560 | disable_smps_locally_set_pull_down(SSBI_REG_ADDR_S0_CTRL, |
| 561 | SSBI_REG_ADDR_S0_TEST2, SSBI_REG_ADDR_VREG_EN_MSM, BIT(7)); |
| 562 | disable_smps_locally_set_pull_down(SSBI_REG_ADDR_S1_CTRL, |
| 563 | SSBI_REG_ADDR_S1_TEST2, SSBI_REG_ADDR_VREG_EN_MSM, BIT(6)); |
| 564 | disable_smps_locally_set_pull_down(SSBI_REG_ADDR_S3_CTRL, |
| 565 | SSBI_REG_ADDR_S3_TEST2, SSBI_REG_ADDR_VREG_EN_GRP_5_4, |
| 566 | BIT(7) | BIT(4)); |
| 567 | /* Disable LDO 21 locally and set pulldown enable bit. */ |
| 568 | disable_ldo_locally_set_pull_down(SSBI_REG_ADDR_L21_CTRL, |
| 569 | SSBI_REG_ADDR_VREG_EN_GRP_5_4, BIT(1)); |
| 570 | } |
| 571 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 572 | /* Set regulator L22 to 1.225V in high power mode. */ |
| 573 | rc = ssbi_read(pmic_chip->dev, SSBI_REG_ADDR_L22_CTRL, &ctrl, 1); |
| 574 | if (rc) { |
| 575 | pr_err("%s: FAIL ssbi_read(0x%x): rc=%d\n", __func__, |
| 576 | SSBI_REG_ADDR_L22_CTRL, rc); |
| 577 | goto get_out3; |
| 578 | } |
| 579 | /* Leave pull-down state intact. */ |
| 580 | ctrl &= 0x40; |
| 581 | ctrl |= 0x93; |
| 582 | rc = ssbi_write(pmic_chip->dev, SSBI_REG_ADDR_L22_CTRL, &ctrl, 1); |
| 583 | if (rc) |
| 584 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", __func__, |
| 585 | SSBI_REG_ADDR_L22_CTRL, ctrl, rc); |
| 586 | |
| 587 | get_out3: |
| 588 | if (!reset) { |
| 589 | /* Only modify the SLEEP_CNTL reg if shutdown is desired. */ |
| 590 | rc = ssbi_read(pmic_chip->dev, SSBI_REG_ADDR_SLEEP_CNTL, |
| 591 | &smpl, 1); |
| 592 | if (rc) { |
| 593 | pr_err("%s: FAIL ssbi_read(0x%x): rc=%d\n", |
| 594 | __func__, SSBI_REG_ADDR_SLEEP_CNTL, rc); |
| 595 | goto get_out2; |
| 596 | } |
| 597 | |
| 598 | smpl &= ~PM8058_SLEEP_SMPL_EN_MASK; |
| 599 | smpl |= PM8058_SLEEP_SMPL_EN_PWR_OFF; |
| 600 | |
| 601 | rc = ssbi_write(pmic_chip->dev, SSBI_REG_ADDR_SLEEP_CNTL, |
| 602 | &smpl, 1); |
| 603 | if (rc) |
| 604 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", |
| 605 | __func__, SSBI_REG_ADDR_SLEEP_CNTL, smpl, rc); |
| 606 | } |
| 607 | |
| 608 | get_out2: |
| 609 | rc = ssbi_read(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_1, &pon, 1); |
| 610 | if (rc) { |
| 611 | pr_err("%s: FAIL ssbi_read(0x%x): rc=%d\n", |
| 612 | __func__, SSBI_REG_ADDR_PON_CNTL_1, rc); |
| 613 | goto get_out; |
| 614 | } |
| 615 | |
| 616 | pon &= ~PM8058_PON_WD_EN_MASK; |
| 617 | pon |= reset ? PM8058_PON_WD_EN_RESET : PM8058_PON_WD_EN_PWR_OFF; |
| 618 | |
| 619 | /* Enable all pullups */ |
| 620 | pon |= PM8058_PON_PUP_MASK; |
| 621 | |
| 622 | rc = ssbi_write(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_1, &pon, 1); |
| 623 | if (rc) { |
| 624 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", |
| 625 | __func__, SSBI_REG_ADDR_PON_CNTL_1, pon, rc); |
| 626 | goto get_out; |
| 627 | } |
| 628 | |
| 629 | get_out: |
| 630 | return rc; |
| 631 | } |
| 632 | EXPORT_SYMBOL(pm8058_reset_pwr_off); |
| 633 | |
| 634 | /* |
| 635 | power on hard reset configuration |
| 636 | config = DISABLE_HARD_RESET to disable hard reset |
| 637 | = SHUTDOWN_ON_HARD_RESET to turn off the system on hard reset |
| 638 | = RESTART_ON_HARD_RESET to restart the system on hard reset |
| 639 | */ |
| 640 | int pm8058_hard_reset_config(enum pon_config config) |
| 641 | { |
| 642 | int rc, ret; |
| 643 | u8 pon, pon_5; |
| 644 | |
| 645 | if (config >= MAX_PON_CONFIG) |
| 646 | return -EINVAL; |
| 647 | |
| 648 | if (pmic_chip == NULL) |
| 649 | return -ENODEV; |
| 650 | |
| 651 | mutex_lock(&pmic_chip->pm_lock); |
| 652 | |
| 653 | rc = ssbi_read(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_5, &pon, 1); |
| 654 | if (rc) { |
| 655 | pr_err("%s: FAIL ssbi_read(0x%x): rc=%d\n", |
| 656 | __func__, SSBI_REG_ADDR_PON_CNTL_5, rc); |
| 657 | mutex_unlock(&pmic_chip->pm_lock); |
| 658 | return rc; |
| 659 | } |
| 660 | |
| 661 | pon_5 = pon; |
| 662 | (config != DISABLE_HARD_RESET) ? (pon |= PM8058_HARD_RESET_EN_MASK) : |
| 663 | (pon &= ~PM8058_HARD_RESET_EN_MASK); |
| 664 | |
| 665 | rc = ssbi_write(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_5, &pon, 1); |
| 666 | if (rc) { |
| 667 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", |
| 668 | __func__, SSBI_REG_ADDR_PON_CNTL_5, pon, rc); |
| 669 | mutex_unlock(&pmic_chip->pm_lock); |
| 670 | return rc; |
| 671 | } |
| 672 | |
| 673 | if (config == DISABLE_HARD_RESET) { |
| 674 | mutex_unlock(&pmic_chip->pm_lock); |
| 675 | return 0; |
| 676 | } |
| 677 | |
| 678 | rc = ssbi_read(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_4, &pon, 1); |
| 679 | if (rc) { |
| 680 | pr_err("%s: FAIL ssbi_read(0x%x): rc=%d\n", |
| 681 | __func__, SSBI_REG_ADDR_PON_CNTL_4, rc); |
| 682 | goto err_restore_pon_5; |
| 683 | } |
| 684 | |
| 685 | (config == RESTART_ON_HARD_RESET) ? (pon |= PM8058_PON_RESET_EN_MASK) : |
| 686 | (pon &= ~PM8058_PON_RESET_EN_MASK); |
| 687 | |
| 688 | rc = ssbi_write(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_4, &pon, 1); |
| 689 | if (rc) { |
| 690 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", |
| 691 | __func__, SSBI_REG_ADDR_PON_CNTL_4, pon, rc); |
| 692 | goto err_restore_pon_5; |
| 693 | } |
| 694 | mutex_unlock(&pmic_chip->pm_lock); |
| 695 | return 0; |
| 696 | |
| 697 | err_restore_pon_5: |
| 698 | ret = ssbi_write(pmic_chip->dev, SSBI_REG_ADDR_PON_CNTL_5, &pon_5, 1); |
| 699 | if (ret) |
| 700 | pr_err("%s: FAIL ssbi_write(0x%x)=0x%x: rc=%d\n", |
| 701 | __func__, SSBI_REG_ADDR_PON_CNTL_5, pon, ret); |
| 702 | mutex_unlock(&pmic_chip->pm_lock); |
| 703 | return rc; |
| 704 | } |
| 705 | EXPORT_SYMBOL(pm8058_hard_reset_config); |
| 706 | |
| 707 | /* Internal functions */ |
| 708 | static inline int |
| 709 | pm8058_config_irq(struct pm8058_chip *chip, u8 *bp, u8 *cp) |
| 710 | { |
| 711 | int rc; |
| 712 | |
| 713 | rc = ssbi_write(chip->dev, SSBI_REG_ADDR_IRQ_BLK_SEL, bp, 1); |
| 714 | if (rc) { |
| 715 | pr_err("%s: ssbi_write: rc=%d (Select block)\n", |
| 716 | __func__, rc); |
| 717 | goto bail_out; |
| 718 | } |
| 719 | |
| 720 | rc = ssbi_write(chip->dev, SSBI_REG_ADDR_IRQ_CONFIG, cp, 1); |
| 721 | if (rc) |
| 722 | pr_err("%s: ssbi_write: rc=%d (Configure IRQ)\n", |
| 723 | __func__, rc); |
| 724 | |
| 725 | bail_out: |
| 726 | return rc; |
| 727 | } |
| 728 | |
| 729 | static void pm8058_irq_mask(struct irq_data *data) |
| 730 | { |
| 731 | int master, irq_bit; |
| 732 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 733 | u8 block, config; |
| 734 | unsigned int irq = data->irq; |
| 735 | |
| 736 | irq -= chip->pdata.irq_base; |
| 737 | block = irq / 8; |
| 738 | master = block / 8; |
| 739 | irq_bit = irq % 8; |
| 740 | |
| 741 | chip->irqs_allowed[block] &= ~(1 << irq_bit); |
| 742 | if (!chip->irqs_allowed[block]) { |
| 743 | chip->blocks_allowed[master] &= ~(1 << (block % 8)); |
| 744 | |
| 745 | if (!chip->blocks_allowed[master]) |
| 746 | chip->masters_allowed &= ~(1 << master); |
| 747 | } |
| 748 | |
| 749 | config = PM8058_IRQF_WRITE | chip->config[irq] | |
| 750 | PM8058_IRQF_MASK_FE | PM8058_IRQF_MASK_RE; |
| 751 | chip->bus_unlock_config[irq] = config; |
| 752 | } |
| 753 | |
| 754 | static void pm8058_irq_unmask(struct irq_data *data) |
| 755 | { |
| 756 | int master, irq_bit; |
| 757 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 758 | u8 block, config, old_irqs_allowed, old_blocks_allowed; |
| 759 | unsigned int irq = data->irq; |
| 760 | |
| 761 | irq -= chip->pdata.irq_base; |
| 762 | block = irq / 8; |
| 763 | master = block / 8; |
| 764 | irq_bit = irq % 8; |
| 765 | |
| 766 | old_irqs_allowed = chip->irqs_allowed[block]; |
| 767 | chip->irqs_allowed[block] |= 1 << irq_bit; |
| 768 | if (!old_irqs_allowed) { |
| 769 | master = block / 8; |
| 770 | |
| 771 | old_blocks_allowed = chip->blocks_allowed[master]; |
| 772 | chip->blocks_allowed[master] |= 1 << (block % 8); |
| 773 | |
| 774 | if (!old_blocks_allowed) |
| 775 | chip->masters_allowed |= 1 << master; |
| 776 | } |
| 777 | |
| 778 | config = PM8058_IRQF_WRITE | chip->config[irq]; |
| 779 | chip->bus_unlock_config[irq] = config; |
| 780 | } |
| 781 | |
| 782 | static void pm8058_irq_ack(struct irq_data *data) |
| 783 | { |
| 784 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 785 | u8 block, config; |
| 786 | unsigned int irq = data->irq; |
| 787 | |
| 788 | irq -= chip->pdata.irq_base; |
| 789 | block = irq / 8; |
| 790 | |
| 791 | config = PM8058_IRQF_WRITE | chip->config[irq] | PM8058_IRQF_CLR; |
| 792 | /* Keep the mask */ |
| 793 | if (!(chip->irqs_allowed[block] & (1 << (irq % 8)))) |
| 794 | config |= PM8058_IRQF_MASK_FE | PM8058_IRQF_MASK_RE; |
| 795 | chip->bus_unlock_config[irq] = config; |
| 796 | } |
| 797 | |
| 798 | static int pm8058_irq_set_type(struct irq_data *data, unsigned int flow_type) |
| 799 | { |
| 800 | int master, irq_bit; |
| 801 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 802 | u8 block, config; |
| 803 | unsigned int irq = data->irq; |
| 804 | |
| 805 | irq -= chip->pdata.irq_base; |
| 806 | if (irq > chip->pm_max_irq) { |
| 807 | chip->pm_max_irq = irq; |
| 808 | chip->pm_max_blocks = |
| 809 | chip->pm_max_irq / 8 + 1; |
| 810 | chip->pm_max_masters = |
| 811 | chip->pm_max_blocks / 8 + 1; |
| 812 | } |
| 813 | block = irq / 8; |
| 814 | master = block / 8; |
| 815 | irq_bit = irq % 8; |
| 816 | |
| 817 | chip->config[irq] = (irq_bit << PM8058_IRQF_BITS_SHIFT) | |
| 818 | PM8058_IRQF_MASK_RE | PM8058_IRQF_MASK_FE; |
| 819 | if (flow_type & (IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)) { |
| 820 | if (flow_type & IRQF_TRIGGER_RISING) |
| 821 | chip->config[irq] &= ~PM8058_IRQF_MASK_RE; |
| 822 | if (flow_type & IRQF_TRIGGER_FALLING) |
| 823 | chip->config[irq] &= ~PM8058_IRQF_MASK_FE; |
| 824 | } else { |
| 825 | chip->config[irq] |= PM8058_IRQF_LVL_SEL; |
| 826 | |
| 827 | if (flow_type & IRQF_TRIGGER_HIGH) |
| 828 | chip->config[irq] &= ~PM8058_IRQF_MASK_RE; |
| 829 | else |
| 830 | chip->config[irq] &= ~PM8058_IRQF_MASK_FE; |
| 831 | } |
| 832 | |
| 833 | config = PM8058_IRQF_WRITE | chip->config[irq] | PM8058_IRQF_CLR; |
| 834 | chip->bus_unlock_config[irq] = config; |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int pm8058_irq_set_wake(struct irq_data *data, unsigned int on) |
| 839 | { |
| 840 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 841 | unsigned int irq = data->irq; |
| 842 | |
| 843 | irq -= chip->pdata.irq_base; |
| 844 | if (on) { |
| 845 | if (!chip->wake_enable[irq]) { |
| 846 | chip->wake_enable[irq] = 1; |
| 847 | chip->count_wakeable++; |
| 848 | } |
| 849 | } else { |
| 850 | if (chip->wake_enable[irq]) { |
| 851 | chip->wake_enable[irq] = 0; |
| 852 | chip->count_wakeable--; |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | static void pm8058_irq_bus_lock(struct irq_data *data) |
| 860 | { |
| 861 | u8 block; |
| 862 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 863 | unsigned int irq = data->irq; |
| 864 | |
| 865 | irq -= chip->pdata.irq_base; |
| 866 | block = irq / 8; |
| 867 | chip->bus_unlock_config[irq] = 0; |
| 868 | |
| 869 | mutex_lock(&chip->pm_lock); |
| 870 | } |
| 871 | |
| 872 | static void pm8058_irq_bus_sync_unlock(struct irq_data *data) |
| 873 | { |
| 874 | u8 block, config; |
| 875 | struct pm8058_chip *chip = irq_data_get_irq_chip_data(data); |
| 876 | unsigned int irq = data->irq; |
| 877 | |
| 878 | irq -= chip->pdata.irq_base; |
| 879 | block = irq / 8; |
| 880 | config = chip->bus_unlock_config[irq]; |
| 881 | /* dont waste cpu cycles if we dont have data to write */ |
| 882 | if (config) |
| 883 | pm8058_config_irq(chip, &block, &config); |
| 884 | mutex_unlock(&chip->pm_lock); |
| 885 | } |
| 886 | |
| 887 | static inline int |
| 888 | pm8058_read_root(struct pm8058_chip *chip, u8 *rp) |
| 889 | { |
| 890 | int rc; |
| 891 | |
| 892 | rc = ssbi_read(chip->dev, SSBI_REG_ADDR_IRQ_ROOT, rp, 1); |
| 893 | if (rc) { |
| 894 | pr_err("%s: FAIL ssbi_read(): rc=%d (Read Root)\n", |
| 895 | __func__, rc); |
| 896 | *rp = 0; |
| 897 | } |
| 898 | |
| 899 | return rc; |
| 900 | } |
| 901 | |
| 902 | static inline int |
| 903 | pm8058_read_master(struct pm8058_chip *chip, u8 m, u8 *bp) |
| 904 | { |
| 905 | int rc; |
| 906 | |
| 907 | rc = ssbi_read(chip->dev, SSBI_REG_ADDR_IRQ_M_STATUS1 + m, bp, 1); |
| 908 | if (rc) { |
| 909 | pr_err("%s: FAIL ssbi_read(): rc=%d (Read Master)\n", |
| 910 | __func__, rc); |
| 911 | *bp = 0; |
| 912 | } |
| 913 | |
| 914 | return rc; |
| 915 | } |
| 916 | |
| 917 | static inline int |
| 918 | pm8058_read_block(struct pm8058_chip *chip, u8 *bp, u8 *ip) |
| 919 | { |
| 920 | int rc; |
| 921 | |
| 922 | rc = ssbi_write(chip->dev, SSBI_REG_ADDR_IRQ_BLK_SEL, bp, 1); |
| 923 | if (rc) { |
| 924 | pr_err("%s: FAIL ssbi_write(): rc=%d (Select Block)\n", |
| 925 | __func__, rc); |
| 926 | *bp = 0; |
| 927 | goto bail_out; |
| 928 | } |
| 929 | |
| 930 | rc = ssbi_read(chip->dev, SSBI_REG_ADDR_IRQ_IT_STATUS, ip, 1); |
| 931 | if (rc) |
| 932 | pr_err("%s: FAIL ssbi_read(): rc=%d (Read Status)\n", |
| 933 | __func__, rc); |
| 934 | |
| 935 | bail_out: |
| 936 | return rc; |
| 937 | } |
| 938 | |
| 939 | static irqreturn_t pm8058_isr_thread(int irq_requested, void *data) |
| 940 | { |
| 941 | struct pm8058_chip *chip = data; |
| 942 | int i, j, k; |
| 943 | u8 root, block, config, bits; |
| 944 | u8 blocks[MAX_PM_MASTERS]; |
| 945 | int masters = 0, irq, handled = 0, spurious = 0; |
| 946 | u16 irqs_to_handle[MAX_PM_IRQ]; |
| 947 | |
| 948 | mutex_lock(&chip->pm_lock); |
| 949 | |
| 950 | /* Read root for masters */ |
| 951 | if (pm8058_read_root(chip, &root)) |
| 952 | goto bail_out; |
| 953 | |
| 954 | masters = root >> 1; |
| 955 | |
| 956 | if (!(masters & chip->masters_allowed) || |
| 957 | (masters & ~chip->masters_allowed)) { |
| 958 | spurious = 1000000; |
| 959 | } |
| 960 | |
| 961 | /* Read allowed masters for blocks. */ |
| 962 | for (i = 0; i < chip->pm_max_masters; i++) { |
| 963 | if (masters & (1 << i)) { |
| 964 | if (pm8058_read_master(chip, i, &blocks[i])) |
| 965 | goto bail_out; |
| 966 | |
| 967 | if (!blocks[i]) { |
| 968 | if (pm8058_can_print()) |
| 969 | pr_err("%s: Spurious master: %d " |
| 970 | "(blocks=0)", __func__, i); |
| 971 | spurious += 10000; |
| 972 | } |
| 973 | } else |
| 974 | blocks[i] = 0; |
| 975 | } |
| 976 | |
| 977 | /* Select block, read status and call isr */ |
| 978 | for (i = 0; i < chip->pm_max_masters; i++) { |
| 979 | if (!blocks[i]) |
| 980 | continue; |
| 981 | |
| 982 | for (j = 0; j < 8; j++) { |
| 983 | if (!(blocks[i] & (1 << j))) |
| 984 | continue; |
| 985 | |
| 986 | block = i * 8 + j; /* block # */ |
| 987 | if (pm8058_read_block(chip, &block, &bits)) |
| 988 | goto bail_out; |
| 989 | |
| 990 | if (!bits) { |
| 991 | if (pm8058_can_print()) |
| 992 | pr_err("%s: Spurious block: " |
| 993 | "[master, block]=[%d, %d] " |
| 994 | "(bits=0)\n", __func__, i, j); |
| 995 | spurious += 100; |
| 996 | continue; |
| 997 | } |
| 998 | |
| 999 | /* Check IRQ bits */ |
| 1000 | for (k = 0; k < 8; k++) { |
| 1001 | if (!(bits & (1 << k))) |
| 1002 | continue; |
| 1003 | |
| 1004 | /* Check spurious interrupts */ |
| 1005 | if (((1 << i) & chip->masters_allowed) && |
| 1006 | (blocks[i] & chip->blocks_allowed[i]) && |
| 1007 | (bits & chip->irqs_allowed[block])) { |
| 1008 | |
| 1009 | /* Found one */ |
| 1010 | irq = block * 8 + k; |
| 1011 | irqs_to_handle[handled] = irq + |
| 1012 | chip->pdata.irq_base; |
| 1013 | handled++; |
| 1014 | } else { |
| 1015 | /* Clear and mask wrong one */ |
| 1016 | config = PM8058_IRQF_W_C_M | |
| 1017 | (k << PM8058_IRQF_BITS_SHIFT); |
| 1018 | |
| 1019 | pm8058_config_irq(chip, |
| 1020 | &block, &config); |
| 1021 | |
| 1022 | if (pm8058_can_print()) |
| 1023 | pr_err("%s: Spurious IRQ: " |
| 1024 | "[master, block, bit]=" |
| 1025 | "[%d, %d (%d), %d]\n", |
| 1026 | __func__, |
| 1027 | i, j, block, k); |
| 1028 | spurious++; |
| 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | |
| 1033 | } |
| 1034 | |
| 1035 | bail_out: |
| 1036 | |
| 1037 | mutex_unlock(&chip->pm_lock); |
| 1038 | |
| 1039 | for (i = 0; i < handled; i++) |
| 1040 | handle_nested_irq(irqs_to_handle[i]); |
| 1041 | |
| 1042 | for (i = 0; i < handled; i++) { |
| 1043 | irqs_to_handle[i] -= chip->pdata.irq_base; |
| 1044 | block = irqs_to_handle[i] / 8 ; |
| 1045 | config = PM8058_IRQF_WRITE | chip->config[irqs_to_handle[i]] |
| 1046 | | PM8058_IRQF_CLR; |
| 1047 | pm8058_config_irq(chip, &block, &config); |
| 1048 | } |
| 1049 | |
| 1050 | if (spurious) { |
| 1051 | if (!pm8058_can_print()) |
| 1052 | return IRQ_HANDLED; |
| 1053 | |
| 1054 | pr_err("%s: spurious = %d (handled = %d)\n", |
| 1055 | __func__, spurious, handled); |
| 1056 | pr_err(" root = 0x%x (masters_allowed<<1 = 0x%x)\n", |
| 1057 | root, chip->masters_allowed << 1); |
| 1058 | for (i = 0; i < chip->pm_max_masters; i++) { |
| 1059 | if (masters & (1 << i)) |
| 1060 | pr_err(" blocks[%d]=0x%x, " |
| 1061 | "allowed[%d]=0x%x\n", |
| 1062 | i, blocks[i], |
| 1063 | i, chip->blocks_allowed[i]); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | return IRQ_HANDLED; |
| 1068 | } |
| 1069 | |
| 1070 | #if defined(CONFIG_DEBUG_FS) |
| 1071 | |
| 1072 | static int check_addr(int addr, const char *func_name) |
| 1073 | { |
| 1074 | if (addr < 0 || addr > 0x3FF) { |
| 1075 | pr_err("%s: PMIC 8058 register address is invalid: %d\n", |
| 1076 | func_name, addr); |
| 1077 | return -EINVAL; |
| 1078 | } |
| 1079 | return 0; |
| 1080 | } |
| 1081 | |
| 1082 | static int data_set(void *data, u64 val) |
| 1083 | { |
| 1084 | struct pm8058_dbg_device *dbgdev = data; |
| 1085 | u8 reg = val; |
| 1086 | int rc; |
| 1087 | |
| 1088 | mutex_lock(&dbgdev->dbg_mutex); |
| 1089 | |
| 1090 | rc = check_addr(dbgdev->addr, __func__); |
| 1091 | if (rc) |
| 1092 | goto done; |
| 1093 | |
| 1094 | rc = pm8058_write(dbgdev->pm_chip, dbgdev->addr, ®, 1); |
| 1095 | |
| 1096 | if (rc) |
| 1097 | pr_err("%s: FAIL pm8058_write(0x%03X)=0x%02X: rc=%d\n", |
| 1098 | __func__, dbgdev->addr, reg, rc); |
| 1099 | done: |
| 1100 | mutex_unlock(&dbgdev->dbg_mutex); |
| 1101 | return rc; |
| 1102 | } |
| 1103 | |
| 1104 | static int data_get(void *data, u64 *val) |
| 1105 | { |
| 1106 | struct pm8058_dbg_device *dbgdev = data; |
| 1107 | int rc; |
| 1108 | u8 reg; |
| 1109 | |
| 1110 | mutex_lock(&dbgdev->dbg_mutex); |
| 1111 | |
| 1112 | rc = check_addr(dbgdev->addr, __func__); |
| 1113 | if (rc) |
| 1114 | goto done; |
| 1115 | |
| 1116 | rc = pm8058_read(dbgdev->pm_chip, dbgdev->addr, ®, 1); |
| 1117 | |
| 1118 | if (rc) { |
| 1119 | pr_err("%s: FAIL pm8058_read(0x%03X)=0x%02X: rc=%d\n", |
| 1120 | __func__, dbgdev->addr, reg, rc); |
| 1121 | goto done; |
| 1122 | } |
| 1123 | |
| 1124 | *val = reg; |
| 1125 | done: |
| 1126 | mutex_unlock(&dbgdev->dbg_mutex); |
| 1127 | return rc; |
| 1128 | } |
| 1129 | |
| 1130 | DEFINE_SIMPLE_ATTRIBUTE(dbg_data_fops, data_get, data_set, "0x%02llX\n"); |
| 1131 | |
| 1132 | static int addr_set(void *data, u64 val) |
| 1133 | { |
| 1134 | struct pm8058_dbg_device *dbgdev = data; |
| 1135 | int rc; |
| 1136 | |
| 1137 | rc = check_addr(val, __func__); |
| 1138 | if (rc) |
| 1139 | return rc; |
| 1140 | |
| 1141 | mutex_lock(&dbgdev->dbg_mutex); |
| 1142 | dbgdev->addr = val; |
| 1143 | mutex_unlock(&dbgdev->dbg_mutex); |
| 1144 | |
| 1145 | return 0; |
| 1146 | } |
| 1147 | |
| 1148 | static int addr_get(void *data, u64 *val) |
| 1149 | { |
| 1150 | struct pm8058_dbg_device *dbgdev = data; |
| 1151 | int rc; |
| 1152 | |
| 1153 | mutex_lock(&dbgdev->dbg_mutex); |
| 1154 | |
| 1155 | rc = check_addr(dbgdev->addr, __func__); |
| 1156 | if (rc) { |
| 1157 | mutex_unlock(&dbgdev->dbg_mutex); |
| 1158 | return rc; |
| 1159 | } |
| 1160 | *val = dbgdev->addr; |
| 1161 | |
| 1162 | mutex_unlock(&dbgdev->dbg_mutex); |
| 1163 | |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
| 1167 | DEFINE_SIMPLE_ATTRIBUTE(dbg_addr_fops, addr_get, addr_set, "0x%03llX\n"); |
| 1168 | |
| 1169 | static int __devinit pmic8058_dbg_probe(struct pm8058_chip *chip) |
| 1170 | { |
| 1171 | struct pm8058_dbg_device *dbgdev; |
| 1172 | struct dentry *dent; |
| 1173 | struct dentry *temp; |
| 1174 | |
| 1175 | if (chip == NULL) { |
| 1176 | pr_err("%s: no parent data passed in.\n", __func__); |
| 1177 | return -EINVAL; |
| 1178 | } |
| 1179 | |
| 1180 | dbgdev = kzalloc(sizeof *dbgdev, GFP_KERNEL); |
| 1181 | if (dbgdev == NULL) { |
| 1182 | pr_err("%s: kzalloc() failed.\n", __func__); |
| 1183 | return -ENOMEM; |
| 1184 | } |
| 1185 | |
| 1186 | mutex_init(&dbgdev->dbg_mutex); |
| 1187 | |
| 1188 | dbgdev->pm_chip = chip; |
| 1189 | dbgdev->addr = -1; |
| 1190 | |
| 1191 | dent = debugfs_create_dir("pm8058-dbg", NULL); |
| 1192 | if (dent == NULL || IS_ERR(dent)) { |
| 1193 | pr_err("%s: ERR debugfs_create_dir: dent=0x%X\n", |
| 1194 | __func__, (unsigned)dent); |
| 1195 | return -ENOMEM; |
| 1196 | } |
| 1197 | |
| 1198 | temp = debugfs_create_file("addr", S_IRUSR | S_IWUSR, dent, |
| 1199 | dbgdev, &dbg_addr_fops); |
| 1200 | if (temp == NULL || IS_ERR(temp)) { |
| 1201 | pr_err("%s: ERR debugfs_create_file: dent=0x%X\n", |
| 1202 | __func__, (unsigned)temp); |
| 1203 | goto debug_error; |
| 1204 | } |
| 1205 | |
| 1206 | temp = debugfs_create_file("data", S_IRUSR | S_IWUSR, dent, |
| 1207 | dbgdev, &dbg_data_fops); |
| 1208 | if (temp == NULL || IS_ERR(temp)) { |
| 1209 | pr_err("%s: ERR debugfs_create_file: dent=0x%X\n", |
| 1210 | __func__, (unsigned)temp); |
| 1211 | goto debug_error; |
| 1212 | } |
| 1213 | |
| 1214 | dbgdev->dent = dent; |
| 1215 | |
| 1216 | pmic_dbg_device = dbgdev; |
| 1217 | |
| 1218 | return 0; |
| 1219 | |
| 1220 | debug_error: |
| 1221 | debugfs_remove_recursive(dent); |
| 1222 | return -ENOMEM; |
| 1223 | } |
| 1224 | |
| 1225 | static int __devexit pmic8058_dbg_remove(void) |
| 1226 | { |
| 1227 | if (pmic_dbg_device) { |
| 1228 | debugfs_remove_recursive(pmic_dbg_device->dent); |
| 1229 | kfree(pmic_dbg_device); |
| 1230 | } |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | #else |
| 1235 | |
| 1236 | static int __devinit pmic8058_dbg_probe(struct pm8058_chip *chip) |
| 1237 | { |
| 1238 | return 0; |
| 1239 | } |
| 1240 | |
| 1241 | static int __devexit pmic8058_dbg_remove(void) |
| 1242 | { |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
| 1246 | #endif |
| 1247 | |
| 1248 | static struct irq_chip pm8058_irq_chip = { |
| 1249 | .name = "pm8058", |
| 1250 | .irq_ack = pm8058_irq_ack, |
| 1251 | .irq_mask = pm8058_irq_mask, |
| 1252 | .irq_unmask = pm8058_irq_unmask, |
| 1253 | .irq_set_type = pm8058_irq_set_type, |
| 1254 | .irq_set_wake = pm8058_irq_set_wake, |
| 1255 | .irq_bus_lock = pm8058_irq_bus_lock, |
| 1256 | .irq_bus_sync_unlock = pm8058_irq_bus_sync_unlock, |
| 1257 | }; |
| 1258 | |
Abhijeet Dharmapurikar | a3c0d94 | 2011-07-25 17:53:45 -0700 | [diff] [blame^] | 1259 | static int pm8058_suspend(void) |
| 1260 | { |
| 1261 | struct pm8058_chip *chip = pmic_chip; |
| 1262 | struct irq_data *data; |
| 1263 | int i; |
| 1264 | |
| 1265 | for (i = 0; i < MAX_PM_IRQ; i++) { |
| 1266 | if (chip->config[i] && !chip->wake_enable[i]) { |
| 1267 | if (!((chip->config[i] & PM8058_IRQF_MASK_ALL) |
| 1268 | == PM8058_IRQF_MASK_ALL)) { |
| 1269 | data = irq_get_irq_data(i + |
| 1270 | chip->pdata.irq_base); |
| 1271 | pm8058_irq_bus_lock(data); |
| 1272 | pm8058_irq_mask(data); |
| 1273 | pm8058_irq_bus_sync_unlock(data); |
| 1274 | } |
| 1275 | } |
| 1276 | } |
| 1277 | |
| 1278 | if (!chip->count_wakeable) |
| 1279 | disable_irq(chip->dev->irq); |
| 1280 | |
| 1281 | return 0; |
| 1282 | } |
| 1283 | |
| 1284 | extern int msm_show_resume_irq_mask; |
| 1285 | |
| 1286 | static void pm8058_show_resume_irq(void) |
| 1287 | { |
| 1288 | u8 block, bits; |
| 1289 | int i; |
| 1290 | struct pm8058_chip *chip = pmic_chip; |
| 1291 | |
| 1292 | if (!msm_show_resume_irq_mask) |
| 1293 | return; |
| 1294 | |
| 1295 | for (i = 0; i < MAX_PM_IRQ; i++) { |
| 1296 | if (chip->wake_enable[i]) { |
| 1297 | block = i / 8; |
| 1298 | if (!pm8058_read_block(chip, &block, &bits)) { |
| 1299 | if (bits & (1 << (i & 0x7))) |
| 1300 | pr_warning("%s:%d triggered\n", |
| 1301 | __func__, i + chip->pdata.irq_base); |
| 1302 | } |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | |
| 1307 | static void pm8058_resume(void) |
| 1308 | { |
| 1309 | struct pm8058_chip *chip = pmic_chip; |
| 1310 | struct irq_data *data; |
| 1311 | int i; |
| 1312 | |
| 1313 | pm8058_show_resume_irq(); |
| 1314 | |
| 1315 | for (i = 0; i < MAX_PM_IRQ; i++) { |
| 1316 | if (chip->config[i] && !chip->wake_enable[i]) { |
| 1317 | if (!((chip->config[i] & PM8058_IRQF_MASK_ALL) |
| 1318 | == PM8058_IRQF_MASK_ALL)) { |
| 1319 | data = irq_get_irq_data(i + |
| 1320 | chip->pdata.irq_base); |
| 1321 | pm8058_irq_bus_lock(data); |
| 1322 | pm8058_irq_unmask(data); |
| 1323 | pm8058_irq_bus_sync_unlock(data); |
| 1324 | } |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | if (!chip->count_wakeable) |
| 1329 | enable_irq(chip->dev->irq); |
| 1330 | } |
| 1331 | |
| 1332 | static struct syscore_ops pm8058_pm = { |
| 1333 | .suspend = pm8058_suspend, |
| 1334 | .resume = pm8058_resume, |
| 1335 | }; |
| 1336 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1337 | static int pm8058_probe(struct i2c_client *client, |
| 1338 | const struct i2c_device_id *id) |
| 1339 | { |
| 1340 | int i, rc; |
| 1341 | struct pm8058_platform_data *pdata = client->dev.platform_data; |
| 1342 | struct pm8058_chip *chip; |
| 1343 | |
| 1344 | if (pdata == NULL || !client->irq) { |
| 1345 | pr_err("%s: No platform_data or IRQ.\n", __func__); |
| 1346 | return -ENODEV; |
| 1347 | } |
| 1348 | |
| 1349 | if (pdata->num_subdevs == 0) { |
| 1350 | pr_err("%s: No sub devices to support.\n", __func__); |
| 1351 | return -ENODEV; |
| 1352 | } |
| 1353 | |
| 1354 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C) == 0) { |
| 1355 | pr_err("%s: i2c_check_functionality failed.\n", __func__); |
| 1356 | return -ENODEV; |
| 1357 | } |
| 1358 | |
| 1359 | chip = kzalloc(sizeof *chip, GFP_KERNEL); |
| 1360 | if (chip == NULL) { |
| 1361 | pr_err("%s: kzalloc() failed.\n", __func__); |
| 1362 | return -ENOMEM; |
| 1363 | } |
| 1364 | |
| 1365 | chip->dev = client; |
| 1366 | |
| 1367 | /* Read PMIC chip revision */ |
| 1368 | rc = ssbi_read(chip->dev, SSBI_REG_REV, &chip->revision, 1); |
| 1369 | if (rc) |
| 1370 | pr_err("%s: Failed on ssbi_read for revision: rc=%d.\n", |
| 1371 | __func__, rc); |
| 1372 | pr_info("%s: PMIC revision: %X\n", __func__, chip->revision); |
| 1373 | |
| 1374 | (void) memcpy((void *)&chip->pdata, (const void *)pdata, |
| 1375 | sizeof(chip->pdata)); |
| 1376 | |
| 1377 | mutex_init(&chip->pm_lock); |
| 1378 | irq_set_handler_data(chip->dev->irq, (void *)chip); |
| 1379 | irq_set_irq_wake(chip->dev->irq, 1); |
| 1380 | |
| 1381 | chip->pm_max_irq = 0; |
| 1382 | chip->pm_max_blocks = 0; |
| 1383 | chip->pm_max_masters = 0; |
| 1384 | |
| 1385 | i2c_set_clientdata(client, chip); |
| 1386 | |
| 1387 | pmic_chip = chip; |
| 1388 | |
| 1389 | /* Register for all reserved IRQs */ |
| 1390 | for (i = pdata->irq_base; i < (pdata->irq_base + MAX_PM_IRQ); i++) { |
| 1391 | irq_set_chip(i, &pm8058_irq_chip); |
| 1392 | irq_set_chip_data(i, (void *)chip); |
| 1393 | irq_set_handler(i, handle_edge_irq); |
| 1394 | set_irq_flags(i, IRQF_VALID); |
| 1395 | irq_set_nested_thread(i, 1); |
| 1396 | } |
| 1397 | |
| 1398 | rc = mfd_add_devices(&chip->dev->dev, 0, pdata->sub_devices, |
| 1399 | pdata->num_subdevs, NULL, 0); |
| 1400 | |
| 1401 | /* Add charger sub device with the chip parameter as driver data */ |
| 1402 | if (pdata->charger_sub_device) { |
| 1403 | rc = mfd_add_devices(&chip->dev->dev, 0, |
| 1404 | pdata->charger_sub_device, |
| 1405 | 1, NULL, 0); |
| 1406 | } |
| 1407 | |
| 1408 | if (pdata->init) { |
| 1409 | rc = pdata->init(chip); |
| 1410 | if (rc != 0) { |
| 1411 | pr_err("%s: board init failed\n", __func__); |
| 1412 | chip->dev = NULL; |
| 1413 | kfree(chip); |
| 1414 | return -ENODEV; |
| 1415 | } |
| 1416 | } |
| 1417 | |
| 1418 | rc = request_threaded_irq(chip->dev->irq, NULL, pm8058_isr_thread, |
| 1419 | IRQF_ONESHOT | IRQF_DISABLED | pdata->irq_trigger_flags, |
| 1420 | "pm8058-irq", chip); |
| 1421 | if (rc < 0) |
| 1422 | pr_err("%s: could not request irq %d: %d\n", __func__, |
| 1423 | chip->dev->irq, rc); |
| 1424 | |
| 1425 | rc = pmic8058_dbg_probe(chip); |
| 1426 | if (rc < 0) |
| 1427 | pr_err("%s: could not set up debugfs: %d\n", __func__, rc); |
| 1428 | |
Abhijeet Dharmapurikar | a3c0d94 | 2011-07-25 17:53:45 -0700 | [diff] [blame^] | 1429 | register_syscore_ops(&pm8058_pm); |
| 1430 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1431 | return 0; |
| 1432 | } |
| 1433 | |
| 1434 | static int __devexit pm8058_remove(struct i2c_client *client) |
| 1435 | { |
| 1436 | struct pm8058_chip *chip; |
| 1437 | |
| 1438 | chip = i2c_get_clientdata(client); |
| 1439 | if (chip) { |
| 1440 | if (chip->pm_max_irq) { |
| 1441 | irq_set_irq_wake(chip->dev->irq, 0); |
| 1442 | free_irq(chip->dev->irq, chip); |
| 1443 | } |
| 1444 | mutex_destroy(&chip->pm_lock); |
| 1445 | chip->dev = NULL; |
| 1446 | |
| 1447 | kfree(chip); |
| 1448 | } |
| 1449 | |
| 1450 | pmic8058_dbg_remove(); |
| 1451 | |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1455 | static const struct i2c_device_id pm8058_ids[] = { |
| 1456 | { "pm8058-core", 0 }, |
| 1457 | { }, |
| 1458 | }; |
| 1459 | MODULE_DEVICE_TABLE(i2c, pm8058_ids); |
| 1460 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1461 | static struct i2c_driver pm8058_driver = { |
| 1462 | .driver.name = "pm8058-core", |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1463 | .id_table = pm8058_ids, |
| 1464 | .probe = pm8058_probe, |
| 1465 | .remove = __devexit_p(pm8058_remove), |
| 1466 | }; |
| 1467 | |
| 1468 | static int __init pm8058_init(void) |
| 1469 | { |
| 1470 | int rc = i2c_add_driver(&pm8058_driver); |
| 1471 | pr_notice("%s: i2c_add_driver: rc = %d\n", __func__, rc); |
| 1472 | |
| 1473 | return rc; |
| 1474 | } |
| 1475 | |
| 1476 | static void __exit pm8058_exit(void) |
| 1477 | { |
| 1478 | i2c_del_driver(&pm8058_driver); |
| 1479 | } |
| 1480 | |
| 1481 | arch_initcall(pm8058_init); |
| 1482 | module_exit(pm8058_exit); |
| 1483 | |
| 1484 | MODULE_LICENSE("GPL v2"); |
| 1485 | MODULE_DESCRIPTION("PMIC8058 core driver"); |
| 1486 | MODULE_VERSION("1.0"); |
| 1487 | MODULE_ALIAS("platform:pmic8058-core"); |