reset-imx7.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. /*
  2. * Copyright (c) 2017, Impinj, Inc.
  3. *
  4. * i.MX7 System Reset Controller (SRC) driver
  5. *
  6. * Author: Andrey Smirnov <andrew.smirnov@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; version 2 of the License.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/mfd/syscon.h>
  18. #include <linux/mod_devicetable.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/reset-controller.h>
  21. #include <linux/regmap.h>
  22. #include <dt-bindings/reset/imx7-reset.h>
  23. struct imx7_src {
  24. struct reset_controller_dev rcdev;
  25. struct regmap *regmap;
  26. };
  27. enum imx7_src_registers {
  28. SRC_A7RCR0 = 0x0004,
  29. SRC_M4RCR = 0x000c,
  30. SRC_ERCR = 0x0014,
  31. SRC_HSICPHY_RCR = 0x001c,
  32. SRC_USBOPHY1_RCR = 0x0020,
  33. SRC_USBOPHY2_RCR = 0x0024,
  34. SRC_MIPIPHY_RCR = 0x0028,
  35. SRC_PCIEPHY_RCR = 0x002c,
  36. SRC_DDRC_RCR = 0x1000,
  37. };
  38. struct imx7_src_signal {
  39. unsigned int offset, bit;
  40. };
  41. static const struct imx7_src_signal imx7_src_signals[IMX7_RESET_NUM] = {
  42. [IMX7_RESET_A7_CORE_POR_RESET0] = { SRC_A7RCR0, BIT(0) },
  43. [IMX7_RESET_A7_CORE_POR_RESET1] = { SRC_A7RCR0, BIT(1) },
  44. [IMX7_RESET_A7_CORE_RESET0] = { SRC_A7RCR0, BIT(4) },
  45. [IMX7_RESET_A7_CORE_RESET1] = { SRC_A7RCR0, BIT(5) },
  46. [IMX7_RESET_A7_DBG_RESET0] = { SRC_A7RCR0, BIT(8) },
  47. [IMX7_RESET_A7_DBG_RESET1] = { SRC_A7RCR0, BIT(9) },
  48. [IMX7_RESET_A7_ETM_RESET0] = { SRC_A7RCR0, BIT(12) },
  49. [IMX7_RESET_A7_ETM_RESET1] = { SRC_A7RCR0, BIT(13) },
  50. [IMX7_RESET_A7_SOC_DBG_RESET] = { SRC_A7RCR0, BIT(20) },
  51. [IMX7_RESET_A7_L2RESET] = { SRC_A7RCR0, BIT(21) },
  52. [IMX7_RESET_SW_M4C_RST] = { SRC_M4RCR, BIT(1) },
  53. [IMX7_RESET_SW_M4P_RST] = { SRC_M4RCR, BIT(2) },
  54. [IMX7_RESET_EIM_RST] = { SRC_ERCR, BIT(0) },
  55. [IMX7_RESET_HSICPHY_PORT_RST] = { SRC_HSICPHY_RCR, BIT(1) },
  56. [IMX7_RESET_USBPHY1_POR] = { SRC_USBOPHY1_RCR, BIT(0) },
  57. [IMX7_RESET_USBPHY1_PORT_RST] = { SRC_USBOPHY1_RCR, BIT(1) },
  58. [IMX7_RESET_USBPHY2_POR] = { SRC_USBOPHY2_RCR, BIT(0) },
  59. [IMX7_RESET_USBPHY2_PORT_RST] = { SRC_USBOPHY2_RCR, BIT(1) },
  60. [IMX7_RESET_MIPI_PHY_MRST] = { SRC_MIPIPHY_RCR, BIT(1) },
  61. [IMX7_RESET_MIPI_PHY_SRST] = { SRC_MIPIPHY_RCR, BIT(2) },
  62. [IMX7_RESET_PCIEPHY] = { SRC_PCIEPHY_RCR, BIT(2) | BIT(1) },
  63. [IMX7_RESET_PCIEPHY_PERST] = { SRC_PCIEPHY_RCR, BIT(3) },
  64. [IMX7_RESET_PCIE_CTRL_APPS_EN] = { SRC_PCIEPHY_RCR, BIT(6) },
  65. [IMX7_RESET_DDRC_PRST] = { SRC_DDRC_RCR, BIT(0) },
  66. [IMX7_RESET_DDRC_CORE_RST] = { SRC_DDRC_RCR, BIT(1) },
  67. };
  68. static struct imx7_src *to_imx7_src(struct reset_controller_dev *rcdev)
  69. {
  70. return container_of(rcdev, struct imx7_src, rcdev);
  71. }
  72. static int imx7_reset_set(struct reset_controller_dev *rcdev,
  73. unsigned long id, bool assert)
  74. {
  75. struct imx7_src *imx7src = to_imx7_src(rcdev);
  76. const struct imx7_src_signal *signal = &imx7_src_signals[id];
  77. unsigned int value = assert ? signal->bit : 0;
  78. switch (id) {
  79. case IMX7_RESET_PCIEPHY:
  80. /*
  81. * wait for more than 10us to release phy g_rst and
  82. * btnrst
  83. */
  84. if (!assert)
  85. udelay(10);
  86. break;
  87. case IMX7_RESET_PCIE_CTRL_APPS_EN:
  88. value = (assert) ? 0 : signal->bit;
  89. break;
  90. }
  91. return regmap_update_bits(imx7src->regmap,
  92. signal->offset, signal->bit, value);
  93. }
  94. static int imx7_reset_assert(struct reset_controller_dev *rcdev,
  95. unsigned long id)
  96. {
  97. return imx7_reset_set(rcdev, id, true);
  98. }
  99. static int imx7_reset_deassert(struct reset_controller_dev *rcdev,
  100. unsigned long id)
  101. {
  102. return imx7_reset_set(rcdev, id, false);
  103. }
  104. static const struct reset_control_ops imx7_reset_ops = {
  105. .assert = imx7_reset_assert,
  106. .deassert = imx7_reset_deassert,
  107. };
  108. static int imx7_reset_probe(struct platform_device *pdev)
  109. {
  110. struct imx7_src *imx7src;
  111. struct device *dev = &pdev->dev;
  112. struct regmap_config config = { .name = "src" };
  113. imx7src = devm_kzalloc(dev, sizeof(*imx7src), GFP_KERNEL);
  114. if (!imx7src)
  115. return -ENOMEM;
  116. imx7src->regmap = syscon_node_to_regmap(dev->of_node);
  117. if (IS_ERR(imx7src->regmap)) {
  118. dev_err(dev, "Unable to get imx7-src regmap");
  119. return PTR_ERR(imx7src->regmap);
  120. }
  121. regmap_attach_dev(dev, imx7src->regmap, &config);
  122. imx7src->rcdev.owner = THIS_MODULE;
  123. imx7src->rcdev.nr_resets = IMX7_RESET_NUM;
  124. imx7src->rcdev.ops = &imx7_reset_ops;
  125. imx7src->rcdev.of_node = dev->of_node;
  126. return devm_reset_controller_register(dev, &imx7src->rcdev);
  127. }
  128. static const struct of_device_id imx7_reset_dt_ids[] = {
  129. { .compatible = "fsl,imx7d-src", },
  130. { /* sentinel */ },
  131. };
  132. static struct platform_driver imx7_reset_driver = {
  133. .probe = imx7_reset_probe,
  134. .driver = {
  135. .name = KBUILD_MODNAME,
  136. .of_match_table = imx7_reset_dt_ids,
  137. },
  138. };
  139. builtin_platform_driver(imx7_reset_driver);