88pm860x-core.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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 irqreturn_t pm860x_irq(int irq, void *data)
  338. {
  339. struct pm860x_chip *chip = data;
  340. struct pm860x_irq_data *irq_data;
  341. struct i2c_client *i2c;
  342. int read_reg = -1, value = 0;
  343. int i;
  344. i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  345. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  346. irq_data = &pm860x_irqs[i];
  347. if (read_reg != irq_data->reg) {
  348. read_reg = irq_data->reg;
  349. value = pm860x_reg_read(i2c, irq_data->reg);
  350. }
  351. if (value & irq_data->enable)
  352. handle_nested_irq(chip->irq_base + i);
  353. }
  354. return IRQ_HANDLED;
  355. }
  356. static void pm860x_irq_lock(struct irq_data *data)
  357. {
  358. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  359. mutex_lock(&chip->irq_lock);
  360. }
  361. static void pm860x_irq_sync_unlock(struct irq_data *data)
  362. {
  363. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  364. struct pm860x_irq_data *irq_data;
  365. struct i2c_client *i2c;
  366. static unsigned char cached[3] = {0x0, 0x0, 0x0};
  367. unsigned char mask[3];
  368. int i;
  369. i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  370. /* Load cached value. In initial, all IRQs are masked */
  371. for (i = 0; i < 3; i++)
  372. mask[i] = cached[i];
  373. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  374. irq_data = &pm860x_irqs[i];
  375. switch (irq_data->mask_reg) {
  376. case PM8607_INT_MASK_1:
  377. mask[0] &= ~irq_data->offs;
  378. mask[0] |= irq_data->enable;
  379. break;
  380. case PM8607_INT_MASK_2:
  381. mask[1] &= ~irq_data->offs;
  382. mask[1] |= irq_data->enable;
  383. break;
  384. case PM8607_INT_MASK_3:
  385. mask[2] &= ~irq_data->offs;
  386. mask[2] |= irq_data->enable;
  387. break;
  388. default:
  389. dev_err(chip->dev, "wrong IRQ\n");
  390. break;
  391. }
  392. }
  393. /* update mask into registers */
  394. for (i = 0; i < 3; i++) {
  395. if (mask[i] != cached[i]) {
  396. cached[i] = mask[i];
  397. pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]);
  398. }
  399. }
  400. mutex_unlock(&chip->irq_lock);
  401. }
  402. static void pm860x_irq_enable(struct irq_data *data)
  403. {
  404. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  405. pm860x_irqs[data->irq - chip->irq_base].enable
  406. = pm860x_irqs[data->irq - chip->irq_base].offs;
  407. }
  408. static void pm860x_irq_disable(struct irq_data *data)
  409. {
  410. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  411. pm860x_irqs[data->irq - chip->irq_base].enable = 0;
  412. }
  413. static struct irq_chip pm860x_irq_chip = {
  414. .name = "88pm860x",
  415. .irq_bus_lock = pm860x_irq_lock,
  416. .irq_bus_sync_unlock = pm860x_irq_sync_unlock,
  417. .irq_enable = pm860x_irq_enable,
  418. .irq_disable = pm860x_irq_disable,
  419. };
  420. static int __devinit device_gpadc_init(struct pm860x_chip *chip,
  421. struct pm860x_platform_data *pdata)
  422. {
  423. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  424. : chip->companion;
  425. int data;
  426. int ret;
  427. /* initialize GPADC without activating it */
  428. if (!pdata || !pdata->touch)
  429. return -EINVAL;
  430. /* set GPADC MISC1 register */
  431. data = 0;
  432. data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
  433. data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
  434. data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
  435. data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
  436. if (data) {
  437. ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
  438. if (ret < 0)
  439. goto out;
  440. }
  441. /* set tsi prebias time */
  442. if (pdata->touch->tsi_prebias) {
  443. data = pdata->touch->tsi_prebias;
  444. ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
  445. if (ret < 0)
  446. goto out;
  447. }
  448. /* set prebias & prechg time of pen detect */
  449. data = 0;
  450. data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
  451. data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
  452. if (data) {
  453. ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
  454. if (ret < 0)
  455. goto out;
  456. }
  457. ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
  458. PM8607_GPADC_EN, PM8607_GPADC_EN);
  459. out:
  460. return ret;
  461. }
  462. static int __devinit device_irq_init(struct pm860x_chip *chip,
  463. struct pm860x_platform_data *pdata)
  464. {
  465. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  466. : chip->companion;
  467. unsigned char status_buf[INT_STATUS_NUM];
  468. unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  469. struct irq_desc *desc;
  470. int i, data, mask, ret = -EINVAL;
  471. int __irq;
  472. if (!pdata || !pdata->irq_base) {
  473. dev_warn(chip->dev, "No interrupt support on IRQ base\n");
  474. return -EINVAL;
  475. }
  476. mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR
  477. | PM8607_B0_MISC1_INT_MASK;
  478. data = 0;
  479. chip->irq_mode = 0;
  480. if (pdata && pdata->irq_mode) {
  481. /*
  482. * irq_mode defines the way of clearing interrupt. If it's 1,
  483. * clear IRQ by write. Otherwise, clear it by read.
  484. * This control bit is valid from 88PM8607 B0 steping.
  485. */
  486. data |= PM8607_B0_MISC1_INT_CLEAR;
  487. chip->irq_mode = 1;
  488. }
  489. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data);
  490. if (ret < 0)
  491. goto out;
  492. /* mask all IRQs */
  493. memset(status_buf, 0, INT_STATUS_NUM);
  494. ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1,
  495. INT_STATUS_NUM, status_buf);
  496. if (ret < 0)
  497. goto out;
  498. if (chip->irq_mode) {
  499. /* clear interrupt status by write */
  500. memset(status_buf, 0xFF, INT_STATUS_NUM);
  501. ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1,
  502. INT_STATUS_NUM, status_buf);
  503. } else {
  504. /* clear interrupt status by read */
  505. ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1,
  506. INT_STATUS_NUM, status_buf);
  507. }
  508. if (ret < 0)
  509. goto out;
  510. mutex_init(&chip->irq_lock);
  511. chip->irq_base = pdata->irq_base;
  512. chip->core_irq = i2c->irq;
  513. if (!chip->core_irq)
  514. goto out;
  515. desc = irq_to_desc(chip->core_irq);
  516. /* register IRQ by genirq */
  517. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  518. __irq = i + chip->irq_base;
  519. set_irq_chip_data(__irq, chip);
  520. set_irq_chip_and_handler(__irq, &pm860x_irq_chip,
  521. handle_edge_irq);
  522. set_irq_nested_thread(__irq, 1);
  523. #ifdef CONFIG_ARM
  524. set_irq_flags(__irq, IRQF_VALID);
  525. #else
  526. set_irq_noprobe(__irq);
  527. #endif
  528. }
  529. ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags,
  530. "88pm860x", chip);
  531. if (ret) {
  532. dev_err(chip->dev, "Failed to request IRQ: %d\n", ret);
  533. chip->core_irq = 0;
  534. }
  535. return 0;
  536. out:
  537. chip->core_irq = 0;
  538. return ret;
  539. }
  540. static void device_irq_exit(struct pm860x_chip *chip)
  541. {
  542. if (chip->core_irq)
  543. free_irq(chip->core_irq, chip);
  544. }
  545. static void __devinit device_8606_init(struct pm860x_chip *chip,
  546. struct i2c_client *i2c,
  547. struct pm860x_platform_data *pdata)
  548. {
  549. int ret;
  550. if (pdata && pdata->backlight) {
  551. ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
  552. ARRAY_SIZE(backlight_devs),
  553. &backlight_resources[0], 0);
  554. if (ret < 0) {
  555. dev_err(chip->dev, "Failed to add backlight "
  556. "subdev\n");
  557. goto out_dev;
  558. }
  559. }
  560. if (pdata && pdata->led) {
  561. ret = mfd_add_devices(chip->dev, 0, &led_devs[0],
  562. ARRAY_SIZE(led_devs),
  563. &led_resources[0], 0);
  564. if (ret < 0) {
  565. dev_err(chip->dev, "Failed to add led "
  566. "subdev\n");
  567. goto out_dev;
  568. }
  569. }
  570. return;
  571. out_dev:
  572. mfd_remove_devices(chip->dev);
  573. device_irq_exit(chip);
  574. }
  575. static void __devinit device_8607_init(struct pm860x_chip *chip,
  576. struct i2c_client *i2c,
  577. struct pm860x_platform_data *pdata)
  578. {
  579. int data, ret;
  580. ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
  581. if (ret < 0) {
  582. dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
  583. goto out;
  584. }
  585. switch (ret & PM8607_VERSION_MASK) {
  586. case 0x40:
  587. case 0x50:
  588. dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n",
  589. ret);
  590. break;
  591. default:
  592. dev_err(chip->dev, "Failed to detect Marvell 88PM8607. "
  593. "Chip ID: %02x\n", ret);
  594. goto out;
  595. }
  596. ret = pm860x_reg_read(i2c, PM8607_BUCK3);
  597. if (ret < 0) {
  598. dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret);
  599. goto out;
  600. }
  601. if (ret & PM8607_BUCK3_DOUBLE)
  602. chip->buck3_double = 1;
  603. ret = pm860x_reg_read(i2c, PM8607_B0_MISC1);
  604. if (ret < 0) {
  605. dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret);
  606. goto out;
  607. }
  608. if (pdata && (pdata->i2c_port == PI2C_PORT))
  609. data = PM8607_B0_MISC1_PI2C;
  610. else
  611. data = 0;
  612. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data);
  613. if (ret < 0) {
  614. dev_err(chip->dev, "Failed to access MISC1:%d\n", ret);
  615. goto out;
  616. }
  617. ret = device_gpadc_init(chip, pdata);
  618. if (ret < 0)
  619. goto out;
  620. ret = device_irq_init(chip, pdata);
  621. if (ret < 0)
  622. goto out;
  623. ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
  624. ARRAY_SIZE(regulator_devs),
  625. &regulator_resources[0], 0);
  626. if (ret < 0) {
  627. dev_err(chip->dev, "Failed to add regulator subdev\n");
  628. goto out_dev;
  629. }
  630. if (pdata && pdata->touch) {
  631. ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
  632. ARRAY_SIZE(touch_devs),
  633. &touch_resources[0], 0);
  634. if (ret < 0) {
  635. dev_err(chip->dev, "Failed to add touch "
  636. "subdev\n");
  637. goto out_dev;
  638. }
  639. }
  640. if (pdata && pdata->power) {
  641. ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
  642. ARRAY_SIZE(power_devs),
  643. &power_supply_resources[0], 0);
  644. if (ret < 0) {
  645. dev_err(chip->dev, "Failed to add power supply "
  646. "subdev\n");
  647. goto out_dev;
  648. }
  649. }
  650. ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
  651. ARRAY_SIZE(onkey_devs),
  652. &onkey_resources[0], 0);
  653. if (ret < 0) {
  654. dev_err(chip->dev, "Failed to add onkey subdev\n");
  655. goto out_dev;
  656. }
  657. ret = mfd_add_devices(chip->dev, 0, &codec_devs[0],
  658. ARRAY_SIZE(codec_devs),
  659. &codec_resources[0], 0);
  660. if (ret < 0) {
  661. dev_err(chip->dev, "Failed to add codec subdev\n");
  662. goto out_dev;
  663. }
  664. return;
  665. out_dev:
  666. mfd_remove_devices(chip->dev);
  667. device_irq_exit(chip);
  668. out:
  669. return;
  670. }
  671. int __devinit pm860x_device_init(struct pm860x_chip *chip,
  672. struct pm860x_platform_data *pdata)
  673. {
  674. chip->core_irq = 0;
  675. switch (chip->id) {
  676. case CHIP_PM8606:
  677. device_8606_init(chip, chip->client, pdata);
  678. break;
  679. case CHIP_PM8607:
  680. device_8607_init(chip, chip->client, pdata);
  681. break;
  682. }
  683. if (chip->companion) {
  684. switch (chip->id) {
  685. case CHIP_PM8607:
  686. device_8606_init(chip, chip->companion, pdata);
  687. break;
  688. case CHIP_PM8606:
  689. device_8607_init(chip, chip->companion, pdata);
  690. break;
  691. }
  692. }
  693. return 0;
  694. }
  695. void __devexit pm860x_device_exit(struct pm860x_chip *chip)
  696. {
  697. device_irq_exit(chip);
  698. mfd_remove_devices(chip->dev);
  699. }
  700. MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
  701. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  702. MODULE_LICENSE("GPL");