Linus Walleij | 401301c | 2012-11-20 22:39:31 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Clock driver for the ARM RealView boards |
| 3 | * Copyright (C) 2012 Linus Walleij |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License version 2 as |
| 7 | * published by the Free Software Foundation. |
| 8 | */ |
Linus Walleij | f9a6aa4 | 2012-08-06 18:32:08 +0200 | [diff] [blame] | 9 | #include <linux/clk.h> |
| 10 | #include <linux/clkdev.h> |
| 11 | #include <linux/err.h> |
| 12 | #include <linux/io.h> |
| 13 | #include <linux/clk-provider.h> |
| 14 | |
| 15 | #include <mach/hardware.h> |
| 16 | #include <mach/platform.h> |
| 17 | |
| 18 | #include "clk-icst.h" |
| 19 | |
| 20 | /* |
| 21 | * Implementation of the ARM RealView clock trees. |
| 22 | */ |
| 23 | |
| 24 | static void __iomem *sys_lock; |
| 25 | static void __iomem *sys_vcoreg; |
| 26 | |
| 27 | /** |
| 28 | * realview_oscvco_get() - get ICST OSC settings for the RealView |
| 29 | */ |
| 30 | static struct icst_vco realview_oscvco_get(void) |
| 31 | { |
| 32 | u32 val; |
| 33 | struct icst_vco vco; |
| 34 | |
| 35 | val = readl(sys_vcoreg); |
| 36 | vco.v = val & 0x1ff; |
| 37 | vco.r = (val >> 9) & 0x7f; |
| 38 | vco.s = (val >> 16) & 03; |
| 39 | return vco; |
| 40 | } |
| 41 | |
| 42 | static void realview_oscvco_set(struct icst_vco vco) |
| 43 | { |
| 44 | u32 val; |
| 45 | |
| 46 | val = readl(sys_vcoreg) & ~0x7ffff; |
| 47 | val |= vco.v | (vco.r << 9) | (vco.s << 16); |
| 48 | |
| 49 | /* This magic unlocks the CM VCO so it can be controlled */ |
| 50 | writel(0xa05f, sys_lock); |
| 51 | writel(val, sys_vcoreg); |
| 52 | /* This locks the CM again */ |
| 53 | writel(0, sys_lock); |
| 54 | } |
| 55 | |
| 56 | static const struct icst_params realview_oscvco_params = { |
| 57 | .ref = 24000000, |
| 58 | .vco_max = ICST307_VCO_MAX, |
| 59 | .vco_min = ICST307_VCO_MIN, |
| 60 | .vd_min = 4 + 8, |
| 61 | .vd_max = 511 + 8, |
| 62 | .rd_min = 1 + 2, |
| 63 | .rd_max = 127 + 2, |
| 64 | .s2div = icst307_s2div, |
| 65 | .idx2s = icst307_idx2s, |
| 66 | }; |
| 67 | |
| 68 | static const struct clk_icst_desc __initdata realview_icst_desc = { |
| 69 | .params = &realview_oscvco_params, |
| 70 | .getvco = realview_oscvco_get, |
| 71 | .setvco = realview_oscvco_set, |
| 72 | }; |
| 73 | |
| 74 | /* |
| 75 | * realview_clk_init() - set up the RealView clock tree |
| 76 | */ |
| 77 | void __init realview_clk_init(void __iomem *sysbase, bool is_pb1176) |
| 78 | { |
| 79 | struct clk *clk; |
| 80 | |
| 81 | sys_lock = sysbase + REALVIEW_SYS_LOCK_OFFSET; |
| 82 | if (is_pb1176) |
| 83 | sys_vcoreg = sysbase + REALVIEW_SYS_OSC0_OFFSET; |
| 84 | else |
| 85 | sys_vcoreg = sysbase + REALVIEW_SYS_OSC4_OFFSET; |
| 86 | |
| 87 | |
| 88 | /* APB clock dummy */ |
| 89 | clk = clk_register_fixed_rate(NULL, "apb_pclk", NULL, CLK_IS_ROOT, 0); |
| 90 | clk_register_clkdev(clk, "apb_pclk", NULL); |
| 91 | |
| 92 | /* 24 MHz clock */ |
| 93 | clk = clk_register_fixed_rate(NULL, "clk24mhz", NULL, CLK_IS_ROOT, |
| 94 | 24000000); |
| 95 | clk_register_clkdev(clk, NULL, "dev:uart0"); |
| 96 | clk_register_clkdev(clk, NULL, "dev:uart1"); |
| 97 | clk_register_clkdev(clk, NULL, "dev:uart2"); |
| 98 | clk_register_clkdev(clk, NULL, "fpga:kmi0"); |
| 99 | clk_register_clkdev(clk, NULL, "fpga:kmi1"); |
| 100 | clk_register_clkdev(clk, NULL, "fpga:mmc0"); |
| 101 | clk_register_clkdev(clk, NULL, "dev:ssp0"); |
| 102 | if (is_pb1176) { |
| 103 | /* |
| 104 | * UART3 is on the dev chip in PB1176 |
| 105 | * UART4 only exists in PB1176 |
| 106 | */ |
| 107 | clk_register_clkdev(clk, NULL, "dev:uart3"); |
| 108 | clk_register_clkdev(clk, NULL, "dev:uart4"); |
| 109 | } else |
| 110 | clk_register_clkdev(clk, NULL, "fpga:uart3"); |
| 111 | |
| 112 | |
| 113 | /* 1 MHz clock */ |
| 114 | clk = clk_register_fixed_rate(NULL, "clk1mhz", NULL, CLK_IS_ROOT, |
| 115 | 1000000); |
| 116 | clk_register_clkdev(clk, NULL, "sp804"); |
| 117 | |
| 118 | /* ICST VCO clock */ |
| 119 | clk = icst_clk_register(NULL, &realview_icst_desc); |
| 120 | clk_register_clkdev(clk, NULL, "dev:clcd"); |
| 121 | clk_register_clkdev(clk, NULL, "issp:clcd"); |
| 122 | } |