.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Copyright (C) 2012-2013, Analog Devices Inc. |
---|
3 | 4 | * Author: Lars-Peter Clausen <lars@metafoo.de> |
---|
4 | | - * |
---|
5 | | - * Licensed under the GPL-2. |
---|
6 | 5 | */ |
---|
7 | 6 | |
---|
8 | 7 | #include <linux/clk.h> |
---|
.. | .. |
---|
42 | 41 | struct regmap *regmap; |
---|
43 | 42 | struct clk *clk; |
---|
44 | 43 | struct clk *clk_ref; |
---|
| 44 | + |
---|
| 45 | + bool has_capture; |
---|
| 46 | + bool has_playback; |
---|
45 | 47 | |
---|
46 | 48 | struct snd_soc_dai_driver dai_driver; |
---|
47 | 49 | |
---|
.. | .. |
---|
136 | 138 | { |
---|
137 | 139 | struct axi_i2s *i2s = snd_soc_dai_get_drvdata(dai); |
---|
138 | 140 | |
---|
139 | | - snd_soc_dai_init_dma_data(dai, &i2s->playback_dma_data, |
---|
140 | | - &i2s->capture_dma_data); |
---|
| 141 | + snd_soc_dai_init_dma_data( |
---|
| 142 | + dai, |
---|
| 143 | + i2s->has_playback ? &i2s->playback_dma_data : NULL, |
---|
| 144 | + i2s->has_capture ? &i2s->capture_dma_data : NULL); |
---|
141 | 145 | |
---|
142 | 146 | return 0; |
---|
143 | 147 | } |
---|
.. | .. |
---|
151 | 155 | |
---|
152 | 156 | static struct snd_soc_dai_driver axi_i2s_dai = { |
---|
153 | 157 | .probe = axi_i2s_dai_probe, |
---|
154 | | - .playback = { |
---|
155 | | - .channels_min = 2, |
---|
156 | | - .channels_max = 2, |
---|
157 | | - .rates = SNDRV_PCM_RATE_KNOT, |
---|
158 | | - .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE, |
---|
159 | | - }, |
---|
160 | | - .capture = { |
---|
161 | | - .channels_min = 2, |
---|
162 | | - .channels_max = 2, |
---|
163 | | - .rates = SNDRV_PCM_RATE_KNOT, |
---|
164 | | - .formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE, |
---|
165 | | - }, |
---|
166 | 158 | .ops = &axi_i2s_dai_ops, |
---|
167 | 159 | .symmetric_rates = 1, |
---|
168 | 160 | }; |
---|
.. | .. |
---|
178 | 170 | .max_register = AXI_I2S_REG_STATUS, |
---|
179 | 171 | }; |
---|
180 | 172 | |
---|
| 173 | +static void axi_i2s_parse_of(struct axi_i2s *i2s, const struct device_node *np) |
---|
| 174 | +{ |
---|
| 175 | + struct property *dma_names; |
---|
| 176 | + const char *dma_name; |
---|
| 177 | + |
---|
| 178 | + of_property_for_each_string(np, "dma-names", dma_names, dma_name) { |
---|
| 179 | + if (strcmp(dma_name, "rx") == 0) |
---|
| 180 | + i2s->has_capture = true; |
---|
| 181 | + if (strcmp(dma_name, "tx") == 0) |
---|
| 182 | + i2s->has_playback = true; |
---|
| 183 | + } |
---|
| 184 | +} |
---|
| 185 | + |
---|
181 | 186 | static int axi_i2s_probe(struct platform_device *pdev) |
---|
182 | 187 | { |
---|
183 | 188 | struct resource *res; |
---|
.. | .. |
---|
190 | 195 | return -ENOMEM; |
---|
191 | 196 | |
---|
192 | 197 | platform_set_drvdata(pdev, i2s); |
---|
| 198 | + |
---|
| 199 | + axi_i2s_parse_of(i2s, pdev->dev.of_node); |
---|
193 | 200 | |
---|
194 | 201 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
195 | 202 | base = devm_ioremap_resource(&pdev->dev, res); |
---|
.. | .. |
---|
213 | 220 | if (ret) |
---|
214 | 221 | return ret; |
---|
215 | 222 | |
---|
216 | | - i2s->playback_dma_data.addr = res->start + AXI_I2S_REG_TX_FIFO; |
---|
217 | | - i2s->playback_dma_data.addr_width = 4; |
---|
218 | | - i2s->playback_dma_data.maxburst = 1; |
---|
| 223 | + if (i2s->has_playback) { |
---|
| 224 | + axi_i2s_dai.playback.channels_min = 2; |
---|
| 225 | + axi_i2s_dai.playback.channels_max = 2; |
---|
| 226 | + axi_i2s_dai.playback.rates = SNDRV_PCM_RATE_KNOT; |
---|
| 227 | + axi_i2s_dai.playback.formats = |
---|
| 228 | + SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE; |
---|
219 | 229 | |
---|
220 | | - i2s->capture_dma_data.addr = res->start + AXI_I2S_REG_RX_FIFO; |
---|
221 | | - i2s->capture_dma_data.addr_width = 4; |
---|
222 | | - i2s->capture_dma_data.maxburst = 1; |
---|
| 230 | + i2s->playback_dma_data.addr = res->start + AXI_I2S_REG_TX_FIFO; |
---|
| 231 | + i2s->playback_dma_data.addr_width = 4; |
---|
| 232 | + i2s->playback_dma_data.maxburst = 1; |
---|
| 233 | + } |
---|
| 234 | + |
---|
| 235 | + if (i2s->has_capture) { |
---|
| 236 | + axi_i2s_dai.capture.channels_min = 2; |
---|
| 237 | + axi_i2s_dai.capture.channels_max = 2; |
---|
| 238 | + axi_i2s_dai.capture.rates = SNDRV_PCM_RATE_KNOT; |
---|
| 239 | + axi_i2s_dai.capture.formats = |
---|
| 240 | + SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_U32_LE; |
---|
| 241 | + |
---|
| 242 | + i2s->capture_dma_data.addr = res->start + AXI_I2S_REG_RX_FIFO; |
---|
| 243 | + i2s->capture_dma_data.addr_width = 4; |
---|
| 244 | + i2s->capture_dma_data.maxburst = 1; |
---|
| 245 | + } |
---|
223 | 246 | |
---|
224 | 247 | i2s->ratnum.num = clk_get_rate(i2s->clk_ref) / 2 / AXI_I2S_BITS_PER_FRAME; |
---|
225 | 248 | i2s->ratnum.den_step = 1; |
---|
.. | .. |
---|
240 | 263 | if (ret) |
---|
241 | 264 | goto err_clk_disable; |
---|
242 | 265 | |
---|
| 266 | + dev_info(&pdev->dev, "probed, capture %s, playback %s\n", |
---|
| 267 | + i2s->has_capture ? "enabled" : "disabled", |
---|
| 268 | + i2s->has_playback ? "enabled" : "disabled"); |
---|
| 269 | + |
---|
243 | 270 | return 0; |
---|
244 | 271 | |
---|
245 | 272 | err_clk_disable: |
---|