]> CyberLeo.Net >> Repos - FreeBSD/releng/8.2.git/blob - sys/contrib/octeon-sdk/cvmx-rtc.h
Copy stable/8 to releng/8.2 in preparation for FreeBSD-8.2 release.
[FreeBSD/releng/8.2.git] / sys / contrib / octeon-sdk / cvmx-rtc.h
1 /***********************license start***************
2  *  Copyright (c) 2003-2008 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  *  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.
33  *
34  *
35  *  For any questions regarding licensing please contact marketing@caviumnetworks.com
36  *
37  ***********************license end**************************************/
38
39
40
41
42
43
44 /**
45  * @file
46  *
47  * This file provides support for real time clocks on some boards
48  *
49  * <hr>$Revision: 41586 $<hr>
50  *
51  */
52
53
54 #ifndef __CVMX_RTC_H__
55 #define __CVMX_RTC_H__
56
57 #include "cvmx-sysinfo.h"
58 #include "cvmx-thunder.h"
59 #include "cvmx-cn3010-evb-hs5.h"
60
61 /**
62  * Supported RTC options
63  */
64 typedef enum
65 {
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 */
70 } cvmx_rtc_options_t;
71
72 /**
73  * Return options supported by the RTC device
74  *
75  * @return Supported options, or 0 if RTC is not supported
76  */
77 static inline cvmx_rtc_options_t cvmx_rtc_supported(void)
78 {
79     static int supported = -1;
80
81     if (supported < 0) {
82         switch (cvmx_sysinfo_get()->board_type)
83         {
84         case CVMX_BOARD_TYPE_THUNDER:
85             supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_EPOCH;
86             break;
87
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;
91             break;
92
93         default:
94             supported = 0;
95             break;
96         }
97
98 #ifdef CVMX_RTC_DEBUG
99         cvmx_dprintf("Board type: %s, RTC support: 0x%x\n",
100                cvmx_board_type_to_string(cvmx_sysinfo_get()->board_type),
101                supported);
102 #endif
103     }
104
105     return (cvmx_rtc_options_t) supported;
106 }
107
108 /**
109  * Read time from RTC device.
110  *
111  * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
112  *
113  * @return Time in seconds or 0 if RTC is not supported
114  */
115 static inline uint32_t cvmx_rtc_read(void)
116 {
117     switch (cvmx_sysinfo_get()->board_type)
118     {
119     case CVMX_BOARD_TYPE_THUNDER:
120         return cvmx_rtc_ds1374_read();
121         break;
122
123     case CVMX_BOARD_TYPE_EBH3000:
124     case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
125         return cvmx_rtc_ds1337_read();
126         break;
127
128     default:
129         return 0;
130         break;
131     }
132 }
133
134 /**
135  * Write time to the RTC device
136  *
137  * @param time    Number of seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
138  *
139  * @return Zero on success or device-specific error on failure.
140  */
141 static inline uint32_t cvmx_rtc_write(uint32_t time)
142 {
143     switch (cvmx_sysinfo_get()->board_type)
144     {
145     case CVMX_BOARD_TYPE_THUNDER:
146         return cvmx_rtc_ds1374_write(time);
147         break;
148
149     case CVMX_BOARD_TYPE_EBH3000:
150     case CVMX_BOARD_TYPE_CN3010_EVB_HS5:
151         return cvmx_rtc_ds1337_write(time);
152         break;
153
154     default:
155         return 0;
156         break;
157     }
158 }
159
160 #endif    /* __CVMX_RTC_H__  */