wm831x-core.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747
  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;
  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. /**
  261. * wm831x_auxadc_read: Read a value from the WM831x AUXADC
  262. *
  263. * @wm831x: Device to read from.
  264. * @input: AUXADC input to read.
  265. */
  266. int wm831x_auxadc_read(struct wm831x *wm831x, enum wm831x_auxadc input)
  267. {
  268. int ret, src, irq_masked, timeout;
  269. /* Are we using the interrupt? */
  270. irq_masked = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_1_MASK);
  271. irq_masked &= WM831X_AUXADC_DATA_EINT;
  272. mutex_lock(&wm831x->auxadc_lock);
  273. ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
  274. WM831X_AUX_ENA, WM831X_AUX_ENA);
  275. if (ret < 0) {
  276. dev_err(wm831x->dev, "Failed to enable AUXADC: %d\n", ret);
  277. goto out;
  278. }
  279. /* We force a single source at present */
  280. src = input;
  281. ret = wm831x_reg_write(wm831x, WM831X_AUXADC_SOURCE,
  282. 1 << src);
  283. if (ret < 0) {
  284. dev_err(wm831x->dev, "Failed to set AUXADC source: %d\n", ret);
  285. goto out;
  286. }
  287. /* Clear any notification from a very late arriving interrupt */
  288. try_wait_for_completion(&wm831x->auxadc_done);
  289. ret = wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL,
  290. WM831X_AUX_CVT_ENA, WM831X_AUX_CVT_ENA);
  291. if (ret < 0) {
  292. dev_err(wm831x->dev, "Failed to start AUXADC: %d\n", ret);
  293. goto disable;
  294. }
  295. if (irq_masked) {
  296. /* If we're not using interrupts then poll the
  297. * interrupt status register */
  298. timeout = 5;
  299. while (timeout) {
  300. msleep(1);
  301. ret = wm831x_reg_read(wm831x,
  302. WM831X_INTERRUPT_STATUS_1);
  303. if (ret < 0) {
  304. dev_err(wm831x->dev,
  305. "ISR 1 read failed: %d\n", ret);
  306. goto disable;
  307. }
  308. /* Did it complete? */
  309. if (ret & WM831X_AUXADC_DATA_EINT) {
  310. wm831x_reg_write(wm831x,
  311. WM831X_INTERRUPT_STATUS_1,
  312. WM831X_AUXADC_DATA_EINT);
  313. break;
  314. } else {
  315. dev_err(wm831x->dev,
  316. "AUXADC conversion timeout\n");
  317. ret = -EBUSY;
  318. goto disable;
  319. }
  320. }
  321. } else {
  322. /* If we are using interrupts then wait for the
  323. * interrupt to complete. Use an extremely long
  324. * timeout to handle situations with heavy load where
  325. * the notification of the interrupt may be delayed by
  326. * threaded IRQ handling. */
  327. if (!wait_for_completion_timeout(&wm831x->auxadc_done,
  328. msecs_to_jiffies(500))) {
  329. dev_err(wm831x->dev, "Timed out waiting for AUXADC\n");
  330. ret = -EBUSY;
  331. goto disable;
  332. }
  333. }
  334. ret = wm831x_reg_read(wm831x, WM831X_AUXADC_DATA);
  335. if (ret < 0) {
  336. dev_err(wm831x->dev, "Failed to read AUXADC data: %d\n", ret);
  337. } else {
  338. src = ((ret & WM831X_AUX_DATA_SRC_MASK)
  339. >> WM831X_AUX_DATA_SRC_SHIFT) - 1;
  340. if (src == 14)
  341. src = WM831X_AUX_CAL;
  342. if (src != input) {
  343. dev_err(wm831x->dev, "Data from source %d not %d\n",
  344. src, input);
  345. ret = -EINVAL;
  346. } else {
  347. ret &= WM831X_AUX_DATA_MASK;
  348. }
  349. }
  350. disable:
  351. wm831x_set_bits(wm831x, WM831X_AUXADC_CONTROL, WM831X_AUX_ENA, 0);
  352. out:
  353. mutex_unlock(&wm831x->auxadc_lock);
  354. return ret;
  355. }
  356. EXPORT_SYMBOL_GPL(wm831x_auxadc_read);
  357. static irqreturn_t wm831x_auxadc_irq(int irq, void *irq_data)
  358. {
  359. struct wm831x *wm831x = irq_data;
  360. complete(&wm831x->auxadc_done);
  361. return IRQ_HANDLED;
  362. }
  363. /**
  364. * wm831x_auxadc_read_uv: Read a voltage from the WM831x AUXADC
  365. *
  366. * @wm831x: Device to read from.
  367. * @input: AUXADC input to read.
  368. */
  369. int wm831x_auxadc_read_uv(struct wm831x *wm831x, enum wm831x_auxadc input)
  370. {
  371. int ret;
  372. ret = wm831x_auxadc_read(wm831x, input);
  373. if (ret < 0)
  374. return ret;
  375. ret *= 1465;
  376. return ret;
  377. }
  378. EXPORT_SYMBOL_GPL(wm831x_auxadc_read_uv);
  379. static struct resource wm831x_dcdc1_resources[] = {
  380. {
  381. .start = WM831X_DC1_CONTROL_1,
  382. .end = WM831X_DC1_DVS_CONTROL,
  383. .flags = IORESOURCE_IO,
  384. },
  385. {
  386. .name = "UV",
  387. .start = WM831X_IRQ_UV_DC1,
  388. .end = WM831X_IRQ_UV_DC1,
  389. .flags = IORESOURCE_IRQ,
  390. },
  391. {
  392. .name = "HC",
  393. .start = WM831X_IRQ_HC_DC1,
  394. .end = WM831X_IRQ_HC_DC1,
  395. .flags = IORESOURCE_IRQ,
  396. },
  397. };
  398. static struct resource wm831x_dcdc2_resources[] = {
  399. {
  400. .start = WM831X_DC2_CONTROL_1,
  401. .end = WM831X_DC2_DVS_CONTROL,
  402. .flags = IORESOURCE_IO,
  403. },
  404. {
  405. .name = "UV",
  406. .start = WM831X_IRQ_UV_DC2,
  407. .end = WM831X_IRQ_UV_DC2,
  408. .flags = IORESOURCE_IRQ,
  409. },
  410. {
  411. .name = "HC",
  412. .start = WM831X_IRQ_HC_DC2,
  413. .end = WM831X_IRQ_HC_DC2,
  414. .flags = IORESOURCE_IRQ,
  415. },
  416. };
  417. static struct resource wm831x_dcdc3_resources[] = {
  418. {
  419. .start = WM831X_DC3_CONTROL_1,
  420. .end = WM831X_DC3_SLEEP_CONTROL,
  421. .flags = IORESOURCE_IO,
  422. },
  423. {
  424. .name = "UV",
  425. .start = WM831X_IRQ_UV_DC3,
  426. .end = WM831X_IRQ_UV_DC3,
  427. .flags = IORESOURCE_IRQ,
  428. },
  429. };
  430. static struct resource wm831x_dcdc4_resources[] = {
  431. {
  432. .start = WM831X_DC4_CONTROL,
  433. .end = WM831X_DC4_SLEEP_CONTROL,
  434. .flags = IORESOURCE_IO,
  435. },
  436. {
  437. .name = "UV",
  438. .start = WM831X_IRQ_UV_DC4,
  439. .end = WM831X_IRQ_UV_DC4,
  440. .flags = IORESOURCE_IRQ,
  441. },
  442. };
  443. static struct resource wm8320_dcdc4_buck_resources[] = {
  444. {
  445. .start = WM831X_DC4_CONTROL,
  446. .end = WM832X_DC4_SLEEP_CONTROL,
  447. .flags = IORESOURCE_IO,
  448. },
  449. {
  450. .name = "UV",
  451. .start = WM831X_IRQ_UV_DC4,
  452. .end = WM831X_IRQ_UV_DC4,
  453. .flags = IORESOURCE_IRQ,
  454. },
  455. };
  456. static struct resource wm831x_gpio_resources[] = {
  457. {
  458. .start = WM831X_IRQ_GPIO_1,
  459. .end = WM831X_IRQ_GPIO_16,
  460. .flags = IORESOURCE_IRQ,
  461. },
  462. };
  463. static struct resource wm831x_isink1_resources[] = {
  464. {
  465. .start = WM831X_CURRENT_SINK_1,
  466. .end = WM831X_CURRENT_SINK_1,
  467. .flags = IORESOURCE_IO,
  468. },
  469. {
  470. .start = WM831X_IRQ_CS1,
  471. .end = WM831X_IRQ_CS1,
  472. .flags = IORESOURCE_IRQ,
  473. },
  474. };
  475. static struct resource wm831x_isink2_resources[] = {
  476. {
  477. .start = WM831X_CURRENT_SINK_2,
  478. .end = WM831X_CURRENT_SINK_2,
  479. .flags = IORESOURCE_IO,
  480. },
  481. {
  482. .start = WM831X_IRQ_CS2,
  483. .end = WM831X_IRQ_CS2,
  484. .flags = IORESOURCE_IRQ,
  485. },
  486. };
  487. static struct resource wm831x_ldo1_resources[] = {
  488. {
  489. .start = WM831X_LDO1_CONTROL,
  490. .end = WM831X_LDO1_SLEEP_CONTROL,
  491. .flags = IORESOURCE_IO,
  492. },
  493. {
  494. .name = "UV",
  495. .start = WM831X_IRQ_UV_LDO1,
  496. .end = WM831X_IRQ_UV_LDO1,
  497. .flags = IORESOURCE_IRQ,
  498. },
  499. };
  500. static struct resource wm831x_ldo2_resources[] = {
  501. {
  502. .start = WM831X_LDO2_CONTROL,
  503. .end = WM831X_LDO2_SLEEP_CONTROL,
  504. .flags = IORESOURCE_IO,
  505. },
  506. {
  507. .name = "UV",
  508. .start = WM831X_IRQ_UV_LDO2,
  509. .end = WM831X_IRQ_UV_LDO2,
  510. .flags = IORESOURCE_IRQ,
  511. },
  512. };
  513. static struct resource wm831x_ldo3_resources[] = {
  514. {
  515. .start = WM831X_LDO3_CONTROL,
  516. .end = WM831X_LDO3_SLEEP_CONTROL,
  517. .flags = IORESOURCE_IO,
  518. },
  519. {
  520. .name = "UV",
  521. .start = WM831X_IRQ_UV_LDO3,
  522. .end = WM831X_IRQ_UV_LDO3,
  523. .flags = IORESOURCE_IRQ,
  524. },
  525. };
  526. static struct resource wm831x_ldo4_resources[] = {
  527. {
  528. .start = WM831X_LDO4_CONTROL,
  529. .end = WM831X_LDO4_SLEEP_CONTROL,
  530. .flags = IORESOURCE_IO,
  531. },
  532. {
  533. .name = "UV",
  534. .start = WM831X_IRQ_UV_LDO4,
  535. .end = WM831X_IRQ_UV_LDO4,
  536. .flags = IORESOURCE_IRQ,
  537. },
  538. };
  539. static struct resource wm831x_ldo5_resources[] = {
  540. {
  541. .start = WM831X_LDO5_CONTROL,
  542. .end = WM831X_LDO5_SLEEP_CONTROL,
  543. .flags = IORESOURCE_IO,
  544. },
  545. {
  546. .name = "UV",
  547. .start = WM831X_IRQ_UV_LDO5,
  548. .end = WM831X_IRQ_UV_LDO5,
  549. .flags = IORESOURCE_IRQ,
  550. },
  551. };
  552. static struct resource wm831x_ldo6_resources[] = {
  553. {
  554. .start = WM831X_LDO6_CONTROL,
  555. .end = WM831X_LDO6_SLEEP_CONTROL,
  556. .flags = IORESOURCE_IO,
  557. },
  558. {
  559. .name = "UV",
  560. .start = WM831X_IRQ_UV_LDO6,
  561. .end = WM831X_IRQ_UV_LDO6,
  562. .flags = IORESOURCE_IRQ,
  563. },
  564. };
  565. static struct resource wm831x_ldo7_resources[] = {
  566. {
  567. .start = WM831X_LDO7_CONTROL,
  568. .end = WM831X_LDO7_SLEEP_CONTROL,
  569. .flags = IORESOURCE_IO,
  570. },
  571. {
  572. .name = "UV",
  573. .start = WM831X_IRQ_UV_LDO7,
  574. .end = WM831X_IRQ_UV_LDO7,
  575. .flags = IORESOURCE_IRQ,
  576. },
  577. };
  578. static struct resource wm831x_ldo8_resources[] = {
  579. {
  580. .start = WM831X_LDO8_CONTROL,
  581. .end = WM831X_LDO8_SLEEP_CONTROL,
  582. .flags = IORESOURCE_IO,
  583. },
  584. {
  585. .name = "UV",
  586. .start = WM831X_IRQ_UV_LDO8,
  587. .end = WM831X_IRQ_UV_LDO8,
  588. .flags = IORESOURCE_IRQ,
  589. },
  590. };
  591. static struct resource wm831x_ldo9_resources[] = {
  592. {
  593. .start = WM831X_LDO9_CONTROL,
  594. .end = WM831X_LDO9_SLEEP_CONTROL,
  595. .flags = IORESOURCE_IO,
  596. },
  597. {
  598. .name = "UV",
  599. .start = WM831X_IRQ_UV_LDO9,
  600. .end = WM831X_IRQ_UV_LDO9,
  601. .flags = IORESOURCE_IRQ,
  602. },
  603. };
  604. static struct resource wm831x_ldo10_resources[] = {
  605. {
  606. .start = WM831X_LDO10_CONTROL,
  607. .end = WM831X_LDO10_SLEEP_CONTROL,
  608. .flags = IORESOURCE_IO,
  609. },
  610. {
  611. .name = "UV",
  612. .start = WM831X_IRQ_UV_LDO10,
  613. .end = WM831X_IRQ_UV_LDO10,
  614. .flags = IORESOURCE_IRQ,
  615. },
  616. };
  617. static struct resource wm831x_ldo11_resources[] = {
  618. {
  619. .start = WM831X_LDO11_ON_CONTROL,
  620. .end = WM831X_LDO11_SLEEP_CONTROL,
  621. .flags = IORESOURCE_IO,
  622. },
  623. };
  624. static struct resource wm831x_on_resources[] = {
  625. {
  626. .start = WM831X_IRQ_ON,
  627. .end = WM831X_IRQ_ON,
  628. .flags = IORESOURCE_IRQ,
  629. },
  630. };
  631. static struct resource wm831x_power_resources[] = {
  632. {
  633. .name = "SYSLO",
  634. .start = WM831X_IRQ_PPM_SYSLO,
  635. .end = WM831X_IRQ_PPM_SYSLO,
  636. .flags = IORESOURCE_IRQ,
  637. },
  638. {
  639. .name = "PWR SRC",
  640. .start = WM831X_IRQ_PPM_PWR_SRC,
  641. .end = WM831X_IRQ_PPM_PWR_SRC,
  642. .flags = IORESOURCE_IRQ,
  643. },
  644. {
  645. .name = "USB CURR",
  646. .start = WM831X_IRQ_PPM_USB_CURR,
  647. .end = WM831X_IRQ_PPM_USB_CURR,
  648. .flags = IORESOURCE_IRQ,
  649. },
  650. {
  651. .name = "BATT HOT",
  652. .start = WM831X_IRQ_CHG_BATT_HOT,
  653. .end = WM831X_IRQ_CHG_BATT_HOT,
  654. .flags = IORESOURCE_IRQ,
  655. },
  656. {
  657. .name = "BATT COLD",
  658. .start = WM831X_IRQ_CHG_BATT_COLD,
  659. .end = WM831X_IRQ_CHG_BATT_COLD,
  660. .flags = IORESOURCE_IRQ,
  661. },
  662. {
  663. .name = "BATT FAIL",
  664. .start = WM831X_IRQ_CHG_BATT_FAIL,
  665. .end = WM831X_IRQ_CHG_BATT_FAIL,
  666. .flags = IORESOURCE_IRQ,
  667. },
  668. {
  669. .name = "OV",
  670. .start = WM831X_IRQ_CHG_OV,
  671. .end = WM831X_IRQ_CHG_OV,
  672. .flags = IORESOURCE_IRQ,
  673. },
  674. {
  675. .name = "END",
  676. .start = WM831X_IRQ_CHG_END,
  677. .end = WM831X_IRQ_CHG_END,
  678. .flags = IORESOURCE_IRQ,
  679. },
  680. {
  681. .name = "TO",
  682. .start = WM831X_IRQ_CHG_TO,
  683. .end = WM831X_IRQ_CHG_TO,
  684. .flags = IORESOURCE_IRQ,
  685. },
  686. {
  687. .name = "MODE",
  688. .start = WM831X_IRQ_CHG_MODE,
  689. .end = WM831X_IRQ_CHG_MODE,
  690. .flags = IORESOURCE_IRQ,
  691. },
  692. {
  693. .name = "START",
  694. .start = WM831X_IRQ_CHG_START,
  695. .end = WM831X_IRQ_CHG_START,
  696. .flags = IORESOURCE_IRQ,
  697. },
  698. };
  699. static struct resource wm831x_rtc_resources[] = {
  700. {
  701. .name = "PER",
  702. .start = WM831X_IRQ_RTC_PER,
  703. .end = WM831X_IRQ_RTC_PER,
  704. .flags = IORESOURCE_IRQ,
  705. },
  706. {
  707. .name = "ALM",
  708. .start = WM831X_IRQ_RTC_ALM,
  709. .end = WM831X_IRQ_RTC_ALM,
  710. .flags = IORESOURCE_IRQ,
  711. },
  712. };
  713. static struct resource wm831x_status1_resources[] = {
  714. {
  715. .start = WM831X_STATUS_LED_1,
  716. .end = WM831X_STATUS_LED_1,
  717. .flags = IORESOURCE_IO,
  718. },
  719. };
  720. static struct resource wm831x_status2_resources[] = {
  721. {
  722. .start = WM831X_STATUS_LED_2,
  723. .end = WM831X_STATUS_LED_2,
  724. .flags = IORESOURCE_IO,
  725. },
  726. };
  727. static struct resource wm831x_touch_resources[] = {
  728. {
  729. .name = "TCHPD",
  730. .start = WM831X_IRQ_TCHPD,
  731. .end = WM831X_IRQ_TCHPD,
  732. .flags = IORESOURCE_IRQ,
  733. },
  734. {
  735. .name = "TCHDATA",
  736. .start = WM831X_IRQ_TCHDATA,
  737. .end = WM831X_IRQ_TCHDATA,
  738. .flags = IORESOURCE_IRQ,
  739. },
  740. };
  741. static struct resource wm831x_wdt_resources[] = {
  742. {
  743. .start = WM831X_IRQ_WDOG_TO,
  744. .end = WM831X_IRQ_WDOG_TO,
  745. .flags = IORESOURCE_IRQ,
  746. },
  747. };
  748. static struct mfd_cell wm8310_devs[] = {
  749. {
  750. .name = "wm831x-backup",
  751. },
  752. {
  753. .name = "wm831x-buckv",
  754. .id = 1,
  755. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  756. .resources = wm831x_dcdc1_resources,
  757. },
  758. {
  759. .name = "wm831x-buckv",
  760. .id = 2,
  761. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  762. .resources = wm831x_dcdc2_resources,
  763. },
  764. {
  765. .name = "wm831x-buckp",
  766. .id = 3,
  767. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  768. .resources = wm831x_dcdc3_resources,
  769. },
  770. {
  771. .name = "wm831x-boostp",
  772. .id = 4,
  773. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  774. .resources = wm831x_dcdc4_resources,
  775. },
  776. {
  777. .name = "wm831x-epe",
  778. .id = 1,
  779. },
  780. {
  781. .name = "wm831x-epe",
  782. .id = 2,
  783. },
  784. {
  785. .name = "wm831x-gpio",
  786. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  787. .resources = wm831x_gpio_resources,
  788. },
  789. {
  790. .name = "wm831x-hwmon",
  791. },
  792. {
  793. .name = "wm831x-isink",
  794. .id = 1,
  795. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  796. .resources = wm831x_isink1_resources,
  797. },
  798. {
  799. .name = "wm831x-isink",
  800. .id = 2,
  801. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  802. .resources = wm831x_isink2_resources,
  803. },
  804. {
  805. .name = "wm831x-ldo",
  806. .id = 1,
  807. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  808. .resources = wm831x_ldo1_resources,
  809. },
  810. {
  811. .name = "wm831x-ldo",
  812. .id = 2,
  813. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  814. .resources = wm831x_ldo2_resources,
  815. },
  816. {
  817. .name = "wm831x-ldo",
  818. .id = 3,
  819. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  820. .resources = wm831x_ldo3_resources,
  821. },
  822. {
  823. .name = "wm831x-ldo",
  824. .id = 4,
  825. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  826. .resources = wm831x_ldo4_resources,
  827. },
  828. {
  829. .name = "wm831x-ldo",
  830. .id = 5,
  831. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  832. .resources = wm831x_ldo5_resources,
  833. },
  834. {
  835. .name = "wm831x-ldo",
  836. .id = 6,
  837. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  838. .resources = wm831x_ldo6_resources,
  839. },
  840. {
  841. .name = "wm831x-aldo",
  842. .id = 7,
  843. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  844. .resources = wm831x_ldo7_resources,
  845. },
  846. {
  847. .name = "wm831x-aldo",
  848. .id = 8,
  849. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  850. .resources = wm831x_ldo8_resources,
  851. },
  852. {
  853. .name = "wm831x-aldo",
  854. .id = 9,
  855. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  856. .resources = wm831x_ldo9_resources,
  857. },
  858. {
  859. .name = "wm831x-aldo",
  860. .id = 10,
  861. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  862. .resources = wm831x_ldo10_resources,
  863. },
  864. {
  865. .name = "wm831x-alive-ldo",
  866. .id = 11,
  867. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  868. .resources = wm831x_ldo11_resources,
  869. },
  870. {
  871. .name = "wm831x-on",
  872. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  873. .resources = wm831x_on_resources,
  874. },
  875. {
  876. .name = "wm831x-power",
  877. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  878. .resources = wm831x_power_resources,
  879. },
  880. {
  881. .name = "wm831x-status",
  882. .id = 1,
  883. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  884. .resources = wm831x_status1_resources,
  885. },
  886. {
  887. .name = "wm831x-status",
  888. .id = 2,
  889. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  890. .resources = wm831x_status2_resources,
  891. },
  892. {
  893. .name = "wm831x-watchdog",
  894. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  895. .resources = wm831x_wdt_resources,
  896. },
  897. };
  898. static struct mfd_cell wm8311_devs[] = {
  899. {
  900. .name = "wm831x-backup",
  901. },
  902. {
  903. .name = "wm831x-buckv",
  904. .id = 1,
  905. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  906. .resources = wm831x_dcdc1_resources,
  907. },
  908. {
  909. .name = "wm831x-buckv",
  910. .id = 2,
  911. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  912. .resources = wm831x_dcdc2_resources,
  913. },
  914. {
  915. .name = "wm831x-buckp",
  916. .id = 3,
  917. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  918. .resources = wm831x_dcdc3_resources,
  919. },
  920. {
  921. .name = "wm831x-boostp",
  922. .id = 4,
  923. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  924. .resources = wm831x_dcdc4_resources,
  925. },
  926. {
  927. .name = "wm831x-epe",
  928. .id = 1,
  929. },
  930. {
  931. .name = "wm831x-epe",
  932. .id = 2,
  933. },
  934. {
  935. .name = "wm831x-gpio",
  936. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  937. .resources = wm831x_gpio_resources,
  938. },
  939. {
  940. .name = "wm831x-hwmon",
  941. },
  942. {
  943. .name = "wm831x-isink",
  944. .id = 1,
  945. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  946. .resources = wm831x_isink1_resources,
  947. },
  948. {
  949. .name = "wm831x-isink",
  950. .id = 2,
  951. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  952. .resources = wm831x_isink2_resources,
  953. },
  954. {
  955. .name = "wm831x-ldo",
  956. .id = 1,
  957. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  958. .resources = wm831x_ldo1_resources,
  959. },
  960. {
  961. .name = "wm831x-ldo",
  962. .id = 2,
  963. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  964. .resources = wm831x_ldo2_resources,
  965. },
  966. {
  967. .name = "wm831x-ldo",
  968. .id = 3,
  969. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  970. .resources = wm831x_ldo3_resources,
  971. },
  972. {
  973. .name = "wm831x-ldo",
  974. .id = 4,
  975. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  976. .resources = wm831x_ldo4_resources,
  977. },
  978. {
  979. .name = "wm831x-ldo",
  980. .id = 5,
  981. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  982. .resources = wm831x_ldo5_resources,
  983. },
  984. {
  985. .name = "wm831x-aldo",
  986. .id = 7,
  987. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  988. .resources = wm831x_ldo7_resources,
  989. },
  990. {
  991. .name = "wm831x-alive-ldo",
  992. .id = 11,
  993. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  994. .resources = wm831x_ldo11_resources,
  995. },
  996. {
  997. .name = "wm831x-on",
  998. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  999. .resources = wm831x_on_resources,
  1000. },
  1001. {
  1002. .name = "wm831x-power",
  1003. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1004. .resources = wm831x_power_resources,
  1005. },
  1006. {
  1007. .name = "wm831x-status",
  1008. .id = 1,
  1009. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1010. .resources = wm831x_status1_resources,
  1011. },
  1012. {
  1013. .name = "wm831x-status",
  1014. .id = 2,
  1015. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1016. .resources = wm831x_status2_resources,
  1017. },
  1018. {
  1019. .name = "wm831x-watchdog",
  1020. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1021. .resources = wm831x_wdt_resources,
  1022. },
  1023. };
  1024. static struct mfd_cell wm8312_devs[] = {
  1025. {
  1026. .name = "wm831x-backup",
  1027. },
  1028. {
  1029. .name = "wm831x-buckv",
  1030. .id = 1,
  1031. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1032. .resources = wm831x_dcdc1_resources,
  1033. },
  1034. {
  1035. .name = "wm831x-buckv",
  1036. .id = 2,
  1037. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1038. .resources = wm831x_dcdc2_resources,
  1039. },
  1040. {
  1041. .name = "wm831x-buckp",
  1042. .id = 3,
  1043. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1044. .resources = wm831x_dcdc3_resources,
  1045. },
  1046. {
  1047. .name = "wm831x-boostp",
  1048. .id = 4,
  1049. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1050. .resources = wm831x_dcdc4_resources,
  1051. },
  1052. {
  1053. .name = "wm831x-epe",
  1054. .id = 1,
  1055. },
  1056. {
  1057. .name = "wm831x-epe",
  1058. .id = 2,
  1059. },
  1060. {
  1061. .name = "wm831x-gpio",
  1062. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1063. .resources = wm831x_gpio_resources,
  1064. },
  1065. {
  1066. .name = "wm831x-hwmon",
  1067. },
  1068. {
  1069. .name = "wm831x-isink",
  1070. .id = 1,
  1071. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1072. .resources = wm831x_isink1_resources,
  1073. },
  1074. {
  1075. .name = "wm831x-isink",
  1076. .id = 2,
  1077. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1078. .resources = wm831x_isink2_resources,
  1079. },
  1080. {
  1081. .name = "wm831x-ldo",
  1082. .id = 1,
  1083. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1084. .resources = wm831x_ldo1_resources,
  1085. },
  1086. {
  1087. .name = "wm831x-ldo",
  1088. .id = 2,
  1089. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1090. .resources = wm831x_ldo2_resources,
  1091. },
  1092. {
  1093. .name = "wm831x-ldo",
  1094. .id = 3,
  1095. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1096. .resources = wm831x_ldo3_resources,
  1097. },
  1098. {
  1099. .name = "wm831x-ldo",
  1100. .id = 4,
  1101. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1102. .resources = wm831x_ldo4_resources,
  1103. },
  1104. {
  1105. .name = "wm831x-ldo",
  1106. .id = 5,
  1107. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1108. .resources = wm831x_ldo5_resources,
  1109. },
  1110. {
  1111. .name = "wm831x-ldo",
  1112. .id = 6,
  1113. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1114. .resources = wm831x_ldo6_resources,
  1115. },
  1116. {
  1117. .name = "wm831x-aldo",
  1118. .id = 7,
  1119. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1120. .resources = wm831x_ldo7_resources,
  1121. },
  1122. {
  1123. .name = "wm831x-aldo",
  1124. .id = 8,
  1125. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1126. .resources = wm831x_ldo8_resources,
  1127. },
  1128. {
  1129. .name = "wm831x-aldo",
  1130. .id = 9,
  1131. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1132. .resources = wm831x_ldo9_resources,
  1133. },
  1134. {
  1135. .name = "wm831x-aldo",
  1136. .id = 10,
  1137. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1138. .resources = wm831x_ldo10_resources,
  1139. },
  1140. {
  1141. .name = "wm831x-alive-ldo",
  1142. .id = 11,
  1143. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1144. .resources = wm831x_ldo11_resources,
  1145. },
  1146. {
  1147. .name = "wm831x-on",
  1148. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1149. .resources = wm831x_on_resources,
  1150. },
  1151. {
  1152. .name = "wm831x-power",
  1153. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1154. .resources = wm831x_power_resources,
  1155. },
  1156. {
  1157. .name = "wm831x-status",
  1158. .id = 1,
  1159. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1160. .resources = wm831x_status1_resources,
  1161. },
  1162. {
  1163. .name = "wm831x-status",
  1164. .id = 2,
  1165. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1166. .resources = wm831x_status2_resources,
  1167. },
  1168. {
  1169. .name = "wm831x-watchdog",
  1170. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1171. .resources = wm831x_wdt_resources,
  1172. },
  1173. };
  1174. static struct mfd_cell wm8320_devs[] = {
  1175. {
  1176. .name = "wm831x-backup",
  1177. },
  1178. {
  1179. .name = "wm831x-buckv",
  1180. .id = 1,
  1181. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1182. .resources = wm831x_dcdc1_resources,
  1183. },
  1184. {
  1185. .name = "wm831x-buckv",
  1186. .id = 2,
  1187. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1188. .resources = wm831x_dcdc2_resources,
  1189. },
  1190. {
  1191. .name = "wm831x-buckp",
  1192. .id = 3,
  1193. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1194. .resources = wm831x_dcdc3_resources,
  1195. },
  1196. {
  1197. .name = "wm831x-buckp",
  1198. .id = 4,
  1199. .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
  1200. .resources = wm8320_dcdc4_buck_resources,
  1201. },
  1202. {
  1203. .name = "wm831x-gpio",
  1204. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1205. .resources = wm831x_gpio_resources,
  1206. },
  1207. {
  1208. .name = "wm831x-hwmon",
  1209. },
  1210. {
  1211. .name = "wm831x-ldo",
  1212. .id = 1,
  1213. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1214. .resources = wm831x_ldo1_resources,
  1215. },
  1216. {
  1217. .name = "wm831x-ldo",
  1218. .id = 2,
  1219. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1220. .resources = wm831x_ldo2_resources,
  1221. },
  1222. {
  1223. .name = "wm831x-ldo",
  1224. .id = 3,
  1225. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1226. .resources = wm831x_ldo3_resources,
  1227. },
  1228. {
  1229. .name = "wm831x-ldo",
  1230. .id = 4,
  1231. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1232. .resources = wm831x_ldo4_resources,
  1233. },
  1234. {
  1235. .name = "wm831x-ldo",
  1236. .id = 5,
  1237. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1238. .resources = wm831x_ldo5_resources,
  1239. },
  1240. {
  1241. .name = "wm831x-ldo",
  1242. .id = 6,
  1243. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1244. .resources = wm831x_ldo6_resources,
  1245. },
  1246. {
  1247. .name = "wm831x-aldo",
  1248. .id = 7,
  1249. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1250. .resources = wm831x_ldo7_resources,
  1251. },
  1252. {
  1253. .name = "wm831x-aldo",
  1254. .id = 8,
  1255. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1256. .resources = wm831x_ldo8_resources,
  1257. },
  1258. {
  1259. .name = "wm831x-aldo",
  1260. .id = 9,
  1261. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1262. .resources = wm831x_ldo9_resources,
  1263. },
  1264. {
  1265. .name = "wm831x-aldo",
  1266. .id = 10,
  1267. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1268. .resources = wm831x_ldo10_resources,
  1269. },
  1270. {
  1271. .name = "wm831x-alive-ldo",
  1272. .id = 11,
  1273. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1274. .resources = wm831x_ldo11_resources,
  1275. },
  1276. {
  1277. .name = "wm831x-on",
  1278. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1279. .resources = wm831x_on_resources,
  1280. },
  1281. {
  1282. .name = "wm831x-status",
  1283. .id = 1,
  1284. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1285. .resources = wm831x_status1_resources,
  1286. },
  1287. {
  1288. .name = "wm831x-status",
  1289. .id = 2,
  1290. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1291. .resources = wm831x_status2_resources,
  1292. },
  1293. {
  1294. .name = "wm831x-watchdog",
  1295. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1296. .resources = wm831x_wdt_resources,
  1297. },
  1298. };
  1299. static struct mfd_cell touch_devs[] = {
  1300. {
  1301. .name = "wm831x-touch",
  1302. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1303. .resources = wm831x_touch_resources,
  1304. },
  1305. };
  1306. static struct mfd_cell rtc_devs[] = {
  1307. {
  1308. .name = "wm831x-rtc",
  1309. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1310. .resources = wm831x_rtc_resources,
  1311. },
  1312. };
  1313. static struct mfd_cell backlight_devs[] = {
  1314. {
  1315. .name = "wm831x-backlight",
  1316. },
  1317. };
  1318. /*
  1319. * Instantiate the generic non-control parts of the device.
  1320. */
  1321. int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
  1322. {
  1323. struct wm831x_pdata *pdata = wm831x->dev->platform_data;
  1324. int rev, wm831x_num;
  1325. enum wm831x_parent parent;
  1326. int ret, i;
  1327. mutex_init(&wm831x->io_lock);
  1328. mutex_init(&wm831x->key_lock);
  1329. mutex_init(&wm831x->auxadc_lock);
  1330. init_completion(&wm831x->auxadc_done);
  1331. dev_set_drvdata(wm831x->dev, wm831x);
  1332. ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
  1333. if (ret < 0) {
  1334. dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
  1335. goto err;
  1336. }
  1337. switch (ret) {
  1338. case 0x6204:
  1339. case 0x6246:
  1340. break;
  1341. default:
  1342. dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
  1343. ret = -EINVAL;
  1344. goto err;
  1345. }
  1346. ret = wm831x_reg_read(wm831x, WM831X_REVISION);
  1347. if (ret < 0) {
  1348. dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
  1349. goto err;
  1350. }
  1351. rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
  1352. ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
  1353. if (ret < 0) {
  1354. dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
  1355. goto err;
  1356. }
  1357. /* Some engineering samples do not have the ID set, rely on
  1358. * the device being registered correctly.
  1359. */
  1360. if (ret == 0) {
  1361. dev_info(wm831x->dev, "Device is an engineering sample\n");
  1362. ret = id;
  1363. }
  1364. switch (ret) {
  1365. case WM8310:
  1366. parent = WM8310;
  1367. wm831x->num_gpio = 16;
  1368. wm831x->charger_irq_wake = 1;
  1369. if (rev > 0) {
  1370. wm831x->has_gpio_ena = 1;
  1371. wm831x->has_cs_sts = 1;
  1372. }
  1373. dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
  1374. break;
  1375. case WM8311:
  1376. parent = WM8311;
  1377. wm831x->num_gpio = 16;
  1378. wm831x->charger_irq_wake = 1;
  1379. if (rev > 0) {
  1380. wm831x->has_gpio_ena = 1;
  1381. wm831x->has_cs_sts = 1;
  1382. }
  1383. dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
  1384. break;
  1385. case WM8312:
  1386. parent = WM8312;
  1387. wm831x->num_gpio = 16;
  1388. wm831x->charger_irq_wake = 1;
  1389. if (rev > 0) {
  1390. wm831x->has_gpio_ena = 1;
  1391. wm831x->has_cs_sts = 1;
  1392. }
  1393. dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
  1394. break;
  1395. case WM8320:
  1396. parent = WM8320;
  1397. wm831x->num_gpio = 12;
  1398. dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
  1399. break;
  1400. case WM8321:
  1401. parent = WM8321;
  1402. wm831x->num_gpio = 12;
  1403. dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
  1404. break;
  1405. case WM8325:
  1406. parent = WM8325;
  1407. wm831x->num_gpio = 12;
  1408. dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
  1409. break;
  1410. case WM8326:
  1411. parent = WM8326;
  1412. wm831x->num_gpio = 12;
  1413. dev_info(wm831x->dev, "WM8326 revision %c\n", 'A' + rev);
  1414. break;
  1415. default:
  1416. dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
  1417. ret = -EINVAL;
  1418. goto err;
  1419. }
  1420. /* This will need revisiting in future but is OK for all
  1421. * current parts.
  1422. */
  1423. if (parent != id)
  1424. dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
  1425. id);
  1426. /* Bootstrap the user key */
  1427. ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
  1428. if (ret < 0) {
  1429. dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
  1430. goto err;
  1431. }
  1432. if (ret != 0) {
  1433. dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
  1434. ret);
  1435. wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  1436. }
  1437. wm831x->locked = 1;
  1438. if (pdata && pdata->pre_init) {
  1439. ret = pdata->pre_init(wm831x);
  1440. if (ret != 0) {
  1441. dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
  1442. goto err;
  1443. }
  1444. }
  1445. if (pdata) {
  1446. for (i = 0; i < ARRAY_SIZE(pdata->gpio_defaults); i++) {
  1447. if (!pdata->gpio_defaults[i])
  1448. continue;
  1449. wm831x_reg_write(wm831x,
  1450. WM831X_GPIO1_CONTROL + i,
  1451. pdata->gpio_defaults[i] & 0xffff);
  1452. }
  1453. }
  1454. /* Multiply by 10 as we have many subdevices of the same type */
  1455. if (pdata && pdata->wm831x_num)
  1456. wm831x_num = pdata->wm831x_num * 10;
  1457. else
  1458. wm831x_num = -1;
  1459. ret = wm831x_irq_init(wm831x, irq);
  1460. if (ret != 0)
  1461. goto err;
  1462. if (wm831x->irq_base) {
  1463. ret = request_threaded_irq(wm831x->irq_base +
  1464. WM831X_IRQ_AUXADC_DATA,
  1465. NULL, wm831x_auxadc_irq, 0,
  1466. "auxadc", wm831x);
  1467. if (ret < 0)
  1468. dev_err(wm831x->dev, "AUXADC IRQ request failed: %d\n",
  1469. ret);
  1470. }
  1471. /* The core device is up, instantiate the subdevices. */
  1472. switch (parent) {
  1473. case WM8310:
  1474. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1475. wm8310_devs, ARRAY_SIZE(wm8310_devs),
  1476. NULL, wm831x->irq_base);
  1477. break;
  1478. case WM8311:
  1479. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1480. wm8311_devs, ARRAY_SIZE(wm8311_devs),
  1481. NULL, wm831x->irq_base);
  1482. if (!pdata || !pdata->disable_touch)
  1483. mfd_add_devices(wm831x->dev, wm831x_num,
  1484. touch_devs, ARRAY_SIZE(touch_devs),
  1485. NULL, wm831x->irq_base);
  1486. break;
  1487. case WM8312:
  1488. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1489. wm8312_devs, ARRAY_SIZE(wm8312_devs),
  1490. NULL, wm831x->irq_base);
  1491. if (!pdata || !pdata->disable_touch)
  1492. mfd_add_devices(wm831x->dev, wm831x_num,
  1493. touch_devs, ARRAY_SIZE(touch_devs),
  1494. NULL, wm831x->irq_base);
  1495. break;
  1496. case WM8320:
  1497. case WM8321:
  1498. case WM8325:
  1499. case WM8326:
  1500. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1501. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1502. NULL, wm831x->irq_base);
  1503. break;
  1504. default:
  1505. /* If this happens the bus probe function is buggy */
  1506. BUG();
  1507. }
  1508. if (ret != 0) {
  1509. dev_err(wm831x->dev, "Failed to add children\n");
  1510. goto err_irq;
  1511. }
  1512. /* The RTC can only be used if the 32.768kHz crystal is
  1513. * enabled; this can't be controlled by software at runtime.
  1514. */
  1515. ret = wm831x_reg_read(wm831x, WM831X_CLOCK_CONTROL_2);
  1516. if (ret < 0) {
  1517. dev_err(wm831x->dev, "Failed to read clock status: %d\n", ret);
  1518. goto err_irq;
  1519. }
  1520. if (ret & WM831X_XTAL_ENA) {
  1521. ret = mfd_add_devices(wm831x->dev, wm831x_num,
  1522. rtc_devs, ARRAY_SIZE(rtc_devs),
  1523. NULL, wm831x->irq_base);
  1524. if (ret != 0) {
  1525. dev_err(wm831x->dev, "Failed to add RTC: %d\n", ret);
  1526. goto err_irq;
  1527. }
  1528. } else {
  1529. dev_info(wm831x->dev, "32.768kHz clock disabled, no RTC\n");
  1530. }
  1531. if (pdata && pdata->backlight) {
  1532. /* Treat errors as non-critical */
  1533. ret = mfd_add_devices(wm831x->dev, wm831x_num, backlight_devs,
  1534. ARRAY_SIZE(backlight_devs), NULL,
  1535. wm831x->irq_base);
  1536. if (ret < 0)
  1537. dev_err(wm831x->dev, "Failed to add backlight: %d\n",
  1538. ret);
  1539. }
  1540. wm831x_otp_init(wm831x);
  1541. if (pdata && pdata->post_init) {
  1542. ret = pdata->post_init(wm831x);
  1543. if (ret != 0) {
  1544. dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
  1545. goto err_irq;
  1546. }
  1547. }
  1548. return 0;
  1549. err_irq:
  1550. wm831x_irq_exit(wm831x);
  1551. err:
  1552. mfd_remove_devices(wm831x->dev);
  1553. kfree(wm831x);
  1554. return ret;
  1555. }
  1556. void wm831x_device_exit(struct wm831x *wm831x)
  1557. {
  1558. wm831x_otp_exit(wm831x);
  1559. mfd_remove_devices(wm831x->dev);
  1560. if (wm831x->irq_base)
  1561. free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
  1562. wm831x_irq_exit(wm831x);
  1563. kfree(wm831x);
  1564. }
  1565. int wm831x_device_suspend(struct wm831x *wm831x)
  1566. {
  1567. int reg, mask;
  1568. /* If the charger IRQs are a wake source then make sure we ack
  1569. * them even if they're not actively being used (eg, no power
  1570. * driver or no IRQ line wired up) then acknowledge the
  1571. * interrupts otherwise suspend won't last very long.
  1572. */
  1573. if (wm831x->charger_irq_wake) {
  1574. reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
  1575. mask = WM831X_CHG_BATT_HOT_EINT |
  1576. WM831X_CHG_BATT_COLD_EINT |
  1577. WM831X_CHG_BATT_FAIL_EINT |
  1578. WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
  1579. WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
  1580. WM831X_CHG_START_EINT;
  1581. /* If any of the interrupts are masked read the statuses */
  1582. if (reg & mask)
  1583. reg = wm831x_reg_read(wm831x,
  1584. WM831X_INTERRUPT_STATUS_2);
  1585. if (reg & mask) {
  1586. dev_info(wm831x->dev,
  1587. "Acknowledging masked charger IRQs: %x\n",
  1588. reg & mask);
  1589. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
  1590. reg & mask);
  1591. }
  1592. }
  1593. return 0;
  1594. }
  1595. MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
  1596. MODULE_LICENSE("GPL");
  1597. MODULE_AUTHOR("Mark Brown");