Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /*
  2  * omap3beagle.c  --  SoC audio for OMAP3 Beagle
  3  *
  4  * Author: Steve Sakoman <steve@sakoman.com>
  5  *
  6  * This program is free software; you can redistribute it and/or
  7  * modify it under the terms of the GNU General Public License
  8  * version 2 as published by the Free Software Foundation.
  9  *
 10  * This program is distributed in the hope that it will be useful, but
 11  * WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  * General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with this program; if not, write to the Free Software
 17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 18  * 02110-1301 USA
 19  *
 20  */
 21 
 22 #include <linux/clk.h>
 23 #include <linux/platform_device.h>
 24 #include <sound/core.h>
 25 #include <sound/pcm.h>
 26 #include <sound/soc.h>
 27 #include <sound/soc-dapm.h>
 28 
 29 #include <asm/mach-types.h>
 30 #include <mach/hardware.h>
 31 #include <mach/gpio.h>
 32 #include <mach/mcbsp.h>
 33 
 34 #include "omap-mcbsp.h"
 35 #include "omap-pcm.h"
 36 #include "../codecs/twl4030.h"
 37 
 38 static int omap3beagle_hw_params(struct snd_pcm_substream *substream,
 39         struct snd_pcm_hw_params *params)
 40 {
 41         struct snd_soc_pcm_runtime *rtd = substream->private_data;
 42         struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
 43         struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
 44         unsigned int fmt;
 45         int ret;
 46 
 47         switch (params_channels(params)) {
 48         case 2: /* Stereo I2S mode */
 49                 fmt =   SND_SOC_DAIFMT_I2S |
 50                         SND_SOC_DAIFMT_NB_NF |
 51                         SND_SOC_DAIFMT_CBM_CFM;
 52                 break;
 53         case 4: /* Four channel TDM mode */
 54                 fmt =   SND_SOC_DAIFMT_DSP_A |
 55                         SND_SOC_DAIFMT_IB_NF |
 56                         SND_SOC_DAIFMT_CBM_CFM;
 57                 break;
 58         default:
 59                 return -EINVAL;
 60         }
 61 
 62         /* Set codec DAI configuration */
 63         ret = snd_soc_dai_set_fmt(codec_dai, fmt);
 64         if (ret < 0) {
 65                 printk(KERN_ERR "can't set codec DAI configuration\n");
 66                 return ret;
 67         }
 68 
 69         /* Set cpu DAI configuration */
 70         ret = snd_soc_dai_set_fmt(cpu_dai, fmt);
 71         if (ret < 0) {
 72                 printk(KERN_ERR "can't set cpu DAI configuration\n");
 73                 return ret;
 74         }
 75 
 76         /* Set the codec system clock for DAC and ADC */
 77         ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
 78                                      SND_SOC_CLOCK_IN);
 79         if (ret < 0) {
 80                 printk(KERN_ERR "can't set codec system clock\n");
 81                 return ret;
 82         }
 83 
 84         return 0;
 85 }
 86 
 87 static struct snd_soc_ops omap3beagle_ops = {
 88         .hw_params = omap3beagle_hw_params,
 89 };
 90 
 91 /* Digital audio interface glue - connects codec <--> CPU */
 92 static struct snd_soc_dai_link omap3beagle_dai = {
 93         .name = "TWL4030",
 94         .stream_name = "TWL4030",
 95         .cpu_dai = &omap_mcbsp_dai[0],
 96         .codec_dai = &twl4030_dai[TWL4030_DAI_HIFI],
 97         .ops = &omap3beagle_ops,
 98 };
 99 
100 /* Audio machine driver */
101 static struct snd_soc_card snd_soc_omap3beagle = {
102         .name = "omap3beagle",
103         .platform = &omap_soc_platform,
104         .dai_link = &omap3beagle_dai,
105         .num_links = 1,
106 };
107 
108 /* Audio subsystem */
109 static struct snd_soc_device omap3beagle_snd_devdata = {
110         .card = &snd_soc_omap3beagle,
111         .codec_dev = &soc_codec_dev_twl4030,
112 };
113 
114 static struct platform_device *omap3beagle_snd_device;
115 
116 static int __init omap3beagle_soc_init(void)
117 {
118         int ret;
119 
120         if (!machine_is_omap3_beagle()) {
121                 pr_debug("Not OMAP3 Beagle!\n");
122                 return -ENODEV;
123         }
124         pr_info("OMAP3 Beagle SoC init\n");
125 
126         omap3beagle_snd_device = platform_device_alloc("soc-audio", -1);
127         if (!omap3beagle_snd_device) {
128                 printk(KERN_ERR "Platform device allocation failed\n");
129                 return -ENOMEM;
130         }
131 
132         platform_set_drvdata(omap3beagle_snd_device, &omap3beagle_snd_devdata);
133         omap3beagle_snd_devdata.dev = &omap3beagle_snd_device->dev;
134         *(unsigned int *)omap3beagle_dai.cpu_dai->private_data = 1; /* McBSP2 */
135 
136         ret = platform_device_add(omap3beagle_snd_device);
137         if (ret)
138                 goto err1;
139 
140         return 0;
141 
142 err1:
143         printk(KERN_ERR "Unable to add platform device\n");
144         platform_device_put(omap3beagle_snd_device);
145 
146         return ret;
147 }
148 
149 static void __exit omap3beagle_soc_exit(void)
150 {
151         platform_device_unregister(omap3beagle_snd_device);
152 }
153 
154 module_init(omap3beagle_soc_init);
155 module_exit(omap3beagle_soc_exit);
156 
157 MODULE_AUTHOR("Steve Sakoman <steve@sakoman.com>");
158 MODULE_DESCRIPTION("ALSA SoC OMAP3 Beagle");
159 MODULE_LICENSE("GPL");
160 
  This page was automatically generated by the LXR engine.