Andra Danciu | ecf4630 | 2019-04-05 14:49:53 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // eukrea-tlv320.c -- SoC audio for eukrea_cpuimxXX in I2S mode |
| 4 | // |
| 5 | // Copyright 2010 Eric Bénard, Eukréa Electromatique <eric@eukrea.com> |
| 6 | // |
| 7 | // based on sound/soc/s3c24xx/s3c24xx_simtec_tlv320aic23.c |
| 8 | // which is Copyright 2009 Simtec Electronics |
| 9 | // and on sound/soc/imx/phycore-ac97.c which is |
| 10 | // Copyright 2009 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 11 | |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 12 | #include <linux/errno.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 13 | #include <linux/module.h> |
| 14 | #include <linux/moduleparam.h> |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 15 | #include <linux/of.h> |
| 16 | #include <linux/of_platform.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 17 | #include <linux/device.h> |
| 18 | #include <linux/i2c.h> |
| 19 | #include <sound/core.h> |
| 20 | #include <sound/pcm.h> |
| 21 | #include <sound/soc.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 22 | #include <asm/mach-types.h> |
| 23 | |
| 24 | #include "../codecs/tlv320aic23.h" |
| 25 | #include "imx-ssi.h" |
Shawn Guo | 3c77c29c | 2012-03-05 22:30:53 +0800 | [diff] [blame] | 26 | #include "imx-audmux.h" |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 27 | |
| 28 | #define CODEC_CLOCK 12000000 |
| 29 | |
| 30 | static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream, |
| 31 | struct snd_pcm_hw_params *params) |
| 32 | { |
Kuninori Morimoto | 9f5f078 | 2020-07-20 10:18:38 +0900 | [diff] [blame] | 33 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 34 | struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0); |
| 35 | struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 36 | int ret; |
| 37 | |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 38 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, |
| 39 | CODEC_CLOCK, SND_SOC_CLOCK_OUT); |
| 40 | if (ret) { |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 41 | dev_err(cpu_dai->dev, |
| 42 | "Failed to set the codec sysclk.\n"); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 43 | return ret; |
| 44 | } |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 45 | |
Lars-Peter Clausen | d0077aa | 2015-01-12 10:27:18 +0100 | [diff] [blame] | 46 | snd_soc_dai_set_tdm_slot(cpu_dai, 0x3, 0x3, 2, 0); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 47 | |
| 48 | ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, |
| 49 | SND_SOC_CLOCK_IN); |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 50 | /* fsl_ssi lacks the set_sysclk ops */ |
| 51 | if (ret && ret != -EINVAL) { |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 52 | dev_err(cpu_dai->dev, |
| 53 | "Can't set the IMX_SSP_SYS_CLK CPU system clock.\n"); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 54 | return ret; |
| 55 | } |
| 56 | |
| 57 | return 0; |
| 58 | } |
| 59 | |
Bhumika Goyal | 5ace37b | 2017-03-14 00:42:22 +0530 | [diff] [blame] | 60 | static const struct snd_soc_ops eukrea_tlv320_snd_ops = { |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 61 | .hw_params = eukrea_tlv320_hw_params, |
| 62 | }; |
| 63 | |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 64 | SND_SOC_DAILINK_DEFS(hifi, |
| 65 | DAILINK_COMP_ARRAY(COMP_EMPTY()), |
Kuninori Morimoto | 68707c3 | 2019-06-28 10:47:14 +0900 | [diff] [blame] | 66 | DAILINK_COMP_ARRAY(COMP_CODEC(NULL, "tlv320aic23-hifi")), |
| 67 | DAILINK_COMP_ARRAY(COMP_EMPTY())); |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 68 | |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 69 | static struct snd_soc_dai_link eukrea_tlv320_dai = { |
| 70 | .name = "tlv320aic23", |
| 71 | .stream_name = "TLV320AIC23", |
Lars-Peter Clausen | 4de59db | 2015-01-01 17:16:12 +0100 | [diff] [blame] | 72 | .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF | |
Mark Brown | 4348be6 | 2021-09-21 22:35:27 +0100 | [diff] [blame] | 73 | SND_SOC_DAIFMT_CBP_CFP, |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 74 | .ops = &eukrea_tlv320_snd_ops, |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 75 | SND_SOC_DAILINK_REG(hifi), |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
| 78 | static struct snd_soc_card eukrea_tlv320 = { |
Axel Lin | 6aff8cc | 2011-12-23 14:47:08 +0800 | [diff] [blame] | 79 | .owner = THIS_MODULE, |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 80 | .dai_link = &eukrea_tlv320_dai, |
| 81 | .num_links = 1, |
| 82 | }; |
| 83 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 84 | static int eukrea_tlv320_probe(struct platform_device *pdev) |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 85 | { |
| 86 | int ret; |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 87 | int int_port = 0, ext_port; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 88 | struct device_node *np = pdev->dev.of_node; |
Takashi Iwai | 077661b | 2014-10-07 20:56:29 +0200 | [diff] [blame] | 89 | struct device_node *ssi_np = NULL, *codec_np = NULL; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 90 | |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 91 | eukrea_tlv320.dev = &pdev->dev; |
| 92 | if (np) { |
| 93 | ret = snd_soc_of_parse_card_name(&eukrea_tlv320, |
| 94 | "eukrea,model"); |
| 95 | if (ret) { |
| 96 | dev_err(&pdev->dev, |
| 97 | "eukrea,model node missing or invalid.\n"); |
| 98 | goto err; |
| 99 | } |
| 100 | |
| 101 | ssi_np = of_parse_phandle(pdev->dev.of_node, |
| 102 | "ssi-controller", 0); |
| 103 | if (!ssi_np) { |
| 104 | dev_err(&pdev->dev, |
| 105 | "ssi-controller missing or invalid.\n"); |
| 106 | ret = -ENODEV; |
| 107 | goto err; |
| 108 | } |
| 109 | |
| 110 | codec_np = of_parse_phandle(ssi_np, "codec-handle", 0); |
| 111 | if (codec_np) |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 112 | eukrea_tlv320_dai.codecs->of_node = codec_np; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 113 | else |
| 114 | dev_err(&pdev->dev, "codec-handle node missing or invalid.\n"); |
| 115 | |
| 116 | ret = of_property_read_u32(np, "fsl,mux-int-port", &int_port); |
| 117 | if (ret) { |
| 118 | dev_err(&pdev->dev, |
| 119 | "fsl,mux-int-port node missing or invalid.\n"); |
Wen Yang | b820d52 | 2019-02-26 16:17:51 +0800 | [diff] [blame] | 120 | goto err; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 121 | } |
| 122 | ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port); |
| 123 | if (ret) { |
| 124 | dev_err(&pdev->dev, |
| 125 | "fsl,mux-ext-port node missing or invalid.\n"); |
Wen Yang | b820d52 | 2019-02-26 16:17:51 +0800 | [diff] [blame] | 126 | goto err; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* |
| 130 | * The port numbering in the hardware manual starts at 1, while |
| 131 | * the audmux API expects it starts at 0. |
| 132 | */ |
| 133 | int_port--; |
| 134 | ext_port--; |
| 135 | |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 136 | eukrea_tlv320_dai.cpus->of_node = ssi_np; |
Kuninori Morimoto | 68707c3 | 2019-06-28 10:47:14 +0900 | [diff] [blame] | 137 | eukrea_tlv320_dai.platforms->of_node = ssi_np; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 138 | } else { |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 139 | eukrea_tlv320_dai.cpus->dai_name = "imx-ssi.0"; |
Kuninori Morimoto | 68707c3 | 2019-06-28 10:47:14 +0900 | [diff] [blame] | 140 | eukrea_tlv320_dai.platforms->name = "imx-ssi.0"; |
Kuninori Morimoto | 3219d9c | 2019-06-06 13:15:54 +0900 | [diff] [blame] | 141 | eukrea_tlv320_dai.codecs->name = "tlv320aic23-codec.0-001a"; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 142 | eukrea_tlv320.name = "cpuimx-audio"; |
| 143 | } |
| 144 | |
| 145 | if (machine_is_eukrea_cpuimx27() || |
| 146 | of_find_compatible_node(NULL, NULL, "fsl,imx21-audmux")) { |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 147 | imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, |
| 148 | IMX_AUDMUX_V1_PCR_SYN | |
| 149 | IMX_AUDMUX_V1_PCR_TFSDIR | |
| 150 | IMX_AUDMUX_V1_PCR_TCLKDIR | |
| 151 | IMX_AUDMUX_V1_PCR_RFSDIR | |
| 152 | IMX_AUDMUX_V1_PCR_RCLKDIR | |
| 153 | IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | |
| 154 | IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | |
| 155 | IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 156 | ); |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 157 | imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4, |
| 158 | IMX_AUDMUX_V1_PCR_SYN | |
| 159 | IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 160 | ); |
| 161 | } else if (machine_is_eukrea_cpuimx25sd() || |
| 162 | machine_is_eukrea_cpuimx35sd() || |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 163 | machine_is_eukrea_cpuimx51sd() || |
| 164 | of_find_compatible_node(NULL, NULL, "fsl,imx31-audmux")) { |
| 165 | if (!np) |
| 166 | ext_port = machine_is_eukrea_cpuimx25sd() ? |
| 167 | 4 : 3; |
| 168 | |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 169 | imx_audmux_v2_configure_port(int_port, |
| 170 | IMX_AUDMUX_V2_PTCR_SYN | |
| 171 | IMX_AUDMUX_V2_PTCR_TFSDIR | |
| 172 | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | |
| 173 | IMX_AUDMUX_V2_PTCR_TCLKDIR | |
| 174 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port), |
| 175 | IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 176 | ); |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 177 | imx_audmux_v2_configure_port(ext_port, |
| 178 | IMX_AUDMUX_V2_PTCR_SYN, |
| 179 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 180 | ); |
| 181 | } else { |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 182 | if (np) { |
Xiubo Li | dcfcf2c | 2015-08-12 14:38:18 +0800 | [diff] [blame] | 183 | /* The eukrea,asoc-tlv320 driver was explicitly |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 184 | * requested (through the device tree). |
| 185 | */ |
| 186 | dev_err(&pdev->dev, |
| 187 | "Missing or invalid audmux DT node.\n"); |
| 188 | return -ENODEV; |
| 189 | } else { |
| 190 | /* Return happy. |
| 191 | * We might run on a totally different machine. |
| 192 | */ |
| 193 | return 0; |
| 194 | } |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 195 | } |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 196 | |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 197 | ret = snd_soc_register_card(&eukrea_tlv320); |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 198 | err: |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 199 | if (ret) |
| 200 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); |
Fabio Estevam | 89dea48 | 2014-10-07 15:29:57 -0300 | [diff] [blame] | 201 | of_node_put(ssi_np); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 202 | |
| 203 | return ret; |
| 204 | } |
| 205 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 206 | static int eukrea_tlv320_remove(struct platform_device *pdev) |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 207 | { |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 208 | snd_soc_unregister_card(&eukrea_tlv320); |
| 209 | |
| 210 | return 0; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 213 | static const struct of_device_id imx_tlv320_dt_ids[] = { |
| 214 | { .compatible = "eukrea,asoc-tlv320"}, |
| 215 | { /* sentinel */ } |
| 216 | }; |
| 217 | MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids); |
| 218 | |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 219 | static struct platform_driver eukrea_tlv320_driver = { |
| 220 | .driver = { |
| 221 | .name = "eukrea_tlv320", |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 222 | .of_match_table = imx_tlv320_dt_ids, |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 223 | }, |
| 224 | .probe = eukrea_tlv320_probe, |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 225 | .remove = eukrea_tlv320_remove, |
| 226 | }; |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 227 | |
| 228 | module_platform_driver(eukrea_tlv320_driver); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 229 | |
| 230 | MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>"); |
| 231 | MODULE_DESCRIPTION("CPUIMX ALSA SoC driver"); |
| 232 | MODULE_LICENSE("GPL"); |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 233 | MODULE_ALIAS("platform:eukrea_tlv320"); |