]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/contrib/octeon-sdk/cvmx-rtc.h
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / contrib / octeon-sdk / cvmx-rtc.h
1 /***********************license start***************
2  * Copyright (c) 2003-2010  Cavium Networks (support@cavium.com). All rights
3  * reserved.
4  *
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  *   * Redistributions of source code must retain the above copyright
11  *     notice, this list of conditions and the following disclaimer.
12  *
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.
17
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
21  *     permission.
22
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
26  * countries.
27
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**************************************/
39
40
41
42
43
44
45
46 /**
47  * @file
48  *
49  * This file provides support for real time clocks on some boards
50  *
51  * <hr>$Revision: 49448 $<hr>
52  *
53  */
54
55
56 #ifndef __CVMX_RTC_H__
57 #define __CVMX_RTC_H__
58
59 #include "cvmx-sysinfo.h"
60 #include "cvmx-thunder.h"
61 #include "cvmx-cn3010-evb-hs5.h"
62
63 /**
64  * Supported RTC options
65  */
66 typedef enum
67 {
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 */
72 } cvmx_rtc_options_t;
73
74 /**
75  * Return options supported by the RTC device
76  *
77  * @return Supported options, or 0 if RTC is not supported
78  */
79 static inline cvmx_rtc_options_t cvmx_rtc_supported(void)
80 {
81     static int supported = -1;
82
83     if (supported < 0) {
84         switch (cvmx_sysinfo_get()->board_type)
85         {
86         case CVMX_BOARD_TYPE_THUNDER:
87             supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_EPOCH;
88             break;
89
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;
93             break;
94
95         default:
96             supported = 0;
97             break;
98         }
99
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),
103                supported);
104 #endif
105     }
106
107     return (cvmx_rtc_options_t) supported;
108 }
109
110 /**
111  * Read time from RTC device.
112  *
113  * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
114  *
115  * @return Time in seconds or 0 if RTC is not supported
116  */
117 static inline uint32_t cvmx_rtc_read(void)
118 {
119     switch (cvmx_sysinfo_get()->board_type)
120     {
121     case CVMX_BOARD_TYPE_THUNDER:
122         return cvmx_rtc_ds1374_read();
123         break;
124
125     case CVMX_BOARD_TYPE_EBH3000:
126     case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
127         return cvmx_rtc_ds1337_read();
128         break;
129
130     default:
131         return 0;
132         break;
133     }
134 }
135
136 /**
137  * Write time to the RTC device
138  *
139  * @param time    Number of seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
140  *
141  * @return Zero on success or device-specific error on failure.
142  */
143 static inline uint32_t cvmx_rtc_write(uint32_t time)
144 {
145     switch (cvmx_sysinfo_get()->board_type)
146     {
147     case CVMX_BOARD_TYPE_THUNDER:
148         return cvmx_rtc_ds1374_write(time);
149         break;
150
151     case CVMX_BOARD_TYPE_EBH3000:
152     case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
153         return cvmx_rtc_ds1337_write(time);
154         break;
155
156     default:
157         return 0;
158         break;
159     }
160 }
161
162 #endif    /* __CVMX_RTC_H__  */