mtk-infracfg.c 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright (c) 2015 Pengutronix, Sascha Hauer <kernel@pengutronix.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/export.h>
  14. #include <linux/jiffies.h>
  15. #include <linux/regmap.h>
  16. #include <linux/soc/mediatek/infracfg.h>
  17. #include <asm/processor.h>
  18. #define MTK_POLL_DELAY_US 10
  19. #define MTK_POLL_TIMEOUT (jiffies_to_usecs(HZ))
  20. #define INFRA_TOPAXI_PROTECTEN 0x0220
  21. #define INFRA_TOPAXI_PROTECTSTA1 0x0228
  22. #define INFRA_TOPAXI_PROTECTEN_SET 0x0260
  23. #define INFRA_TOPAXI_PROTECTEN_CLR 0x0264
  24. /**
  25. * mtk_infracfg_set_bus_protection - enable bus protection
  26. * @regmap: The infracfg regmap
  27. * @mask: The mask containing the protection bits to be enabled.
  28. * @reg_update: The boolean flag determines to set the protection bits
  29. * by regmap_update_bits with enable register(PROTECTEN) or
  30. * by regmap_write with set register(PROTECTEN_SET).
  31. *
  32. * This function enables the bus protection bits for disabled power
  33. * domains so that the system does not hang when some unit accesses the
  34. * bus while in power down.
  35. */
  36. int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask,
  37. bool reg_update)
  38. {
  39. u32 val;
  40. int ret;
  41. if (reg_update)
  42. regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask,
  43. mask);
  44. else
  45. regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_SET, mask);
  46. ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
  47. val, (val & mask) == mask,
  48. MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
  49. return ret;
  50. }
  51. /**
  52. * mtk_infracfg_clear_bus_protection - disable bus protection
  53. * @regmap: The infracfg regmap
  54. * @mask: The mask containing the protection bits to be disabled.
  55. * @reg_update: The boolean flag determines to clear the protection bits
  56. * by regmap_update_bits with enable register(PROTECTEN) or
  57. * by regmap_write with clear register(PROTECTEN_CLR).
  58. *
  59. * This function disables the bus protection bits previously enabled with
  60. * mtk_infracfg_set_bus_protection.
  61. */
  62. int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask,
  63. bool reg_update)
  64. {
  65. int ret;
  66. u32 val;
  67. if (reg_update)
  68. regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
  69. else
  70. regmap_write(infracfg, INFRA_TOPAXI_PROTECTEN_CLR, mask);
  71. ret = regmap_read_poll_timeout(infracfg, INFRA_TOPAXI_PROTECTSTA1,
  72. val, !(val & mask),
  73. MTK_POLL_DELAY_US, MTK_POLL_TIMEOUT);
  74. return ret;
  75. }