88pm860x-core.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  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. #include <linux/regulator/machine.h>
  20. #define INT_STATUS_NUM 3
  21. static struct resource bk0_resources[] __devinitdata = {
  22. {2, 2, "duty cycle", IORESOURCE_REG, },
  23. {3, 3, "always on", IORESOURCE_REG, },
  24. {3, 3, "current", IORESOURCE_REG, },
  25. };
  26. static struct resource bk1_resources[] __devinitdata = {
  27. {4, 4, "duty cycle", IORESOURCE_REG, },
  28. {5, 5, "always on", IORESOURCE_REG, },
  29. {5, 5, "current", IORESOURCE_REG, },
  30. };
  31. static struct resource bk2_resources[] __devinitdata = {
  32. {6, 6, "duty cycle", IORESOURCE_REG, },
  33. {7, 7, "always on", IORESOURCE_REG, },
  34. {5, 5, "current", IORESOURCE_REG, },
  35. };
  36. static struct resource led0_resources[] __devinitdata = {
  37. /* RGB1 Red LED */
  38. {0xd, 0xd, "control", IORESOURCE_REG, },
  39. {0xc, 0xc, "blink", IORESOURCE_REG, },
  40. };
  41. static struct resource led1_resources[] __devinitdata = {
  42. /* RGB1 Green LED */
  43. {0xe, 0xe, "control", IORESOURCE_REG, },
  44. {0xc, 0xc, "blink", IORESOURCE_REG, },
  45. };
  46. static struct resource led2_resources[] __devinitdata = {
  47. /* RGB1 Blue LED */
  48. {0xf, 0xf, "control", IORESOURCE_REG, },
  49. {0xc, 0xc, "blink", IORESOURCE_REG, },
  50. };
  51. static struct resource led3_resources[] __devinitdata = {
  52. /* RGB2 Red LED */
  53. {0x9, 0x9, "control", IORESOURCE_REG, },
  54. {0x8, 0x8, "blink", IORESOURCE_REG, },
  55. };
  56. static struct resource led4_resources[] __devinitdata = {
  57. /* RGB2 Green LED */
  58. {0xa, 0xa, "control", IORESOURCE_REG, },
  59. {0x8, 0x8, "blink", IORESOURCE_REG, },
  60. };
  61. static struct resource led5_resources[] __devinitdata = {
  62. /* RGB2 Blue LED */
  63. {0xb, 0xb, "control", IORESOURCE_REG, },
  64. {0x8, 0x8, "blink", IORESOURCE_REG, },
  65. };
  66. static struct resource buck1_resources[] __devinitdata = {
  67. {0x24, 0x24, "buck set", IORESOURCE_REG, },
  68. };
  69. static struct resource buck2_resources[] __devinitdata = {
  70. {0x25, 0x25, "buck set", IORESOURCE_REG, },
  71. };
  72. static struct resource buck3_resources[] __devinitdata = {
  73. {0x26, 0x26, "buck set", IORESOURCE_REG, },
  74. };
  75. static struct resource ldo1_resources[] __devinitdata = {
  76. {0x10, 0x10, "ldo set", IORESOURCE_REG, },
  77. };
  78. static struct resource ldo2_resources[] __devinitdata = {
  79. {0x11, 0x11, "ldo set", IORESOURCE_REG, },
  80. };
  81. static struct resource ldo3_resources[] __devinitdata = {
  82. {0x12, 0x12, "ldo set", IORESOURCE_REG, },
  83. };
  84. static struct resource ldo4_resources[] __devinitdata = {
  85. {0x13, 0x13, "ldo set", IORESOURCE_REG, },
  86. };
  87. static struct resource ldo5_resources[] __devinitdata = {
  88. {0x14, 0x14, "ldo set", IORESOURCE_REG, },
  89. };
  90. static struct resource ldo6_resources[] __devinitdata = {
  91. {0x15, 0x15, "ldo set", IORESOURCE_REG, },
  92. };
  93. static struct resource ldo7_resources[] __devinitdata = {
  94. {0x16, 0x16, "ldo set", IORESOURCE_REG, },
  95. };
  96. static struct resource ldo8_resources[] __devinitdata = {
  97. {0x17, 0x17, "ldo set", IORESOURCE_REG, },
  98. };
  99. static struct resource ldo9_resources[] __devinitdata = {
  100. {0x18, 0x18, "ldo set", IORESOURCE_REG, },
  101. };
  102. static struct resource ldo10_resources[] __devinitdata = {
  103. {0x19, 0x19, "ldo set", IORESOURCE_REG, },
  104. };
  105. static struct resource ldo12_resources[] __devinitdata = {
  106. {0x1a, 0x1a, "ldo set", IORESOURCE_REG, },
  107. };
  108. static struct resource ldo_vibrator_resources[] __devinitdata = {
  109. {0x28, 0x28, "ldo set", IORESOURCE_REG, },
  110. };
  111. static struct resource ldo14_resources[] __devinitdata = {
  112. {0x1b, 0x1b, "ldo set", IORESOURCE_REG, },
  113. };
  114. static struct resource touch_resources[] __devinitdata = {
  115. {PM8607_IRQ_PEN, PM8607_IRQ_PEN, "touch", IORESOURCE_IRQ,},
  116. };
  117. static struct resource onkey_resources[] __devinitdata = {
  118. {PM8607_IRQ_ONKEY, PM8607_IRQ_ONKEY, "onkey", IORESOURCE_IRQ,},
  119. };
  120. static struct resource codec_resources[] __devinitdata = {
  121. /* Headset microphone insertion or removal */
  122. {PM8607_IRQ_MICIN, PM8607_IRQ_MICIN, "micin", IORESOURCE_IRQ,},
  123. /* Hook-switch press or release */
  124. {PM8607_IRQ_HOOK, PM8607_IRQ_HOOK, "hook", IORESOURCE_IRQ,},
  125. /* Headset insertion or removal */
  126. {PM8607_IRQ_HEADSET, PM8607_IRQ_HEADSET, "headset", IORESOURCE_IRQ,},
  127. /* Audio short */
  128. {PM8607_IRQ_AUDIO_SHORT, PM8607_IRQ_AUDIO_SHORT, "audio-short", IORESOURCE_IRQ,},
  129. };
  130. static struct resource battery_resources[] __devinitdata = {
  131. {PM8607_IRQ_CC, PM8607_IRQ_CC, "columb counter", IORESOURCE_IRQ,},
  132. {PM8607_IRQ_BAT, PM8607_IRQ_BAT, "battery", IORESOURCE_IRQ,},
  133. };
  134. static struct resource charger_resources[] __devinitdata = {
  135. {PM8607_IRQ_CHG, PM8607_IRQ_CHG, "charger detect", IORESOURCE_IRQ,},
  136. {PM8607_IRQ_CHG_DONE, PM8607_IRQ_CHG_DONE, "charging done", IORESOURCE_IRQ,},
  137. {PM8607_IRQ_CHG_FAULT, PM8607_IRQ_CHG_FAULT, "charging timeout", IORESOURCE_IRQ,},
  138. {PM8607_IRQ_GPADC1, PM8607_IRQ_GPADC1, "battery temperature", IORESOURCE_IRQ,},
  139. {PM8607_IRQ_VBAT, PM8607_IRQ_VBAT, "battery voltage", IORESOURCE_IRQ,},
  140. {PM8607_IRQ_VCHG, PM8607_IRQ_VCHG, "vchg voltage", IORESOURCE_IRQ,},
  141. };
  142. static struct resource rtc_resources[] __devinitdata = {
  143. {PM8607_IRQ_RTC, PM8607_IRQ_RTC, "rtc", IORESOURCE_IRQ,},
  144. };
  145. static struct mfd_cell bk_devs[] __devinitdata = {
  146. {
  147. .name = "88pm860x-backlight",
  148. .id = 0,
  149. .num_resources = ARRAY_SIZE(bk0_resources),
  150. .resources = bk0_resources,
  151. }, {
  152. .name = "88pm860x-backlight",
  153. .id = 1,
  154. .num_resources = ARRAY_SIZE(bk1_resources),
  155. .resources = bk1_resources,
  156. }, {
  157. .name = "88pm860x-backlight",
  158. .id = 2,
  159. .num_resources = ARRAY_SIZE(bk2_resources),
  160. .resources = bk2_resources,
  161. },
  162. };
  163. static struct mfd_cell led_devs[] __devinitdata = {
  164. {
  165. .name = "88pm860x-led",
  166. .id = 0,
  167. .num_resources = ARRAY_SIZE(led0_resources),
  168. .resources = led0_resources,
  169. }, {
  170. .name = "88pm860x-led",
  171. .id = 1,
  172. .num_resources = ARRAY_SIZE(led1_resources),
  173. .resources = led1_resources,
  174. }, {
  175. .name = "88pm860x-led",
  176. .id = 2,
  177. .num_resources = ARRAY_SIZE(led2_resources),
  178. .resources = led2_resources,
  179. }, {
  180. .name = "88pm860x-led",
  181. .id = 3,
  182. .num_resources = ARRAY_SIZE(led3_resources),
  183. .resources = led3_resources,
  184. }, {
  185. .name = "88pm860x-led",
  186. .id = 4,
  187. .num_resources = ARRAY_SIZE(led4_resources),
  188. .resources = led4_resources,
  189. }, {
  190. .name = "88pm860x-led",
  191. .id = 5,
  192. .num_resources = ARRAY_SIZE(led5_resources),
  193. .resources = led5_resources,
  194. },
  195. };
  196. static struct mfd_cell reg_devs[] __devinitdata = {
  197. {
  198. .name = "88pm860x-regulator",
  199. .id = 0,
  200. .num_resources = ARRAY_SIZE(buck1_resources),
  201. .resources = buck1_resources,
  202. }, {
  203. .name = "88pm860x-regulator",
  204. .id = 1,
  205. .num_resources = ARRAY_SIZE(buck2_resources),
  206. .resources = buck2_resources,
  207. }, {
  208. .name = "88pm860x-regulator",
  209. .id = 2,
  210. .num_resources = ARRAY_SIZE(buck3_resources),
  211. .resources = buck3_resources,
  212. }, {
  213. .name = "88pm860x-regulator",
  214. .id = 3,
  215. .num_resources = ARRAY_SIZE(ldo1_resources),
  216. .resources = ldo1_resources,
  217. }, {
  218. .name = "88pm860x-regulator",
  219. .id = 4,
  220. .num_resources = ARRAY_SIZE(ldo2_resources),
  221. .resources = ldo2_resources,
  222. }, {
  223. .name = "88pm860x-regulator",
  224. .id = 5,
  225. .num_resources = ARRAY_SIZE(ldo3_resources),
  226. .resources = ldo3_resources,
  227. }, {
  228. .name = "88pm860x-regulator",
  229. .id = 6,
  230. .num_resources = ARRAY_SIZE(ldo4_resources),
  231. .resources = ldo4_resources,
  232. }, {
  233. .name = "88pm860x-regulator",
  234. .id = 7,
  235. .num_resources = ARRAY_SIZE(ldo5_resources),
  236. .resources = ldo5_resources,
  237. }, {
  238. .name = "88pm860x-regulator",
  239. .id = 8,
  240. .num_resources = ARRAY_SIZE(ldo6_resources),
  241. .resources = ldo6_resources,
  242. }, {
  243. .name = "88pm860x-regulator",
  244. .id = 9,
  245. .num_resources = ARRAY_SIZE(ldo7_resources),
  246. .resources = ldo7_resources,
  247. }, {
  248. .name = "88pm860x-regulator",
  249. .id = 10,
  250. .num_resources = ARRAY_SIZE(ldo8_resources),
  251. .resources = ldo8_resources,
  252. }, {
  253. .name = "88pm860x-regulator",
  254. .id = 11,
  255. .num_resources = ARRAY_SIZE(ldo9_resources),
  256. .resources = ldo9_resources,
  257. }, {
  258. .name = "88pm860x-regulator",
  259. .id = 12,
  260. .num_resources = ARRAY_SIZE(ldo10_resources),
  261. .resources = ldo10_resources,
  262. }, {
  263. .name = "88pm860x-regulator",
  264. .id = 13,
  265. .num_resources = ARRAY_SIZE(ldo12_resources),
  266. .resources = ldo12_resources,
  267. }, {
  268. .name = "88pm860x-regulator",
  269. .id = 14,
  270. .num_resources = ARRAY_SIZE(ldo_vibrator_resources),
  271. .resources = ldo_vibrator_resources,
  272. }, {
  273. .name = "88pm860x-regulator",
  274. .id = 15,
  275. .num_resources = ARRAY_SIZE(ldo14_resources),
  276. .resources = ldo14_resources,
  277. },
  278. };
  279. static struct mfd_cell touch_devs[] = {
  280. {"88pm860x-touch", -1,},
  281. };
  282. static struct mfd_cell onkey_devs[] = {
  283. {"88pm860x-onkey", -1,},
  284. };
  285. static struct mfd_cell codec_devs[] = {
  286. {"88pm860x-codec", -1,},
  287. };
  288. static struct regulator_consumer_supply preg_supply[] = {
  289. REGULATOR_SUPPLY("preg", "charger-manager"),
  290. };
  291. static struct regulator_init_data preg_init_data = {
  292. .num_consumer_supplies = ARRAY_SIZE(preg_supply),
  293. .consumer_supplies = &preg_supply[0],
  294. };
  295. static struct mfd_cell power_devs[] = {
  296. {"88pm860x-battery", -1,},
  297. {"88pm860x-charger", -1,},
  298. {"88pm860x-preg", -1,},
  299. };
  300. static struct mfd_cell rtc_devs[] = {
  301. {"88pm860x-rtc", -1,},
  302. };
  303. struct pm860x_irq_data {
  304. int reg;
  305. int mask_reg;
  306. int enable; /* enable or not */
  307. int offs; /* bit offset in mask register */
  308. };
  309. static struct pm860x_irq_data pm860x_irqs[] = {
  310. [PM8607_IRQ_ONKEY] = {
  311. .reg = PM8607_INT_STATUS1,
  312. .mask_reg = PM8607_INT_MASK_1,
  313. .offs = 1 << 0,
  314. },
  315. [PM8607_IRQ_EXTON] = {
  316. .reg = PM8607_INT_STATUS1,
  317. .mask_reg = PM8607_INT_MASK_1,
  318. .offs = 1 << 1,
  319. },
  320. [PM8607_IRQ_CHG] = {
  321. .reg = PM8607_INT_STATUS1,
  322. .mask_reg = PM8607_INT_MASK_1,
  323. .offs = 1 << 2,
  324. },
  325. [PM8607_IRQ_BAT] = {
  326. .reg = PM8607_INT_STATUS1,
  327. .mask_reg = PM8607_INT_MASK_1,
  328. .offs = 1 << 3,
  329. },
  330. [PM8607_IRQ_RTC] = {
  331. .reg = PM8607_INT_STATUS1,
  332. .mask_reg = PM8607_INT_MASK_1,
  333. .offs = 1 << 4,
  334. },
  335. [PM8607_IRQ_CC] = {
  336. .reg = PM8607_INT_STATUS1,
  337. .mask_reg = PM8607_INT_MASK_1,
  338. .offs = 1 << 5,
  339. },
  340. [PM8607_IRQ_VBAT] = {
  341. .reg = PM8607_INT_STATUS2,
  342. .mask_reg = PM8607_INT_MASK_2,
  343. .offs = 1 << 0,
  344. },
  345. [PM8607_IRQ_VCHG] = {
  346. .reg = PM8607_INT_STATUS2,
  347. .mask_reg = PM8607_INT_MASK_2,
  348. .offs = 1 << 1,
  349. },
  350. [PM8607_IRQ_VSYS] = {
  351. .reg = PM8607_INT_STATUS2,
  352. .mask_reg = PM8607_INT_MASK_2,
  353. .offs = 1 << 2,
  354. },
  355. [PM8607_IRQ_TINT] = {
  356. .reg = PM8607_INT_STATUS2,
  357. .mask_reg = PM8607_INT_MASK_2,
  358. .offs = 1 << 3,
  359. },
  360. [PM8607_IRQ_GPADC0] = {
  361. .reg = PM8607_INT_STATUS2,
  362. .mask_reg = PM8607_INT_MASK_2,
  363. .offs = 1 << 4,
  364. },
  365. [PM8607_IRQ_GPADC1] = {
  366. .reg = PM8607_INT_STATUS2,
  367. .mask_reg = PM8607_INT_MASK_2,
  368. .offs = 1 << 5,
  369. },
  370. [PM8607_IRQ_GPADC2] = {
  371. .reg = PM8607_INT_STATUS2,
  372. .mask_reg = PM8607_INT_MASK_2,
  373. .offs = 1 << 6,
  374. },
  375. [PM8607_IRQ_GPADC3] = {
  376. .reg = PM8607_INT_STATUS2,
  377. .mask_reg = PM8607_INT_MASK_2,
  378. .offs = 1 << 7,
  379. },
  380. [PM8607_IRQ_AUDIO_SHORT] = {
  381. .reg = PM8607_INT_STATUS3,
  382. .mask_reg = PM8607_INT_MASK_3,
  383. .offs = 1 << 0,
  384. },
  385. [PM8607_IRQ_PEN] = {
  386. .reg = PM8607_INT_STATUS3,
  387. .mask_reg = PM8607_INT_MASK_3,
  388. .offs = 1 << 1,
  389. },
  390. [PM8607_IRQ_HEADSET] = {
  391. .reg = PM8607_INT_STATUS3,
  392. .mask_reg = PM8607_INT_MASK_3,
  393. .offs = 1 << 2,
  394. },
  395. [PM8607_IRQ_HOOK] = {
  396. .reg = PM8607_INT_STATUS3,
  397. .mask_reg = PM8607_INT_MASK_3,
  398. .offs = 1 << 3,
  399. },
  400. [PM8607_IRQ_MICIN] = {
  401. .reg = PM8607_INT_STATUS3,
  402. .mask_reg = PM8607_INT_MASK_3,
  403. .offs = 1 << 4,
  404. },
  405. [PM8607_IRQ_CHG_FAIL] = {
  406. .reg = PM8607_INT_STATUS3,
  407. .mask_reg = PM8607_INT_MASK_3,
  408. .offs = 1 << 5,
  409. },
  410. [PM8607_IRQ_CHG_DONE] = {
  411. .reg = PM8607_INT_STATUS3,
  412. .mask_reg = PM8607_INT_MASK_3,
  413. .offs = 1 << 6,
  414. },
  415. [PM8607_IRQ_CHG_FAULT] = {
  416. .reg = PM8607_INT_STATUS3,
  417. .mask_reg = PM8607_INT_MASK_3,
  418. .offs = 1 << 7,
  419. },
  420. };
  421. static irqreturn_t pm860x_irq(int irq, void *data)
  422. {
  423. struct pm860x_chip *chip = data;
  424. struct pm860x_irq_data *irq_data;
  425. struct i2c_client *i2c;
  426. int read_reg = -1, value = 0;
  427. int i;
  428. i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  429. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  430. irq_data = &pm860x_irqs[i];
  431. if (read_reg != irq_data->reg) {
  432. read_reg = irq_data->reg;
  433. value = pm860x_reg_read(i2c, irq_data->reg);
  434. }
  435. if (value & irq_data->enable)
  436. handle_nested_irq(chip->irq_base + i);
  437. }
  438. return IRQ_HANDLED;
  439. }
  440. static void pm860x_irq_lock(struct irq_data *data)
  441. {
  442. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  443. mutex_lock(&chip->irq_lock);
  444. }
  445. static void pm860x_irq_sync_unlock(struct irq_data *data)
  446. {
  447. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  448. struct pm860x_irq_data *irq_data;
  449. struct i2c_client *i2c;
  450. static unsigned char cached[3] = {0x0, 0x0, 0x0};
  451. unsigned char mask[3];
  452. int i;
  453. i2c = (chip->id == CHIP_PM8607) ? chip->client : chip->companion;
  454. /* Load cached value. In initial, all IRQs are masked */
  455. for (i = 0; i < 3; i++)
  456. mask[i] = cached[i];
  457. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  458. irq_data = &pm860x_irqs[i];
  459. switch (irq_data->mask_reg) {
  460. case PM8607_INT_MASK_1:
  461. mask[0] &= ~irq_data->offs;
  462. mask[0] |= irq_data->enable;
  463. break;
  464. case PM8607_INT_MASK_2:
  465. mask[1] &= ~irq_data->offs;
  466. mask[1] |= irq_data->enable;
  467. break;
  468. case PM8607_INT_MASK_3:
  469. mask[2] &= ~irq_data->offs;
  470. mask[2] |= irq_data->enable;
  471. break;
  472. default:
  473. dev_err(chip->dev, "wrong IRQ\n");
  474. break;
  475. }
  476. }
  477. /* update mask into registers */
  478. for (i = 0; i < 3; i++) {
  479. if (mask[i] != cached[i]) {
  480. cached[i] = mask[i];
  481. pm860x_reg_write(i2c, PM8607_INT_MASK_1 + i, mask[i]);
  482. }
  483. }
  484. mutex_unlock(&chip->irq_lock);
  485. }
  486. static void pm860x_irq_enable(struct irq_data *data)
  487. {
  488. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  489. pm860x_irqs[data->irq - chip->irq_base].enable
  490. = pm860x_irqs[data->irq - chip->irq_base].offs;
  491. }
  492. static void pm860x_irq_disable(struct irq_data *data)
  493. {
  494. struct pm860x_chip *chip = irq_data_get_irq_chip_data(data);
  495. pm860x_irqs[data->irq - chip->irq_base].enable = 0;
  496. }
  497. static struct irq_chip pm860x_irq_chip = {
  498. .name = "88pm860x",
  499. .irq_bus_lock = pm860x_irq_lock,
  500. .irq_bus_sync_unlock = pm860x_irq_sync_unlock,
  501. .irq_enable = pm860x_irq_enable,
  502. .irq_disable = pm860x_irq_disable,
  503. };
  504. static int __devinit device_gpadc_init(struct pm860x_chip *chip,
  505. struct pm860x_platform_data *pdata)
  506. {
  507. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  508. : chip->companion;
  509. int data;
  510. int ret;
  511. /* initialize GPADC without activating it */
  512. if (!pdata || !pdata->touch)
  513. return -EINVAL;
  514. /* set GPADC MISC1 register */
  515. data = 0;
  516. data |= (pdata->touch->gpadc_prebias << 1) & PM8607_GPADC_PREBIAS_MASK;
  517. data |= (pdata->touch->slot_cycle << 3) & PM8607_GPADC_SLOT_CYCLE_MASK;
  518. data |= (pdata->touch->off_scale << 5) & PM8607_GPADC_OFF_SCALE_MASK;
  519. data |= (pdata->touch->sw_cal << 7) & PM8607_GPADC_SW_CAL_MASK;
  520. if (data) {
  521. ret = pm860x_reg_write(i2c, PM8607_GPADC_MISC1, data);
  522. if (ret < 0)
  523. goto out;
  524. }
  525. /* set tsi prebias time */
  526. if (pdata->touch->tsi_prebias) {
  527. data = pdata->touch->tsi_prebias;
  528. ret = pm860x_reg_write(i2c, PM8607_TSI_PREBIAS, data);
  529. if (ret < 0)
  530. goto out;
  531. }
  532. /* set prebias & prechg time of pen detect */
  533. data = 0;
  534. data |= pdata->touch->pen_prebias & PM8607_PD_PREBIAS_MASK;
  535. data |= (pdata->touch->pen_prechg << 5) & PM8607_PD_PRECHG_MASK;
  536. if (data) {
  537. ret = pm860x_reg_write(i2c, PM8607_PD_PREBIAS, data);
  538. if (ret < 0)
  539. goto out;
  540. }
  541. ret = pm860x_set_bits(i2c, PM8607_GPADC_MISC1,
  542. PM8607_GPADC_EN, PM8607_GPADC_EN);
  543. out:
  544. return ret;
  545. }
  546. static int __devinit device_irq_init(struct pm860x_chip *chip,
  547. struct pm860x_platform_data *pdata)
  548. {
  549. struct i2c_client *i2c = (chip->id == CHIP_PM8607) ? chip->client \
  550. : chip->companion;
  551. unsigned char status_buf[INT_STATUS_NUM];
  552. unsigned long flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT;
  553. int i, data, mask, ret = -EINVAL;
  554. int __irq;
  555. if (!pdata || !pdata->irq_base) {
  556. dev_warn(chip->dev, "No interrupt support on IRQ base\n");
  557. return -EINVAL;
  558. }
  559. mask = PM8607_B0_MISC1_INV_INT | PM8607_B0_MISC1_INT_CLEAR
  560. | PM8607_B0_MISC1_INT_MASK;
  561. data = 0;
  562. chip->irq_mode = 0;
  563. if (pdata && pdata->irq_mode) {
  564. /*
  565. * irq_mode defines the way of clearing interrupt. If it's 1,
  566. * clear IRQ by write. Otherwise, clear it by read.
  567. * This control bit is valid from 88PM8607 B0 steping.
  568. */
  569. data |= PM8607_B0_MISC1_INT_CLEAR;
  570. chip->irq_mode = 1;
  571. }
  572. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, mask, data);
  573. if (ret < 0)
  574. goto out;
  575. /* mask all IRQs */
  576. memset(status_buf, 0, INT_STATUS_NUM);
  577. ret = pm860x_bulk_write(i2c, PM8607_INT_MASK_1,
  578. INT_STATUS_NUM, status_buf);
  579. if (ret < 0)
  580. goto out;
  581. if (chip->irq_mode) {
  582. /* clear interrupt status by write */
  583. memset(status_buf, 0xFF, INT_STATUS_NUM);
  584. ret = pm860x_bulk_write(i2c, PM8607_INT_STATUS1,
  585. INT_STATUS_NUM, status_buf);
  586. } else {
  587. /* clear interrupt status by read */
  588. ret = pm860x_bulk_read(i2c, PM8607_INT_STATUS1,
  589. INT_STATUS_NUM, status_buf);
  590. }
  591. if (ret < 0)
  592. goto out;
  593. mutex_init(&chip->irq_lock);
  594. chip->irq_base = pdata->irq_base;
  595. chip->core_irq = i2c->irq;
  596. if (!chip->core_irq)
  597. goto out;
  598. /* register IRQ by genirq */
  599. for (i = 0; i < ARRAY_SIZE(pm860x_irqs); i++) {
  600. __irq = i + chip->irq_base;
  601. irq_set_chip_data(__irq, chip);
  602. irq_set_chip_and_handler(__irq, &pm860x_irq_chip,
  603. handle_edge_irq);
  604. irq_set_nested_thread(__irq, 1);
  605. #ifdef CONFIG_ARM
  606. set_irq_flags(__irq, IRQF_VALID);
  607. #else
  608. irq_set_noprobe(__irq);
  609. #endif
  610. }
  611. ret = request_threaded_irq(chip->core_irq, NULL, pm860x_irq, flags | IRQF_ONESHOT,
  612. "88pm860x", chip);
  613. if (ret) {
  614. dev_err(chip->dev, "Failed to request IRQ: %d\n", ret);
  615. chip->core_irq = 0;
  616. }
  617. return 0;
  618. out:
  619. chip->core_irq = 0;
  620. return ret;
  621. }
  622. static void device_irq_exit(struct pm860x_chip *chip)
  623. {
  624. if (chip->core_irq)
  625. free_irq(chip->core_irq, chip);
  626. }
  627. int pm8606_osc_enable(struct pm860x_chip *chip, unsigned short client)
  628. {
  629. int ret = -EIO;
  630. struct i2c_client *i2c = (chip->id == CHIP_PM8606) ?
  631. chip->client : chip->companion;
  632. dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client);
  633. dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n",
  634. __func__, chip->osc_vote,
  635. chip->osc_status);
  636. mutex_lock(&chip->osc_lock);
  637. /* Update voting status */
  638. chip->osc_vote |= client;
  639. /* If reference group is off - turn on*/
  640. if (chip->osc_status != PM8606_REF_GP_OSC_ON) {
  641. chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN;
  642. /* Enable Reference group Vsys */
  643. if (pm860x_set_bits(i2c, PM8606_VSYS,
  644. PM8606_VSYS_EN, PM8606_VSYS_EN))
  645. goto out;
  646. /*Enable Internal Oscillator */
  647. if (pm860x_set_bits(i2c, PM8606_MISC,
  648. PM8606_MISC_OSC_EN, PM8606_MISC_OSC_EN))
  649. goto out;
  650. /* Update status (only if writes succeed) */
  651. chip->osc_status = PM8606_REF_GP_OSC_ON;
  652. }
  653. mutex_unlock(&chip->osc_lock);
  654. dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n",
  655. __func__, chip->osc_vote,
  656. chip->osc_status, ret);
  657. return 0;
  658. out:
  659. mutex_unlock(&chip->osc_lock);
  660. return ret;
  661. }
  662. EXPORT_SYMBOL(pm8606_osc_enable);
  663. int pm8606_osc_disable(struct pm860x_chip *chip, unsigned short client)
  664. {
  665. int ret = -EIO;
  666. struct i2c_client *i2c = (chip->id == CHIP_PM8606) ?
  667. chip->client : chip->companion;
  668. dev_dbg(chip->dev, "%s(B): client=0x%x\n", __func__, client);
  669. dev_dbg(chip->dev, "%s(B): vote=0x%x status=%d\n",
  670. __func__, chip->osc_vote,
  671. chip->osc_status);
  672. mutex_lock(&chip->osc_lock);
  673. /*Update voting status */
  674. chip->osc_vote &= ~(client);
  675. /* If reference group is off and this is the last client to release
  676. * - turn off */
  677. if ((chip->osc_status != PM8606_REF_GP_OSC_OFF) &&
  678. (chip->osc_vote == REF_GP_NO_CLIENTS)) {
  679. chip->osc_status = PM8606_REF_GP_OSC_UNKNOWN;
  680. /* Disable Reference group Vsys */
  681. if (pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0))
  682. goto out;
  683. /* Disable Internal Oscillator */
  684. if (pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0))
  685. goto out;
  686. chip->osc_status = PM8606_REF_GP_OSC_OFF;
  687. }
  688. mutex_unlock(&chip->osc_lock);
  689. dev_dbg(chip->dev, "%s(A): vote=0x%x status=%d ret=%d\n",
  690. __func__, chip->osc_vote,
  691. chip->osc_status, ret);
  692. return 0;
  693. out:
  694. mutex_unlock(&chip->osc_lock);
  695. return ret;
  696. }
  697. EXPORT_SYMBOL(pm8606_osc_disable);
  698. static void __devinit device_osc_init(struct i2c_client *i2c)
  699. {
  700. struct pm860x_chip *chip = i2c_get_clientdata(i2c);
  701. mutex_init(&chip->osc_lock);
  702. /* init portofino reference group voting and status */
  703. /* Disable Reference group Vsys */
  704. pm860x_set_bits(i2c, PM8606_VSYS, PM8606_VSYS_EN, 0);
  705. /* Disable Internal Oscillator */
  706. pm860x_set_bits(i2c, PM8606_MISC, PM8606_MISC_OSC_EN, 0);
  707. chip->osc_vote = REF_GP_NO_CLIENTS;
  708. chip->osc_status = PM8606_REF_GP_OSC_OFF;
  709. }
  710. static void __devinit device_bk_init(struct pm860x_chip *chip,
  711. struct pm860x_platform_data *pdata)
  712. {
  713. int ret, i;
  714. if (pdata && pdata->backlight) {
  715. if (pdata->num_backlights > ARRAY_SIZE(bk_devs))
  716. pdata->num_backlights = ARRAY_SIZE(bk_devs);
  717. for (i = 0; i < pdata->num_backlights; i++) {
  718. bk_devs[i].platform_data = &pdata->backlight[i];
  719. bk_devs[i].pdata_size =
  720. sizeof(struct pm860x_backlight_pdata);
  721. }
  722. }
  723. ret = mfd_add_devices(chip->dev, 0, bk_devs,
  724. ARRAY_SIZE(bk_devs), NULL, 0, NULL);
  725. if (ret < 0)
  726. dev_err(chip->dev, "Failed to add backlight subdev\n");
  727. }
  728. static void __devinit device_led_init(struct pm860x_chip *chip,
  729. struct pm860x_platform_data *pdata)
  730. {
  731. int ret, i;
  732. if (pdata && pdata->led) {
  733. if (pdata->num_leds > ARRAY_SIZE(led_devs))
  734. pdata->num_leds = ARRAY_SIZE(led_devs);
  735. for (i = 0; i < pdata->num_leds; i++) {
  736. led_devs[i].platform_data = &pdata->led[i];
  737. led_devs[i].pdata_size =
  738. sizeof(struct pm860x_led_pdata);
  739. }
  740. }
  741. ret = mfd_add_devices(chip->dev, 0, led_devs,
  742. ARRAY_SIZE(led_devs), NULL, 0, NULL);
  743. if (ret < 0) {
  744. dev_err(chip->dev, "Failed to add led subdev\n");
  745. return;
  746. }
  747. }
  748. static void __devinit device_regulator_init(struct pm860x_chip *chip,
  749. struct pm860x_platform_data *pdata)
  750. {
  751. int ret;
  752. if (pdata == NULL)
  753. return;
  754. if (pdata->buck1) {
  755. reg_devs[0].platform_data = pdata->buck1;
  756. reg_devs[0].pdata_size = sizeof(struct regulator_init_data);
  757. }
  758. if (pdata->buck2) {
  759. reg_devs[1].platform_data = pdata->buck2;
  760. reg_devs[1].pdata_size = sizeof(struct regulator_init_data);
  761. }
  762. if (pdata->buck3) {
  763. reg_devs[2].platform_data = pdata->buck3;
  764. reg_devs[2].pdata_size = sizeof(struct regulator_init_data);
  765. }
  766. if (pdata->ldo1) {
  767. reg_devs[3].platform_data = pdata->ldo1;
  768. reg_devs[3].pdata_size = sizeof(struct regulator_init_data);
  769. }
  770. if (pdata->ldo2) {
  771. reg_devs[4].platform_data = pdata->ldo2;
  772. reg_devs[4].pdata_size = sizeof(struct regulator_init_data);
  773. }
  774. if (pdata->ldo3) {
  775. reg_devs[5].platform_data = pdata->ldo3;
  776. reg_devs[5].pdata_size = sizeof(struct regulator_init_data);
  777. }
  778. if (pdata->ldo4) {
  779. reg_devs[6].platform_data = pdata->ldo4;
  780. reg_devs[6].pdata_size = sizeof(struct regulator_init_data);
  781. }
  782. if (pdata->ldo5) {
  783. reg_devs[7].platform_data = pdata->ldo5;
  784. reg_devs[7].pdata_size = sizeof(struct regulator_init_data);
  785. }
  786. if (pdata->ldo6) {
  787. reg_devs[8].platform_data = pdata->ldo6;
  788. reg_devs[8].pdata_size = sizeof(struct regulator_init_data);
  789. }
  790. if (pdata->ldo7) {
  791. reg_devs[9].platform_data = pdata->ldo7;
  792. reg_devs[9].pdata_size = sizeof(struct regulator_init_data);
  793. }
  794. if (pdata->ldo8) {
  795. reg_devs[10].platform_data = pdata->ldo8;
  796. reg_devs[10].pdata_size = sizeof(struct regulator_init_data);
  797. }
  798. if (pdata->ldo9) {
  799. reg_devs[11].platform_data = pdata->ldo9;
  800. reg_devs[11].pdata_size = sizeof(struct regulator_init_data);
  801. }
  802. if (pdata->ldo10) {
  803. reg_devs[12].platform_data = pdata->ldo10;
  804. reg_devs[12].pdata_size = sizeof(struct regulator_init_data);
  805. }
  806. if (pdata->ldo12) {
  807. reg_devs[13].platform_data = pdata->ldo12;
  808. reg_devs[13].pdata_size = sizeof(struct regulator_init_data);
  809. }
  810. if (pdata->ldo_vibrator) {
  811. reg_devs[14].platform_data = pdata->ldo_vibrator;
  812. reg_devs[14].pdata_size = sizeof(struct regulator_init_data);
  813. }
  814. if (pdata->ldo14) {
  815. reg_devs[15].platform_data = pdata->ldo14;
  816. reg_devs[15].pdata_size = sizeof(struct regulator_init_data);
  817. }
  818. ret = mfd_add_devices(chip->dev, 0, reg_devs,
  819. ARRAY_SIZE(reg_devs), NULL, 0, NULL);
  820. if (ret < 0) {
  821. dev_err(chip->dev, "Failed to add regulator subdev\n");
  822. return;
  823. }
  824. }
  825. static void __devinit device_rtc_init(struct pm860x_chip *chip,
  826. struct pm860x_platform_data *pdata)
  827. {
  828. int ret;
  829. if ((pdata == NULL))
  830. return;
  831. rtc_devs[0].platform_data = pdata->rtc;
  832. rtc_devs[0].pdata_size = sizeof(struct pm860x_rtc_pdata);
  833. rtc_devs[0].num_resources = ARRAY_SIZE(rtc_resources);
  834. rtc_devs[0].resources = &rtc_resources[0];
  835. ret = mfd_add_devices(chip->dev, 0, &rtc_devs[0],
  836. ARRAY_SIZE(rtc_devs), &rtc_resources[0],
  837. chip->irq_base, NULL);
  838. if (ret < 0)
  839. dev_err(chip->dev, "Failed to add rtc subdev\n");
  840. }
  841. static void __devinit device_touch_init(struct pm860x_chip *chip,
  842. struct pm860x_platform_data *pdata)
  843. {
  844. int ret;
  845. if (pdata == NULL)
  846. return;
  847. touch_devs[0].platform_data = pdata->touch;
  848. touch_devs[0].pdata_size = sizeof(struct pm860x_touch_pdata);
  849. touch_devs[0].num_resources = ARRAY_SIZE(touch_resources);
  850. touch_devs[0].resources = &touch_resources[0];
  851. ret = mfd_add_devices(chip->dev, 0, &touch_devs[0],
  852. ARRAY_SIZE(touch_devs), &touch_resources[0],
  853. chip->irq_base, NULL);
  854. if (ret < 0)
  855. dev_err(chip->dev, "Failed to add touch subdev\n");
  856. }
  857. static void __devinit device_power_init(struct pm860x_chip *chip,
  858. struct pm860x_platform_data *pdata)
  859. {
  860. int ret;
  861. if (pdata == NULL)
  862. return;
  863. power_devs[0].platform_data = pdata->power;
  864. power_devs[0].pdata_size = sizeof(struct pm860x_power_pdata);
  865. power_devs[0].num_resources = ARRAY_SIZE(battery_resources);
  866. power_devs[0].resources = &battery_resources[0],
  867. ret = mfd_add_devices(chip->dev, 0, &power_devs[0], 1,
  868. &battery_resources[0], chip->irq_base, NULL);
  869. if (ret < 0)
  870. dev_err(chip->dev, "Failed to add battery subdev\n");
  871. power_devs[1].platform_data = pdata->power;
  872. power_devs[1].pdata_size = sizeof(struct pm860x_power_pdata);
  873. power_devs[1].num_resources = ARRAY_SIZE(charger_resources);
  874. power_devs[1].resources = &charger_resources[0],
  875. ret = mfd_add_devices(chip->dev, 0, &power_devs[1], 1,
  876. &charger_resources[0], chip->irq_base, NULL);
  877. if (ret < 0)
  878. dev_err(chip->dev, "Failed to add charger subdev\n");
  879. power_devs[2].platform_data = &preg_init_data;
  880. power_devs[2].pdata_size = sizeof(struct regulator_init_data);
  881. ret = mfd_add_devices(chip->dev, 0, &power_devs[2], 1,
  882. NULL, chip->irq_base, NULL);
  883. if (ret < 0)
  884. dev_err(chip->dev, "Failed to add preg subdev\n");
  885. }
  886. static void __devinit device_onkey_init(struct pm860x_chip *chip,
  887. struct pm860x_platform_data *pdata)
  888. {
  889. int ret;
  890. onkey_devs[0].num_resources = ARRAY_SIZE(onkey_resources);
  891. onkey_devs[0].resources = &onkey_resources[0],
  892. ret = mfd_add_devices(chip->dev, 0, &onkey_devs[0],
  893. ARRAY_SIZE(onkey_devs), &onkey_resources[0],
  894. chip->irq_base, NULL);
  895. if (ret < 0)
  896. dev_err(chip->dev, "Failed to add onkey subdev\n");
  897. }
  898. static void __devinit device_codec_init(struct pm860x_chip *chip,
  899. struct pm860x_platform_data *pdata)
  900. {
  901. int ret;
  902. codec_devs[0].num_resources = ARRAY_SIZE(codec_resources);
  903. codec_devs[0].resources = &codec_resources[0],
  904. ret = mfd_add_devices(chip->dev, 0, &codec_devs[0],
  905. ARRAY_SIZE(codec_devs), &codec_resources[0], 0,
  906. NULL);
  907. if (ret < 0)
  908. dev_err(chip->dev, "Failed to add codec subdev\n");
  909. }
  910. static void __devinit device_8607_init(struct pm860x_chip *chip,
  911. struct i2c_client *i2c,
  912. struct pm860x_platform_data *pdata)
  913. {
  914. int data, ret;
  915. ret = pm860x_reg_read(i2c, PM8607_CHIP_ID);
  916. if (ret < 0) {
  917. dev_err(chip->dev, "Failed to read CHIP ID: %d\n", ret);
  918. goto out;
  919. }
  920. switch (ret & PM8607_VERSION_MASK) {
  921. case 0x40:
  922. case 0x50:
  923. dev_info(chip->dev, "Marvell 88PM8607 (ID: %02x) detected\n",
  924. ret);
  925. break;
  926. default:
  927. dev_err(chip->dev, "Failed to detect Marvell 88PM8607. "
  928. "Chip ID: %02x\n", ret);
  929. goto out;
  930. }
  931. ret = pm860x_reg_read(i2c, PM8607_BUCK3);
  932. if (ret < 0) {
  933. dev_err(chip->dev, "Failed to read BUCK3 register: %d\n", ret);
  934. goto out;
  935. }
  936. if (ret & PM8607_BUCK3_DOUBLE)
  937. chip->buck3_double = 1;
  938. ret = pm860x_reg_read(i2c, PM8607_B0_MISC1);
  939. if (ret < 0) {
  940. dev_err(chip->dev, "Failed to read MISC1 register: %d\n", ret);
  941. goto out;
  942. }
  943. if (pdata && (pdata->i2c_port == PI2C_PORT))
  944. data = PM8607_B0_MISC1_PI2C;
  945. else
  946. data = 0;
  947. ret = pm860x_set_bits(i2c, PM8607_B0_MISC1, PM8607_B0_MISC1_PI2C, data);
  948. if (ret < 0) {
  949. dev_err(chip->dev, "Failed to access MISC1:%d\n", ret);
  950. goto out;
  951. }
  952. ret = device_gpadc_init(chip, pdata);
  953. if (ret < 0)
  954. goto out;
  955. ret = device_irq_init(chip, pdata);
  956. if (ret < 0)
  957. goto out;
  958. device_regulator_init(chip, pdata);
  959. device_rtc_init(chip, pdata);
  960. device_onkey_init(chip, pdata);
  961. device_touch_init(chip, pdata);
  962. device_power_init(chip, pdata);
  963. device_codec_init(chip, pdata);
  964. out:
  965. return;
  966. }
  967. static void __devinit device_8606_init(struct pm860x_chip *chip,
  968. struct i2c_client *i2c,
  969. struct pm860x_platform_data *pdata)
  970. {
  971. device_osc_init(i2c);
  972. device_bk_init(chip, pdata);
  973. device_led_init(chip, pdata);
  974. }
  975. int __devinit pm860x_device_init(struct pm860x_chip *chip,
  976. struct pm860x_platform_data *pdata)
  977. {
  978. chip->core_irq = 0;
  979. switch (chip->id) {
  980. case CHIP_PM8606:
  981. device_8606_init(chip, chip->client, pdata);
  982. break;
  983. case CHIP_PM8607:
  984. device_8607_init(chip, chip->client, pdata);
  985. break;
  986. }
  987. if (chip->companion) {
  988. switch (chip->id) {
  989. case CHIP_PM8607:
  990. device_8606_init(chip, chip->companion, pdata);
  991. break;
  992. case CHIP_PM8606:
  993. device_8607_init(chip, chip->companion, pdata);
  994. break;
  995. }
  996. }
  997. return 0;
  998. }
  999. void __devexit pm860x_device_exit(struct pm860x_chip *chip)
  1000. {
  1001. device_irq_exit(chip);
  1002. mfd_remove_devices(chip->dev);
  1003. }
  1004. MODULE_DESCRIPTION("PMIC Driver for Marvell 88PM860x");
  1005. MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
  1006. MODULE_LICENSE("GPL");