Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 1 | /* arch/arm/mach-lh7a40x/clocks.c |
| 2 | * |
| 3 | * Copyright (C) 2004 Marc Singer |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * version 2 as published by the Free Software Foundation. |
| 8 | * |
| 9 | */ |
| 10 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 11 | #include <linux/cpufreq.h> |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 12 | #include <mach/hardware.h> |
| 13 | #include <mach/clocks.h> |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 14 | #include <linux/err.h> |
| 15 | |
| 16 | struct module; |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 17 | |
| 18 | struct clk { |
| 19 | struct list_head node; |
| 20 | unsigned long rate; |
| 21 | struct module *owner; |
| 22 | const char *name; |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 25 | /* ----- */ |
| 26 | |
| 27 | #define MAINDIV1(c) (((c) >> 7) & 0x0f) |
| 28 | #define MAINDIV2(c) (((c) >> 11) & 0x1f) |
| 29 | #define PS(c) (((c) >> 18) & 0x03) |
| 30 | #define PREDIV(c) (((c) >> 2) & 0x1f) |
| 31 | #define HCLKDIV(c) (((c) >> 0) & 0x02) |
| 32 | #define PCLKDIV(c) (((c) >> 16) & 0x03) |
| 33 | |
| 34 | unsigned int cpufreq_get (unsigned int cpu) /* in kHz */ |
| 35 | { |
| 36 | return fclkfreq_get ()/1000; |
| 37 | } |
| 38 | EXPORT_SYMBOL(cpufreq_get); |
| 39 | |
| 40 | unsigned int fclkfreq_get (void) |
| 41 | { |
| 42 | unsigned int clkset = CSC_CLKSET; |
| 43 | unsigned int gclk |
| 44 | = XTAL_IN |
| 45 | / (1 << PS(clkset)) |
| 46 | * (MAINDIV1(clkset) + 2) |
| 47 | / (PREDIV(clkset) + 2) |
| 48 | * (MAINDIV2(clkset) + 2) |
| 49 | ; |
| 50 | return gclk; |
| 51 | } |
| 52 | |
| 53 | unsigned int hclkfreq_get (void) |
| 54 | { |
| 55 | unsigned int clkset = CSC_CLKSET; |
| 56 | unsigned int hclk = fclkfreq_get () / (HCLKDIV(clkset) + 1); |
| 57 | |
| 58 | return hclk; |
| 59 | } |
| 60 | |
| 61 | unsigned int pclkfreq_get (void) |
| 62 | { |
| 63 | unsigned int clkset = CSC_CLKSET; |
| 64 | int pclkdiv = PCLKDIV(clkset); |
| 65 | unsigned int pclk; |
| 66 | if (pclkdiv == 0x3) |
| 67 | pclkdiv = 0x2; |
| 68 | pclk = hclkfreq_get () / (1 << pclkdiv); |
| 69 | |
| 70 | return pclk; |
| 71 | } |
| 72 | |
| 73 | /* ----- */ |
| 74 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 75 | struct clk *clk_get (struct device *dev, const char *id) |
| 76 | { |
Russell King | 80a5931 | 2008-11-30 17:34:32 +0000 | [diff] [blame] | 77 | return dev && strcmp(dev_name(dev), "cldc-lh7a40x") == 0 |
| 78 | ? NULL : ERR_PTR(-ENOENT); |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 79 | } |
| 80 | EXPORT_SYMBOL(clk_get); |
| 81 | |
| 82 | void clk_put (struct clk *clk) |
| 83 | { |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 84 | } |
| 85 | EXPORT_SYMBOL(clk_put); |
| 86 | |
| 87 | int clk_enable (struct clk *clk) |
| 88 | { |
| 89 | return 0; |
| 90 | } |
| 91 | EXPORT_SYMBOL(clk_enable); |
| 92 | |
| 93 | void clk_disable (struct clk *clk) |
| 94 | { |
| 95 | } |
| 96 | EXPORT_SYMBOL(clk_disable); |
| 97 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 98 | unsigned long clk_get_rate (struct clk *clk) |
| 99 | { |
Russell King | 80a5931 | 2008-11-30 17:34:32 +0000 | [diff] [blame] | 100 | return 0; |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 101 | } |
| 102 | EXPORT_SYMBOL(clk_get_rate); |
| 103 | |
| 104 | long clk_round_rate (struct clk *clk, unsigned long rate) |
| 105 | { |
| 106 | return rate; |
| 107 | } |
| 108 | EXPORT_SYMBOL(clk_round_rate); |
| 109 | |
| 110 | int clk_set_rate (struct clk *clk, unsigned long rate) |
| 111 | { |
Russell King | 80a5931 | 2008-11-30 17:34:32 +0000 | [diff] [blame] | 112 | return -EIO; |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 113 | } |
| 114 | EXPORT_SYMBOL(clk_set_rate); |