88pm860x-core.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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 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 data;
  396. int ret;
  397. /* initialize GPADC without activating it */
  398. if (!pdata || !pdata->touch)
  399. return -EINVAL;
  400. /* set GPADC MISC1 register */
  401. data = 0;
  402. data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
  403. data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
  404. data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
  405. data |= (pdata->touch->sw_cal << 7) & 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) & PM8607_PD_PRECHG_MASK;
  422. if (data) {
  423. ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
  424. if (ret < 0)
  425. goto out;
  426. }
  427. ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
  428. PM8607_GPADC_EN, PM8607_GPADC_EN);
  429. out:
  430. return ret;
  431. }
  432. static int __devinit device_irq_init(struct pm860x_chip *chip,
  433. struct pm860x_platform_data *pdata)
  434. {
  435. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  436. : chip->companion;
  437. unsigned char status_buf[INT_STATUS_NUM];
  438. unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  439. struct irq_desc *desc;
  440. int i, data, mask, ret = -EINVAL;
  441. int __irq;
  442. if (!pdata || !pdata->irq_base) {
  443. dev_warn(chip->dev, "No interrupt support on IRQ base\n");
  444. return -EINVAL;
  445. }
  446. mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR
  447. | PM8607_B0_MISC1_INT_MASK;
  448. data = 0;
  449. chip->irq_mode = 0;
  450. if (pdata && pdata->irq_mode) {
  451. /*
  452. * irq_mode defines the way of clearing interrupt. If it's 1,
  453. * clear IRQ by write. Otherwise, clear it by read.
  454. * This control bit is valid from 88PM8607 B0 steping.
  455. */
  456. data |= PM8607_B0_MISC1_INT_CLEAR;
  457. chip->irq_mode = 1;
  458. }
  459. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data);
  460. if (ret < 0)
  461. goto out;
  462. /* mask all IRQs */
  463. memset(status_buf, 0, INT_STATUS_NUM);
  464. ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1,
  465. INT_STATUS_NUM, status_buf);
  466. if (ret < 0)
  467. goto out;
  468. if (chip->irq_mode) {
  469. /* clear interrupt status by write */
  470. memset(status_buf, 0xFF, INT_STATUS_NUM);
  471. ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1,
  472. INT_STATUS_NUM, status_buf);
  473. } else {
  474. /* clear interrupt status by read */
  475. ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1,
  476. INT_STATUS_NUM, status_buf);
  477. }
  478. if (ret < 0)
  479. goto out;
  480. mutex_init(&chip->irq_lock);
  481. chip->irq_base = pdata->irq_base;
  482. chip->core_irq = i2c->irq;
  483. if (!chip->core_irq)
  484. goto out;
  485. desc = irq_to_desc(chip->core_irq);
  486. /* register IRQ by genirq */
  487. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  488. __irq = i + chip->irq_base;
  489. set_irq_chip_data(__irq, chip);
  490. set_irq_chip_and_handler(__irq, &pm860x_irq_chip,
  491. handle_edge_irq);
  492. set_irq_nested_thread(__irq, 1);
  493. #ifdef CONFIG_ARM
  494. set_irq_flags(__irq, IRQF_VALID);
  495. #else
  496. set_irq_noprobe(__irq);
  497. #endif
  498. }
  499. ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags,
  500. "88pm860x", chip);
  501. if (ret) {
  502. dev_err(chip->dev, "Failed to request IRQ: %d\n", ret);
  503. chip->core_irq = 0;
  504. }
  505. return 0;
  506. out:
  507. chip->core_irq = 0;
  508. return ret;
  509. }
  510. static void device_irq_exit(struct pm860x_chip *chip)
  511. {
  512. if (chip->core_irq)
  513. free_irq(chip->core_irq, chip);
  514. }
  515. static void __devinit device_8606_init(struct pm860x_chip *chip,
  516. struct i2c_client *i2c,
  517. struct pm860x_platform_data *pdata)
  518. {
  519. int ret;
  520. if (pdata && pdata->backlight) {
  521. ret = mfd_add_devices(chip->dev, 0, &backlight_devs[0],
  522. ARRAY_SIZE(backlight_devs),
  523. &backlight_resources[0], 0);
  524. if (ret < 0) {
  525. dev_err(chip->dev, "Failed to add backlight "
  526. "subdev\n");
  527. goto out_dev;
  528. }
  529. }
  530. if (pdata && pdata->led) {
  531. ret = mfd_add_devices(chip->dev, 0, &led_devs[0],
  532. ARRAY_SIZE(led_devs),
  533. &led_resources[0], 0);
  534. if (ret < 0) {
  535. dev_err(chip->dev, "Failed to add led "
  536. "subdev\n");
  537. goto out_dev;
  538. }
  539. }
  540. return;
  541. out_dev:
  542. mfd_remove_devices(chip->dev);
  543. device_irq_exit(chip);
  544. }
  545. static void __devinit device_8607_init(struct pm860x_chip *chip,
  546. struct i2c_client *i2c,
  547. struct pm860x_platform_data *pdata)
  548. {
  549. int data, ret;
  550. ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
  551. if (ret < 0) {
  552. dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
  553. goto out;
  554. }
  555. if ((ret & PM8607_VERSION_MASK) == PM8607_VERSION)
  556. dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n",
  557. ret);
  558. else {
  559. dev_err(chip->dev, "Failed to detect Marvell 88PM8607. "
  560. "Chip ID: %02x\n", ret);
  561. goto out;
  562. }
  563. ret = pm860x_reg_read(i2c, PM8607_BUCK3);
  564. if (ret < 0) {
  565. dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret);
  566. goto out;
  567. }
  568. if (ret & PM8607_BUCK3_DOUBLE)
  569. chip->buck3_double = 1;
  570. ret = pm860x_reg_read(i2c, PM8607_B0_MISC1);
  571. if (ret < 0) {
  572. dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret);
  573. goto out;
  574. }
  575. if (pdata && (pdata->i2c_port == PI2C_PORT))
  576. data = PM8607_B0_MISC1_PI2C;
  577. else
  578. data = 0;
  579. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data);
  580. if (ret < 0) {
  581. dev_err(chip->dev, "Failed to access MISC1:%d\n", ret);
  582. goto out;
  583. }
  584. ret = device_gpadc_init(chip, pdata);
  585. if (ret < 0)
  586. goto out;
  587. ret = device_irq_init(chip, pdata);
  588. if (ret < 0)
  589. goto out;
  590. ret = mfd_add_devices(chip->dev, 0, &regulator_devs[0],
  591. ARRAY_SIZE(regulator_devs),
  592. &regulator_resources[0], 0);
  593. if (ret < 0) {
  594. dev_err(chip->dev, "Failed to add regulator subdev\n");
  595. goto out_dev;
  596. }
  597. if (pdata && pdata->touch) {
  598. ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
  599. ARRAY_SIZE(touch_devs),
  600. &touch_resources[0], 0);
  601. if (ret < 0) {
  602. dev_err(chip->dev, "Failed to add touch "
  603. "subdev\n");
  604. goto out_dev;
  605. }
  606. }
  607. if (pdata && pdata->power) {
  608. ret = mfd_add_devices(chip->dev, 0, &power_devs[0],
  609. ARRAY_SIZE(power_devs),
  610. &power_supply_resources[0], 0);
  611. if (ret < 0) {
  612. dev_err(chip->dev, "Failed to add power supply "
  613. "subdev\n");
  614. goto out_dev;
  615. }
  616. }
  617. ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
  618. ARRAY_SIZE(onkey_devs),
  619. &onkey_resources[0], 0);
  620. if (ret < 0) {
  621. dev_err(chip->dev, "Failed to add onkey subdev\n");
  622. goto out_dev;
  623. }
  624. return;
  625. out_dev:
  626. mfd_remove_devices(chip->dev);
  627. device_irq_exit(chip);
  628. out:
  629. return;
  630. }
  631. int __devinit pm860x_device_init(struct pm860x_chip *chip,
  632. struct pm860x_platform_data *pdata)
  633. {
  634. chip->core_irq = 0;
  635. switch (chip->id) {
  636. case CHIP_PM8606:
  637. device_8606_init(chip, chip->client, pdata);
  638. break;
  639. case CHIP_PM8607:
  640. device_8607_init(chip, chip->client, pdata);
  641. break;
  642. }
  643. if (chip->companion) {
  644. switch (chip->id) {
  645. case CHIP_PM8607:
  646. device_8606_init(chip, chip->companion, pdata);
  647. break;
  648. case CHIP_PM8606:
  649. device_8607_init(chip, chip->companion, pdata);
  650. break;
  651. }
  652. }
  653. return 0;
  654. }
  655. void __devexit pm860x_device_exit(struct pm860x_chip *chip)
  656. {
  657. device_irq_exit(chip);
  658. mfd_remove_devices(chip->dev);
  659. }
  660. MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
  661. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  662. MODULE_LICENSE("GPL");