Linus Walleij | 401301c | 2012-11-20 22:39:31 +0100 | [diff] [blame^] | 1 | /* |
| 2 | * Clock driver for the ARM Integrator/AP and Integrator/CP 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 | */ |
| 9 | #include <linux/clk-provider.h> |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 10 | #include <linux/clk.h> |
| 11 | #include <linux/clkdev.h> |
| 12 | #include <linux/err.h> |
| 13 | #include <linux/io.h> |
Linus Walleij | a613163 | 2012-06-11 17:33:12 +0200 | [diff] [blame] | 14 | |
| 15 | #include <mach/hardware.h> |
| 16 | #include <mach/platform.h> |
| 17 | |
| 18 | #include "clk-icst.h" |
| 19 | |
| 20 | /* |
| 21 | * Implementation of the ARM Integrator/AP and Integrator/CP clock tree. |
| 22 | * Inspired by portions of: |
| 23 | * plat-versatile/clock.c and plat-versatile/include/plat/clock.h |
| 24 | */ |
| 25 | #define CM_LOCK (__io_address(INTEGRATOR_HDR_BASE)+INTEGRATOR_HDR_LOCK_OFFSET) |
| 26 | #define CM_AUXOSC (__io_address(INTEGRATOR_HDR_BASE)+0x1c) |
| 27 | |
| 28 | /** |
| 29 | * cp_auxvco_get() - get ICST VCO settings for the Integrator/CP |
| 30 | * @vco: ICST VCO parameters to update with hardware status |
| 31 | */ |
| 32 | static struct icst_vco cp_auxvco_get(void) |
| 33 | { |
| 34 | u32 val; |
| 35 | struct icst_vco vco; |
| 36 | |
| 37 | val = readl(CM_AUXOSC); |
| 38 | vco.v = val & 0x1ff; |
| 39 | vco.r = (val >> 9) & 0x7f; |
| 40 | vco.s = (val >> 16) & 03; |
| 41 | return vco; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * cp_auxvco_set() - commit changes to Integrator/CP ICST VCO |
| 46 | * @vco: ICST VCO parameters to commit |
| 47 | */ |
| 48 | static void cp_auxvco_set(struct icst_vco vco) |
| 49 | { |
| 50 | u32 val; |
| 51 | |
| 52 | val = readl(CM_AUXOSC) & ~0x7ffff; |
| 53 | val |= vco.v | (vco.r << 9) | (vco.s << 16); |
| 54 | |
| 55 | /* This magic unlocks the CM VCO so it can be controlled */ |
| 56 | writel(0xa05f, CM_LOCK); |
| 57 | writel(val, CM_AUXOSC); |
| 58 | /* This locks the CM again */ |
| 59 | writel(0, CM_LOCK); |
| 60 | } |
| 61 | |
| 62 | static const struct icst_params cp_auxvco_params = { |
| 63 | .ref = 24000000, |
| 64 | .vco_max = ICST525_VCO_MAX_5V, |
| 65 | .vco_min = ICST525_VCO_MIN, |
| 66 | .vd_min = 8, |
| 67 | .vd_max = 263, |
| 68 | .rd_min = 3, |
| 69 | .rd_max = 65, |
| 70 | .s2div = icst525_s2div, |
| 71 | .idx2s = icst525_idx2s, |
| 72 | }; |
| 73 | |
| 74 | static const struct clk_icst_desc __initdata cp_icst_desc = { |
| 75 | .params = &cp_auxvco_params, |
| 76 | .getvco = cp_auxvco_get, |
| 77 | .setvco = cp_auxvco_set, |
| 78 | }; |
| 79 | |
| 80 | /* |
| 81 | * integrator_clk_init() - set up the integrator clock tree |
| 82 | * @is_cp: pass true if it's the Integrator/CP else AP is assumed |
| 83 | */ |
| 84 | void __init integrator_clk_init(bool is_cp) |
| 85 | { |
| 86 | struct clk *clk; |
| 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 | /* UART reference clock */ |
| 93 | clk = clk_register_fixed_rate(NULL, "uartclk", NULL, CLK_IS_ROOT, |
| 94 | 14745600); |
| 95 | clk_register_clkdev(clk, NULL, "uart0"); |
| 96 | clk_register_clkdev(clk, NULL, "uart1"); |
| 97 | if (is_cp) |
| 98 | clk_register_clkdev(clk, NULL, "mmci"); |
| 99 | |
| 100 | /* 24 MHz clock */ |
| 101 | clk = clk_register_fixed_rate(NULL, "clk24mhz", NULL, CLK_IS_ROOT, |
| 102 | 24000000); |
| 103 | clk_register_clkdev(clk, NULL, "kmi0"); |
| 104 | clk_register_clkdev(clk, NULL, "kmi1"); |
| 105 | if (!is_cp) |
| 106 | clk_register_clkdev(clk, NULL, "ap_timer"); |
| 107 | |
| 108 | if (!is_cp) |
| 109 | return; |
| 110 | |
| 111 | /* 1 MHz clock */ |
| 112 | clk = clk_register_fixed_rate(NULL, "clk1mhz", NULL, CLK_IS_ROOT, |
| 113 | 1000000); |
| 114 | clk_register_clkdev(clk, NULL, "sp804"); |
| 115 | |
| 116 | /* ICST VCO clock used on the Integrator/CP CLCD */ |
| 117 | clk = icst_clk_register(NULL, &cp_icst_desc); |
| 118 | clk_register_clkdev(clk, NULL, "clcd"); |
| 119 | } |