88pm860x-core.c 18 KB

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