wm8955.c 30 KB

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