Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 1 | /* |
Uwe Kleine-König | 5886269 | 2007-05-09 07:51:49 +0200 | [diff] [blame] | 2 | * arch/sh/kernel/cpu/sh4a/clock-sh7780.c |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 3 | * |
| 4 | * SH7780 support for the clock framework |
| 5 | * |
| 6 | * Copyright (C) 2005 Paul Mundt |
| 7 | * |
| 8 | * This file is subject to the terms and conditions of the GNU General Public |
| 9 | * License. See the file "COPYING" in the main directory of this archive |
| 10 | * for more details. |
| 11 | */ |
| 12 | #include <linux/init.h> |
| 13 | #include <linux/kernel.h> |
| 14 | #include <asm/clock.h> |
| 15 | #include <asm/freq.h> |
| 16 | #include <asm/io.h> |
| 17 | |
| 18 | static int ifc_divisors[] = { 2, 4 }; |
| 19 | static int bfc_divisors[] = { 1, 1, 1, 8, 12, 16, 24, 1 }; |
| 20 | static int pfc_divisors[] = { 1, 24, 24, 1 }; |
| 21 | static int cfc_divisors[] = { 1, 1, 4, 1, 6, 1, 1, 1 }; |
| 22 | |
| 23 | static void master_clk_init(struct clk *clk) |
| 24 | { |
Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame^] | 25 | clk->rate *= pfc_divisors[__raw_readl(FRQCR) & 0x0003]; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | static struct clk_ops sh7780_master_clk_ops = { |
| 29 | .init = master_clk_init, |
| 30 | }; |
| 31 | |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 32 | static unsigned long module_clk_recalc(struct clk *clk) |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 33 | { |
Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame^] | 34 | int idx = (__raw_readl(FRQCR) & 0x0003); |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 35 | return clk->parent->rate / pfc_divisors[idx]; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | static struct clk_ops sh7780_module_clk_ops = { |
| 39 | .recalc = module_clk_recalc, |
| 40 | }; |
| 41 | |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 42 | static unsigned long bus_clk_recalc(struct clk *clk) |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 43 | { |
Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame^] | 44 | int idx = ((__raw_readl(FRQCR) >> 16) & 0x0007); |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 45 | return clk->parent->rate / bfc_divisors[idx]; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static struct clk_ops sh7780_bus_clk_ops = { |
| 49 | .recalc = bus_clk_recalc, |
| 50 | }; |
| 51 | |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 52 | static unsigned long cpu_clk_recalc(struct clk *clk) |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 53 | { |
Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame^] | 54 | int idx = ((__raw_readl(FRQCR) >> 24) & 0x0001); |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 55 | return clk->parent->rate / ifc_divisors[idx]; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static struct clk_ops sh7780_cpu_clk_ops = { |
| 59 | .recalc = cpu_clk_recalc, |
| 60 | }; |
| 61 | |
| 62 | static struct clk_ops *sh7780_clk_ops[] = { |
| 63 | &sh7780_master_clk_ops, |
| 64 | &sh7780_module_clk_ops, |
| 65 | &sh7780_bus_clk_ops, |
| 66 | &sh7780_cpu_clk_ops, |
| 67 | }; |
| 68 | |
| 69 | void __init arch_init_clk_ops(struct clk_ops **ops, int idx) |
| 70 | { |
| 71 | if (idx < ARRAY_SIZE(sh7780_clk_ops)) |
| 72 | *ops = sh7780_clk_ops[idx]; |
| 73 | } |
| 74 | |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 75 | static unsigned long shyway_clk_recalc(struct clk *clk) |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 76 | { |
Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame^] | 77 | int idx = ((__raw_readl(FRQCR) >> 20) & 0x0007); |
Paul Mundt | b68d8201 | 2009-05-12 03:45:08 +0900 | [diff] [blame] | 78 | return clk->parent->rate / cfc_divisors[idx]; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | static struct clk_ops sh7780_shyway_clk_ops = { |
| 82 | .recalc = shyway_clk_recalc, |
| 83 | }; |
| 84 | |
| 85 | static struct clk sh7780_shyway_clk = { |
| 86 | .name = "shyway_clk", |
Paul Mundt | 4ff29ff | 2009-05-12 05:14:53 +0900 | [diff] [blame] | 87 | .flags = CLK_ENABLE_ON_INIT, |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 88 | .ops = &sh7780_shyway_clk_ops, |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * Additional SH7780-specific on-chip clocks that aren't already part of the |
| 93 | * clock framework |
| 94 | */ |
| 95 | static struct clk *sh7780_onchip_clocks[] = { |
| 96 | &sh7780_shyway_clk, |
| 97 | }; |
| 98 | |
Paul Mundt | 9fe5ee0 | 2009-05-12 19:29:04 +0900 | [diff] [blame] | 99 | int __init arch_clk_init(void) |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 100 | { |
Paul Mundt | 253b088 | 2009-05-13 17:38:11 +0900 | [diff] [blame] | 101 | struct clk *clk; |
Paul Mundt | f5c84cf | 2009-05-12 05:59:27 +0900 | [diff] [blame] | 102 | int i, ret = 0; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 103 | |
Paul Mundt | 253b088 | 2009-05-13 17:38:11 +0900 | [diff] [blame] | 104 | cpg_clk_init(); |
| 105 | |
| 106 | clk = clk_get(NULL, "master_clk"); |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 107 | for (i = 0; i < ARRAY_SIZE(sh7780_onchip_clocks); i++) { |
| 108 | struct clk *clkp = sh7780_onchip_clocks[i]; |
| 109 | |
| 110 | clkp->parent = clk; |
Paul Mundt | f5c84cf | 2009-05-12 05:59:27 +0900 | [diff] [blame] | 111 | ret |= clk_register(clkp); |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 114 | clk_put(clk); |
| 115 | |
Paul Mundt | f5c84cf | 2009-05-12 05:59:27 +0900 | [diff] [blame] | 116 | return ret; |
Paul Mundt | 36ddf31 | 2006-01-16 22:14:17 -0800 | [diff] [blame] | 117 | } |