2 * Support functions for OMAP3 SDTI (Serial Debug Tracing Interface)
4 * Copyright (C) 2008 Nokia Corporation
5 * Written by: Roman Tereshonkov <roman.tereshonkov@nokia.com>
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
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 <asm/arch/sti.h>
20 #include <asm/byteorder.h>
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
31 #define CPU1_TRACE_EN 0x01
32 #define CPU2_TRACE_EN 0x02
34 #define EPM_BASE 0x5401D000
35 #define EPM_CONTROL_0 0x50
36 #define EPM_CONTROL_1 0x54
37 #define EPM_CONTROL_2 0x58
39 static struct clk *sdti_ck;
40 unsigned long sti_base, sti_channel_base, epm_base;
41 static DEFINE_SPINLOCK(sdti_lock);
43 void omap_sti_channel_write_trace(int len, int id, void *data,
46 const u8 *tpntr = data;
48 spin_lock_irq(&sdti_lock);
50 sti_channel_writeb(id, channel);
52 sti_channel_writeb(*tpntr++, channel);
53 sti_channel_flush(channel);
55 spin_unlock_irq(&sdti_lock);
57 EXPORT_SYMBOL(omap_sti_channel_write_trace);
59 static void omap_sdti_reset(void)
63 sti_writel(0x02, SDTI_SYSCONFIG);
65 for (i = 0; i < 10000; i++)
66 if (sti_readl(SDTI_SYSSTATUS) & 1)
69 printk(KERN_WARNING "XTI: no real reset\n");
74 epm_base = (unsigned long)ioremap(EPM_BASE, 256);
75 if (unlikely(!epm_base)) {
76 printk(KERN_ERR "EPM cannot be ioremapped\n");
80 __raw_writel(1<<30, epm_base + EPM_CONTROL_2);
81 __raw_writel(0x78, epm_base + EPM_CONTROL_0);
82 __raw_writel(0x80000000, epm_base + EPM_CONTROL_1);
83 __raw_writel(1<<31 | 0x00007770, epm_base + EPM_CONTROL_2);
86 static int __init omap_sdti_init(void)
91 sdti_ck = clk_get(NULL, "emu_per_alwon_ck");
92 if (IS_ERR(sdti_ck)) {
93 printk(KERN_ERR "Cannot get clk emu_per_alwon_ck\n");
94 return PTR_ERR(sdti_ck);
98 /* Init emulation pin manager */
102 sti_writel(0xC5ACCE55, SDTI_LOCK_ACCESS);
105 sti_writel(1 << 30, SDTI_WINCTRL);
106 i = sti_readl(SDTI_WINCTRL);
107 if (!(i & (1 << 30)))
108 printk(KERN_WARNING "SDTI: cannot claim SDTI\n");
110 /* 4 bits dual, fclk/3 */
111 sti_writel(0x43, SDTI_SCONFIG);
113 /* CPU1 trace enable */
114 sti_writel(i | CPU2_TRACE_EN, SDTI_WINCTRL);
115 i = sti_readl(SDTI_WINCTRL);
118 sti_writel((1 << 31) | (i & 0x3FFFFFFF), SDTI_WINCTRL);
120 i = sti_readl(SDTI_REVISION);
121 snprintf(buf, sizeof(buf), "OMAP SDTI support loaded (HW v%u.%u)\n",
122 (i >> 4) & 0x0f, i & 0x0f);
123 printk(KERN_INFO "%s", buf);
124 omap_sti_channel_write_trace(strlen(buf), 0xc3, buf, 239);
129 static void omap_sdti_exit(void)
131 sti_writel(0, SDTI_WINCTRL);
132 clk_disable(sdti_ck);
136 static int __devinit omap_sdti_probe(struct platform_device *pdev)
138 struct resource *res, *cres;
141 if (pdev->num_resources != 2) {
142 dev_err(&pdev->dev, "invalid number of resources: %d\n",
143 pdev->num_resources);
148 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
149 if (unlikely(!res)) {
150 dev_err(&pdev->dev, "invalid mem resource\n");
155 cres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
156 if (unlikely(!cres)) {
157 dev_err(&pdev->dev, "invalid channel mem resource\n");
161 size = res->end - res->start;
162 sti_base = (unsigned long)ioremap(res->start, size);
163 if (unlikely(!sti_base))
166 size = cres->end - cres->start;
167 sti_channel_base = (unsigned long)ioremap(cres->start, size);
168 if (unlikely(!sti_channel_base)) {
169 iounmap((void *)sti_base);
173 return omap_sdti_init();
176 static int __devexit omap_sdti_remove(struct platform_device *pdev)
178 iounmap((void *)sti_channel_base);
179 iounmap((void *)sti_base);
180 iounmap((void *)epm_base);
186 static struct platform_driver omap_sdti_driver = {
187 .probe = omap_sdti_probe,
188 .remove = __devexit_p(omap_sdti_remove),
191 .owner = THIS_MODULE,
195 static int __init omap_sdti_module_init(void)
197 return platform_driver_register(&omap_sdti_driver);
200 static void __exit omap_sdti_module_exit(void)
202 platform_driver_unregister(&omap_sdti_driver);
204 subsys_initcall(omap_sdti_module_init);
205 module_exit(omap_sdti_module_exit);
207 MODULE_AUTHOR("Roman Tereshonkov");
208 MODULE_LICENSE("GPL");