wm831x-core.c 34 KB

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