Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 1 | /* |
| 2 | * afeb9260.c -- SoC audio for AFEB9260 |
| 3 | * |
| 4 | * Copyright (C) 2009 Sergey Lapin <slapin@ossfans.org> |
| 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/module.h> |
| 23 | #include <linux/moduleparam.h> |
| 24 | #include <linux/kernel.h> |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/platform_device.h> |
| 27 | |
| 28 | #include <linux/atmel-ssc.h> |
| 29 | #include <sound/core.h> |
| 30 | #include <sound/pcm.h> |
| 31 | #include <sound/pcm_params.h> |
| 32 | #include <sound/soc.h> |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 33 | |
| 34 | #include <asm/mach-types.h> |
| 35 | #include <mach/hardware.h> |
| 36 | #include <linux/gpio.h> |
| 37 | |
| 38 | #include "../codecs/tlv320aic23.h" |
| 39 | #include "atmel-pcm.h" |
| 40 | #include "atmel_ssc_dai.h" |
| 41 | |
| 42 | #define CODEC_CLOCK 12000000 |
| 43 | |
| 44 | static int afeb9260_hw_params(struct snd_pcm_substream *substream, |
| 45 | struct snd_pcm_hw_params *params) |
| 46 | { |
| 47 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 48 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 49 | int err; |
| 50 | |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 51 | /* Set the codec system clock for DAC and ADC */ |
| 52 | err = |
| 53 | snd_soc_dai_set_sysclk(codec_dai, 0, CODEC_CLOCK, SND_SOC_CLOCK_IN); |
| 54 | |
| 55 | if (err < 0) { |
| 56 | printk(KERN_ERR "can't set codec system clock\n"); |
| 57 | return err; |
| 58 | } |
| 59 | |
| 60 | return err; |
| 61 | } |
| 62 | |
| 63 | static struct snd_soc_ops afeb9260_ops = { |
| 64 | .hw_params = afeb9260_hw_params, |
| 65 | }; |
| 66 | |
| 67 | static const struct snd_soc_dapm_widget tlv320aic23_dapm_widgets[] = { |
| 68 | SND_SOC_DAPM_HP("Headphone Jack", NULL), |
| 69 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 70 | SND_SOC_DAPM_MIC("Mic Jack", NULL), |
| 71 | }; |
| 72 | |
Axel Lin | bc6c117 | 2012-01-29 16:52:51 +0800 | [diff] [blame] | 73 | static const struct snd_soc_dapm_route afeb9260_audio_map[] = { |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 74 | {"Headphone Jack", NULL, "LHPOUT"}, |
| 75 | {"Headphone Jack", NULL, "RHPOUT"}, |
| 76 | |
| 77 | {"LLINEIN", NULL, "Line In"}, |
| 78 | {"RLINEIN", NULL, "Line In"}, |
| 79 | |
| 80 | {"MICIN", NULL, "Mic Jack"}, |
| 81 | }; |
| 82 | |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 83 | |
| 84 | /* Digital audio interface glue - connects codec <--> CPU */ |
| 85 | static struct snd_soc_dai_link afeb9260_dai = { |
| 86 | .name = "TLV320AIC23", |
| 87 | .stream_name = "AIC23", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 88 | .cpu_dai_name = "atmel-ssc-dai.0", |
| 89 | .codec_dai_name = "tlv320aic23-hifi", |
| 90 | .platform_name = "atmel_pcm-audio", |
Lars-Peter Clausen | 81d7da5 | 2011-01-24 22:09:22 +0100 | [diff] [blame] | 91 | .codec_name = "tlv320aic23-codec.0-001a", |
Axel Lin | 5813db9 | 2012-01-29 16:52:02 +0800 | [diff] [blame] | 92 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_IF | |
| 93 | SND_SOC_DAIFMT_CBM_CFM, |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 94 | .ops = &afeb9260_ops, |
| 95 | }; |
| 96 | |
| 97 | /* Audio machine driver */ |
| 98 | static struct snd_soc_card snd_soc_machine_afeb9260 = { |
| 99 | .name = "AFEB9260", |
Axel Lin | 338d68d | 2011-12-22 21:14:58 +0800 | [diff] [blame] | 100 | .owner = THIS_MODULE, |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 101 | .dai_link = &afeb9260_dai, |
| 102 | .num_links = 1, |
Axel Lin | bc6c117 | 2012-01-29 16:52:51 +0800 | [diff] [blame] | 103 | |
| 104 | .dapm_widgets = tlv320aic23_dapm_widgets, |
| 105 | .num_dapm_widgets = ARRAY_SIZE(tlv320aic23_dapm_widgets), |
| 106 | .dapm_routes = afeb9260_audio_map, |
| 107 | .num_dapm_routes = ARRAY_SIZE(afeb9260_audio_map), |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 108 | }; |
| 109 | |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 110 | static struct platform_device *afeb9260_snd_device; |
| 111 | |
| 112 | static int __init afeb9260_soc_init(void) |
| 113 | { |
| 114 | int err; |
| 115 | struct device *dev; |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 116 | |
| 117 | if (!(machine_is_afeb9260())) |
| 118 | return -ENODEV; |
| 119 | |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 120 | |
| 121 | afeb9260_snd_device = platform_device_alloc("soc-audio", -1); |
| 122 | if (!afeb9260_snd_device) { |
| 123 | printk(KERN_ERR "ASoC: Platform device allocation failed\n"); |
| 124 | return -ENOMEM; |
| 125 | } |
| 126 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 127 | platform_set_drvdata(afeb9260_snd_device, &snd_soc_machine_afeb9260); |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 128 | err = platform_device_add(afeb9260_snd_device); |
| 129 | if (err) |
| 130 | goto err1; |
| 131 | |
| 132 | dev = &afeb9260_snd_device->dev; |
| 133 | |
| 134 | return 0; |
| 135 | err1: |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 136 | platform_device_put(afeb9260_snd_device); |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 137 | return err; |
Sergey Lapin | b4df0a6 | 2009-05-08 19:19:41 +0400 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | static void __exit afeb9260_soc_exit(void) |
| 141 | { |
| 142 | platform_device_unregister(afeb9260_snd_device); |
| 143 | } |
| 144 | |
| 145 | module_init(afeb9260_soc_init); |
| 146 | module_exit(afeb9260_soc_exit); |
| 147 | |
| 148 | MODULE_AUTHOR("Sergey Lapin <slapin@ossfans.org>"); |
| 149 | MODULE_DESCRIPTION("ALSA SoC for AFEB9260"); |
| 150 | MODULE_LICENSE("GPL"); |
| 151 | |