ubc.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * arch/sh/kernel/cpu/sh4a/ubc.c
  4. *
  5. * On-chip UBC support for SH-4A CPUs.
  6. *
  7. * Copyright (C) 2009 - 2010 Paul Mundt
  8. */
  9. #include <linux/init.h>
  10. #include <linux/err.h>
  11. #include <linux/clk.h>
  12. #include <linux/io.h>
  13. #include <asm/hw_breakpoint.h>
  14. #define UBC_CBR(idx) (0xff200000 + (0x20 * idx))
  15. #define UBC_CRR(idx) (0xff200004 + (0x20 * idx))
  16. #define UBC_CAR(idx) (0xff200008 + (0x20 * idx))
  17. #define UBC_CAMR(idx) (0xff20000c + (0x20 * idx))
  18. #define UBC_CCMFR 0xff200600
  19. #define UBC_CBCR 0xff200620
  20. /* CRR */
  21. #define UBC_CRR_PCB (1 << 1)
  22. #define UBC_CRR_BIE (1 << 0)
  23. /* CBR */
  24. #define UBC_CBR_CE (1 << 0)
  25. static struct sh_ubc sh4a_ubc;
  26. static void sh4a_ubc_enable(struct arch_hw_breakpoint *info, int idx)
  27. {
  28. __raw_writel(UBC_CBR_CE | info->len | info->type, UBC_CBR(idx));
  29. __raw_writel(info->address, UBC_CAR(idx));
  30. }
  31. static void sh4a_ubc_disable(struct arch_hw_breakpoint *info, int idx)
  32. {
  33. __raw_writel(0, UBC_CBR(idx));
  34. __raw_writel(0, UBC_CAR(idx));
  35. }
  36. static void sh4a_ubc_enable_all(unsigned long mask)
  37. {
  38. int i;
  39. for (i = 0; i < sh4a_ubc.num_events; i++)
  40. if (mask & (1 << i))
  41. __raw_writel(__raw_readl(UBC_CBR(i)) | UBC_CBR_CE,
  42. UBC_CBR(i));
  43. }
  44. static void sh4a_ubc_disable_all(void)
  45. {
  46. int i;
  47. for (i = 0; i < sh4a_ubc.num_events; i++)
  48. __raw_writel(__raw_readl(UBC_CBR(i)) & ~UBC_CBR_CE,
  49. UBC_CBR(i));
  50. }
  51. static unsigned long sh4a_ubc_active_mask(void)
  52. {
  53. unsigned long active = 0;
  54. int i;
  55. for (i = 0; i < sh4a_ubc.num_events; i++)
  56. if (__raw_readl(UBC_CBR(i)) & UBC_CBR_CE)
  57. active |= (1 << i);
  58. return active;
  59. }
  60. static unsigned long sh4a_ubc_triggered_mask(void)
  61. {
  62. return __raw_readl(UBC_CCMFR);
  63. }
  64. static void sh4a_ubc_clear_triggered_mask(unsigned long mask)
  65. {
  66. __raw_writel(__raw_readl(UBC_CCMFR) & ~mask, UBC_CCMFR);
  67. }
  68. static struct sh_ubc sh4a_ubc = {
  69. .name = "SH-4A",
  70. .num_events = 2,
  71. .trap_nr = 0x1e0,
  72. .enable = sh4a_ubc_enable,
  73. .disable = sh4a_ubc_disable,
  74. .enable_all = sh4a_ubc_enable_all,
  75. .disable_all = sh4a_ubc_disable_all,
  76. .active_mask = sh4a_ubc_active_mask,
  77. .triggered_mask = sh4a_ubc_triggered_mask,
  78. .clear_triggered_mask = sh4a_ubc_clear_triggered_mask,
  79. };
  80. static int __init sh4a_ubc_init(void)
  81. {
  82. struct clk *ubc_iclk = clk_get(NULL, "ubc0");
  83. int i;
  84. /*
  85. * The UBC MSTP bit is optional, as not all platforms will have
  86. * it. Just ignore it if we can't find it.
  87. */
  88. if (IS_ERR(ubc_iclk))
  89. ubc_iclk = NULL;
  90. clk_enable(ubc_iclk);
  91. __raw_writel(0, UBC_CBCR);
  92. for (i = 0; i < sh4a_ubc.num_events; i++) {
  93. __raw_writel(0, UBC_CAMR(i));
  94. __raw_writel(0, UBC_CBR(i));
  95. __raw_writel(UBC_CRR_BIE | UBC_CRR_PCB, UBC_CRR(i));
  96. /* dummy read for write posting */
  97. (void)__raw_readl(UBC_CRR(i));
  98. }
  99. clk_disable(ubc_iclk);
  100. sh4a_ubc.clk = ubc_iclk;
  101. return register_sh_ubc(&sh4a_ubc);
  102. }
  103. arch_initcall(sh4a_ubc_init);