152-ASoC-mchp-i2s-mcc-Add-support-to-select-TDM-pins.patch 3.5 KB

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