cvmx-clock.c revision 215990
1215976Sjmallett/***********************license start*************** 2215976Sjmallett * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights 3215976Sjmallett * reserved. 4215976Sjmallett * 5215976Sjmallett * 6215976Sjmallett * Redistribution and use in source and binary forms, with or without 7215976Sjmallett * modification, are permitted provided that the following conditions are 8215976Sjmallett * met: 9215976Sjmallett * 10215976Sjmallett * * Redistributions of source code must retain the above copyright 11215976Sjmallett * notice, this list of conditions and the following disclaimer. 12215976Sjmallett * 13215976Sjmallett * * Redistributions in binary form must reproduce the above 14215976Sjmallett * copyright notice, this list of conditions and the following 15215976Sjmallett * disclaimer in the documentation and/or other materials provided 16215976Sjmallett * with the distribution. 17215976Sjmallett 18215976Sjmallett * * Neither the name of Cavium Networks nor the names of 19215976Sjmallett * its contributors may be used to endorse or promote products 20215976Sjmallett * derived from this software without specific prior written 21215976Sjmallett * permission. 22215976Sjmallett 23215976Sjmallett * This Software, including technical data, may be subject to U.S. export control 24215976Sjmallett * laws, including the U.S. Export Administration Act and its associated 25215976Sjmallett * regulations, and may be subject to export or import regulations in other 26215976Sjmallett * countries. 27215976Sjmallett 28215976Sjmallett * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" 29215976Sjmallett * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR 30215976Sjmallett * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO 31215976Sjmallett * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR 32215976Sjmallett * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM 33215976Sjmallett * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE, 34215976Sjmallett * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF 35215976Sjmallett * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR 36215976Sjmallett * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR 37215976Sjmallett * PERFORMANCE OF THE SOFTWARE LIES WITH YOU. 38215976Sjmallett ***********************license end**************************************/ 39215976Sjmallett 40215976Sjmallett 41215976Sjmallett 42215976Sjmallett 43215976Sjmallett 44215976Sjmallett 45215976Sjmallett 46215976Sjmallett/** 47215976Sjmallett * @file 48215976Sjmallett * 49215976Sjmallett * Interface to Core, IO and DDR Clock. 50215976Sjmallett * 51215976Sjmallett * <hr>$Revision: 45089 $<hr> 52215976Sjmallett*/ 53215976Sjmallett 54215976Sjmallett#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 55215976Sjmallett#include <linux/module.h> 56215976Sjmallett#include <asm/octeon/octeon.h> 57215976Sjmallett#include <asm/octeon/cvmx-clock.h> 58215976Sjmallett#include <asm/octeon/cvmx-npei-defs.h> 59215976Sjmallett#include <asm/octeon/cvmx-pexp-defs.h> 60215976Sjmallett#include <asm/octeon/cvmx-dbg-defs.h> 61215976Sjmallett#else 62215990Sjmallett#if !defined(__FreeBSD__) || !defined(_KERNEL) 63215976Sjmallett#include "executive-config.h" 64215990Sjmallett#endif 65215976Sjmallett#include "cvmx.h" 66215976Sjmallett#endif 67215976Sjmallett 68215976Sjmallett#ifndef CVMX_BUILD_FOR_UBOOT 69215976Sjmallettstatic uint64_t rate_eclk = 0; 70215976Sjmallettstatic uint64_t rate_sclk = 0; 71215976Sjmallettstatic uint64_t rate_dclk = 0; 72215976Sjmallett#endif 73215976Sjmallett 74215976Sjmallett/** 75215976Sjmallett * Get clock rate based on the clock type. 76215976Sjmallett * 77215976Sjmallett * @param clock - Enumeration of the clock type. 78215976Sjmallett * @return - return the clock rate. 79215976Sjmallett */ 80215976Sjmallettuint64_t cvmx_clock_get_rate(cvmx_clock_t clock) 81215976Sjmallett{ 82215976Sjmallett const uint64_t REF_CLOCK = 50000000; 83215976Sjmallett 84215976Sjmallett#ifdef CVMX_BUILD_FOR_UBOOT 85215976Sjmallett uint64_t rate_eclk = 0; 86215976Sjmallett uint64_t rate_sclk = 0; 87215976Sjmallett uint64_t rate_dclk = 0; 88215976Sjmallett#endif 89215976Sjmallett 90215976Sjmallett if (cvmx_unlikely(!rate_eclk)) 91215976Sjmallett { 92215976Sjmallett if (octeon_has_feature(OCTEON_FEATURE_NPEI)) 93215976Sjmallett { 94215976Sjmallett cvmx_npei_dbg_data_t npei_dbg_data; 95215976Sjmallett npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA); 96215976Sjmallett rate_eclk = REF_CLOCK * npei_dbg_data.s.c_mul; 97215976Sjmallett rate_sclk = rate_eclk; 98215976Sjmallett } 99215976Sjmallett else if (octeon_has_feature(OCTEON_FEATURE_PCIE)) 100215976Sjmallett { 101215976Sjmallett cvmx_mio_rst_boot_t mio_rst_boot; 102215976Sjmallett mio_rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT); 103215976Sjmallett rate_eclk = REF_CLOCK * mio_rst_boot.s.c_mul; 104215976Sjmallett rate_sclk = REF_CLOCK * mio_rst_boot.s.pnr_mul; 105215976Sjmallett } 106215976Sjmallett else 107215976Sjmallett { 108215976Sjmallett cvmx_dbg_data_t dbg_data; 109215976Sjmallett dbg_data.u64 = cvmx_read_csr(CVMX_DBG_DATA); 110215976Sjmallett rate_eclk = REF_CLOCK * dbg_data.s.c_mul; 111215976Sjmallett rate_sclk = rate_eclk; 112215976Sjmallett } 113215976Sjmallett } 114215976Sjmallett 115215976Sjmallett switch (clock) 116215976Sjmallett { 117215976Sjmallett case CVMX_CLOCK_SCLK: 118215976Sjmallett case CVMX_CLOCK_TIM: 119215976Sjmallett case CVMX_CLOCK_IPD: 120215976Sjmallett return rate_sclk; 121215976Sjmallett 122215976Sjmallett case CVMX_CLOCK_RCLK: 123215976Sjmallett case CVMX_CLOCK_CORE: 124215976Sjmallett return rate_eclk; 125215976Sjmallett 126215976Sjmallett case CVMX_CLOCK_DDR: 127215976Sjmallett#if !defined(CVMX_BUILD_FOR_LINUX_HOST) && !defined(__OCTEON_NEWLIB__) 128215976Sjmallett if (cvmx_unlikely(!rate_dclk)) 129215976Sjmallett rate_dclk = cvmx_sysinfo_get()->dram_data_rate_hz; 130215976Sjmallett#endif 131215976Sjmallett return rate_dclk; 132215976Sjmallett } 133215976Sjmallett 134215976Sjmallett cvmx_dprintf("cvmx_clock_get_rate: Unknown clock type\n"); 135215976Sjmallett return 0; 136215976Sjmallett} 137215976Sjmallett#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 138215976SjmallettEXPORT_SYMBOL(cvmx_clock_get_rate); 139215976Sjmallett#endif 140