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>
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 static struct clk *sdti_ck;
35 void __iomem *sti_base, *sti_channel_base;
36 static DEFINE_SPINLOCK(sdti_lock);
38 void omap_sti_channel_write_trace(int len, int id, void *data,
41 const u8 *tpntr = data;
43 spin_lock_irq(&sdti_lock);
45 sti_channel_writeb(id, channel);
47 sti_channel_writeb(*tpntr++, channel);
48 sti_channel_flush(channel);
50 spin_unlock_irq(&sdti_lock);
52 EXPORT_SYMBOL(omap_sti_channel_write_trace);
54 static void omap_sdti_reset(void)
58 sti_writel(0x02, SDTI_SYSCONFIG);
60 for (i = 0; i < 10000; i++)
61 if (sti_readl(SDTI_SYSSTATUS) & 1)
64 printk(KERN_WARNING "XTI: no real reset\n");
67 static int __init omap_sdti_init(void)
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);
80 sti_writel(0xC5ACCE55, SDTI_LOCK_ACCESS);
83 sti_writel(1 << 30, SDTI_WINCTRL);
84 i = sti_readl(SDTI_WINCTRL);
86 printk(KERN_WARNING "SDTI: cannot claim SDTI\n");
88 /* 4 bits dual, fclk/3 */
89 sti_writel(0x43, SDTI_SCONFIG);
91 /* CPU2 trace enable */
92 sti_writel(i | CPU2_TRACE_EN, SDTI_WINCTRL);
93 i = sti_readl(SDTI_WINCTRL);
96 sti_writel((1 << 31) | (i & 0x3FFFFFFF), SDTI_WINCTRL);
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);
107 static void omap_sdti_exit(void)
109 sti_writel(0, SDTI_WINCTRL);
110 clk_disable(sdti_ck);
114 static int __devinit omap_sdti_probe(struct platform_device *pdev)
116 struct resource *res, *cres;
119 if (pdev->num_resources != 2) {
120 dev_err(&pdev->dev, "invalid number of resources: %d\n",
121 pdev->num_resources);
126 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
127 if (unlikely(!res)) {
128 dev_err(&pdev->dev, "invalid mem resource\n");
133 cres = platform_get_resource(pdev, IORESOURCE_MEM, 1);
134 if (unlikely(!cres)) {
135 dev_err(&pdev->dev, "invalid channel mem resource\n");
139 size = res->end - res->start;
140 sti_base = ioremap(res->start, size);
141 if (unlikely(!sti_base))
144 size = cres->end - cres->start;
145 sti_channel_base = ioremap(cres->start, size);
146 if (unlikely(!sti_channel_base)) {
151 return omap_sdti_init();
154 static int __devexit omap_sdti_remove(struct platform_device *pdev)
156 iounmap(sti_channel_base);
163 static struct platform_driver omap_sdti_driver = {
164 .probe = omap_sdti_probe,
165 .remove = __devexit_p(omap_sdti_remove),
168 .owner = THIS_MODULE,
172 static int __init omap_sdti_module_init(void)
174 return platform_driver_register(&omap_sdti_driver);
177 static void __exit omap_sdti_module_exit(void)
179 platform_driver_unregister(&omap_sdti_driver);
181 subsys_initcall(omap_sdti_module_init);
182 module_exit(omap_sdti_module_exit);
184 MODULE_AUTHOR("Roman Tereshonkov");
185 MODULE_LICENSE("GPL");