wm831x-core.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714
  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-rtc",
  882. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  883. .resources = wm831x_rtc_resources,
  884. },
  885. {
  886. .name = "wm831x-status",
  887. .id = 1,
  888. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  889. .resources = wm831x_status1_resources,
  890. },
  891. {
  892. .name = "wm831x-status",
  893. .id = 2,
  894. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  895. .resources = wm831x_status2_resources,
  896. },
  897. {
  898. .name = "wm831x-watchdog",
  899. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  900. .resources = wm831x_wdt_resources,
  901. },
  902. };
  903. static struct mfd_cell wm8311_devs[] = {
  904. {
  905. .name = "wm831x-backup",
  906. },
  907. {
  908. .name = "wm831x-buckv",
  909. .id = 1,
  910. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  911. .resources = wm831x_dcdc1_resources,
  912. },
  913. {
  914. .name = "wm831x-buckv",
  915. .id = 2,
  916. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  917. .resources = wm831x_dcdc2_resources,
  918. },
  919. {
  920. .name = "wm831x-buckp",
  921. .id = 3,
  922. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  923. .resources = wm831x_dcdc3_resources,
  924. },
  925. {
  926. .name = "wm831x-boostp",
  927. .id = 4,
  928. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  929. .resources = wm831x_dcdc4_resources,
  930. },
  931. {
  932. .name = "wm831x-epe",
  933. .id = 1,
  934. },
  935. {
  936. .name = "wm831x-epe",
  937. .id = 2,
  938. },
  939. {
  940. .name = "wm831x-gpio",
  941. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  942. .resources = wm831x_gpio_resources,
  943. },
  944. {
  945. .name = "wm831x-hwmon",
  946. },
  947. {
  948. .name = "wm831x-isink",
  949. .id = 1,
  950. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  951. .resources = wm831x_isink1_resources,
  952. },
  953. {
  954. .name = "wm831x-isink",
  955. .id = 2,
  956. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  957. .resources = wm831x_isink2_resources,
  958. },
  959. {
  960. .name = "wm831x-ldo",
  961. .id = 1,
  962. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  963. .resources = wm831x_ldo1_resources,
  964. },
  965. {
  966. .name = "wm831x-ldo",
  967. .id = 2,
  968. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  969. .resources = wm831x_ldo2_resources,
  970. },
  971. {
  972. .name = "wm831x-ldo",
  973. .id = 3,
  974. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  975. .resources = wm831x_ldo3_resources,
  976. },
  977. {
  978. .name = "wm831x-ldo",
  979. .id = 4,
  980. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  981. .resources = wm831x_ldo4_resources,
  982. },
  983. {
  984. .name = "wm831x-ldo",
  985. .id = 5,
  986. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  987. .resources = wm831x_ldo5_resources,
  988. },
  989. {
  990. .name = "wm831x-aldo",
  991. .id = 7,
  992. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  993. .resources = wm831x_ldo7_resources,
  994. },
  995. {
  996. .name = "wm831x-alive-ldo",
  997. .id = 11,
  998. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  999. .resources = wm831x_ldo11_resources,
  1000. },
  1001. {
  1002. .name = "wm831x-on",
  1003. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1004. .resources = wm831x_on_resources,
  1005. },
  1006. {
  1007. .name = "wm831x-power",
  1008. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1009. .resources = wm831x_power_resources,
  1010. },
  1011. {
  1012. .name = "wm831x-rtc",
  1013. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1014. .resources = wm831x_rtc_resources,
  1015. },
  1016. {
  1017. .name = "wm831x-status",
  1018. .id = 1,
  1019. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1020. .resources = wm831x_status1_resources,
  1021. },
  1022. {
  1023. .name = "wm831x-status",
  1024. .id = 2,
  1025. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1026. .resources = wm831x_status2_resources,
  1027. },
  1028. {
  1029. .name = "wm831x-touch",
  1030. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1031. .resources = wm831x_touch_resources,
  1032. },
  1033. {
  1034. .name = "wm831x-watchdog",
  1035. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1036. .resources = wm831x_wdt_resources,
  1037. },
  1038. };
  1039. static struct mfd_cell wm8312_devs[] = {
  1040. {
  1041. .name = "wm831x-backup",
  1042. },
  1043. {
  1044. .name = "wm831x-buckv",
  1045. .id = 1,
  1046. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1047. .resources = wm831x_dcdc1_resources,
  1048. },
  1049. {
  1050. .name = "wm831x-buckv",
  1051. .id = 2,
  1052. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1053. .resources = wm831x_dcdc2_resources,
  1054. },
  1055. {
  1056. .name = "wm831x-buckp",
  1057. .id = 3,
  1058. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1059. .resources = wm831x_dcdc3_resources,
  1060. },
  1061. {
  1062. .name = "wm831x-boostp",
  1063. .id = 4,
  1064. .num_resources = ARRAY_SIZE(wm831x_dcdc4_resources),
  1065. .resources = wm831x_dcdc4_resources,
  1066. },
  1067. {
  1068. .name = "wm831x-epe",
  1069. .id = 1,
  1070. },
  1071. {
  1072. .name = "wm831x-epe",
  1073. .id = 2,
  1074. },
  1075. {
  1076. .name = "wm831x-gpio",
  1077. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1078. .resources = wm831x_gpio_resources,
  1079. },
  1080. {
  1081. .name = "wm831x-hwmon",
  1082. },
  1083. {
  1084. .name = "wm831x-isink",
  1085. .id = 1,
  1086. .num_resources = ARRAY_SIZE(wm831x_isink1_resources),
  1087. .resources = wm831x_isink1_resources,
  1088. },
  1089. {
  1090. .name = "wm831x-isink",
  1091. .id = 2,
  1092. .num_resources = ARRAY_SIZE(wm831x_isink2_resources),
  1093. .resources = wm831x_isink2_resources,
  1094. },
  1095. {
  1096. .name = "wm831x-ldo",
  1097. .id = 1,
  1098. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1099. .resources = wm831x_ldo1_resources,
  1100. },
  1101. {
  1102. .name = "wm831x-ldo",
  1103. .id = 2,
  1104. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1105. .resources = wm831x_ldo2_resources,
  1106. },
  1107. {
  1108. .name = "wm831x-ldo",
  1109. .id = 3,
  1110. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1111. .resources = wm831x_ldo3_resources,
  1112. },
  1113. {
  1114. .name = "wm831x-ldo",
  1115. .id = 4,
  1116. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1117. .resources = wm831x_ldo4_resources,
  1118. },
  1119. {
  1120. .name = "wm831x-ldo",
  1121. .id = 5,
  1122. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1123. .resources = wm831x_ldo5_resources,
  1124. },
  1125. {
  1126. .name = "wm831x-ldo",
  1127. .id = 6,
  1128. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1129. .resources = wm831x_ldo6_resources,
  1130. },
  1131. {
  1132. .name = "wm831x-aldo",
  1133. .id = 7,
  1134. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1135. .resources = wm831x_ldo7_resources,
  1136. },
  1137. {
  1138. .name = "wm831x-aldo",
  1139. .id = 8,
  1140. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1141. .resources = wm831x_ldo8_resources,
  1142. },
  1143. {
  1144. .name = "wm831x-aldo",
  1145. .id = 9,
  1146. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1147. .resources = wm831x_ldo9_resources,
  1148. },
  1149. {
  1150. .name = "wm831x-aldo",
  1151. .id = 10,
  1152. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1153. .resources = wm831x_ldo10_resources,
  1154. },
  1155. {
  1156. .name = "wm831x-alive-ldo",
  1157. .id = 11,
  1158. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1159. .resources = wm831x_ldo11_resources,
  1160. },
  1161. {
  1162. .name = "wm831x-on",
  1163. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1164. .resources = wm831x_on_resources,
  1165. },
  1166. {
  1167. .name = "wm831x-power",
  1168. .num_resources = ARRAY_SIZE(wm831x_power_resources),
  1169. .resources = wm831x_power_resources,
  1170. },
  1171. {
  1172. .name = "wm831x-rtc",
  1173. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1174. .resources = wm831x_rtc_resources,
  1175. },
  1176. {
  1177. .name = "wm831x-status",
  1178. .id = 1,
  1179. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1180. .resources = wm831x_status1_resources,
  1181. },
  1182. {
  1183. .name = "wm831x-status",
  1184. .id = 2,
  1185. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1186. .resources = wm831x_status2_resources,
  1187. },
  1188. {
  1189. .name = "wm831x-touch",
  1190. .num_resources = ARRAY_SIZE(wm831x_touch_resources),
  1191. .resources = wm831x_touch_resources,
  1192. },
  1193. {
  1194. .name = "wm831x-watchdog",
  1195. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1196. .resources = wm831x_wdt_resources,
  1197. },
  1198. };
  1199. static struct mfd_cell wm8320_devs[] = {
  1200. {
  1201. .name = "wm831x-backup",
  1202. },
  1203. {
  1204. .name = "wm831x-buckv",
  1205. .id = 1,
  1206. .num_resources = ARRAY_SIZE(wm831x_dcdc1_resources),
  1207. .resources = wm831x_dcdc1_resources,
  1208. },
  1209. {
  1210. .name = "wm831x-buckv",
  1211. .id = 2,
  1212. .num_resources = ARRAY_SIZE(wm831x_dcdc2_resources),
  1213. .resources = wm831x_dcdc2_resources,
  1214. },
  1215. {
  1216. .name = "wm831x-buckp",
  1217. .id = 3,
  1218. .num_resources = ARRAY_SIZE(wm831x_dcdc3_resources),
  1219. .resources = wm831x_dcdc3_resources,
  1220. },
  1221. {
  1222. .name = "wm831x-buckp",
  1223. .id = 4,
  1224. .num_resources = ARRAY_SIZE(wm8320_dcdc4_buck_resources),
  1225. .resources = wm8320_dcdc4_buck_resources,
  1226. },
  1227. {
  1228. .name = "wm831x-gpio",
  1229. .num_resources = ARRAY_SIZE(wm831x_gpio_resources),
  1230. .resources = wm831x_gpio_resources,
  1231. },
  1232. {
  1233. .name = "wm831x-hwmon",
  1234. },
  1235. {
  1236. .name = "wm831x-ldo",
  1237. .id = 1,
  1238. .num_resources = ARRAY_SIZE(wm831x_ldo1_resources),
  1239. .resources = wm831x_ldo1_resources,
  1240. },
  1241. {
  1242. .name = "wm831x-ldo",
  1243. .id = 2,
  1244. .num_resources = ARRAY_SIZE(wm831x_ldo2_resources),
  1245. .resources = wm831x_ldo2_resources,
  1246. },
  1247. {
  1248. .name = "wm831x-ldo",
  1249. .id = 3,
  1250. .num_resources = ARRAY_SIZE(wm831x_ldo3_resources),
  1251. .resources = wm831x_ldo3_resources,
  1252. },
  1253. {
  1254. .name = "wm831x-ldo",
  1255. .id = 4,
  1256. .num_resources = ARRAY_SIZE(wm831x_ldo4_resources),
  1257. .resources = wm831x_ldo4_resources,
  1258. },
  1259. {
  1260. .name = "wm831x-ldo",
  1261. .id = 5,
  1262. .num_resources = ARRAY_SIZE(wm831x_ldo5_resources),
  1263. .resources = wm831x_ldo5_resources,
  1264. },
  1265. {
  1266. .name = "wm831x-ldo",
  1267. .id = 6,
  1268. .num_resources = ARRAY_SIZE(wm831x_ldo6_resources),
  1269. .resources = wm831x_ldo6_resources,
  1270. },
  1271. {
  1272. .name = "wm831x-aldo",
  1273. .id = 7,
  1274. .num_resources = ARRAY_SIZE(wm831x_ldo7_resources),
  1275. .resources = wm831x_ldo7_resources,
  1276. },
  1277. {
  1278. .name = "wm831x-aldo",
  1279. .id = 8,
  1280. .num_resources = ARRAY_SIZE(wm831x_ldo8_resources),
  1281. .resources = wm831x_ldo8_resources,
  1282. },
  1283. {
  1284. .name = "wm831x-aldo",
  1285. .id = 9,
  1286. .num_resources = ARRAY_SIZE(wm831x_ldo9_resources),
  1287. .resources = wm831x_ldo9_resources,
  1288. },
  1289. {
  1290. .name = "wm831x-aldo",
  1291. .id = 10,
  1292. .num_resources = ARRAY_SIZE(wm831x_ldo10_resources),
  1293. .resources = wm831x_ldo10_resources,
  1294. },
  1295. {
  1296. .name = "wm831x-alive-ldo",
  1297. .id = 11,
  1298. .num_resources = ARRAY_SIZE(wm831x_ldo11_resources),
  1299. .resources = wm831x_ldo11_resources,
  1300. },
  1301. {
  1302. .name = "wm831x-on",
  1303. .num_resources = ARRAY_SIZE(wm831x_on_resources),
  1304. .resources = wm831x_on_resources,
  1305. },
  1306. {
  1307. .name = "wm831x-rtc",
  1308. .num_resources = ARRAY_SIZE(wm831x_rtc_resources),
  1309. .resources = wm831x_rtc_resources,
  1310. },
  1311. {
  1312. .name = "wm831x-status",
  1313. .id = 1,
  1314. .num_resources = ARRAY_SIZE(wm831x_status1_resources),
  1315. .resources = wm831x_status1_resources,
  1316. },
  1317. {
  1318. .name = "wm831x-status",
  1319. .id = 2,
  1320. .num_resources = ARRAY_SIZE(wm831x_status2_resources),
  1321. .resources = wm831x_status2_resources,
  1322. },
  1323. {
  1324. .name = "wm831x-watchdog",
  1325. .num_resources = ARRAY_SIZE(wm831x_wdt_resources),
  1326. .resources = wm831x_wdt_resources,
  1327. },
  1328. };
  1329. static struct mfd_cell backlight_devs[] = {
  1330. {
  1331. .name = "wm831x-backlight",
  1332. },
  1333. };
  1334. /*
  1335. * Instantiate the generic non-control parts of the device.
  1336. */
  1337. int wm831x_device_init(struct wm831x *wm831x, unsigned long id, int irq)
  1338. {
  1339. struct wm831x_pdata *pdata = wm831x->dev->platform_data;
  1340. int rev;
  1341. enum wm831x_parent parent;
  1342. int ret;
  1343. mutex_init(&wm831x->io_lock);
  1344. mutex_init(&wm831x->key_lock);
  1345. mutex_init(&wm831x->auxadc_lock);
  1346. init_completion(&wm831x->auxadc_done);
  1347. dev_set_drvdata(wm831x->dev, wm831x);
  1348. ret = wm831x_reg_read(wm831x, WM831X_PARENT_ID);
  1349. if (ret < 0) {
  1350. dev_err(wm831x->dev, "Failed to read parent ID: %d\n", ret);
  1351. goto err;
  1352. }
  1353. if (ret != 0x6204) {
  1354. dev_err(wm831x->dev, "Device is not a WM831x: ID %x\n", ret);
  1355. ret = -EINVAL;
  1356. goto err;
  1357. }
  1358. ret = wm831x_reg_read(wm831x, WM831X_REVISION);
  1359. if (ret < 0) {
  1360. dev_err(wm831x->dev, "Failed to read revision: %d\n", ret);
  1361. goto err;
  1362. }
  1363. rev = (ret & WM831X_PARENT_REV_MASK) >> WM831X_PARENT_REV_SHIFT;
  1364. ret = wm831x_reg_read(wm831x, WM831X_RESET_ID);
  1365. if (ret < 0) {
  1366. dev_err(wm831x->dev, "Failed to read device ID: %d\n", ret);
  1367. goto err;
  1368. }
  1369. /* Some engineering samples do not have the ID set, rely on
  1370. * the device being registered correctly.
  1371. */
  1372. if (ret == 0) {
  1373. dev_info(wm831x->dev, "Device is an engineering sample\n");
  1374. ret = id;
  1375. }
  1376. switch (ret) {
  1377. case WM8310:
  1378. parent = WM8310;
  1379. wm831x->num_gpio = 16;
  1380. wm831x->charger_irq_wake = 1;
  1381. if (rev > 0) {
  1382. wm831x->has_gpio_ena = 1;
  1383. wm831x->has_cs_sts = 1;
  1384. }
  1385. dev_info(wm831x->dev, "WM8310 revision %c\n", 'A' + rev);
  1386. break;
  1387. case WM8311:
  1388. parent = WM8311;
  1389. wm831x->num_gpio = 16;
  1390. wm831x->charger_irq_wake = 1;
  1391. if (rev > 0) {
  1392. wm831x->has_gpio_ena = 1;
  1393. wm831x->has_cs_sts = 1;
  1394. }
  1395. dev_info(wm831x->dev, "WM8311 revision %c\n", 'A' + rev);
  1396. break;
  1397. case WM8312:
  1398. parent = WM8312;
  1399. wm831x->num_gpio = 16;
  1400. wm831x->charger_irq_wake = 1;
  1401. if (rev > 0) {
  1402. wm831x->has_gpio_ena = 1;
  1403. wm831x->has_cs_sts = 1;
  1404. }
  1405. dev_info(wm831x->dev, "WM8312 revision %c\n", 'A' + rev);
  1406. break;
  1407. case WM8320:
  1408. parent = WM8320;
  1409. wm831x->num_gpio = 12;
  1410. dev_info(wm831x->dev, "WM8320 revision %c\n", 'A' + rev);
  1411. break;
  1412. case WM8321:
  1413. parent = WM8321;
  1414. wm831x->num_gpio = 12;
  1415. dev_info(wm831x->dev, "WM8321 revision %c\n", 'A' + rev);
  1416. break;
  1417. case WM8325:
  1418. parent = WM8325;
  1419. wm831x->num_gpio = 12;
  1420. dev_info(wm831x->dev, "WM8325 revision %c\n", 'A' + rev);
  1421. break;
  1422. default:
  1423. dev_err(wm831x->dev, "Unknown WM831x device %04x\n", ret);
  1424. ret = -EINVAL;
  1425. goto err;
  1426. }
  1427. /* This will need revisiting in future but is OK for all
  1428. * current parts.
  1429. */
  1430. if (parent != id)
  1431. dev_warn(wm831x->dev, "Device was registered as a WM%lx\n",
  1432. id);
  1433. /* Bootstrap the user key */
  1434. ret = wm831x_reg_read(wm831x, WM831X_SECURITY_KEY);
  1435. if (ret < 0) {
  1436. dev_err(wm831x->dev, "Failed to read security key: %d\n", ret);
  1437. goto err;
  1438. }
  1439. if (ret != 0) {
  1440. dev_warn(wm831x->dev, "Security key had non-zero value %x\n",
  1441. ret);
  1442. wm831x_reg_write(wm831x, WM831X_SECURITY_KEY, 0);
  1443. }
  1444. wm831x->locked = 1;
  1445. if (pdata && pdata->pre_init) {
  1446. ret = pdata->pre_init(wm831x);
  1447. if (ret != 0) {
  1448. dev_err(wm831x->dev, "pre_init() failed: %d\n", ret);
  1449. goto err;
  1450. }
  1451. }
  1452. ret = wm831x_irq_init(wm831x, irq);
  1453. if (ret != 0)
  1454. goto err;
  1455. if (wm831x->irq_base) {
  1456. ret = request_threaded_irq(wm831x->irq_base +
  1457. WM831X_IRQ_AUXADC_DATA,
  1458. NULL, wm831x_auxadc_irq, 0,
  1459. "auxadc", wm831x);
  1460. if (ret < 0)
  1461. dev_err(wm831x->dev, "AUXADC IRQ request failed: %d\n",
  1462. ret);
  1463. }
  1464. /* The core device is up, instantiate the subdevices. */
  1465. switch (parent) {
  1466. case WM8310:
  1467. ret = mfd_add_devices(wm831x->dev, -1,
  1468. wm8310_devs, ARRAY_SIZE(wm8310_devs),
  1469. NULL, wm831x->irq_base);
  1470. break;
  1471. case WM8311:
  1472. ret = mfd_add_devices(wm831x->dev, -1,
  1473. wm8311_devs, ARRAY_SIZE(wm8311_devs),
  1474. NULL, wm831x->irq_base);
  1475. break;
  1476. case WM8312:
  1477. ret = mfd_add_devices(wm831x->dev, -1,
  1478. wm8312_devs, ARRAY_SIZE(wm8312_devs),
  1479. NULL, wm831x->irq_base);
  1480. break;
  1481. case WM8320:
  1482. ret = mfd_add_devices(wm831x->dev, -1,
  1483. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1484. NULL, 0);
  1485. break;
  1486. case WM8321:
  1487. ret = mfd_add_devices(wm831x->dev, -1,
  1488. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1489. NULL, 0);
  1490. break;
  1491. case WM8325:
  1492. ret = mfd_add_devices(wm831x->dev, -1,
  1493. wm8320_devs, ARRAY_SIZE(wm8320_devs),
  1494. NULL, 0);
  1495. break;
  1496. default:
  1497. /* If this happens the bus probe function is buggy */
  1498. BUG();
  1499. }
  1500. if (ret != 0) {
  1501. dev_err(wm831x->dev, "Failed to add children\n");
  1502. goto err_irq;
  1503. }
  1504. if (pdata && pdata->backlight) {
  1505. /* Treat errors as non-critical */
  1506. ret = mfd_add_devices(wm831x->dev, -1, backlight_devs,
  1507. ARRAY_SIZE(backlight_devs), NULL,
  1508. wm831x->irq_base);
  1509. if (ret < 0)
  1510. dev_err(wm831x->dev, "Failed to add backlight: %d\n",
  1511. ret);
  1512. }
  1513. wm831x_otp_init(wm831x);
  1514. if (pdata && pdata->post_init) {
  1515. ret = pdata->post_init(wm831x);
  1516. if (ret != 0) {
  1517. dev_err(wm831x->dev, "post_init() failed: %d\n", ret);
  1518. goto err_irq;
  1519. }
  1520. }
  1521. return 0;
  1522. err_irq:
  1523. wm831x_irq_exit(wm831x);
  1524. err:
  1525. mfd_remove_devices(wm831x->dev);
  1526. kfree(wm831x);
  1527. return ret;
  1528. }
  1529. void wm831x_device_exit(struct wm831x *wm831x)
  1530. {
  1531. wm831x_otp_exit(wm831x);
  1532. mfd_remove_devices(wm831x->dev);
  1533. if (wm831x->irq_base)
  1534. free_irq(wm831x->irq_base + WM831X_IRQ_AUXADC_DATA, wm831x);
  1535. wm831x_irq_exit(wm831x);
  1536. kfree(wm831x);
  1537. }
  1538. int wm831x_device_suspend(struct wm831x *wm831x)
  1539. {
  1540. int reg, mask;
  1541. /* If the charger IRQs are a wake source then make sure we ack
  1542. * them even if they're not actively being used (eg, no power
  1543. * driver or no IRQ line wired up) then acknowledge the
  1544. * interrupts otherwise suspend won't last very long.
  1545. */
  1546. if (wm831x->charger_irq_wake) {
  1547. reg = wm831x_reg_read(wm831x, WM831X_INTERRUPT_STATUS_2_MASK);
  1548. mask = WM831X_CHG_BATT_HOT_EINT |
  1549. WM831X_CHG_BATT_COLD_EINT |
  1550. WM831X_CHG_BATT_FAIL_EINT |
  1551. WM831X_CHG_OV_EINT | WM831X_CHG_END_EINT |
  1552. WM831X_CHG_TO_EINT | WM831X_CHG_MODE_EINT |
  1553. WM831X_CHG_START_EINT;
  1554. /* If any of the interrupts are masked read the statuses */
  1555. if (reg & mask)
  1556. reg = wm831x_reg_read(wm831x,
  1557. WM831X_INTERRUPT_STATUS_2);
  1558. if (reg & mask) {
  1559. dev_info(wm831x->dev,
  1560. "Acknowledging masked charger IRQs: %x\n",
  1561. reg & mask);
  1562. wm831x_reg_write(wm831x, WM831X_INTERRUPT_STATUS_2,
  1563. reg & mask);
  1564. }
  1565. }
  1566. return 0;
  1567. }
  1568. MODULE_DESCRIPTION("Core support for the WM831X AudioPlus PMIC");
  1569. MODULE_LICENSE("GPL");
  1570. MODULE_AUTHOR("Mark Brown");