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 11#include <linux/cpufreq.h> 12#include <asm/hardware.h> 13#include <asm/arch/clocks.h> 14#include <linux/err.h> 15 16struct module; 17struct icst525_params; 18 19struct clk { 20 struct list_head node; 21 unsigned long rate; 22 struct module *owner; 23 const char *name; 24// void *data; 25// const struct icst525_params *params; 26// void (*setvco)(struct clk *, struct icst525_vco vco); 27}; 28 29int clk_register(struct clk *clk); 30void clk_unregister(struct clk *clk); 31 32/* ----- */ 33 34#define MAINDIV1(c) (((c) >> 7) & 0x0f) 35#define MAINDIV2(c) (((c) >> 11) & 0x1f) 36#define PS(c) (((c) >> 18) & 0x03) 37#define PREDIV(c) (((c) >> 2) & 0x1f) 38#define HCLKDIV(c) (((c) >> 0) & 0x02) 39#define PCLKDIV(c) (((c) >> 16) & 0x03) 40 41unsigned int cpufreq_get (unsigned int cpu) /* in kHz */ 42{ 43 return fclkfreq_get ()/1000; 44} 45EXPORT_SYMBOL(cpufreq_get); 46 47unsigned int fclkfreq_get (void) 48{ 49 unsigned int clkset = CSC_CLKSET; 50 unsigned int gclk 51 = XTAL_IN 52 / (1 << PS(clkset)) 53 * (MAINDIV1(clkset) + 2) 54 / (PREDIV(clkset) + 2) 55 * (MAINDIV2(clkset) + 2) 56 ; 57 return gclk; 58} 59 60unsigned int hclkfreq_get (void) 61{ 62 unsigned int clkset = CSC_CLKSET; 63 unsigned int hclk = fclkfreq_get () / (HCLKDIV(clkset) + 1); 64 65 return hclk; 66} 67 68unsigned int pclkfreq_get (void) 69{ 70 unsigned int clkset = CSC_CLKSET; 71 int pclkdiv = PCLKDIV(clkset); 72 unsigned int pclk; 73 if (pclkdiv == 0x3) 74 pclkdiv = 0x2; 75 pclk = hclkfreq_get () / (1 << pclkdiv); 76 77 return pclk; 78} 79 80/* ----- */ 81 82static LIST_HEAD(clocks); 83static DECLARE_MUTEX(clocks_sem); 84 85struct clk *clk_get (struct device *dev, const char *id) 86{ 87 struct clk *p; 88 struct clk *clk = ERR_PTR(-ENOENT); 89 90 down (&clocks_sem); 91 list_for_each_entry (p, &clocks, node) { 92 if (strcmp (id, p->name) == 0 93 && try_module_get(p->owner)) { 94 clk = p; 95 break; 96 } 97 } 98 up (&clocks_sem); 99 100 return clk; 101} 102EXPORT_SYMBOL(clk_get); 103 104void clk_put (struct clk *clk) 105{ 106 module_put(clk->owner); 107} 108EXPORT_SYMBOL(clk_put); 109 110int clk_enable (struct clk *clk) 111{ 112 return 0; 113} 114EXPORT_SYMBOL(clk_enable); 115 116void clk_disable (struct clk *clk) 117{ 118} 119EXPORT_SYMBOL(clk_disable); 120 121int clk_use (struct clk *clk) 122{ 123 return 0; 124} 125EXPORT_SYMBOL(clk_use); 126 127void clk_unuse (struct clk *clk) 128{ 129} 130EXPORT_SYMBOL(clk_unuse); 131 132unsigned long clk_get_rate (struct clk *clk) 133{ 134 return clk->rate; 135} 136EXPORT_SYMBOL(clk_get_rate); 137 138long clk_round_rate (struct clk *clk, unsigned long rate) 139{ 140 return rate; 141} 142EXPORT_SYMBOL(clk_round_rate); 143 144int clk_set_rate (struct clk *clk, unsigned long rate) 145{ 146 int ret = -EIO; 147 return ret; 148} 149EXPORT_SYMBOL(clk_set_rate); 150 151 152static struct clk clcd_clk = { 153 .name = "CLCDCLK", 154 .rate = 0, 155}; 156 157int clk_register (struct clk *clk) 158{ 159 down (&clocks_sem); 160 list_add (&clk->node, &clocks); 161 up (&clocks_sem); 162 return 0; 163} 164EXPORT_SYMBOL(clk_register); 165 166void clk_unregister (struct clk *clk) 167{ 168 down (&clocks_sem); 169 list_del (&clk->node); 170 up (&clocks_sem); 171} 172EXPORT_SYMBOL(clk_unregister); 173 174static int __init clk_init (void) 175{ 176 clk_register(&clcd_clk); 177 return 0; 178} 179arch_initcall(clk_init); 180