blob: bf9ae2a6f90199bc1a8c02e245e98a7da7122097 [file] [log] [blame]
Anuj Aggarwal14610ce2009-05-14 13:59:19 +05301/*
2 * omap3evm.c -- ALSA SoC support for OMAP3 EVM
3 *
4 * Author: Anuj Aggarwal <anuj.aggarwal@ti.com>
5 *
6 * Based on sound/soc/omap/beagle.c by Steve Sakoman
7 *
8 * Copyright (C) 2008 Texas Instruments, Incorporated
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 version 2.
13 *
14 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
15 * whether express or implied; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 */
19
20#include <linux/clk.h>
21#include <linux/platform_device.h>
22#include <sound/core.h>
23#include <sound/pcm.h>
24#include <sound/soc.h>
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053025
26#include <asm/mach-types.h>
27#include <mach/hardware.h>
28#include <mach/gpio.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070029#include <plat/mcbsp.h>
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053030
31#include "omap-mcbsp.h"
32#include "omap-pcm.h"
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053033
34static int omap3evm_hw_params(struct snd_pcm_substream *substream,
35 struct snd_pcm_hw_params *params)
36{
37 struct snd_soc_pcm_runtime *rtd = substream->private_data;
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000038 struct snd_soc_dai *codec_dai = rtd->codec_dai;
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053039 int ret;
40
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053041 /* Set the codec system clock for DAC and ADC */
42 ret = snd_soc_dai_set_sysclk(codec_dai, 0, 26000000,
43 SND_SOC_CLOCK_IN);
44 if (ret < 0) {
45 printk(KERN_ERR "Can't set codec system clock\n");
46 return ret;
47 }
48
49 return 0;
50}
51
52static struct snd_soc_ops omap3evm_ops = {
53 .hw_params = omap3evm_hw_params,
54};
55
56/* Digital audio interface glue - connects codec <--> CPU */
57static struct snd_soc_dai_link omap3evm_dai = {
58 .name = "TWL4030",
59 .stream_name = "TWL4030",
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000060 .cpu_dai_name = "omap-mcbsp-dai.1",
61 .codec_dai_name = "twl4030-hifi",
62 .platform_name = "omap-pcm-audio",
63 .codec_name = "twl4030-codec",
Jarkko Nikulacf9feff2011-09-30 16:07:45 +030064 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
65 SND_SOC_DAIFMT_CBM_CFM,
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053066 .ops = &omap3evm_ops,
67};
68
69/* Audio machine driver */
70static struct snd_soc_card snd_soc_omap3evm = {
71 .name = "omap3evm",
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053072 .dai_link = &omap3evm_dai,
73 .num_links = 1,
74};
75
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053076static struct platform_device *omap3evm_snd_device;
77
78static int __init omap3evm_soc_init(void)
79{
80 int ret;
81
Jarkko Nikulaec588ae2010-10-06 16:47:26 +030082 if (!machine_is_omap3evm())
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053083 return -ENODEV;
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053084 pr_info("OMAP3 EVM SoC init\n");
85
86 omap3evm_snd_device = platform_device_alloc("soc-audio", -1);
87 if (!omap3evm_snd_device) {
88 printk(KERN_ERR "Platform device allocation failed\n");
89 return -ENOMEM;
90 }
91
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000092 platform_set_drvdata(omap3evm_snd_device, &snd_soc_omap3evm);
Anuj Aggarwal14610ce2009-05-14 13:59:19 +053093 ret = platform_device_add(omap3evm_snd_device);
94 if (ret)
95 goto err1;
96
97 return 0;
98
99err1:
100 printk(KERN_ERR "Unable to add platform device\n");
101 platform_device_put(omap3evm_snd_device);
102
103 return ret;
104}
105
106static void __exit omap3evm_soc_exit(void)
107{
108 platform_device_unregister(omap3evm_snd_device);
109}
110
111module_init(omap3evm_soc_init);
112module_exit(omap3evm_soc_exit);
113
114MODULE_AUTHOR("Anuj Aggarwal <anuj.aggarwal@ti.com>");
115MODULE_DESCRIPTION("ALSA SoC OMAP3 EVM");
Anuj Aggarwalbd6ddcb2009-11-17 21:43:42 +0530116MODULE_LICENSE("GPL v2");