]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/misc/sti/sdti.c
SDTI: Fix sdti to use right clocks from clockfw
[linux-2.6-omap-h63xx.git] / drivers / misc / sti / sdti.c
index adfbcbc7e7ad27ea2d0a38b4bcfa43ce11904fff..8c275049ad7d130570c6955b65640a8609d4110d 100644 (file)
@@ -16,7 +16,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/clk.h>
-#include <asm/arch/sti.h>
+#include <mach/sti.h>
 #include <asm/byteorder.h>
 #include <asm/io.h>
 
 #define CPU1_TRACE_EN          0x01
 #define CPU2_TRACE_EN          0x02
 
-#define EPM_BASE               0x5401D000
-#define EPM_CONTROL_0          0x50
-#define EPM_CONTROL_1          0x54
-#define EPM_CONTROL_2          0x58
+#define SDTI_SYSCONFIG_SOFTRESET       (1 << 1)
+#define SDTI_SYSCONFIG_AUTOIDLE                (1 << 0)
 
-static struct clk *sdti_ck;
-unsigned long sti_base, sti_channel_base, epm_base;
+static struct clk *sdti_fck, *sdti_ick;
+void __iomem *sti_base, *sti_channel_base;
 static DEFINE_SPINLOCK(sdti_lock);
 
-void omap_sti_channel_write_trace(int len, int id, void *data,
+void sti_channel_write_trace(int len, int id, void *data,
                                unsigned int channel)
 {
        const u8 *tpntr = data;
@@ -54,13 +52,13 @@ void omap_sti_channel_write_trace(int len, int id, void *data,
 
        spin_unlock_irq(&sdti_lock);
 }
-EXPORT_SYMBOL(omap_sti_channel_write_trace);
+EXPORT_SYMBOL(sti_channel_write_trace);
 
 static void omap_sdti_reset(void)
 {
        int i;
 
-       sti_writel(0x02, SDTI_SYSCONFIG);
+       sti_writel(SDTI_SYSCONFIG_SOFTRESET, SDTI_SYSCONFIG);
 
        for (i = 0; i < 10000; i++)
                if (sti_readl(SDTI_SYSSTATUS) & 1)
@@ -69,38 +67,40 @@ static void omap_sdti_reset(void)
                printk(KERN_WARNING "XTI: no real reset\n");
 }
 
-void init_epm(void)
-{
-       epm_base = (unsigned long)ioremap(EPM_BASE, 256);
-       if (unlikely(!epm_base)) {
-               printk(KERN_ERR "EPM cannot be ioremapped\n");
-               return;
-       }
-
-       __raw_writel(1<<30, epm_base + EPM_CONTROL_2);
-       __raw_writel(0x78, epm_base + EPM_CONTROL_0);
-       __raw_writel(0x80000000, epm_base + EPM_CONTROL_1);
-       __raw_writel(1<<31 | 0x00007770, epm_base + EPM_CONTROL_2);
-}
-
 static int __init omap_sdti_init(void)
 {
        char buf[64];
-       int i;
+       int i, ret = 0;
 
-       sdti_ck = clk_get(NULL, "emu_per_alwon_ck");
-       if (IS_ERR(sdti_ck)) {
-               printk(KERN_ERR "Cannot get clk emu_per_alwon_ck\n");
-               return PTR_ERR(sdti_ck);
+       sdti_fck = clk_get(NULL, "pclk_fck");
+       if (IS_ERR(sdti_fck)) {
+               printk(KERN_ERR "Cannot get clk pclk_fck\n");
+               ret = PTR_ERR(sdti_fck);
+               goto err0;
+       }
+       sdti_ick = clk_get(NULL, "pclkx2_fck");
+       if (IS_ERR(sdti_ick)) {
+               printk(KERN_ERR "Cannot get clk pclkx2_fck\n");
+               ret = PTR_ERR(sdti_ick);
+               goto err1;
+       }
+       ret = clk_enable(sdti_fck);
+       if (ret) {
+               printk(KERN_ERR "Cannot enable sdti_fck\n");
+               goto err2;
+       }
+       ret = clk_enable(sdti_ick);
+       if (ret) {
+               printk(KERN_ERR "Cannot enable sdti_ick\n");
+               goto err3;
        }
-       clk_enable(sdti_ck);
-
-       /* Init emulation pin manager */
-       init_epm();
 
        omap_sdti_reset();
        sti_writel(0xC5ACCE55, SDTI_LOCK_ACCESS);
 
+       /* Autoidle */
+       sti_writel(SDTI_SYSCONFIG_AUTOIDLE, SDTI_SYSCONFIG);
+
        /* Claim SDTI */
        sti_writel(1 << 30, SDTI_WINCTRL);
        i = sti_readl(SDTI_WINCTRL);
@@ -110,7 +110,7 @@ static int __init omap_sdti_init(void)
        /* 4 bits dual, fclk/3 */
        sti_writel(0x43, SDTI_SCONFIG);
 
-       /* CPU1 trace enable */
+       /* CPU2 trace enable */
        sti_writel(i | CPU2_TRACE_EN, SDTI_WINCTRL);
        i = sti_readl(SDTI_WINCTRL);
 
@@ -121,16 +121,27 @@ static int __init omap_sdti_init(void)
        snprintf(buf, sizeof(buf), "OMAP SDTI support loaded (HW v%u.%u)\n",
                (i >> 4) & 0x0f, i & 0x0f);
        printk(KERN_INFO "%s", buf);
-       omap_sti_channel_write_trace(strlen(buf), 0xc3, buf, 239);
-
-       return 0;
+       sti_channel_write_trace(strlen(buf), 0xc3, buf, 239);
+
+       return ret;
+
+err3:
+       clk_disable(sdti_fck);
+err2:
+       clk_put(sdti_ick);
+err1:
+       clk_put(sdti_fck);
+err0:
+       return ret;
 }
 
 static void omap_sdti_exit(void)
 {
        sti_writel(0, SDTI_WINCTRL);
-       clk_disable(sdti_ck);
-       clk_put(sdti_ck);
+       clk_disable(sdti_fck);
+       clk_disable(sdti_ick);
+       clk_put(sdti_fck);
+       clk_put(sdti_ick);
 }
 
 static int __devinit omap_sdti_probe(struct platform_device *pdev)
@@ -159,14 +170,14 @@ static int __devinit omap_sdti_probe(struct platform_device *pdev)
        }
 
        size = res->end - res->start;
-       sti_base = (unsigned long)ioremap(res->start, size);
+       sti_base = ioremap(res->start, size);
        if (unlikely(!sti_base))
                return -ENODEV;
 
        size = cres->end - cres->start;
-       sti_channel_base = (unsigned long)ioremap(cres->start, size);
+       sti_channel_base = ioremap(cres->start, size);
        if (unlikely(!sti_channel_base)) {
-               iounmap((void *)sti_base);
+               iounmap(sti_base);
                return -ENODEV;
        }
 
@@ -175,9 +186,8 @@ static int __devinit omap_sdti_probe(struct platform_device *pdev)
 
 static int __devexit omap_sdti_remove(struct platform_device *pdev)
 {
-       iounmap((void *)sti_channel_base);
-       iounmap((void *)sti_base);
-       iounmap((void *)epm_base);
+       iounmap(sti_channel_base);
+       iounmap(sti_base);
        omap_sdti_exit();
 
        return 0;