1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Networks (support@cavium.com). All rights
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * * Neither the name of Cavium Networks nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
23 * This Software, including technical data, may be subject to U.S. export control
24 * laws, including the U.S. Export Administration Act and its associated
25 * regulations, and may be subject to export or import regulations in other
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT TO
31 * THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY REPRESENTATION OR
32 * DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT DEFECTS, AND CAVIUM
33 * SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES OF TITLE,
34 * MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR PURPOSE, LACK OF
35 * VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET POSSESSION OR
36 * CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT OF USE OR
37 * PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
49 * Interface to Core, IO and DDR Clock.
51 * <hr>$Revision: 45089 $<hr>
54 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
55 #include <linux/module.h>
56 #include <asm/octeon/octeon.h>
57 #include <asm/octeon/cvmx-clock.h>
58 #include <asm/octeon/cvmx-npei-defs.h>
59 #include <asm/octeon/cvmx-pexp-defs.h>
60 #include <asm/octeon/cvmx-dbg-defs.h>
62 #if !defined(__FreeBSD__) || !defined(_KERNEL)
63 #include "executive-config.h"
68 #ifndef CVMX_BUILD_FOR_UBOOT
69 static uint64_t rate_eclk = 0;
70 static uint64_t rate_sclk = 0;
71 static uint64_t rate_dclk = 0;
75 * Get clock rate based on the clock type.
77 * @param clock - Enumeration of the clock type.
78 * @return - return the clock rate.
80 uint64_t cvmx_clock_get_rate(cvmx_clock_t clock)
82 const uint64_t REF_CLOCK = 50000000;
84 #ifdef CVMX_BUILD_FOR_UBOOT
85 uint64_t rate_eclk = 0;
86 uint64_t rate_sclk = 0;
87 uint64_t rate_dclk = 0;
90 if (cvmx_unlikely(!rate_eclk))
92 if (octeon_has_feature(OCTEON_FEATURE_NPEI))
94 cvmx_npei_dbg_data_t npei_dbg_data;
95 npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
96 rate_eclk = REF_CLOCK * npei_dbg_data.s.c_mul;
97 rate_sclk = rate_eclk;
99 else if (octeon_has_feature(OCTEON_FEATURE_PCIE))
101 cvmx_mio_rst_boot_t mio_rst_boot;
102 mio_rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
103 rate_eclk = REF_CLOCK * mio_rst_boot.s.c_mul;
104 rate_sclk = REF_CLOCK * mio_rst_boot.s.pnr_mul;
108 cvmx_dbg_data_t dbg_data;
109 dbg_data.u64 = cvmx_read_csr(CVMX_DBG_DATA);
110 rate_eclk = REF_CLOCK * dbg_data.s.c_mul;
111 rate_sclk = rate_eclk;
117 case CVMX_CLOCK_SCLK:
122 case CVMX_CLOCK_RCLK:
123 case CVMX_CLOCK_CORE:
127 #if !defined(CVMX_BUILD_FOR_LINUX_HOST) && !defined(__OCTEON_NEWLIB__)
128 if (cvmx_unlikely(!rate_dclk))
129 rate_dclk = cvmx_sysinfo_get()->dram_data_rate_hz;
134 cvmx_dprintf("cvmx_clock_get_rate: Unknown clock type\n");
137 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
138 EXPORT_SYMBOL(cvmx_clock_get_rate);