wm831x-core.c 32 KB

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