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
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.
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>
17 sound/soc/atmel/mchp-i2s-mcc.c | 52 +++++++++++++++++++++++++++++++---
18 1 file changed, 48 insertions(+), 4 deletions(-)
20 --- a/sound/soc/atmel/mchp-i2s-mcc.c
21 +++ b/sound/soc/atmel/mchp-i2s-mcc.c
23 #define MCHP_I2SMCC_MRA_DATALENGTH_8_BITS_COMPACT (7 << 1)
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;
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
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);
46 if (channels % 2 && channels * 2 <= dev->tdm_slots) {
48 @@ -914,6 +919,45 @@ static const struct of_device_id mchp_i2
49 MODULE_DEVICE_TABLE(of, mchp_i2s_mcc_dt_ids);
52 +static int mchp_i2s_mcc_soc_data_parse(struct platform_device *pdev,
53 + struct mchp_i2s_mcc_dev *dev)
58 + dev_err(&pdev->dev, "failed to get soc data\n");
62 + if (dev->soc->data_pin_pair_num == 1)
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) {
69 + "bad property data for 'microchip,tdm-data-pair': %d",
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;
78 + if (dev->tdm_data_pair > dev->soc->data_pin_pair_num - 1) {
80 + "invalid value for 'microchip,tdm-data-pair': %d\n",
81 + dev->tdm_data_pair);
84 + dev_dbg(&pdev->dev, "TMD format on DIN/DOUT %d pins\n",
85 + dev->tdm_data_pair);
91 static int mchp_i2s_mcc_probe(struct platform_device *pdev)
93 struct mchp_i2s_mcc_dev *dev;
94 @@ -966,10 +1010,10 @@ static int mchp_i2s_mcc_probe(struct pla
97 dev->soc = of_device_get_match_data(&pdev->dev);
99 - dev_err(&pdev->dev, "failed to get soc data\n");
102 + err = mchp_i2s_mcc_soc_data_parse(pdev, dev);
106 dev->dev = &pdev->dev;
107 dev->regmap = regmap;
108 platform_set_drvdata(pdev, dev);