cvmx-clock.c revision 232812
1215976Sjmallett/***********************license start*************** 2232812Sjmallett * Copyright (c) 2003-2010 Cavium Inc. (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 18232812Sjmallett * * Neither the name of Cavium Inc. 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" 29232812Sjmallett * AND WITH ALL FAULTS AND CAVIUM INC. 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 { 92232812Sjmallett /* Note: The order of these checks is important. 93232812Sjmallett ** octeon_has_feature(OCTEON_FEATURE_PCIE) is true for both 6XXX 94232812Sjmallett ** and 52XX/56XX, so OCTEON_FEATURE_NPEI _must_ be checked first */ 95215976Sjmallett if (octeon_has_feature(OCTEON_FEATURE_NPEI)) 96215976Sjmallett { 97215976Sjmallett cvmx_npei_dbg_data_t npei_dbg_data; 98215976Sjmallett npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA); 99215976Sjmallett rate_eclk = REF_CLOCK * npei_dbg_data.s.c_mul; 100215976Sjmallett rate_sclk = rate_eclk; 101215976Sjmallett } 102215976Sjmallett else if (octeon_has_feature(OCTEON_FEATURE_PCIE)) 103215976Sjmallett { 104215976Sjmallett cvmx_mio_rst_boot_t mio_rst_boot; 105215976Sjmallett mio_rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT); 106215976Sjmallett rate_eclk = REF_CLOCK * mio_rst_boot.s.c_mul; 107215976Sjmallett rate_sclk = REF_CLOCK * mio_rst_boot.s.pnr_mul; 108215976Sjmallett } 109215976Sjmallett else 110215976Sjmallett { 111215976Sjmallett cvmx_dbg_data_t dbg_data; 112215976Sjmallett dbg_data.u64 = cvmx_read_csr(CVMX_DBG_DATA); 113215976Sjmallett rate_eclk = REF_CLOCK * dbg_data.s.c_mul; 114215976Sjmallett rate_sclk = rate_eclk; 115215976Sjmallett } 116215976Sjmallett } 117215976Sjmallett 118215976Sjmallett switch (clock) 119215976Sjmallett { 120215976Sjmallett case CVMX_CLOCK_SCLK: 121215976Sjmallett case CVMX_CLOCK_TIM: 122215976Sjmallett case CVMX_CLOCK_IPD: 123215976Sjmallett return rate_sclk; 124215976Sjmallett 125215976Sjmallett case CVMX_CLOCK_RCLK: 126215976Sjmallett case CVMX_CLOCK_CORE: 127215976Sjmallett return rate_eclk; 128215976Sjmallett 129215976Sjmallett case CVMX_CLOCK_DDR: 130232812Sjmallett#if !defined(CVMX_BUILD_FOR_LINUX_HOST) && !defined(CVMX_BUILD_FOR_TOOLCHAIN) 131215976Sjmallett if (cvmx_unlikely(!rate_dclk)) 132215976Sjmallett rate_dclk = cvmx_sysinfo_get()->dram_data_rate_hz; 133215976Sjmallett#endif 134215976Sjmallett return rate_dclk; 135215976Sjmallett } 136215976Sjmallett 137215976Sjmallett cvmx_dprintf("cvmx_clock_get_rate: Unknown clock type\n"); 138215976Sjmallett return 0; 139215976Sjmallett} 140215976Sjmallett#ifdef CVMX_BUILD_FOR_LINUX_KERNEL 141215976SjmallettEXPORT_SYMBOL(cvmx_clock_get_rate); 142215976Sjmallett#endif 143