Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 1 | /* |
| 2 | * trimslice.c - TrimSlice machine ASoC driver |
| 3 | * |
| 4 | * Copyright (C) 2011 - CompuLab, Ltd. |
| 5 | * Author: Mike Rapoport <mike@compulab.co.il> |
| 6 | * |
| 7 | * Based on code copyright/by: |
| 8 | * Author: Stephen Warren <swarren@nvidia.com> |
| 9 | * Copyright (C) 2010-2011 - NVIDIA, Inc. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License |
| 13 | * version 2 as published by the Free Software Foundation. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, but |
| 16 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 23 | * 02110-1301 USA |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <asm/mach-types.h> |
| 28 | |
| 29 | #include <linux/module.h> |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 30 | #include <linux/of.h> |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 31 | #include <linux/platform_device.h> |
| 32 | #include <linux/slab.h> |
| 33 | |
| 34 | #include <sound/core.h> |
| 35 | #include <sound/jack.h> |
| 36 | #include <sound/pcm.h> |
| 37 | #include <sound/pcm_params.h> |
| 38 | #include <sound/soc.h> |
| 39 | |
| 40 | #include "../codecs/tlv320aic23.h" |
| 41 | |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 42 | #include "tegra_asoc_utils.h" |
| 43 | |
| 44 | #define DRV_NAME "tegra-snd-trimslice" |
| 45 | |
| 46 | struct tegra_trimslice { |
| 47 | struct tegra_asoc_utils_data util_data; |
| 48 | }; |
| 49 | |
| 50 | static int trimslice_asoc_hw_params(struct snd_pcm_substream *substream, |
| 51 | struct snd_pcm_hw_params *params) |
| 52 | { |
| 53 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 54 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 55 | struct snd_soc_codec *codec = rtd->codec; |
| 56 | struct snd_soc_card *card = codec->card; |
| 57 | struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card); |
| 58 | int srate, mclk; |
| 59 | int err; |
| 60 | |
| 61 | srate = params_rate(params); |
| 62 | mclk = 128 * srate; |
| 63 | |
| 64 | err = tegra_asoc_utils_set_rate(&trimslice->util_data, srate, mclk); |
| 65 | if (err < 0) { |
| 66 | dev_err(card->dev, "Can't configure clocks\n"); |
| 67 | return err; |
| 68 | } |
| 69 | |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 70 | err = snd_soc_dai_set_sysclk(codec_dai, 0, mclk, |
| 71 | SND_SOC_CLOCK_IN); |
| 72 | if (err < 0) { |
| 73 | dev_err(card->dev, "codec_dai clock not set\n"); |
| 74 | return err; |
| 75 | } |
| 76 | |
| 77 | return 0; |
| 78 | } |
| 79 | |
| 80 | static struct snd_soc_ops trimslice_asoc_ops = { |
| 81 | .hw_params = trimslice_asoc_hw_params, |
| 82 | }; |
| 83 | |
| 84 | static const struct snd_soc_dapm_widget trimslice_dapm_widgets[] = { |
| 85 | SND_SOC_DAPM_HP("Line Out", NULL), |
| 86 | SND_SOC_DAPM_LINE("Line In", NULL), |
| 87 | }; |
| 88 | |
| 89 | static const struct snd_soc_dapm_route trimslice_audio_map[] = { |
| 90 | {"Line Out", NULL, "LOUT"}, |
| 91 | {"Line Out", NULL, "ROUT"}, |
| 92 | |
| 93 | {"LLINEIN", NULL, "Line In"}, |
| 94 | {"RLINEIN", NULL, "Line In"}, |
| 95 | }; |
| 96 | |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 97 | static struct snd_soc_dai_link trimslice_tlv320aic23_dai = { |
| 98 | .name = "TLV320AIC23", |
| 99 | .stream_name = "AIC23", |
| 100 | .codec_name = "tlv320aic23-codec.2-001a", |
Stephen Warren | 896637a | 2012-04-06 10:30:52 -0600 | [diff] [blame] | 101 | .platform_name = "tegra20-i2s.0", |
| 102 | .cpu_dai_name = "tegra20-i2s.0", |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 103 | .codec_dai_name = "tlv320aic23-hifi", |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 104 | .ops = &trimslice_asoc_ops, |
Stephen Warren | 408dafc | 2012-06-06 17:15:48 -0600 | [diff] [blame^] | 105 | .dai_fmt = SND_SOC_DAIFMT_I2S | |
| 106 | SND_SOC_DAIFMT_NB_NF | |
| 107 | SND_SOC_DAIFMT_CBS_CFS, |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | static struct snd_soc_card snd_soc_trimslice = { |
| 111 | .name = "tegra-trimslice", |
Axel Lin | b16eaf9 | 2011-12-22 21:23:01 +0800 | [diff] [blame] | 112 | .owner = THIS_MODULE, |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 113 | .dai_link = &trimslice_tlv320aic23_dai, |
| 114 | .num_links = 1, |
| 115 | |
| 116 | .dapm_widgets = trimslice_dapm_widgets, |
| 117 | .num_dapm_widgets = ARRAY_SIZE(trimslice_dapm_widgets), |
| 118 | .dapm_routes = trimslice_audio_map, |
| 119 | .num_dapm_routes = ARRAY_SIZE(trimslice_audio_map), |
Stephen Warren | 504855d | 2011-11-23 12:42:06 -0700 | [diff] [blame] | 120 | .fully_routed = true, |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | static __devinit int tegra_snd_trimslice_probe(struct platform_device *pdev) |
| 124 | { |
| 125 | struct snd_soc_card *card = &snd_soc_trimslice; |
| 126 | struct tegra_trimslice *trimslice; |
| 127 | int ret; |
| 128 | |
Stephen Warren | 45c2609 | 2011-11-22 18:21:21 -0700 | [diff] [blame] | 129 | trimslice = devm_kzalloc(&pdev->dev, sizeof(struct tegra_trimslice), |
| 130 | GFP_KERNEL); |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 131 | if (!trimslice) { |
| 132 | dev_err(&pdev->dev, "Can't allocate tegra_trimslice\n"); |
Stephen Warren | 45c2609 | 2011-11-22 18:21:21 -0700 | [diff] [blame] | 133 | ret = -ENOMEM; |
| 134 | goto err; |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 135 | } |
| 136 | |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 137 | if (pdev->dev.of_node) { |
| 138 | trimslice_tlv320aic23_dai.codec_name = NULL; |
| 139 | trimslice_tlv320aic23_dai.codec_of_node = of_parse_phandle( |
| 140 | pdev->dev.of_node, "nvidia,audio-codec", 0); |
| 141 | if (!trimslice_tlv320aic23_dai.codec_of_node) { |
| 142 | dev_err(&pdev->dev, |
| 143 | "Property 'nvidia,audio-codec' missing or invalid\n"); |
| 144 | ret = -EINVAL; |
| 145 | goto err; |
| 146 | } |
| 147 | |
| 148 | trimslice_tlv320aic23_dai.cpu_dai_name = NULL; |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 149 | trimslice_tlv320aic23_dai.cpu_of_node = of_parse_phandle( |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 150 | pdev->dev.of_node, "nvidia,i2s-controller", 0); |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 151 | if (!trimslice_tlv320aic23_dai.cpu_of_node) { |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 152 | dev_err(&pdev->dev, |
| 153 | "Property 'nvidia,i2s-controller' missing or invalid\n"); |
| 154 | ret = -EINVAL; |
| 155 | goto err; |
| 156 | } |
| 157 | |
| 158 | trimslice_tlv320aic23_dai.platform_name = NULL; |
| 159 | trimslice_tlv320aic23_dai.platform_of_node = |
Stephen Warren | bc92657 | 2012-05-25 18:22:11 -0600 | [diff] [blame] | 160 | trimslice_tlv320aic23_dai.cpu_of_node; |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 161 | } |
| 162 | |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 163 | ret = tegra_asoc_utils_init(&trimslice->util_data, &pdev->dev); |
| 164 | if (ret) |
Stephen Warren | 45c2609 | 2011-11-22 18:21:21 -0700 | [diff] [blame] | 165 | goto err; |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 166 | |
| 167 | card->dev = &pdev->dev; |
| 168 | platform_set_drvdata(pdev, card); |
| 169 | snd_soc_card_set_drvdata(card, trimslice); |
| 170 | |
| 171 | ret = snd_soc_register_card(card); |
| 172 | if (ret) { |
| 173 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", |
| 174 | ret); |
| 175 | goto err_fini_utils; |
| 176 | } |
| 177 | |
| 178 | return 0; |
| 179 | |
| 180 | err_fini_utils: |
| 181 | tegra_asoc_utils_fini(&trimslice->util_data); |
Stephen Warren | 45c2609 | 2011-11-22 18:21:21 -0700 | [diff] [blame] | 182 | err: |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 183 | return ret; |
| 184 | } |
| 185 | |
| 186 | static int __devexit tegra_snd_trimslice_remove(struct platform_device *pdev) |
| 187 | { |
| 188 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
| 189 | struct tegra_trimslice *trimslice = snd_soc_card_get_drvdata(card); |
| 190 | |
| 191 | snd_soc_unregister_card(card); |
| 192 | |
| 193 | tegra_asoc_utils_fini(&trimslice->util_data); |
| 194 | |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 198 | static const struct of_device_id trimslice_of_match[] __devinitconst = { |
| 199 | { .compatible = "nvidia,tegra-audio-trimslice", }, |
| 200 | {}, |
| 201 | }; |
| 202 | MODULE_DEVICE_TABLE(of, trimslice_of_match); |
| 203 | |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 204 | static struct platform_driver tegra_snd_trimslice_driver = { |
| 205 | .driver = { |
| 206 | .name = DRV_NAME, |
| 207 | .owner = THIS_MODULE, |
Stephen Warren | 6264f66 | 2012-04-27 13:34:19 -0600 | [diff] [blame] | 208 | .of_match_table = trimslice_of_match, |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 209 | }, |
| 210 | .probe = tegra_snd_trimslice_probe, |
| 211 | .remove = __devexit_p(tegra_snd_trimslice_remove), |
| 212 | }; |
Stephen Warren | 45c2609 | 2011-11-22 18:21:21 -0700 | [diff] [blame] | 213 | module_platform_driver(tegra_snd_trimslice_driver); |
Mike Rapoport | 1307394 | 2011-04-26 11:52:42 +0300 | [diff] [blame] | 214 | |
| 215 | MODULE_AUTHOR("Mike Rapoport <mike@compulab.co.il>"); |
| 216 | MODULE_DESCRIPTION("Trimslice machine ASoC driver"); |
| 217 | MODULE_LICENSE("GPL"); |
| 218 | MODULE_ALIAS("platform:" DRV_NAME); |