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 | |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 18 | #include <linux/errno.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 19 | #include <linux/module.h> |
| 20 | #include <linux/moduleparam.h> |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 21 | #include <linux/of.h> |
| 22 | #include <linux/of_platform.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 23 | #include <linux/device.h> |
| 24 | #include <linux/i2c.h> |
| 25 | #include <sound/core.h> |
| 26 | #include <sound/pcm.h> |
| 27 | #include <sound/soc.h> |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 28 | #include <asm/mach-types.h> |
| 29 | |
| 30 | #include "../codecs/tlv320aic23.h" |
| 31 | #include "imx-ssi.h" |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 32 | #include "fsl_ssi.h" |
Shawn Guo | 3c77c29c | 2012-03-05 22:30:53 +0800 | [diff] [blame] | 33 | #include "imx-audmux.h" |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 34 | |
| 35 | #define CODEC_CLOCK 12000000 |
| 36 | |
| 37 | static int eukrea_tlv320_hw_params(struct snd_pcm_substream *substream, |
| 38 | struct snd_pcm_hw_params *params) |
| 39 | { |
| 40 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
Sascha Hauer | add330e | 2010-11-04 17:05:40 +0100 | [diff] [blame] | 41 | struct snd_soc_dai *codec_dai = rtd->codec_dai; |
| 42 | struct snd_soc_dai *cpu_dai = rtd->cpu_dai; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 43 | int ret; |
| 44 | |
| 45 | ret = snd_soc_dai_set_fmt(cpu_dai, SND_SOC_DAIFMT_I2S | |
| 46 | SND_SOC_DAIFMT_NB_NF | |
| 47 | SND_SOC_DAIFMT_CBM_CFM); |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 48 | /* fsl_ssi lacks the set_fmt ops. */ |
| 49 | if (ret && ret != -ENOTSUPP) { |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 50 | dev_err(cpu_dai->dev, |
| 51 | "Failed to set the cpu dai format.\n"); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 52 | return ret; |
| 53 | } |
| 54 | |
| 55 | ret = snd_soc_dai_set_fmt(codec_dai, SND_SOC_DAIFMT_I2S | |
| 56 | SND_SOC_DAIFMT_NB_NF | |
| 57 | SND_SOC_DAIFMT_CBM_CFM); |
| 58 | if (ret) { |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 59 | dev_err(cpu_dai->dev, |
| 60 | "Failed to set the codec format.\n"); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 61 | return ret; |
| 62 | } |
| 63 | |
| 64 | ret = snd_soc_dai_set_sysclk(codec_dai, 0, |
| 65 | CODEC_CLOCK, SND_SOC_CLOCK_OUT); |
| 66 | if (ret) { |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 67 | dev_err(cpu_dai->dev, |
| 68 | "Failed to set the codec sysclk.\n"); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 69 | return ret; |
| 70 | } |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 71 | |
Eric Bénard | 4379320 | 2010-06-17 15:44:01 +0200 | [diff] [blame] | 72 | 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] | 73 | |
| 74 | ret = snd_soc_dai_set_sysclk(cpu_dai, IMX_SSP_SYS_CLK, 0, |
| 75 | SND_SOC_CLOCK_IN); |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 76 | /* fsl_ssi lacks the set_sysclk ops */ |
| 77 | if (ret && ret != -EINVAL) { |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 78 | dev_err(cpu_dai->dev, |
| 79 | "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] | 80 | return ret; |
| 81 | } |
| 82 | |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static struct snd_soc_ops eukrea_tlv320_snd_ops = { |
| 87 | .hw_params = eukrea_tlv320_hw_params, |
| 88 | }; |
| 89 | |
| 90 | static struct snd_soc_dai_link eukrea_tlv320_dai = { |
| 91 | .name = "tlv320aic23", |
| 92 | .stream_name = "TLV320AIC23", |
Sascha Hauer | add330e | 2010-11-04 17:05:40 +0100 | [diff] [blame] | 93 | .codec_dai_name = "tlv320aic23-hifi", |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 94 | .ops = &eukrea_tlv320_snd_ops, |
| 95 | }; |
| 96 | |
| 97 | static struct snd_soc_card eukrea_tlv320 = { |
Axel Lin | 6aff8cc | 2011-12-23 14:47:08 +0800 | [diff] [blame] | 98 | .owner = THIS_MODULE, |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 99 | .dai_link = &eukrea_tlv320_dai, |
| 100 | .num_links = 1, |
| 101 | }; |
| 102 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 103 | static int eukrea_tlv320_probe(struct platform_device *pdev) |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 104 | { |
| 105 | int ret; |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 106 | int int_port = 0, ext_port; |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 107 | struct device_node *np = pdev->dev.of_node; |
| 108 | struct device_node *ssi_np, *codec_np; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 109 | |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 110 | eukrea_tlv320.dev = &pdev->dev; |
| 111 | if (np) { |
| 112 | ret = snd_soc_of_parse_card_name(&eukrea_tlv320, |
| 113 | "eukrea,model"); |
| 114 | if (ret) { |
| 115 | dev_err(&pdev->dev, |
| 116 | "eukrea,model node missing or invalid.\n"); |
| 117 | goto err; |
| 118 | } |
| 119 | |
| 120 | ssi_np = of_parse_phandle(pdev->dev.of_node, |
| 121 | "ssi-controller", 0); |
| 122 | if (!ssi_np) { |
| 123 | dev_err(&pdev->dev, |
| 124 | "ssi-controller missing or invalid.\n"); |
| 125 | ret = -ENODEV; |
| 126 | goto err; |
| 127 | } |
| 128 | |
| 129 | codec_np = of_parse_phandle(ssi_np, "codec-handle", 0); |
| 130 | if (codec_np) |
| 131 | eukrea_tlv320_dai.codec_of_node = codec_np; |
| 132 | else |
| 133 | dev_err(&pdev->dev, "codec-handle node missing or invalid.\n"); |
| 134 | |
| 135 | ret = of_property_read_u32(np, "fsl,mux-int-port", &int_port); |
| 136 | if (ret) { |
| 137 | dev_err(&pdev->dev, |
| 138 | "fsl,mux-int-port node missing or invalid.\n"); |
| 139 | return ret; |
| 140 | } |
| 141 | ret = of_property_read_u32(np, "fsl,mux-ext-port", &ext_port); |
| 142 | if (ret) { |
| 143 | dev_err(&pdev->dev, |
| 144 | "fsl,mux-ext-port node missing or invalid.\n"); |
| 145 | return ret; |
| 146 | } |
| 147 | |
| 148 | /* |
| 149 | * The port numbering in the hardware manual starts at 1, while |
| 150 | * the audmux API expects it starts at 0. |
| 151 | */ |
| 152 | int_port--; |
| 153 | ext_port--; |
| 154 | |
| 155 | eukrea_tlv320_dai.cpu_of_node = ssi_np; |
| 156 | eukrea_tlv320_dai.platform_of_node = ssi_np; |
| 157 | } else { |
| 158 | eukrea_tlv320_dai.cpu_dai_name = "imx-ssi.0"; |
| 159 | eukrea_tlv320_dai.platform_name = "imx-ssi.0"; |
| 160 | eukrea_tlv320_dai.codec_name = "tlv320aic23-codec.0-001a"; |
| 161 | eukrea_tlv320.name = "cpuimx-audio"; |
| 162 | } |
| 163 | |
| 164 | if (machine_is_eukrea_cpuimx27() || |
| 165 | of_find_compatible_node(NULL, NULL, "fsl,imx21-audmux")) { |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 166 | imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0, |
| 167 | IMX_AUDMUX_V1_PCR_SYN | |
| 168 | IMX_AUDMUX_V1_PCR_TFSDIR | |
| 169 | IMX_AUDMUX_V1_PCR_TCLKDIR | |
| 170 | IMX_AUDMUX_V1_PCR_RFSDIR | |
| 171 | IMX_AUDMUX_V1_PCR_RCLKDIR | |
| 172 | IMX_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | |
| 173 | IMX_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) | |
| 174 | IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 175 | ); |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 176 | imx_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4, |
| 177 | IMX_AUDMUX_V1_PCR_SYN | |
| 178 | IMX_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 179 | ); |
| 180 | } else if (machine_is_eukrea_cpuimx25sd() || |
| 181 | machine_is_eukrea_cpuimx35sd() || |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 182 | machine_is_eukrea_cpuimx51sd() || |
| 183 | of_find_compatible_node(NULL, NULL, "fsl,imx31-audmux")) { |
| 184 | if (!np) |
| 185 | ext_port = machine_is_eukrea_cpuimx25sd() ? |
| 186 | 4 : 3; |
| 187 | |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 188 | imx_audmux_v2_configure_port(int_port, |
| 189 | IMX_AUDMUX_V2_PTCR_SYN | |
| 190 | IMX_AUDMUX_V2_PTCR_TFSDIR | |
| 191 | IMX_AUDMUX_V2_PTCR_TFSEL(ext_port) | |
| 192 | IMX_AUDMUX_V2_PTCR_TCLKDIR | |
| 193 | IMX_AUDMUX_V2_PTCR_TCSEL(ext_port), |
| 194 | IMX_AUDMUX_V2_PDCR_RXDSEL(ext_port) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 195 | ); |
Shawn Guo | af4872f | 2012-03-05 22:30:54 +0800 | [diff] [blame] | 196 | imx_audmux_v2_configure_port(ext_port, |
| 197 | IMX_AUDMUX_V2_PTCR_SYN, |
| 198 | IMX_AUDMUX_V2_PDCR_RXDSEL(int_port) |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 199 | ); |
| 200 | } else { |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 201 | if (np) { |
| 202 | /* The eukrea,asoc-tlv320 driver was explicitely |
| 203 | * requested (through the device tree). |
| 204 | */ |
| 205 | dev_err(&pdev->dev, |
| 206 | "Missing or invalid audmux DT node.\n"); |
| 207 | return -ENODEV; |
| 208 | } else { |
| 209 | /* Return happy. |
| 210 | * We might run on a totally different machine. |
| 211 | */ |
| 212 | return 0; |
| 213 | } |
Shawn Guo | 60282ed | 2012-03-05 22:30:49 +0800 | [diff] [blame] | 214 | } |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 215 | |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 216 | ret = snd_soc_register_card(&eukrea_tlv320); |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 217 | err: |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 218 | if (ret) |
| 219 | dev_err(&pdev->dev, "snd_soc_register_card failed (%d)\n", ret); |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 220 | if (np) |
| 221 | of_node_put(ssi_np); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 222 | |
| 223 | return ret; |
| 224 | } |
| 225 | |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 226 | static int eukrea_tlv320_remove(struct platform_device *pdev) |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 227 | { |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 228 | snd_soc_unregister_card(&eukrea_tlv320); |
| 229 | |
| 230 | return 0; |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 233 | static const struct of_device_id imx_tlv320_dt_ids[] = { |
| 234 | { .compatible = "eukrea,asoc-tlv320"}, |
| 235 | { /* sentinel */ } |
| 236 | }; |
| 237 | MODULE_DEVICE_TABLE(of, imx_tlv320_dt_ids); |
| 238 | |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 239 | static struct platform_driver eukrea_tlv320_driver = { |
| 240 | .driver = { |
| 241 | .name = "eukrea_tlv320", |
| 242 | .owner = THIS_MODULE, |
Denis Carikli | 66f2329 | 2014-01-15 18:23:25 +0100 | [diff] [blame] | 243 | .of_match_table = imx_tlv320_dt_ids, |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 244 | }, |
| 245 | .probe = eukrea_tlv320_probe, |
Denis Carikli | 154bab1 | 2013-10-24 14:13:48 +0200 | [diff] [blame] | 246 | .remove = eukrea_tlv320_remove, |
| 247 | }; |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 248 | |
| 249 | module_platform_driver(eukrea_tlv320_driver); |
Eric Bénard | 9115788 | 2010-05-27 10:58:55 +0200 | [diff] [blame] | 250 | |
| 251 | MODULE_AUTHOR("Eric Bénard <eric@eukrea.com>"); |
| 252 | MODULE_DESCRIPTION("CPUIMX ALSA SoC driver"); |
| 253 | MODULE_LICENSE("GPL"); |
Fabio Estevam | da75c92 | 2012-09-22 12:27:31 -0300 | [diff] [blame] | 254 | MODULE_ALIAS("platform:eukrea_tlv320"); |