bf5xx-ad73311.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. /*
  2. * File: sound/soc/blackfin/bf5xx-ad73311.c
  3. * Author: Cliff Cai <Cliff.Cai@analog.com>
  4. *
  5. * Created: Thur Sep 25 2008
  6. * Description: Board driver for ad73311 sound chip
  7. *
  8. * Modified:
  9. * Copyright 2008 Analog Devices Inc.
  10. *
  11. * Bugs: Enter bugs at http://blackfin.uclinux.org/
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, see the file COPYING, or write
  25. * to the Free Software Foundation, Inc.,
  26. * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  27. */
  28. #include <linux/module.h>
  29. #include <linux/moduleparam.h>
  30. #include <linux/device.h>
  31. #include <linux/delay.h>
  32. #include <linux/gpio.h>
  33. #include <sound/core.h>
  34. #include <sound/pcm.h>
  35. #include <sound/soc.h>
  36. #include <sound/pcm_params.h>
  37. #include <asm/blackfin.h>
  38. #include <asm/cacheflush.h>
  39. #include <asm/irq.h>
  40. #include <asm/dma.h>
  41. #include <asm/portmux.h>
  42. #include "../codecs/ad73311.h"
  43. #include "bf5xx-sport.h"
  44. #if CONFIG_SND_BF5XX_SPORT_NUM == 0
  45. #define bfin_write_SPORT_TCR1 bfin_write_SPORT0_TCR1
  46. #define bfin_read_SPORT_TCR1 bfin_read_SPORT0_TCR1
  47. #define bfin_write_SPORT_TCR2 bfin_write_SPORT0_TCR2
  48. #define bfin_write_SPORT_TX16 bfin_write_SPORT0_TX16
  49. #define bfin_read_SPORT_STAT bfin_read_SPORT0_STAT
  50. #else
  51. #define bfin_write_SPORT_TCR1 bfin_write_SPORT1_TCR1
  52. #define bfin_read_SPORT_TCR1 bfin_read_SPORT1_TCR1
  53. #define bfin_write_SPORT_TCR2 bfin_write_SPORT1_TCR2
  54. #define bfin_write_SPORT_TX16 bfin_write_SPORT1_TX16
  55. #define bfin_read_SPORT_STAT bfin_read_SPORT1_STAT
  56. #endif
  57. #define GPIO_SE CONFIG_SND_BFIN_AD73311_SE
  58. static struct snd_soc_card bf5xx_ad73311;
  59. static int snd_ad73311_startup(void)
  60. {
  61. pr_debug("%s enter\n", __func__);
  62. /* Pull up SE pin on AD73311L */
  63. gpio_set_value(GPIO_SE, 1);
  64. return 0;
  65. }
  66. static int snd_ad73311_configure(void)
  67. {
  68. unsigned short ctrl_regs[6];
  69. unsigned short status = 0;
  70. int count = 0;
  71. /* DMCLK = MCLK = 16.384 MHz
  72. * SCLK = DMCLK/8 = 2.048 MHz
  73. * Sample Rate = DMCLK/2048 = 8 KHz
  74. */
  75. ctrl_regs[0] = AD_CONTROL | AD_WRITE | CTRL_REG_B | REGB_MCDIV(0) | \
  76. REGB_SCDIV(0) | REGB_DIRATE(0);
  77. ctrl_regs[1] = AD_CONTROL | AD_WRITE | CTRL_REG_C | REGC_PUDEV | \
  78. REGC_PUADC | REGC_PUDAC | REGC_PUREF | REGC_REFUSE ;
  79. ctrl_regs[2] = AD_CONTROL | AD_WRITE | CTRL_REG_D | REGD_OGS(2) | \
  80. REGD_IGS(2);
  81. ctrl_regs[3] = AD_CONTROL | AD_WRITE | CTRL_REG_E | REGE_DA(0x1f);
  82. ctrl_regs[4] = AD_CONTROL | AD_WRITE | CTRL_REG_F | REGF_SEEN ;
  83. ctrl_regs[5] = AD_CONTROL | AD_WRITE | CTRL_REG_A | REGA_MODE_DATA;
  84. local_irq_disable();
  85. snd_ad73311_startup();
  86. udelay(1);
  87. bfin_write_SPORT_TCR1(TFSR);
  88. bfin_write_SPORT_TCR2(0xF);
  89. SSYNC();
  90. /* SPORT Tx Register is a 8 x 16 FIFO, all the data can be put to
  91. * FIFO before enable SPORT to transfer the data
  92. */
  93. for (count = 0; count < 6; count++)
  94. bfin_write_SPORT_TX16(ctrl_regs[count]);
  95. SSYNC();
  96. bfin_write_SPORT_TCR1(bfin_read_SPORT_TCR1() | TSPEN);
  97. SSYNC();
  98. /* When TUVF is set, the data is already send out */
  99. while (!(status & TUVF) && ++count < 10000) {
  100. udelay(1);
  101. status = bfin_read_SPORT_STAT();
  102. SSYNC();
  103. }
  104. bfin_write_SPORT_TCR1(bfin_read_SPORT_TCR1() & ~TSPEN);
  105. SSYNC();
  106. local_irq_enable();
  107. if (count >= 10000) {
  108. printk(KERN_ERR "ad73311: failed to configure codec\n");
  109. return -1;
  110. }
  111. return 0;
  112. }
  113. static int bf5xx_probe(struct snd_soc_card *card)
  114. {
  115. int err;
  116. if (gpio_request(GPIO_SE, "AD73311_SE")) {
  117. printk(KERN_ERR "%s: Failed ro request GPIO_%d\n", __func__, GPIO_SE);
  118. return -EBUSY;
  119. }
  120. gpio_direction_output(GPIO_SE, 0);
  121. err = snd_ad73311_configure();
  122. if (err < 0)
  123. return -EFAULT;
  124. return 0;
  125. }
  126. #define BF5XX_AD7311_DAI_FMT (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF | \
  127. SND_SOC_DAIFMT_CBM_CFM)
  128. static struct snd_soc_dai_link bf5xx_ad73311_dai[] = {
  129. {
  130. .name = "ad73311",
  131. .stream_name = "AD73311",
  132. .cpu_dai_name = "bfin-i2s.0",
  133. .codec_dai_name = "ad73311-hifi",
  134. .platform_name = "bfin-i2s-pcm-audio",
  135. .codec_name = "ad73311",
  136. .dai_fmt = BF5XX_AD7311_DAI_FMT,
  137. },
  138. {
  139. .name = "ad73311",
  140. .stream_name = "AD73311",
  141. .cpu_dai_name = "bfin-i2s.1",
  142. .codec_dai_name = "ad73311-hifi",
  143. .platform_name = "bfin-i2s-pcm-audio",
  144. .codec_name = "ad73311",
  145. .dai_fmt = BF5XX_AD7311_DAI_FMT,
  146. },
  147. };
  148. static struct snd_soc_card bf5xx_ad73311 = {
  149. .name = "bfin-ad73311",
  150. .owner = THIS_MODULE,
  151. .probe = bf5xx_probe,
  152. .dai_link = &bf5xx_ad73311_dai[CONFIG_SND_BF5XX_SPORT_NUM],
  153. .num_links = 1,
  154. };
  155. static struct platform_device *bf5xx_ad73311_snd_device;
  156. static int __init bf5xx_ad73311_init(void)
  157. {
  158. int ret;
  159. pr_debug("%s enter\n", __func__);
  160. bf5xx_ad73311_snd_device = platform_device_alloc("soc-audio", -1);
  161. if (!bf5xx_ad73311_snd_device)
  162. return -ENOMEM;
  163. platform_set_drvdata(bf5xx_ad73311_snd_device, &bf5xx_ad73311);
  164. ret = platform_device_add(bf5xx_ad73311_snd_device);
  165. if (ret)
  166. platform_device_put(bf5xx_ad73311_snd_device);
  167. return ret;
  168. }
  169. static void __exit bf5xx_ad73311_exit(void)
  170. {
  171. pr_debug("%s enter\n", __func__);
  172. platform_device_unregister(bf5xx_ad73311_snd_device);
  173. }
  174. module_init(bf5xx_ad73311_init);
  175. module_exit(bf5xx_ad73311_exit);
  176. /* Module information */
  177. MODULE_AUTHOR("Cliff Cai");
  178. MODULE_DESCRIPTION("ALSA SoC AD73311 Blackfin");
  179. MODULE_LICENSE("GPL");