]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/sh/kernel/cpu/sh2a/ubc.c
Merge remote-tracking branch 'net-next/master'
[karo-tx-linux.git] / arch / sh / kernel / cpu / sh2a / ubc.c
1 /*
2  * arch/sh/kernel/cpu/sh2a/ubc.c
3  *
4  * On-chip UBC support for SH-2A 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
18 #define UBC_BAR(idx)    (0xfffc0400 + (0x10 * idx))
19 #define UBC_BAMR(idx)   (0xfffc0404 + (0x10 * idx))
20 #define UBC_BBR(idx)    (0xfffc04A0 + (0x10 * idx))
21 #define UBC_BDR(idx)    (0xfffc0408 + (0x10 * idx))
22 #define UBC_BDMR(idx)   (0xfffc040C + (0x10 * idx))
23
24 #define UBC_BRCR        0xfffc04C0
25
26 /* BBR */
27 #define UBC_BBR_UBID    (1 << 13)     /* User Break Interrupt Disable */
28 #define UBC_BBR_DBE     (1 << 12)     /* Data Break Enable */
29 #define UBC_BBR_CD_C    (1 << 6)      /* C Bus Cycle */
30 #define UBC_BBR_CD_I    (2 << 6)      /* I Bus Cycle */
31 #define UBC_BBR_ID_I    (1 << 4)      /* Break Condition is instruction fetch cycle */
32 #define UBC_BBR_ID_D    (2 << 4)      /* Break Condition is data access cycle */
33 #define UBC_BBR_ID_ID   (3 << 4)      /* Break Condition is instruction fetch or data access cycle */
34
35 #define UBC_CRR_BIE     (1 << 0)
36
37 /* CBR */
38 #define UBC_CBR_CE      (1 << 0)
39
40 static struct sh_ubc sh2a_ubc;
41
42 static void sh2a_ubc_enable(struct arch_hw_breakpoint *info, int idx)
43 {
44         __raw_writel(UBC_BBR_DBE | UBC_BBR_CD_C | UBC_BBR_ID_ID |
45                      info->len | info->type, UBC_BBR(idx));
46         __raw_writel(info->address, UBC_BAR(idx));
47 }
48
49 static void sh2a_ubc_disable(struct arch_hw_breakpoint *info, int idx)
50 {
51         __raw_writel(UBC_BBR_UBID, UBC_BBR(idx));
52         __raw_writel(0, UBC_BAR(idx));
53 }
54
55 static void sh2a_ubc_enable_all(unsigned long mask)
56 {
57         int i;
58
59         for (i = 0; i < sh2a_ubc.num_events; i++)
60                 if (mask & (1 << i))
61                         __raw_writel(__raw_readl(UBC_BBR(i)) & ~UBC_BBR_UBID,
62                                      UBC_BBR(i));
63 }
64
65 static void sh2a_ubc_disable_all(void)
66 {
67         int i;
68         
69         for (i = 0; i < sh2a_ubc.num_events; i++)
70                 __raw_writel(__raw_readl(UBC_BBR(i)) | UBC_BBR_UBID,
71                              UBC_BBR(i));
72 }
73
74 static unsigned long sh2a_ubc_active_mask(void)
75 {
76         unsigned long active = 0;
77         int i;
78
79         for (i = 0; i < sh2a_ubc.num_events; i++)
80                 if (!(__raw_readl(UBC_BBR(i)) & UBC_BBR_UBID))
81                         active |= (1 << i);
82
83         return active;
84 }
85
86 static unsigned long sh2a_ubc_triggered_mask(void)
87 {
88         unsigned int ret, mask;
89         
90         mask = 0;
91         ret = __raw_readl(UBC_BRCR);
92         if ((ret & (1 << 15)) || (ret & (1 << 13))) {
93                 mask |= (1 << 0); /* Match condition for channel 0 */
94         } else 
95                 mask &= ~(1 << 0);
96         
97         if ((ret & (1 << 14)) || (ret & (1 << 12))) {
98                 mask |= (1 << 1); /* Match condition for channel 1 */
99         } else 
100                 mask &= ~(1 << 1);
101
102         return mask;
103 }
104
105 static void sh2a_ubc_clear_triggered_mask(unsigned long mask)
106 {
107         if (mask & (1 << 0)) /* Channel 0 statisfied break condition */
108                 __raw_writel(__raw_readl(UBC_BRCR) &
109                              ~((1 << 15) | (1 << 13)), UBC_BRCR);
110         
111         if (mask & (1 << 1)) /* Channel 1 statisfied break condition */
112                 __raw_writel(__raw_readl(UBC_BRCR) &
113                              ~((1 << 14) | (1 << 12)), UBC_BRCR);
114 }
115
116 static struct sh_ubc sh2a_ubc = {
117         .name                   = "SH-2A",
118         .num_events             = 2,
119         .trap_nr                = 0x1e0,
120         .enable                 = sh2a_ubc_enable,
121         .disable                = sh2a_ubc_disable,
122         .enable_all             = sh2a_ubc_enable_all,
123         .disable_all            = sh2a_ubc_disable_all,
124         .active_mask            = sh2a_ubc_active_mask,
125         .triggered_mask         = sh2a_ubc_triggered_mask,
126         .clear_triggered_mask   = sh2a_ubc_clear_triggered_mask,
127 };
128
129 static int __init sh2a_ubc_init(void)
130 {
131         struct clk *ubc_iclk = clk_get(NULL, "ubc0");
132         int i;
133
134         /*
135          * The UBC MSTP bit is optional, as not all platforms will have
136          * it. Just ignore it if we can't find it.
137          */
138         if (IS_ERR(ubc_iclk))
139                 ubc_iclk = NULL;
140
141         clk_enable(ubc_iclk);
142
143         for (i = 0; i < sh2a_ubc.num_events; i++) {
144                 __raw_writel(0, UBC_BAMR(i));
145                 __raw_writel(0, UBC_BBR(i));
146         }
147
148         clk_disable(ubc_iclk);
149
150         sh2a_ubc.clk = ubc_iclk;
151
152         return register_sh_ubc(&sh2a_ubc);
153 }
154 arch_initcall(sh2a_ubc_init);