1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* drivers/rtc/rtc-tegra-odm.c
*
* Tegra ODM kit wrapper for RTC functionality implemented in Tegra
* ODM PMU adaptation
*
* Copyright (c) 2009, NVIDIA Corporation.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
#include <linux/ioport.h>
#include <linux/delay.h>
#include <linux/rtc.h>
#include <linux/bcd.h>
#include <linux/platform_device.h>
#include <linux/tegra_devices.h>
#include <nvodm_pmu.h>
#define SET_YEAR(Y) (Y-1900)
#define SET_MONTH(M) (M-1)
/* Create a custom rtc structrue and move this to that structure */
static NvOdmPmuDeviceHandle hPmu = NULL;
static int tegra_rtc_read_time(struct device *dev, struct rtc_time *tm)
{
NvU32 now;
if (hPmu == NULL)
return -1;
if (!NvOdmPmuReadRtc(hPmu, &now)) {
printk("NvOdmPmuReadRtc failed\n");
return -1;
}
if (!now) {
tm->tm_sec = 0;
tm->tm_min = 0;
tm->tm_hour = 0;
tm->tm_mday = 1;
tm->tm_mon = SET_MONTH(5);
tm->tm_year = SET_YEAR(2009);
tm->tm_wday = 0;
tm->tm_yday = 0;
tm->tm_isdst = 0;
} else {
rtc_time_to_tm(now, tm);
}
return 0;
}
static int tegra_rtc_set_time(struct device *dev, struct rtc_time *tm)
{
unsigned long now;
int ret;
if (hPmu == NULL)
return -1;
ret = rtc_tm_to_time(tm, &now);
if (ret != 0)
return -1;
if (!NvOdmPmuWriteRtc(hPmu, (NvU32)now)) {
printk("NvOdmPmuWriteRtc failed\n");
return -1;
}
return 0;
}
static struct rtc_class_ops tegra_rtc_ops = {
.read_time = tegra_rtc_read_time,
.set_time = tegra_rtc_set_time,
};
static int __init tegra_rtc_probe(struct platform_device *pdev)
{
struct rtc_device *rtc;
if (NvOdmPmuDeviceOpen(&hPmu) == NV_FALSE) {
pr_debug("%s: NvOdmPmuDeviceOpen failed\n", pdev->name);
return -ENXIO;
}
rtc = rtc_device_register(pdev->name, &pdev->dev,
&tegra_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc)) {
pr_debug("%s: can't register RTC device, err %ld\n",
pdev->name, PTR_ERR(rtc));
NvOdmPmuDeviceClose(hPmu);
return -1;
}
platform_set_drvdata(pdev, rtc);
return 0;
}
static int __exit tegra_rtc_remove(struct platform_device *pdev)
{
struct rtc_device *rtc = platform_get_drvdata(pdev);;
rtc_device_unregister(rtc);
return 0;
}
#ifdef CONFIG_PM
static int tegra_rtc_suspend(struct platform_device *pdev, pm_message_t state)
{
return 0;
}
static int tegra_rtc_resume(struct platform_device *pdev)
{
return 0;
}
#endif
static void tegra_rtc_shutdown(struct platform_device *pdev)
{
}
MODULE_ALIAS("platform:tegra_rtc");
static struct platform_driver tegra_rtc_driver = {
.remove = __exit_p(tegra_rtc_remove),
.shutdown = tegra_rtc_shutdown,
#ifdef CONFIG_PM
.suspend = tegra_rtc_suspend,
.resume = tegra_rtc_resume,
#endif
.driver = {
.name = "tegra_rtc",
.owner = THIS_MODULE,
},
};
static int __init rtc_init(void)
{
return platform_driver_probe(&tegra_rtc_driver, tegra_rtc_probe);
}
module_init(rtc_init);
static void __exit rtc_exit(void)
{
platform_driver_unregister(&tegra_rtc_driver);
}
module_exit(rtc_exit);
|