Andra Danciu | eed9bb2 | 2019-04-05 14:50:04 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // |
| 3 | // Freescale MPC8610HPCD ALSA SoC Machine driver |
| 4 | // |
| 5 | // Author: Timur Tabi <timur@freescale.com> |
| 6 | // |
| 7 | // Copyright 2007-2010 Freescale Semiconductor, Inc. |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/interrupt.h> |
Scott Wood | 9484865 | 2015-09-19 23:29:53 -0500 | [diff] [blame] | 11 | #include <linux/fsl/guts.h> |
Rob Herring | 5af5073 | 2013-09-17 14:28:33 -0500 | [diff] [blame] | 12 | #include <linux/of_address.h> |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 13 | #include <linux/of_device.h> |
Timur Tabi | 38fec72 | 2010-08-19 15:26:58 -0500 | [diff] [blame] | 14 | #include <linux/slab.h> |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 15 | #include <sound/soc.h> |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 16 | |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 17 | #include "fsl_dma.h" |
| 18 | #include "fsl_ssi.h" |
Shawn Guo | 60aae8d | 2012-03-16 16:56:40 +0800 | [diff] [blame] | 19 | #include "fsl_utils.h" |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 20 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 21 | /* There's only one global utilities register */ |
| 22 | static phys_addr_t guts_phys; |
| 23 | |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 24 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 25 | * mpc8610_hpcd_data: machine-specific ASoC device data |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 26 | * |
| 27 | * This structure contains data for a single sound platform device on an |
| 28 | * MPC8610 HPCD. Some of the data is taken from the device tree. |
| 29 | */ |
| 30 | struct mpc8610_hpcd_data { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 31 | struct snd_soc_dai_link dai[2]; |
| 32 | struct snd_soc_card card; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 33 | unsigned int dai_format; |
| 34 | unsigned int codec_clk_direction; |
| 35 | unsigned int cpu_clk_direction; |
| 36 | unsigned int clk_frequency; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 37 | unsigned int ssi_id; /* 0 = SSI1, 1 = SSI2, etc */ |
| 38 | unsigned int dma_id[2]; /* 0 = DMA1, 1 = DMA2, etc */ |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 39 | unsigned int dma_channel_id[2]; /* 0 = ch 0, 1 = ch 1, etc*/ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 40 | char codec_dai_name[DAI_NAME_SIZE]; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 41 | char platform_name[2][DAI_NAME_SIZE]; /* One for each DMA channel */ |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 45 | * mpc8610_hpcd_machine_probe: initialize the board |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 46 | * |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 47 | * This function is used to initialize the board-specific hardware. |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 48 | * |
| 49 | * Here we program the DMACR and PMUXCR registers. |
| 50 | */ |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 51 | static int mpc8610_hpcd_machine_probe(struct snd_soc_card *card) |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 52 | { |
| 53 | struct mpc8610_hpcd_data *machine_data = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 54 | container_of(card, struct mpc8610_hpcd_data, card); |
Timur Tabi | 9cb6abc | 2012-03-19 11:06:39 -0500 | [diff] [blame] | 55 | struct ccsr_guts __iomem *guts; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 56 | |
Timur Tabi | 9cb6abc | 2012-03-19 11:06:39 -0500 | [diff] [blame] | 57 | guts = ioremap(guts_phys, sizeof(struct ccsr_guts)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 58 | if (!guts) { |
| 59 | dev_err(card->dev, "could not map global utilities\n"); |
| 60 | return -ENOMEM; |
| 61 | } |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 62 | |
| 63 | /* Program the signal routing between the SSI and the DMA */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 64 | guts_set_dmacr(guts, machine_data->dma_id[0], |
| 65 | machine_data->dma_channel_id[0], |
| 66 | CCSR_GUTS_DMACR_DEV_SSI); |
| 67 | guts_set_dmacr(guts, machine_data->dma_id[1], |
| 68 | machine_data->dma_channel_id[1], |
| 69 | CCSR_GUTS_DMACR_DEV_SSI); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 70 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 71 | guts_set_pmuxcr_dma(guts, machine_data->dma_id[0], |
| 72 | machine_data->dma_channel_id[0], 0); |
| 73 | guts_set_pmuxcr_dma(guts, machine_data->dma_id[1], |
| 74 | machine_data->dma_channel_id[1], 0); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 75 | |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 76 | switch (machine_data->ssi_id) { |
| 77 | case 0: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 78 | clrsetbits_be32(&guts->pmuxcr, |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 79 | CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_SSI); |
| 80 | break; |
| 81 | case 1: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 82 | clrsetbits_be32(&guts->pmuxcr, |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 83 | CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_SSI); |
| 84 | break; |
| 85 | } |
| 86 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 87 | iounmap(guts); |
| 88 | |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * mpc8610_hpcd_startup: program the board with various hardware parameters |
| 94 | * |
| 95 | * This function takes board-specific information, like clock frequencies |
| 96 | * and serial data formats, and passes that information to the codec and |
| 97 | * transport drivers. |
| 98 | */ |
| 99 | static int mpc8610_hpcd_startup(struct snd_pcm_substream *substream) |
| 100 | { |
Kuninori Morimoto | 9f5f078 | 2020-07-20 10:18:38 +0900 | [diff] [blame] | 101 | struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 102 | struct mpc8610_hpcd_data *machine_data = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 103 | container_of(rtd->card, struct mpc8610_hpcd_data, card); |
| 104 | struct device *dev = rtd->card->dev; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 105 | int ret = 0; |
| 106 | |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 107 | /* Tell the codec driver what the serial protocol is. */ |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 108 | ret = snd_soc_dai_set_fmt(asoc_rtd_to_codec(rtd, 0), machine_data->dai_format); |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 109 | if (ret < 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 110 | dev_err(dev, "could not set codec driver audio format\n"); |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 111 | return ret; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* |
| 115 | * Tell the codec driver what the MCLK frequency is, and whether it's |
| 116 | * a slave or master. |
| 117 | */ |
Kuninori Morimoto | 17198ae | 2020-03-23 14:18:30 +0900 | [diff] [blame] | 118 | ret = snd_soc_dai_set_sysclk(asoc_rtd_to_codec(rtd, 0), 0, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 119 | machine_data->clk_frequency, |
| 120 | machine_data->codec_clk_direction); |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 121 | if (ret < 0) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 122 | dev_err(dev, "could not set codec driver clock params\n"); |
Liam Girdwood | 64105cf | 2008-07-08 13:19:18 +0100 | [diff] [blame] | 123 | return ret; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | return 0; |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * mpc8610_hpcd_machine_remove: Remove the sound device |
| 131 | * |
| 132 | * This function is called to remove the sound device for one SSI. We |
| 133 | * de-program the DMACR and PMUXCR register. |
| 134 | */ |
Mark Brown | e7361ec | 2011-01-26 14:17:20 +0000 | [diff] [blame] | 135 | static int mpc8610_hpcd_machine_remove(struct snd_soc_card *card) |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 136 | { |
| 137 | struct mpc8610_hpcd_data *machine_data = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 138 | container_of(card, struct mpc8610_hpcd_data, card); |
Timur Tabi | 9cb6abc | 2012-03-19 11:06:39 -0500 | [diff] [blame] | 139 | struct ccsr_guts __iomem *guts; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 140 | |
Timur Tabi | 9cb6abc | 2012-03-19 11:06:39 -0500 | [diff] [blame] | 141 | guts = ioremap(guts_phys, sizeof(struct ccsr_guts)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 142 | if (!guts) { |
| 143 | dev_err(card->dev, "could not map global utilities\n"); |
| 144 | return -ENOMEM; |
| 145 | } |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 146 | |
| 147 | /* Restore the signal routing */ |
| 148 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 149 | guts_set_dmacr(guts, machine_data->dma_id[0], |
| 150 | machine_data->dma_channel_id[0], 0); |
| 151 | guts_set_dmacr(guts, machine_data->dma_id[1], |
| 152 | machine_data->dma_channel_id[1], 0); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 153 | |
| 154 | switch (machine_data->ssi_id) { |
| 155 | case 0: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 156 | clrsetbits_be32(&guts->pmuxcr, |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 157 | CCSR_GUTS_PMUXCR_SSI1_MASK, CCSR_GUTS_PMUXCR_SSI1_LA); |
| 158 | break; |
| 159 | case 1: |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 160 | clrsetbits_be32(&guts->pmuxcr, |
Timur Tabi | 8354499 | 2008-06-13 14:02:31 -0500 | [diff] [blame] | 161 | CCSR_GUTS_PMUXCR_SSI2_MASK, CCSR_GUTS_PMUXCR_SSI2_LA); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 162 | break; |
| 163 | } |
| 164 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 165 | iounmap(guts); |
| 166 | |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 167 | return 0; |
| 168 | } |
| 169 | |
| 170 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 171 | * mpc8610_hpcd_ops: ASoC machine driver operations |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 172 | */ |
Bhumika Goyal | 5ace37b | 2017-03-14 00:42:22 +0530 | [diff] [blame] | 173 | static const struct snd_soc_ops mpc8610_hpcd_ops = { |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 174 | .startup = mpc8610_hpcd_startup, |
| 175 | }; |
| 176 | |
| 177 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 178 | * mpc8610_hpcd_probe: platform probe function for the machine driver |
| 179 | * |
| 180 | * Although this is a machine driver, the SSI node is the "master" node with |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 181 | * respect to audio hardware connections. Therefore, we create a new ASoC |
| 182 | * device for each new SSI node that has a codec attached. |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 183 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 184 | static int mpc8610_hpcd_probe(struct platform_device *pdev) |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 185 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 186 | struct device *dev = pdev->dev.parent; |
Timur Tabi | 38fec72 | 2010-08-19 15:26:58 -0500 | [diff] [blame] | 187 | /* ssi_pdev is the platform device for the SSI node that probed us */ |
Geliang Tang | bb18f09 | 2015-12-23 21:03:39 +0800 | [diff] [blame] | 188 | struct platform_device *ssi_pdev = to_platform_device(dev); |
Timur Tabi | 38fec72 | 2010-08-19 15:26:58 -0500 | [diff] [blame] | 189 | struct device_node *np = ssi_pdev->dev.of_node; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 190 | struct device_node *codec_np = NULL; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 191 | struct mpc8610_hpcd_data *machine_data; |
Kuninori Morimoto | 6aa7b40 | 2019-06-06 13:15:25 +0900 | [diff] [blame] | 192 | struct snd_soc_dai_link_component *comp; |
Pierre-Louis Bossart | f5036db | 2021-02-19 17:29:36 -0600 | [diff] [blame] | 193 | int ret; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 194 | const char *sprop; |
| 195 | const u32 *iprop; |
| 196 | |
Shawn Guo | 7c59bc5 | 2012-02-24 22:09:37 +0800 | [diff] [blame] | 197 | /* Find the codec node for this SSI. */ |
| 198 | codec_np = of_parse_phandle(np, "codec-handle", 0); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 199 | if (!codec_np) { |
| 200 | dev_err(dev, "invalid codec node\n"); |
| 201 | return -EINVAL; |
| 202 | } |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 203 | |
| 204 | machine_data = kzalloc(sizeof(struct mpc8610_hpcd_data), GFP_KERNEL); |
Julia Lawall | c09f5ca | 2011-08-20 09:02:01 +0200 | [diff] [blame] | 205 | if (!machine_data) { |
| 206 | ret = -ENOMEM; |
| 207 | goto error_alloc; |
| 208 | } |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 209 | |
Kuninori Morimoto | 6aa7b40 | 2019-06-06 13:15:25 +0900 | [diff] [blame] | 210 | comp = devm_kzalloc(&pdev->dev, 6 * sizeof(*comp), GFP_KERNEL); |
| 211 | if (!comp) { |
| 212 | ret = -ENOMEM; |
| 213 | goto error_alloc; |
| 214 | } |
| 215 | |
| 216 | machine_data->dai[0].cpus = &comp[0]; |
| 217 | machine_data->dai[0].codecs = &comp[1]; |
| 218 | machine_data->dai[0].platforms = &comp[2]; |
| 219 | |
| 220 | machine_data->dai[0].num_cpus = 1; |
| 221 | machine_data->dai[0].num_codecs = 1; |
| 222 | machine_data->dai[0].num_platforms = 1; |
| 223 | |
| 224 | machine_data->dai[1].cpus = &comp[3]; |
| 225 | machine_data->dai[1].codecs = &comp[4]; |
| 226 | machine_data->dai[1].platforms = &comp[5]; |
| 227 | |
| 228 | machine_data->dai[1].num_cpus = 1; |
| 229 | machine_data->dai[1].num_codecs = 1; |
| 230 | machine_data->dai[1].num_platforms = 1; |
| 231 | |
| 232 | machine_data->dai[0].cpus->dai_name = dev_name(&ssi_pdev->dev); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 233 | machine_data->dai[0].ops = &mpc8610_hpcd_ops; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 234 | |
Shawn Guo | 8f549d7 | 2012-03-16 16:56:41 +0800 | [diff] [blame] | 235 | /* ASoC core can match codec with device node */ |
Kuninori Morimoto | 6aa7b40 | 2019-06-06 13:15:25 +0900 | [diff] [blame] | 236 | machine_data->dai[0].codecs->of_node = codec_np; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 237 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 238 | /* The DAI name from the codec (snd_soc_dai_driver.name) */ |
Kuninori Morimoto | 6aa7b40 | 2019-06-06 13:15:25 +0900 | [diff] [blame] | 239 | machine_data->dai[0].codecs->dai_name = "cs4270-hifi"; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 240 | |
| 241 | /* We register two DAIs per SSI, one for playback and the other for |
| 242 | * capture. Currently, we only support codecs that have one DAI for |
| 243 | * both playback and capture. |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 244 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 245 | memcpy(&machine_data->dai[1], &machine_data->dai[0], |
| 246 | sizeof(struct snd_soc_dai_link)); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 247 | |
| 248 | /* Get the device ID */ |
| 249 | iprop = of_get_property(np, "cell-index", NULL); |
| 250 | if (!iprop) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 251 | dev_err(&pdev->dev, "cell-index property not found\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 252 | ret = -EINVAL; |
| 253 | goto error; |
| 254 | } |
Timur Tabi | 147dfe9 | 2011-06-08 15:02:55 -0500 | [diff] [blame] | 255 | machine_data->ssi_id = be32_to_cpup(iprop); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 256 | |
| 257 | /* Get the serial format and clock direction. */ |
| 258 | sprop = of_get_property(np, "fsl,mode", NULL); |
| 259 | if (!sprop) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 260 | dev_err(&pdev->dev, "fsl,mode property not found\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 261 | ret = -EINVAL; |
| 262 | goto error; |
| 263 | } |
| 264 | |
| 265 | if (strcasecmp(sprop, "i2s-slave") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 266 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 267 | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBP_CFP; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 268 | machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT; |
| 269 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN; |
| 270 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 271 | /* In i2s-slave mode, the codec has its own clock source, so we |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 272 | * need to get the frequency from the device tree and pass it to |
| 273 | * the codec driver. |
| 274 | */ |
| 275 | iprop = of_get_property(codec_np, "clock-frequency", NULL); |
| 276 | if (!iprop || !*iprop) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 277 | dev_err(&pdev->dev, "codec bus-frequency " |
| 278 | "property is missing or invalid\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 279 | ret = -EINVAL; |
| 280 | goto error; |
| 281 | } |
Timur Tabi | 147dfe9 | 2011-06-08 15:02:55 -0500 | [diff] [blame] | 282 | machine_data->clk_frequency = be32_to_cpup(iprop); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 283 | } else if (strcasecmp(sprop, "i2s-master") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 284 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 285 | SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBC_CFC; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 286 | machine_data->codec_clk_direction = SND_SOC_CLOCK_IN; |
| 287 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT; |
| 288 | } else if (strcasecmp(sprop, "lj-slave") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 289 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 290 | SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBP_CFP; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 291 | machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT; |
| 292 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN; |
| 293 | } else if (strcasecmp(sprop, "lj-master") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 294 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 295 | SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_CBC_CFC; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 296 | machine_data->codec_clk_direction = SND_SOC_CLOCK_IN; |
| 297 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT; |
Roel Kluin | e5c2157 | 2008-02-22 18:41:41 +0100 | [diff] [blame] | 298 | } else if (strcasecmp(sprop, "rj-slave") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 299 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 300 | SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBP_CFP; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 301 | machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT; |
| 302 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN; |
| 303 | } else if (strcasecmp(sprop, "rj-master") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 304 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 305 | SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_CBC_CFC; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 306 | machine_data->codec_clk_direction = SND_SOC_CLOCK_IN; |
| 307 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT; |
| 308 | } else if (strcasecmp(sprop, "ac97-slave") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 309 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 310 | SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBP_CFP; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 311 | machine_data->codec_clk_direction = SND_SOC_CLOCK_OUT; |
| 312 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_IN; |
| 313 | } else if (strcasecmp(sprop, "ac97-master") == 0) { |
Timur Tabi | 380c883 | 2011-11-22 14:38:59 -0600 | [diff] [blame] | 314 | machine_data->dai_format = |
Mark Brown | 8a7f299 | 2021-09-21 22:35:40 +0100 | [diff] [blame] | 315 | SND_SOC_DAIFMT_AC97 | SND_SOC_DAIFMT_CBC_CFC; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 316 | machine_data->codec_clk_direction = SND_SOC_CLOCK_IN; |
| 317 | machine_data->cpu_clk_direction = SND_SOC_CLOCK_OUT; |
| 318 | } else { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 319 | dev_err(&pdev->dev, |
| 320 | "unrecognized fsl,mode property '%s'\n", sprop); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 321 | ret = -EINVAL; |
| 322 | goto error; |
| 323 | } |
| 324 | |
| 325 | if (!machine_data->clk_frequency) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 326 | dev_err(&pdev->dev, "unknown clock frequency\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 327 | ret = -EINVAL; |
| 328 | goto error; |
| 329 | } |
| 330 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 331 | /* Find the playback DMA channel to use. */ |
Kuninori Morimoto | 6aa7b40 | 2019-06-06 13:15:25 +0900 | [diff] [blame] | 332 | machine_data->dai[0].platforms->name = machine_data->platform_name[0]; |
Shawn Guo | 60aae8d | 2012-03-16 16:56:40 +0800 | [diff] [blame] | 333 | ret = fsl_asoc_get_dma_channel(np, "fsl,playback-dma", |
| 334 | &machine_data->dai[0], |
| 335 | &machine_data->dma_channel_id[0], |
| 336 | &machine_data->dma_id[0]); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 337 | if (ret) { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 338 | dev_err(&pdev->dev, "missing/invalid playback DMA phandle\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 339 | goto error; |
| 340 | } |
| 341 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 342 | /* Find the capture DMA channel to use. */ |
Kuninori Morimoto | 6aa7b40 | 2019-06-06 13:15:25 +0900 | [diff] [blame] | 343 | machine_data->dai[1].platforms->name = machine_data->platform_name[1]; |
Shawn Guo | 60aae8d | 2012-03-16 16:56:40 +0800 | [diff] [blame] | 344 | ret = fsl_asoc_get_dma_channel(np, "fsl,capture-dma", |
| 345 | &machine_data->dai[1], |
| 346 | &machine_data->dma_channel_id[1], |
| 347 | &machine_data->dma_id[1]); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 348 | if (ret) { |
| 349 | dev_err(&pdev->dev, "missing/invalid capture DMA phandle\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 350 | goto error; |
| 351 | } |
| 352 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 353 | /* Initialize our DAI data structure. */ |
| 354 | machine_data->dai[0].stream_name = "playback"; |
| 355 | machine_data->dai[1].stream_name = "capture"; |
| 356 | machine_data->dai[0].name = machine_data->dai[0].stream_name; |
| 357 | machine_data->dai[1].name = machine_data->dai[1].stream_name; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 358 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 359 | machine_data->card.probe = mpc8610_hpcd_machine_probe; |
| 360 | machine_data->card.remove = mpc8610_hpcd_machine_remove; |
| 361 | machine_data->card.name = pdev->name; /* The platform driver name */ |
Timur Tabi | 13c57e5 | 2012-09-14 16:14:34 -0500 | [diff] [blame] | 362 | machine_data->card.owner = THIS_MODULE; |
| 363 | machine_data->card.dev = &pdev->dev; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 364 | machine_data->card.num_links = 2; |
| 365 | machine_data->card.dai_link = machine_data->dai; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 366 | |
Timur Tabi | 13c57e5 | 2012-09-14 16:14:34 -0500 | [diff] [blame] | 367 | /* Register with ASoC */ |
| 368 | ret = snd_soc_register_card(&machine_data->card); |
| 369 | if (ret) { |
| 370 | dev_err(&pdev->dev, "could not register card\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 371 | goto error; |
| 372 | } |
| 373 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 374 | of_node_put(codec_np); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 375 | |
| 376 | return 0; |
| 377 | |
| 378 | error: |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 379 | kfree(machine_data); |
Julia Lawall | c09f5ca | 2011-08-20 09:02:01 +0200 | [diff] [blame] | 380 | error_alloc: |
| 381 | of_node_put(codec_np); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 386 | * mpc8610_hpcd_remove: remove the platform device |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 387 | * |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 388 | * This function is called when the platform device is removed. |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 389 | */ |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 390 | static int mpc8610_hpcd_remove(struct platform_device *pdev) |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 391 | { |
Timur Tabi | 13c57e5 | 2012-09-14 16:14:34 -0500 | [diff] [blame] | 392 | struct snd_soc_card *card = platform_get_drvdata(pdev); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 393 | struct mpc8610_hpcd_data *machine_data = |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 394 | container_of(card, struct mpc8610_hpcd_data, card); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 395 | |
Timur Tabi | 13c57e5 | 2012-09-14 16:14:34 -0500 | [diff] [blame] | 396 | snd_soc_unregister_card(card); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 397 | kfree(machine_data); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 402 | static struct platform_driver mpc8610_hpcd_driver = { |
| 403 | .probe = mpc8610_hpcd_probe, |
Bill Pemberton | a0a3d51 | 2012-12-07 09:26:16 -0500 | [diff] [blame] | 404 | .remove = mpc8610_hpcd_remove, |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 405 | .driver = { |
Shawn Guo | 2b81ec6 | 2012-03-09 00:59:46 +0800 | [diff] [blame] | 406 | /* The name must match 'compatible' property in the device tree, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 407 | * in lowercase letters. |
| 408 | */ |
| 409 | .name = "snd-soc-mpc8610hpcd", |
Grant Likely | 4018294 | 2010-04-13 16:13:02 -0700 | [diff] [blame] | 410 | }, |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 411 | }; |
| 412 | |
| 413 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 414 | * mpc8610_hpcd_init: machine driver initialization. |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 415 | * |
| 416 | * This function is called when this module is loaded. |
| 417 | */ |
| 418 | static int __init mpc8610_hpcd_init(void) |
| 419 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 420 | struct device_node *guts_np; |
| 421 | struct resource res; |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 422 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 423 | pr_info("Freescale MPC8610 HPCD ALSA SoC machine driver\n"); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 424 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 425 | /* Get the physical address of the global utilities registers */ |
| 426 | guts_np = of_find_compatible_node(NULL, NULL, "fsl,mpc8610-guts"); |
| 427 | if (of_address_to_resource(guts_np, 0, &res)) { |
| 428 | pr_err("mpc8610-hpcd: missing/invalid global utilities node\n"); |
Liao Pingfang | a5911ac | 2020-07-07 19:47:47 +0800 | [diff] [blame] | 429 | of_node_put(guts_np); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 430 | return -EINVAL; |
| 431 | } |
| 432 | guts_phys = res.start; |
Liao Pingfang | a5911ac | 2020-07-07 19:47:47 +0800 | [diff] [blame] | 433 | of_node_put(guts_np); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 434 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 435 | return platform_driver_register(&mpc8610_hpcd_driver); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | /** |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 439 | * mpc8610_hpcd_exit: machine driver exit |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 440 | * |
| 441 | * This function is called when this driver is unloaded. |
| 442 | */ |
| 443 | static void __exit mpc8610_hpcd_exit(void) |
| 444 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 445 | platform_driver_unregister(&mpc8610_hpcd_driver); |
Timur Tabi | 17467f2 | 2008-01-11 18:15:26 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | module_init(mpc8610_hpcd_init); |
| 449 | module_exit(mpc8610_hpcd_exit); |
| 450 | |
| 451 | MODULE_AUTHOR("Timur Tabi <timur@freescale.com>"); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 452 | MODULE_DESCRIPTION("Freescale MPC8610 HPCD ALSA SoC machine driver"); |
| 453 | MODULE_LICENSE("GPL v2"); |