0006-soc-mediatek-Add-infracfg-misc-driver-support.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. From d6d7a7dc1b7db2e3d496bf67b30abc894edbc4bd Mon Sep 17 00:00:00 2001
  2. From: Sascha Hauer <[email protected]>
  3. Date: Tue, 9 Jun 2015 10:46:59 +0200
  4. Subject: [PATCH 06/76] soc: mediatek: Add infracfg misc driver support
  5. This adds support for some miscellaneous bits of the infracfg controller.
  6. The mtk_infracfg_set/clear_bus_protection functions are necessary for
  7. the scpsys power domain driver to handle the bus protection bits which
  8. are contained in the infacfg register space.
  9. Signed-off-by: Sascha Hauer <[email protected]>
  10. ---
  11. drivers/soc/mediatek/Kconfig | 9 ++++
  12. drivers/soc/mediatek/Makefile | 1 +
  13. drivers/soc/mediatek/mtk-infracfg.c | 91 +++++++++++++++++++++++++++++++++
  14. include/linux/soc/mediatek/infracfg.h | 26 ++++++++++
  15. 4 files changed, 127 insertions(+)
  16. create mode 100644 drivers/soc/mediatek/mtk-infracfg.c
  17. create mode 100644 include/linux/soc/mediatek/infracfg.h
  18. --- a/drivers/soc/mediatek/Kconfig
  19. +++ b/drivers/soc/mediatek/Kconfig
  20. @@ -1,6 +1,15 @@
  21. #
  22. # MediaTek SoC drivers
  23. #
  24. +config MTK_INFRACFG
  25. + bool "MediaTek INFRACFG Support"
  26. + depends on ARCH_MEDIATEK
  27. + select REGMAP
  28. + help
  29. + Say yes here to add support for the MediaTek INFRACFG controller. The
  30. + INFRACFG controller contains various infrastructure registers not
  31. + directly associated to any device.
  32. +
  33. config MTK_PMIC_WRAP
  34. tristate "MediaTek PMIC Wrapper Support"
  35. depends on ARCH_MEDIATEK
  36. --- a/drivers/soc/mediatek/Makefile
  37. +++ b/drivers/soc/mediatek/Makefile
  38. @@ -1 +1,2 @@
  39. +obj-$(CONFIG_MTK_INFRACFG) += mtk-infracfg.o
  40. obj-$(CONFIG_MTK_PMIC_WRAP) += mtk-pmic-wrap.o
  41. --- /dev/null
  42. +++ b/drivers/soc/mediatek/mtk-infracfg.c
  43. @@ -0,0 +1,91 @@
  44. +/*
  45. + * Copyright (c) 2015 Pengutronix, Sascha Hauer <[email protected]>
  46. + *
  47. + * This program is free software; you can redistribute it and/or modify
  48. + * it under the terms of the GNU General Public License version 2 as
  49. + * published by the Free Software Foundation.
  50. + *
  51. + * This program is distributed in the hope that it will be useful,
  52. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  53. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  54. + * GNU General Public License for more details.
  55. + */
  56. +
  57. +#include <linux/export.h>
  58. +#include <linux/jiffies.h>
  59. +#include <linux/regmap.h>
  60. +#include <linux/soc/mediatek/infracfg.h>
  61. +#include <asm/processor.h>
  62. +
  63. +#define INFRA_TOPAXI_PROTECTEN 0x0220
  64. +#define INFRA_TOPAXI_PROTECTSTA1 0x0228
  65. +
  66. +/**
  67. + * mtk_infracfg_set_bus_protection - enable bus protection
  68. + * @regmap: The infracfg regmap
  69. + * @mask: The mask containing the protection bits to be enabled.
  70. + *
  71. + * This function enables the bus protection bits for disabled power
  72. + * domains so that the system does not hanf when some unit accesses the
  73. + * bus while in power down.
  74. + */
  75. +int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask)
  76. +{
  77. + unsigned long expired;
  78. + u32 val;
  79. + int ret;
  80. +
  81. + regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, mask);
  82. +
  83. + expired = jiffies + HZ;
  84. +
  85. + while (1) {
  86. + ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
  87. + if (ret)
  88. + return ret;
  89. +
  90. + if ((val & mask) == mask)
  91. + break;
  92. +
  93. + cpu_relax();
  94. + if (time_after(jiffies, expired))
  95. + return -EIO;
  96. + }
  97. +
  98. + return 0;
  99. +}
  100. +
  101. +/**
  102. + * mtk_infracfg_clear_bus_protection - disable bus protection
  103. + * @regmap: The infracfg regmap
  104. + * @mask: The mask containing the protection bits to be disabled.
  105. + *
  106. + * This function disables the bus protection bits previously enabled with
  107. + * mtk_infracfg_set_bus_protection.
  108. + */
  109. +int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask)
  110. +{
  111. + unsigned long expired;
  112. + int ret;
  113. +
  114. + regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
  115. +
  116. + expired = jiffies + HZ;
  117. +
  118. + while (1) {
  119. + u32 val;
  120. +
  121. + ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
  122. + if (ret)
  123. + return ret;
  124. +
  125. + if (!(val & mask))
  126. + break;
  127. +
  128. + cpu_relax();
  129. + if (time_after(jiffies, expired))
  130. + return -EIO;
  131. + }
  132. +
  133. + return 0;
  134. +}
  135. --- /dev/null
  136. +++ b/include/linux/soc/mediatek/infracfg.h
  137. @@ -0,0 +1,26 @@
  138. +#ifndef __SOC_MEDIATEK_INFRACFG_H
  139. +#define __SOC_MEDIATEK_INFRACFG_H
  140. +
  141. +#define MT8173_TOP_AXI_PROT_EN_MCI_M2 BIT(0)
  142. +#define MT8173_TOP_AXI_PROT_EN_MM_M0 BIT(1)
  143. +#define MT8173_TOP_AXI_PROT_EN_MM_M1 BIT(2)
  144. +#define MT8173_TOP_AXI_PROT_EN_MMAPB_S BIT(6)
  145. +#define MT8173_TOP_AXI_PROT_EN_L2C_M2 BIT(9)
  146. +#define MT8173_TOP_AXI_PROT_EN_L2SS_SMI BIT(11)
  147. +#define MT8173_TOP_AXI_PROT_EN_L2SS_ADD BIT(12)
  148. +#define MT8173_TOP_AXI_PROT_EN_CCI_M2 BIT(13)
  149. +#define MT8173_TOP_AXI_PROT_EN_MFG_S BIT(14)
  150. +#define MT8173_TOP_AXI_PROT_EN_PERI_M0 BIT(15)
  151. +#define MT8173_TOP_AXI_PROT_EN_PERI_M1 BIT(16)
  152. +#define MT8173_TOP_AXI_PROT_EN_DEBUGSYS BIT(17)
  153. +#define MT8173_TOP_AXI_PROT_EN_CQ_DMA BIT(18)
  154. +#define MT8173_TOP_AXI_PROT_EN_GCPU BIT(19)
  155. +#define MT8173_TOP_AXI_PROT_EN_IOMMU BIT(20)
  156. +#define MT8173_TOP_AXI_PROT_EN_MFG_M0 BIT(21)
  157. +#define MT8173_TOP_AXI_PROT_EN_MFG_M1 BIT(22)
  158. +#define MT8173_TOP_AXI_PROT_EN_MFG_SNOOP_OUT BIT(23)
  159. +
  160. +int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask);
  161. +int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask);
  162. +
  163. +#endif /* __SOC_MEDIATEK_INFRACFG_H */