wm831x-core.c 38 KB

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