1/***********************license start***************
2 * Copyright (c) 2003-2010  Cavium Inc. (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 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
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 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**************************************/
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: 70030 $<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 */
66typedef 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 */
79static 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	case CVMX_BOARD_TYPE_EBH5200:
93	    supported = CVMX_RTC_READ | CVMX_RTC_WRITE | CVMX_RTC_TIME_CAL;
94	    break;
95
96	default:
97	    supported = 0;
98	    break;
99	}
100
101#ifdef CVMX_RTC_DEBUG
102	cvmx_dprintf("Board type: %s, RTC support: 0x%x\n",
103	       cvmx_board_type_to_string(cvmx_sysinfo_get()->board_type),
104	       supported);
105#endif
106    }
107
108    return (cvmx_rtc_options_t) supported;
109}
110
111/**
112 * Read time from RTC device.
113 *
114 * Time is expressed in seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
115 *
116 * @return Time in seconds or 0 if RTC is not supported
117 */
118static inline uint32_t cvmx_rtc_read(void)
119{
120    switch (cvmx_sysinfo_get()->board_type)
121    {
122    case CVMX_BOARD_TYPE_THUNDER:
123        return cvmx_rtc_ds1374_read();
124        break;
125
126    default:
127	return cvmx_rtc_ds1337_read();
128	break;
129    }
130}
131
132/**
133 * Write time to the RTC device
134 *
135 * @param time    Number of seconds from epoch (Jan 1 1970 at 00:00:00 UTC)
136 *
137 * @return Zero on success or device-specific error on failure.
138 */
139static inline uint32_t cvmx_rtc_write(uint32_t time)
140{
141    switch (cvmx_sysinfo_get()->board_type)
142    {
143    case CVMX_BOARD_TYPE_THUNDER:
144        return cvmx_rtc_ds1374_write(time);
145        break;
146
147    default:
148	return cvmx_rtc_ds1337_write(time);
149	break;
150    }
151}
152
153#endif    /* __CVMX_RTC_H__  */
154