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 | */ |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 10 | #include <mach/hardware.h> |
| 11 | #include <mach/clocks.h> |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 12 | #include <linux/err.h> |
Peter Hüwe | 657b366 | 2010-01-09 13:46:57 +0100 | [diff] [blame] | 13 | #include <linux/device.h> |
| 14 | #include <linux/string.h> |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 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 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 34 | unsigned int fclkfreq_get (void) |
| 35 | { |
| 36 | unsigned int clkset = CSC_CLKSET; |
| 37 | unsigned int gclk |
| 38 | = XTAL_IN |
| 39 | / (1 << PS(clkset)) |
| 40 | * (MAINDIV1(clkset) + 2) |
| 41 | / (PREDIV(clkset) + 2) |
| 42 | * (MAINDIV2(clkset) + 2) |
| 43 | ; |
| 44 | return gclk; |
| 45 | } |
| 46 | |
| 47 | unsigned int hclkfreq_get (void) |
| 48 | { |
| 49 | unsigned int clkset = CSC_CLKSET; |
| 50 | unsigned int hclk = fclkfreq_get () / (HCLKDIV(clkset) + 1); |
| 51 | |
| 52 | return hclk; |
| 53 | } |
| 54 | |
| 55 | unsigned int pclkfreq_get (void) |
| 56 | { |
| 57 | unsigned int clkset = CSC_CLKSET; |
| 58 | int pclkdiv = PCLKDIV(clkset); |
| 59 | unsigned int pclk; |
| 60 | if (pclkdiv == 0x3) |
| 61 | pclkdiv = 0x2; |
| 62 | pclk = hclkfreq_get () / (1 << pclkdiv); |
| 63 | |
| 64 | return pclk; |
| 65 | } |
| 66 | |
| 67 | /* ----- */ |
| 68 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 69 | struct clk *clk_get (struct device *dev, const char *id) |
| 70 | { |
Russell King | 80a5931 | 2008-11-30 17:34:32 +0000 | [diff] [blame] | 71 | return dev && strcmp(dev_name(dev), "cldc-lh7a40x") == 0 |
| 72 | ? NULL : ERR_PTR(-ENOENT); |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 73 | } |
| 74 | EXPORT_SYMBOL(clk_get); |
| 75 | |
| 76 | void clk_put (struct clk *clk) |
| 77 | { |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 78 | } |
| 79 | EXPORT_SYMBOL(clk_put); |
| 80 | |
| 81 | int clk_enable (struct clk *clk) |
| 82 | { |
| 83 | return 0; |
| 84 | } |
| 85 | EXPORT_SYMBOL(clk_enable); |
| 86 | |
| 87 | void clk_disable (struct clk *clk) |
| 88 | { |
| 89 | } |
| 90 | EXPORT_SYMBOL(clk_disable); |
| 91 | |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 92 | unsigned long clk_get_rate (struct clk *clk) |
| 93 | { |
Russell King | 80a5931 | 2008-11-30 17:34:32 +0000 | [diff] [blame] | 94 | return 0; |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 95 | } |
| 96 | EXPORT_SYMBOL(clk_get_rate); |
| 97 | |
| 98 | long clk_round_rate (struct clk *clk, unsigned long rate) |
| 99 | { |
| 100 | return rate; |
| 101 | } |
| 102 | EXPORT_SYMBOL(clk_round_rate); |
| 103 | |
| 104 | int clk_set_rate (struct clk *clk, unsigned long rate) |
| 105 | { |
Russell King | 80a5931 | 2008-11-30 17:34:32 +0000 | [diff] [blame] | 106 | return -EIO; |
Marc Singer | 638b266 | 2006-05-16 11:41:28 +0100 | [diff] [blame] | 107 | } |
| 108 | EXPORT_SYMBOL(clk_set_rate); |