kernel: bump 5.10 to 5.10.103
[openwrt/openwrt.git] / target / linux / at91 / patches-5.10 / 152-ASoC-mchp-i2s-mcc-Add-support-to-select-TDM-pins.patch
1 From 2bbdc5b38603384996271a8817b0578a2360af2f Mon Sep 17 00:00:00 2001
2 From: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
3 Date: Mon, 1 Mar 2021 19:09:03 +0200
4 Subject: [PATCH 152/247] ASoC: mchp-i2s-mcc: Add support to select TDM pins
5
6 SAMA7G5's I2S-MCC has 4 pairs of DIN/DOUT pins. Since TDM only uses a
7 single pair of pins for synchronous capture and playback, the controller
8 needs to be told which of the pair is connected. This can be mentioned
9 using the "microchip,tdm-data-pair" property from DT. The property is
10 optional, useful only if TDM is used. If it's missing, DIN/DOUT 0 pins
11 will be used by default.
12
13 Signed-off-by: Codrin Ciubotariu <codrin.ciubotariu@microchip.com>
14 Link: https://lore.kernel.org/r/20210301170905.835091-6-codrin.ciubotariu@microchip.com
15 Signed-off-by: Mark Brown <broonie@kernel.org>
16 ---
17 sound/soc/atmel/mchp-i2s-mcc.c | 52 +++++++++++++++++++++++++++++++---
18 1 file changed, 48 insertions(+), 4 deletions(-)
19
20 --- a/sound/soc/atmel/mchp-i2s-mcc.c
21 +++ b/sound/soc/atmel/mchp-i2s-mcc.c
22 @@ -100,6 +100,8 @@
23 #define MCHP_I2SMCC_MRA_DATALENGTH_8_BITS_COMPACT (7 << 1)
24
25 #define MCHP_I2SMCC_MRA_WIRECFG_MASK GENMASK(5, 4)
26 +#define MCHP_I2SMCC_MRA_WIRECFG_TDM(pin) (((pin) << 4) & \
27 + MCHP_I2SMCC_MRA_WIRECFG_MASK)
28 #define MCHP_I2SMCC_MRA_WIRECFG_I2S_1_TDM_0 (0 << 4)
29 #define MCHP_I2SMCC_MRA_WIRECFG_I2S_2_TDM_1 (1 << 4)
30 #define MCHP_I2SMCC_MRA_WIRECFG_I2S_4_TDM_2 (2 << 4)
31 @@ -245,6 +247,7 @@ struct mchp_i2s_mcc_dev {
32 unsigned int frame_length;
33 int tdm_slots;
34 int channels;
35 + u8 tdm_data_pair;
36 unsigned int gclk_use:1;
37 unsigned int gclk_running:1;
38 unsigned int tx_rdy:1;
39 @@ -589,6 +592,8 @@ static int mchp_i2s_mcc_hw_params(struct
40 if (!frame_length)
41 frame_length = 2 * params_physical_width(params);
42 } else if (dev->fmt & SND_SOC_DAIFMT_DSP_A) {
43 + mra |= MCHP_I2SMCC_MRA_WIRECFG_TDM(dev->tdm_data_pair);
44 +
45 if (dev->tdm_slots) {
46 if (channels % 2 && channels * 2 <= dev->tdm_slots) {
47 /*
48 @@ -914,6 +919,45 @@ static const struct of_device_id mchp_i2
49 MODULE_DEVICE_TABLE(of, mchp_i2s_mcc_dt_ids);
50 #endif
51
52 +static int mchp_i2s_mcc_soc_data_parse(struct platform_device *pdev,
53 + struct mchp_i2s_mcc_dev *dev)
54 +{
55 + int err;
56 +
57 + if (!dev->soc) {
58 + dev_err(&pdev->dev, "failed to get soc data\n");
59 + return -ENODEV;
60 + }
61 +
62 + if (dev->soc->data_pin_pair_num == 1)
63 + return 0;
64 +
65 + err = of_property_read_u8(pdev->dev.of_node, "microchip,tdm-data-pair",
66 + &dev->tdm_data_pair);
67 + if (err < 0 && err != -EINVAL) {
68 + dev_err(&pdev->dev,
69 + "bad property data for 'microchip,tdm-data-pair': %d",
70 + err);
71 + return err;
72 + }
73 + if (err == -EINVAL) {
74 + dev_info(&pdev->dev,
75 + "'microchip,tdm-data-pair' not found; assuming DIN/DOUT 0 for TDM\n");
76 + dev->tdm_data_pair = 0;
77 + } else {
78 + if (dev->tdm_data_pair > dev->soc->data_pin_pair_num - 1) {
79 + dev_err(&pdev->dev,
80 + "invalid value for 'microchip,tdm-data-pair': %d\n",
81 + dev->tdm_data_pair);
82 + return -EINVAL;
83 + }
84 + dev_dbg(&pdev->dev, "TMD format on DIN/DOUT %d pins\n",
85 + dev->tdm_data_pair);
86 + }
87 +
88 + return 0;
89 +}
90 +
91 static int mchp_i2s_mcc_probe(struct platform_device *pdev)
92 {
93 struct mchp_i2s_mcc_dev *dev;
94 @@ -966,10 +1010,10 @@ static int mchp_i2s_mcc_probe(struct pla
95 }
96
97 dev->soc = of_device_get_match_data(&pdev->dev);
98 - if (!dev->soc) {
99 - dev_err(&pdev->dev, "failed to get soc data\n");
100 - return -ENODEV;
101 - }
102 + err = mchp_i2s_mcc_soc_data_parse(pdev, dev);
103 + if (err < 0)
104 + return err;
105 +
106 dev->dev = &pdev->dev;
107 dev->regmap = regmap;
108 platform_set_drvdata(pdev, dev);