wm8960.c 29 KB

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