sh: mach-sdk7786: Detect/configure/propagate EXTAL.
authorPaul Mundt <lethal@linux-sh.org>
Tue, 19 Jan 2010 10:38:36 +0000 (19:38 +0900)
committerPaul Mundt <lethal@linux-sh.org>
Tue, 19 Jan 2010 10:38:36 +0000 (19:38 +0900)
This uses the mode pins exposed through the FPGA to work out whether
we're driven from EXTAL or not and does the appropriate setup and
propagation through the clock framework.

This will also -EINVAL out for anyone adding in their own oscillators,
forcing proper configuration with the clock framework instead of
proceeding on with bogus clock values.

Signed-off-by: Paul Mundt <lethal@linux-sh.org>
arch/sh/boards/mach-sdk7786/setup.c

index c38c6cc..0e4b1c3 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/smsc911x.h>
 #include <linux/i2c.h>
 #include <linux/irq.h>
+#include <linux/clk.h>
 #include <asm/machvec.h>
 #include <asm/heartbeat.h>
 #include <asm/sizes.h>
@@ -235,6 +236,27 @@ static int sdk7786_mode_pins(void)
        return pin_states;
 }
 
+static int sdk7786_clk_init(void)
+{
+       struct clk *clk;
+       int ret;
+
+       /*
+        * Only handle the EXTAL case, anyone interfacing a crystal
+        * resonator will need to provide their own input clock.
+        */
+       if (test_mode_pin(MODE_PIN9))
+               return -EINVAL;
+
+       clk = clk_get(NULL, "extal");
+       if (!clk || IS_ERR(clk))
+               return PTR_ERR(clk);
+       ret = clk_set_rate(clk, 33333333);
+       clk_put(clk);
+
+       return ret;
+}
+
 /* Initialize the board */
 static void __init sdk7786_setup(char **cmdline_p)
 {
@@ -248,5 +270,6 @@ static struct sh_machine_vector mv_sdk7786 __initmv = {
        .mv_name                = "SDK7786",
        .mv_setup               = sdk7786_setup,
        .mv_mode_pins           = sdk7786_mode_pins,
+       .mv_clk_init            = sdk7786_clk_init,
        .mv_init_irq            = init_sdk7786_IRQ,
 };