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