tegra20_das.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * tegra20_das.c - Tegra20 DAS driver
  4. *
  5. * Author: Stephen Warren <[email protected]>
  6. * Copyright (C) 2010 - NVIDIA, Inc.
  7. */
  8. #include <linux/device.h>
  9. #include <linux/io.h>
  10. #include <linux/module.h>
  11. #include <linux/platform_device.h>
  12. #include <linux/regmap.h>
  13. #include <linux/slab.h>
  14. #include <sound/soc.h>
  15. #define DRV_NAME "tegra20-das"
  16. /* Register TEGRA20_DAS_DAP_CTRL_SEL */
  17. #define TEGRA20_DAS_DAP_CTRL_SEL 0x00
  18. #define TEGRA20_DAS_DAP_CTRL_SEL_COUNT 5
  19. #define TEGRA20_DAS_DAP_CTRL_SEL_STRIDE 4
  20. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_P 31
  21. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_MS_SEL_S 1
  22. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_P 30
  23. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA1_TX_RX_S 1
  24. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_P 29
  25. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_SDATA2_TX_RX_S 1
  26. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P 0
  27. #define TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_S 5
  28. /* Values for field TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL */
  29. #define TEGRA20_DAS_DAP_SEL_DAC1 0
  30. #define TEGRA20_DAS_DAP_SEL_DAC2 1
  31. #define TEGRA20_DAS_DAP_SEL_DAC3 2
  32. #define TEGRA20_DAS_DAP_SEL_DAP1 16
  33. #define TEGRA20_DAS_DAP_SEL_DAP2 17
  34. #define TEGRA20_DAS_DAP_SEL_DAP3 18
  35. #define TEGRA20_DAS_DAP_SEL_DAP4 19
  36. #define TEGRA20_DAS_DAP_SEL_DAP5 20
  37. /* Register TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL */
  38. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL 0x40
  39. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_COUNT 3
  40. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE 4
  41. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P 28
  42. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_S 4
  43. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P 24
  44. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_S 4
  45. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P 0
  46. #define TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_S 4
  47. /*
  48. * Values for:
  49. * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL
  50. * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL
  51. * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL
  52. */
  53. #define TEGRA20_DAS_DAC_SEL_DAP1 0
  54. #define TEGRA20_DAS_DAC_SEL_DAP2 1
  55. #define TEGRA20_DAS_DAC_SEL_DAP3 2
  56. #define TEGRA20_DAS_DAC_SEL_DAP4 3
  57. #define TEGRA20_DAS_DAC_SEL_DAP5 4
  58. /*
  59. * Names/IDs of the DACs/DAPs.
  60. */
  61. #define TEGRA20_DAS_DAP_ID_1 0
  62. #define TEGRA20_DAS_DAP_ID_2 1
  63. #define TEGRA20_DAS_DAP_ID_3 2
  64. #define TEGRA20_DAS_DAP_ID_4 3
  65. #define TEGRA20_DAS_DAP_ID_5 4
  66. #define TEGRA20_DAS_DAC_ID_1 0
  67. #define TEGRA20_DAS_DAC_ID_2 1
  68. #define TEGRA20_DAS_DAC_ID_3 2
  69. struct tegra20_das {
  70. struct regmap *regmap;
  71. };
  72. /*
  73. * Terminology:
  74. * DAS: Digital audio switch (HW module controlled by this driver)
  75. * DAP: Digital audio port (port/pins on Tegra device)
  76. * DAC: Digital audio controller (e.g. I2S or AC97 controller elsewhere)
  77. *
  78. * The Tegra DAS is a mux/cross-bar which can connect each DAP to a specific
  79. * DAC, or another DAP. When DAPs are connected, one must be the master and
  80. * one the slave. Each DAC allows selection of a specific DAP for input, to
  81. * cater for the case where N DAPs are connected to 1 DAC for broadcast
  82. * output.
  83. *
  84. * This driver is dumb; no attempt is made to ensure that a valid routing
  85. * configuration is programmed.
  86. */
  87. static inline void tegra20_das_write(struct tegra20_das *das, u32 reg, u32 val)
  88. {
  89. regmap_write(das->regmap, reg, val);
  90. }
  91. static void tegra20_das_connect_dap_to_dac(struct tegra20_das *das, int dap, int dac)
  92. {
  93. u32 addr;
  94. u32 reg;
  95. addr = TEGRA20_DAS_DAP_CTRL_SEL +
  96. (dap * TEGRA20_DAS_DAP_CTRL_SEL_STRIDE);
  97. reg = dac << TEGRA20_DAS_DAP_CTRL_SEL_DAP_CTRL_SEL_P;
  98. tegra20_das_write(das, addr, reg);
  99. }
  100. static void tegra20_das_connect_dac_to_dap(struct tegra20_das *das, int dac, int dap)
  101. {
  102. u32 addr;
  103. u32 reg;
  104. addr = TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL +
  105. (dac * TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_STRIDE);
  106. reg = dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_CLK_SEL_P |
  107. dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA1_SEL_P |
  108. dap << TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL_DAC_SDATA2_SEL_P;
  109. tegra20_das_write(das, addr, reg);
  110. }
  111. #define LAST_REG(name) \
  112. (TEGRA20_DAS_##name + \
  113. (TEGRA20_DAS_##name##_STRIDE * (TEGRA20_DAS_##name##_COUNT - 1)))
  114. static bool tegra20_das_wr_rd_reg(struct device *dev, unsigned int reg)
  115. {
  116. if (reg <= LAST_REG(DAP_CTRL_SEL))
  117. return true;
  118. if ((reg >= TEGRA20_DAS_DAC_INPUT_DATA_CLK_SEL) &&
  119. (reg <= LAST_REG(DAC_INPUT_DATA_CLK_SEL)))
  120. return true;
  121. return false;
  122. }
  123. static const struct regmap_config tegra20_das_regmap_config = {
  124. .reg_bits = 32,
  125. .reg_stride = 4,
  126. .val_bits = 32,
  127. .max_register = LAST_REG(DAC_INPUT_DATA_CLK_SEL),
  128. .writeable_reg = tegra20_das_wr_rd_reg,
  129. .readable_reg = tegra20_das_wr_rd_reg,
  130. .cache_type = REGCACHE_FLAT,
  131. };
  132. static int tegra20_das_probe(struct platform_device *pdev)
  133. {
  134. void __iomem *regs;
  135. struct tegra20_das *das;
  136. das = devm_kzalloc(&pdev->dev, sizeof(struct tegra20_das), GFP_KERNEL);
  137. if (!das)
  138. return -ENOMEM;
  139. regs = devm_platform_ioremap_resource(pdev, 0);
  140. if (IS_ERR(regs))
  141. return PTR_ERR(regs);
  142. das->regmap = devm_regmap_init_mmio(&pdev->dev, regs,
  143. &tegra20_das_regmap_config);
  144. if (IS_ERR(das->regmap)) {
  145. dev_err(&pdev->dev, "regmap init failed\n");
  146. return PTR_ERR(das->regmap);
  147. }
  148. tegra20_das_connect_dap_to_dac(das, TEGRA20_DAS_DAP_ID_1,
  149. TEGRA20_DAS_DAP_SEL_DAC1);
  150. tegra20_das_connect_dac_to_dap(das, TEGRA20_DAS_DAC_ID_1,
  151. TEGRA20_DAS_DAC_SEL_DAP1);
  152. tegra20_das_connect_dap_to_dac(das, TEGRA20_DAS_DAP_ID_3,
  153. TEGRA20_DAS_DAP_SEL_DAC3);
  154. tegra20_das_connect_dac_to_dap(das, TEGRA20_DAS_DAC_ID_3,
  155. TEGRA20_DAS_DAC_SEL_DAP3);
  156. return 0;
  157. }
  158. static const struct of_device_id tegra20_das_of_match[] = {
  159. { .compatible = "nvidia,tegra20-das", },
  160. {},
  161. };
  162. static struct platform_driver tegra20_das_driver = {
  163. .probe = tegra20_das_probe,
  164. .driver = {
  165. .name = DRV_NAME,
  166. .of_match_table = tegra20_das_of_match,
  167. },
  168. };
  169. module_platform_driver(tegra20_das_driver);
  170. MODULE_AUTHOR("Stephen Warren <[email protected]>");
  171. MODULE_DESCRIPTION("Tegra20 DAS driver");
  172. MODULE_LICENSE("GPL");
  173. MODULE_ALIAS("platform:" DRV_NAME);
  174. MODULE_DEVICE_TABLE(of, tegra20_das_of_match);