Path: blob/master/arch/mips/alchemy/common/clocks.c
10819 views
/*1* BRIEF MODULE DESCRIPTION2* Simple Au1xx0 clocks routines.3*4* Copyright 2001, 2008 MontaVista Software Inc.5* Author: MontaVista Software, Inc. <[email protected]>6*7* This program is free software; you can redistribute it and/or modify it8* under the terms of the GNU General Public License as published by the9* Free Software Foundation; either version 2 of the License, or (at your10* option) any later version.11*12* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED13* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF14* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN15* NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,16* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT17* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF18* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON19* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT20* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF21* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.22*23* You should have received a copy of the GNU General Public License along24* with this program; if not, write to the Free Software Foundation, Inc.,25* 675 Mass Ave, Cambridge, MA 02139, USA.26*/2728#include <linux/module.h>29#include <linux/spinlock.h>30#include <asm/time.h>31#include <asm/mach-au1x00/au1000.h>3233/*34* I haven't found anyone that doesn't use a 12 MHz source clock,35* but just in case.....36*/37#define AU1000_SRC_CLK 120000003839static unsigned int au1x00_clock; /* Hz */40static unsigned long uart_baud_base;4142/*43* Set the au1000_clock44*/45void set_au1x00_speed(unsigned int new_freq)46{47au1x00_clock = new_freq;48}4950unsigned int get_au1x00_speed(void)51{52return au1x00_clock;53}54EXPORT_SYMBOL(get_au1x00_speed);5556/*57* The UART baud base is not known at compile time ... if58* we want to be able to use the same code on different59* speed CPUs.60*/61unsigned long get_au1x00_uart_baud_base(void)62{63return uart_baud_base;64}6566void set_au1x00_uart_baud_base(unsigned long new_baud_base)67{68uart_baud_base = new_baud_base;69}7071/*72* We read the real processor speed from the PLL. This is important73* because it is more accurate than computing it from the 32 KHz74* counter, if it exists. If we don't have an accurate processor75* speed, all of the peripherals that derive their clocks based on76* this advertised speed will introduce error and sometimes not work77* properly. This function is further convoluted to still allow configurations78* to do that in case they have really, really old silicon with a79* write-only PLL register. -- Dan80*/81unsigned long au1xxx_calc_clock(void)82{83unsigned long cpu_speed;8485/*86* On early Au1000, sys_cpupll was write-only. Since these87* silicon versions of Au1000 are not sold by AMD, we don't bend88* over backwards trying to determine the frequency.89*/90if (au1xxx_cpu_has_pll_wo())91cpu_speed = 396000000;92else93cpu_speed = (au_readl(SYS_CPUPLL) & 0x0000003f) * AU1000_SRC_CLK;9495/* On Alchemy CPU:counter ratio is 1:1 */96mips_hpt_frequency = cpu_speed;97/* Equation: Baudrate = CPU / (SD * 2 * CLKDIV * 16) */98set_au1x00_uart_baud_base(cpu_speed / (2 * ((int)(au_readl(SYS_POWERCTRL)99& 0x03) + 2) * 16));100101set_au1x00_speed(cpu_speed);102103return cpu_speed;104}105106107