wm831x-core.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609
  1. /*
  2. * wm831x-core.c -- Device access for Wolfson WM831x PMICs
  3. *
  4. * Copyright 2009 Wolfson Microelectronics PLC.
  5. *
  6. * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. *
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/bcd.h>
  17. #include <linux/delay.h>
  18. #include <linux/mfd/core.h>
  19. #include <linux/slab.h>
  20. #include <linux/mfd/wm831x/core.h>
  21. #include <linux/mfd/wm831x/pdata.h>
  22. #include <linux/mfd/wm831x/irq.h>
  23. #include <linux/mfd/wm831x/auxadc.h>
  24. #include <linux/mfd/wm831x/otp.h>
  25. #include <linux/mfd/wm831x/regulator.h>
  26. /* Current settings - values are 2*2^(reg_val/4) microamps. These are
  27. * exported since they are used by multiple drivers.
  28. */
  29. int wm831x_isinkv_values[WM831X_ISINK_MAX_ISEL + 1] = {
  30. 2,
  31. 2,
  32. 3,
  33. 3,
  34. 4,
  35. 5,
  36. 6,
  37. 7,
  38. 8,
  39. 10,
  40. 11,
  41. 13,
  42. 16,
  43. 19,
  44. 23,
  45. 27,
  46. 32,
  47. 38,
  48. 45,
  49. 54,
  50. 64,
  51. 76,
  52. 91,
  53. 108,
  54. 128,
  55. 152,
  56. 181,
  57. 215,
  58. 256,
  59. 304,
  60. 362,
  61. 431,
  62. 512,
  63. 609,
  64. 724,
  65. 861,
  66. 1024,
  67. 1218,
  68. 1448,
  69. 1722,
  70. 2048,
  71. 2435,
  72. 2896,
  73. 3444,
  74. 4096,
  75. 4871,
  76. 5793,
  77. 6889,
  78. 8192,
  79. 9742,
  80. 11585,
  81. 13777,
  82. 16384,
  83. 19484,
  84. 23170,
  85. 27554,
  86. };
  87. EXPORT_SYMBOL_GPL(wm831x_isinkv_values);
  88. static int wm831x_reg_locked(struct wm831x *wm831x, unsigned short reg)
  89. {
  90. if (!wm831x->locked)
  91. return 0;
  92. switch (reg) {
  93. case WM831X_WATCHDOG:
  94. case WM831X_DC4_CONTROL:
  95. case WM831X_ON_PIN_CONTROL:
  96. case WM831X_BACKUP_CHARGER_CONTROL:
  97. case WM831X_CHARGER_CONTROL_1:
  98. case WM831X_CHARGER_CONTROL_2:
  99. return 1;
  100. default:
  101. return 0;
  102. }
  103. }
  104. /**
  105. * wm831x_reg_unlock: Unlock user keyed registers
  106. *
  107. * The WM831x has a user key preventing writes to particularly
  108. * critical registers. This function locks those registers,
  109. * allowing writes to them.
  110. */
  111. void wm831x_reg_lock(struct wm831x *wm831x)
  112. {
  113. int ret;
  114. ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  115. if (ret == 0) {
  116. dev_vdbg(wm831x->dev, "Registers locked\n");
  117. mutex_lock(&wm831x->io_lock);
  118. WARN_ON(wm831x->locked);
  119. wm831x->locked = 1;
  120. mutex_unlock(&wm831x->io_lock);
  121. } else {
  122. dev_err(wm831x->dev, "Failed to lock registers: %d\n", ret);
  123. }
  124. }
  125. EXPORT_SYMBOL_GPL(wm831x_reg_lock);
  126. /**
  127. * wm831x_reg_unlock: Unlock user keyed registers
  128. *
  129. * The WM831x has a user key preventing writes to particularly
  130. * critical registers. This function locks those registers,
  131. * preventing spurious writes.
  132. */
  133. int wm831x_reg_unlock(struct wm831x *wm831x)
  134. {
  135. int ret;
  136. /* 0x9716 is the value required to unlock the registers */
  137. ret = wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0x9716);
  138. if (ret == 0) {
  139. dev_vdbg(wm831x->dev, "Registers unlocked\n");
  140. mutex_lock(&wm831x->io_lock);
  141. WARN_ON(!wm831x->locked);
  142. wm831x->locked = 0;
  143. mutex_unlock(&wm831x->io_lock);
  144. }
  145. return ret;
  146. }
  147. EXPORT_SYMBOL_GPL(wm831x_reg_unlock);
  148. static int wm831x_read(struct wm831x *wm831x, unsigned short reg,
  149. int bytes, void *dest)
  150. {
  151. int ret, i;
  152. u16 *buf = dest;
  153. BUG_ON(bytes % 2);
  154. BUG_ON(bytes <= 0);
  155. ret = wm831x->read_dev(wm831x, reg, bytes, dest);
  156. if (ret < 0)
  157. return ret;
  158. for (i = 0; i < bytes / 2; i++) {
  159. buf[i] = be16_to_cpu(buf[i]);
  160. dev_vdbg(wm831x->dev, "Read %04x from R%d(0x%x)\n",
  161. buf[i], reg + i, reg + i);
  162. }
  163. return 0;
  164. }
  165. /**
  166. * wm831x_reg_read: Read a single WM831x register.
  167. *
  168. * @wm831x: Device to read from.
  169. * @reg: Register to read.
  170. */
  171. int wm831x_reg_read(struct wm831x *wm831x, unsigned short reg)
  172. {
  173. unsigned short val;
  174. int ret;
  175. mutex_lock(&wm831x->io_lock);
  176. ret = wm831x_read(wm831x, reg, 2, &val);
  177. mutex_unlock(&wm831x->io_lock);
  178. if (ret < 0)
  179. return ret;
  180. else
  181. return val;
  182. }
  183. EXPORT_SYMBOL_GPL(wm831x_reg_read);
  184. /**
  185. * wm831x_bulk_read: Read multiple WM831x registers
  186. *
  187. * @wm831x: Device to read from
  188. * @reg: First register
  189. * @count: Number of registers
  190. * @buf: Buffer to fill.
  191. */
  192. int wm831x_bulk_read(struct wm831x *wm831x, unsigned short reg,
  193. int count, u16 *buf)
  194. {
  195. int ret;
  196. mutex_lock(&wm831x->io_lock);
  197. ret = wm831x_read(wm831x, reg, count * 2, buf);
  198. mutex_unlock(&wm831x->io_lock);
  199. return ret;
  200. }
  201. EXPORT_SYMBOL_GPL(wm831x_bulk_read);
  202. static int wm831x_write(struct wm831x *wm831x, unsigned short reg,
  203. int bytes, void *src)
  204. {
  205. u16 *buf = src;
  206. int i;
  207. BUG_ON(bytes % 2);
  208. BUG_ON(bytes <= 0);
  209. for (i = 0; i < bytes / 2; i++) {
  210. if (wm831x_reg_locked(wm831x, reg))
  211. return -EPERM;
  212. dev_vdbg(wm831x->dev, "Write %04x to R%d(0x%x)\n",
  213. buf[i], reg + i, reg + i);
  214. buf[i] = cpu_to_be16(buf[i]);
  215. }
  216. return wm831x->write_dev(wm831x, reg, bytes, src);
  217. }
  218. /**
  219. * wm831x_reg_write: Write a single WM831x register.
  220. *
  221. * @wm831x: Device to write to.
  222. * @reg: Register to write to.
  223. * @val: Value to write.
  224. */
  225. int wm831x_reg_write(struct wm831x *wm831x, unsigned short reg,
  226. unsigned short val)
  227. {
  228. int ret;
  229. mutex_lock(&wm831x->io_lock);
  230. ret = wm831x_write(wm831x, reg, 2, &val);
  231. mutex_unlock(&wm831x->io_lock);
  232. return ret;
  233. }
  234. EXPORT_SYMBOL_GPL(wm831x_reg_write);
  235. /**
  236. * wm831x_set_bits: Set the value of a bitfield in a WM831x register
  237. *
  238. * @wm831x: Device to write to.
  239. * @reg: Register to write to.
  240. * @mask: Mask of bits to set.
  241. * @val: Value to set (unshifted)
  242. */
  243. int wm831x_set_bits(struct wm831x *wm831x, unsigned short reg,
  244. unsigned short mask, unsigned short val)
  245. {
  246. int ret;
  247. u16 r;
  248. mutex_lock(&wm831x->io_lock);
  249. ret = wm831x_read(wm831x, reg, 2, &r);
  250. if (ret < 0)
  251. goto out;
  252. r &= ~mask;
  253. r |= val & mask;
  254. ret = wm831x_write(wm831x, reg, 2, &r);
  255. out:
  256. mutex_unlock(&wm831x->io_lock);
  257. return ret;
  258. }
  259. EXPORT_SYMBOL_GPL(wm831x_set_bits);
  260. static struct resource wm831x_dcdc1_resources[] = {
  261. {
  262. .start = WM831X_DC1_CONTROL_1,
  263. .end = WM831X_DC1_DVS_CONTROL,
  264. .flags = IORESOURCE_IO,
  265. },
  266. {
  267. .name = "UV",
  268. .start = WM831X_IRQ_UV_DC1,
  269. .end = WM831X_IRQ_UV_DC1,
  270. .flags = IORESOURCE_IRQ,
  271. },
  272. {
  273. .name = "HC",
  274. .start = WM831X_IRQ_HC_DC1,
  275. .end = WM831X_IRQ_HC_DC1,
  276. .flags = IORESOURCE_IRQ,
  277. },
  278. };
  279. static struct resource wm831x_dcdc2_resources[] = {
  280. {
  281. .start = WM831X_DC2_CONTROL_1,
  282. .end = WM831X_DC2_DVS_CONTROL,
  283. .flags = IORESOURCE_IO,
  284. },
  285. {
  286. .name = "UV",
  287. .start = WM831X_IRQ_UV_DC2,
  288. .end = WM831X_IRQ_UV_DC2,
  289. .flags = IORESOURCE_IRQ,
  290. },
  291. {
  292. .name = "HC",
  293. .start = WM831X_IRQ_HC_DC2,
  294. .end = WM831X_IRQ_HC_DC2,
  295. .flags = IORESOURCE_IRQ,
  296. },
  297. };
  298. static struct resource wm831x_dcdc3_resources[] = {
  299. {
  300. .start = WM831X_DC3_CONTROL_1,
  301. .end = WM831X_DC3_SLEEP_CONTROL,
  302. .flags = IORESOURCE_IO,
  303. },
  304. {
  305. .name = "UV",
  306. .start = WM831X_IRQ_UV_DC3,
  307. .end = WM831X_IRQ_UV_DC3,
  308. .flags = IORESOURCE_IRQ,
  309. },
  310. };
  311. static struct resource wm831x_dcdc4_resources[] = {
  312. {
  313. .start = WM831X_DC4_CONTROL,
  314. .end = WM831X_DC4_SLEEP_CONTROL,
  315. .flags = IORESOURCE_IO,
  316. },
  317. {
  318. .name = "UV",
  319. .start = WM831X_IRQ_UV_DC4,
  320. .end = WM831X_IRQ_UV_DC4,
  321. .flags = IORESOURCE_IRQ,
  322. },
  323. };
  324. static struct resource wm8320_dcdc4_buck_resources[] = {
  325. {
  326. .start = WM831X_DC4_CONTROL,
  327. .end = WM832X_DC4_SLEEP_CONTROL,
  328. .flags = IORESOURCE_IO,
  329. },
  330. {
  331. .name = "UV",
  332. .start = WM831X_IRQ_UV_DC4,
  333. .end = WM831X_IRQ_UV_DC4,
  334. .flags = IORESOURCE_IRQ,
  335. },
  336. };
  337. static struct resource wm831x_gpio_resources[] = {
  338. {
  339. .start = WM831X_IRQ_GPIO_1,
  340. .end = WM831X_IRQ_GPIO_16,
  341. .flags = IORESOURCE_IRQ,
  342. },
  343. };
  344. static struct resource wm831x_isink1_resources[] = {
  345. {
  346. .start = WM831X_CURRENT_SINK_1,
  347. .end = WM831X_CURRENT_SINK_1,
  348. .flags = IORESOURCE_IO,
  349. },
  350. {
  351. .start = WM831X_IRQ_CS1,
  352. .end = WM831X_IRQ_CS1,
  353. .flags = IORESOURCE_IRQ,
  354. },
  355. };
  356. static struct resource wm831x_isink2_resources[] = {
  357. {
  358. .start = WM831X_CURRENT_SINK_2,
  359. .end = WM831X_CURRENT_SINK_2,
  360. .flags = IORESOURCE_IO,
  361. },
  362. {
  363. .start = WM831X_IRQ_CS2,
  364. .end = WM831X_IRQ_CS2,
  365. .flags = IORESOURCE_IRQ,
  366. },
  367. };
  368. static struct resource wm831x_ldo1_resources[] = {
  369. {
  370. .start = WM831X_LDO1_CONTROL,
  371. .end = WM831X_LDO1_SLEEP_CONTROL,
  372. .flags = IORESOURCE_IO,
  373. },
  374. {
  375. .name = "UV",
  376. .start = WM831X_IRQ_UV_LDO1,
  377. .end = WM831X_IRQ_UV_LDO1,
  378. .flags = IORESOURCE_IRQ,
  379. },
  380. };
  381. static struct resource wm831x_ldo2_resources[] = {
  382. {
  383. .start = WM831X_LDO2_CONTROL,
  384. .end = WM831X_LDO2_SLEEP_CONTROL,
  385. .flags = IORESOURCE_IO,
  386. },
  387. {
  388. .name = "UV",
  389. .start = WM831X_IRQ_UV_LDO2,
  390. .end = WM831X_IRQ_UV_LDO2,
  391. .flags = IORESOURCE_IRQ,
  392. },
  393. };
  394. static struct resource wm831x_ldo3_resources[] = {
  395. {
  396. .start = WM831X_LDO3_CONTROL,
  397. .end = WM831X_LDO3_SLEEP_CONTROL,
  398. .flags = IORESOURCE_IO,
  399. },
  400. {
  401. .name = "UV",
  402. .start = WM831X_IRQ_UV_LDO3,
  403. .end = WM831X_IRQ_UV_LDO3,
  404. .flags = IORESOURCE_IRQ,
  405. },
  406. };
  407. static struct resource wm831x_ldo4_resources[] = {
  408. {
  409. .start = WM831X_LDO4_CONTROL,
  410. .end = WM831X_LDO4_SLEEP_CONTROL,
  411. .flags = IORESOURCE_IO,
  412. },
  413. {
  414. .name = "UV",
  415. .start = WM831X_IRQ_UV_LDO4,
  416. .end = WM831X_IRQ_UV_LDO4,
  417. .flags = IORESOURCE_IRQ,
  418. },
  419. };
  420. static struct resource wm831x_ldo5_resources[] = {
  421. {
  422. .start = WM831X_LDO5_CONTROL,
  423. .end = WM831X_LDO5_SLEEP_CONTROL,
  424. .flags = IORESOURCE_IO,
  425. },
  426. {
  427. .name = "UV",
  428. .start = WM831X_IRQ_UV_LDO5,
  429. .end = WM831X_IRQ_UV_LDO5,
  430. .flags = IORESOURCE_IRQ,
  431. },
  432. };
  433. static struct resource wm831x_ldo6_resources[] = {
  434. {
  435. .start = WM831X_LDO6_CONTROL,
  436. .end = WM831X_LDO6_SLEEP_CONTROL,
  437. .flags = IORESOURCE_IO,
  438. },
  439. {
  440. .name = "UV",
  441. .start = WM831X_IRQ_UV_LDO6,
  442. .end = WM831X_IRQ_UV_LDO6,
  443. .flags = IORESOURCE_IRQ,
  444. },
  445. };
  446. static struct resource wm831x_ldo7_resources[] = {
  447. {
  448. .start = WM831X_LDO7_CONTROL,
  449. .end = WM831X_LDO7_SLEEP_CONTROL,
  450. .flags = IORESOURCE_IO,
  451. },
  452. {
  453. .name = "UV",
  454. .start = WM831X_IRQ_UV_LDO7,
  455. .end = WM831X_IRQ_UV_LDO7,
  456. .flags = IORESOURCE_IRQ,
  457. },
  458. };
  459. static struct resource wm831x_ldo8_resources[] = {
  460. {
  461. .start = WM831X_LDO8_CONTROL,
  462. .end = WM831X_LDO8_SLEEP_CONTROL,
  463. .flags = IORESOURCE_IO,
  464. },
  465. {
  466. .name = "UV",
  467. .start = WM831X_IRQ_UV_LDO8,
  468. .end = WM831X_IRQ_UV_LDO8,
  469. .flags = IORESOURCE_IRQ,
  470. },
  471. };
  472. static struct resource wm831x_ldo9_resources[] = {
  473. {
  474. .start = WM831X_LDO9_CONTROL,
  475. .end = WM831X_LDO9_SLEEP_CONTROL,
  476. .flags = IORESOURCE_IO,
  477. },
  478. {
  479. .name = "UV",
  480. .start = WM831X_IRQ_UV_LDO9,
  481. .end = WM831X_IRQ_UV_LDO9,
  482. .flags = IORESOURCE_IRQ,
  483. },
  484. };
  485. static struct resource wm831x_ldo10_resources[] = {
  486. {
  487. .start = WM831X_LDO10_CONTROL,
  488. .end = WM831X_LDO10_SLEEP_CONTROL,
  489. .flags = IORESOURCE_IO,
  490. },
  491. {
  492. .name = "UV",
  493. .start = WM831X_IRQ_UV_LDO10,
  494. .end = WM831X_IRQ_UV_LDO10,
  495. .flags = IORESOURCE_IRQ,
  496. },
  497. };
  498. static struct resource wm831x_ldo11_resources[] = {
  499. {
  500. .start = WM831X_LDO11_ON_CONTROL,
  501. .end = WM831X_LDO11_SLEEP_CONTROL,
  502. .flags = IORESOURCE_IO,
  503. },
  504. };
  505. static struct resource wm831x_on_resources[] = {
  506. {
  507. .start = WM831X_IRQ_ON,
  508. .end = WM831X_IRQ_ON,
  509. .flags = IORESOURCE_IRQ,
  510. },
  511. };
  512. static struct resource wm831x_power_resources[] = {
  513. {
  514. .name = "SYSLO",
  515. .start = WM831X_IRQ_PPM_SYSLO,
  516. .end = WM831X_IRQ_PPM_SYSLO,
  517. .flags = IORESOURCE_IRQ,
  518. },
  519. {
  520. .name = "PWR SRC",
  521. .start = WM831X_IRQ_PPM_PWR_SRC,
  522. .end = WM831X_IRQ_PPM_PWR_SRC,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. {
  526. .name = "USB CURR",
  527. .start = WM831X_IRQ_PPM_USB_CURR,
  528. .end = WM831X_IRQ_PPM_USB_CURR,
  529. .flags = IORESOURCE_IRQ,
  530. },
  531. {
  532. .name = "BATT HOT",
  533. .start = WM831X_IRQ_CHG_BATT_HOT,
  534. .end = WM831X_IRQ_CHG_BATT_HOT,
  535. .flags = IORESOURCE_IRQ,
  536. },
  537. {
  538. .name = "BATT COLD",
  539. .start = WM831X_IRQ_CHG_BATT_COLD,
  540. .end = WM831X_IRQ_CHG_BATT_COLD,
  541. .flags = IORESOURCE_IRQ,
  542. },
  543. {
  544. .name = "BATT FAIL",
  545. .start = WM831X_IRQ_CHG_BATT_FAIL,
  546. .end = WM831X_IRQ_CHG_BATT_FAIL,
  547. .flags = IORESOURCE_IRQ,
  548. },
  549. {
  550. .name = "OV",
  551. .start = WM831X_IRQ_CHG_OV,
  552. .end = WM831X_IRQ_CHG_OV,
  553. .flags = IORESOURCE_IRQ,
  554. },
  555. {
  556. .name = "END",
  557. .start = WM831X_IRQ_CHG_END,
  558. .end = WM831X_IRQ_CHG_END,
  559. .flags = IORESOURCE_IRQ,
  560. },
  561. {
  562. .name = "TO",
  563. .start = WM831X_IRQ_CHG_TO,
  564. .end = WM831X_IRQ_CHG_TO,
  565. .flags = IORESOURCE_IRQ,
  566. },
  567. {
  568. .name = "MODE",
  569. .start = WM831X_IRQ_CHG_MODE,
  570. .end = WM831X_IRQ_CHG_MODE,
  571. .flags = IORESOURCE_IRQ,
  572. },
  573. {
  574. .name = "START",
  575. .start = WM831X_IRQ_CHG_START,
  576. .end = WM831X_IRQ_CHG_START,
  577. .flags = IORESOURCE_IRQ,
  578. },
  579. };
  580. static struct resource wm831x_rtc_resources[] = {
  581. {
  582. .name = "PER",
  583. .start = WM831X_IRQ_RTC_PER,
  584. .end = WM831X_IRQ_RTC_PER,
  585. .flags = IORESOURCE_IRQ,
  586. },
  587. {
  588. .name = "ALM",
  589. .start = WM831X_IRQ_RTC_ALM,
  590. .end = WM831X_IRQ_RTC_ALM,
  591. .flags = IORESOURCE_IRQ,
  592. },
  593. };
  594. static struct resource wm831x_status1_resources[] = {
  595. {
  596. .start = WM831X_STATUS_LED_1,
  597. .end = WM831X_STATUS_LED_1,
  598. .flags = IORESOURCE_IO,
  599. },
  600. };
  601. static struct resource wm831x_status2_resources[] = {
  602. {
  603. .start = WM831X_STATUS_LED_2,
  604. .end = WM831X_STATUS_LED_2,
  605. .flags = IORESOURCE_IO,
  606. },
  607. };
  608. static struct resource wm831x_touch_resources[] = {
  609. {
  610. .name = "TCHPD",
  611. .start = WM831X_IRQ_TCHPD,
  612. .end = WM831X_IRQ_TCHPD,
  613. .flags = IORESOURCE_IRQ,
  614. },
  615. {
  616. .name = "TCHDATA",
  617. .start = WM831X_IRQ_TCHDATA,
  618. .end = WM831X_IRQ_TCHDATA,
  619. .flags = IORESOURCE_IRQ,
  620. },
  621. };
  622. static struct resource wm831x_wdt_resources[] = {
  623. {
  624. .start = WM831X_IRQ_WDOG_TO,
  625. .end = WM831X_IRQ_WDOG_TO,
  626. .flags = IORESOURCE_IRQ,
  627. },
  628. };
  629. static struct mfd_cell wm8310_devs[] = {
  630. {
  631. .name = "wm831x-backup",
  632. },
  633. {
  634. .name = "wm831x-buckv",
  635. .id = 1,
  636. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  637. .resources = wm831x_dcdc1_resources,
  638. },
  639. {
  640. .name = "wm831x-buckv",
  641. .id = 2,
  642. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  643. .resources = wm831x_dcdc2_resources,
  644. },
  645. {
  646. .name = "wm831x-buckp",
  647. .id = 3,
  648. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  649. .resources = wm831x_dcdc3_resources,
  650. },
  651. {
  652. .name = "wm831x-boostp",
  653. .id = 4,
  654. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  655. .resources = wm831x_dcdc4_resources,
  656. },
  657. {
  658. .name = "wm831x-clk",
  659. },
  660. {
  661. .name = "wm831x-epe",
  662. .id = 1,
  663. },
  664. {
  665. .name = "wm831x-epe",
  666. .id = 2,
  667. },
  668. {
  669. .name = "wm831x-gpio",
  670. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  671. .resources = wm831x_gpio_resources,
  672. },
  673. {
  674. .name = "wm831x-hwmon",
  675. },
  676. {
  677. .name = "wm831x-isink",
  678. .id = 1,
  679. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  680. .resources = wm831x_isink1_resources,
  681. },
  682. {
  683. .name = "wm831x-isink",
  684. .id = 2,
  685. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  686. .resources = wm831x_isink2_resources,
  687. },
  688. {
  689. .name = "wm831x-ldo",
  690. .id = 1,
  691. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  692. .resources = wm831x_ldo1_resources,
  693. },
  694. {
  695. .name = "wm831x-ldo",
  696. .id = 2,
  697. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  698. .resources = wm831x_ldo2_resources,
  699. },
  700. {
  701. .name = "wm831x-ldo",
  702. .id = 3,
  703. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  704. .resources = wm831x_ldo3_resources,
  705. },
  706. {
  707. .name = "wm831x-ldo",
  708. .id = 4,
  709. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  710. .resources = wm831x_ldo4_resources,
  711. },
  712. {
  713. .name = "wm831x-ldo",
  714. .id = 5,
  715. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  716. .resources = wm831x_ldo5_resources,
  717. },
  718. {
  719. .name = "wm831x-ldo",
  720. .id = 6,
  721. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  722. .resources = wm831x_ldo6_resources,
  723. },
  724. {
  725. .name = "wm831x-aldo",
  726. .id = 7,
  727. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  728. .resources = wm831x_ldo7_resources,
  729. },
  730. {
  731. .name = "wm831x-aldo",
  732. .id = 8,
  733. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  734. .resources = wm831x_ldo8_resources,
  735. },
  736. {
  737. .name = "wm831x-aldo",
  738. .id = 9,
  739. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  740. .resources = wm831x_ldo9_resources,
  741. },
  742. {
  743. .name = "wm831x-aldo",
  744. .id = 10,
  745. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  746. .resources = wm831x_ldo10_resources,
  747. },
  748. {
  749. .name = "wm831x-alive-ldo",
  750. .id = 11,
  751. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  752. .resources = wm831x_ldo11_resources,
  753. },
  754. {
  755. .name = "wm831x-on",
  756. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  757. .resources = wm831x_on_resources,
  758. },
  759. {
  760. .name = "wm831x-power",
  761. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  762. .resources = wm831x_power_resources,
  763. },
  764. {
  765. .name = "wm831x-status",
  766. .id = 1,
  767. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  768. .resources = wm831x_status1_resources,
  769. },
  770. {
  771. .name = "wm831x-status",
  772. .id = 2,
  773. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  774. .resources = wm831x_status2_resources,
  775. },
  776. {
  777. .name = "wm831x-watchdog",
  778. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  779. .resources = wm831x_wdt_resources,
  780. },
  781. };
  782. static struct mfd_cell wm8311_devs[] = {
  783. {
  784. .name = "wm831x-backup",
  785. },
  786. {
  787. .name = "wm831x-buckv",
  788. .id = 1,
  789. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  790. .resources = wm831x_dcdc1_resources,
  791. },
  792. {
  793. .name = "wm831x-buckv",
  794. .id = 2,
  795. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  796. .resources = wm831x_dcdc2_resources,
  797. },
  798. {
  799. .name = "wm831x-buckp",
  800. .id = 3,
  801. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  802. .resources = wm831x_dcdc3_resources,
  803. },
  804. {
  805. .name = "wm831x-boostp",
  806. .id = 4,
  807. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  808. .resources = wm831x_dcdc4_resources,
  809. },
  810. {
  811. .name = "wm831x-clk",
  812. },
  813. {
  814. .name = "wm831x-epe",
  815. .id = 1,
  816. },
  817. {
  818. .name = "wm831x-epe",
  819. .id = 2,
  820. },
  821. {
  822. .name = "wm831x-gpio",
  823. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  824. .resources = wm831x_gpio_resources,
  825. },
  826. {
  827. .name = "wm831x-hwmon",
  828. },
  829. {
  830. .name = "wm831x-isink",
  831. .id = 1,
  832. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  833. .resources = wm831x_isink1_resources,
  834. },
  835. {
  836. .name = "wm831x-isink",
  837. .id = 2,
  838. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  839. .resources = wm831x_isink2_resources,
  840. },
  841. {
  842. .name = "wm831x-ldo",
  843. .id = 1,
  844. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  845. .resources = wm831x_ldo1_resources,
  846. },
  847. {
  848. .name = "wm831x-ldo",
  849. .id = 2,
  850. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  851. .resources = wm831x_ldo2_resources,
  852. },
  853. {
  854. .name = "wm831x-ldo",
  855. .id = 3,
  856. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  857. .resources = wm831x_ldo3_resources,
  858. },
  859. {
  860. .name = "wm831x-ldo",
  861. .id = 4,
  862. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  863. .resources = wm831x_ldo4_resources,
  864. },
  865. {
  866. .name = "wm831x-ldo",
  867. .id = 5,
  868. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  869. .resources = wm831x_ldo5_resources,
  870. },
  871. {
  872. .name = "wm831x-aldo",
  873. .id = 7,
  874. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  875. .resources = wm831x_ldo7_resources,
  876. },
  877. {
  878. .name = "wm831x-alive-ldo",
  879. .id = 11,
  880. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  881. .resources = wm831x_ldo11_resources,
  882. },
  883. {
  884. .name = "wm831x-on",
  885. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  886. .resources = wm831x_on_resources,
  887. },
  888. {
  889. .name = "wm831x-power",
  890. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  891. .resources = wm831x_power_resources,
  892. },
  893. {
  894. .name = "wm831x-status",
  895. .id = 1,
  896. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  897. .resources = wm831x_status1_resources,
  898. },
  899. {
  900. .name = "wm831x-status",
  901. .id = 2,
  902. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  903. .resources = wm831x_status2_resources,
  904. },
  905. {
  906. .name = "wm831x-watchdog",
  907. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  908. .resources = wm831x_wdt_resources,
  909. },
  910. };
  911. static struct mfd_cell wm8312_devs[] = {
  912. {
  913. .name = "wm831x-backup",
  914. },
  915. {
  916. .name = "wm831x-buckv",
  917. .id = 1,
  918. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  919. .resources = wm831x_dcdc1_resources,
  920. },
  921. {
  922. .name = "wm831x-buckv",
  923. .id = 2,
  924. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  925. .resources = wm831x_dcdc2_resources,
  926. },
  927. {
  928. .name = "wm831x-buckp",
  929. .id = 3,
  930. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  931. .resources = wm831x_dcdc3_resources,
  932. },
  933. {
  934. .name = "wm831x-boostp",
  935. .id = 4,
  936. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  937. .resources = wm831x_dcdc4_resources,
  938. },
  939. {
  940. .name = "wm831x-clk",
  941. },
  942. {
  943. .name = "wm831x-epe",
  944. .id = 1,
  945. },
  946. {
  947. .name = "wm831x-epe",
  948. .id = 2,
  949. },
  950. {
  951. .name = "wm831x-gpio",
  952. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  953. .resources = wm831x_gpio_resources,
  954. },
  955. {
  956. .name = "wm831x-hwmon",
  957. },
  958. {
  959. .name = "wm831x-isink",
  960. .id = 1,
  961. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  962. .resources = wm831x_isink1_resources,
  963. },
  964. {
  965. .name = "wm831x-isink",
  966. .id = 2,
  967. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  968. .resources = wm831x_isink2_resources,
  969. },
  970. {
  971. .name = "wm831x-ldo",
  972. .id = 1,
  973. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  974. .resources = wm831x_ldo1_resources,
  975. },
  976. {
  977. .name = "wm831x-ldo",
  978. .id = 2,
  979. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  980. .resources = wm831x_ldo2_resources,
  981. },
  982. {
  983. .name = "wm831x-ldo",
  984. .id = 3,
  985. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  986. .resources = wm831x_ldo3_resources,
  987. },
  988. {
  989. .name = "wm831x-ldo",
  990. .id = 4,
  991. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  992. .resources = wm831x_ldo4_resources,
  993. },
  994. {
  995. .name = "wm831x-ldo",
  996. .id = 5,
  997. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  998. .resources = wm831x_ldo5_resources,
  999. },
  1000. {
  1001. .name = "wm831x-ldo",
  1002. .id = 6,
  1003. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1004. .resources = wm831x_ldo6_resources,
  1005. },
  1006. {
  1007. .name = "wm831x-aldo",
  1008. .id = 7,
  1009. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1010. .resources = wm831x_ldo7_resources,
  1011. },
  1012. {
  1013. .name = "wm831x-aldo",
  1014. .id = 8,
  1015. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1016. .resources = wm831x_ldo8_resources,
  1017. },
  1018. {
  1019. .name = "wm831x-aldo",
  1020. .id = 9,
  1021. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1022. .resources = wm831x_ldo9_resources,
  1023. },
  1024. {
  1025. .name = "wm831x-aldo",
  1026. .id = 10,
  1027. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1028. .resources = wm831x_ldo10_resources,
  1029. },
  1030. {
  1031. .name = "wm831x-alive-ldo",
  1032. .id = 11,
  1033. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1034. .resources = wm831x_ldo11_resources,
  1035. },
  1036. {
  1037. .name = "wm831x-on",
  1038. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1039. .resources = wm831x_on_resources,
  1040. },
  1041. {
  1042. .name = "wm831x-power",
  1043. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1044. .resources = wm831x_power_resources,
  1045. },
  1046. {
  1047. .name = "wm831x-status",
  1048. .id = 1,
  1049. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1050. .resources = wm831x_status1_resources,
  1051. },
  1052. {
  1053. .name = "wm831x-status",
  1054. .id = 2,
  1055. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1056. .resources = wm831x_status2_resources,
  1057. },
  1058. {
  1059. .name = "wm831x-watchdog",
  1060. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1061. .resources = wm831x_wdt_resources,
  1062. },
  1063. };
  1064. static struct mfd_cell wm8320_devs[] = {
  1065. {
  1066. .name = "wm831x-backup",
  1067. },
  1068. {
  1069. .name = "wm831x-buckv",
  1070. .id = 1,
  1071. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1072. .resources = wm831x_dcdc1_resources,
  1073. },
  1074. {
  1075. .name = "wm831x-buckv",
  1076. .id = 2,
  1077. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1078. .resources = wm831x_dcdc2_resources,
  1079. },
  1080. {
  1081. .name = "wm831x-buckp",
  1082. .id = 3,
  1083. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1084. .resources = wm831x_dcdc3_resources,
  1085. },
  1086. {
  1087. .name = "wm831x-buckp",
  1088. .id = 4,
  1089. .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
  1090. .resources = wm8320_dcdc4_buck_resources,
  1091. },
  1092. {
  1093. .name = "wm831x-clk",
  1094. },
  1095. {
  1096. .name = "wm831x-gpio",
  1097. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1098. .resources = wm831x_gpio_resources,
  1099. },
  1100. {
  1101. .name = "wm831x-hwmon",
  1102. },
  1103. {
  1104. .name = "wm831x-ldo",
  1105. .id = 1,
  1106. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1107. .resources = wm831x_ldo1_resources,
  1108. },
  1109. {
  1110. .name = "wm831x-ldo",
  1111. .id = 2,
  1112. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1113. .resources = wm831x_ldo2_resources,
  1114. },
  1115. {
  1116. .name = "wm831x-ldo",
  1117. .id = 3,
  1118. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1119. .resources = wm831x_ldo3_resources,
  1120. },
  1121. {
  1122. .name = "wm831x-ldo",
  1123. .id = 4,
  1124. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1125. .resources = wm831x_ldo4_resources,
  1126. },
  1127. {
  1128. .name = "wm831x-ldo",
  1129. .id = 5,
  1130. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1131. .resources = wm831x_ldo5_resources,
  1132. },
  1133. {
  1134. .name = "wm831x-ldo",
  1135. .id = 6,
  1136. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1137. .resources = wm831x_ldo6_resources,
  1138. },
  1139. {
  1140. .name = "wm831x-aldo",
  1141. .id = 7,
  1142. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1143. .resources = wm831x_ldo7_resources,
  1144. },
  1145. {
  1146. .name = "wm831x-aldo",
  1147. .id = 8,
  1148. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1149. .resources = wm831x_ldo8_resources,
  1150. },
  1151. {
  1152. .name = "wm831x-aldo",
  1153. .id = 9,
  1154. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1155. .resources = wm831x_ldo9_resources,
  1156. },
  1157. {
  1158. .name = "wm831x-aldo",
  1159. .id = 10,
  1160. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1161. .resources = wm831x_ldo10_resources,
  1162. },
  1163. {
  1164. .name = "wm831x-alive-ldo",
  1165. .id = 11,
  1166. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1167. .resources = wm831x_ldo11_resources,
  1168. },
  1169. {
  1170. .name = "wm831x-on",
  1171. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1172. .resources = wm831x_on_resources,
  1173. },
  1174. {
  1175. .name = "wm831x-status",
  1176. .id = 1,
  1177. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1178. .resources = wm831x_status1_resources,
  1179. },
  1180. {
  1181. .name = "wm831x-status",
  1182. .id = 2,
  1183. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1184. .resources = wm831x_status2_resources,
  1185. },
  1186. {
  1187. .name = "wm831x-watchdog",
  1188. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1189. .resources = wm831x_wdt_resources,
  1190. },
  1191. };
  1192. static struct mfd_cell touch_devs[] = {
  1193. {
  1194. .name = "wm831x-touch",
  1195. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1196. .resources = wm831x_touch_resources,
  1197. },
  1198. };
  1199. static struct mfd_cell rtc_devs[] = {
  1200. {
  1201. .name = "wm831x-rtc",
  1202. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1203. .resources = wm831x_rtc_resources,
  1204. },
  1205. };
  1206. static struct mfd_cell backlight_devs[] = {
  1207. {
  1208. .name = "wm831x-backlight",
  1209. },
  1210. };
  1211. /*
  1212. * Instantiate the generic non-control parts of the device.
  1213. */
  1214. int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
  1215. {
  1216. struct wm831x_pdata *pdata = wm831x->dev->platform_data;
  1217. int rev, wm831x_num;
  1218. enum wm831x_parent parent;
  1219. int ret, i;
  1220. mutex_init(&wm831x->io_lock);
  1221. mutex_init(&wm831x->key_lock);
  1222. dev_set_drvdata(wm831x->dev, wm831x);
  1223. ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
  1224. if (ret < 0) {
  1225. dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
  1226. goto err;
  1227. }
  1228. switch (ret) {
  1229. case 0x6204:
  1230. case 0x6246:
  1231. break;
  1232. default:
  1233. dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
  1234. ret = -EINVAL;
  1235. goto err;
  1236. }
  1237. ret = wm831x_reg_read(wm831x, WM831X_REVISION);
  1238. if (ret < 0) {
  1239. dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
  1240. goto err;
  1241. }
  1242. rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
  1243. ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
  1244. if (ret < 0) {
  1245. dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
  1246. goto err;
  1247. }
  1248. /* Some engineering samples do not have the ID set, rely on
  1249. * the device being registered correctly.
  1250. */
  1251. if (ret == 0) {
  1252. dev_info(wm831x->dev, "Device is an engineering sample\n");
  1253. ret = id;
  1254. }
  1255. switch (ret) {
  1256. case WM8310:
  1257. parent = WM8310;
  1258. wm831x->num_gpio = 16;
  1259. wm831x->charger_irq_wake = 1;
  1260. if (rev > 0) {
  1261. wm831x->has_gpio_ena = 1;
  1262. wm831x->has_cs_sts = 1;
  1263. }
  1264. dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
  1265. break;
  1266. case WM8311:
  1267. parent = WM8311;
  1268. wm831x->num_gpio = 16;
  1269. wm831x->charger_irq_wake = 1;
  1270. if (rev > 0) {
  1271. wm831x->has_gpio_ena = 1;
  1272. wm831x->has_cs_sts = 1;
  1273. }
  1274. dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
  1275. break;
  1276. case WM8312:
  1277. parent = WM8312;
  1278. wm831x->num_gpio = 16;
  1279. wm831x->charger_irq_wake = 1;
  1280. if (rev > 0) {
  1281. wm831x->has_gpio_ena = 1;
  1282. wm831x->has_cs_sts = 1;
  1283. }
  1284. dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
  1285. break;
  1286. case WM8320:
  1287. parent = WM8320;
  1288. wm831x->num_gpio = 12;
  1289. dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
  1290. break;
  1291. case WM8321:
  1292. parent = WM8321;
  1293. wm831x->num_gpio = 12;
  1294. dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
  1295. break;
  1296. case WM8325:
  1297. parent = WM8325;
  1298. wm831x->num_gpio = 12;
  1299. dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
  1300. break;
  1301. case WM8326:
  1302. parent = WM8326;
  1303. wm831x->num_gpio = 12;
  1304. dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
  1305. break;
  1306. default:
  1307. dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
  1308. ret = -EINVAL;
  1309. goto err;
  1310. }
  1311. /* This will need revisiting in future but is OK for all
  1312. * current parts.
  1313. */
  1314. if (parent != id)
  1315. dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
  1316. id);
  1317. /* Bootstrap the user key */
  1318. ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
  1319. if (ret < 0) {
  1320. dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
  1321. goto err;
  1322. }
  1323. if (ret != 0) {
  1324. dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
  1325. ret);
  1326. wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  1327. }
  1328. wm831x->locked = 1;
  1329. if (pdata && pdata->pre_init) {
  1330. ret = pdata->pre_init(wm831x);
  1331. if (ret != 0) {
  1332. dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
  1333. goto err;
  1334. }
  1335. }
  1336. if (pdata) {
  1337. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  1338. if (!pdata->gpio_defaults[i])
  1339. continue;
  1340. wm831x_reg_write(wm831x,
  1341. WM831X_GPIO1_CONTROL + i,
  1342. pdata->gpio_defaults[i] & 0xffff);
  1343. }
  1344. }
  1345. /* Multiply by 10 as we have many subdevices of the same type */
  1346. if (pdata && pdata->wm831x_num)
  1347. wm831x_num = pdata->wm831x_num * 10;
  1348. else
  1349. wm831x_num = -1;
  1350. ret = wm831x_irq_init(wm831x, irq);
  1351. if (ret != 0)
  1352. goto err;
  1353. wm831x_auxadc_init(wm831x);
  1354. /* The core device is up, instantiate the subdevices. */
  1355. switch (parent) {
  1356. case WM8310:
  1357. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1358. wm8310_devs, ARRAY_SIZE(wm8310_devs),
  1359. NULL, wm831x->irq_base);
  1360. break;
  1361. case WM8311:
  1362. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1363. wm8311_devs, ARRAY_SIZE(wm8311_devs),
  1364. NULL, wm831x->irq_base);
  1365. if (!pdata || !pdata->disable_touch)
  1366. mfd_add_devices(wm831x->dev, wm831x_num,
  1367. touch_devs, ARRAY_SIZE(touch_devs),
  1368. NULL, wm831x->irq_base);
  1369. break;
  1370. case WM8312:
  1371. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1372. wm8312_devs, ARRAY_SIZE(wm8312_devs),
  1373. NULL, wm831x->irq_base);
  1374. if (!pdata || !pdata->disable_touch)
  1375. mfd_add_devices(wm831x->dev, wm831x_num,
  1376. touch_devs, ARRAY_SIZE(touch_devs),
  1377. NULL, wm831x->irq_base);
  1378. break;
  1379. case WM8320:
  1380. case WM8321:
  1381. case WM8325:
  1382. case WM8326:
  1383. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1384. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1385. NULL, wm831x->irq_base);
  1386. break;
  1387. default:
  1388. /* If this happens the bus probe function is buggy */
  1389. BUG();
  1390. }
  1391. if (ret != 0) {
  1392. dev_err(wm831x->dev, "Failed to add children\n");
  1393. goto err_irq;
  1394. }
  1395. /* The RTC can only be used if the 32.768kHz crystal is
  1396. * enabled; this can't be controlled by software at runtime.
  1397. */
  1398. ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
  1399. if (ret < 0) {
  1400. dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret);
  1401. goto err_irq;
  1402. }
  1403. if (ret & WM831X_XTAL_ENA) {
  1404. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1405. rtc_devs, ARRAY_SIZE(rtc_devs),
  1406. NULL, wm831x->irq_base);
  1407. if (ret != 0) {
  1408. dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
  1409. goto err_irq;
  1410. }
  1411. } else {
  1412. dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n");
  1413. }
  1414. if (pdata && pdata->backlight) {
  1415. /* Treat errors as non-critical */
  1416. ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
  1417. ARRAY_SIZE(backlight_devs), NULL,
  1418. wm831x->irq_base);
  1419. if (ret < 0)
  1420. dev_err(wm831x->dev, "Failed to add backlight: %d\n",
  1421. ret);
  1422. }
  1423. wm831x_otp_init(wm831x);
  1424. if (pdata && pdata->post_init) {
  1425. ret = pdata->post_init(wm831x);
  1426. if (ret != 0) {
  1427. dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
  1428. goto err_irq;
  1429. }
  1430. }
  1431. return 0;
  1432. err_irq:
  1433. wm831x_irq_exit(wm831x);
  1434. err:
  1435. mfd_remove_devices(wm831x->dev);
  1436. kfree(wm831x);
  1437. return ret;
  1438. }
  1439. void wm831x_device_exit(struct wm831x *wm831x)
  1440. {
  1441. wm831x_otp_exit(wm831x);
  1442. mfd_remove_devices(wm831x->dev);
  1443. if (wm831x->irq_base)
  1444. free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
  1445. wm831x_irq_exit(wm831x);
  1446. kfree(wm831x);
  1447. }
  1448. int wm831x_device_suspend(struct wm831x *wm831x)
  1449. {
  1450. int reg, mask;
  1451. /* If the charger IRQs are a wake source then make sure we ack
  1452. * them even if they're not actively being used (eg, no power
  1453. * driver or no IRQ line wired up) then acknowledge the
  1454. * interrupts otherwise suspend won't last very long.
  1455. */
  1456. if (wm831x->charger_irq_wake) {
  1457. reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
  1458. mask = WM831X_CHG_BATT_HOT_EINT |
  1459. WM831X_CHG_BATT_COLD_EINT |
  1460. WM831X_CHG_BATT_FAIL_EINT |
  1461. WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
  1462. WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
  1463. WM831X_CHG_START_EINT;
  1464. /* If any of the interrupts are masked read the statuses */
  1465. if (reg & mask)
  1466. reg = wm831x_reg_read(wm831x,
  1467. WM831X_INTERRUPT_STATUS_2);
  1468. if (reg & mask) {
  1469. dev_info(wm831x->dev,
  1470. "Acknowledging masked charger IRQs: %x\n",
  1471. reg & mask);
  1472. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
  1473. reg & mask);
  1474. }
  1475. }
  1476. return 0;
  1477. }
  1478. MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
  1479. MODULE_LICENSE("GPL");
  1480. MODULE_AUTHOR("Mark Brown");