wm8960.c 29 KB

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