5047e04d5b9bab5cf8ceef57642cf0c7fde244db
[openwrt/staging/ldir.git] / target / linux / at91 / patches-5.10 / 151-ASoC-mchp-i2s-mcc-Add-multi-channel-support-for-I2S-.patch
1 From 5bef4e8125d09443b5486971d5550ed285cde4b1 Mon Sep 17 00:00:00 2001
2 From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
3 Date: Mon, 1 Mar 2021 19:09:01 +0200
4 Subject: [PATCH 151/247] ASoC: mchp-i2s-mcc: Add multi-channel support for I2S
5 and LEFT_J formats
6
7 The latest I2S-MCC available in SAMA7G5 supports multi-channel for I2S and
8 Left-Justified formats. For this, the new version uses 8 (4 * 2) input and
9 output pins, with each pin being responsible for 2 channels. This sums up
10 to a total of 8 channels for synchronous capture and playback.
11
12 Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
13 Link: https://lore.kernel.org/r/20210301170905.835091-4-codrin.ciubotariu@microchip.com
14 Signed-off-by: Mark Brown <broonie@kernel.org>
15 ---
16 sound/soc/atmel/mchp-i2s-mcc.c | 38 ++++++++++++++++++++++++++++++++++
17 1 file changed, 38 insertions(+)
18
19 --- a/sound/soc/atmel/mchp-i2s-mcc.c
20 +++ b/sound/soc/atmel/mchp-i2s-mcc.c
21 @@ -16,6 +16,7 @@
22 #include <linux/clk.h>
23 #include <linux/mfd/syscon.h>
24 #include <linux/lcm.h>
25 +#include <linux/of_device.h>
26
27 #include <sound/core.h>
28 #include <sound/pcm.h>
29 @@ -225,6 +226,10 @@ static const struct regmap_config mchp_i
30 .max_register = MCHP_I2SMCC_VERSION,
31 };
32
33 +struct mchp_i2s_mcc_soc_data {
34 + unsigned int data_pin_pair_num;
35 +};
36 +
37 struct mchp_i2s_mcc_dev {
38 struct wait_queue_head wq_txrdy;
39 struct wait_queue_head wq_rxrdy;
40 @@ -232,6 +237,7 @@ struct mchp_i2s_mcc_dev {
41 struct regmap *regmap;
42 struct clk *pclk;
43 struct clk *gclk;
44 + const struct mchp_i2s_mcc_soc_data *soc;
45 struct snd_dmaengine_dai_dma_data playback;
46 struct snd_dmaengine_dai_dma_data capture;
47 unsigned int fmt;
48 @@ -549,6 +555,17 @@ static int mchp_i2s_mcc_hw_params(struct
49 }
50
51 if (dev->fmt & (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_LEFT_J)) {
52 + /* for I2S and LEFT_J one pin is needed for every 2 channels */
53 + if (channels > dev->soc->data_pin_pair_num * 2) {
54 + dev_err(dev->dev,
55 + "unsupported number of audio channels: %d\n",
56 + channels);
57 + return -EINVAL;
58 + }
59 +
60 + /* enable for interleaved format */
61 + mrb |= MCHP_I2SMCC_MRB_CRAMODE_REGULAR;
62 +
63 switch (channels) {
64 case 1:
65 if (is_playback)
66 @@ -558,6 +575,12 @@ static int mchp_i2s_mcc_hw_params(struct
67 break;
68 case 2:
69 break;
70 + case 4:
71 + mra |= MCHP_I2SMCC_MRA_WIRECFG_I2S_2_TDM_1;
72 + break;
73 + case 8:
74 + mra |= MCHP_I2SMCC_MRA_WIRECFG_I2S_4_TDM_2;
75 + break;
76 default:
77 dev_err(dev->dev, "unsupported number of audio channels\n");
78 return -EINVAL;
79 @@ -869,12 +892,22 @@ static const struct snd_soc_component_dr
80 };
81
82 #ifdef CONFIG_OF
83 +static struct mchp_i2s_mcc_soc_data mchp_i2s_mcc_sam9x60 = {
84 + .data_pin_pair_num = 1,
85 +};
86 +
87 +static struct mchp_i2s_mcc_soc_data mchp_i2s_mcc_sama7g5 = {
88 + .data_pin_pair_num = 4,
89 +};
90 +
91 static const struct of_device_id mchp_i2s_mcc_dt_ids[] = {
92 {
93 .compatible = "microchip,sam9x60-i2smcc",
94 + .data = &mchp_i2s_mcc_sam9x60,
95 },
96 {
97 .compatible = "microchip,sama7g5-i2smcc",
98 + .data = &mchp_i2s_mcc_sama7g5,
99 },
100 { /* sentinel */ }
101 };
102 @@ -932,6 +965,11 @@ static int mchp_i2s_mcc_probe(struct pla
103 dev->gclk = NULL;
104 }
105
106 + dev->soc = of_device_get_match_data(&pdev->dev);
107 + if (!dev->soc) {
108 + dev_err(&pdev->dev, "failed to get soc data\n");
109 + return -ENODEV;
110 + }
111 dev->dev = &pdev->dev;
112 dev->regmap = regmap;
113 platform_set_drvdata(pdev, dev);