1 /***********************license start***************
2 * Copyright (c) 2003-2010 Cavium Inc. (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 Inc. 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 INC. 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 /* Note: The order of these checks is important.
93 ** octeon_has_feature(OCTEON_FEATURE_PCIE) is true for both 6XXX
94 ** and 52XX/56XX, so OCTEON_FEATURE_NPEI _must_ be checked first */
95 if (octeon_has_feature(OCTEON_FEATURE_NPEI))
97 cvmx_npei_dbg_data_t npei_dbg_data;
98 npei_dbg_data.u64 = cvmx_read_csr(CVMX_PEXP_NPEI_DBG_DATA);
99 rate_eclk = REF_CLOCK * npei_dbg_data.s.c_mul;
100 rate_sclk = rate_eclk;
102 else if (octeon_has_feature(OCTEON_FEATURE_PCIE))
104 cvmx_mio_rst_boot_t mio_rst_boot;
105 mio_rst_boot.u64 = cvmx_read_csr(CVMX_MIO_RST_BOOT);
106 rate_eclk = REF_CLOCK * mio_rst_boot.s.c_mul;
107 rate_sclk = REF_CLOCK * mio_rst_boot.s.pnr_mul;
111 cvmx_dbg_data_t dbg_data;
112 dbg_data.u64 = cvmx_read_csr(CVMX_DBG_DATA);
113 rate_eclk = REF_CLOCK * dbg_data.s.c_mul;
114 rate_sclk = rate_eclk;
120 case CVMX_CLOCK_SCLK:
125 case CVMX_CLOCK_RCLK:
126 case CVMX_CLOCK_CORE:
130 #if !defined(CVMX_BUILD_FOR_LINUX_HOST) && !defined(CVMX_BUILD_FOR_TOOLCHAIN)
131 if (cvmx_unlikely(!rate_dclk))
132 rate_dclk = cvmx_sysinfo_get()->dram_data_rate_hz;
137 cvmx_dprintf("cvmx_clock_get_rate: Unknown clock type\n");
140 #ifdef CVMX_BUILD_FOR_LINUX_KERNEL
141 EXPORT_SYMBOL(cvmx_clock_get_rate);