Advertisement
Guest User

dfl61-wl1273.c

a guest
Aug 6th, 2011
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.12 KB | None | 0 0
  1. /*
  2.  * dfl61-wl1273.c -- SoC audio for WL1273 on Nokia DFL61 class devices
  3.  *
  4.  * Author: Matti Aaltonen <matti.j.aaltonen@nokia.com>
  5.  *
  6.  * Copyright:   (C) 2010 Nokia Corporation
  7.  *
  8.  * This program is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU General Public License
  10.  * version 2 as published by the Free Software Foundation.
  11.  *
  12.  * This program is distributed in the hope that it will be useful, but
  13.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.  * General Public License for more details.
  16.  *
  17.  * You should have received a copy of the GNU General Public License
  18.  * along with this program; if not, write to the Free Software
  19.  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  20.  * 02110-1301 USA
  21.  *
  22.  */
  23.  
  24. #include <sound/soc.h>
  25. #include <asm/mach-types.h>
  26. #include <plat/dfl61-audio.h>
  27. #include <plat/mcbsp.h>
  28.  
  29. #include "omap-mcbsp.h"
  30. #include "omap-pcm.h"
  31. #include "../codecs/wl1273.h"
  32.  
  33. static int dfl61wl1273_startup(struct snd_pcm_substream *substream)
  34. {
  35.     struct snd_soc_pcm_runtime *rtd = substream->private_data;
  36.     struct snd_soc_device *socdev = rtd->socdev;
  37.     struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
  38.     struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
  39.     struct snd_soc_codec *codec = socdev->card->codec;
  40.     unsigned int fmt;
  41.     int r;
  42.  
  43.     switch (wl1273_get_codec_mode(codec)) {
  44.     case WL1273_MODE_FM_RX:
  45.     case WL1273_MODE_FM_TX:
  46.         fmt =   SND_SOC_DAIFMT_I2S |
  47.             SND_SOC_DAIFMT_NB_NF |
  48.             SND_SOC_DAIFMT_CBM_CFM;
  49.  
  50.         break;
  51.     case WL1273_MODE_BT:
  52.         fmt =   SND_SOC_DAIFMT_DSP_A |
  53.             SND_SOC_DAIFMT_IB_NF |
  54.             SND_SOC_DAIFMT_CBM_CFM;
  55.  
  56.         break;
  57.     default:
  58.         return -EINVAL;
  59.     }
  60.  
  61.     /* Set codec DAI configuration */
  62.     r = snd_soc_dai_set_fmt(codec_dai, fmt);
  63.     if (r < 0) {
  64.         pr_err("Can't set codec DAI configuration: %d\n", r);
  65.         return r;
  66.     }
  67.  
  68.     /* Set cpu DAI configuration */
  69.     r = snd_soc_dai_set_fmt(cpu_dai, fmt);
  70.     if (r < 0) {
  71.         pr_err("Can't set cpu DAI configuration: %d\n", r);
  72.         return r;
  73.     }
  74.     return 0;
  75. }
  76.  
  77. static struct snd_soc_ops dfl61wl1273_ops = {
  78.     .startup = dfl61wl1273_startup,
  79. };
  80.  
  81. /* Digital audio interface glue - connects codec <--> CPU */
  82. static struct snd_soc_dai_link dfl61wl1273_dai = {
  83.     .name = "BT/FM PCM",
  84.     .stream_name = "BT/FM Stream",
  85.     .cpu_dai = &omap_mcbsp_dai[DFL61_WL1273_ID],
  86.     .codec_dai = &wl1273_dai,
  87.     .ops = &dfl61wl1273_ops,
  88. };
  89.  
  90. /* Audio card driver */
  91. static struct snd_soc_card snd_soc_card_dfl61wl1273 = {
  92.     .name = "dfl61-wl1273",
  93.     .platform = &omap_soc_platform,
  94.     .dai_link = &dfl61wl1273_dai,
  95.     .num_links = 1,
  96. };
  97.  
  98. /* Audio subsystem */
  99. static struct snd_soc_device dfl61wl1273_snd_devdata = {
  100.     .card = &snd_soc_card_dfl61wl1273,
  101.     .codec_dev = &soc_codec_dev_wl1273,
  102. };
  103.  
  104. static struct platform_device *dfl61wl1273_snd_device;
  105.  
  106. static int __init dfl61wl1273_soc_init(void)
  107. {
  108.     int r;
  109.  
  110.     if (!machine_is_nokia_rx71() &&
  111.         !machine_is_nokia_rm680() && !machine_is_nokia_rm696())
  112.         return -ENODEV;
  113.  
  114.     dfl61wl1273_snd_device = platform_device_alloc("soc-audio",
  115.                             DFL61_WL1273_ID);
  116.     if (!dfl61wl1273_snd_device) {
  117.         pr_err("Platform device allocation failed\n");
  118.         return -ENOMEM;
  119.     }
  120.  
  121.     platform_set_drvdata(dfl61wl1273_snd_device, &dfl61wl1273_snd_devdata);
  122.     dfl61wl1273_snd_devdata.dev = &dfl61wl1273_snd_device->dev;
  123.     *(unsigned int *)dfl61wl1273_dai.cpu_dai->private_data = 3; /* McBSP4 */
  124.  
  125.     r = platform_device_add(dfl61wl1273_snd_device);
  126.     if (r)
  127.         goto fail;
  128.  
  129.     /* Threshold + SMARTIDLE */
  130.     omap_mcbsp_set_dma_op_mode(3, MCBSP_DMA_MODE_THRESHOLD);
  131.     omap_mcbsp_set_sidle_mode(3, MCBSP_SIDLE_SMART_IDLE,
  132.                   MCBSP_CLKACT_IOFF_FON);
  133.  
  134.     return 0;
  135.  
  136. fail:
  137.     pr_err("Unable to add platform device\n");
  138.     platform_device_put(dfl61wl1273_snd_device);
  139.  
  140.     return r;
  141. }
  142.  
  143. static void __exit dfl61wl1273_soc_exit(void)
  144. {
  145.     platform_device_unregister(dfl61wl1273_snd_device);
  146. }
  147.  
  148. module_init(dfl61wl1273_soc_init);
  149. module_exit(dfl61wl1273_soc_exit);
  150.  
  151. MODULE_AUTHOR("Matti Aaltonen <matti.j.aaltonen@nokia.com>");
  152. MODULE_DESCRIPTION("ALSA SoC for WL1273 on Nokia DFL61 class devices");
  153. MODULE_LICENSE("GPL");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement