151-ASoC-mchp-i2s-mcc-Add-multi-channel-support-for-I2S-.patch 3.5 KB

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