wm8993.c 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614
  1. /*
  2. * wm8993.c -- WM8993 ALSA SoC audio driver
  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
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/module.h>
  13. #include <linux/moduleparam.h>
  14. #include <linux/init.h>
  15. #include <linux/delay.h>
  16. #include <linux/pm.h>
  17. #include <linux/i2c.h>
  18. #include <linux/spi/spi.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/tlv.h>
  23. #include <sound/soc.h>
  24. #include <sound/soc-dapm.h>
  25. #include <sound/initval.h>
  26. #include <sound/wm8993.h>
  27. #include "wm8993.h"
  28. #include "wm_hubs.h"
  29. static u16 wm8993_reg_defaults[WM8993_REGISTER_COUNT] = {
  30. 0x8993, /* R0 - Software Reset */
  31. 0x0000, /* R1 - Power Management (1) */
  32. 0x6000, /* R2 - Power Management (2) */
  33. 0x0000, /* R3 - Power Management (3) */
  34. 0x4050, /* R4 - Audio Interface (1) */
  35. 0x4000, /* R5 - Audio Interface (2) */
  36. 0x01C8, /* R6 - Clocking 1 */
  37. 0x0000, /* R7 - Clocking 2 */
  38. 0x0000, /* R8 - Audio Interface (3) */
  39. 0x0040, /* R9 - Audio Interface (4) */
  40. 0x0004, /* R10 - DAC CTRL */
  41. 0x00C0, /* R11 - Left DAC Digital Volume */
  42. 0x00C0, /* R12 - Right DAC Digital Volume */
  43. 0x0000, /* R13 - Digital Side Tone */
  44. 0x0300, /* R14 - ADC CTRL */
  45. 0x00C0, /* R15 - Left ADC Digital Volume */
  46. 0x00C0, /* R16 - Right ADC Digital Volume */
  47. 0x0000, /* R17 */
  48. 0x0000, /* R18 - GPIO CTRL 1 */
  49. 0x0010, /* R19 - GPIO1 */
  50. 0x0000, /* R20 - IRQ_DEBOUNCE */
  51. 0x0000, /* R21 */
  52. 0x8000, /* R22 - GPIOCTRL 2 */
  53. 0x0800, /* R23 - GPIO_POL */
  54. 0x008B, /* R24 - Left Line Input 1&2 Volume */
  55. 0x008B, /* R25 - Left Line Input 3&4 Volume */
  56. 0x008B, /* R26 - Right Line Input 1&2 Volume */
  57. 0x008B, /* R27 - Right Line Input 3&4 Volume */
  58. 0x006D, /* R28 - Left Output Volume */
  59. 0x006D, /* R29 - Right Output Volume */
  60. 0x0066, /* R30 - Line Outputs Volume */
  61. 0x0020, /* R31 - HPOUT2 Volume */
  62. 0x0079, /* R32 - Left OPGA Volume */
  63. 0x0079, /* R33 - Right OPGA Volume */
  64. 0x0003, /* R34 - SPKMIXL Attenuation */
  65. 0x0003, /* R35 - SPKMIXR Attenuation */
  66. 0x0011, /* R36 - SPKOUT Mixers */
  67. 0x0100, /* R37 - SPKOUT Boost */
  68. 0x0079, /* R38 - Speaker Volume Left */
  69. 0x0079, /* R39 - Speaker Volume Right */
  70. 0x0000, /* R40 - Input Mixer2 */
  71. 0x0000, /* R41 - Input Mixer3 */
  72. 0x0000, /* R42 - Input Mixer4 */
  73. 0x0000, /* R43 - Input Mixer5 */
  74. 0x0000, /* R44 - Input Mixer6 */
  75. 0x0000, /* R45 - Output Mixer1 */
  76. 0x0000, /* R46 - Output Mixer2 */
  77. 0x0000, /* R47 - Output Mixer3 */
  78. 0x0000, /* R48 - Output Mixer4 */
  79. 0x0000, /* R49 - Output Mixer5 */
  80. 0x0000, /* R50 - Output Mixer6 */
  81. 0x0000, /* R51 - HPOUT2 Mixer */
  82. 0x0000, /* R52 - Line Mixer1 */
  83. 0x0000, /* R53 - Line Mixer2 */
  84. 0x0000, /* R54 - Speaker Mixer */
  85. 0x0000, /* R55 - Additional Control */
  86. 0x0000, /* R56 - AntiPOP1 */
  87. 0x0000, /* R57 - AntiPOP2 */
  88. 0x0000, /* R58 - MICBIAS */
  89. 0x0000, /* R59 */
  90. 0x0000, /* R60 - FLL Control 1 */
  91. 0x0000, /* R61 - FLL Control 2 */
  92. 0x0000, /* R62 - FLL Control 3 */
  93. 0x2EE0, /* R63 - FLL Control 4 */
  94. 0x0002, /* R64 - FLL Control 5 */
  95. 0x2287, /* R65 - Clocking 3 */
  96. 0x025F, /* R66 - Clocking 4 */
  97. 0x0000, /* R67 - MW Slave Control */
  98. 0x0000, /* R68 */
  99. 0x0002, /* R69 - Bus Control 1 */
  100. 0x0000, /* R70 - Write Sequencer 0 */
  101. 0x0000, /* R71 - Write Sequencer 1 */
  102. 0x0000, /* R72 - Write Sequencer 2 */
  103. 0x0000, /* R73 - Write Sequencer 3 */
  104. 0x0000, /* R74 - Write Sequencer 4 */
  105. 0x0000, /* R75 - Write Sequencer 5 */
  106. 0x1F25, /* R76 - Charge Pump 1 */
  107. 0x0000, /* R77 */
  108. 0x0000, /* R78 */
  109. 0x0000, /* R79 */
  110. 0x0000, /* R80 */
  111. 0x0000, /* R81 - Class W 0 */
  112. 0x0000, /* R82 */
  113. 0x0000, /* R83 */
  114. 0x0000, /* R84 - DC Servo 0 */
  115. 0x054A, /* R85 - DC Servo 1 */
  116. 0x0000, /* R86 */
  117. 0x0000, /* R87 - DC Servo 3 */
  118. 0x0000, /* R88 - DC Servo Readback 0 */
  119. 0x0000, /* R89 - DC Servo Readback 1 */
  120. 0x0000, /* R90 - DC Servo Readback 2 */
  121. 0x0000, /* R91 */
  122. 0x0000, /* R92 */
  123. 0x0000, /* R93 */
  124. 0x0000, /* R94 */
  125. 0x0000, /* R95 */
  126. 0x0100, /* R96 - Analogue HP 0 */
  127. 0x0000, /* R97 */
  128. 0x0000, /* R98 - EQ1 */
  129. 0x000C, /* R99 - EQ2 */
  130. 0x000C, /* R100 - EQ3 */
  131. 0x000C, /* R101 - EQ4 */
  132. 0x000C, /* R102 - EQ5 */
  133. 0x000C, /* R103 - EQ6 */
  134. 0x0FCA, /* R104 - EQ7 */
  135. 0x0400, /* R105 - EQ8 */
  136. 0x00D8, /* R106 - EQ9 */
  137. 0x1EB5, /* R107 - EQ10 */
  138. 0xF145, /* R108 - EQ11 */
  139. 0x0B75, /* R109 - EQ12 */
  140. 0x01C5, /* R110 - EQ13 */
  141. 0x1C58, /* R111 - EQ14 */
  142. 0xF373, /* R112 - EQ15 */
  143. 0x0A54, /* R113 - EQ16 */
  144. 0x0558, /* R114 - EQ17 */
  145. 0x168E, /* R115 - EQ18 */
  146. 0xF829, /* R116 - EQ19 */
  147. 0x07AD, /* R117 - EQ20 */
  148. 0x1103, /* R118 - EQ21 */
  149. 0x0564, /* R119 - EQ22 */
  150. 0x0559, /* R120 - EQ23 */
  151. 0x4000, /* R121 - EQ24 */
  152. 0x0000, /* R122 - Digital Pulls */
  153. 0x0F08, /* R123 - DRC Control 1 */
  154. 0x0000, /* R124 - DRC Control 2 */
  155. 0x0080, /* R125 - DRC Control 3 */
  156. 0x0000, /* R126 - DRC Control 4 */
  157. };
  158. static struct {
  159. int ratio;
  160. int clk_sys_rate;
  161. } clk_sys_rates[] = {
  162. { 64, 0 },
  163. { 128, 1 },
  164. { 192, 2 },
  165. { 256, 3 },
  166. { 384, 4 },
  167. { 512, 5 },
  168. { 768, 6 },
  169. { 1024, 7 },
  170. { 1408, 8 },
  171. { 1536, 9 },
  172. };
  173. static struct {
  174. int rate;
  175. int sample_rate;
  176. } sample_rates[] = {
  177. { 8000, 0 },
  178. { 11025, 1 },
  179. { 12000, 1 },
  180. { 16000, 2 },
  181. { 22050, 3 },
  182. { 24000, 3 },
  183. { 32000, 4 },
  184. { 44100, 5 },
  185. { 48000, 5 },
  186. };
  187. static struct {
  188. int div; /* *10 due to .5s */
  189. int bclk_div;
  190. } bclk_divs[] = {
  191. { 10, 0 },
  192. { 15, 1 },
  193. { 20, 2 },
  194. { 30, 3 },
  195. { 40, 4 },
  196. { 55, 5 },
  197. { 60, 6 },
  198. { 80, 7 },
  199. { 110, 8 },
  200. { 120, 9 },
  201. { 160, 10 },
  202. { 220, 11 },
  203. { 240, 12 },
  204. { 320, 13 },
  205. { 440, 14 },
  206. { 480, 15 },
  207. };
  208. struct wm8993_priv {
  209. u16 reg_cache[WM8993_REGISTER_COUNT];
  210. struct wm8993_platform_data pdata;
  211. struct snd_soc_codec codec;
  212. int master;
  213. int sysclk_source;
  214. unsigned int mclk_rate;
  215. unsigned int sysclk_rate;
  216. unsigned int fs;
  217. unsigned int bclk;
  218. int class_w_users;
  219. unsigned int fll_fref;
  220. unsigned int fll_fout;
  221. };
  222. static unsigned int wm8993_read_hw(struct snd_soc_codec *codec, u8 reg)
  223. {
  224. struct i2c_msg xfer[2];
  225. u16 data;
  226. int ret;
  227. struct i2c_client *i2c = codec->control_data;
  228. /* Write register */
  229. xfer[0].addr = i2c->addr;
  230. xfer[0].flags = 0;
  231. xfer[0].len = 1;
  232. xfer[0].buf = &reg;
  233. /* Read data */
  234. xfer[1].addr = i2c->addr;
  235. xfer[1].flags = I2C_M_RD;
  236. xfer[1].len = 2;
  237. xfer[1].buf = (u8 *)&data;
  238. ret = i2c_transfer(i2c->adapter, xfer, 2);
  239. if (ret != 2) {
  240. dev_err(codec->dev, "Failed to read 0x%x: %d\n", reg, ret);
  241. return 0;
  242. }
  243. return (data >> 8) | ((data & 0xff) << 8);
  244. }
  245. static int wm8993_volatile(unsigned int reg)
  246. {
  247. switch (reg) {
  248. case WM8993_SOFTWARE_RESET:
  249. case WM8993_DC_SERVO_0:
  250. case WM8993_DC_SERVO_READBACK_0:
  251. case WM8993_DC_SERVO_READBACK_1:
  252. case WM8993_DC_SERVO_READBACK_2:
  253. return 1;
  254. default:
  255. return 0;
  256. }
  257. }
  258. static unsigned int wm8993_read(struct snd_soc_codec *codec,
  259. unsigned int reg)
  260. {
  261. u16 *reg_cache = codec->reg_cache;
  262. BUG_ON(reg > WM8993_MAX_REGISTER);
  263. if (wm8993_volatile(reg))
  264. return wm8993_read_hw(codec, reg);
  265. else
  266. return reg_cache[reg];
  267. }
  268. static int wm8993_write(struct snd_soc_codec *codec, unsigned int reg,
  269. unsigned int value)
  270. {
  271. u16 *reg_cache = codec->reg_cache;
  272. u8 data[3];
  273. int ret;
  274. BUG_ON(reg > WM8993_MAX_REGISTER);
  275. /* data is
  276. * D15..D9 WM8993 register offset
  277. * D8...D0 register data
  278. */
  279. data[0] = reg;
  280. data[1] = value >> 8;
  281. data[2] = value & 0x00ff;
  282. if (!wm8993_volatile(reg))
  283. reg_cache[reg] = value;
  284. ret = codec->hw_write(codec->control_data, data, 3);
  285. if (ret == 3)
  286. return 0;
  287. if (ret < 0)
  288. return ret;
  289. return -EIO;
  290. }
  291. struct _fll_div {
  292. u16 fll_fratio;
  293. u16 fll_outdiv;
  294. u16 fll_clk_ref_div;
  295. u16 n;
  296. u16 k;
  297. };
  298. /* The size in bits of the FLL divide multiplied by 10
  299. * to allow rounding later */
  300. #define FIXED_FLL_SIZE ((1 << 16) * 10)
  301. static struct {
  302. unsigned int min;
  303. unsigned int max;
  304. u16 fll_fratio;
  305. int ratio;
  306. } fll_fratios[] = {
  307. { 0, 64000, 4, 16 },
  308. { 64000, 128000, 3, 8 },
  309. { 128000, 256000, 2, 4 },
  310. { 256000, 1000000, 1, 2 },
  311. { 1000000, 13500000, 0, 1 },
  312. };
  313. static int fll_factors(struct _fll_div *fll_div, unsigned int Fref,
  314. unsigned int Fout)
  315. {
  316. u64 Kpart;
  317. unsigned int K, Ndiv, Nmod, target;
  318. unsigned int div;
  319. int i;
  320. /* Fref must be <=13.5MHz */
  321. div = 1;
  322. fll_div->fll_clk_ref_div = 0;
  323. while ((Fref / div) > 13500000) {
  324. div *= 2;
  325. fll_div->fll_clk_ref_div++;
  326. if (div > 8) {
  327. pr_err("Can't scale %dMHz input down to <=13.5MHz\n",
  328. Fref);
  329. return -EINVAL;
  330. }
  331. }
  332. pr_debug("Fref=%u Fout=%u\n", Fref, Fout);
  333. /* Apply the division for our remaining calculations */
  334. Fref /= div;
  335. /* Fvco should be 90-100MHz; don't check the upper bound */
  336. div = 0;
  337. target = Fout * 2;
  338. while (target < 90000000) {
  339. div++;
  340. target *= 2;
  341. if (div > 7) {
  342. pr_err("Unable to find FLL_OUTDIV for Fout=%uHz\n",
  343. Fout);
  344. return -EINVAL;
  345. }
  346. }
  347. fll_div->fll_outdiv = div;
  348. pr_debug("Fvco=%dHz\n", target);
  349. /* Find an appropraite FLL_FRATIO and factor it out of the target */
  350. for (i = 0; i < ARRAY_SIZE(fll_fratios); i++) {
  351. if (fll_fratios[i].min <= Fref && Fref <= fll_fratios[i].max) {
  352. fll_div->fll_fratio = fll_fratios[i].fll_fratio;
  353. target /= fll_fratios[i].ratio;
  354. break;
  355. }
  356. }
  357. if (i == ARRAY_SIZE(fll_fratios)) {
  358. pr_err("Unable to find FLL_FRATIO for Fref=%uHz\n", Fref);
  359. return -EINVAL;
  360. }
  361. /* Now, calculate N.K */
  362. Ndiv = target / Fref;
  363. fll_div->n = Ndiv;
  364. Nmod = target % Fref;
  365. pr_debug("Nmod=%d\n", Nmod);
  366. /* Calculate fractional part - scale up so we can round. */
  367. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  368. do_div(Kpart, Fref);
  369. K = Kpart & 0xFFFFFFFF;
  370. if ((K % 10) >= 5)
  371. K += 5;
  372. /* Move down to proper range now rounding is done */
  373. fll_div->k = K / 10;
  374. pr_debug("N=%x K=%x FLL_FRATIO=%x FLL_OUTDIV=%x FLL_CLK_REF_DIV=%x\n",
  375. fll_div->n, fll_div->k,
  376. fll_div->fll_fratio, fll_div->fll_outdiv,
  377. fll_div->fll_clk_ref_div);
  378. return 0;
  379. }
  380. static int wm8993_set_fll(struct snd_soc_dai *dai, int fll_id,
  381. unsigned int Fref, unsigned int Fout)
  382. {
  383. struct snd_soc_codec *codec = dai->codec;
  384. struct wm8993_priv *wm8993 = codec->private_data;
  385. u16 reg1, reg4, reg5;
  386. struct _fll_div fll_div;
  387. int ret;
  388. /* Any change? */
  389. if (Fref == wm8993->fll_fref && Fout == wm8993->fll_fout)
  390. return 0;
  391. /* Disable the FLL */
  392. if (Fout == 0) {
  393. dev_dbg(codec->dev, "FLL disabled\n");
  394. wm8993->fll_fref = 0;
  395. wm8993->fll_fout = 0;
  396. reg1 = wm8993_read(codec, WM8993_FLL_CONTROL_1);
  397. reg1 &= ~WM8993_FLL_ENA;
  398. wm8993_write(codec, WM8993_FLL_CONTROL_1, reg1);
  399. return 0;
  400. }
  401. ret = fll_factors(&fll_div, Fref, Fout);
  402. if (ret != 0)
  403. return ret;
  404. reg5 = wm8993_read(codec, WM8993_FLL_CONTROL_5);
  405. reg5 &= ~WM8993_FLL_CLK_SRC_MASK;
  406. switch (fll_id) {
  407. case WM8993_FLL_MCLK:
  408. break;
  409. case WM8993_FLL_LRCLK:
  410. reg5 |= 1;
  411. break;
  412. case WM8993_FLL_BCLK:
  413. reg5 |= 2;
  414. break;
  415. default:
  416. dev_err(codec->dev, "Unknown FLL ID %d\n", fll_id);
  417. return -EINVAL;
  418. }
  419. /* Any FLL configuration change requires that the FLL be
  420. * disabled first. */
  421. reg1 = wm8993_read(codec, WM8993_FLL_CONTROL_1);
  422. reg1 &= ~WM8993_FLL_ENA;
  423. wm8993_write(codec, WM8993_FLL_CONTROL_1, reg1);
  424. /* Apply the configuration */
  425. if (fll_div.k)
  426. reg1 |= WM8993_FLL_FRAC_MASK;
  427. else
  428. reg1 &= ~WM8993_FLL_FRAC_MASK;
  429. wm8993_write(codec, WM8993_FLL_CONTROL_1, reg1);
  430. wm8993_write(codec, WM8993_FLL_CONTROL_2,
  431. (fll_div.fll_outdiv << WM8993_FLL_OUTDIV_SHIFT) |
  432. (fll_div.fll_fratio << WM8993_FLL_FRATIO_SHIFT));
  433. wm8993_write(codec, WM8993_FLL_CONTROL_3, fll_div.k);
  434. reg4 = wm8993_read(codec, WM8993_FLL_CONTROL_4);
  435. reg4 &= ~WM8993_FLL_N_MASK;
  436. reg4 |= fll_div.n << WM8993_FLL_N_SHIFT;
  437. wm8993_write(codec, WM8993_FLL_CONTROL_4, reg4);
  438. reg5 &= ~WM8993_FLL_CLK_REF_DIV_MASK;
  439. reg5 |= fll_div.fll_clk_ref_div << WM8993_FLL_CLK_REF_DIV_SHIFT;
  440. wm8993_write(codec, WM8993_FLL_CONTROL_5, reg5);
  441. /* Enable the FLL */
  442. wm8993_write(codec, WM8993_FLL_CONTROL_1, reg1 | WM8993_FLL_ENA);
  443. dev_dbg(codec->dev, "FLL enabled at %dHz->%dHz\n", Fref, Fout);
  444. wm8993->fll_fref = Fref;
  445. wm8993->fll_fout = Fout;
  446. return 0;
  447. }
  448. static int configure_clock(struct snd_soc_codec *codec)
  449. {
  450. struct wm8993_priv *wm8993 = codec->private_data;
  451. unsigned int reg;
  452. /* This should be done on init() for bypass paths */
  453. switch (wm8993->sysclk_source) {
  454. case WM8993_SYSCLK_MCLK:
  455. dev_dbg(codec->dev, "Using %dHz MCLK\n", wm8993->mclk_rate);
  456. reg = wm8993_read(codec, WM8993_CLOCKING_2);
  457. reg &= ~WM8993_SYSCLK_SRC;
  458. if (wm8993->mclk_rate > 13500000) {
  459. reg |= WM8993_MCLK_DIV;
  460. wm8993->sysclk_rate = wm8993->mclk_rate / 2;
  461. } else {
  462. reg &= ~WM8993_MCLK_DIV;
  463. wm8993->sysclk_rate = wm8993->mclk_rate;
  464. }
  465. reg &= ~WM8993_MCLK_DIV;
  466. reg &= ~(WM8993_MCLK_DIV | WM8993_SYSCLK_SRC);
  467. wm8993_write(codec, WM8993_CLOCKING_2, reg);
  468. break;
  469. case WM8993_SYSCLK_FLL:
  470. dev_dbg(codec->dev, "Using %dHz FLL clock\n",
  471. wm8993->fll_fout);
  472. reg = wm8993_read(codec, WM8993_CLOCKING_2);
  473. reg |= WM8993_SYSCLK_SRC;
  474. if (wm8993->fll_fout > 13500000) {
  475. reg |= WM8993_MCLK_DIV;
  476. wm8993->sysclk_rate = wm8993->fll_fout / 2;
  477. } else {
  478. reg &= ~WM8993_MCLK_DIV;
  479. wm8993->sysclk_rate = wm8993->fll_fout;
  480. }
  481. wm8993_write(codec, WM8993_CLOCKING_2, reg);
  482. break;
  483. default:
  484. dev_err(codec->dev, "System clock not configured\n");
  485. return -EINVAL;
  486. }
  487. dev_dbg(codec->dev, "CLK_SYS is %dHz\n", wm8993->sysclk_rate);
  488. return 0;
  489. }
  490. static const DECLARE_TLV_DB_SCALE(sidetone_tlv, -3600, 300, 0);
  491. static const DECLARE_TLV_DB_SCALE(drc_comp_threash, -4500, 75, 0);
  492. static const DECLARE_TLV_DB_SCALE(drc_comp_amp, -2250, 75, 0);
  493. static const DECLARE_TLV_DB_SCALE(drc_min_tlv, -1800, 600, 0);
  494. static const unsigned int drc_max_tlv[] = {
  495. TLV_DB_RANGE_HEAD(4),
  496. 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0),
  497. 3, 3, TLV_DB_SCALE_ITEM(3600, 0, 0),
  498. };
  499. static const DECLARE_TLV_DB_SCALE(drc_qr_tlv, 1200, 600, 0);
  500. static const DECLARE_TLV_DB_SCALE(drc_startup_tlv, -1800, 300, 0);
  501. static const DECLARE_TLV_DB_SCALE(eq_tlv, -1200, 100, 0);
  502. static const DECLARE_TLV_DB_SCALE(digital_tlv, -7200, 75, 1);
  503. static const DECLARE_TLV_DB_SCALE(dac_boost_tlv, 0, 600, 0);
  504. static const char *dac_deemph_text[] = {
  505. "None",
  506. "32kHz",
  507. "44.1kHz",
  508. "48kHz",
  509. };
  510. static const struct soc_enum dac_deemph =
  511. SOC_ENUM_SINGLE(WM8993_DAC_CTRL, 4, 4, dac_deemph_text);
  512. static const char *adc_hpf_text[] = {
  513. "Hi-Fi",
  514. "Voice 1",
  515. "Voice 2",
  516. "Voice 3",
  517. };
  518. static const struct soc_enum adc_hpf =
  519. SOC_ENUM_SINGLE(WM8993_ADC_CTRL, 5, 4, adc_hpf_text);
  520. static const char *drc_path_text[] = {
  521. "ADC",
  522. "DAC"
  523. };
  524. static const struct soc_enum drc_path =
  525. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_1, 14, 2, drc_path_text);
  526. static const char *drc_r0_text[] = {
  527. "1",
  528. "1/2",
  529. "1/4",
  530. "1/8",
  531. "1/16",
  532. "0",
  533. };
  534. static const struct soc_enum drc_r0 =
  535. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 8, 6, drc_r0_text);
  536. static const char *drc_r1_text[] = {
  537. "1",
  538. "1/2",
  539. "1/4",
  540. "1/8",
  541. "0",
  542. };
  543. static const struct soc_enum drc_r1 =
  544. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_4, 13, 5, drc_r1_text);
  545. static const char *drc_attack_text[] = {
  546. "Reserved",
  547. "181us",
  548. "363us",
  549. "726us",
  550. "1.45ms",
  551. "2.9ms",
  552. "5.8ms",
  553. "11.6ms",
  554. "23.2ms",
  555. "46.4ms",
  556. "92.8ms",
  557. "185.6ms",
  558. };
  559. static const struct soc_enum drc_attack =
  560. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_2, 12, 12, drc_attack_text);
  561. static const char *drc_decay_text[] = {
  562. "186ms",
  563. "372ms",
  564. "743ms",
  565. "1.49s",
  566. "2.97ms",
  567. "5.94ms",
  568. "11.89ms",
  569. "23.78ms",
  570. "47.56ms",
  571. };
  572. static const struct soc_enum drc_decay =
  573. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_2, 8, 9, drc_decay_text);
  574. static const char *drc_ff_text[] = {
  575. "5 samples",
  576. "9 samples",
  577. };
  578. static const struct soc_enum drc_ff =
  579. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 7, 2, drc_ff_text);
  580. static const char *drc_qr_rate_text[] = {
  581. "0.725ms",
  582. "1.45ms",
  583. "5.8ms",
  584. };
  585. static const struct soc_enum drc_qr_rate =
  586. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_3, 0, 3, drc_qr_rate_text);
  587. static const char *drc_smooth_text[] = {
  588. "Low",
  589. "Medium",
  590. "High",
  591. };
  592. static const struct soc_enum drc_smooth =
  593. SOC_ENUM_SINGLE(WM8993_DRC_CONTROL_1, 4, 3, drc_smooth_text);
  594. static const struct snd_kcontrol_new wm8993_snd_controls[] = {
  595. SOC_DOUBLE_TLV("Digital Sidetone Volume", WM8993_DIGITAL_SIDE_TONE,
  596. 5, 9, 12, 0, sidetone_tlv),
  597. SOC_SINGLE("DRC Switch", WM8993_DRC_CONTROL_1, 15, 1, 0),
  598. SOC_ENUM("DRC Path", drc_path),
  599. SOC_SINGLE_TLV("DRC Compressor Threashold Volume", WM8993_DRC_CONTROL_2,
  600. 2, 60, 1, drc_comp_threash),
  601. SOC_SINGLE_TLV("DRC Compressor Amplitude Volume", WM8993_DRC_CONTROL_3,
  602. 11, 30, 1, drc_comp_amp),
  603. SOC_ENUM("DRC R0", drc_r0),
  604. SOC_ENUM("DRC R1", drc_r1),
  605. SOC_SINGLE_TLV("DRC Minimum Volume", WM8993_DRC_CONTROL_1, 2, 3, 1,
  606. drc_min_tlv),
  607. SOC_SINGLE_TLV("DRC Maximum Volume", WM8993_DRC_CONTROL_1, 0, 3, 0,
  608. drc_max_tlv),
  609. SOC_ENUM("DRC Attack Rate", drc_attack),
  610. SOC_ENUM("DRC Decay Rate", drc_decay),
  611. SOC_ENUM("DRC FF Delay", drc_ff),
  612. SOC_SINGLE("DRC Anti-clip Switch", WM8993_DRC_CONTROL_1, 9, 1, 0),
  613. SOC_SINGLE("DRC Quick Release Switch", WM8993_DRC_CONTROL_1, 10, 1, 0),
  614. SOC_SINGLE_TLV("DRC Quick Release Volume", WM8993_DRC_CONTROL_3, 2, 3, 0,
  615. drc_qr_tlv),
  616. SOC_ENUM("DRC Quick Release Rate", drc_qr_rate),
  617. SOC_SINGLE("DRC Smoothing Switch", WM8993_DRC_CONTROL_1, 11, 1, 0),
  618. SOC_SINGLE("DRC Smoothing Hysteresis Switch", WM8993_DRC_CONTROL_1, 8, 1, 0),
  619. SOC_ENUM("DRC Smoothing Hysteresis Threashold", drc_smooth),
  620. SOC_SINGLE_TLV("DRC Startup Volume", WM8993_DRC_CONTROL_4, 8, 18, 0,
  621. drc_startup_tlv),
  622. SOC_SINGLE("EQ Switch", WM8993_EQ1, 0, 1, 0),
  623. SOC_DOUBLE_R_TLV("Capture Volume", WM8993_LEFT_ADC_DIGITAL_VOLUME,
  624. WM8993_RIGHT_ADC_DIGITAL_VOLUME, 1, 96, 0, digital_tlv),
  625. SOC_SINGLE("ADC High Pass Filter Switch", WM8993_ADC_CTRL, 8, 1, 0),
  626. SOC_ENUM("ADC High Pass Filter Mode", adc_hpf),
  627. SOC_DOUBLE_R_TLV("Playback Volume", WM8993_LEFT_DAC_DIGITAL_VOLUME,
  628. WM8993_RIGHT_DAC_DIGITAL_VOLUME, 1, 96, 0, digital_tlv),
  629. SOC_SINGLE_TLV("Playback Boost Volume", WM8993_AUDIO_INTERFACE_2, 10, 3, 0,
  630. dac_boost_tlv),
  631. SOC_ENUM("DAC Deemphasis", dac_deemph),
  632. SOC_SINGLE_TLV("SPKL DAC Volume", WM8993_SPKMIXL_ATTENUATION,
  633. 2, 1, 1, wm_hubs_spkmix_tlv),
  634. SOC_SINGLE_TLV("SPKR DAC Volume", WM8993_SPKMIXR_ATTENUATION,
  635. 2, 1, 1, wm_hubs_spkmix_tlv),
  636. };
  637. static const struct snd_kcontrol_new wm8993_eq_controls[] = {
  638. SOC_SINGLE_TLV("EQ1 Volume", WM8993_EQ2, 0, 24, 0, eq_tlv),
  639. SOC_SINGLE_TLV("EQ2 Volume", WM8993_EQ3, 0, 24, 0, eq_tlv),
  640. SOC_SINGLE_TLV("EQ3 Volume", WM8993_EQ4, 0, 24, 0, eq_tlv),
  641. SOC_SINGLE_TLV("EQ4 Volume", WM8993_EQ5, 0, 24, 0, eq_tlv),
  642. SOC_SINGLE_TLV("EQ5 Volume", WM8993_EQ6, 0, 24, 0, eq_tlv),
  643. };
  644. static int clk_sys_event(struct snd_soc_dapm_widget *w,
  645. struct snd_kcontrol *kcontrol, int event)
  646. {
  647. struct snd_soc_codec *codec = w->codec;
  648. switch (event) {
  649. case SND_SOC_DAPM_PRE_PMU:
  650. return configure_clock(codec);
  651. case SND_SOC_DAPM_POST_PMD:
  652. break;
  653. }
  654. return 0;
  655. }
  656. /*
  657. * When used with DAC outputs only the WM8993 charge pump supports
  658. * operation in class W mode, providing very low power consumption
  659. * when used with digital sources. Enable and disable this mode
  660. * automatically depending on the mixer configuration.
  661. *
  662. * Currently the only supported paths are the direct DAC->headphone
  663. * paths (which provide minimum power consumption anyway).
  664. */
  665. static int class_w_put(struct snd_kcontrol *kcontrol,
  666. struct snd_ctl_elem_value *ucontrol)
  667. {
  668. struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
  669. struct snd_soc_codec *codec = widget->codec;
  670. struct wm8993_priv *wm8993 = codec->private_data;
  671. int ret;
  672. /* Turn it off if we're using the main output mixer */
  673. if (ucontrol->value.integer.value[0] == 0) {
  674. if (wm8993->class_w_users == 0) {
  675. dev_dbg(codec->dev, "Disabling Class W\n");
  676. snd_soc_update_bits(codec, WM8993_CLASS_W_0,
  677. WM8993_CP_DYN_FREQ |
  678. WM8993_CP_DYN_V,
  679. 0);
  680. }
  681. wm8993->class_w_users++;
  682. }
  683. /* Implement the change */
  684. ret = snd_soc_dapm_put_enum_double(kcontrol, ucontrol);
  685. /* Enable it if we're using the direct DAC path */
  686. if (ucontrol->value.integer.value[0] == 1) {
  687. if (wm8993->class_w_users == 1) {
  688. dev_dbg(codec->dev, "Enabling Class W\n");
  689. snd_soc_update_bits(codec, WM8993_CLASS_W_0,
  690. WM8993_CP_DYN_FREQ |
  691. WM8993_CP_DYN_V,
  692. WM8993_CP_DYN_FREQ |
  693. WM8993_CP_DYN_V);
  694. }
  695. wm8993->class_w_users--;
  696. }
  697. dev_dbg(codec->dev, "Indirect DAC use count now %d\n",
  698. wm8993->class_w_users);
  699. return ret;
  700. }
  701. #define SOC_DAPM_ENUM_W(xname, xenum) \
  702. { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
  703. .info = snd_soc_info_enum_double, \
  704. .get = snd_soc_dapm_get_enum_double, \
  705. .put = class_w_put, \
  706. .private_value = (unsigned long)&xenum }
  707. static const char *hp_mux_text[] = {
  708. "Mixer",
  709. "DAC",
  710. };
  711. static const struct soc_enum hpl_enum =
  712. SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER1, 8, 2, hp_mux_text);
  713. static const struct snd_kcontrol_new hpl_mux =
  714. SOC_DAPM_ENUM_W("Left Headphone Mux", hpl_enum);
  715. static const struct soc_enum hpr_enum =
  716. SOC_ENUM_SINGLE(WM8993_OUTPUT_MIXER2, 8, 2, hp_mux_text);
  717. static const struct snd_kcontrol_new hpr_mux =
  718. SOC_DAPM_ENUM_W("Right Headphone Mux", hpr_enum);
  719. static const struct snd_kcontrol_new left_speaker_mixer[] = {
  720. SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 7, 1, 0),
  721. SOC_DAPM_SINGLE("IN1LP Switch", WM8993_SPEAKER_MIXER, 5, 1, 0),
  722. SOC_DAPM_SINGLE("Output Switch", WM8993_SPEAKER_MIXER, 3, 1, 0),
  723. SOC_DAPM_SINGLE("DAC Switch", WM8993_SPEAKER_MIXER, 6, 1, 0),
  724. };
  725. static const struct snd_kcontrol_new right_speaker_mixer[] = {
  726. SOC_DAPM_SINGLE("Input Switch", WM8993_SPEAKER_MIXER, 6, 1, 0),
  727. SOC_DAPM_SINGLE("IN1RP Switch", WM8993_SPEAKER_MIXER, 4, 1, 0),
  728. SOC_DAPM_SINGLE("Output Switch", WM8993_SPEAKER_MIXER, 2, 1, 0),
  729. SOC_DAPM_SINGLE("DAC Switch", WM8993_SPEAKER_MIXER, 0, 1, 0),
  730. };
  731. static const char *aif_text[] = {
  732. "Left", "Right"
  733. };
  734. static const struct soc_enum aifoutl_enum =
  735. SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_1, 15, 2, aif_text);
  736. static const struct snd_kcontrol_new aifoutl_mux =
  737. SOC_DAPM_ENUM("AIFOUTL Mux", aifoutl_enum);
  738. static const struct soc_enum aifoutr_enum =
  739. SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_1, 14, 2, aif_text);
  740. static const struct snd_kcontrol_new aifoutr_mux =
  741. SOC_DAPM_ENUM("AIFOUTR Mux", aifoutr_enum);
  742. static const struct soc_enum aifinl_enum =
  743. SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_2, 15, 2, aif_text);
  744. static const struct snd_kcontrol_new aifinl_mux =
  745. SOC_DAPM_ENUM("AIFINL Mux", aifinl_enum);
  746. static const struct soc_enum aifinr_enum =
  747. SOC_ENUM_SINGLE(WM8993_AUDIO_INTERFACE_2, 14, 2, aif_text);
  748. static const struct snd_kcontrol_new aifinr_mux =
  749. SOC_DAPM_ENUM("AIFINR Mux", aifinr_enum);
  750. static const char *sidetone_text[] = {
  751. "None", "Left", "Right"
  752. };
  753. static const struct soc_enum sidetonel_enum =
  754. SOC_ENUM_SINGLE(WM8993_DIGITAL_SIDE_TONE, 2, 3, sidetone_text);
  755. static const struct snd_kcontrol_new sidetonel_mux =
  756. SOC_DAPM_ENUM("Left Sidetone", sidetonel_enum);
  757. static const struct soc_enum sidetoner_enum =
  758. SOC_ENUM_SINGLE(WM8993_DIGITAL_SIDE_TONE, 0, 3, sidetone_text);
  759. static const struct snd_kcontrol_new sidetoner_mux =
  760. SOC_DAPM_ENUM("Right Sidetone", sidetoner_enum);
  761. static const struct snd_soc_dapm_widget wm8993_dapm_widgets[] = {
  762. SND_SOC_DAPM_SUPPLY("CLK_SYS", WM8993_BUS_CONTROL_1, 1, 0, clk_sys_event,
  763. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  764. SND_SOC_DAPM_SUPPLY("TOCLK", WM8993_CLOCKING_1, 14, 0, NULL, 0),
  765. SND_SOC_DAPM_SUPPLY("CLK_DSP", WM8993_CLOCKING_3, 0, 0, NULL, 0),
  766. SND_SOC_DAPM_ADC("ADCL", NULL, WM8993_POWER_MANAGEMENT_2, 1, 0),
  767. SND_SOC_DAPM_ADC("ADCR", NULL, WM8993_POWER_MANAGEMENT_2, 0, 0),
  768. SND_SOC_DAPM_MUX("AIFOUTL Mux", SND_SOC_NOPM, 0, 0, &aifoutl_mux),
  769. SND_SOC_DAPM_MUX("AIFOUTR Mux", SND_SOC_NOPM, 0, 0, &aifoutr_mux),
  770. SND_SOC_DAPM_AIF_OUT("AIFOUTL", "Capture", 0, SND_SOC_NOPM, 0, 0),
  771. SND_SOC_DAPM_AIF_OUT("AIFOUTR", "Capture", 1, SND_SOC_NOPM, 0, 0),
  772. SND_SOC_DAPM_AIF_IN("AIFINL", "Playback", 0, SND_SOC_NOPM, 0, 0),
  773. SND_SOC_DAPM_AIF_IN("AIFINR", "Playback", 1, SND_SOC_NOPM, 0, 0),
  774. SND_SOC_DAPM_MUX("DACL Mux", SND_SOC_NOPM, 0, 0, &aifinl_mux),
  775. SND_SOC_DAPM_MUX("DACR Mux", SND_SOC_NOPM, 0, 0, &aifinr_mux),
  776. SND_SOC_DAPM_MUX("DACL Sidetone", SND_SOC_NOPM, 0, 0, &sidetonel_mux),
  777. SND_SOC_DAPM_MUX("DACR Sidetone", SND_SOC_NOPM, 0, 0, &sidetoner_mux),
  778. SND_SOC_DAPM_DAC("DACL", NULL, WM8993_POWER_MANAGEMENT_3, 1, 0),
  779. SND_SOC_DAPM_DAC("DACR", NULL, WM8993_POWER_MANAGEMENT_3, 0, 0),
  780. SND_SOC_DAPM_MUX("Left Headphone Mux", SND_SOC_NOPM, 0, 0, &hpl_mux),
  781. SND_SOC_DAPM_MUX("Right Headphone Mux", SND_SOC_NOPM, 0, 0, &hpr_mux),
  782. SND_SOC_DAPM_MIXER("SPKL", WM8993_POWER_MANAGEMENT_3, 8, 0,
  783. left_speaker_mixer, ARRAY_SIZE(left_speaker_mixer)),
  784. SND_SOC_DAPM_MIXER("SPKR", WM8993_POWER_MANAGEMENT_3, 9, 0,
  785. right_speaker_mixer, ARRAY_SIZE(right_speaker_mixer)),
  786. };
  787. static const struct snd_soc_dapm_route routes[] = {
  788. { "ADCL", NULL, "CLK_SYS" },
  789. { "ADCL", NULL, "CLK_DSP" },
  790. { "ADCR", NULL, "CLK_SYS" },
  791. { "ADCR", NULL, "CLK_DSP" },
  792. { "AIFOUTL Mux", "Left", "ADCL" },
  793. { "AIFOUTL Mux", "Right", "ADCR" },
  794. { "AIFOUTR Mux", "Left", "ADCL" },
  795. { "AIFOUTR Mux", "Right", "ADCR" },
  796. { "AIFOUTL", NULL, "AIFOUTL Mux" },
  797. { "AIFOUTR", NULL, "AIFOUTR Mux" },
  798. { "DACL Mux", "Left", "AIFINL" },
  799. { "DACL Mux", "Right", "AIFINR" },
  800. { "DACR Mux", "Left", "AIFINL" },
  801. { "DACR Mux", "Right", "AIFINR" },
  802. { "DACL Sidetone", "Left", "ADCL" },
  803. { "DACL Sidetone", "Right", "ADCR" },
  804. { "DACR Sidetone", "Left", "ADCL" },
  805. { "DACR Sidetone", "Right", "ADCR" },
  806. { "DACL", NULL, "CLK_SYS" },
  807. { "DACL", NULL, "CLK_DSP" },
  808. { "DACL", NULL, "DACL Mux" },
  809. { "DACL", NULL, "DACL Sidetone" },
  810. { "DACR", NULL, "CLK_SYS" },
  811. { "DACR", NULL, "CLK_DSP" },
  812. { "DACR", NULL, "DACR Mux" },
  813. { "DACR", NULL, "DACR Sidetone" },
  814. { "Left Output Mixer", "DAC Switch", "DACL" },
  815. { "Right Output Mixer", "DAC Switch", "DACR" },
  816. { "Left Output PGA", NULL, "CLK_SYS" },
  817. { "Right Output PGA", NULL, "CLK_SYS" },
  818. { "SPKL", "DAC Switch", "DACL" },
  819. { "SPKL", NULL, "CLK_SYS" },
  820. { "SPKR", "DAC Switch", "DACR" },
  821. { "SPKR", NULL, "CLK_SYS" },
  822. { "Left Headphone Mux", "DAC", "DACL" },
  823. { "Right Headphone Mux", "DAC", "DACR" },
  824. };
  825. static int wm8993_set_bias_level(struct snd_soc_codec *codec,
  826. enum snd_soc_bias_level level)
  827. {
  828. struct wm8993_priv *wm8993 = codec->private_data;
  829. switch (level) {
  830. case SND_SOC_BIAS_ON:
  831. case SND_SOC_BIAS_PREPARE:
  832. /* VMID=2*40k */
  833. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  834. WM8993_VMID_SEL_MASK, 0x2);
  835. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_2,
  836. WM8993_TSHUT_ENA, WM8993_TSHUT_ENA);
  837. break;
  838. case SND_SOC_BIAS_STANDBY:
  839. if (codec->bias_level == SND_SOC_BIAS_OFF) {
  840. /* Bring up VMID with fast soft start */
  841. snd_soc_update_bits(codec, WM8993_ANTIPOP2,
  842. WM8993_STARTUP_BIAS_ENA |
  843. WM8993_VMID_BUF_ENA |
  844. WM8993_VMID_RAMP_MASK |
  845. WM8993_BIAS_SRC,
  846. WM8993_STARTUP_BIAS_ENA |
  847. WM8993_VMID_BUF_ENA |
  848. WM8993_VMID_RAMP_MASK |
  849. WM8993_BIAS_SRC);
  850. /* If either line output is single ended we
  851. * need the VMID buffer */
  852. if (!wm8993->pdata.lineout1_diff ||
  853. !wm8993->pdata.lineout2_diff)
  854. snd_soc_update_bits(codec, WM8993_ANTIPOP1,
  855. WM8993_LINEOUT_VMID_BUF_ENA,
  856. WM8993_LINEOUT_VMID_BUF_ENA);
  857. /* VMID=2*40k */
  858. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  859. WM8993_VMID_SEL_MASK |
  860. WM8993_BIAS_ENA,
  861. WM8993_BIAS_ENA | 0x2);
  862. msleep(32);
  863. /* Switch to normal bias */
  864. snd_soc_update_bits(codec, WM8993_ANTIPOP2,
  865. WM8993_BIAS_SRC |
  866. WM8993_STARTUP_BIAS_ENA, 0);
  867. }
  868. /* VMID=2*240k */
  869. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  870. WM8993_VMID_SEL_MASK, 0x4);
  871. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_2,
  872. WM8993_TSHUT_ENA, 0);
  873. break;
  874. case SND_SOC_BIAS_OFF:
  875. snd_soc_update_bits(codec, WM8993_ANTIPOP1,
  876. WM8993_LINEOUT_VMID_BUF_ENA, 0);
  877. snd_soc_update_bits(codec, WM8993_POWER_MANAGEMENT_1,
  878. WM8993_VMID_SEL_MASK | WM8993_BIAS_ENA,
  879. 0);
  880. break;
  881. }
  882. codec->bias_level = level;
  883. return 0;
  884. }
  885. static int wm8993_set_sysclk(struct snd_soc_dai *codec_dai,
  886. int clk_id, unsigned int freq, int dir)
  887. {
  888. struct snd_soc_codec *codec = codec_dai->codec;
  889. struct wm8993_priv *wm8993 = codec->private_data;
  890. switch (clk_id) {
  891. case WM8993_SYSCLK_MCLK:
  892. wm8993->mclk_rate = freq;
  893. case WM8993_SYSCLK_FLL:
  894. wm8993->sysclk_source = clk_id;
  895. break;
  896. default:
  897. return -EINVAL;
  898. }
  899. return 0;
  900. }
  901. static int wm8993_set_dai_fmt(struct snd_soc_dai *dai,
  902. unsigned int fmt)
  903. {
  904. struct snd_soc_codec *codec = dai->codec;
  905. struct wm8993_priv *wm8993 = codec->private_data;
  906. unsigned int aif1 = wm8993_read(codec, WM8993_AUDIO_INTERFACE_1);
  907. unsigned int aif4 = wm8993_read(codec, WM8993_AUDIO_INTERFACE_4);
  908. aif1 &= ~(WM8993_BCLK_DIR | WM8993_AIF_BCLK_INV |
  909. WM8993_AIF_LRCLK_INV | WM8993_AIF_FMT_MASK);
  910. aif4 &= ~WM8993_LRCLK_DIR;
  911. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  912. case SND_SOC_DAIFMT_CBS_CFS:
  913. wm8993->master = 0;
  914. break;
  915. case SND_SOC_DAIFMT_CBS_CFM:
  916. aif4 |= WM8993_LRCLK_DIR;
  917. wm8993->master = 1;
  918. break;
  919. case SND_SOC_DAIFMT_CBM_CFS:
  920. aif1 |= WM8993_BCLK_DIR;
  921. wm8993->master = 1;
  922. break;
  923. case SND_SOC_DAIFMT_CBM_CFM:
  924. aif1 |= WM8993_BCLK_DIR;
  925. aif4 |= WM8993_LRCLK_DIR;
  926. wm8993->master = 1;
  927. break;
  928. default:
  929. return -EINVAL;
  930. }
  931. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  932. case SND_SOC_DAIFMT_DSP_B:
  933. aif1 |= WM8993_AIF_LRCLK_INV;
  934. case SND_SOC_DAIFMT_DSP_A:
  935. aif1 |= 0x18;
  936. break;
  937. case SND_SOC_DAIFMT_I2S:
  938. aif1 |= 0x10;
  939. break;
  940. case SND_SOC_DAIFMT_RIGHT_J:
  941. break;
  942. case SND_SOC_DAIFMT_LEFT_J:
  943. aif1 |= 0x8;
  944. break;
  945. default:
  946. return -EINVAL;
  947. }
  948. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  949. case SND_SOC_DAIFMT_DSP_A:
  950. case SND_SOC_DAIFMT_DSP_B:
  951. /* frame inversion not valid for DSP modes */
  952. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  953. case SND_SOC_DAIFMT_NB_NF:
  954. break;
  955. case SND_SOC_DAIFMT_IB_NF:
  956. aif1 |= WM8993_AIF_BCLK_INV;
  957. break;
  958. default:
  959. return -EINVAL;
  960. }
  961. break;
  962. case SND_SOC_DAIFMT_I2S:
  963. case SND_SOC_DAIFMT_RIGHT_J:
  964. case SND_SOC_DAIFMT_LEFT_J:
  965. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  966. case SND_SOC_DAIFMT_NB_NF:
  967. break;
  968. case SND_SOC_DAIFMT_IB_IF:
  969. aif1 |= WM8993_AIF_BCLK_INV | WM8993_AIF_LRCLK_INV;
  970. break;
  971. case SND_SOC_DAIFMT_IB_NF:
  972. aif1 |= WM8993_AIF_BCLK_INV;
  973. break;
  974. case SND_SOC_DAIFMT_NB_IF:
  975. aif1 |= WM8993_AIF_LRCLK_INV;
  976. break;
  977. default:
  978. return -EINVAL;
  979. }
  980. break;
  981. default:
  982. return -EINVAL;
  983. }
  984. wm8993_write(codec, WM8993_AUDIO_INTERFACE_1, aif1);
  985. wm8993_write(codec, WM8993_AUDIO_INTERFACE_4, aif4);
  986. return 0;
  987. }
  988. static int wm8993_hw_params(struct snd_pcm_substream *substream,
  989. struct snd_pcm_hw_params *params,
  990. struct snd_soc_dai *dai)
  991. {
  992. struct snd_soc_codec *codec = dai->codec;
  993. struct wm8993_priv *wm8993 = codec->private_data;
  994. int ret, i, best, best_val, cur_val;
  995. unsigned int clocking1, clocking3, aif1, aif4;
  996. clocking1 = wm8993_read(codec, WM8993_CLOCKING_1);
  997. clocking1 &= ~WM8993_BCLK_DIV_MASK;
  998. clocking3 = wm8993_read(codec, WM8993_CLOCKING_3);
  999. clocking3 &= ~(WM8993_CLK_SYS_RATE_MASK | WM8993_SAMPLE_RATE_MASK);
  1000. aif1 = wm8993_read(codec, WM8993_AUDIO_INTERFACE_1);
  1001. aif1 &= ~WM8993_AIF_WL_MASK;
  1002. aif4 = wm8993_read(codec, WM8993_AUDIO_INTERFACE_4);
  1003. aif4 &= ~WM8993_LRCLK_RATE_MASK;
  1004. /* What BCLK do we need? */
  1005. wm8993->fs = params_rate(params);
  1006. wm8993->bclk = 2 * wm8993->fs;
  1007. switch (params_format(params)) {
  1008. case SNDRV_PCM_FORMAT_S16_LE:
  1009. wm8993->bclk *= 16;
  1010. break;
  1011. case SNDRV_PCM_FORMAT_S20_3LE:
  1012. wm8993->bclk *= 20;
  1013. aif1 |= 0x8;
  1014. break;
  1015. case SNDRV_PCM_FORMAT_S24_LE:
  1016. wm8993->bclk *= 24;
  1017. aif1 |= 0x10;
  1018. break;
  1019. case SNDRV_PCM_FORMAT_S32_LE:
  1020. wm8993->bclk *= 32;
  1021. aif1 |= 0x18;
  1022. break;
  1023. default:
  1024. return -EINVAL;
  1025. }
  1026. dev_dbg(codec->dev, "Target BCLK is %dHz\n", wm8993->bclk);
  1027. ret = configure_clock(codec);
  1028. if (ret != 0)
  1029. return ret;
  1030. /* Select nearest CLK_SYS_RATE */
  1031. best = 0;
  1032. best_val = abs((wm8993->sysclk_rate / clk_sys_rates[0].ratio)
  1033. - wm8993->fs);
  1034. for (i = 1; i < ARRAY_SIZE(clk_sys_rates); i++) {
  1035. cur_val = abs((wm8993->sysclk_rate /
  1036. clk_sys_rates[i].ratio) - wm8993->fs);;
  1037. if (cur_val < best_val) {
  1038. best = i;
  1039. best_val = cur_val;
  1040. }
  1041. }
  1042. dev_dbg(codec->dev, "Selected CLK_SYS_RATIO of %d\n",
  1043. clk_sys_rates[best].ratio);
  1044. clocking3 |= (clk_sys_rates[best].clk_sys_rate
  1045. << WM8993_CLK_SYS_RATE_SHIFT);
  1046. /* SAMPLE_RATE */
  1047. best = 0;
  1048. best_val = abs(wm8993->fs - sample_rates[0].rate);
  1049. for (i = 1; i < ARRAY_SIZE(sample_rates); i++) {
  1050. /* Closest match */
  1051. cur_val = abs(wm8993->fs - sample_rates[i].rate);
  1052. if (cur_val < best_val) {
  1053. best = i;
  1054. best_val = cur_val;
  1055. }
  1056. }
  1057. dev_dbg(codec->dev, "Selected SAMPLE_RATE of %dHz\n",
  1058. sample_rates[best].rate);
  1059. clocking3 |= (sample_rates[best].sample_rate
  1060. << WM8993_SAMPLE_RATE_SHIFT);
  1061. /* BCLK_DIV */
  1062. best = 0;
  1063. best_val = INT_MAX;
  1064. for (i = 0; i < ARRAY_SIZE(bclk_divs); i++) {
  1065. cur_val = ((wm8993->sysclk_rate * 10) / bclk_divs[i].div)
  1066. - wm8993->bclk;
  1067. if (cur_val < 0) /* Table is sorted */
  1068. break;
  1069. if (cur_val < best_val) {
  1070. best = i;
  1071. best_val = cur_val;
  1072. }
  1073. }
  1074. wm8993->bclk = (wm8993->sysclk_rate * 10) / bclk_divs[best].div;
  1075. dev_dbg(codec->dev, "Selected BCLK_DIV of %d for %dHz BCLK\n",
  1076. bclk_divs[best].div, wm8993->bclk);
  1077. clocking1 |= bclk_divs[best].bclk_div << WM8993_BCLK_DIV_SHIFT;
  1078. /* LRCLK is a simple fraction of BCLK */
  1079. dev_dbg(codec->dev, "LRCLK_RATE is %d\n", wm8993->bclk / wm8993->fs);
  1080. aif4 |= wm8993->bclk / wm8993->fs;
  1081. wm8993_write(codec, WM8993_CLOCKING_1, clocking1);
  1082. wm8993_write(codec, WM8993_CLOCKING_3, clocking3);
  1083. wm8993_write(codec, WM8993_AUDIO_INTERFACE_1, aif1);
  1084. wm8993_write(codec, WM8993_AUDIO_INTERFACE_4, aif4);
  1085. /* ReTune Mobile? */
  1086. if (wm8993->pdata.num_retune_configs) {
  1087. u16 eq1 = wm8993_read(codec, WM8993_EQ1);
  1088. struct wm8993_retune_mobile_setting *s;
  1089. best = 0;
  1090. best_val = abs(wm8993->pdata.retune_configs[0].rate
  1091. - wm8993->fs);
  1092. for (i = 0; i < wm8993->pdata.num_retune_configs; i++) {
  1093. cur_val = abs(wm8993->pdata.retune_configs[i].rate
  1094. - wm8993->fs);
  1095. if (cur_val < best_val) {
  1096. best_val = cur_val;
  1097. best = i;
  1098. }
  1099. }
  1100. s = &wm8993->pdata.retune_configs[best];
  1101. dev_dbg(codec->dev, "ReTune Mobile %s tuned for %dHz\n",
  1102. s->name, s->rate);
  1103. /* Disable EQ while we reconfigure */
  1104. snd_soc_update_bits(codec, WM8993_EQ1, WM8993_EQ_ENA, 0);
  1105. for (i = 1; i < ARRAY_SIZE(s->config); i++)
  1106. wm8993_write(codec, WM8993_EQ1 + i, s->config[i]);
  1107. snd_soc_update_bits(codec, WM8993_EQ1, WM8993_EQ_ENA, eq1);
  1108. }
  1109. return 0;
  1110. }
  1111. static int wm8993_digital_mute(struct snd_soc_dai *codec_dai, int mute)
  1112. {
  1113. struct snd_soc_codec *codec = codec_dai->codec;
  1114. unsigned int reg;
  1115. reg = wm8993_read(codec, WM8993_DAC_CTRL);
  1116. if (mute)
  1117. reg |= WM8993_DAC_MUTE;
  1118. else
  1119. reg &= ~WM8993_DAC_MUTE;
  1120. wm8993_write(codec, WM8993_DAC_CTRL, reg);
  1121. return 0;
  1122. }
  1123. static struct snd_soc_dai_ops wm8993_ops = {
  1124. .set_sysclk = wm8993_set_sysclk,
  1125. .set_fmt = wm8993_set_dai_fmt,
  1126. .hw_params = wm8993_hw_params,
  1127. .digital_mute = wm8993_digital_mute,
  1128. .set_pll = wm8993_set_fll,
  1129. };
  1130. #define WM8993_RATES SNDRV_PCM_RATE_8000_48000
  1131. #define WM8993_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
  1132. SNDRV_PCM_FMTBIT_S20_3LE |\
  1133. SNDRV_PCM_FMTBIT_S24_LE |\
  1134. SNDRV_PCM_FMTBIT_S32_LE)
  1135. struct snd_soc_dai wm8993_dai = {
  1136. .name = "WM8993",
  1137. .playback = {
  1138. .stream_name = "Playback",
  1139. .channels_min = 1,
  1140. .channels_max = 2,
  1141. .rates = WM8993_RATES,
  1142. .formats = WM8993_FORMATS,
  1143. },
  1144. .capture = {
  1145. .stream_name = "Capture",
  1146. .channels_min = 1,
  1147. .channels_max = 2,
  1148. .rates = WM8993_RATES,
  1149. .formats = WM8993_FORMATS,
  1150. },
  1151. .ops = &wm8993_ops,
  1152. .symmetric_rates = 1,
  1153. };
  1154. EXPORT_SYMBOL_GPL(wm8993_dai);
  1155. static struct snd_soc_codec *wm8993_codec;
  1156. static int wm8993_probe(struct platform_device *pdev)
  1157. {
  1158. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  1159. struct snd_soc_codec *codec;
  1160. struct wm8993_priv *wm8993;
  1161. int ret = 0;
  1162. if (!wm8993_codec) {
  1163. dev_err(&pdev->dev, "I2C device not yet probed\n");
  1164. goto err;
  1165. }
  1166. socdev->card->codec = wm8993_codec;
  1167. codec = wm8993_codec;
  1168. wm8993 = codec->private_data;
  1169. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  1170. if (ret < 0) {
  1171. dev_err(codec->dev, "failed to create pcms\n");
  1172. goto err;
  1173. }
  1174. snd_soc_add_controls(codec, wm8993_snd_controls,
  1175. ARRAY_SIZE(wm8993_snd_controls));
  1176. if (wm8993->pdata.num_retune_configs != 0) {
  1177. dev_dbg(codec->dev, "Using ReTune Mobile\n");
  1178. } else {
  1179. dev_dbg(codec->dev, "No ReTune Mobile, using normal EQ\n");
  1180. snd_soc_add_controls(codec, wm8993_eq_controls,
  1181. ARRAY_SIZE(wm8993_eq_controls));
  1182. }
  1183. snd_soc_dapm_new_controls(codec, wm8993_dapm_widgets,
  1184. ARRAY_SIZE(wm8993_dapm_widgets));
  1185. wm_hubs_add_analogue_controls(codec);
  1186. snd_soc_dapm_add_routes(codec, routes, ARRAY_SIZE(routes));
  1187. wm_hubs_add_analogue_routes(codec, wm8993->pdata.lineout1_diff,
  1188. wm8993->pdata.lineout2_diff);
  1189. snd_soc_dapm_new_widgets(codec);
  1190. ret = snd_soc_init_card(socdev);
  1191. if (ret < 0) {
  1192. dev_err(codec->dev, "failed to register card\n");
  1193. goto card_err;
  1194. }
  1195. return ret;
  1196. card_err:
  1197. snd_soc_free_pcms(socdev);
  1198. snd_soc_dapm_free(socdev);
  1199. err:
  1200. return ret;
  1201. }
  1202. static int wm8993_remove(struct platform_device *pdev)
  1203. {
  1204. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  1205. snd_soc_free_pcms(socdev);
  1206. snd_soc_dapm_free(socdev);
  1207. return 0;
  1208. }
  1209. struct snd_soc_codec_device soc_codec_dev_wm8993 = {
  1210. .probe = wm8993_probe,
  1211. .remove = wm8993_remove,
  1212. };
  1213. EXPORT_SYMBOL_GPL(soc_codec_dev_wm8993);
  1214. static int wm8993_i2c_probe(struct i2c_client *i2c,
  1215. const struct i2c_device_id *id)
  1216. {
  1217. struct wm8993_priv *wm8993;
  1218. struct snd_soc_codec *codec;
  1219. unsigned int val;
  1220. int ret;
  1221. if (wm8993_codec) {
  1222. dev_err(&i2c->dev, "A WM8993 is already registered\n");
  1223. return -EINVAL;
  1224. }
  1225. wm8993 = kzalloc(sizeof(struct wm8993_priv), GFP_KERNEL);
  1226. if (wm8993 == NULL)
  1227. return -ENOMEM;
  1228. codec = &wm8993->codec;
  1229. if (i2c->dev.platform_data)
  1230. memcpy(&wm8993->pdata, i2c->dev.platform_data,
  1231. sizeof(wm8993->pdata));
  1232. mutex_init(&codec->mutex);
  1233. INIT_LIST_HEAD(&codec->dapm_widgets);
  1234. INIT_LIST_HEAD(&codec->dapm_paths);
  1235. codec->name = "WM8993";
  1236. codec->read = wm8993_read;
  1237. codec->write = wm8993_write;
  1238. codec->hw_write = (hw_write_t)i2c_master_send;
  1239. codec->reg_cache = wm8993->reg_cache;
  1240. codec->reg_cache_size = ARRAY_SIZE(wm8993->reg_cache);
  1241. codec->bias_level = SND_SOC_BIAS_OFF;
  1242. codec->set_bias_level = wm8993_set_bias_level;
  1243. codec->dai = &wm8993_dai;
  1244. codec->num_dai = 1;
  1245. codec->private_data = wm8993;
  1246. memcpy(wm8993->reg_cache, wm8993_reg_defaults,
  1247. sizeof(wm8993->reg_cache));
  1248. i2c_set_clientdata(i2c, wm8993);
  1249. codec->control_data = i2c;
  1250. wm8993_codec = codec;
  1251. codec->dev = &i2c->dev;
  1252. val = wm8993_read_hw(codec, WM8993_SOFTWARE_RESET);
  1253. if (val != wm8993_reg_defaults[WM8993_SOFTWARE_RESET]) {
  1254. dev_err(codec->dev, "Invalid ID register value %x\n", val);
  1255. ret = -EINVAL;
  1256. goto err;
  1257. }
  1258. ret = wm8993_write(codec, WM8993_SOFTWARE_RESET, 0xffff);
  1259. if (ret != 0)
  1260. goto err;
  1261. /* By default we're using the output mixers */
  1262. wm8993->class_w_users = 2;
  1263. /* Latch volume update bits and default ZC on */
  1264. snd_soc_update_bits(codec, WM8993_RIGHT_DAC_DIGITAL_VOLUME,
  1265. WM8993_DAC_VU, WM8993_DAC_VU);
  1266. snd_soc_update_bits(codec, WM8993_RIGHT_ADC_DIGITAL_VOLUME,
  1267. WM8993_ADC_VU, WM8993_ADC_VU);
  1268. /* Manualy manage the HPOUT sequencing for independent stereo
  1269. * control. */
  1270. snd_soc_update_bits(codec, WM8993_ANALOGUE_HP_0,
  1271. WM8993_HPOUT1_AUTO_PU, 0);
  1272. /* Use automatic clock configuration */
  1273. snd_soc_update_bits(codec, WM8993_CLOCKING_4, WM8993_SR_MODE, 0);
  1274. if (!wm8993->pdata.lineout1_diff)
  1275. snd_soc_update_bits(codec, WM8993_LINE_MIXER1,
  1276. WM8993_LINEOUT1_MODE,
  1277. WM8993_LINEOUT1_MODE);
  1278. if (!wm8993->pdata.lineout2_diff)
  1279. snd_soc_update_bits(codec, WM8993_LINE_MIXER2,
  1280. WM8993_LINEOUT2_MODE,
  1281. WM8993_LINEOUT2_MODE);
  1282. if (wm8993->pdata.lineout1fb)
  1283. snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
  1284. WM8993_LINEOUT1_FB, WM8993_LINEOUT1_FB);
  1285. if (wm8993->pdata.lineout2fb)
  1286. snd_soc_update_bits(codec, WM8993_ADDITIONAL_CONTROL,
  1287. WM8993_LINEOUT2_FB, WM8993_LINEOUT2_FB);
  1288. /* Apply the microphone bias/detection configuration - the
  1289. * platform data is directly applicable to the register. */
  1290. snd_soc_update_bits(codec, WM8993_MICBIAS,
  1291. WM8993_JD_SCTHR_MASK | WM8993_JD_THR_MASK |
  1292. WM8993_MICB1_LVL | WM8993_MICB2_LVL,
  1293. wm8993->pdata.jd_scthr << WM8993_JD_SCTHR_SHIFT |
  1294. wm8993->pdata.jd_thr << WM8993_JD_THR_SHIFT |
  1295. wm8993->pdata.micbias1_lvl |
  1296. wm8993->pdata.micbias1_lvl << 1);
  1297. ret = wm8993_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  1298. if (ret != 0)
  1299. goto err;
  1300. wm8993_dai.dev = codec->dev;
  1301. ret = snd_soc_register_dai(&wm8993_dai);
  1302. if (ret != 0)
  1303. goto err_bias;
  1304. ret = snd_soc_register_codec(codec);
  1305. return 0;
  1306. err_bias:
  1307. wm8993_set_bias_level(codec, SND_SOC_BIAS_OFF);
  1308. err:
  1309. wm8993_codec = NULL;
  1310. kfree(wm8993);
  1311. return ret;
  1312. }
  1313. static int wm8993_i2c_remove(struct i2c_client *client)
  1314. {
  1315. struct wm8993_priv *wm8993 = i2c_get_clientdata(client);
  1316. snd_soc_unregister_codec(&wm8993->codec);
  1317. snd_soc_unregister_dai(&wm8993_dai);
  1318. wm8993_set_bias_level(&wm8993->codec, SND_SOC_BIAS_OFF);
  1319. kfree(wm8993);
  1320. return 0;
  1321. }
  1322. static const struct i2c_device_id wm8993_i2c_id[] = {
  1323. { "wm8993", 0 },
  1324. { }
  1325. };
  1326. MODULE_DEVICE_TABLE(i2c, wm8993_i2c_id);
  1327. static struct i2c_driver wm8993_i2c_driver = {
  1328. .driver = {
  1329. .name = "WM8993",
  1330. .owner = THIS_MODULE,
  1331. },
  1332. .probe = wm8993_i2c_probe,
  1333. .remove = wm8993_i2c_remove,
  1334. .id_table = wm8993_i2c_id,
  1335. };
  1336. static int __init wm8993_modinit(void)
  1337. {
  1338. int ret;
  1339. ret = i2c_add_driver(&wm8993_i2c_driver);
  1340. if (ret != 0)
  1341. pr_err("WM8993: Unable to register I2C driver: %d\n", ret);
  1342. return ret;
  1343. }
  1344. module_init(wm8993_modinit);
  1345. static void __exit wm8993_exit(void)
  1346. {
  1347. i2c_del_driver(&wm8993_i2c_driver);
  1348. }
  1349. module_exit(wm8993_exit);
  1350. MODULE_DESCRIPTION("ASoC WM8993 driver");
  1351. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  1352. MODULE_LICENSE("GPL");