88pm860x-core.c 17 KB

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