wm831x-core.c 35 KB

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