]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - drivers/misc/sti/sdti.c
c35821d5b4dd75780b8b75bff155f2216fed1642
[linux-2.6-omap-h63xx.git] / drivers / misc / sti / sdti.c
1 /*
2  * Support functions for OMAP3 SDTI (Serial Debug Tracing Interface)
3  *
4  * Copyright (C) 2008 Nokia Corporation
5  * Written by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
6  *
7  * This file is subject to the terms and conditions of the GNU General Public
8  * License.  See the file "COPYING" in the main directory of this archive
9  * for more details.
10  */
11 #include <linux/init.h>
12 #include <linux/err.h>
13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/spinlock.h>
16 #include <linux/interrupt.h>
17 #include <linux/platform_device.h>
18 #include <linux/clk.h>
19 #include <mach/sti.h>
20 #include <asm/byteorder.h>
21 #include <asm/io.h>
22
23 #define SDTI_REVISION           0x000
24 #define SDTI_SYSCONFIG          0x010
25 #define SDTI_SYSSTATUS          0x014
26 #define SDTI_WINCTRL            0x024
27 #define SDTI_SCONFIG            0x028
28 #define SDTI_TESTCTRL           0x02C
29 #define SDTI_LOCK_ACCESS        0xFB0
30
31 #define CPU1_TRACE_EN           0x01
32 #define CPU2_TRACE_EN           0x02
33
34 static struct clk *sdti_ck;
35 unsigned long sti_base, sti_channel_base;
36 static DEFINE_SPINLOCK(sdti_lock);
37
38 void omap_sti_channel_write_trace(int len, int id, void *data,
39                                 unsigned int channel)
40 {
41         const u8 *tpntr = data;
42
43         spin_lock_irq(&sdti_lock);
44
45         sti_channel_writeb(id, channel);
46         while (len--)
47                 sti_channel_writeb(*tpntr++, channel);
48         sti_channel_flush(channel);
49
50         spin_unlock_irq(&sdti_lock);
51 }
52 EXPORT_SYMBOL(omap_sti_channel_write_trace);
53
54 static void omap_sdti_reset(void)
55 {
56         int i;
57
58         sti_writel(0x02, SDTI_SYSCONFIG);
59
60         for (i = 0; i < 10000; i++)
61                 if (sti_readl(SDTI_SYSSTATUS) & 1)
62                         break;
63         if (i == 10000)
64                 printk(KERN_WARNING "XTI: no real reset\n");
65 }
66
67 static int __init omap_sdti_init(void)
68 {
69         char buf[64];
70         int i;
71
72         sdti_ck = clk_get(NULL, "emu_per_alwon_ck");
73         if (IS_ERR(sdti_ck)) {
74                 printk(KERN_ERR "Cannot get clk emu_per_alwon_ck\n");
75                 return PTR_ERR(sdti_ck);
76         }
77         clk_enable(sdti_ck);
78
79         omap_sdti_reset();
80         sti_writel(0xC5ACCE55, SDTI_LOCK_ACCESS);
81
82         /* Claim SDTI */
83         sti_writel(1 << 30, SDTI_WINCTRL);
84         i = sti_readl(SDTI_WINCTRL);
85         if (!(i & (1 << 30)))
86                 printk(KERN_WARNING "SDTI: cannot claim SDTI\n");
87
88         /* 4 bits dual, fclk/3 */
89         sti_writel(0x43, SDTI_SCONFIG);
90
91         /* CPU2 trace enable */
92         sti_writel(i | CPU2_TRACE_EN, SDTI_WINCTRL);
93         i = sti_readl(SDTI_WINCTRL);
94
95         /* Enable SDTI */
96         sti_writel((1 << 31) | (i & 0x3FFFFFFF), SDTI_WINCTRL);
97
98         i = sti_readl(SDTI_REVISION);
99         snprintf(buf, sizeof(buf), "OMAP SDTI support loaded (HW v%u.%u)\n",
100                 (i >> 4) & 0x0f, i & 0x0f);
101         printk(KERN_INFO "%s", buf);
102         omap_sti_channel_write_trace(strlen(buf), 0xc3, buf, 239);
103
104         return 0;
105 }
106
107 static void omap_sdti_exit(void)
108 {
109         sti_writel(0, SDTI_WINCTRL);
110         clk_disable(sdti_ck);
111         clk_put(sdti_ck);
112 }
113
114 static int __devinit omap_sdti_probe(struct platform_device *pdev)
115 {
116         struct resource *res, *cres;
117         unsigned int size;
118
119         if (pdev->num_resources != 2) {
120                 dev_err(&pdev->dev, "invalid number of resources: %d\n",
121                         pdev->num_resources);
122                 return -ENODEV;
123         }
124
125         /* SDTI base */
126         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
127         if (unlikely(!res)) {
128                 dev_err(&pdev->dev, "invalid mem resource\n");
129                 return -ENODEV;
130         }
131
132         /* Channel base */
133         cres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
134         if (unlikely(!cres)) {
135                 dev_err(&pdev->dev, "invalid channel mem resource\n");
136                 return -ENODEV;
137         }
138
139         size = res->end - res->start;
140         sti_base = (unsigned long)ioremap(res->start, size);
141         if (unlikely(!sti_base))
142                 return -ENODEV;
143
144         size = cres->end - cres->start;
145         sti_channel_base = (unsigned long)ioremap(cres->start, size);
146         if (unlikely(!sti_channel_base)) {
147                 iounmap((void *)sti_base);
148                 return -ENODEV;
149         }
150
151         return omap_sdti_init();
152 }
153
154 static int __devexit omap_sdti_remove(struct platform_device *pdev)
155 {
156         iounmap((void *)sti_channel_base);
157         iounmap((void *)sti_base);
158         omap_sdti_exit();
159
160         return 0;
161 }
162
163 static struct platform_driver omap_sdti_driver = {
164         .probe          = omap_sdti_probe,
165         .remove         = __devexit_p(omap_sdti_remove),
166         .driver         = {
167                 .name   = "sti",
168                 .owner  = THIS_MODULE,
169         },
170 };
171
172 static int __init omap_sdti_module_init(void)
173 {
174         return platform_driver_register(&omap_sdti_driver);
175 }
176
177 static void __exit omap_sdti_module_exit(void)
178 {
179         platform_driver_unregister(&omap_sdti_driver);
180 }
181 subsys_initcall(omap_sdti_module_init);
182 module_exit(omap_sdti_module_exit);
183
184 MODULE_AUTHOR("Roman Tereshonkov");
185 MODULE_LICENSE("GPL");