mtk-infracfg.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 INFRA_TOPAXI_PROTECTEN 0x0220
  19. #define INFRA_TOPAXI_PROTECTSTA1 0x0228
  20. /**
  21. * mtk_infracfg_set_bus_protection - enable bus protection
  22. * @regmap: The infracfg regmap
  23. * @mask: The mask containing the protection bits to be enabled.
  24. *
  25. * This function enables the bus protection bits for disabled power
  26. * domains so that the system does not hang when some unit accesses the
  27. * bus while in power down.
  28. */
  29. int mtk_infracfg_set_bus_protection(struct regmap *infracfg, u32 mask)
  30. {
  31. unsigned long expired;
  32. u32 val;
  33. int ret;
  34. regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, mask);
  35. expired = jiffies + HZ;
  36. while (1) {
  37. ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
  38. if (ret)
  39. return ret;
  40. if ((val & mask) == mask)
  41. break;
  42. cpu_relax();
  43. if (time_after(jiffies, expired))
  44. return -EIO;
  45. }
  46. return 0;
  47. }
  48. /**
  49. * mtk_infracfg_clear_bus_protection - disable bus protection
  50. * @regmap: The infracfg regmap
  51. * @mask: The mask containing the protection bits to be disabled.
  52. *
  53. * This function disables the bus protection bits previously enabled with
  54. * mtk_infracfg_set_bus_protection.
  55. */
  56. int mtk_infracfg_clear_bus_protection(struct regmap *infracfg, u32 mask)
  57. {
  58. unsigned long expired;
  59. int ret;
  60. regmap_update_bits(infracfg, INFRA_TOPAXI_PROTECTEN, mask, 0);
  61. expired = jiffies + HZ;
  62. while (1) {
  63. u32 val;
  64. ret = regmap_read(infracfg, INFRA_TOPAXI_PROTECTSTA1, &val);
  65. if (ret)
  66. return ret;
  67. if (!(val & mask))
  68. break;
  69. cpu_relax();
  70. if (time_after(jiffies, expired))
  71. return -EIO;
  72. }
  73. return 0;
  74. }