[ar7] use the righ value in the DSP clock calculation
[openwrt-10.03/.git] / target / linux / ar7 / files / arch / mips / ar7 / clock.c
index 139e91517591ac0cda23a807a5ef8d020aa83eb1..25e6b7326c391eac75662363852faece3e4effc2 100644 (file)
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2007 OpenWrt.org
+ * Copyright (C) 2007 Felix Fietkau <nbd@openwrt.org>
+ * Copyright (C) 2007 Eugene Konev <ejka@openwrt.org>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #define TNETD7200_DEF_USB_CLK  48000000
 
 struct tnetd7300_clock {
-       volatile u32 ctrl;
+       u32 ctrl;
 #define PREDIV_MASK    0x001f0000
 #define PREDIV_SHIFT   16
 #define POSTDIV_MASK   0x0000001f
        u32 unused1[3];
-       volatile u32 pll;
+       u32 pll;
 #define MUL_MASK       0x0000f000
 #define MUL_SHIFT      12
 #define PLL_MODE_MASK  0x00000001
@@ -60,35 +61,35 @@ struct tnetd7300_clock {
 #define PLL_DIV                0x00000002
 #define PLL_STATUS     0x00000001
        u32 unused2[3];
-} __packed;
+};
 
 struct tnetd7300_clocks {
        struct tnetd7300_clock bus;
        struct tnetd7300_clock cpu;
        struct tnetd7300_clock usb;
        struct tnetd7300_clock dsp;
-} __packed;
+};
 
 struct tnetd7200_clock {
-       volatile u32 ctrl;
+       u32 ctrl;
        u32 unused1[3];
 #define DIVISOR_ENABLE_MASK 0x00008000
-       volatile u32 mul;
-       volatile u32 prediv;
-       volatile u32 postdiv;
-       volatile u32 postdiv2;
+       u32 mul;
+       u32 prediv;
+       u32 postdiv;
+       u32 postdiv2;
        u32 unused2[6];
-       volatile u32 cmd;
-       volatile u32 status;
-       volatile u32 cmden;
+       u32 cmd;
+       u32 status;
+       u32 cmden;
        u32 padding[15];
-} __packed;
+};
 
 struct tnetd7200_clocks {
        struct tnetd7200_clock cpu;
        struct tnetd7200_clock dsp;
        struct tnetd7200_clock usb;
-} __packed;
+};
 
 int ar7_cpu_clock = 150000000;
 EXPORT_SYMBOL(ar7_cpu_clock);
@@ -179,8 +180,8 @@ static int tnetd7300_get_clock(u32 shift, struct tnetd7300_clock *clock,
 {
        int product;
        int base_clock = AR7_REF_CLOCK;
-       u32 ctrl = clock->ctrl;
-       u32 pll = clock->pll;
+       u32 ctrl = readl(&clock->ctrl);
+       u32 pll = readl(&clock->pll);
        int prediv = ((ctrl & PREDIV_MASK) >> PREDIV_SHIFT) + 1;
        int postdiv = (ctrl & POSTDIV_MASK) + 1;
        int divisor = prediv * postdiv;
@@ -223,7 +224,6 @@ static int tnetd7300_get_clock(u32 shift, struct tnetd7300_clock *clock,
 static void tnetd7300_set_clock(u32 shift, struct tnetd7300_clock *clock,
        u32 *bootcr, u32 frequency)
 {
-       u32 status;
        int prediv, postdiv, mul;
        int base_clock = ar7_bus_clock;
 
@@ -244,13 +244,11 @@ static void tnetd7300_set_clock(u32 shift, struct tnetd7300_clock *clock,
 
        calculate(base_clock, frequency, &prediv, &postdiv, &mul);
 
-       clock->ctrl = ((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1);
+       writel(((prediv - 1) << PREDIV_SHIFT) | (postdiv - 1), &clock->ctrl);
        mdelay(1);
-       clock->pll = 4;
-       do
-               status = clock->pll;
-       while (status & PLL_STATUS);
-       clock->pll = ((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e;
+       writel(4, &clock->pll);
+       while (readl(&clock->pll) & PLL_STATUS);
+       writel(((mul - 1) << MUL_SHIFT) | (0xff << 3) | 0x0e, &clock->pll);
        mdelay(75);
 }
 
@@ -285,13 +283,13 @@ static void __init tnetd7300_init_clocks(void)
 static int tnetd7200_get_clock(int base, struct tnetd7200_clock *clock,
        u32 *bootcr, u32 bus_clock)
 {
-       int divisor = ((clock->prediv & 0x1f) + 1) *
-               ((clock->postdiv & 0x1f) + 1);
+       int divisor = ((readl(&clock->prediv) & 0x1f) + 1) *
+               ((readl(&clock->postdiv) & 0x1f) + 1);
 
        if (*bootcr & BOOT_PLL_BYPASS)
                return base / divisor;
 
-       return base * ((clock->mul & 0xf) + 1) / divisor;
+       return base * ((readl(&clock->mul) & 0xf) + 1) / divisor;
 }
 
 
@@ -303,29 +301,29 @@ static void tnetd7200_set_clock(int base, struct tnetd7200_clock *clock,
                "postdiv = %d, postdiv2 = %d, mul = %d\n",
                base, frequency, prediv, postdiv, postdiv2, mul);
 
-       clock->ctrl = 0;
-       clock->prediv = DIVISOR_ENABLE_MASK | ((prediv - 1) & 0x1F);
-       clock->mul = ((mul - 1) & 0xF);
+       writel(0, &clock->ctrl);
+       writel(DIVISOR_ENABLE_MASK | ((prediv - 1) & 0x1F), &clock->prediv);
+       writel((mul - 1) & 0xF, &clock->mul);
 
        for (mul = 0; mul < 2000; mul++) /* nop */;
 
-       while (clock->status & 0x1) /* nop */;
+       while (readl(&clock->status) & 0x1) /* nop */;
 
-       clock->postdiv = DIVISOR_ENABLE_MASK | ((postdiv - 1) & 0x1F);
+       writel(DIVISOR_ENABLE_MASK | ((postdiv - 1) & 0x1F), &clock->postdiv);
 
-       clock->cmden |= 1;
-       clock->cmd |= 1;
+       writel(readl(&clock->cmden) | 1, &clock->cmden);
+       writel(readl(&clock->cmd) | 1, &clock->cmd);
 
-       while (clock->status & 0x1) /* nop */;
+       while (readl(&clock->status) & 0x1) /* nop */;
 
-       clock->postdiv2 = DIVISOR_ENABLE_MASK | ((postdiv2 - 1) & 0x1F);
+       writel(DIVISOR_ENABLE_MASK | ((postdiv2 - 1) & 0x1F), &clock->postdiv2);
 
-       clock->cmden |= 1;
-       clock->cmd |= 1;
+       writel(readl(&clock->cmden) | 1, &clock->cmden);
+       writel(readl(&clock->cmd) | 1, &clock->cmd);
 
-       while (clock->status & 0x1) /* nop */;
+       while (readl(&clock->status) & 0x1) /* nop */;
 
-       clock->ctrl |= 1;
+       writel(readl(&clock->ctrl) | 1, &clock->ctrl);
 }
 
 static int tnetd7200_get_clock_base(int clock_id, u32 *bootcr)
@@ -439,7 +437,7 @@ static void __init tnetd7200_init_clocks(void)
                        printk(KERN_INFO "Clocks: Sync 1:1 mode\n");
 
                        printk(KERN_INFO "Clocks: Setting DSP clock\n");
-                       calculate(dsp_base, TNETD7200_DEF_CPU_CLK, &dsp_prediv,
+                       calculate(dsp_base, TNETD7200_DEF_DSP_CLK, &dsp_prediv,
                                &dsp_postdiv, &dsp_mul);
                        ar7_bus_clock = ((dsp_base / dsp_prediv) * dsp_mul)
                                                                / dsp_postdiv;