88pm860x-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  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. #include <linux/kernel.h>
  12. #include <linux/module.h>
  13. #include <linux/i2c.h>
  14. #include <linux/irq.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mfd/core.h>
  18. #include <linux/mfd/88pm860x.h>
  19. #define INT_STATUS_NUM 3
  20. char pm860x_backlight_name[][MFD_NAME_SIZE] = {
  21. "backlight-0",
  22. "backlight-1",
  23. "backlight-2",
  24. };
  25. EXPORT_SYMBOL(pm860x_backlight_name);
  26. char pm860x_led_name[][MFD_NAME_SIZE] = {
  27. "led0-red",
  28. "led0-green",
  29. "led0-blue",
  30. "led1-red",
  31. "led1-green",
  32. "led1-blue",
  33. };
  34. EXPORT_SYMBOL(pm860x_led_name);
  35. #define PM8606_BACKLIGHT_RESOURCE(_i, _x) \
  36. { \
  37. .name = pm860x_backlight_name[_i], \
  38. .start = PM8606_##_x, \
  39. .end = PM8606_##_x, \
  40. .flags = IORESOURCE_IO, \
  41. }
  42. static struct resource backlight_resources[] = {
  43. PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT1, WLED1A),
  44. PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT2, WLED2A),
  45. PM8606_BACKLIGHT_RESOURCE(PM8606_BACKLIGHT3, WLED3A),
  46. };
  47. #define PM8606_BACKLIGHT_DEVS(_i) \
  48. { \
  49. .name = "88pm860x-backlight", \
  50. .num_resources = 1, \
  51. .resources = &backlight_resources[_i], \
  52. .id = _i, \
  53. }
  54. static struct mfd_cell backlight_devs[] = {
  55. PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT1),
  56. PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT2),
  57. PM8606_BACKLIGHT_DEVS(PM8606_BACKLIGHT3),
  58. };
  59. #define PM8606_LED_RESOURCE(_i, _x) \
  60. { \
  61. .name = pm860x_led_name[_i], \
  62. .start = PM8606_##_x, \
  63. .end = PM8606_##_x, \
  64. .flags = IORESOURCE_IO, \
  65. }
  66. static struct resource led_resources[] = {
  67. PM8606_LED_RESOURCE(PM8606_LED1_RED, RGB2B),
  68. PM8606_LED_RESOURCE(PM8606_LED1_GREEN, RGB2C),
  69. PM8606_LED_RESOURCE(PM8606_LED1_BLUE, RGB2D),
  70. PM8606_LED_RESOURCE(PM8606_LED2_RED, RGB1B),
  71. PM8606_LED_RESOURCE(PM8606_LED2_GREEN, RGB1C),
  72. PM8606_LED_RESOURCE(PM8606_LED2_BLUE, RGB1D),
  73. };
  74. #define PM8606_LED_DEVS(_i) \
  75. { \
  76. .name = "88pm860x-led", \
  77. .num_resources = 1, \
  78. .resources = &led_resources[_i], \
  79. .id = _i, \
  80. }
  81. static struct mfd_cell led_devs[] = {
  82. PM8606_LED_DEVS(PM8606_LED1_RED),
  83. PM8606_LED_DEVS(PM8606_LED1_GREEN),
  84. PM8606_LED_DEVS(PM8606_LED1_BLUE),
  85. PM8606_LED_DEVS(PM8606_LED2_RED),
  86. PM8606_LED_DEVS(PM8606_LED2_GREEN),
  87. PM8606_LED_DEVS(PM8606_LED2_BLUE),
  88. };
  89. static struct resource touch_resources[] = {
  90. {
  91. .start = PM8607_IRQ_PEN,
  92. .end = PM8607_IRQ_PEN,
  93. .flags = IORESOURCE_IRQ,
  94. },
  95. };
  96. static struct mfd_cell touch_devs[] = {
  97. {
  98. .name = "88pm860x-touch",
  99. .num_resources = 1,
  100. .resources = &touch_resources[0],
  101. },
  102. };
  103. #define PM8607_REG_RESOURCE(_start, _end) \
  104. { \
  105. .start = PM8607_##_start, \
  106. .end = PM8607_##_end, \
  107. .flags = IORESOURCE_IO, \
  108. }
  109. static struct resource power_supply_resources[] = {
  110. {
  111. .name = "88pm860x-power",
  112. .start = PM8607_IRQ_CHG,
  113. .end = PM8607_IRQ_CHG,
  114. .flags = IORESOURCE_IRQ,
  115. },
  116. };
  117. static struct mfd_cell power_devs[] = {
  118. {
  119. .name = "88pm860x-power",
  120. .num_resources = 1,
  121. .resources = &power_supply_resources[0],
  122. .id = -1,
  123. },
  124. };
  125. static struct resource onkey_resources[] = {
  126. {
  127. .name = "88pm860x-onkey",
  128. .start = PM8607_IRQ_ONKEY,
  129. .end = PM8607_IRQ_ONKEY,
  130. .flags = IORESOURCE_IRQ,
  131. },
  132. };
  133. static struct mfd_cell onkey_devs[] = {
  134. {
  135. .name = "88pm860x-onkey",
  136. .num_resources = 1,
  137. .resources = &onkey_resources[0],
  138. .id = -1,
  139. },
  140. };
  141. static struct resource regulator_resources[] = {
  142. PM8607_REG_RESOURCE(BUCK1, BUCK1),
  143. PM8607_REG_RESOURCE(BUCK2, BUCK2),
  144. PM8607_REG_RESOURCE(BUCK3, BUCK3),
  145. PM8607_REG_RESOURCE(LDO1, LDO1),
  146. PM8607_REG_RESOURCE(LDO2, LDO2),
  147. PM8607_REG_RESOURCE(LDO3, LDO3),
  148. PM8607_REG_RESOURCE(LDO4, LDO4),
  149. PM8607_REG_RESOURCE(LDO5, LDO5),
  150. PM8607_REG_RESOURCE(LDO6, LDO6),
  151. PM8607_REG_RESOURCE(LDO7, LDO7),
  152. PM8607_REG_RESOURCE(LDO8, LDO8),
  153. PM8607_REG_RESOURCE(LDO9, LDO9),
  154. PM8607_REG_RESOURCE(LDO10, LDO10),
  155. PM8607_REG_RESOURCE(LDO12, LDO12),
  156. PM8607_REG_RESOURCE(VIBRATOR_SET, VIBRATOR_SET),
  157. PM8607_REG_RESOURCE(LDO14, LDO14),
  158. };
  159. #define PM8607_REG_DEVS(_id) \
  160. { \
  161. .name = "88pm860x-regulator", \
  162. .num_resources = 1, \
  163. .resources = &regulator_resources[PM8607_ID_##_id], \
  164. .id = PM8607_ID_##_id, \
  165. }
  166. static struct mfd_cell regulator_devs[] = {
  167. PM8607_REG_DEVS(BUCK1),
  168. PM8607_REG_DEVS(BUCK2),
  169. PM8607_REG_DEVS(BUCK3),
  170. PM8607_REG_DEVS(LDO1),
  171. PM8607_REG_DEVS(LDO2),
  172. PM8607_REG_DEVS(LDO3),
  173. PM8607_REG_DEVS(LDO4),
  174. PM8607_REG_DEVS(LDO5),
  175. PM8607_REG_DEVS(LDO6),
  176. PM8607_REG_DEVS(LDO7),
  177. PM8607_REG_DEVS(LDO8),
  178. PM8607_REG_DEVS(LDO9),
  179. PM8607_REG_DEVS(LDO10),
  180. PM8607_REG_DEVS(LDO12),
  181. PM8607_REG_DEVS(LDO13),
  182. PM8607_REG_DEVS(LDO14),
  183. };
  184. struct pm860x_irq_data {
  185. int reg;
  186. int mask_reg;
  187. int enable; /* enable or not */
  188. int offs; /* bit offset in mask register */
  189. };
  190. static struct pm860x_irq_data pm860x_irqs[] = {
  191. [PM8607_IRQ_ONKEY] = {
  192. .reg = PM8607_INT_STATUS1,
  193. .mask_reg = PM8607_INT_MASK_1,
  194. .offs = 1 << 0,
  195. },
  196. [PM8607_IRQ_EXTON] = {
  197. .reg = PM8607_INT_STATUS1,
  198. .mask_reg = PM8607_INT_MASK_1,
  199. .offs = 1 << 1,
  200. },
  201. [PM8607_IRQ_CHG] = {
  202. .reg = PM8607_INT_STATUS1,
  203. .mask_reg = PM8607_INT_MASK_1,
  204. .offs = 1 << 2,
  205. },
  206. [PM8607_IRQ_BAT] = {
  207. .reg = PM8607_INT_STATUS1,
  208. .mask_reg = PM8607_INT_MASK_1,
  209. .offs = 1 << 3,
  210. },
  211. [PM8607_IRQ_RTC] = {
  212. .reg = PM8607_INT_STATUS1,
  213. .mask_reg = PM8607_INT_MASK_1,
  214. .offs = 1 << 4,
  215. },
  216. [PM8607_IRQ_CC] = {
  217. .reg = PM8607_INT_STATUS1,
  218. .mask_reg = PM8607_INT_MASK_1,
  219. .offs = 1 << 5,
  220. },
  221. [PM8607_IRQ_VBAT] = {
  222. .reg = PM8607_INT_STATUS2,
  223. .mask_reg = PM8607_INT_MASK_2,
  224. .offs = 1 << 0,
  225. },
  226. [PM8607_IRQ_VCHG] = {
  227. .reg = PM8607_INT_STATUS2,
  228. .mask_reg = PM8607_INT_MASK_2,
  229. .offs = 1 << 1,
  230. },
  231. [PM8607_IRQ_VSYS] = {
  232. .reg = PM8607_INT_STATUS2,
  233. .mask_reg = PM8607_INT_MASK_2,
  234. .offs = 1 << 2,
  235. },
  236. [PM8607_IRQ_TINT] = {
  237. .reg = PM8607_INT_STATUS2,
  238. .mask_reg = PM8607_INT_MASK_2,
  239. .offs = 1 << 3,
  240. },
  241. [PM8607_IRQ_GPADC0] = {
  242. .reg = PM8607_INT_STATUS2,
  243. .mask_reg = PM8607_INT_MASK_2,
  244. .offs = 1 << 4,
  245. },
  246. [PM8607_IRQ_GPADC1] = {
  247. .reg = PM8607_INT_STATUS2,
  248. .mask_reg = PM8607_INT_MASK_2,
  249. .offs = 1 << 5,
  250. },
  251. [PM8607_IRQ_GPADC2] = {
  252. .reg = PM8607_INT_STATUS2,
  253. .mask_reg = PM8607_INT_MASK_2,
  254. .offs = 1 << 6,
  255. },
  256. [PM8607_IRQ_GPADC3] = {
  257. .reg = PM8607_INT_STATUS2,
  258. .mask_reg = PM8607_INT_MASK_2,
  259. .offs = 1 << 7,
  260. },
  261. [PM8607_IRQ_AUDIO_SHORT] = {
  262. .reg = PM8607_INT_STATUS3,
  263. .mask_reg = PM8607_INT_MASK_3,
  264. .offs = 1 << 0,
  265. },
  266. [PM8607_IRQ_PEN] = {
  267. .reg = PM8607_INT_STATUS3,
  268. .mask_reg = PM8607_INT_MASK_3,
  269. .offs = 1 << 1,
  270. },
  271. [PM8607_IRQ_HEADSET] = {
  272. .reg = PM8607_INT_STATUS3,
  273. .mask_reg = PM8607_INT_MASK_3,
  274. .offs = 1 << 2,
  275. },
  276. [PM8607_IRQ_HOOK] = {
  277. .reg = PM8607_INT_STATUS3,
  278. .mask_reg = PM8607_INT_MASK_3,
  279. .offs = 1 << 3,
  280. },
  281. [PM8607_IRQ_MICIN] = {
  282. .reg = PM8607_INT_STATUS3,
  283. .mask_reg = PM8607_INT_MASK_3,
  284. .offs = 1 << 4,
  285. },
  286. [PM8607_IRQ_CHG_FAIL] = {
  287. .reg = PM8607_INT_STATUS3,
  288. .mask_reg = PM8607_INT_MASK_3,
  289. .offs = 1 << 5,
  290. },
  291. [PM8607_IRQ_CHG_DONE] = {
  292. .reg = PM8607_INT_STATUS3,
  293. .mask_reg = PM8607_INT_MASK_3,
  294. .offs = 1 << 6,
  295. },
  296. [PM8607_IRQ_CHG_FAULT] = {
  297. .reg = PM8607_INT_STATUS3,
  298. .mask_reg = PM8607_INT_MASK_3,
  299. .offs = 1 << 7,
  300. },
  301. };
  302. static inline struct pm860x_irq_data *irq_to_pm860x(struct pm860x_chip *chip,
  303. int irq)
  304. {
  305. return &pm860x_irqs[irq - chip->irq_base];
  306. }
  307. static irqreturn_t pm860x_irq(int irq, void *data)
  308. {
  309. struct pm860x_chip *chip = data;
  310. struct pm860x_irq_data *irq_data;
  311. struct i2c_client *i2c;
  312. int read_reg = -1, value = 0;
  313. int i;
  314. i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  315. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  316. irq_data = &pm860x_irqs[i];
  317. if (read_reg != irq_data->reg) {
  318. read_reg = irq_data->reg;
  319. value = pm860x_reg_read(i2c, irq_data->reg);
  320. }
  321. if (value & irq_data->enable)
  322. handle_nested_irq(chip->irq_base + i);
  323. }
  324. return IRQ_HANDLED;
  325. }
  326. static void pm860x_irq_lock(unsigned int irq)
  327. {
  328. struct pm860x_chip *chip = get_irq_chip_data(irq);
  329. mutex_lock(&chip->irq_lock);
  330. }
  331. static void pm860x_irq_sync_unlock(unsigned int irq)
  332. {
  333. struct pm860x_chip *chip = get_irq_chip_data(irq);
  334. struct pm860x_irq_data *irq_data;
  335. struct i2c_client *i2c;
  336. static unsigned char cached[3] = {0x0, 0x0, 0x0};
  337. unsigned char mask[3];
  338. int i;
  339. i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  340. /* Load cached value. In initial, all IRQs are masked */
  341. for (i = 0; i < 3; i++)
  342. mask[i] = cached[i];
  343. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  344. irq_data = &pm860x_irqs[i];
  345. switch (irq_data->mask_reg) {
  346. case PM8607_INT_MASK_1:
  347. mask[0] &= ~irq_data->offs;
  348. mask[0] |= irq_data->enable;
  349. break;
  350. case PM8607_INT_MASK_2:
  351. mask[1] &= ~irq_data->offs;
  352. mask[1] |= irq_data->enable;
  353. break;
  354. case PM8607_INT_MASK_3:
  355. mask[2] &= ~irq_data->offs;
  356. mask[2] |= irq_data->enable;
  357. break;
  358. default:
  359. dev_err(chip->dev, "wrong IRQ\n");
  360. break;
  361. }
  362. }
  363. /* update mask into registers */
  364. for (i = 0; i < 3; i++) {
  365. if (mask[i] != cached[i]) {
  366. cached[i] = mask[i];
  367. pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]);
  368. }
  369. }
  370. mutex_unlock(&chip->irq_lock);
  371. }
  372. static void pm860x_irq_enable(unsigned int irq)
  373. {
  374. struct pm860x_chip *chip = get_irq_chip_data(irq);
  375. pm860x_irqs[irq - chip->irq_base].enable
  376. = pm860x_irqs[irq - chip->irq_base].offs;
  377. }
  378. static void pm860x_irq_disable(unsigned int irq)
  379. {
  380. struct pm860x_chip *chip = get_irq_chip_data(irq);
  381. pm860x_irqs[irq - chip->irq_base].enable = 0;
  382. }
  383. static struct irq_chip pm860x_irq_chip = {
  384. .name = "88pm860x",
  385. .bus_lock = pm860x_irq_lock,
  386. .bus_sync_unlock = pm860x_irq_sync_unlock,
  387. .enable = pm860x_irq_enable,
  388. .disable = pm860x_irq_disable,
  389. };
  390. static int __devinit device_gpadc_init(struct pm860x_chip *chip,
  391. struct pm860x_platform_data *pdata)
  392. {
  393. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  394. : chip->companion;
  395. int use_gpadc = 0, data, ret;
  396. /* initialize GPADC without activating it */
  397. if (pdata && pdata->touch) {
  398. /* set GPADC MISC1 register */
  399. data = 0;
  400. data |= (pdata->touch->gpadc_prebias << 1)
  401. & PM8607_GPADC_PREBIAS_MASK;
  402. data |= (pdata->touch->slot_cycle << 3)
  403. & PM8607_GPADC_SLOT_CYCLE_MASK;
  404. data |= (pdata->touch->off_scale << 5)
  405. & PM8607_GPADC_OFF_SCALE_MASK;
  406. data |= (pdata->touch->sw_cal << 7)
  407. & PM8607_GPADC_SW_CAL_MASK;
  408. if (data) {
  409. ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
  410. if (ret < 0)
  411. goto out;
  412. }
  413. /* set tsi prebias time */
  414. if (pdata->touch->tsi_prebias) {
  415. data = pdata->touch->tsi_prebias;
  416. ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
  417. if (ret < 0)
  418. goto out;
  419. }
  420. /* set prebias & prechg time of pen detect */
  421. data = 0;
  422. data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
  423. data |= (pdata->touch->pen_prechg << 5)
  424. & PM8607_PD_PRECHG_MASK;
  425. if (data) {
  426. ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
  427. if (ret < 0)
  428. goto out;
  429. }
  430. use_gpadc = 1;
  431. }
  432. /* turn on GPADC */
  433. if (use_gpadc) {
  434. ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
  435. PM8607_GPADC_EN, PM8607_GPADC_EN);
  436. }
  437. out:
  438. return ret;
  439. }
  440. static int __devinit device_irq_init(struct pm860x_chip *chip,
  441. struct pm860x_platform_data *pdata)
  442. {
  443. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  444. : chip->companion;
  445. unsigned char status_buf[INT_STATUS_NUM];
  446. unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  447. struct irq_desc *desc;
  448. int i, data, mask, ret = -EINVAL;
  449. int __irq;
  450. if (!pdata || !pdata->irq_base) {
  451. dev_warn(chip->dev, "No interrupt support on IRQ base\n");
  452. return -EINVAL;
  453. }
  454. mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR
  455. | PM8607_B0_MISC1_INT_MASK;
  456. data = 0;
  457. chip->irq_mode = 0;
  458. if (pdata && pdata->irq_mode) {
  459. /*
  460. * irq_mode defines the way of clearing interrupt. If it's 1,
  461. * clear IRQ by write. Otherwise, clear it by read.
  462. * This control bit is valid from 88PM8607 B0 steping.
  463. */
  464. data |= PM8607_B0_MISC1_INT_CLEAR;
  465. chip->irq_mode = 1;
  466. }
  467. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data);
  468. if (ret < 0)
  469. goto out;
  470. /* mask all IRQs */
  471. memset(status_buf, 0, INT_STATUS_NUM);
  472. ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1,
  473. INT_STATUS_NUM, status_buf);
  474. if (ret < 0)
  475. goto out;
  476. if (chip->irq_mode) {
  477. /* clear interrupt status by write */
  478. memset(status_buf, 0xFF, INT_STATUS_NUM);
  479. ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1,
  480. INT_STATUS_NUM, status_buf);
  481. } else {
  482. /* clear interrupt status by read */
  483. ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1,
  484. INT_STATUS_NUM, status_buf);
  485. }
  486. if (ret < 0)
  487. goto out;
  488. mutex_init(&chip->irq_lock);
  489. chip->irq_base = pdata->irq_base;
  490. chip->core_irq = i2c->irq;
  491. if (!chip->core_irq)
  492. goto out;
  493. desc = irq_to_desc(chip->core_irq);
  494. /* register IRQ by genirq */
  495. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  496. __irq = i + chip->irq_base;
  497. set_irq_chip_data(__irq, chip);
  498. set_irq_chip_and_handler(__irq, &pm860x_irq_chip,
  499. handle_edge_irq);
  500. set_irq_nested_thread(__irq, 1);
  501. #ifdef CONFIG_ARM
  502. set_irq_flags(__irq, IRQF_VALID);
  503. #else
  504. set_irq_noprobe(__irq);
  505. #endif
  506. }
  507. ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags,
  508. "88pm860x", chip);
  509. if (ret) {
  510. dev_err(chip->dev, "Failed to request IRQ: %d\n", ret);
  511. chip->core_irq = 0;
  512. }
  513. return 0;
  514. out:
  515. chip->core_irq = 0;
  516. return ret;
  517. }
  518. static void device_irq_exit(struct pm860x_chip *chip)
  519. {
  520. if (chip->core_irq)
  521. free_irq(chip->core_irq, chip);
  522. }
  523. static void __devinit device_8606_init(struct pm860x_chip *chip,
  524. struct i2c_client *i2c,
  525. struct pm860x_platform_data *pdata)
  526. {
  527. int ret;
  528. if (pdata && pdata->backlight) {
  529. ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
  530. ARRAY_SIZE(backlight_devs),
  531. &backlight_resources[0], 0);
  532. if (ret < 0) {
  533. dev_err(chip->dev, "Failed to add backlight "
  534. "subdev\n");
  535. goto out_dev;
  536. }
  537. }
  538. if (pdata && pdata->led) {
  539. ret = mfd_add_devices(chip->dev, 0, &led_devs[0],
  540. ARRAY_SIZE(led_devs),
  541. &led_resources[0], 0);
  542. if (ret < 0) {
  543. dev_err(chip->dev, "Failed to add led "
  544. "subdev\n");
  545. goto out_dev;
  546. }
  547. }
  548. return;
  549. out_dev:
  550. mfd_remove_devices(chip->dev);
  551. device_irq_exit(chip);
  552. }
  553. static void __devinit device_8607_init(struct pm860x_chip *chip,
  554. struct i2c_client *i2c,
  555. struct pm860x_platform_data *pdata)
  556. {
  557. int data, ret;
  558. ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
  559. if (ret < 0) {
  560. dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
  561. goto out;
  562. }
  563. if ((ret & PM8607_VERSION_MASK) == PM8607_VERSION)
  564. dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n",
  565. ret);
  566. else {
  567. dev_err(chip->dev, "Failed to detect Marvell 88PM8607. "
  568. "Chip ID: %02x\n", ret);
  569. goto out;
  570. }
  571. ret = pm860x_reg_read(i2c, PM8607_BUCK3);
  572. if (ret < 0) {
  573. dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret);
  574. goto out;
  575. }
  576. if (ret & PM8607_BUCK3_DOUBLE)
  577. chip->buck3_double = 1;
  578. ret = pm860x_reg_read(i2c, PM8607_B0_MISC1);
  579. if (ret < 0) {
  580. dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret);
  581. goto out;
  582. }
  583. if (pdata && (pdata->i2c_port == PI2C_PORT))
  584. data = PM8607_B0_MISC1_PI2C;
  585. else
  586. data = 0;
  587. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data);
  588. if (ret < 0) {
  589. dev_err(chip->dev, "Failed to access MISC1:%d\n", ret);
  590. goto out;
  591. }
  592. ret = device_gpadc_init(chip, pdata);
  593. if (ret < 0)
  594. goto out;
  595. ret = device_irq_init(chip, pdata);
  596. if (ret < 0)
  597. goto out;
  598. ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
  599. ARRAY_SIZE(regulator_devs),
  600. &regulator_resources[0], 0);
  601. if (ret < 0) {
  602. dev_err(chip->dev, "Failed to add regulator subdev\n");
  603. goto out_dev;
  604. }
  605. if (pdata && pdata->touch) {
  606. ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
  607. ARRAY_SIZE(touch_devs),
  608. &touch_resources[0], 0);
  609. if (ret < 0) {
  610. dev_err(chip->dev, "Failed to add touch "
  611. "subdev\n");
  612. goto out_dev;
  613. }
  614. }
  615. if (pdata && pdata->power) {
  616. ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
  617. ARRAY_SIZE(power_devs),
  618. &power_supply_resources[0], 0);
  619. if (ret < 0) {
  620. dev_err(chip->dev, "Failed to add power supply "
  621. "subdev\n");
  622. goto out_dev;
  623. }
  624. }
  625. ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
  626. ARRAY_SIZE(onkey_devs),
  627. &onkey_resources[0], 0);
  628. if (ret < 0) {
  629. dev_err(chip->dev, "Failed to add onkey subdev\n");
  630. goto out_dev;
  631. }
  632. return;
  633. out_dev:
  634. mfd_remove_devices(chip->dev);
  635. device_irq_exit(chip);
  636. out:
  637. return;
  638. }
  639. int __devinit pm860x_device_init(struct pm860x_chip *chip,
  640. struct pm860x_platform_data *pdata)
  641. {
  642. chip->core_irq = 0;
  643. switch (chip->id) {
  644. case CHIP_PM8606:
  645. device_8606_init(chip, chip->client, pdata);
  646. break;
  647. case CHIP_PM8607:
  648. device_8607_init(chip, chip->client, pdata);
  649. break;
  650. }
  651. if (chip->companion) {
  652. switch (chip->id) {
  653. case CHIP_PM8607:
  654. device_8606_init(chip, chip->companion, pdata);
  655. break;
  656. case CHIP_PM8606:
  657. device_8607_init(chip, chip->companion, pdata);
  658. break;
  659. }
  660. }
  661. return 0;
  662. }
  663. void __devexit pm860x_device_exit(struct pm860x_chip *chip)
  664. {
  665. device_irq_exit(chip);
  666. mfd_remove_devices(chip->dev);
  667. }
  668. MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
  669. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  670. MODULE_LICENSE("GPL");