wm831x-core.c 34 KB

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