spitz.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. /*
  2. * spitz.c -- SoC audio for Sharp SL-Cxx00 models Spitz, Borzoi and Akita
  3. *
  4. * Copyright 2005 Wolfson Microelectronics PLC.
  5. * Copyright 2005 Openedhand Ltd.
  6. *
  7. * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
  8. * Richard Purdie <richard@openedhand.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. * Revision history
  16. * 30th Nov 2005 Initial version.
  17. *
  18. */
  19. #include <linux/module.h>
  20. #include <linux/moduleparam.h>
  21. #include <linux/timer.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/platform_device.h>
  24. #include <sound/driver.h>
  25. #include <sound/core.h>
  26. #include <sound/pcm.h>
  27. #include <sound/soc.h>
  28. #include <sound/soc-dapm.h>
  29. #include <asm/mach-types.h>
  30. #include <asm/hardware/scoop.h>
  31. #include <asm/arch/pxa-regs.h>
  32. #include <asm/arch/hardware.h>
  33. #include <asm/arch/akita.h>
  34. #include <asm/arch/spitz.h>
  35. #include <asm/mach-types.h>
  36. #include "../codecs/wm8750.h"
  37. #include "pxa2xx-pcm.h"
  38. #define SPITZ_HP 0
  39. #define SPITZ_MIC 1
  40. #define SPITZ_LINE 2
  41. #define SPITZ_HEADSET 3
  42. #define SPITZ_HP_OFF 4
  43. #define SPITZ_SPK_ON 0
  44. #define SPITZ_SPK_OFF 1
  45. /* audio clock in Hz - rounded from 12.235MHz */
  46. #define SPITZ_AUDIO_CLOCK 12288000
  47. static int spitz_jack_func;
  48. static int spitz_spk_func;
  49. static void spitz_ext_control(struct snd_soc_codec *codec)
  50. {
  51. if (spitz_spk_func == SPITZ_SPK_ON)
  52. snd_soc_dapm_set_endpoint(codec, "Ext Spk", 1);
  53. else
  54. snd_soc_dapm_set_endpoint(codec, "Ext Spk", 0);
  55. /* set up jack connection */
  56. switch (spitz_jack_func) {
  57. case SPITZ_HP:
  58. /* enable and unmute hp jack, disable mic bias */
  59. snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
  60. snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
  61. snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
  62. snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
  63. set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
  64. set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
  65. break;
  66. case SPITZ_MIC:
  67. /* enable mic jack and bias, mute hp */
  68. snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
  69. snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
  70. snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
  71. snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
  72. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
  73. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
  74. break;
  75. case SPITZ_LINE:
  76. /* enable line jack, disable mic bias and mute hp */
  77. snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
  78. snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
  79. snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
  80. snd_soc_dapm_set_endpoint(codec, "Line Jack", 1);
  81. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
  82. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
  83. break;
  84. case SPITZ_HEADSET:
  85. /* enable and unmute headset jack enable mic bias, mute L hp */
  86. snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
  87. snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
  88. snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
  89. snd_soc_dapm_set_endpoint(codec, "Headset Jack", 1);
  90. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
  91. set_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
  92. break;
  93. case SPITZ_HP_OFF:
  94. /* jack removed, everything off */
  95. snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 0);
  96. snd_soc_dapm_set_endpoint(codec, "Headset Jack", 0);
  97. snd_soc_dapm_set_endpoint(codec, "Mic Jack", 0);
  98. snd_soc_dapm_set_endpoint(codec, "Line Jack", 0);
  99. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_L);
  100. reset_scoop_gpio(&spitzscoop_device.dev, SPITZ_SCP_MUTE_R);
  101. break;
  102. }
  103. snd_soc_dapm_sync_endpoints(codec);
  104. }
  105. static int spitz_startup(struct snd_pcm_substream *substream)
  106. {
  107. struct snd_soc_pcm_runtime *rtd = substream->private_data;
  108. struct snd_soc_codec *codec = rtd->socdev->codec;
  109. /* check the jack status at stream startup */
  110. spitz_ext_control(codec);
  111. return 0;
  112. }
  113. static struct snd_soc_ops spitz_ops = {
  114. .startup = spitz_startup,
  115. };
  116. static int spitz_get_jack(struct snd_kcontrol *kcontrol,
  117. struct snd_ctl_elem_value *ucontrol)
  118. {
  119. ucontrol->value.integer.value[0] = spitz_jack_func;
  120. return 0;
  121. }
  122. static int spitz_set_jack(struct snd_kcontrol *kcontrol,
  123. struct snd_ctl_elem_value *ucontrol)
  124. {
  125. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  126. if (spitz_jack_func == ucontrol->value.integer.value[0])
  127. return 0;
  128. spitz_jack_func = ucontrol->value.integer.value[0];
  129. spitz_ext_control(codec);
  130. return 1;
  131. }
  132. static int spitz_get_spk(struct snd_kcontrol *kcontrol,
  133. struct snd_ctl_elem_value *ucontrol)
  134. {
  135. ucontrol->value.integer.value[0] = spitz_spk_func;
  136. return 0;
  137. }
  138. static int spitz_set_spk(struct snd_kcontrol *kcontrol,
  139. struct snd_ctl_elem_value *ucontrol)
  140. {
  141. struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
  142. if (spitz_spk_func == ucontrol->value.integer.value[0])
  143. return 0;
  144. spitz_spk_func = ucontrol->value.integer.value[0];
  145. spitz_ext_control(codec);
  146. return 1;
  147. }
  148. static int spitz_mic_bias(struct snd_soc_dapm_widget *w, int event)
  149. {
  150. if (machine_is_borzoi() || machine_is_spitz()) {
  151. if (SND_SOC_DAPM_EVENT_ON(event))
  152. set_scoop_gpio(&spitzscoop2_device.dev,
  153. SPITZ_SCP2_MIC_BIAS);
  154. else
  155. reset_scoop_gpio(&spitzscoop2_device.dev,
  156. SPITZ_SCP2_MIC_BIAS);
  157. }
  158. if (machine_is_akita()) {
  159. if (SND_SOC_DAPM_EVENT_ON(event))
  160. akita_set_ioexp(&akitaioexp_device.dev,
  161. AKITA_IOEXP_MIC_BIAS);
  162. else
  163. akita_reset_ioexp(&akitaioexp_device.dev,
  164. AKITA_IOEXP_MIC_BIAS);
  165. }
  166. return 0;
  167. }
  168. /* spitz machine dapm widgets */
  169. static const struct snd_soc_dapm_widget wm8750_dapm_widgets[] = {
  170. SND_SOC_DAPM_HP("Headphone Jack", NULL),
  171. SND_SOC_DAPM_MIC("Mic Jack", spitz_mic_bias),
  172. SND_SOC_DAPM_SPK("Ext Spk", NULL),
  173. SND_SOC_DAPM_LINE("Line Jack", NULL),
  174. /* headset is a mic and mono headphone */
  175. SND_SOC_DAPM_HP("Headset Jack", NULL),
  176. };
  177. /* Spitz machine audio_map */
  178. static const char *audio_map[][3] = {
  179. /* headphone connected to LOUT1, ROUT1 */
  180. {"Headphone Jack", NULL, "LOUT1"},
  181. {"Headphone Jack", NULL, "ROUT1"},
  182. /* headset connected to ROUT1 and LINPUT1 with bias (def below) */
  183. {"Headset Jack", NULL, "ROUT1"},
  184. /* ext speaker connected to LOUT2, ROUT2 */
  185. {"Ext Spk", NULL , "ROUT2"},
  186. {"Ext Spk", NULL , "LOUT2"},
  187. /* mic is connected to input 1 - with bias */
  188. {"LINPUT1", NULL, "Mic Bias"},
  189. {"Mic Bias", NULL, "Mic Jack"},
  190. /* line is connected to input 1 - no bias */
  191. {"LINPUT1", NULL, "Line Jack"},
  192. {NULL, NULL, NULL},
  193. };
  194. static const char *jack_function[] = {"Headphone", "Mic", "Line", "Headset",
  195. "Off"};
  196. static const char *spk_function[] = {"On", "Off"};
  197. static const struct soc_enum spitz_enum[] = {
  198. SOC_ENUM_SINGLE_EXT(5, jack_function),
  199. SOC_ENUM_SINGLE_EXT(2, spk_function),
  200. };
  201. static const struct snd_kcontrol_new wm8750_spitz_controls[] = {
  202. SOC_ENUM_EXT("Jack Function", spitz_enum[0], spitz_get_jack,
  203. spitz_set_jack),
  204. SOC_ENUM_EXT("Speaker Function", spitz_enum[1], spitz_get_spk,
  205. spitz_set_spk),
  206. };
  207. /*
  208. * Logic for a wm8750 as connected on a Sharp SL-Cxx00 Device
  209. */
  210. static int spitz_wm8750_init(struct snd_soc_codec *codec)
  211. {
  212. int i, err;
  213. /* NC codec pins */
  214. snd_soc_dapm_set_endpoint(codec, "RINPUT1", 0);
  215. snd_soc_dapm_set_endpoint(codec, "LINPUT2", 0);
  216. snd_soc_dapm_set_endpoint(codec, "RINPUT2", 0);
  217. snd_soc_dapm_set_endpoint(codec, "LINPUT3", 0);
  218. snd_soc_dapm_set_endpoint(codec, "RINPUT3", 0);
  219. snd_soc_dapm_set_endpoint(codec, "OUT3", 0);
  220. snd_soc_dapm_set_endpoint(codec, "MONO", 0);
  221. /* Add spitz specific controls */
  222. for (i = 0; i < ARRAY_SIZE(wm8750_spitz_controls); i++) {
  223. err = snd_ctl_add(codec->card,
  224. snd_soc_cnew(&wm8750_spitz_controls[i], codec, NULL));
  225. if (err < 0)
  226. return err;
  227. }
  228. /* Add spitz specific widgets */
  229. for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) {
  230. snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
  231. }
  232. /* Set up spitz specific audio path audio_map */
  233. for (i = 0; audio_map[i][0] != NULL; i++) {
  234. snd_soc_dapm_connect_input(codec, audio_map[i][0],
  235. audio_map[i][1], audio_map[i][2]);
  236. }
  237. snd_soc_dapm_sync_endpoints(codec);
  238. return 0;
  239. }
  240. static unsigned int spitz_config_sysclk(struct snd_soc_pcm_runtime *rtd,
  241. struct snd_soc_clock_info *info)
  242. {
  243. if (info->bclk_master & SND_SOC_DAIFMT_CBS_CFS) {
  244. /* pxa2xx is i2s master */
  245. switch (info->rate) {
  246. case 11025:
  247. case 22050:
  248. case 44100:
  249. case 88200:
  250. /* configure codec digital filters
  251. * for 11.025, 22.05, 44.1, 88.2 */
  252. rtd->codec_dai->config_sysclk(rtd->codec_dai, info,
  253. 11289600);
  254. break;
  255. default:
  256. /* configure codec digital filters for all other rates */
  257. rtd->codec_dai->config_sysclk(rtd->codec_dai, info,
  258. SPITZ_AUDIO_CLOCK);
  259. break;
  260. }
  261. /* configure pxa2xx i2s interface clocks as master */
  262. return rtd->cpu_dai->config_sysclk(rtd->cpu_dai, info,
  263. SPITZ_AUDIO_CLOCK);
  264. } else {
  265. /* codec is i2s master - only configure codec DAI clock */
  266. return rtd->codec_dai->config_sysclk(rtd->codec_dai, info,
  267. SPITZ_AUDIO_CLOCK);
  268. }
  269. }
  270. /* spitz digital audio interface glue - connects codec <--> CPU */
  271. static struct snd_soc_dai_link spitz_dai = {
  272. .name = "wm8750",
  273. .stream_name = "WM8750",
  274. .cpu_dai = &pxa_i2s_dai,
  275. .codec_dai = &wm8750_dai,
  276. .init = spitz_wm8750_init,
  277. .config_sysclk = spitz_config_sysclk,
  278. };
  279. /* spitz audio machine driver */
  280. static struct snd_soc_machine snd_soc_machine_spitz = {
  281. .name = "Spitz",
  282. .dai_link = &spitz_dai,
  283. .num_links = 1,
  284. .ops = &spitz_ops,
  285. };
  286. /* spitz audio private data */
  287. static struct wm8750_setup_data spitz_wm8750_setup = {
  288. .i2c_address = 0x1b,
  289. };
  290. /* spitz audio subsystem */
  291. static struct snd_soc_device spitz_snd_devdata = {
  292. .machine = &snd_soc_machine_spitz,
  293. .platform = &pxa2xx_soc_platform,
  294. .codec_dev = &soc_codec_dev_wm8750,
  295. .codec_data = &spitz_wm8750_setup,
  296. };
  297. static struct platform_device *spitz_snd_device;
  298. static int __init spitz_init(void)
  299. {
  300. int ret;
  301. if (!(machine_is_spitz() || machine_is_borzoi() || machine_is_akita()))
  302. return -ENODEV;
  303. spitz_snd_device = platform_device_alloc("soc-audio", -1);
  304. if (!spitz_snd_device)
  305. return -ENOMEM;
  306. platform_set_drvdata(spitz_snd_device, &spitz_snd_devdata);
  307. spitz_snd_devdata.dev = &spitz_snd_device->dev;
  308. ret = platform_device_add(spitz_snd_device);
  309. if (ret)
  310. platform_device_put(spitz_snd_device);
  311. return ret;
  312. }
  313. static void __exit spitz_exit(void)
  314. {
  315. platform_device_unregister(spitz_snd_device);
  316. }
  317. module_init(spitz_init);
  318. module_exit(spitz_exit);
  319. MODULE_AUTHOR("Richard Purdie");
  320. MODULE_DESCRIPTION("ALSA SoC Spitz");
  321. MODULE_LICENSE("GPL");