ubc.c 2.9 KB

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