Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * eukrea-tlv320.c -- SoC audio for eukrea_cpuimxXX in I2S mode |
| 3 | * |
| 4 | * Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com> |
| 5 | * |
| 6 | * based on sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c |
| 7 | * which is Copyright 2009 Simtec Electronics |
| 8 | * and on sound/soc/imx/phycore-ac97.c which is |
| 9 | * Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> |
Shawn Guo | a23dc69 | 2012-03-16 16:56:38 +0800 | [diff] [blame] | 10 | * |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify it |
| 12 | * under the terms of the GNU General Public License as published by the |
| 13 | * Free Software Foundation; either version 2 of the License, or (at your |
| 14 | * option) any later version. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/moduleparam.h> |
| 20 | #include <linux/device.h> |
| 21 | #include <linux/i2c.h> |
| 22 | #include <sound/core.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/soc.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 25 | #include <asm/mach-types.h> |
| 26 | |
| 27 | #include "../codecs/tlv320aic23.h" |
| 28 | #include "imx-ssi.h" |
Shawn Guo | 3c77c29 | 2012-03-05 22:30:53 +0800 | [diff] [blame] | 29 | #include "imx-audmux.h" |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 30 | |
| 31 | #define CODEC_CLOCK 12000000 |
| 32 | |
| 33 | static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream, |
| 34 | struct snd_pcm_hw_params *params) |
| 35 | { |
| 36 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Sascha Hauer | add330e | 2010-11-04 17:05:40 +0100 | [diff] [blame] | 37 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 38 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 39 | int ret; |
| 40 | |
| 41 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
| 42 | SND_SOC_DAIFMT_NB_NF | |
| 43 | SND_SOC_DAIFMT_CBM_CFM); |
| 44 | if (ret) { |
| 45 | pr_err("%s: failed set cpu dai format\n", __func__); |
| 46 | return ret; |
| 47 | } |
| 48 | |
| 49 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
| 50 | SND_SOC_DAIFMT_NB_NF | |
| 51 | SND_SOC_DAIFMT_CBM_CFM); |
| 52 | if (ret) { |
| 53 | pr_err("%s: failed set codec dai format\n", __func__); |
| 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, |
| 58 | CODEC_CLOCK, SND_SOC_CLOCK_OUT); |
| 59 | if (ret) { |
| 60 | pr_err("%s: failed setting codec sysclk\n", __func__); |
| 61 | return ret; |
| 62 | } |
Eric Bénard | 4379320 | 2010-06-17 15:44:01 +0200 | [diff] [blame] | 63 | snd_soc_dai_set_tdm_slot(cpu_dai, 0xffffffc, 0xffffffc, 2, 0); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 64 | |
| 65 | ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, |
| 66 | SND_SOC_CLOCK_IN); |
| 67 | if (ret) { |
| 68 | pr_err("can't set CPU system clock IMX_SSP_SYS_CLK\n"); |
| 69 | return ret; |
| 70 | } |
| 71 | |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static struct snd_soc_ops eukrea_tlv320_snd_ops = { |
| 76 | .hw_params = eukrea_tlv320_hw_params, |
| 77 | }; |
| 78 | |
| 79 | static struct snd_soc_dai_link eukrea_tlv320_dai = { |
| 80 | .name = "tlv320aic23", |
| 81 | .stream_name = "TLV320AIC23", |
Sascha Hauer | add330e | 2010-11-04 17:05:40 +0100 | [diff] [blame] | 82 | .codec_dai_name = "tlv320aic23-hifi", |
Shawn Guo | 2bf9d4b | 2013-04-25 11:18:49 +0800 | [diff] [blame] | 83 | .platform_name = "imx-ssi.0", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 84 | .codec_name = "tlv320aic23-codec.0-001a", |
Sascha Hauer | add330e | 2010-11-04 17:05:40 +0100 | [diff] [blame] | 85 | .cpu_dai_name = "imx-ssi.0", |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 86 | .ops = &eukrea_tlv320_snd_ops, |
| 87 | }; |
| 88 | |
| 89 | static struct snd_soc_card eukrea_tlv320 = { |
| 90 | .name = "cpuimx-audio", |
Axel Lin | 6aff8cc | 2011-12-23 14:47:08 +0800 | [diff] [blame] | 91 | .owner = THIS_MODULE, |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 92 | .dai_link = &eukrea_tlv320_dai, |
| 93 | .num_links = 1, |
| 94 | }; |
| 95 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 96 | static int eukrea_tlv320_probe(struct platform_device *pdev) |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 97 | { |
| 98 | int ret; |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 99 | int int_port = 0, ext_port; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 100 | |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 101 | if (machine_is_eukrea_cpuimx27()) { |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 102 | imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, |
| 103 | IMX_AUDMUX_V1_PCR_SYN | |
| 104 | IMX_AUDMUX_V1_PCR_TFSDIR | |
| 105 | IMX_AUDMUX_V1_PCR_TCLKDIR | |
| 106 | IMX_AUDMUX_V1_PCR_RFSDIR | |
| 107 | IMX_AUDMUX_V1_PCR_RCLKDIR | |
| 108 | IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | |
| 109 | IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | |
| 110 | IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 111 | ); |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 112 | imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4, |
| 113 | IMX_AUDMUX_V1_PCR_SYN | |
| 114 | IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 115 | ); |
| 116 | } else if (machine_is_eukrea_cpuimx25sd() || |
| 117 | machine_is_eukrea_cpuimx35sd() || |
| 118 | machine_is_eukrea_cpuimx51sd()) { |
| 119 | ext_port = machine_is_eukrea_cpuimx25sd() ? 4 : 3; |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 120 | imx_audmux_v2_configure_port(int_port, |
| 121 | IMX_AUDMUX_V2_PTCR_SYN | |
| 122 | IMX_AUDMUX_V2_PTCR_TFSDIR | |
| 123 | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | |
| 124 | IMX_AUDMUX_V2_PTCR_TCLKDIR | |
| 125 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port), |
| 126 | IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 127 | ); |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 128 | imx_audmux_v2_configure_port(ext_port, |
| 129 | IMX_AUDMUX_V2_PTCR_SYN, |
| 130 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 131 | ); |
| 132 | } else { |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 133 | /* return happy. We might run on a totally different machine */ |
| 134 | return 0; |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 135 | } |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 136 | |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 137 | eukrea_tlv320.dev = &pdev->dev; |
| 138 | ret = snd_soc_register_card(&eukrea_tlv320); |
| 139 | if (ret) |
| 140 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 141 | |
| 142 | return ret; |
| 143 | } |
| 144 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 145 | static int eukrea_tlv320_remove(struct platform_device *pdev) |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 146 | { |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 147 | snd_soc_unregister_card(&eukrea_tlv320); |
| 148 | |
| 149 | return 0; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 150 | } |
| 151 | |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 152 | static struct platform_driver eukrea_tlv320_driver = { |
| 153 | .driver = { |
| 154 | .name = "eukrea_tlv320", |
| 155 | .owner = THIS_MODULE, |
| 156 | }, |
| 157 | .probe = eukrea_tlv320_probe, |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 158 | .remove = eukrea_tlv320_remove,}; |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 159 | |
| 160 | module_platform_driver(eukrea_tlv320_driver); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 161 | |
| 162 | MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>"); |
| 163 | MODULE_DESCRIPTION("CPUIMX ALSA SoC driver"); |
| 164 | MODULE_LICENSE("GPL"); |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 165 | MODULE_ALIAS("platform:eukrea_tlv320"); |