1 /* 2 * Base driver for Marvell 88PM8607 3 * 4 * Copyright (C) 2009 Marvell International Ltd. 5 * Haojian Zhuang <haojian.zhuang@marvell.com> 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License version 2 as 9 * published by the Free Software Foundation. 10 */ 11 12 #include <linux/kernel.h> 13 #include <linux/module.h> 14 #include <linux/err.h> 15 #include <linux/i2c.h> 16 #include <linux/irq.h> 17 #include <linux/interrupt.h> 18 #include <linux/platform_device.h> 19 #include <linux/regmap.h> 20 #include <linux/slab.h> 21 #include <linux/mfd/core.h> 22 #include <linux/mfd/88pm860x.h> 23 #include <linux/regulator/machine.h> 24 25 #define INT_STATUS_NUM 3 26 27 static struct resource bk0_resources[] __devinitdata = { 28 {2, 2, "duty cycle", IORESOURCE_REG, }, 29 {3, 3, "always on", IORESOURCE_REG, }, 30 {3, 3, "current", IORESOURCE_REG, }, 31 }; 32 static struct resource bk1_resources[] __devinitdata = { 33 {4, 4, "duty cycle", IORESOURCE_REG, }, 34 {5, 5, "always on", IORESOURCE_REG, }, 35 {5, 5, "current", IORESOURCE_REG, }, 36 }; 37 static struct resource bk2_resources[] __devinitdata = { 38 {6, 6, "duty cycle", IORESOURCE_REG, }, 39 {7, 7, "always on", IORESOURCE_REG, }, 40 {5, 5, "current", IORESOURCE_REG, }, 41 }; 42 43 static struct resource led0_resources[] __devinitdata = { 44 /* RGB1 Red LED */ 45 {0xd, 0xd, "control", IORESOURCE_REG, }, 46 {0xc, 0xc, "blink", IORESOURCE_REG, }, 47 }; 48 static struct resource led1_resources[] __devinitdata = { 49 /* RGB1 Green LED */ 50 {0xe, 0xe, "control", IORESOURCE_REG, }, 51 {0xc, 0xc, "blink", IORESOURCE_REG, }, 52 }; 53 static struct resource led2_resources[] __devinitdata = { 54 /* RGB1 Blue LED */ 55 {0xf, 0xf, "control", IORESOURCE_REG, }, 56 {0xc, 0xc, "blink", IORESOURCE_REG, }, 57 }; 58 static struct resource led3_resources[] __devinitdata = { 59 /* RGB2 Red LED */ 60 {0x9, 0x9, "control", IORESOURCE_REG, }, 61 {0x8, 0x8, "blink", IORESOURCE_REG, }, 62 }; 63 static struct resource led4_resources[] __devinitdata = { 64 /* RGB2 Green LED */ 65 {0xa, 0xa, "control", IORESOURCE_REG, }, 66 {0x8, 0x8, "blink", IORESOURCE_REG, }, 67 }; 68 static struct resource led5_resources[] __devinitdata = { 69 /* RGB2 Blue LED */ 70 {0xb, 0xb, "control", IORESOURCE_REG, }, 71 {0x8, 0x8, "blink", IORESOURCE_REG, }, 72 }; 73 74 static struct resource buck1_resources[] __devinitdata = { 75 {0x24, 0x24, "buck set", IORESOURCE_REG, }, 76 }; 77 static struct resource buck2_resources[] __devinitdata = { 78 {0x25, 0x25, "buck set", IORESOURCE_REG, }, 79 }; 80 static struct resource buck3_resources[] __devinitdata = { 81 {0x26, 0x26, "buck set", IORESOURCE_REG, }, 82 }; 83 static struct resource ldo1_resources[] __devinitdata = { 84 {0x10, 0x10, "ldo set", IORESOURCE_REG, }, 85 }; 86 static struct resource ldo2_resources[] __devinitdata = { 87 {0x11, 0x11, "ldo set", IORESOURCE_REG, }, 88 }; 89 static struct resource ldo3_resources[] __devinitdata = { 90 {0x12, 0x12, "ldo set", IORESOURCE_REG, }, 91 }; 92 static struct resource ldo4_resources[] __devinitdata = { 93 {0x13, 0x13, "ldo set", IORESOURCE_REG, }, 94 }; 95 static struct resource ldo5_resources[] __devinitdata = { 96 {0x14, 0x14, "ldo set", IORESOURCE_REG, }, 97 }; 98 static struct resource ldo6_resources[] __devinitdata = { 99 {0x15, 0x15, "ldo set", IORESOURCE_REG, }, 100 }; 101 static struct resource ldo7_resources[] __devinitdata = { 102 {0x16, 0x16, "ldo set", IORESOURCE_REG, }, 103 }; 104 static struct resource ldo8_resources[] __devinitdata = { 105 {0x17, 0x17, "ldo set", IORESOURCE_REG, }, 106 }; 107 static struct resource ldo9_resources[] __devinitdata = { 108 {0x18, 0x18, "ldo set", IORESOURCE_REG, }, 109 }; 110 static struct resource ldo10_resources[] __devinitdata = { 111 {0x19, 0x19, "ldo set", IORESOURCE_REG, }, 112 }; 113 static struct resource ldo12_resources[] __devinitdata = { 114 {0x1a, 0x1a, "ldo set", IORESOURCE_REG, }, 115 }; 116 static struct resource ldo_vibrator_resources[] __devinitdata = { 117 {0x28, 0x28, "ldo set", IORESOURCE_REG, }, 118 }; 119 static struct resource ldo14_resources[] __devinitdata = { 120 {0x1b, 0x1b, "ldo set", IORESOURCE_REG, }, 121 }; 122 123 static struct resource touch_resources[] __devinitdata = { 124 {PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,}, 125 }; 126 127 static struct resource onkey_resources[] __devinitdata = { 128 {PM8607_IRQ_ONKEY, PM8607_IRQ_ONKEY, "onkey", IORESOURCE_IRQ,}, 129 }; 130 131 static struct resource codec_resources[] __devinitdata = { 132 /* Headset microphone insertion or removal */ 133 {PM8607_IRQ_MICIN, PM8607_IRQ_MICIN, "micin", IORESOURCE_IRQ,}, 134 /* Hook-switch press or release */ 135 {PM8607_IRQ_HOOK, PM8607_IRQ_HOOK, "hook", IORESOURCE_IRQ,}, 136 /* Headset insertion or removal */ 137 {PM8607_IRQ_HEADSET, PM8607_IRQ_HEADSET, "headset", IORESOURCE_IRQ,}, 138 /* Audio short */ 139 {PM8607_IRQ_AUDIO_SHORT, PM8607_IRQ_AUDIO_SHORT, "audio-short", IORESOURCE_IRQ,}, 140 }; 141 142 static struct resource battery_resources[] __devinitdata = { 143 {PM8607_IRQ_CC, PM8607_IRQ_CC, "columb counter", IORESOURCE_IRQ,}, 144 {PM8607_IRQ_BAT, PM8607_IRQ_BAT, "battery", IORESOURCE_IRQ,}, 145 }; 146 147 static struct resource charger_resources[] __devinitdata = { 148 {PM8607_IRQ_CHG, PM8607_IRQ_CHG, "charger detect", IORESOURCE_IRQ,}, 149 {PM8607_IRQ_CHG_DONE, PM8607_IRQ_CHG_DONE, "charging done", IORESOURCE_IRQ,}, 150 {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging timeout", IORESOURCE_IRQ,}, 151 {PM8607_IRQ_GPADC1, PM8607_IRQ_GPADC1, "battery temperature", IORESOURCE_IRQ,}, 152 {PM8607_IRQ_VBAT, PM8607_IRQ_VBAT, "battery voltage", IORESOURCE_IRQ,}, 153 {PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage", IORESOURCE_IRQ,}, 154 }; 155 156 static struct resource rtc_resources[] __devinitdata = { 157 {PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,}, 158 }; 159 160 static struct mfd_cell bk_devs[] __devinitdata = { 161 { 162 .name = "88pm860x-backlight", 163 .id = 0, 164 .num_resources = ARRAY_SIZE(bk0_resources), 165 .resources = bk0_resources, 166 }, { 167 .name = "88pm860x-backlight", 168 .id = 1, 169 .num_resources = ARRAY_SIZE(bk1_resources), 170 .resources = bk1_resources, 171 }, { 172 .name = "88pm860x-backlight", 173 .id = 2, 174 .num_resources = ARRAY_SIZE(bk2_resources), 175 .resources = bk2_resources, 176 }, 177 }; 178 179 static struct mfd_cell led_devs[] __devinitdata = { 180 { 181 .name = "88pm860x-led", 182 .id = 0, 183 .num_resources = ARRAY_SIZE(led0_resources), 184 .resources = led0_resources, 185 }, { 186 .name = "88pm860x-led", 187 .id = 1, 188 .num_resources = ARRAY_SIZE(led1_resources), 189 .resources = led1_resources, 190 }, { 191 .name = "88pm860x-led", 192 .id = 2, 193 .num_resources = ARRAY_SIZE(led2_resources), 194 .resources = led2_resources, 195 }, { 196 .name = "88pm860x-led", 197 .id = 3, 198 .num_resources = ARRAY_SIZE(led3_resources), 199 .resources = led3_resources, 200 }, { 201 .name = "88pm860x-led", 202 .id = 4, 203 .num_resources = ARRAY_SIZE(led4_resources), 204 .resources = led4_resources, 205 }, { 206 .name = "88pm860x-led", 207 .id = 5, 208 .num_resources = ARRAY_SIZE(led5_resources), 209 .resources = led5_resources, 210 }, 211 }; 212 213 static struct mfd_cell reg_devs[] __devinitdata = { 214 { 215 .name = "88pm860x-regulator", 216 .id = 0, 217 .num_resources = ARRAY_SIZE(buck1_resources), 218 .resources = buck1_resources, 219 }, { 220 .name = "88pm860x-regulator", 221 .id = 1, 222 .num_resources = ARRAY_SIZE(buck2_resources), 223 .resources = buck2_resources, 224 }, { 225 .name = "88pm860x-regulator", 226 .id = 2, 227 .num_resources = ARRAY_SIZE(buck3_resources), 228 .resources = buck3_resources, 229 }, { 230 .name = "88pm860x-regulator", 231 .id = 3, 232 .num_resources = ARRAY_SIZE(ldo1_resources), 233 .resources = ldo1_resources, 234 }, { 235 .name = "88pm860x-regulator", 236 .id = 4, 237 .num_resources = ARRAY_SIZE(ldo2_resources), 238 .resources = ldo2_resources, 239 }, { 240 .name = "88pm860x-regulator", 241 .id = 5, 242 .num_resources = ARRAY_SIZE(ldo3_resources), 243 .resources = ldo3_resources, 244 }, { 245 .name = "88pm860x-regulator", 246 .id = 6, 247 .num_resources = ARRAY_SIZE(ldo4_resources), 248 .resources = ldo4_resources, 249 }, { 250 .name = "88pm860x-regulator", 251 .id = 7, 252 .num_resources = ARRAY_SIZE(ldo5_resources), 253 .resources = ldo5_resources, 254 }, { 255 .name = "88pm860x-regulator", 256 .id = 8, 257 .num_resources = ARRAY_SIZE(ldo6_resources), 258 .resources = ldo6_resources, 259 }, { 260 .name = "88pm860x-regulator", 261 .id = 9, 262 .num_resources = ARRAY_SIZE(ldo7_resources), 263 .resources = ldo7_resources, 264 }, { 265 .name = "88pm860x-regulator", 266 .id = 10, 267 .num_resources = ARRAY_SIZE(ldo8_resources), 268 .resources = ldo8_resources, 269 }, { 270 .name = "88pm860x-regulator", 271 .id = 11, 272 .num_resources = ARRAY_SIZE(ldo9_resources), 273 .resources = ldo9_resources, 274 }, { 275 .name = "88pm860x-regulator", 276 .id = 12, 277 .num_resources = ARRAY_SIZE(ldo10_resources), 278 .resources = ldo10_resources, 279 }, { 280 .name = "88pm860x-regulator", 281 .id = 13, 282 .num_resources = ARRAY_SIZE(ldo12_resources), 283 .resources = ldo12_resources, 284 }, { 285 .name = "88pm860x-regulator", 286 .id = 14, 287 .num_resources = ARRAY_SIZE(ldo_vibrator_resources), 288 .resources = ldo_vibrator_resources, 289 }, { 290 .name = "88pm860x-regulator", 291 .id = 15, 292 .num_resources = ARRAY_SIZE(ldo14_resources), 293 .resources = ldo14_resources, 294 }, 295 }; 296 297 static struct mfd_cell touch_devs[] = { 298 {"88pm860x-touch", -1,}, 299 }; 300 301 static struct mfd_cell onkey_devs[] = { 302 {"88pm860x-onkey", -1,}, 303 }; 304 305 static struct mfd_cell codec_devs[] = { 306 {"88pm860x-codec", -1,}, 307 }; 308 309 static struct regulator_consumer_supply preg_supply[] = { 310 REGULATOR_SUPPLY("preg", "charger-manager"), 311 }; 312 313 static struct regulator_init_data preg_init_data = { 314 .num_consumer_supplies = ARRAY_SIZE(preg_supply), 315 .consumer_supplies = &preg_supply[0], 316 }; 317 318 static struct mfd_cell power_devs[] = { 319 {"88pm860x-battery", -1,}, 320 {"88pm860x-charger", -1,}, 321 {"88pm860x-preg", -1,}, 322 }; 323 324 static struct mfd_cell rtc_devs[] = { 325 {"88pm860x-rtc", -1,}, 326 }; 327 328 329 struct pm860x_irq_data { 330 int reg; 331 int mask_reg; 332 int enable; /* enable or not */ 333 int offs; /* bit offset in mask register */ 334 }; 335 336 static struct pm860x_irq_data pm860x_irqs[] = { 337 [PM8607_IRQ_ONKEY] = { 338 .reg = PM8607_INT_STATUS1, 339 .mask_reg = PM8607_INT_MASK_1, 340 .offs = 1 << 0, 341 }, 342 [PM8607_IRQ_EXTON] = { 343 .reg = PM8607_INT_STATUS1, 344 .mask_reg = PM8607_INT_MASK_1, 345 .offs = 1 << 1, 346 }, 347 [PM8607_IRQ_CHG] = { 348 .reg = PM8607_INT_STATUS1, 349 .mask_reg = PM8607_INT_MASK_1, 350 .offs = 1 << 2, 351 }, 352 [PM8607_IRQ_BAT] = { 353 .reg = PM8607_INT_STATUS1, 354 .mask_reg = PM8607_INT_MASK_1, 355 .offs = 1 << 3, 356 }, 357 [PM8607_IRQ_RTC] = { 358 .reg = PM8607_INT_STATUS1, 359 .mask_reg = PM8607_INT_MASK_1, 360 .offs = 1 << 4, 361 }, 362 [PM8607_IRQ_CC] = { 363 .reg = PM8607_INT_STATUS1, 364 .mask_reg = PM8607_INT_MASK_1, 365 .offs = 1 << 5, 366 }, 367 [PM8607_IRQ_VBAT] = { 368 .reg = PM8607_INT_STATUS2, 369 .mask_reg = PM8607_INT_MASK_2, 370 .offs = 1 << 0, 371 }, 372 [PM8607_IRQ_VCHG] = { 373 .reg = PM8607_INT_STATUS2, 374 .mask_reg = PM8607_INT_MASK_2, 375 .offs = 1 << 1, 376 }, 377 [PM8607_IRQ_VSYS] = { 378 .reg = PM8607_INT_STATUS2, 379 .mask_reg = PM8607_INT_MASK_2, 380 .offs = 1 << 2, 381 }, 382 [PM8607_IRQ_TINT] = { 383 .reg = PM8607_INT_STATUS2, 384 .mask_reg = PM8607_INT_MASK_2, 385 .offs = 1 << 3, 386 }, 387 [PM8607_IRQ_GPADC0] = { 388 .reg = PM8607_INT_STATUS2, 389 .mask_reg = PM8607_INT_MASK_2, 390 .offs = 1 << 4, 391 }, 392 [PM8607_IRQ_GPADC1] = { 393 .reg = PM8607_INT_STATUS2, 394 .mask_reg = PM8607_INT_MASK_2, 395 .offs = 1 << 5, 396 }, 397 [PM8607_IRQ_GPADC2] = { 398 .reg = PM8607_INT_STATUS2, 399 .mask_reg = PM8607_INT_MASK_2, 400 .offs = 1 << 6, 401 }, 402 [PM8607_IRQ_GPADC3] = { 403 .reg = PM8607_INT_STATUS2, 404 .mask_reg = PM8607_INT_MASK_2, 405 .offs = 1 << 7, 406 }, 407 [PM8607_IRQ_AUDIO_SHORT] = { 408 .reg = PM8607_INT_STATUS3, 409 .mask_reg = PM8607_INT_MASK_3, 410 .offs = 1 << 0, 411 }, 412 [PM8607_IRQ_PEN] = { 413 .reg = PM8607_INT_STATUS3, 414 .mask_reg = PM8607_INT_MASK_3, 415 .offs = 1 << 1, 416 }, 417 [PM8607_IRQ_HEADSET] = { 418 .reg = PM8607_INT_STATUS3, 419 .mask_reg = PM8607_INT_MASK_3, 420 .offs = 1 << 2, 421 }, 422 [PM8607_IRQ_HOOK] = { 423 .reg = PM8607_INT_STATUS3, 424 .mask_reg = PM8607_INT_MASK_3, 425 .offs = 1 << 3, 426 }, 427 [PM8607_IRQ_MICIN] = { 428 .reg = PM8607_INT_STATUS3, 429 .mask_reg = PM8607_INT_MASK_3, 430 .offs = 1 << 4, 431 }, 432 [PM8607_IRQ_CHG_FAIL] = { 433 .reg = PM8607_INT_STATUS3, 434 .mask_reg = PM8607_INT_MASK_3, 435 .offs = 1 << 5, 436 }, 437 [PM8607_IRQ_CHG_DONE] = { 438 .reg = PM8607_INT_STATUS3, 439 .mask_reg = PM8607_INT_MASK_3, 440 .offs = 1 << 6, 441 }, 442 [PM8607_IRQ_CHG_FAULT] = { 443 .reg = PM8607_INT_STATUS3, 444 .mask_reg = PM8607_INT_MASK_3, 445 .offs = 1 << 7, 446 }, 447 }; 448 449 static irqreturn_t pm860x_irq(int irq, void *data) 450 { 451 struct pm860x_chip *chip = data; 452 struct pm860x_irq_data *irq_data; 453 struct i2c_client *i2c; 454 int read_reg = -1, value = 0; 455 int i; 456 457 i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; 458 for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { 459 irq_data = &pm860x_irqs[i]; 460 if (read_reg != irq_data->reg) { 461 read_reg = irq_data->reg; 462 value = pm860x_reg_read(i2c, irq_data->reg); 463 } 464 if (value & irq_data->enable) 465 handle_nested_irq(chip->irq_base + i); 466 } 467 return IRQ_HANDLED; 468 } 469 470 static void pm860x_irq_lock(struct irq_data *data) 471 { 472 struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); 473 474 mutex_lock(&chip->irq_lock); 475 } 476 477 static void pm860x_irq_sync_unlock(struct irq_data *data) 478 { 479 struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); 480 struct pm860x_irq_data *irq_data; 481 struct i2c_client *i2c; 482 static unsigned char cached[3] = {0x0, 0x0, 0x0}; 483 unsigned char mask[3]; 484 int i; 485 486 i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion; 487 /* Load cached value. In initial, all IRQs are masked */ 488 for (i = 0; i < 3; i++) 489 mask[i] = cached[i]; 490 for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { 491 irq_data = &pm860x_irqs[i]; 492 switch (irq_data->mask_reg) { 493 case PM8607_INT_MASK_1: 494 mask[0] &= ~irq_data->offs; 495 mask[0] |= irq_data->enable; 496 break; 497 case PM8607_INT_MASK_2: 498 mask[1] &= ~irq_data->offs; 499 mask[1] |= irq_data->enable; 500 break; 501 case PM8607_INT_MASK_3: 502 mask[2] &= ~irq_data->offs; 503 mask[2] |= irq_data->enable; 504 break; 505 default: 506 dev_err(chip->dev, "wrong IRQ\n"); 507 break; 508 } 509 } 510 /* update mask into registers */ 511 for (i = 0; i < 3; i++) { 512 if (mask[i] != cached[i]) { 513 cached[i] = mask[i]; 514 pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]); 515 } 516 } 517 518 mutex_unlock(&chip->irq_lock); 519 } 520 521 static void pm860x_irq_enable(struct irq_data *data) 522 { 523 struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); 524 pm860x_irqs[data->irq - chip->irq_base].enable 525 = pm860x_irqs[data->irq - chip->irq_base].offs; 526 } 527 528 static void pm860x_irq_disable(struct irq_data *data) 529 { 530 struct pm860x_chip *chip = irq_data_get_irq_chip_data(data); 531 pm860x_irqs[data->irq - chip->irq_base].enable = 0; 532 } 533 534 static struct irq_chip pm860x_irq_chip = { 535 .name = "88pm860x", 536 .irq_bus_lock = pm860x_irq_lock, 537 .irq_bus_sync_unlock = pm860x_irq_sync_unlock, 538 .irq_enable = pm860x_irq_enable, 539 .irq_disable = pm860x_irq_disable, 540 }; 541 542 static int __devinit device_gpadc_init(struct pm860x_chip *chip, 543 struct pm860x_platform_data *pdata) 544 { 545 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ 546 : chip->companion; 547 int data; 548 int ret; 549 550 /* initialize GPADC without activating it */ 551 552 if (!pdata || !pdata->touch) 553 return -EINVAL; 554 555 /* set GPADC MISC1 register */ 556 data = 0; 557 data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK; 558 data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK; 559 data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK; 560 data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK; 561 if (data) { 562 ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data); 563 if (ret < 0) 564 goto out; 565 } 566 /* set tsi prebias time */ 567 if (pdata->touch->tsi_prebias) { 568 data = pdata->touch->tsi_prebias; 569 ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data); 570 if (ret < 0) 571 goto out; 572 } 573 /* set prebias & prechg time of pen detect */ 574 data = 0; 575 data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK; 576 data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK; 577 if (data) { 578 ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data); 579 if (ret < 0) 580 goto out; 581 } 582 583 ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1, 584 PM8607_GPADC_EN, PM8607_GPADC_EN); 585 out: 586 return ret; 587 } 588 589 static int __devinit device_irq_init(struct pm860x_chip *chip, 590 struct pm860x_platform_data *pdata) 591 { 592 struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \ 593 : chip->companion; 594 unsigned char status_buf[INT_STATUS_NUM]; 595 unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT; 596 int i, data, mask, ret = -EINVAL; 597 int __irq; 598 599 if (!pdata || !pdata->irq_base) { 600 dev_warn(chip->dev, "No interrupt support on IRQ base\n"); 601 return -EINVAL; 602 } 603 604 mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR 605 | PM8607_B0_MISC1_INT_MASK; 606 data = 0; 607 chip->irq_mode = 0; 608 if (pdata && pdata->irq_mode) { 609 /* 610 * irq_mode defines the way of clearing interrupt. If it's 1, 611 * clear IRQ by write. Otherwise, clear it by read. 612 * This control bit is valid from 88PM8607 B0 steping. 613 */ 614 data |= PM8607_B0_MISC1_INT_CLEAR; 615 chip->irq_mode = 1; 616 } 617 ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data); 618 if (ret < 0) 619 goto out; 620 621 /* mask all IRQs */ 622 memset(status_buf, 0, INT_STATUS_NUM); 623 ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1, 624 INT_STATUS_NUM, status_buf); 625 if (ret < 0) 626 goto out; 627 628 if (chip->irq_mode) { 629 /* clear interrupt status by write */ 630 memset(status_buf, 0xFF, INT_STATUS_NUM); 631 ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1, 632 INT_STATUS_NUM, status_buf); 633 } else { 634 /* clear interrupt status by read */ 635 ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1, 636 INT_STATUS_NUM, status_buf); 637 } 638 if (ret < 0) 639 goto out; 640 641 mutex_init(&chip->irq_lock); 642 chip->irq_base = pdata->irq_base; 643 chip->core_irq = i2c->irq; 644 if (!chip->core_irq) 645 goto out; 646 647 /* register IRQ by genirq */ 648 for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) { 649 __irq = i + chip->irq_base; 650 irq_set_chip_data(__irq, chip); 651 irq_set_chip_and_handler(__irq, &pm860x_irq_chip, 652 handle_edge_irq); 653 irq_set_nested_thread(__irq, 1); 654 #ifdef CONFIG_ARM 655 set_irq_flags(__irq, IRQF_VALID); 656 #else 657 irq_set_noprobe(__irq); 658 #endif 659 } 660 661 ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags | IRQF_ONESHOT, 662 "88pm860x", chip); 663 if (ret) { 664 dev_err(chip->dev, "Failed to request IRQ: %d\n", ret); 665 chip->core_irq = 0; 666 } 667 668 return 0; 669 out: 670 chip->core_irq = 0; 671 return ret; 672 } 673 674 static void device_irq_exit(struct pm860x_chip *chip) 675 { 676 if (chip->core_irq) 677 free_irq(chip->core_irq, chip); 678 } 679 680 int pm8606_osc_enable(struct pm860x_chip *chip, unsigned short client) 681 { 682 int ret = -EIO; 683 struct i2c_client *i2c = (chip->id == CHIP_PM8606) ? 684 chip->client : chip->companion; 685 686 dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client); 687 dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n", 688 __func__, chip->osc_vote, 689 chip->osc_status); 690 691 mutex_lock(&chip->osc_lock); 692 /* Update voting status */ 693 chip->osc_vote |= client; 694 /* If reference group is off - turn on*/ 695 if (chip->osc_status != PM8606_REF_GP_OSC_ON) { 696 chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN; 697 /* Enable Reference group Vsys */ 698 if (pm860x_set_bits(i2c, PM8606_VSYS, 699 PM8606_VSYS_EN, PM8606_VSYS_EN)) 700 goto out; 701 702 /*Enable Internal Oscillator */ 703 if (pm860x_set_bits(i2c, PM8606_MISC, 704 PM8606_MISC_OSC_EN, PM8606_MISC_OSC_EN)) 705 goto out; 706 /* Update status (only if writes succeed) */ 707 chip->osc_status = PM8606_REF_GP_OSC_ON; 708 } 709 mutex_unlock(&chip->osc_lock); 710 711 dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n", 712 __func__, chip->osc_vote, 713 chip->osc_status, ret); 714 return 0; 715 out: 716 mutex_unlock(&chip->osc_lock); 717 return ret; 718 } 719 EXPORT_SYMBOL(pm8606_osc_enable); 720 721 int pm8606_osc_disable(struct pm860x_chip *chip, unsigned short client) 722 { 723 int ret = -EIO; 724 struct i2c_client *i2c = (chip->id == CHIP_PM8606) ? 725 chip->client : chip->companion; 726 727 dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client); 728 dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n", 729 __func__, chip->osc_vote, 730 chip->osc_status); 731 732 mutex_lock(&chip->osc_lock); 733 /*Update voting status */ 734 chip->osc_vote &= ~(client); 735 /* If reference group is off and this is the last client to release 736 * - turn off */ 737 if ((chip->osc_status != PM8606_REF_GP_OSC_OFF) && 738 (chip->osc_vote == REF_GP_NO_CLIENTS)) { 739 chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN; 740 /* Disable Reference group Vsys */ 741 if (pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0)) 742 goto out; 743 /* Disable Internal Oscillator */ 744 if (pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0)) 745 goto out; 746 chip->osc_status = PM8606_REF_GP_OSC_OFF; 747 } 748 mutex_unlock(&chip->osc_lock); 749 750 dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n", 751 __func__, chip->osc_vote, 752 chip->osc_status, ret); 753 return 0; 754 out: 755 mutex_unlock(&chip->osc_lock); 756 return ret; 757 } 758 EXPORT_SYMBOL(pm8606_osc_disable); 759 760 static void __devinit device_osc_init(struct i2c_client *i2c) 761 { 762 struct pm860x_chip *chip = i2c_get_clientdata(i2c); 763 764 mutex_init(&chip->osc_lock); 765 /* init portofino reference group voting and status */ 766 /* Disable Reference group Vsys */ 767 pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0); 768 /* Disable Internal Oscillator */ 769 pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0); 770 771 chip->osc_vote = REF_GP_NO_CLIENTS; 772 chip->osc_status = PM8606_REF_GP_OSC_OFF; 773 } 774 775 static void __devinit device_bk_init(struct pm860x_chip *chip, 776 struct pm860x_platform_data *pdata) 777 { 778 int ret, i; 779 780 if (pdata && pdata->backlight) { 781 if (pdata->num_backlights > ARRAY_SIZE(bk_devs)) 782 pdata->num_backlights = ARRAY_SIZE(bk_devs); 783 for (i = 0; i < pdata->num_backlights; i++) { 784 bk_devs[i].platform_data = &pdata->backlight[i]; 785 bk_devs[i].pdata_size = 786 sizeof(struct pm860x_backlight_pdata); 787 } 788 } 789 ret = mfd_add_devices(chip->dev, 0, bk_devs, 790 ARRAY_SIZE(bk_devs), NULL, 0, NULL); 791 if (ret < 0) 792 dev_err(chip->dev, "Failed to add backlight subdev\n"); 793 } 794 795 static void __devinit device_led_init(struct pm860x_chip *chip, 796 struct pm860x_platform_data *pdata) 797 { 798 int ret, i; 799 800 if (pdata && pdata->led) { 801 if (pdata->num_leds > ARRAY_SIZE(led_devs)) 802 pdata->num_leds = ARRAY_SIZE(led_devs); 803 for (i = 0; i < pdata->num_leds; i++) { 804 led_devs[i].platform_data = &pdata->led[i]; 805 led_devs[i].pdata_size = 806 sizeof(struct pm860x_led_pdata); 807 } 808 } 809 ret = mfd_add_devices(chip->dev, 0, led_devs, 810 ARRAY_SIZE(led_devs), NULL, 0, NULL); 811 if (ret < 0) { 812 dev_err(chip->dev, "Failed to add led subdev\n"); 813 return; 814 } 815 } 816 817 static void __devinit device_regulator_init(struct pm860x_chip *chip, 818 struct pm860x_platform_data *pdata) 819 { 820 int ret; 821 822 if (pdata == NULL) 823 return; 824 if (pdata->buck1) { 825 reg_devs[0].platform_data = pdata->buck1; 826 reg_devs[0].pdata_size = sizeof(struct regulator_init_data); 827 } 828 if (pdata->buck2) { 829 reg_devs[1].platform_data = pdata->buck2; 830 reg_devs[1].pdata_size = sizeof(struct regulator_init_data); 831 } 832 if (pdata->buck3) { 833 reg_devs[2].platform_data = pdata->buck3; 834 reg_devs[2].pdata_size = sizeof(struct regulator_init_data); 835 } 836 if (pdata->ldo1) { 837 reg_devs[3].platform_data = pdata->ldo1; 838 reg_devs[3].pdata_size = sizeof(struct regulator_init_data); 839 } 840 if (pdata->ldo2) { 841 reg_devs[4].platform_data = pdata->ldo2; 842 reg_devs[4].pdata_size = sizeof(struct regulator_init_data); 843 } 844 if (pdata->ldo3) { 845 reg_devs[5].platform_data = pdata->ldo3; 846 reg_devs[5].pdata_size = sizeof(struct regulator_init_data); 847 } 848 if (pdata->ldo4) { 849 reg_devs[6].platform_data = pdata->ldo4; 850 reg_devs[6].pdata_size = sizeof(struct regulator_init_data); 851 } 852 if (pdata->ldo5) { 853 reg_devs[7].platform_data = pdata->ldo5; 854 reg_devs[7].pdata_size = sizeof(struct regulator_init_data); 855 } 856 if (pdata->ldo6) { 857 reg_devs[8].platform_data = pdata->ldo6; 858 reg_devs[8].pdata_size = sizeof(struct regulator_init_data); 859 } 860 if (pdata->ldo7) { 861 reg_devs[9].platform_data = pdata->ldo7; 862 reg_devs[9].pdata_size = sizeof(struct regulator_init_data); 863 } 864 if (pdata->ldo8) { 865 reg_devs[10].platform_data = pdata->ldo8; 866 reg_devs[10].pdata_size = sizeof(struct regulator_init_data); 867 } 868 if (pdata->ldo9) { 869 reg_devs[11].platform_data = pdata->ldo9; 870 reg_devs[11].pdata_size = sizeof(struct regulator_init_data); 871 } 872 if (pdata->ldo10) { 873 reg_devs[12].platform_data = pdata->ldo10; 874 reg_devs[12].pdata_size = sizeof(struct regulator_init_data); 875 } 876 if (pdata->ldo12) { 877 reg_devs[13].platform_data = pdata->ldo12; 878 reg_devs[13].pdata_size = sizeof(struct regulator_init_data); 879 } 880 if (pdata->ldo_vibrator) { 881 reg_devs[14].platform_data = pdata->ldo_vibrator; 882 reg_devs[14].pdata_size = sizeof(struct regulator_init_data); 883 } 884 if (pdata->ldo14) { 885 reg_devs[15].platform_data = pdata->ldo14; 886 reg_devs[15].pdata_size = sizeof(struct regulator_init_data); 887 } 888 ret = mfd_add_devices(chip->dev, 0, reg_devs, 889 ARRAY_SIZE(reg_devs), NULL, 0, NULL); 890 if (ret < 0) { 891 dev_err(chip->dev, "Failed to add regulator subdev\n"); 892 return; 893 } 894 } 895 896 static void __devinit device_rtc_init(struct pm860x_chip *chip, 897 struct pm860x_platform_data *pdata) 898 { 899 int ret; 900 901 if ((pdata == NULL)) 902 return; 903 904 rtc_devs[0].platform_data = pdata->rtc; 905 rtc_devs[0].pdata_size = sizeof(struct pm860x_rtc_pdata); 906 rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources); 907 rtc_devs[0].resources = &rtc_resources[0]; 908 ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0], 909 ARRAY_SIZE(rtc_devs), &rtc_resources[0], 910 chip->irq_base, NULL); 911 if (ret < 0) 912 dev_err(chip->dev, "Failed to add rtc subdev\n"); 913 } 914 915 static void __devinit device_touch_init(struct pm860x_chip *chip, 916 struct pm860x_platform_data *pdata) 917 { 918 int ret; 919 920 if (pdata == NULL) 921 return; 922 923 touch_devs[0].platform_data = pdata->touch; 924 touch_devs[0].pdata_size = sizeof(struct pm860x_touch_pdata); 925 touch_devs[0].num_resources = ARRAY_SIZE(touch_resources); 926 touch_devs[0].resources = &touch_resources[0]; 927 ret = mfd_add_devices(chip->dev, 0, &touch_devs[0], 928 ARRAY_SIZE(touch_devs), &touch_resources[0], 929 chip->irq_base, NULL); 930 if (ret < 0) 931 dev_err(chip->dev, "Failed to add touch subdev\n"); 932 } 933 934 static void __devinit device_power_init(struct pm860x_chip *chip, 935 struct pm860x_platform_data *pdata) 936 { 937 int ret; 938 939 if (pdata == NULL) 940 return; 941 942 power_devs[0].platform_data = pdata->power; 943 power_devs[0].pdata_size = sizeof(struct pm860x_power_pdata); 944 power_devs[0].num_resources = ARRAY_SIZE(battery_resources); 945 power_devs[0].resources = &battery_resources[0], 946 ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1, 947 &battery_resources[0], chip->irq_base, NULL); 948 if (ret < 0) 949 dev_err(chip->dev, "Failed to add battery subdev\n"); 950 951 power_devs[1].platform_data = pdata->power; 952 power_devs[1].pdata_size = sizeof(struct pm860x_power_pdata); 953 power_devs[1].num_resources = ARRAY_SIZE(charger_resources); 954 power_devs[1].resources = &charger_resources[0], 955 ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1, 956 &charger_resources[0], chip->irq_base, NULL); 957 if (ret < 0) 958 dev_err(chip->dev, "Failed to add charger subdev\n"); 959 960 power_devs[2].platform_data = &preg_init_data; 961 power_devs[2].pdata_size = sizeof(struct regulator_init_data); 962 ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1, 963 NULL, chip->irq_base, NULL); 964 if (ret < 0) 965 dev_err(chip->dev, "Failed to add preg subdev\n"); 966 } 967 968 static void __devinit device_onkey_init(struct pm860x_chip *chip, 969 struct pm860x_platform_data *pdata) 970 { 971 int ret; 972 973 onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources); 974 onkey_devs[0].resources = &onkey_resources[0], 975 ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0], 976 ARRAY_SIZE(onkey_devs), &onkey_resources[0], 977 chip->irq_base, NULL); 978 if (ret < 0) 979 dev_err(chip->dev, "Failed to add onkey subdev\n"); 980 } 981 982 static void __devinit device_codec_init(struct pm860x_chip *chip, 983 struct pm860x_platform_data *pdata) 984 { 985 int ret; 986 987 codec_devs[0].num_resources = ARRAY_SIZE(codec_resources); 988 codec_devs[0].resources = &codec_resources[0], 989 ret = mfd_add_devices(chip->dev, 0, &codec_devs[0], 990 ARRAY_SIZE(codec_devs), &codec_resources[0], 0, 991 NULL); 992 if (ret < 0) 993 dev_err(chip->dev, "Failed to add codec subdev\n"); 994 } 995 996 static void __devinit device_8607_init(struct pm860x_chip *chip, 997 struct i2c_client *i2c, 998 struct pm860x_platform_data *pdata) 999 { 1000 int data, ret; 1001 1002 ret = pm860x_reg_read(i2c, PM8607_CHIP_ID); 1003 if (ret < 0) { 1004 dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret); 1005 goto out; 1006 } 1007 switch (ret & PM8607_VERSION_MASK) { 1008 case 0x40: 1009 case 0x50: 1010 dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n", 1011 ret); 1012 break; 1013 default: 1014 dev_err(chip->dev, "Failed to detect Marvell 88PM8607. " 1015 "Chip ID: %02x\n", ret); 1016 goto out; 1017 } 1018 1019 ret = pm860x_reg_read(i2c, PM8607_BUCK3); 1020 if (ret < 0) { 1021 dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret); 1022 goto out; 1023 } 1024 if (ret & PM8607_BUCK3_DOUBLE) 1025 chip->buck3_double = 1; 1026 1027 ret = pm860x_reg_read(i2c, PM8607_B0_MISC1); 1028 if (ret < 0) { 1029 dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret); 1030 goto out; 1031 } 1032 1033 if (pdata && (pdata->i2c_port == PI2C_PORT)) 1034 data = PM8607_B0_MISC1_PI2C; 1035 else 1036 data = 0; 1037 ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data); 1038 if (ret < 0) { 1039 dev_err(chip->dev, "Failed to access MISC1:%d\n", ret); 1040 goto out; 1041 } 1042 1043 ret = device_gpadc_init(chip, pdata); 1044 if (ret < 0) 1045 goto out; 1046 1047 ret = device_irq_init(chip, pdata); 1048 if (ret < 0) 1049 goto out; 1050 1051 device_regulator_init(chip, pdata); 1052 device_rtc_init(chip, pdata); 1053 device_onkey_init(chip, pdata); 1054 device_touch_init(chip, pdata); 1055 device_power_init(chip, pdata); 1056 device_codec_init(chip, pdata); 1057 out: 1058 return; 1059 } 1060 1061 static void __devinit device_8606_init(struct pm860x_chip *chip, 1062 struct i2c_client *i2c, 1063 struct pm860x_platform_data *pdata) 1064 { 1065 device_osc_init(i2c); 1066 device_bk_init(chip, pdata); 1067 device_led_init(chip, pdata); 1068 } 1069 1070 static int __devinit pm860x_device_init(struct pm860x_chip *chip, 1071 struct pm860x_platform_data *pdata) 1072 { 1073 chip->core_irq = 0; 1074 1075 switch (chip->id) { 1076 case CHIP_PM8606: 1077 device_8606_init(chip, chip->client, pdata); 1078 break; 1079 case CHIP_PM8607: 1080 device_8607_init(chip, chip->client, pdata); 1081 break; 1082 } 1083 1084 if (chip->companion) { 1085 switch (chip->id) { 1086 case CHIP_PM8607: 1087 device_8606_init(chip, chip->companion, pdata); 1088 break; 1089 case CHIP_PM8606: 1090 device_8607_init(chip, chip->companion, pdata); 1091 break; 1092 } 1093 } 1094 1095 return 0; 1096 } 1097 1098 static void __devexit pm860x_device_exit(struct pm860x_chip *chip) 1099 { 1100 device_irq_exit(chip); 1101 mfd_remove_devices(chip->dev); 1102 } 1103 1104 static const struct i2c_device_id pm860x_id_table[] = { 1105 { "88PM860x", 0 }, 1106 {} 1107 }; 1108 MODULE_DEVICE_TABLE(i2c, pm860x_id_table); 1109 1110 static int verify_addr(struct i2c_client *i2c) 1111 { 1112 unsigned short addr_8607[] = {0x30, 0x34}; 1113 unsigned short addr_8606[] = {0x10, 0x11}; 1114 int size, i; 1115 1116 if (i2c == NULL) 1117 return 0; 1118 size = ARRAY_SIZE(addr_8606); 1119 for (i = 0; i < size; i++) { 1120 if (i2c->addr == *(addr_8606 + i)) 1121 return CHIP_PM8606; 1122 } 1123 size = ARRAY_SIZE(addr_8607); 1124 for (i = 0; i < size; i++) { 1125 if (i2c->addr == *(addr_8607 + i)) 1126 return CHIP_PM8607; 1127 } 1128 return 0; 1129 } 1130 1131 static struct regmap_config pm860x_regmap_config = { 1132 .reg_bits = 8, 1133 .val_bits = 8, 1134 }; 1135 1136 static int __devinit pm860x_probe(struct i2c_client *client, 1137 const struct i2c_device_id *id) 1138 { 1139 struct pm860x_platform_data *pdata = client->dev.platform_data; 1140 struct pm860x_chip *chip; 1141 int ret; 1142 1143 if (!pdata) { 1144 pr_info("No platform data in %s!\n", __func__); 1145 return -EINVAL; 1146 } 1147 1148 chip = kzalloc(sizeof(struct pm860x_chip), GFP_KERNEL); 1149 if (chip == NULL) 1150 return -ENOMEM; 1151 1152 chip->id = verify_addr(client); 1153 chip->regmap = regmap_init_i2c(client, &pm860x_regmap_config); 1154 if (IS_ERR(chip->regmap)) { 1155 ret = PTR_ERR(chip->regmap); 1156 dev_err(&client->dev, "Failed to allocate register map: %d\n", 1157 ret); 1158 kfree(chip); 1159 return ret; 1160 } 1161 chip->client = client; 1162 i2c_set_clientdata(client, chip); 1163 chip->dev = &client->dev; 1164 dev_set_drvdata(chip->dev, chip); 1165 1166 /* 1167 * Both client and companion client shares same platform driver. 1168 * Driver distinguishes them by pdata->companion_addr. 1169 * pdata->companion_addr is only assigned if companion chip exists. 1170 * At the same time, the companion_addr shouldn't equal to client 1171 * address. 1172 */ 1173 if (pdata->companion_addr && (pdata->companion_addr != client->addr)) { 1174 chip->companion_addr = pdata->companion_addr; 1175 chip->companion = i2c_new_dummy(chip->client->adapter, 1176 chip->companion_addr); 1177 chip->regmap_companion = regmap_init_i2c(chip->companion, 1178 &pm860x_regmap_config); 1179 if (IS_ERR(chip->regmap_companion)) { 1180 ret = PTR_ERR(chip->regmap_companion); 1181 dev_err(&chip->companion->dev, 1182 "Failed to allocate register map: %d\n", ret); 1183 return ret; 1184 } 1185 i2c_set_clientdata(chip->companion, chip); 1186 } 1187 1188 pm860x_device_init(chip, pdata); 1189 return 0; 1190 } 1191 1192 static int __devexit pm860x_remove(struct i2c_client *client) 1193 { 1194 struct pm860x_chip *chip = i2c_get_clientdata(client); 1195 1196 pm860x_device_exit(chip); 1197 if (chip->companion) { 1198 regmap_exit(chip->regmap_companion); 1199 i2c_unregister_device(chip->companion); 1200 } 1201 regmap_exit(chip->regmap); 1202 kfree(chip); 1203 return 0; 1204 } 1205 1206 #ifdef CONFIG_PM_SLEEP 1207 static int pm860x_suspend(struct device *dev) 1208 { 1209 struct i2c_client *client = container_of(dev, struct i2c_client, dev); 1210 struct pm860x_chip *chip = i2c_get_clientdata(client); 1211 1212 if (device_may_wakeup(dev) && chip->wakeup_flag) 1213 enable_irq_wake(chip->core_irq); 1214 return 0; 1215 } 1216 1217 static int pm860x_resume(struct device *dev) 1218 { 1219 struct i2c_client *client = container_of(dev, struct i2c_client, dev); 1220 struct pm860x_chip *chip = i2c_get_clientdata(client); 1221 1222 if (device_may_wakeup(dev) && chip->wakeup_flag) 1223 disable_irq_wake(chip->core_irq); 1224 return 0; 1225 } 1226 #endif 1227 1228 static SIMPLE_DEV_PM_OPS(pm860x_pm_ops, pm860x_suspend, pm860x_resume); 1229 1230 static struct i2c_driver pm860x_driver = { 1231 .driver = { 1232 .name = "88PM860x", 1233 .owner = THIS_MODULE, 1234 .pm = &pm860x_pm_ops, 1235 }, 1236 .probe = pm860x_probe, 1237 .remove = __devexit_p(pm860x_remove), 1238 .id_table = pm860x_id_table, 1239 }; 1240 1241 static int __init pm860x_i2c_init(void) 1242 { 1243 int ret; 1244 ret = i2c_add_driver(&pm860x_driver); 1245 if (ret != 0) 1246 pr_err("Failed to register 88PM860x I2C driver: %d\n", ret); 1247 return ret; 1248 } 1249 subsys_initcall(pm860x_i2c_init); 1250 1251 static void __exit pm860x_i2c_exit(void) 1252 { 1253 i2c_del_driver(&pm860x_driver); 1254 } 1255 module_exit(pm860x_i2c_exit); 1256 1257 MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x"); 1258 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); 1259 MODULE_LICENSE("GPL"); 1260