1 /***********************license start***************
2 * Copyright (c) 2003-2008 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 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
24 * AND WITH ALL FAULTS AND CAVIUM NETWORKS MAKES NO PROMISES, REPRESENTATIONS
25 * OR WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH
26 * RESPECT TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
27 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
28 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
29 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
30 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, QUIET
31 * POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK ARISING OUT
32 * OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
35 * For any questions regarding licensing please contact marketing@caviumnetworks.com
37 ***********************license end**************************************/
47 * This file provides support for real time clocks on some boards
49 * <hr>$Revision: 41586 $<hr>
54 #ifndef __CVMX_RTC_H__
55 #define __CVMX_RTC_H__
57 #include "cvmx-sysinfo.h"
58 #include "cvmx-thunder.h"
59 #include "cvmx-cn3010-evb-hs5.h"
62 * Supported RTC options
66 CVMX_RTC_READ = 0x1, /**< Device supports read access */
67 CVMX_RTC_WRITE = 0x2, /**< Device supports write access */
68 CVMX_RTC_TIME_EPOCH = 0x10, /**< Time stored as seconds from epoch */
69 CVMX_RTC_TIME_CAL = 0x20, /**< Time stored as calendar */
73 * Return options supported by the RTC device
75 * @return Supported options, or 0 if RTC is not supported
77 static inline cvmx_rtc_options_t cvmx_rtc_supported(void)
79 static int supported = -1;
82 switch (cvmx_sysinfo_get()->board_type)
84 case CVMX_BOARD_TYPE_THUNDER:
85 supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_EPOCH;
88 case CVMX_BOARD_TYPE_EBH3000:
89 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
90 supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_CAL;
99 cvmx_dprintf("Board type: %s, RTC support: 0x%x\n",
100 cvmx_board_type_to_string(cvmx_sysinfo_get()->board_type),
105 return (cvmx_rtc_options_t) supported;
109 * Read time from RTC device.
111 * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
113 * @return Time in seconds or 0 if RTC is not supported
115 static inline uint32_t cvmx_rtc_read(void)
117 switch (cvmx_sysinfo_get()->board_type)
119 case CVMX_BOARD_TYPE_THUNDER:
120 return cvmx_rtc_ds1374_read();
123 case CVMX_BOARD_TYPE_EBH3000:
124 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
125 return cvmx_rtc_ds1337_read();
135 * Write time to the RTC device
137 * @param time Number of seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
139 * @return Zero on success or device-specific error on failure.
141 static inline uint32_t cvmx_rtc_write(uint32_t time)
143 switch (cvmx_sysinfo_get()->board_type)
145 case CVMX_BOARD_TYPE_THUNDER:
146 return cvmx_rtc_ds1374_write(time);
149 case CVMX_BOARD_TYPE_EBH3000:
150 case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
151 return cvmx_rtc_ds1337_write(time);
160 #endif /* __CVMX_RTC_H__ */