wm8955.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. * wm8955.c -- WM8955 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/platform_device.h>
  19. #include <linux/regulator/consumer.h>
  20. #include <linux/slab.h>
  21. #include <sound/core.h>
  22. #include <sound/pcm.h>
  23. #include <sound/pcm_params.h>
  24. #include <sound/soc.h>
  25. #include <sound/soc-dapm.h>
  26. #include <sound/initval.h>
  27. #include <sound/tlv.h>
  28. #include <sound/wm8955.h>
  29. #include "wm8955.h"
  30. static struct snd_soc_codec *wm8955_codec;
  31. struct snd_soc_codec_device soc_codec_dev_wm8955;
  32. #define WM8955_NUM_SUPPLIES 4
  33. static const char *wm8955_supply_names[WM8955_NUM_SUPPLIES] = {
  34. "DCVDD",
  35. "DBVDD",
  36. "HPVDD",
  37. "AVDD",
  38. };
  39. /* codec private data */
  40. struct wm8955_priv {
  41. struct snd_soc_codec codec;
  42. u16 reg_cache[WM8955_MAX_REGISTER + 1];
  43. unsigned int mclk_rate;
  44. int deemph;
  45. int fs;
  46. struct regulator_bulk_data supplies[WM8955_NUM_SUPPLIES];
  47. struct wm8955_pdata *pdata;
  48. };
  49. static const u16 wm8955_reg[WM8955_MAX_REGISTER + 1] = {
  50. 0x0000, /* R0 */
  51. 0x0000, /* R1 */
  52. 0x0079, /* R2 - LOUT1 volume */
  53. 0x0079, /* R3 - ROUT1 volume */
  54. 0x0000, /* R4 */
  55. 0x0008, /* R5 - DAC Control */
  56. 0x0000, /* R6 */
  57. 0x000A, /* R7 - Audio Interface */
  58. 0x0000, /* R8 - Sample Rate */
  59. 0x0000, /* R9 */
  60. 0x00FF, /* R10 - Left DAC volume */
  61. 0x00FF, /* R11 - Right DAC volume */
  62. 0x000F, /* R12 - Bass control */
  63. 0x000F, /* R13 - Treble control */
  64. 0x0000, /* R14 */
  65. 0x0000, /* R15 - Reset */
  66. 0x0000, /* R16 */
  67. 0x0000, /* R17 */
  68. 0x0000, /* R18 */
  69. 0x0000, /* R19 */
  70. 0x0000, /* R20 */
  71. 0x0000, /* R21 */
  72. 0x0000, /* R22 */
  73. 0x00C1, /* R23 - Additional control (1) */
  74. 0x0000, /* R24 - Additional control (2) */
  75. 0x0000, /* R25 - Power Management (1) */
  76. 0x0000, /* R26 - Power Management (2) */
  77. 0x0000, /* R27 - Additional Control (3) */
  78. 0x0000, /* R28 */
  79. 0x0000, /* R29 */
  80. 0x0000, /* R30 */
  81. 0x0000, /* R31 */
  82. 0x0000, /* R32 */
  83. 0x0000, /* R33 */
  84. 0x0050, /* R34 - Left out Mix (1) */
  85. 0x0050, /* R35 - Left out Mix (2) */
  86. 0x0050, /* R36 - Right out Mix (1) */
  87. 0x0050, /* R37 - Right Out Mix (2) */
  88. 0x0050, /* R38 - Mono out Mix (1) */
  89. 0x0050, /* R39 - Mono out Mix (2) */
  90. 0x0079, /* R40 - LOUT2 volume */
  91. 0x0079, /* R41 - ROUT2 volume */
  92. 0x0079, /* R42 - MONOOUT volume */
  93. 0x0000, /* R43 - Clocking / PLL */
  94. 0x0103, /* R44 - PLL Control 1 */
  95. 0x0024, /* R45 - PLL Control 2 */
  96. 0x01BA, /* R46 - PLL Control 3 */
  97. 0x0000, /* R47 */
  98. 0x0000, /* R48 */
  99. 0x0000, /* R49 */
  100. 0x0000, /* R50 */
  101. 0x0000, /* R51 */
  102. 0x0000, /* R52 */
  103. 0x0000, /* R53 */
  104. 0x0000, /* R54 */
  105. 0x0000, /* R55 */
  106. 0x0000, /* R56 */
  107. 0x0000, /* R57 */
  108. 0x0000, /* R58 */
  109. 0x0000, /* R59 - PLL Control 4 */
  110. };
  111. static int wm8955_reset(struct snd_soc_codec *codec)
  112. {
  113. return snd_soc_write(codec, WM8955_RESET, 0);
  114. }
  115. struct pll_factors {
  116. int n;
  117. int k;
  118. int outdiv;
  119. };
  120. /* The size in bits of the FLL divide multiplied by 10
  121. * to allow rounding later */
  122. #define FIXED_FLL_SIZE ((1 << 22) * 10)
  123. static int wm8995_pll_factors(struct device *dev,
  124. int Fref, int Fout, struct pll_factors *pll)
  125. {
  126. u64 Kpart;
  127. unsigned int K, Ndiv, Nmod, target;
  128. dev_dbg(dev, "Fref=%u Fout=%u\n", Fref, Fout);
  129. /* The oscilator should run at should be 90-100MHz, and
  130. * there's a divide by 4 plus an optional divide by 2 in the
  131. * output path to generate the system clock. The clock table
  132. * is sortd so we should always generate a suitable target. */
  133. target = Fout * 4;
  134. if (target < 90000000) {
  135. pll->outdiv = 1;
  136. target *= 2;
  137. } else {
  138. pll->outdiv = 0;
  139. }
  140. WARN_ON(target < 90000000 || target > 100000000);
  141. dev_dbg(dev, "Fvco=%dHz\n", target);
  142. /* Now, calculate N.K */
  143. Ndiv = target / Fref;
  144. pll->n = Ndiv;
  145. Nmod = target % Fref;
  146. dev_dbg(dev, "Nmod=%d\n", Nmod);
  147. /* Calculate fractional part - scale up so we can round. */
  148. Kpart = FIXED_FLL_SIZE * (long long)Nmod;
  149. do_div(Kpart, Fref);
  150. K = Kpart & 0xFFFFFFFF;
  151. if ((K % 10) >= 5)
  152. K += 5;
  153. /* Move down to proper range now rounding is done */
  154. pll->k = K / 10;
  155. dev_dbg(dev, "N=%x K=%x OUTDIV=%x\n", pll->n, pll->k, pll->outdiv);
  156. return 0;
  157. }
  158. /* Lookup table specifiying SRATE (table 25 in datasheet); some of the
  159. * output frequencies have been rounded to the standard frequencies
  160. * they are intended to match where the error is slight. */
  161. static struct {
  162. int mclk;
  163. int fs;
  164. int usb;
  165. int sr;
  166. } clock_cfgs[] = {
  167. { 18432000, 8000, 0, 3, },
  168. { 18432000, 12000, 0, 9, },
  169. { 18432000, 16000, 0, 11, },
  170. { 18432000, 24000, 0, 29, },
  171. { 18432000, 32000, 0, 13, },
  172. { 18432000, 48000, 0, 1, },
  173. { 18432000, 96000, 0, 15, },
  174. { 16934400, 8018, 0, 19, },
  175. { 16934400, 11025, 0, 25, },
  176. { 16934400, 22050, 0, 27, },
  177. { 16934400, 44100, 0, 17, },
  178. { 16934400, 88200, 0, 31, },
  179. { 12000000, 8000, 1, 2, },
  180. { 12000000, 11025, 1, 25, },
  181. { 12000000, 12000, 1, 8, },
  182. { 12000000, 16000, 1, 10, },
  183. { 12000000, 22050, 1, 27, },
  184. { 12000000, 24000, 1, 28, },
  185. { 12000000, 32000, 1, 12, },
  186. { 12000000, 44100, 1, 17, },
  187. { 12000000, 48000, 1, 0, },
  188. { 12000000, 88200, 1, 31, },
  189. { 12000000, 96000, 1, 14, },
  190. { 12288000, 8000, 0, 2, },
  191. { 12288000, 12000, 0, 8, },
  192. { 12288000, 16000, 0, 10, },
  193. { 12288000, 24000, 0, 28, },
  194. { 12288000, 32000, 0, 12, },
  195. { 12288000, 48000, 0, 0, },
  196. { 12288000, 96000, 0, 14, },
  197. { 12289600, 8018, 0, 18, },
  198. { 12289600, 11025, 0, 24, },
  199. { 12289600, 22050, 0, 26, },
  200. { 11289600, 44100, 0, 16, },
  201. { 11289600, 88200, 0, 31, },
  202. };
  203. static int wm8955_configure_clocking(struct snd_soc_codec *codec)
  204. {
  205. struct wm8955_priv *wm8955 = codec->private_data;
  206. int i, ret, val;
  207. int clocking = 0;
  208. int srate = 0;
  209. int sr = -1;
  210. struct pll_factors pll;
  211. /* If we're not running a sample rate currently just pick one */
  212. if (wm8955->fs == 0)
  213. wm8955->fs = 8000;
  214. /* Can we generate an exact output? */
  215. for (i = 0; i < ARRAY_SIZE(clock_cfgs); i++) {
  216. if (wm8955->fs != clock_cfgs[i].fs)
  217. continue;
  218. sr = i;
  219. if (wm8955->mclk_rate == clock_cfgs[i].mclk)
  220. break;
  221. }
  222. /* We should never get here with an unsupported sample rate */
  223. if (sr == -1) {
  224. dev_err(codec->dev, "Sample rate %dHz unsupported\n",
  225. wm8955->fs);
  226. WARN_ON(sr == -1);
  227. return -EINVAL;
  228. }
  229. if (i == ARRAY_SIZE(clock_cfgs)) {
  230. /* If we can't generate the right clock from MCLK then
  231. * we should configure the PLL to supply us with an
  232. * appropriate clock.
  233. */
  234. clocking |= WM8955_MCLKSEL;
  235. /* Use the last divider configuration we saw for the
  236. * sample rate. */
  237. ret = wm8995_pll_factors(codec->dev, wm8955->mclk_rate,
  238. clock_cfgs[sr].mclk, &pll);
  239. if (ret != 0) {
  240. dev_err(codec->dev,
  241. "Unable to generate %dHz from %dHz MCLK\n",
  242. wm8955->fs, wm8955->mclk_rate);
  243. return -EINVAL;
  244. }
  245. snd_soc_update_bits(codec, WM8955_PLL_CONTROL_1,
  246. WM8955_N_MASK | WM8955_K_21_18_MASK,
  247. (pll.n << WM8955_N_SHIFT) |
  248. pll.k >> 18);
  249. snd_soc_update_bits(codec, WM8955_PLL_CONTROL_2,
  250. WM8955_K_17_9_MASK,
  251. (pll.k >> 9) & WM8955_K_17_9_MASK);
  252. snd_soc_update_bits(codec, WM8955_PLL_CONTROL_2,
  253. WM8955_K_8_0_MASK,
  254. pll.k & WM8955_K_8_0_MASK);
  255. if (pll.k)
  256. snd_soc_update_bits(codec, WM8955_PLL_CONTROL_4,
  257. WM8955_KEN, WM8955_KEN);
  258. else
  259. snd_soc_update_bits(codec, WM8955_PLL_CONTROL_4,
  260. WM8955_KEN, 0);
  261. if (pll.outdiv)
  262. val = WM8955_PLL_RB | WM8955_PLLOUTDIV2;
  263. else
  264. val = WM8955_PLL_RB;
  265. /* Now start the PLL running */
  266. snd_soc_update_bits(codec, WM8955_CLOCKING_PLL,
  267. WM8955_PLL_RB | WM8955_PLLOUTDIV2, val);
  268. snd_soc_update_bits(codec, WM8955_CLOCKING_PLL,
  269. WM8955_PLLEN, WM8955_PLLEN);
  270. }
  271. srate = clock_cfgs[sr].usb | (clock_cfgs[sr].sr << WM8955_SR_SHIFT);
  272. snd_soc_update_bits(codec, WM8955_SAMPLE_RATE,
  273. WM8955_USB | WM8955_SR_MASK, srate);
  274. snd_soc_update_bits(codec, WM8955_CLOCKING_PLL,
  275. WM8955_MCLKSEL, clocking);
  276. return 0;
  277. }
  278. static int wm8955_sysclk(struct snd_soc_dapm_widget *w,
  279. struct snd_kcontrol *kcontrol, int event)
  280. {
  281. struct snd_soc_codec *codec = w->codec;
  282. int ret = 0;
  283. /* Always disable the clocks - if we're doing reconfiguration this
  284. * avoids misclocking.
  285. */
  286. snd_soc_update_bits(codec, WM8955_POWER_MANAGEMENT_1,
  287. WM8955_DIGENB, 0);
  288. snd_soc_update_bits(codec, WM8955_CLOCKING_PLL,
  289. WM8955_PLL_RB | WM8955_PLLEN, 0);
  290. switch (event) {
  291. case SND_SOC_DAPM_POST_PMD:
  292. break;
  293. case SND_SOC_DAPM_PRE_PMU:
  294. ret = wm8955_configure_clocking(codec);
  295. break;
  296. default:
  297. ret = -EINVAL;
  298. break;
  299. }
  300. return ret;
  301. }
  302. static int deemph_settings[] = { 0, 32000, 44100, 48000 };
  303. static int wm8955_set_deemph(struct snd_soc_codec *codec)
  304. {
  305. struct wm8955_priv *wm8955 = codec->private_data;
  306. int val, i, best;
  307. /* If we're using deemphasis select the nearest available sample
  308. * rate.
  309. */
  310. if (wm8955->deemph) {
  311. best = 1;
  312. for (i = 2; i < ARRAY_SIZE(deemph_settings); i++) {
  313. if (abs(deemph_settings[i] - wm8955->fs) <
  314. abs(deemph_settings[best] - wm8955->fs))
  315. best = i;
  316. }
  317. val = best << WM8955_DEEMPH_SHIFT;
  318. } else {
  319. val = 0;
  320. }
  321. dev_dbg(codec->dev, "Set deemphasis %d\n", val);
  322. return snd_soc_update_bits(codec, WM8955_DAC_CONTROL,
  323. WM8955_DEEMPH_MASK, val);
  324. }
  325. static int wm8955_get_deemph(struct snd_kcontrol *kcontrol,
  326. struct snd_ctl_elem_value *ucontrol)
  327. {
  328. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  329. struct wm8955_priv *wm8955 = codec->private_data;
  330. return wm8955->deemph;
  331. }
  332. static int wm8955_put_deemph(struct snd_kcontrol *kcontrol,
  333. struct snd_ctl_elem_value *ucontrol)
  334. {
  335. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  336. struct wm8955_priv *wm8955 = codec->private_data;
  337. int deemph = ucontrol->value.enumerated.item[0];
  338. if (deemph > 1)
  339. return -EINVAL;
  340. wm8955->deemph = deemph;
  341. return wm8955_set_deemph(codec);
  342. }
  343. static const char *bass_mode_text[] = {
  344. "Linear", "Adaptive",
  345. };
  346. static const struct soc_enum bass_mode =
  347. SOC_ENUM_SINGLE(WM8955_BASS_CONTROL, 7, 2, bass_mode_text);
  348. static const char *bass_cutoff_text[] = {
  349. "Low", "High"
  350. };
  351. static const struct soc_enum bass_cutoff =
  352. SOC_ENUM_SINGLE(WM8955_BASS_CONTROL, 6, 2, bass_cutoff_text);
  353. static const char *treble_cutoff_text[] = {
  354. "High", "Low"
  355. };
  356. static const struct soc_enum treble_cutoff =
  357. SOC_ENUM_SINGLE(WM8955_TREBLE_CONTROL, 6, 2, treble_cutoff_text);
  358. static const DECLARE_TLV_DB_SCALE(digital_tlv, -12750, 50, 1);
  359. static const DECLARE_TLV_DB_SCALE(atten_tlv, -600, 600, 0);
  360. static const DECLARE_TLV_DB_SCALE(bypass_tlv, -1500, 300, 0);
  361. static const DECLARE_TLV_DB_SCALE(mono_tlv, -2100, 300, 0);
  362. static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
  363. static const DECLARE_TLV_DB_SCALE(treble_tlv, -1200, 150, 1);
  364. static const struct snd_kcontrol_new wm8955_snd_controls[] = {
  365. SOC_DOUBLE_R_TLV("Digital Playback Volume", WM8955_LEFT_DAC_VOLUME,
  366. WM8955_RIGHT_DAC_VOLUME, 0, 255, 0, digital_tlv),
  367. SOC_SINGLE_TLV("Playback Attenuation Volume", WM8955_DAC_CONTROL, 7, 1, 1,
  368. atten_tlv),
  369. SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,
  370. wm8955_get_deemph, wm8955_put_deemph),
  371. SOC_ENUM("Bass Mode", bass_mode),
  372. SOC_ENUM("Bass Cutoff", bass_cutoff),
  373. SOC_SINGLE("Bass Volume", WM8955_BASS_CONTROL, 0, 15, 1),
  374. SOC_ENUM("Treble Cutoff", treble_cutoff),
  375. SOC_SINGLE_TLV("Treble Volume", WM8955_TREBLE_CONTROL, 0, 14, 1, treble_tlv),
  376. SOC_SINGLE_TLV("Left Bypass Volume", WM8955_LEFT_OUT_MIX_1, 4, 7, 1,
  377. bypass_tlv),
  378. SOC_SINGLE_TLV("Left Mono Volume", WM8955_LEFT_OUT_MIX_2, 4, 7, 1,
  379. bypass_tlv),
  380. SOC_SINGLE_TLV("Right Mono Volume", WM8955_RIGHT_OUT_MIX_1, 4, 7, 1,
  381. bypass_tlv),
  382. SOC_SINGLE_TLV("Right Bypass Volume", WM8955_RIGHT_OUT_MIX_2, 4, 7, 1,
  383. bypass_tlv),
  384. /* Not a stereo pair so they line up with the DAPM switches */
  385. SOC_SINGLE_TLV("Mono Left Bypass Volume", WM8955_MONO_OUT_MIX_1, 4, 7, 1,
  386. mono_tlv),
  387. SOC_SINGLE_TLV("Mono Right Bypass Volume", WM8955_MONO_OUT_MIX_2, 4, 7, 1,
  388. mono_tlv),
  389. SOC_DOUBLE_R_TLV("Headphone Volume", WM8955_LOUT1_VOLUME,
  390. WM8955_ROUT1_VOLUME, 0, 127, 0, out_tlv),
  391. SOC_DOUBLE_R("Headphone ZC Switch", WM8955_LOUT1_VOLUME,
  392. WM8955_ROUT1_VOLUME, 7, 1, 0),
  393. SOC_DOUBLE_R_TLV("Speaker Volume", WM8955_LOUT2_VOLUME,
  394. WM8955_ROUT2_VOLUME, 0, 127, 0, out_tlv),
  395. SOC_DOUBLE_R("Speaker ZC Switch", WM8955_LOUT2_VOLUME,
  396. WM8955_ROUT2_VOLUME, 7, 1, 0),
  397. SOC_SINGLE_TLV("Mono Volume", WM8955_MONOOUT_VOLUME, 0, 127, 0, out_tlv),
  398. SOC_SINGLE("Mono ZC Switch", WM8955_MONOOUT_VOLUME, 7, 1, 0),
  399. };
  400. static const struct snd_kcontrol_new lmixer[] = {
  401. SOC_DAPM_SINGLE("Playback Switch", WM8955_LEFT_OUT_MIX_1, 8, 1, 0),
  402. SOC_DAPM_SINGLE("Bypass Switch", WM8955_LEFT_OUT_MIX_1, 7, 1, 0),
  403. SOC_DAPM_SINGLE("Right Playback Switch", WM8955_LEFT_OUT_MIX_2, 8, 1, 0),
  404. SOC_DAPM_SINGLE("Mono Switch", WM8955_LEFT_OUT_MIX_2, 7, 1, 0),
  405. };
  406. static const struct snd_kcontrol_new rmixer[] = {
  407. SOC_DAPM_SINGLE("Left Playback Switch", WM8955_RIGHT_OUT_MIX_1, 8, 1, 0),
  408. SOC_DAPM_SINGLE("Mono Switch", WM8955_RIGHT_OUT_MIX_1, 7, 1, 0),
  409. SOC_DAPM_SINGLE("Playback Switch", WM8955_RIGHT_OUT_MIX_2, 8, 1, 0),
  410. SOC_DAPM_SINGLE("Bypass Switch", WM8955_RIGHT_OUT_MIX_2, 7, 1, 0),
  411. };
  412. static const struct snd_kcontrol_new mmixer[] = {
  413. SOC_DAPM_SINGLE("Left Playback Switch", WM8955_MONO_OUT_MIX_1, 8, 1, 0),
  414. SOC_DAPM_SINGLE("Left Bypass Switch", WM8955_MONO_OUT_MIX_1, 7, 1, 0),
  415. SOC_DAPM_SINGLE("Right Playback Switch", WM8955_MONO_OUT_MIX_2, 8, 1, 0),
  416. SOC_DAPM_SINGLE("Right Bypass Switch", WM8955_MONO_OUT_MIX_2, 7, 1, 0),
  417. };
  418. static const struct snd_soc_dapm_widget wm8955_dapm_widgets[] = {
  419. SND_SOC_DAPM_INPUT("MONOIN-"),
  420. SND_SOC_DAPM_INPUT("MONOIN+"),
  421. SND_SOC_DAPM_INPUT("LINEINR"),
  422. SND_SOC_DAPM_INPUT("LINEINL"),
  423. SND_SOC_DAPM_PGA("Mono Input", SND_SOC_NOPM, 0, 0, NULL, 0),
  424. SND_SOC_DAPM_SUPPLY("SYSCLK", WM8955_POWER_MANAGEMENT_1, 0, 1, wm8955_sysclk,
  425. SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD),
  426. SND_SOC_DAPM_SUPPLY("TSDEN", WM8955_ADDITIONAL_CONTROL_1, 8, 0, NULL, 0),
  427. SND_SOC_DAPM_DAC("DACL", "Playback", WM8955_POWER_MANAGEMENT_2, 8, 0),
  428. SND_SOC_DAPM_DAC("DACR", "Playback", WM8955_POWER_MANAGEMENT_2, 7, 0),
  429. SND_SOC_DAPM_PGA("LOUT1 PGA", WM8955_POWER_MANAGEMENT_2, 6, 0, NULL, 0),
  430. SND_SOC_DAPM_PGA("ROUT1 PGA", WM8955_POWER_MANAGEMENT_2, 5, 0, NULL, 0),
  431. SND_SOC_DAPM_PGA("LOUT2 PGA", WM8955_POWER_MANAGEMENT_2, 4, 0, NULL, 0),
  432. SND_SOC_DAPM_PGA("ROUT2 PGA", WM8955_POWER_MANAGEMENT_2, 3, 0, NULL, 0),
  433. SND_SOC_DAPM_PGA("MOUT PGA", WM8955_POWER_MANAGEMENT_2, 2, 0, NULL, 0),
  434. SND_SOC_DAPM_PGA("OUT3 PGA", WM8955_POWER_MANAGEMENT_2, 1, 0, NULL, 0),
  435. /* The names are chosen to make the control names nice */
  436. SND_SOC_DAPM_MIXER("Left", SND_SOC_NOPM, 0, 0,
  437. lmixer, ARRAY_SIZE(lmixer)),
  438. SND_SOC_DAPM_MIXER("Right", SND_SOC_NOPM, 0, 0,
  439. rmixer, ARRAY_SIZE(rmixer)),
  440. SND_SOC_DAPM_MIXER("Mono", SND_SOC_NOPM, 0, 0,
  441. mmixer, ARRAY_SIZE(mmixer)),
  442. SND_SOC_DAPM_OUTPUT("LOUT1"),
  443. SND_SOC_DAPM_OUTPUT("ROUT1"),
  444. SND_SOC_DAPM_OUTPUT("LOUT2"),
  445. SND_SOC_DAPM_OUTPUT("ROUT2"),
  446. SND_SOC_DAPM_OUTPUT("MONOOUT"),
  447. SND_SOC_DAPM_OUTPUT("OUT3"),
  448. };
  449. static const struct snd_soc_dapm_route wm8955_intercon[] = {
  450. { "DACL", NULL, "SYSCLK" },
  451. { "DACR", NULL, "SYSCLK" },
  452. { "Mono Input", NULL, "MONOIN-" },
  453. { "Mono Input", NULL, "MONOIN+" },
  454. { "Left", "Playback Switch", "DACL" },
  455. { "Left", "Right Playback Switch", "DACR" },
  456. { "Left", "Bypass Switch", "LINEINL" },
  457. { "Left", "Mono Switch", "Mono Input" },
  458. { "Right", "Playback Switch", "DACR" },
  459. { "Right", "Left Playback Switch", "DACL" },
  460. { "Right", "Bypass Switch", "LINEINR" },
  461. { "Right", "Mono Switch", "Mono Input" },
  462. { "Mono", "Left Playback Switch", "DACL" },
  463. { "Mono", "Right Playback Switch", "DACR" },
  464. { "Mono", "Left Bypass Switch", "LINEINL" },
  465. { "Mono", "Right Bypass Switch", "LINEINR" },
  466. { "LOUT1 PGA", NULL, "Left" },
  467. { "LOUT1", NULL, "TSDEN" },
  468. { "LOUT1", NULL, "LOUT1 PGA" },
  469. { "ROUT1 PGA", NULL, "Right" },
  470. { "ROUT1", NULL, "TSDEN" },
  471. { "ROUT1", NULL, "ROUT1 PGA" },
  472. { "LOUT2 PGA", NULL, "Left" },
  473. { "LOUT2", NULL, "TSDEN" },
  474. { "LOUT2", NULL, "LOUT2 PGA" },
  475. { "ROUT2 PGA", NULL, "Right" },
  476. { "ROUT2", NULL, "TSDEN" },
  477. { "ROUT2", NULL, "ROUT2 PGA" },
  478. { "MOUT PGA", NULL, "Mono" },
  479. { "MONOOUT", NULL, "MOUT PGA" },
  480. /* OUT3 not currently implemented */
  481. { "OUT3", NULL, "OUT3 PGA" },
  482. };
  483. static int wm8955_add_widgets(struct snd_soc_codec *codec)
  484. {
  485. snd_soc_add_controls(codec, wm8955_snd_controls,
  486. ARRAY_SIZE(wm8955_snd_controls));
  487. snd_soc_dapm_new_controls(codec, wm8955_dapm_widgets,
  488. ARRAY_SIZE(wm8955_dapm_widgets));
  489. snd_soc_dapm_add_routes(codec, wm8955_intercon,
  490. ARRAY_SIZE(wm8955_intercon));
  491. return 0;
  492. }
  493. static int wm8955_hw_params(struct snd_pcm_substream *substream,
  494. struct snd_pcm_hw_params *params,
  495. struct snd_soc_dai *dai)
  496. {
  497. struct snd_soc_codec *codec = dai->codec;
  498. struct wm8955_priv *wm8955 = codec->private_data;
  499. int ret;
  500. int wl;
  501. switch (params_format(params)) {
  502. case SNDRV_PCM_FORMAT_S16_LE:
  503. wl = 0;
  504. break;
  505. case SNDRV_PCM_FORMAT_S20_3LE:
  506. wl = 0x4;
  507. break;
  508. case SNDRV_PCM_FORMAT_S24_LE:
  509. wl = 0x8;
  510. break;
  511. case SNDRV_PCM_FORMAT_S32_LE:
  512. wl = 0xc;
  513. break;
  514. default:
  515. return -EINVAL;
  516. }
  517. snd_soc_update_bits(codec, WM8955_AUDIO_INTERFACE,
  518. WM8955_WL_MASK, wl);
  519. wm8955->fs = params_rate(params);
  520. wm8955_set_deemph(codec);
  521. /* If the chip is clocked then disable the clocks and force a
  522. * reconfiguration, otherwise DAPM will power up the
  523. * clocks for us later. */
  524. ret = snd_soc_read(codec, WM8955_POWER_MANAGEMENT_1);
  525. if (ret < 0)
  526. return ret;
  527. if (ret & WM8955_DIGENB) {
  528. snd_soc_update_bits(codec, WM8955_POWER_MANAGEMENT_1,
  529. WM8955_DIGENB, 0);
  530. snd_soc_update_bits(codec, WM8955_CLOCKING_PLL,
  531. WM8955_PLL_RB | WM8955_PLLEN, 0);
  532. wm8955_configure_clocking(codec);
  533. }
  534. return 0;
  535. }
  536. static int wm8955_set_sysclk(struct snd_soc_dai *dai, int clk_id,
  537. unsigned int freq, int dir)
  538. {
  539. struct snd_soc_codec *codec = dai->codec;
  540. struct wm8955_priv *priv = codec->private_data;
  541. int div;
  542. switch (clk_id) {
  543. case WM8955_CLK_MCLK:
  544. if (freq > 15000000) {
  545. priv->mclk_rate = freq /= 2;
  546. div = WM8955_MCLKDIV2;
  547. } else {
  548. priv->mclk_rate = freq;
  549. div = 0;
  550. }
  551. snd_soc_update_bits(codec, WM8955_SAMPLE_RATE,
  552. WM8955_MCLKDIV2, div);
  553. break;
  554. default:
  555. return -EINVAL;
  556. }
  557. dev_dbg(dai->dev, "Clock source is %d at %uHz\n", clk_id, freq);
  558. return 0;
  559. }
  560. static int wm8955_set_fmt(struct snd_soc_dai *dai, unsigned int fmt)
  561. {
  562. struct snd_soc_codec *codec = dai->codec;
  563. u16 aif = 0;
  564. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  565. case SND_SOC_DAIFMT_CBS_CFS:
  566. break;
  567. case SND_SOC_DAIFMT_CBM_CFM:
  568. aif |= WM8955_MS;
  569. break;
  570. default:
  571. return -EINVAL;
  572. }
  573. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  574. case SND_SOC_DAIFMT_DSP_B:
  575. aif |= WM8955_LRP;
  576. case SND_SOC_DAIFMT_DSP_A:
  577. aif |= 0x3;
  578. break;
  579. case SND_SOC_DAIFMT_I2S:
  580. aif |= 0x2;
  581. break;
  582. case SND_SOC_DAIFMT_RIGHT_J:
  583. break;
  584. case SND_SOC_DAIFMT_LEFT_J:
  585. aif |= 0x1;
  586. break;
  587. default:
  588. return -EINVAL;
  589. }
  590. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  591. case SND_SOC_DAIFMT_DSP_A:
  592. case SND_SOC_DAIFMT_DSP_B:
  593. /* frame inversion not valid for DSP modes */
  594. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  595. case SND_SOC_DAIFMT_NB_NF:
  596. break;
  597. case SND_SOC_DAIFMT_IB_NF:
  598. aif |= WM8955_BCLKINV;
  599. break;
  600. default:
  601. return -EINVAL;
  602. }
  603. break;
  604. case SND_SOC_DAIFMT_I2S:
  605. case SND_SOC_DAIFMT_RIGHT_J:
  606. case SND_SOC_DAIFMT_LEFT_J:
  607. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  608. case SND_SOC_DAIFMT_NB_NF:
  609. break;
  610. case SND_SOC_DAIFMT_IB_IF:
  611. aif |= WM8955_BCLKINV | WM8955_LRP;
  612. break;
  613. case SND_SOC_DAIFMT_IB_NF:
  614. aif |= WM8955_BCLKINV;
  615. break;
  616. case SND_SOC_DAIFMT_NB_IF:
  617. aif |= WM8955_LRP;
  618. break;
  619. default:
  620. return -EINVAL;
  621. }
  622. break;
  623. default:
  624. return -EINVAL;
  625. }
  626. snd_soc_update_bits(codec, WM8955_AUDIO_INTERFACE,
  627. WM8955_MS | WM8955_FORMAT_MASK | WM8955_BCLKINV |
  628. WM8955_LRP, aif);
  629. return 0;
  630. }
  631. static int wm8955_digital_mute(struct snd_soc_dai *codec_dai, int mute)
  632. {
  633. struct snd_soc_codec *codec = codec_dai->codec;
  634. int val;
  635. if (mute)
  636. val = WM8955_DACMU;
  637. else
  638. val = 0;
  639. snd_soc_update_bits(codec, WM8955_DAC_CONTROL, WM8955_DACMU, val);
  640. return 0;
  641. }
  642. static int wm8955_set_bias_level(struct snd_soc_codec *codec,
  643. enum snd_soc_bias_level level)
  644. {
  645. struct wm8955_priv *wm8955 = codec->private_data;
  646. int ret, i;
  647. switch (level) {
  648. case SND_SOC_BIAS_ON:
  649. break;
  650. case SND_SOC_BIAS_PREPARE:
  651. /* VMID resistance 2*50k */
  652. snd_soc_update_bits(codec, WM8955_POWER_MANAGEMENT_1,
  653. WM8955_VMIDSEL_MASK,
  654. 0x1 << WM8955_VMIDSEL_SHIFT);
  655. /* Default bias current */
  656. snd_soc_update_bits(codec, WM8955_ADDITIONAL_CONTROL_1,
  657. WM8955_VSEL_MASK,
  658. 0x2 << WM8955_VSEL_SHIFT);
  659. break;
  660. case SND_SOC_BIAS_STANDBY:
  661. if (codec->bias_level == SND_SOC_BIAS_OFF) {
  662. ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies),
  663. wm8955->supplies);
  664. if (ret != 0) {
  665. dev_err(codec->dev,
  666. "Failed to enable supplies: %d\n",
  667. ret);
  668. return ret;
  669. }
  670. /* Sync back cached values if they're
  671. * different from the hardware default.
  672. */
  673. for (i = 0; i < ARRAY_SIZE(wm8955->reg_cache); i++) {
  674. if (i == WM8955_RESET)
  675. continue;
  676. if (wm8955->reg_cache[i] == wm8955_reg[i])
  677. continue;
  678. snd_soc_write(codec, i, wm8955->reg_cache[i]);
  679. }
  680. /* Enable VREF and VMID */
  681. snd_soc_update_bits(codec, WM8955_POWER_MANAGEMENT_1,
  682. WM8955_VREF |
  683. WM8955_VMIDSEL_MASK,
  684. WM8955_VREF |
  685. 0x3 << WM8955_VREF_SHIFT);
  686. /* Let VMID ramp */
  687. msleep(500);
  688. /* High resistance VROI to maintain outputs */
  689. snd_soc_update_bits(codec,
  690. WM8955_ADDITIONAL_CONTROL_3,
  691. WM8955_VROI, WM8955_VROI);
  692. }
  693. /* Maintain VMID with 2*250k */
  694. snd_soc_update_bits(codec, WM8955_POWER_MANAGEMENT_1,
  695. WM8955_VMIDSEL_MASK,
  696. 0x2 << WM8955_VMIDSEL_SHIFT);
  697. /* Minimum bias current */
  698. snd_soc_update_bits(codec, WM8955_ADDITIONAL_CONTROL_1,
  699. WM8955_VSEL_MASK, 0);
  700. break;
  701. case SND_SOC_BIAS_OFF:
  702. /* Low resistance VROI to help discharge */
  703. snd_soc_update_bits(codec,
  704. WM8955_ADDITIONAL_CONTROL_3,
  705. WM8955_VROI, 0);
  706. /* Turn off VMID and VREF */
  707. snd_soc_update_bits(codec, WM8955_POWER_MANAGEMENT_1,
  708. WM8955_VREF |
  709. WM8955_VMIDSEL_MASK, 0);
  710. regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies),
  711. wm8955->supplies);
  712. break;
  713. }
  714. codec->bias_level = level;
  715. return 0;
  716. }
  717. #define WM8955_RATES SNDRV_PCM_RATE_8000_96000
  718. #define WM8955_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
  719. SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S32_LE)
  720. static struct snd_soc_dai_ops wm8955_dai_ops = {
  721. .set_sysclk = wm8955_set_sysclk,
  722. .set_fmt = wm8955_set_fmt,
  723. .hw_params = wm8955_hw_params,
  724. .digital_mute = wm8955_digital_mute,
  725. };
  726. struct snd_soc_dai wm8955_dai = {
  727. .name = "WM8955",
  728. .playback = {
  729. .stream_name = "Playback",
  730. .channels_min = 2,
  731. .channels_max = 2,
  732. .rates = WM8955_RATES,
  733. .formats = WM8955_FORMATS,
  734. },
  735. .ops = &wm8955_dai_ops,
  736. };
  737. EXPORT_SYMBOL_GPL(wm8955_dai);
  738. #ifdef CONFIG_PM
  739. static int wm8955_suspend(struct platform_device *pdev, pm_message_t state)
  740. {
  741. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  742. struct snd_soc_codec *codec = socdev->card->codec;
  743. wm8955_set_bias_level(codec, SND_SOC_BIAS_OFF);
  744. return 0;
  745. }
  746. static int wm8955_resume(struct platform_device *pdev)
  747. {
  748. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  749. struct snd_soc_codec *codec = socdev->card->codec;
  750. wm8955_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  751. return 0;
  752. }
  753. #else
  754. #define wm8955_suspend NULL
  755. #define wm8955_resume NULL
  756. #endif
  757. static int wm8955_probe(struct platform_device *pdev)
  758. {
  759. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  760. struct snd_soc_codec *codec;
  761. int ret = 0;
  762. if (wm8955_codec == NULL) {
  763. dev_err(&pdev->dev, "Codec device not registered\n");
  764. return -ENODEV;
  765. }
  766. socdev->card->codec = wm8955_codec;
  767. codec = wm8955_codec;
  768. /* register pcms */
  769. ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
  770. if (ret < 0) {
  771. dev_err(codec->dev, "failed to create pcms: %d\n", ret);
  772. goto pcm_err;
  773. }
  774. wm8955_add_widgets(codec);
  775. return ret;
  776. pcm_err:
  777. return ret;
  778. }
  779. static int wm8955_remove(struct platform_device *pdev)
  780. {
  781. struct snd_soc_device *socdev = platform_get_drvdata(pdev);
  782. snd_soc_free_pcms(socdev);
  783. snd_soc_dapm_free(socdev);
  784. return 0;
  785. }
  786. struct snd_soc_codec_device soc_codec_dev_wm8955 = {
  787. .probe = wm8955_probe,
  788. .remove = wm8955_remove,
  789. .suspend = wm8955_suspend,
  790. .resume = wm8955_resume,
  791. };
  792. EXPORT_SYMBOL_GPL(soc_codec_dev_wm8955);
  793. static int wm8955_register(struct wm8955_priv *wm8955,
  794. enum snd_soc_control_type control)
  795. {
  796. int ret;
  797. struct snd_soc_codec *codec = &wm8955->codec;
  798. int i;
  799. if (wm8955_codec) {
  800. dev_err(codec->dev, "Another WM8955 is registered\n");
  801. return -EINVAL;
  802. }
  803. mutex_init(&codec->mutex);
  804. INIT_LIST_HEAD(&codec->dapm_widgets);
  805. INIT_LIST_HEAD(&codec->dapm_paths);
  806. codec->private_data = wm8955;
  807. codec->name = "WM8955";
  808. codec->owner = THIS_MODULE;
  809. codec->bias_level = SND_SOC_BIAS_OFF;
  810. codec->set_bias_level = wm8955_set_bias_level;
  811. codec->dai = &wm8955_dai;
  812. codec->num_dai = 1;
  813. codec->reg_cache_size = WM8955_MAX_REGISTER;
  814. codec->reg_cache = &wm8955->reg_cache;
  815. memcpy(codec->reg_cache, wm8955_reg, sizeof(wm8955_reg));
  816. ret = snd_soc_codec_set_cache_io(codec, 7, 9, control);
  817. if (ret != 0) {
  818. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  819. goto err;
  820. }
  821. for (i = 0; i < ARRAY_SIZE(wm8955->supplies); i++)
  822. wm8955->supplies[i].supply = wm8955_supply_names[i];
  823. ret = regulator_bulk_get(codec->dev, ARRAY_SIZE(wm8955->supplies),
  824. wm8955->supplies);
  825. if (ret != 0) {
  826. dev_err(codec->dev, "Failed to request supplies: %d\n", ret);
  827. goto err;
  828. }
  829. ret = regulator_bulk_enable(ARRAY_SIZE(wm8955->supplies),
  830. wm8955->supplies);
  831. if (ret != 0) {
  832. dev_err(codec->dev, "Failed to enable supplies: %d\n", ret);
  833. goto err_get;
  834. }
  835. ret = wm8955_reset(codec);
  836. if (ret < 0) {
  837. dev_err(codec->dev, "Failed to issue reset: %d\n", ret);
  838. goto err_enable;
  839. }
  840. wm8955_dai.dev = codec->dev;
  841. /* Change some default settings - latch VU and enable ZC */
  842. wm8955->reg_cache[WM8955_LEFT_DAC_VOLUME] |= WM8955_LDVU;
  843. wm8955->reg_cache[WM8955_RIGHT_DAC_VOLUME] |= WM8955_RDVU;
  844. wm8955->reg_cache[WM8955_LOUT1_VOLUME] |= WM8955_LO1VU | WM8955_LO1ZC;
  845. wm8955->reg_cache[WM8955_ROUT1_VOLUME] |= WM8955_RO1VU | WM8955_RO1ZC;
  846. wm8955->reg_cache[WM8955_LOUT2_VOLUME] |= WM8955_LO2VU | WM8955_LO2ZC;
  847. wm8955->reg_cache[WM8955_ROUT2_VOLUME] |= WM8955_RO2VU | WM8955_RO2ZC;
  848. wm8955->reg_cache[WM8955_MONOOUT_VOLUME] |= WM8955_MOZC;
  849. /* Also enable adaptive bass boost by default */
  850. wm8955->reg_cache[WM8955_BASS_CONTROL] |= WM8955_BB;
  851. /* Set platform data values */
  852. if (wm8955->pdata) {
  853. if (wm8955->pdata->out2_speaker)
  854. wm8955->reg_cache[WM8955_ADDITIONAL_CONTROL_2]
  855. |= WM8955_ROUT2INV;
  856. if (wm8955->pdata->monoin_diff)
  857. wm8955->reg_cache[WM8955_MONO_OUT_MIX_1]
  858. |= WM8955_DMEN;
  859. }
  860. wm8955_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  861. /* Bias level configuration will have done an extra enable */
  862. regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies), wm8955->supplies);
  863. wm8955_codec = codec;
  864. ret = snd_soc_register_codec(codec);
  865. if (ret != 0) {
  866. dev_err(codec->dev, "Failed to register codec: %d\n", ret);
  867. return ret;
  868. }
  869. ret = snd_soc_register_dai(&wm8955_dai);
  870. if (ret != 0) {
  871. dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
  872. snd_soc_unregister_codec(codec);
  873. return ret;
  874. }
  875. return 0;
  876. err_enable:
  877. regulator_bulk_disable(ARRAY_SIZE(wm8955->supplies), wm8955->supplies);
  878. err_get:
  879. regulator_bulk_free(ARRAY_SIZE(wm8955->supplies), wm8955->supplies);
  880. err:
  881. kfree(wm8955);
  882. return ret;
  883. }
  884. static void wm8955_unregister(struct wm8955_priv *wm8955)
  885. {
  886. wm8955_set_bias_level(&wm8955->codec, SND_SOC_BIAS_OFF);
  887. regulator_bulk_free(ARRAY_SIZE(wm8955->supplies), wm8955->supplies);
  888. snd_soc_unregister_dai(&wm8955_dai);
  889. snd_soc_unregister_codec(&wm8955->codec);
  890. kfree(wm8955);
  891. wm8955_codec = NULL;
  892. }
  893. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  894. static __devinit int wm8955_i2c_probe(struct i2c_client *i2c,
  895. const struct i2c_device_id *id)
  896. {
  897. struct wm8955_priv *wm8955;
  898. struct snd_soc_codec *codec;
  899. wm8955 = kzalloc(sizeof(struct wm8955_priv), GFP_KERNEL);
  900. if (wm8955 == NULL)
  901. return -ENOMEM;
  902. codec = &wm8955->codec;
  903. codec->hw_write = (hw_write_t)i2c_master_send;
  904. i2c_set_clientdata(i2c, wm8955);
  905. codec->control_data = i2c;
  906. wm8955->pdata = i2c->dev.platform_data;
  907. codec->dev = &i2c->dev;
  908. return wm8955_register(wm8955, SND_SOC_I2C);
  909. }
  910. static __devexit int wm8955_i2c_remove(struct i2c_client *client)
  911. {
  912. struct wm8955_priv *wm8955 = i2c_get_clientdata(client);
  913. wm8955_unregister(wm8955);
  914. return 0;
  915. }
  916. static const struct i2c_device_id wm8955_i2c_id[] = {
  917. { "wm8955", 0 },
  918. { }
  919. };
  920. MODULE_DEVICE_TABLE(i2c, wm8955_i2c_id);
  921. static struct i2c_driver wm8955_i2c_driver = {
  922. .driver = {
  923. .name = "wm8955",
  924. .owner = THIS_MODULE,
  925. },
  926. .probe = wm8955_i2c_probe,
  927. .remove = __devexit_p(wm8955_i2c_remove),
  928. .id_table = wm8955_i2c_id,
  929. };
  930. #endif
  931. static int __init wm8955_modinit(void)
  932. {
  933. int ret;
  934. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  935. ret = i2c_add_driver(&wm8955_i2c_driver);
  936. if (ret != 0) {
  937. printk(KERN_ERR "Failed to register WM8955 I2C driver: %d\n",
  938. ret);
  939. }
  940. #endif
  941. return 0;
  942. }
  943. module_init(wm8955_modinit);
  944. static void __exit wm8955_exit(void)
  945. {
  946. #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
  947. i2c_del_driver(&wm8955_i2c_driver);
  948. #endif
  949. }
  950. module_exit(wm8955_exit);
  951. MODULE_DESCRIPTION("ASoC WM8955 driver");
  952. MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
  953. MODULE_LICENSE("GPL");