wm8960.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091
  1. /*
  2. * wm8960.c -- WM8960 ALSA SoC Audio driver
  3. *
  4. * Copyright 2007-11 Wolfson Microelectronics, plc
  5. *
  6. * Author: Liam Girdwood
  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/slab.h>
  19. #include <sound/core.h>
  20. #include <sound/pcm.h>
  21. #include <sound/pcm_params.h>
  22. #include <sound/soc.h>
  23. #include <sound/initval.h>
  24. #include <sound/tlv.h>
  25. #include <sound/wm8960.h>
  26. #include "wm8960.h"
  27. /* R25 - Power 1 */
  28. #define WM8960_VMID_MASK 0x180
  29. #define WM8960_VREF 0x40
  30. /* R26 - Power 2 */
  31. #define WM8960_PWR2_LOUT1 0x40
  32. #define WM8960_PWR2_ROUT1 0x20
  33. #define WM8960_PWR2_OUT3 0x02
  34. /* R28 - Anti-pop 1 */
  35. #define WM8960_POBCTRL 0x80
  36. #define WM8960_BUFDCOPEN 0x10
  37. #define WM8960_BUFIOEN 0x08
  38. #define WM8960_SOFT_ST 0x04
  39. #define WM8960_HPSTBY 0x01
  40. /* R29 - Anti-pop 2 */
  41. #define WM8960_DISOP 0x40
  42. #define WM8960_DRES_MASK 0x30
  43. /*
  44. * wm8960 register cache
  45. * We can't read the WM8960 register space when we are
  46. * using 2 wire for device control, so we cache them instead.
  47. */
  48. static const struct reg_default wm8960_reg_defaults[] = {
  49. { 0x0, 0x00a7 },
  50. { 0x1, 0x00a7 },
  51. { 0x2, 0x0000 },
  52. { 0x3, 0x0000 },
  53. { 0x4, 0x0000 },
  54. { 0x5, 0x0008 },
  55. { 0x6, 0x0000 },
  56. { 0x7, 0x000a },
  57. { 0x8, 0x01c0 },
  58. { 0x9, 0x0000 },
  59. { 0xa, 0x00ff },
  60. { 0xb, 0x00ff },
  61. { 0x10, 0x0000 },
  62. { 0x11, 0x007b },
  63. { 0x12, 0x0100 },
  64. { 0x13, 0x0032 },
  65. { 0x14, 0x0000 },
  66. { 0x15, 0x00c3 },
  67. { 0x16, 0x00c3 },
  68. { 0x17, 0x01c0 },
  69. { 0x18, 0x0000 },
  70. { 0x19, 0x0000 },
  71. { 0x1a, 0x0000 },
  72. { 0x1b, 0x0000 },
  73. { 0x1c, 0x0000 },
  74. { 0x1d, 0x0000 },
  75. { 0x20, 0x0100 },
  76. { 0x21, 0x0100 },
  77. { 0x22, 0x0050 },
  78. { 0x25, 0x0050 },
  79. { 0x26, 0x0000 },
  80. { 0x27, 0x0000 },
  81. { 0x28, 0x0000 },
  82. { 0x29, 0x0000 },
  83. { 0x2a, 0x0040 },
  84. { 0x2b, 0x0000 },
  85. { 0x2c, 0x0000 },
  86. { 0x2d, 0x0050 },
  87. { 0x2e, 0x0050 },
  88. { 0x2f, 0x0000 },
  89. { 0x30, 0x0002 },
  90. { 0x31, 0x0037 },
  91. { 0x33, 0x0080 },
  92. { 0x34, 0x0008 },
  93. { 0x35, 0x0031 },
  94. { 0x36, 0x0026 },
  95. { 0x37, 0x00e9 },
  96. };
  97. static bool wm8960_volatile(struct device *dev, unsigned int reg)
  98. {
  99. switch (reg) {
  100. case WM8960_RESET:
  101. return true;
  102. default:
  103. return false;
  104. }
  105. }
  106. struct wm8960_priv {
  107. struct regmap *regmap;
  108. int (*set_bias_level)(struct snd_soc_codec *,
  109. enum snd_soc_bias_level level);
  110. struct snd_soc_dapm_widget *lout1;
  111. struct snd_soc_dapm_widget *rout1;
  112. struct snd_soc_dapm_widget *out3;
  113. bool deemph;
  114. int playback_fs;
  115. };
  116. #define wm8960_reset(c) snd_soc_write(c, WM8960_RESET, 0)
  117. /* enumerated controls */
  118. static const char *wm8960_polarity[] = {"No Inversion", "Left Inverted",
  119. "Right Inverted", "Stereo Inversion"};
  120. static const char *wm8960_3d_upper_cutoff[] = {"High", "Low"};
  121. static const char *wm8960_3d_lower_cutoff[] = {"Low", "High"};
  122. static const char *wm8960_alcfunc[] = {"Off", "Right", "Left", "Stereo"};
  123. static const char *wm8960_alcmode[] = {"ALC", "Limiter"};
  124. static const struct soc_enum wm8960_enum[] = {
  125. SOC_ENUM_SINGLE(WM8960_DACCTL1, 5, 4, wm8960_polarity),
  126. SOC_ENUM_SINGLE(WM8960_DACCTL2, 5, 4, wm8960_polarity),
  127. SOC_ENUM_SINGLE(WM8960_3D, 6, 2, wm8960_3d_upper_cutoff),
  128. SOC_ENUM_SINGLE(WM8960_3D, 5, 2, wm8960_3d_lower_cutoff),
  129. SOC_ENUM_SINGLE(WM8960_ALC1, 7, 4, wm8960_alcfunc),
  130. SOC_ENUM_SINGLE(WM8960_ALC3, 8, 2, wm8960_alcmode),
  131. };
  132. static const int deemph_settings[] = { 0, 32000, 44100, 48000 };
  133. static int wm8960_set_deemph(struct snd_soc_codec *codec)
  134. {
  135. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  136. int val, i, best;
  137. /* If we're using deemphasis select the nearest available sample
  138. * rate.
  139. */
  140. if (wm8960->deemph) {
  141. best = 1;
  142. for (i = 2; i < ARRAY_SIZE(deemph_settings); i++) {
  143. if (abs(deemph_settings[i] - wm8960->playback_fs) <
  144. abs(deemph_settings[best] - wm8960->playback_fs))
  145. best = i;
  146. }
  147. val = best << 1;
  148. } else {
  149. val = 0;
  150. }
  151. dev_dbg(codec->dev, "Set deemphasis %d\n", val);
  152. return snd_soc_update_bits(codec, WM8960_DACCTL1,
  153. 0x6, val);
  154. }
  155. static int wm8960_get_deemph(struct snd_kcontrol *kcontrol,
  156. struct snd_ctl_elem_value *ucontrol)
  157. {
  158. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  159. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  160. ucontrol->value.enumerated.item[0] = wm8960->deemph;
  161. return 0;
  162. }
  163. static int wm8960_put_deemph(struct snd_kcontrol *kcontrol,
  164. struct snd_ctl_elem_value *ucontrol)
  165. {
  166. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  167. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  168. int deemph = ucontrol->value.enumerated.item[0];
  169. if (deemph > 1)
  170. return -EINVAL;
  171. wm8960->deemph = deemph;
  172. return wm8960_set_deemph(codec);
  173. }
  174. static const DECLARE_TLV_DB_SCALE(adc_tlv, -9700, 50, 0);
  175. static const DECLARE_TLV_DB_SCALE(dac_tlv, -12700, 50, 1);
  176. static const DECLARE_TLV_DB_SCALE(bypass_tlv, -2100, 300, 0);
  177. static const DECLARE_TLV_DB_SCALE(out_tlv, -12100, 100, 1);
  178. static const struct snd_kcontrol_new wm8960_snd_controls[] = {
  179. SOC_DOUBLE_R_TLV("Capture Volume", WM8960_LINVOL, WM8960_RINVOL,
  180. 0, 63, 0, adc_tlv),
  181. SOC_DOUBLE_R("Capture Volume ZC Switch", WM8960_LINVOL, WM8960_RINVOL,
  182. 6, 1, 0),
  183. SOC_DOUBLE_R("Capture Switch", WM8960_LINVOL, WM8960_RINVOL,
  184. 7, 1, 0),
  185. SOC_DOUBLE_R_TLV("Playback Volume", WM8960_LDAC, WM8960_RDAC,
  186. 0, 255, 0, dac_tlv),
  187. SOC_DOUBLE_R_TLV("Headphone Playback Volume", WM8960_LOUT1, WM8960_ROUT1,
  188. 0, 127, 0, out_tlv),
  189. SOC_DOUBLE_R("Headphone Playback ZC Switch", WM8960_LOUT1, WM8960_ROUT1,
  190. 7, 1, 0),
  191. SOC_DOUBLE_R_TLV("Speaker Playback Volume", WM8960_LOUT2, WM8960_ROUT2,
  192. 0, 127, 0, out_tlv),
  193. SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8960_LOUT2, WM8960_ROUT2,
  194. 7, 1, 0),
  195. SOC_SINGLE("Speaker DC Volume", WM8960_CLASSD3, 3, 5, 0),
  196. SOC_SINGLE("Speaker AC Volume", WM8960_CLASSD3, 0, 5, 0),
  197. SOC_SINGLE("PCM Playback -6dB Switch", WM8960_DACCTL1, 7, 1, 0),
  198. SOC_ENUM("ADC Polarity", wm8960_enum[0]),
  199. SOC_SINGLE("ADC High Pass Filter Switch", WM8960_DACCTL1, 0, 1, 0),
  200. SOC_ENUM("DAC Polarity", wm8960_enum[2]),
  201. SOC_SINGLE_BOOL_EXT("DAC Deemphasis Switch", 0,
  202. wm8960_get_deemph, wm8960_put_deemph),
  203. SOC_ENUM("3D Filter Upper Cut-Off", wm8960_enum[2]),
  204. SOC_ENUM("3D Filter Lower Cut-Off", wm8960_enum[3]),
  205. SOC_SINGLE("3D Volume", WM8960_3D, 1, 15, 0),
  206. SOC_SINGLE("3D Switch", WM8960_3D, 0, 1, 0),
  207. SOC_ENUM("ALC Function", wm8960_enum[4]),
  208. SOC_SINGLE("ALC Max Gain", WM8960_ALC1, 4, 7, 0),
  209. SOC_SINGLE("ALC Target", WM8960_ALC1, 0, 15, 1),
  210. SOC_SINGLE("ALC Min Gain", WM8960_ALC2, 4, 7, 0),
  211. SOC_SINGLE("ALC Hold Time", WM8960_ALC2, 0, 15, 0),
  212. SOC_ENUM("ALC Mode", wm8960_enum[5]),
  213. SOC_SINGLE("ALC Decay", WM8960_ALC3, 4, 15, 0),
  214. SOC_SINGLE("ALC Attack", WM8960_ALC3, 0, 15, 0),
  215. SOC_SINGLE("Noise Gate Threshold", WM8960_NOISEG, 3, 31, 0),
  216. SOC_SINGLE("Noise Gate Switch", WM8960_NOISEG, 0, 1, 0),
  217. SOC_DOUBLE_R("ADC PCM Capture Volume", WM8960_LINPATH, WM8960_RINPATH,
  218. 0, 127, 0),
  219. SOC_SINGLE_TLV("Left Output Mixer Boost Bypass Volume",
  220. WM8960_BYPASS1, 4, 7, 1, bypass_tlv),
  221. SOC_SINGLE_TLV("Left Output Mixer LINPUT3 Volume",
  222. WM8960_LOUTMIX, 4, 7, 1, bypass_tlv),
  223. SOC_SINGLE_TLV("Right Output Mixer Boost Bypass Volume",
  224. WM8960_BYPASS2, 4, 7, 1, bypass_tlv),
  225. SOC_SINGLE_TLV("Right Output Mixer RINPUT3 Volume",
  226. WM8960_ROUTMIX, 4, 7, 1, bypass_tlv),
  227. };
  228. static const struct snd_kcontrol_new wm8960_lin_boost[] = {
  229. SOC_DAPM_SINGLE("LINPUT2 Switch", WM8960_LINPATH, 6, 1, 0),
  230. SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LINPATH, 7, 1, 0),
  231. SOC_DAPM_SINGLE("LINPUT1 Switch", WM8960_LINPATH, 8, 1, 0),
  232. };
  233. static const struct snd_kcontrol_new wm8960_lin[] = {
  234. SOC_DAPM_SINGLE("Boost Switch", WM8960_LINPATH, 3, 1, 0),
  235. };
  236. static const struct snd_kcontrol_new wm8960_rin_boost[] = {
  237. SOC_DAPM_SINGLE("RINPUT2 Switch", WM8960_RINPATH, 6, 1, 0),
  238. SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_RINPATH, 7, 1, 0),
  239. SOC_DAPM_SINGLE("RINPUT1 Switch", WM8960_RINPATH, 8, 1, 0),
  240. };
  241. static const struct snd_kcontrol_new wm8960_rin[] = {
  242. SOC_DAPM_SINGLE("Boost Switch", WM8960_RINPATH, 3, 1, 0),
  243. };
  244. static const struct snd_kcontrol_new wm8960_loutput_mixer[] = {
  245. SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_LOUTMIX, 8, 1, 0),
  246. SOC_DAPM_SINGLE("LINPUT3 Switch", WM8960_LOUTMIX, 7, 1, 0),
  247. SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS1, 7, 1, 0),
  248. };
  249. static const struct snd_kcontrol_new wm8960_routput_mixer[] = {
  250. SOC_DAPM_SINGLE("PCM Playback Switch", WM8960_ROUTMIX, 8, 1, 0),
  251. SOC_DAPM_SINGLE("RINPUT3 Switch", WM8960_ROUTMIX, 7, 1, 0),
  252. SOC_DAPM_SINGLE("Boost Bypass Switch", WM8960_BYPASS2, 7, 1, 0),
  253. };
  254. static const struct snd_kcontrol_new wm8960_mono_out[] = {
  255. SOC_DAPM_SINGLE("Left Switch", WM8960_MONOMIX1, 7, 1, 0),
  256. SOC_DAPM_SINGLE("Right Switch", WM8960_MONOMIX2, 7, 1, 0),
  257. };
  258. static const struct snd_soc_dapm_widget wm8960_dapm_widgets[] = {
  259. SND_SOC_DAPM_INPUT("LINPUT1"),
  260. SND_SOC_DAPM_INPUT("RINPUT1"),
  261. SND_SOC_DAPM_INPUT("LINPUT2"),
  262. SND_SOC_DAPM_INPUT("RINPUT2"),
  263. SND_SOC_DAPM_INPUT("LINPUT3"),
  264. SND_SOC_DAPM_INPUT("RINPUT3"),
  265. SND_SOC_DAPM_SUPPLY("MICB", WM8960_POWER1, 1, 0, NULL, 0),
  266. SND_SOC_DAPM_MIXER("Left Boost Mixer", WM8960_POWER1, 5, 0,
  267. wm8960_lin_boost, ARRAY_SIZE(wm8960_lin_boost)),
  268. SND_SOC_DAPM_MIXER("Right Boost Mixer", WM8960_POWER1, 4, 0,
  269. wm8960_rin_boost, ARRAY_SIZE(wm8960_rin_boost)),
  270. SND_SOC_DAPM_MIXER("Left Input Mixer", WM8960_POWER3, 5, 0,
  271. wm8960_lin, ARRAY_SIZE(wm8960_lin)),
  272. SND_SOC_DAPM_MIXER("Right Input Mixer", WM8960_POWER3, 4, 0,
  273. wm8960_rin, ARRAY_SIZE(wm8960_rin)),
  274. SND_SOC_DAPM_ADC("Left ADC", "Capture", WM8960_POWER1, 3, 0),
  275. SND_SOC_DAPM_ADC("Right ADC", "Capture", WM8960_POWER1, 2, 0),
  276. SND_SOC_DAPM_DAC("Left DAC", "Playback", WM8960_POWER2, 8, 0),
  277. SND_SOC_DAPM_DAC("Right DAC", "Playback", WM8960_POWER2, 7, 0),
  278. SND_SOC_DAPM_MIXER("Left Output Mixer", WM8960_POWER3, 3, 0,
  279. &wm8960_loutput_mixer[0],
  280. ARRAY_SIZE(wm8960_loutput_mixer)),
  281. SND_SOC_DAPM_MIXER("Right Output Mixer", WM8960_POWER3, 2, 0,
  282. &wm8960_routput_mixer[0],
  283. ARRAY_SIZE(wm8960_routput_mixer)),
  284. SND_SOC_DAPM_PGA("LOUT1 PGA", WM8960_POWER2, 6, 0, NULL, 0),
  285. SND_SOC_DAPM_PGA("ROUT1 PGA", WM8960_POWER2, 5, 0, NULL, 0),
  286. SND_SOC_DAPM_PGA("Left Speaker PGA", WM8960_POWER2, 4, 0, NULL, 0),
  287. SND_SOC_DAPM_PGA("Right Speaker PGA", WM8960_POWER2, 3, 0, NULL, 0),
  288. SND_SOC_DAPM_PGA("Right Speaker Output", WM8960_CLASSD1, 7, 0, NULL, 0),
  289. SND_SOC_DAPM_PGA("Left Speaker Output", WM8960_CLASSD1, 6, 0, NULL, 0),
  290. SND_SOC_DAPM_OUTPUT("SPK_LP"),
  291. SND_SOC_DAPM_OUTPUT("SPK_LN"),
  292. SND_SOC_DAPM_OUTPUT("HP_L"),
  293. SND_SOC_DAPM_OUTPUT("HP_R"),
  294. SND_SOC_DAPM_OUTPUT("SPK_RP"),
  295. SND_SOC_DAPM_OUTPUT("SPK_RN"),
  296. SND_SOC_DAPM_OUTPUT("OUT3"),
  297. };
  298. static const struct snd_soc_dapm_widget wm8960_dapm_widgets_out3[] = {
  299. SND_SOC_DAPM_MIXER("Mono Output Mixer", WM8960_POWER2, 1, 0,
  300. &wm8960_mono_out[0],
  301. ARRAY_SIZE(wm8960_mono_out)),
  302. };
  303. /* Represent OUT3 as a PGA so that it gets turned on with LOUT1/ROUT1 */
  304. static const struct snd_soc_dapm_widget wm8960_dapm_widgets_capless[] = {
  305. SND_SOC_DAPM_PGA("OUT3 VMID", WM8960_POWER2, 1, 0, NULL, 0),
  306. };
  307. static const struct snd_soc_dapm_route audio_paths[] = {
  308. { "Left Boost Mixer", "LINPUT1 Switch", "LINPUT1" },
  309. { "Left Boost Mixer", "LINPUT2 Switch", "LINPUT2" },
  310. { "Left Boost Mixer", "LINPUT3 Switch", "LINPUT3" },
  311. { "Left Input Mixer", "Boost Switch", "Left Boost Mixer", },
  312. { "Left Input Mixer", NULL, "LINPUT1", }, /* Really Boost Switch */
  313. { "Left Input Mixer", NULL, "LINPUT2" },
  314. { "Left Input Mixer", NULL, "LINPUT3" },
  315. { "Right Boost Mixer", "RINPUT1 Switch", "RINPUT1" },
  316. { "Right Boost Mixer", "RINPUT2 Switch", "RINPUT2" },
  317. { "Right Boost Mixer", "RINPUT3 Switch", "RINPUT3" },
  318. { "Right Input Mixer", "Boost Switch", "Right Boost Mixer", },
  319. { "Right Input Mixer", NULL, "RINPUT1", }, /* Really Boost Switch */
  320. { "Right Input Mixer", NULL, "RINPUT2" },
  321. { "Right Input Mixer", NULL, "LINPUT3" },
  322. { "Left ADC", NULL, "Left Input Mixer" },
  323. { "Right ADC", NULL, "Right Input Mixer" },
  324. { "Left Output Mixer", "LINPUT3 Switch", "LINPUT3" },
  325. { "Left Output Mixer", "Boost Bypass Switch", "Left Boost Mixer"} ,
  326. { "Left Output Mixer", "PCM Playback Switch", "Left DAC" },
  327. { "Right Output Mixer", "RINPUT3 Switch", "RINPUT3" },
  328. { "Right Output Mixer", "Boost Bypass Switch", "Right Boost Mixer" } ,
  329. { "Right Output Mixer", "PCM Playback Switch", "Right DAC" },
  330. { "LOUT1 PGA", NULL, "Left Output Mixer" },
  331. { "ROUT1 PGA", NULL, "Right Output Mixer" },
  332. { "HP_L", NULL, "LOUT1 PGA" },
  333. { "HP_R", NULL, "ROUT1 PGA" },
  334. { "Left Speaker PGA", NULL, "Left Output Mixer" },
  335. { "Right Speaker PGA", NULL, "Right Output Mixer" },
  336. { "Left Speaker Output", NULL, "Left Speaker PGA" },
  337. { "Right Speaker Output", NULL, "Right Speaker PGA" },
  338. { "SPK_LN", NULL, "Left Speaker Output" },
  339. { "SPK_LP", NULL, "Left Speaker Output" },
  340. { "SPK_RN", NULL, "Right Speaker Output" },
  341. { "SPK_RP", NULL, "Right Speaker Output" },
  342. };
  343. static const struct snd_soc_dapm_route audio_paths_out3[] = {
  344. { "Mono Output Mixer", "Left Switch", "Left Output Mixer" },
  345. { "Mono Output Mixer", "Right Switch", "Right Output Mixer" },
  346. { "OUT3", NULL, "Mono Output Mixer", }
  347. };
  348. static const struct snd_soc_dapm_route audio_paths_capless[] = {
  349. { "HP_L", NULL, "OUT3 VMID" },
  350. { "HP_R", NULL, "OUT3 VMID" },
  351. { "OUT3 VMID", NULL, "Left Output Mixer" },
  352. { "OUT3 VMID", NULL, "Right Output Mixer" },
  353. };
  354. static int wm8960_add_widgets(struct snd_soc_codec *codec)
  355. {
  356. struct wm8960_data *pdata = codec->dev->platform_data;
  357. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  358. struct snd_soc_dapm_context *dapm = &codec->dapm;
  359. struct snd_soc_dapm_widget *w;
  360. snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets,
  361. ARRAY_SIZE(wm8960_dapm_widgets));
  362. snd_soc_dapm_add_routes(dapm, audio_paths, ARRAY_SIZE(audio_paths));
  363. /* In capless mode OUT3 is used to provide VMID for the
  364. * headphone outputs, otherwise it is used as a mono mixer.
  365. */
  366. if (pdata && pdata->capless) {
  367. snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_capless,
  368. ARRAY_SIZE(wm8960_dapm_widgets_capless));
  369. snd_soc_dapm_add_routes(dapm, audio_paths_capless,
  370. ARRAY_SIZE(audio_paths_capless));
  371. } else {
  372. snd_soc_dapm_new_controls(dapm, wm8960_dapm_widgets_out3,
  373. ARRAY_SIZE(wm8960_dapm_widgets_out3));
  374. snd_soc_dapm_add_routes(dapm, audio_paths_out3,
  375. ARRAY_SIZE(audio_paths_out3));
  376. }
  377. /* We need to power up the headphone output stage out of
  378. * sequence for capless mode. To save scanning the widget
  379. * list each time to find the desired power state do so now
  380. * and save the result.
  381. */
  382. list_for_each_entry(w, &codec->card->widgets, list) {
  383. if (w->dapm != &codec->dapm)
  384. continue;
  385. if (strcmp(w->name, "LOUT1 PGA") == 0)
  386. wm8960->lout1 = w;
  387. if (strcmp(w->name, "ROUT1 PGA") == 0)
  388. wm8960->rout1 = w;
  389. if (strcmp(w->name, "OUT3 VMID") == 0)
  390. wm8960->out3 = w;
  391. }
  392. return 0;
  393. }
  394. static int wm8960_set_dai_fmt(struct snd_soc_dai *codec_dai,
  395. unsigned int fmt)
  396. {
  397. struct snd_soc_codec *codec = codec_dai->codec;
  398. u16 iface = 0;
  399. /* set master/slave audio interface */
  400. switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
  401. case SND_SOC_DAIFMT_CBM_CFM:
  402. iface |= 0x0040;
  403. break;
  404. case SND_SOC_DAIFMT_CBS_CFS:
  405. break;
  406. default:
  407. return -EINVAL;
  408. }
  409. /* interface format */
  410. switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
  411. case SND_SOC_DAIFMT_I2S:
  412. iface |= 0x0002;
  413. break;
  414. case SND_SOC_DAIFMT_RIGHT_J:
  415. break;
  416. case SND_SOC_DAIFMT_LEFT_J:
  417. iface |= 0x0001;
  418. break;
  419. case SND_SOC_DAIFMT_DSP_A:
  420. iface |= 0x0003;
  421. break;
  422. case SND_SOC_DAIFMT_DSP_B:
  423. iface |= 0x0013;
  424. break;
  425. default:
  426. return -EINVAL;
  427. }
  428. /* clock inversion */
  429. switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
  430. case SND_SOC_DAIFMT_NB_NF:
  431. break;
  432. case SND_SOC_DAIFMT_IB_IF:
  433. iface |= 0x0090;
  434. break;
  435. case SND_SOC_DAIFMT_IB_NF:
  436. iface |= 0x0080;
  437. break;
  438. case SND_SOC_DAIFMT_NB_IF:
  439. iface |= 0x0010;
  440. break;
  441. default:
  442. return -EINVAL;
  443. }
  444. /* set iface */
  445. snd_soc_write(codec, WM8960_IFACE1, iface);
  446. return 0;
  447. }
  448. static struct {
  449. int rate;
  450. unsigned int val;
  451. } alc_rates[] = {
  452. { 48000, 0 },
  453. { 44100, 0 },
  454. { 32000, 1 },
  455. { 22050, 2 },
  456. { 24000, 2 },
  457. { 16000, 3 },
  458. { 11250, 4 },
  459. { 12000, 4 },
  460. { 8000, 5 },
  461. };
  462. static int wm8960_hw_params(struct snd_pcm_substream *substream,
  463. struct snd_pcm_hw_params *params,
  464. struct snd_soc_dai *dai)
  465. {
  466. struct snd_soc_codec *codec = dai->codec;
  467. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  468. u16 iface = snd_soc_read(codec, WM8960_IFACE1) & 0xfff3;
  469. snd_pcm_format_t format = params_format(params);
  470. int i;
  471. /* bit size */
  472. switch (format) {
  473. case SNDRV_PCM_FORMAT_S16_LE:
  474. case SNDRV_PCM_FORMAT_S16_BE:
  475. break;
  476. case SNDRV_PCM_FORMAT_S20_3LE:
  477. case SNDRV_PCM_FORMAT_S20_3BE:
  478. iface |= 0x0004;
  479. break;
  480. case SNDRV_PCM_FORMAT_S24_LE:
  481. case SNDRV_PCM_FORMAT_S24_BE:
  482. iface |= 0x0008;
  483. break;
  484. default:
  485. dev_err(codec->dev, "unsupported format %i\n", format);
  486. return -EINVAL;
  487. }
  488. /* Update filters for the new rate */
  489. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
  490. wm8960->playback_fs = params_rate(params);
  491. wm8960_set_deemph(codec);
  492. } else {
  493. for (i = 0; i < ARRAY_SIZE(alc_rates); i++)
  494. if (alc_rates[i].rate == params_rate(params))
  495. snd_soc_update_bits(codec,
  496. WM8960_ADDCTL3, 0x7,
  497. alc_rates[i].val);
  498. }
  499. /* set iface */
  500. snd_soc_write(codec, WM8960_IFACE1, iface);
  501. return 0;
  502. }
  503. static int wm8960_mute(struct snd_soc_dai *dai, int mute)
  504. {
  505. struct snd_soc_codec *codec = dai->codec;
  506. if (mute)
  507. snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0x8);
  508. else
  509. snd_soc_update_bits(codec, WM8960_DACCTL1, 0x8, 0);
  510. return 0;
  511. }
  512. static int wm8960_set_bias_level_out3(struct snd_soc_codec *codec,
  513. enum snd_soc_bias_level level)
  514. {
  515. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  516. switch (level) {
  517. case SND_SOC_BIAS_ON:
  518. break;
  519. case SND_SOC_BIAS_PREPARE:
  520. /* Set VMID to 2x50k */
  521. snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x80);
  522. break;
  523. case SND_SOC_BIAS_STANDBY:
  524. if (codec->dapm.bias_level == SND_SOC_BIAS_OFF) {
  525. regcache_sync(wm8960->regmap);
  526. /* Enable anti-pop features */
  527. snd_soc_write(codec, WM8960_APOP1,
  528. WM8960_POBCTRL | WM8960_SOFT_ST |
  529. WM8960_BUFDCOPEN | WM8960_BUFIOEN);
  530. /* Enable & ramp VMID at 2x50k */
  531. snd_soc_update_bits(codec, WM8960_POWER1, 0x80, 0x80);
  532. msleep(100);
  533. /* Enable VREF */
  534. snd_soc_update_bits(codec, WM8960_POWER1, WM8960_VREF,
  535. WM8960_VREF);
  536. /* Disable anti-pop features */
  537. snd_soc_write(codec, WM8960_APOP1, WM8960_BUFIOEN);
  538. }
  539. /* Set VMID to 2x250k */
  540. snd_soc_update_bits(codec, WM8960_POWER1, 0x180, 0x100);
  541. break;
  542. case SND_SOC_BIAS_OFF:
  543. /* Enable anti-pop features */
  544. snd_soc_write(codec, WM8960_APOP1,
  545. WM8960_POBCTRL | WM8960_SOFT_ST |
  546. WM8960_BUFDCOPEN | WM8960_BUFIOEN);
  547. /* Disable VMID and VREF, let them discharge */
  548. snd_soc_write(codec, WM8960_POWER1, 0);
  549. msleep(600);
  550. break;
  551. }
  552. codec->dapm.bias_level = level;
  553. return 0;
  554. }
  555. static int wm8960_set_bias_level_capless(struct snd_soc_codec *codec,
  556. enum snd_soc_bias_level level)
  557. {
  558. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  559. int reg;
  560. switch (level) {
  561. case SND_SOC_BIAS_ON:
  562. break;
  563. case SND_SOC_BIAS_PREPARE:
  564. switch (codec->dapm.bias_level) {
  565. case SND_SOC_BIAS_STANDBY:
  566. /* Enable anti pop mode */
  567. snd_soc_update_bits(codec, WM8960_APOP1,
  568. WM8960_POBCTRL | WM8960_SOFT_ST |
  569. WM8960_BUFDCOPEN,
  570. WM8960_POBCTRL | WM8960_SOFT_ST |
  571. WM8960_BUFDCOPEN);
  572. /* Enable LOUT1, ROUT1 and OUT3 if they're enabled */
  573. reg = 0;
  574. if (wm8960->lout1 && wm8960->lout1->power)
  575. reg |= WM8960_PWR2_LOUT1;
  576. if (wm8960->rout1 && wm8960->rout1->power)
  577. reg |= WM8960_PWR2_ROUT1;
  578. if (wm8960->out3 && wm8960->out3->power)
  579. reg |= WM8960_PWR2_OUT3;
  580. snd_soc_update_bits(codec, WM8960_POWER2,
  581. WM8960_PWR2_LOUT1 |
  582. WM8960_PWR2_ROUT1 |
  583. WM8960_PWR2_OUT3, reg);
  584. /* Enable VMID at 2*50k */
  585. snd_soc_update_bits(codec, WM8960_POWER1,
  586. WM8960_VMID_MASK, 0x80);
  587. /* Ramp */
  588. msleep(100);
  589. /* Enable VREF */
  590. snd_soc_update_bits(codec, WM8960_POWER1,
  591. WM8960_VREF, WM8960_VREF);
  592. msleep(100);
  593. break;
  594. case SND_SOC_BIAS_ON:
  595. /* Enable anti-pop mode */
  596. snd_soc_update_bits(codec, WM8960_APOP1,
  597. WM8960_POBCTRL | WM8960_SOFT_ST |
  598. WM8960_BUFDCOPEN,
  599. WM8960_POBCTRL | WM8960_SOFT_ST |
  600. WM8960_BUFDCOPEN);
  601. /* Disable VMID and VREF */
  602. snd_soc_update_bits(codec, WM8960_POWER1,
  603. WM8960_VREF | WM8960_VMID_MASK, 0);
  604. break;
  605. case SND_SOC_BIAS_OFF:
  606. regcache_sync(wm8960->regmap);
  607. break;
  608. default:
  609. break;
  610. }
  611. break;
  612. case SND_SOC_BIAS_STANDBY:
  613. switch (codec->dapm.bias_level) {
  614. case SND_SOC_BIAS_PREPARE:
  615. /* Disable HP discharge */
  616. snd_soc_update_bits(codec, WM8960_APOP2,
  617. WM8960_DISOP | WM8960_DRES_MASK,
  618. 0);
  619. /* Disable anti-pop features */
  620. snd_soc_update_bits(codec, WM8960_APOP1,
  621. WM8960_POBCTRL | WM8960_SOFT_ST |
  622. WM8960_BUFDCOPEN,
  623. WM8960_POBCTRL | WM8960_SOFT_ST |
  624. WM8960_BUFDCOPEN);
  625. break;
  626. default:
  627. break;
  628. }
  629. break;
  630. case SND_SOC_BIAS_OFF:
  631. break;
  632. }
  633. codec->dapm.bias_level = level;
  634. return 0;
  635. }
  636. /* PLL divisors */
  637. struct _pll_div {
  638. u32 pre_div:1;
  639. u32 n:4;
  640. u32 k:24;
  641. };
  642. /* The size in bits of the pll divide multiplied by 10
  643. * to allow rounding later */
  644. #define FIXED_PLL_SIZE ((1 << 24) * 10)
  645. static int pll_factors(unsigned int source, unsigned int target,
  646. struct _pll_div *pll_div)
  647. {
  648. unsigned long long Kpart;
  649. unsigned int K, Ndiv, Nmod;
  650. pr_debug("WM8960 PLL: setting %dHz->%dHz\n", source, target);
  651. /* Scale up target to PLL operating frequency */
  652. target *= 4;
  653. Ndiv = target / source;
  654. if (Ndiv < 6) {
  655. source >>= 1;
  656. pll_div->pre_div = 1;
  657. Ndiv = target / source;
  658. } else
  659. pll_div->pre_div = 0;
  660. if ((Ndiv < 6) || (Ndiv > 12)) {
  661. pr_err("WM8960 PLL: Unsupported N=%d\n", Ndiv);
  662. return -EINVAL;
  663. }
  664. pll_div->n = Ndiv;
  665. Nmod = target % source;
  666. Kpart = FIXED_PLL_SIZE * (long long)Nmod;
  667. do_div(Kpart, source);
  668. K = Kpart & 0xFFFFFFFF;
  669. /* Check if we need to round */
  670. if ((K % 10) >= 5)
  671. K += 5;
  672. /* Move down to proper range now rounding is done */
  673. K /= 10;
  674. pll_div->k = K;
  675. pr_debug("WM8960 PLL: N=%x K=%x pre_div=%d\n",
  676. pll_div->n, pll_div->k, pll_div->pre_div);
  677. return 0;
  678. }
  679. static int wm8960_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id,
  680. int source, unsigned int freq_in, unsigned int freq_out)
  681. {
  682. struct snd_soc_codec *codec = codec_dai->codec;
  683. u16 reg;
  684. static struct _pll_div pll_div;
  685. int ret;
  686. if (freq_in && freq_out) {
  687. ret = pll_factors(freq_in, freq_out, &pll_div);
  688. if (ret != 0)
  689. return ret;
  690. }
  691. /* Disable the PLL: even if we are changing the frequency the
  692. * PLL needs to be disabled while we do so. */
  693. snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0);
  694. snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0);
  695. if (!freq_in || !freq_out)
  696. return 0;
  697. reg = snd_soc_read(codec, WM8960_PLL1) & ~0x3f;
  698. reg |= pll_div.pre_div << 4;
  699. reg |= pll_div.n;
  700. if (pll_div.k) {
  701. reg |= 0x20;
  702. snd_soc_write(codec, WM8960_PLL2, (pll_div.k >> 18) & 0x3f);
  703. snd_soc_write(codec, WM8960_PLL3, (pll_div.k >> 9) & 0x1ff);
  704. snd_soc_write(codec, WM8960_PLL4, pll_div.k & 0x1ff);
  705. }
  706. snd_soc_write(codec, WM8960_PLL1, reg);
  707. /* Turn it on */
  708. snd_soc_update_bits(codec, WM8960_POWER2, 0x1, 0x1);
  709. msleep(250);
  710. snd_soc_update_bits(codec, WM8960_CLOCK1, 0x1, 0x1);
  711. return 0;
  712. }
  713. static int wm8960_set_dai_clkdiv(struct snd_soc_dai *codec_dai,
  714. int div_id, int div)
  715. {
  716. struct snd_soc_codec *codec = codec_dai->codec;
  717. u16 reg;
  718. switch (div_id) {
  719. case WM8960_SYSCLKDIV:
  720. reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1f9;
  721. snd_soc_write(codec, WM8960_CLOCK1, reg | div);
  722. break;
  723. case WM8960_DACDIV:
  724. reg = snd_soc_read(codec, WM8960_CLOCK1) & 0x1c7;
  725. snd_soc_write(codec, WM8960_CLOCK1, reg | div);
  726. break;
  727. case WM8960_OPCLKDIV:
  728. reg = snd_soc_read(codec, WM8960_PLL1) & 0x03f;
  729. snd_soc_write(codec, WM8960_PLL1, reg | div);
  730. break;
  731. case WM8960_DCLKDIV:
  732. reg = snd_soc_read(codec, WM8960_CLOCK2) & 0x03f;
  733. snd_soc_write(codec, WM8960_CLOCK2, reg | div);
  734. break;
  735. case WM8960_TOCLKSEL:
  736. reg = snd_soc_read(codec, WM8960_ADDCTL1) & 0x1fd;
  737. snd_soc_write(codec, WM8960_ADDCTL1, reg | div);
  738. break;
  739. default:
  740. return -EINVAL;
  741. }
  742. return 0;
  743. }
  744. static int wm8960_set_bias_level(struct snd_soc_codec *codec,
  745. enum snd_soc_bias_level level)
  746. {
  747. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  748. return wm8960->set_bias_level(codec, level);
  749. }
  750. #define WM8960_RATES SNDRV_PCM_RATE_8000_48000
  751. #define WM8960_FORMATS \
  752. (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
  753. SNDRV_PCM_FMTBIT_S24_LE)
  754. static const struct snd_soc_dai_ops wm8960_dai_ops = {
  755. .hw_params = wm8960_hw_params,
  756. .digital_mute = wm8960_mute,
  757. .set_fmt = wm8960_set_dai_fmt,
  758. .set_clkdiv = wm8960_set_dai_clkdiv,
  759. .set_pll = wm8960_set_dai_pll,
  760. };
  761. static struct snd_soc_dai_driver wm8960_dai = {
  762. .name = "wm8960-hifi",
  763. .playback = {
  764. .stream_name = "Playback",
  765. .channels_min = 1,
  766. .channels_max = 2,
  767. .rates = WM8960_RATES,
  768. .formats = WM8960_FORMATS,},
  769. .capture = {
  770. .stream_name = "Capture",
  771. .channels_min = 1,
  772. .channels_max = 2,
  773. .rates = WM8960_RATES,
  774. .formats = WM8960_FORMATS,},
  775. .ops = &wm8960_dai_ops,
  776. .symmetric_rates = 1,
  777. };
  778. static int wm8960_suspend(struct snd_soc_codec *codec)
  779. {
  780. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  781. wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF);
  782. return 0;
  783. }
  784. static int wm8960_resume(struct snd_soc_codec *codec)
  785. {
  786. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  787. wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  788. return 0;
  789. }
  790. static int wm8960_probe(struct snd_soc_codec *codec)
  791. {
  792. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  793. struct wm8960_data *pdata = dev_get_platdata(codec->dev);
  794. int ret;
  795. wm8960->set_bias_level = wm8960_set_bias_level_out3;
  796. if (!pdata) {
  797. dev_warn(codec->dev, "No platform data supplied\n");
  798. } else {
  799. if (pdata->capless)
  800. wm8960->set_bias_level = wm8960_set_bias_level_capless;
  801. }
  802. ret = snd_soc_codec_set_cache_io(codec, 7, 9, SND_SOC_REGMAP);
  803. if (ret < 0) {
  804. dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
  805. return ret;
  806. }
  807. ret = wm8960_reset(codec);
  808. if (ret < 0) {
  809. dev_err(codec->dev, "Failed to issue reset\n");
  810. return ret;
  811. }
  812. wm8960->set_bias_level(codec, SND_SOC_BIAS_STANDBY);
  813. /* Latch the update bits */
  814. snd_soc_update_bits(codec, WM8960_LINVOL, 0x100, 0x100);
  815. snd_soc_update_bits(codec, WM8960_RINVOL, 0x100, 0x100);
  816. snd_soc_update_bits(codec, WM8960_LADC, 0x100, 0x100);
  817. snd_soc_update_bits(codec, WM8960_RADC, 0x100, 0x100);
  818. snd_soc_update_bits(codec, WM8960_LDAC, 0x100, 0x100);
  819. snd_soc_update_bits(codec, WM8960_RDAC, 0x100, 0x100);
  820. snd_soc_update_bits(codec, WM8960_LOUT1, 0x100, 0x100);
  821. snd_soc_update_bits(codec, WM8960_ROUT1, 0x100, 0x100);
  822. snd_soc_update_bits(codec, WM8960_LOUT2, 0x100, 0x100);
  823. snd_soc_update_bits(codec, WM8960_ROUT2, 0x100, 0x100);
  824. snd_soc_add_codec_controls(codec, wm8960_snd_controls,
  825. ARRAY_SIZE(wm8960_snd_controls));
  826. wm8960_add_widgets(codec);
  827. return 0;
  828. }
  829. /* power down chip */
  830. static int wm8960_remove(struct snd_soc_codec *codec)
  831. {
  832. struct wm8960_priv *wm8960 = snd_soc_codec_get_drvdata(codec);
  833. wm8960->set_bias_level(codec, SND_SOC_BIAS_OFF);
  834. return 0;
  835. }
  836. static struct snd_soc_codec_driver soc_codec_dev_wm8960 = {
  837. .probe = wm8960_probe,
  838. .remove = wm8960_remove,
  839. .suspend = wm8960_suspend,
  840. .resume = wm8960_resume,
  841. .set_bias_level = wm8960_set_bias_level,
  842. };
  843. static const struct regmap_config wm8960_regmap = {
  844. .reg_bits = 7,
  845. .val_bits = 9,
  846. .max_register = WM8960_PLL4,
  847. .reg_defaults = wm8960_reg_defaults,
  848. .num_reg_defaults = ARRAY_SIZE(wm8960_reg_defaults),
  849. .cache_type = REGCACHE_RBTREE,
  850. .volatile_reg = wm8960_volatile,
  851. };
  852. static int wm8960_i2c_probe(struct i2c_client *i2c,
  853. const struct i2c_device_id *id)
  854. {
  855. struct wm8960_data *pdata = dev_get_platdata(&i2c->dev);
  856. struct wm8960_priv *wm8960;
  857. int ret;
  858. wm8960 = devm_kzalloc(&i2c->dev, sizeof(struct wm8960_priv),
  859. GFP_KERNEL);
  860. if (wm8960 == NULL)
  861. return -ENOMEM;
  862. wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap);
  863. if (IS_ERR(wm8960->regmap))
  864. return PTR_ERR(wm8960->regmap);
  865. if (pdata && pdata->shared_lrclk) {
  866. ret = regmap_update_bits(wm8960->regmap, WM8960_ADDCTL2,
  867. 0x4, 0x4);
  868. if (ret != 0) {
  869. dev_err(&i2c->dev, "Failed to enable LRCM: %d\n",
  870. ret);
  871. return ret;
  872. }
  873. }
  874. i2c_set_clientdata(i2c, wm8960);
  875. ret = snd_soc_register_codec(&i2c->dev,
  876. &soc_codec_dev_wm8960, &wm8960_dai, 1);
  877. return ret;
  878. }
  879. static int wm8960_i2c_remove(struct i2c_client *client)
  880. {
  881. snd_soc_unregister_codec(&client->dev);
  882. return 0;
  883. }
  884. static const struct i2c_device_id wm8960_i2c_id[] = {
  885. { "wm8960", 0 },
  886. { }
  887. };
  888. MODULE_DEVICE_TABLE(i2c, wm8960_i2c_id);
  889. static struct i2c_driver wm8960_i2c_driver = {
  890. .driver = {
  891. .name = "wm8960",
  892. .owner = THIS_MODULE,
  893. },
  894. .probe = wm8960_i2c_probe,
  895. .remove = wm8960_i2c_remove,
  896. .id_table = wm8960_i2c_id,
  897. };
  898. module_i2c_driver(wm8960_i2c_driver);
  899. MODULE_DESCRIPTION("ASoC WM8960 driver");
  900. MODULE_AUTHOR("Liam Girdwood");
  901. MODULE_LICENSE("GPL");