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 * This file provides support for real time clocks on some boards
51 * <hr>$Revision: 49448 $<hr>
56 #ifndef __CVMX_RTC_H__
57 #define __CVMX_RTC_H__
59 #include "cvmx-sysinfo.h"
60 #include "cvmx-thunder.h"
61 #include "cvmx-cn3010-evb-hs5.h"
64 * Supported RTC options
68 CVMX_RTC_READ = 0x1, /**< Device supports read access */
69 CVMX_RTC_WRITE = 0x2, /**< Device supports write access */
70 CVMX_RTC_TIME_EPOCH = 0x10, /**< Time stored as seconds from epoch */
71 CVMX_RTC_TIME_CAL = 0x20, /**< Time stored as calendar */
75 * Return options supported by the RTC device
77 * @return Supported options, or 0 if RTC is not supported
79 static inline cvmx_rtc_options_t cvmx_rtc_supported(void)
81 static int supported = -1;
84 switch (cvmx_sysinfo_get()->board_type)
86 case CVMX_BOARD_TYPE_THUNDER:
87 supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_EPOCH;
90 case CVMX_BOARD_TYPE_EBH3000:
91 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
92 supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_CAL;
100 #ifdef CVMX_RTC_DEBUG
101 cvmx_dprintf("Board type: %s, RTC support: 0x%x\n",
102 cvmx_board_type_to_string(cvmx_sysinfo_get()->board_type),
107 return (cvmx_rtc_options_t) supported;
111 * Read time from RTC device.
113 * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
115 * @return Time in seconds or 0 if RTC is not supported
117 static inline uint32_t cvmx_rtc_read(void)
119 switch (cvmx_sysinfo_get()->board_type)
121 case CVMX_BOARD_TYPE_THUNDER:
122 return cvmx_rtc_ds1374_read();
125 case CVMX_BOARD_TYPE_EBH3000:
126 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
127 return cvmx_rtc_ds1337_read();
137 * Write time to the RTC device
139 * @param time Number of seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
141 * @return Zero on success or device-specific error on failure.
143 static inline uint32_t cvmx_rtc_write(uint32_t time)
145 switch (cvmx_sysinfo_get()->board_type)
147 case CVMX_BOARD_TYPE_THUNDER:
148 return cvmx_rtc_ds1374_write(time);
151 case CVMX_BOARD_TYPE_EBH3000:
152 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
153 return cvmx_rtc_ds1337_write(time);
162 #endif /* __CVMX_RTC_H__ */