xref: /linux/drivers/rtc/rtc-vt8500.c (revision 2f90b68309683f2c5765a1b04ca23d71e51f1494)
1f77fbdf9SAlexey Charkov /*
2f77fbdf9SAlexey Charkov  * drivers/rtc/rtc-vt8500.c
3f77fbdf9SAlexey Charkov  *
4f77fbdf9SAlexey Charkov  *  Copyright (C) 2010 Alexey Charkov <alchark@gmail.com>
5f77fbdf9SAlexey Charkov  *
6f77fbdf9SAlexey Charkov  * Based on rtc-pxa.c
7f77fbdf9SAlexey Charkov  *
8f77fbdf9SAlexey Charkov  * This software is licensed under the terms of the GNU General Public
9f77fbdf9SAlexey Charkov  * License version 2, as published by the Free Software Foundation, and
10f77fbdf9SAlexey Charkov  * may be copied, distributed, and modified under those terms.
11f77fbdf9SAlexey Charkov  *
12f77fbdf9SAlexey Charkov  * This program is distributed in the hope that it will be useful,
13f77fbdf9SAlexey Charkov  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14f77fbdf9SAlexey Charkov  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15f77fbdf9SAlexey Charkov  * GNU General Public License for more details.
16f77fbdf9SAlexey Charkov  */
17f77fbdf9SAlexey Charkov 
18f77fbdf9SAlexey Charkov #include <linux/module.h>
19f77fbdf9SAlexey Charkov #include <linux/rtc.h>
20f77fbdf9SAlexey Charkov #include <linux/init.h>
21f77fbdf9SAlexey Charkov #include <linux/interrupt.h>
22f77fbdf9SAlexey Charkov #include <linux/io.h>
23f77fbdf9SAlexey Charkov #include <linux/bcd.h>
24f77fbdf9SAlexey Charkov #include <linux/platform_device.h>
25f77fbdf9SAlexey Charkov #include <linux/slab.h>
267f4b48b3STony Prisk #include <linux/of.h>
27f77fbdf9SAlexey Charkov 
28f77fbdf9SAlexey Charkov /*
29f77fbdf9SAlexey Charkov  * Register definitions
30f77fbdf9SAlexey Charkov  */
31f77fbdf9SAlexey Charkov #define VT8500_RTC_TS		0x00	/* Time set */
32f77fbdf9SAlexey Charkov #define VT8500_RTC_DS		0x04	/* Date set */
33f77fbdf9SAlexey Charkov #define VT8500_RTC_AS		0x08	/* Alarm set */
34f77fbdf9SAlexey Charkov #define VT8500_RTC_CR		0x0c	/* Control */
35f77fbdf9SAlexey Charkov #define VT8500_RTC_TR		0x10	/* Time read */
36f77fbdf9SAlexey Charkov #define VT8500_RTC_DR		0x14	/* Date read */
37f77fbdf9SAlexey Charkov #define VT8500_RTC_WS		0x18	/* Write status */
38f77fbdf9SAlexey Charkov #define VT8500_RTC_CL		0x20	/* Calibration */
39f77fbdf9SAlexey Charkov #define VT8500_RTC_IS		0x24	/* Interrupt status */
40f77fbdf9SAlexey Charkov #define VT8500_RTC_ST		0x28	/* Status */
41f77fbdf9SAlexey Charkov 
42f77fbdf9SAlexey Charkov #define INVALID_TIME_BIT	(1 << 31)
43f77fbdf9SAlexey Charkov 
44f77fbdf9SAlexey Charkov #define DATE_CENTURY_S		19
45f77fbdf9SAlexey Charkov #define DATE_YEAR_S		11
46f77fbdf9SAlexey Charkov #define DATE_YEAR_MASK		(0xff << DATE_YEAR_S)
47f77fbdf9SAlexey Charkov #define DATE_MONTH_S		6
48f77fbdf9SAlexey Charkov #define DATE_MONTH_MASK		(0x1f << DATE_MONTH_S)
49f77fbdf9SAlexey Charkov #define DATE_DAY_MASK		0x3f
50f77fbdf9SAlexey Charkov 
51f77fbdf9SAlexey Charkov #define TIME_DOW_S		20
52f77fbdf9SAlexey Charkov #define TIME_DOW_MASK		(0x07 << TIME_DOW_S)
53f77fbdf9SAlexey Charkov #define TIME_HOUR_S		14
54f77fbdf9SAlexey Charkov #define TIME_HOUR_MASK		(0x3f << TIME_HOUR_S)
55f77fbdf9SAlexey Charkov #define TIME_MIN_S		7
56f77fbdf9SAlexey Charkov #define TIME_MIN_MASK		(0x7f << TIME_MIN_S)
57f77fbdf9SAlexey Charkov #define TIME_SEC_MASK		0x7f
58f77fbdf9SAlexey Charkov 
59f77fbdf9SAlexey Charkov #define ALARM_DAY_S		20
60f77fbdf9SAlexey Charkov #define ALARM_DAY_MASK		(0x3f << ALARM_DAY_S)
61f77fbdf9SAlexey Charkov 
62f77fbdf9SAlexey Charkov #define ALARM_DAY_BIT		(1 << 29)
63f77fbdf9SAlexey Charkov #define ALARM_HOUR_BIT		(1 << 28)
64f77fbdf9SAlexey Charkov #define ALARM_MIN_BIT		(1 << 27)
65f77fbdf9SAlexey Charkov #define ALARM_SEC_BIT		(1 << 26)
66f77fbdf9SAlexey Charkov 
67f77fbdf9SAlexey Charkov #define ALARM_ENABLE_MASK	(ALARM_DAY_BIT \
68f77fbdf9SAlexey Charkov 				| ALARM_HOUR_BIT \
69f77fbdf9SAlexey Charkov 				| ALARM_MIN_BIT \
70f77fbdf9SAlexey Charkov 				| ALARM_SEC_BIT)
71f77fbdf9SAlexey Charkov 
72f77fbdf9SAlexey Charkov #define VT8500_RTC_CR_ENABLE	(1 << 0)	/* Enable RTC */
73532db570STony Prisk #define VT8500_RTC_CR_12H	(1 << 1)	/* 12h time format */
74f77fbdf9SAlexey Charkov #define VT8500_RTC_CR_SM_ENABLE	(1 << 2)	/* Enable periodic irqs */
75f77fbdf9SAlexey Charkov #define VT8500_RTC_CR_SM_SEC	(1 << 3)	/* 0: 1Hz/60, 1: 1Hz */
76f77fbdf9SAlexey Charkov #define VT8500_RTC_CR_CALIB	(1 << 4)	/* Enable calibration */
77f77fbdf9SAlexey Charkov 
7807187ee1SWolfram Sang #define VT8500_RTC_IS_ALARM	(1 << 0)	/* Alarm interrupt status */
7907187ee1SWolfram Sang 
80f77fbdf9SAlexey Charkov struct vt8500_rtc {
81f77fbdf9SAlexey Charkov 	void __iomem		*regbase;
82f77fbdf9SAlexey Charkov 	struct resource		*res;
83f77fbdf9SAlexey Charkov 	int			irq_alarm;
84f77fbdf9SAlexey Charkov 	struct rtc_device	*rtc;
85f77fbdf9SAlexey Charkov 	spinlock_t		lock;		/* Protects this structure */
86f77fbdf9SAlexey Charkov };
87f77fbdf9SAlexey Charkov 
88f77fbdf9SAlexey Charkov static irqreturn_t vt8500_rtc_irq(int irq, void *dev_id)
89f77fbdf9SAlexey Charkov {
90f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = dev_id;
91f77fbdf9SAlexey Charkov 	u32 isr;
92f77fbdf9SAlexey Charkov 	unsigned long events = 0;
93f77fbdf9SAlexey Charkov 
94f77fbdf9SAlexey Charkov 	spin_lock(&vt8500_rtc->lock);
95f77fbdf9SAlexey Charkov 
96f77fbdf9SAlexey Charkov 	/* clear interrupt sources */
97f77fbdf9SAlexey Charkov 	isr = readl(vt8500_rtc->regbase + VT8500_RTC_IS);
98f77fbdf9SAlexey Charkov 	writel(isr, vt8500_rtc->regbase + VT8500_RTC_IS);
99f77fbdf9SAlexey Charkov 
100f77fbdf9SAlexey Charkov 	spin_unlock(&vt8500_rtc->lock);
101f77fbdf9SAlexey Charkov 
10207187ee1SWolfram Sang 	if (isr & VT8500_RTC_IS_ALARM)
103f77fbdf9SAlexey Charkov 		events |= RTC_AF | RTC_IRQF;
104f77fbdf9SAlexey Charkov 
105f77fbdf9SAlexey Charkov 	rtc_update_irq(vt8500_rtc->rtc, 1, events);
106f77fbdf9SAlexey Charkov 
107f77fbdf9SAlexey Charkov 	return IRQ_HANDLED;
108f77fbdf9SAlexey Charkov }
109f77fbdf9SAlexey Charkov 
110f77fbdf9SAlexey Charkov static int vt8500_rtc_read_time(struct device *dev, struct rtc_time *tm)
111f77fbdf9SAlexey Charkov {
112f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = dev_get_drvdata(dev);
113f77fbdf9SAlexey Charkov 	u32 date, time;
114f77fbdf9SAlexey Charkov 
115f77fbdf9SAlexey Charkov 	date = readl(vt8500_rtc->regbase + VT8500_RTC_DR);
116f77fbdf9SAlexey Charkov 	time = readl(vt8500_rtc->regbase + VT8500_RTC_TR);
117f77fbdf9SAlexey Charkov 
118f77fbdf9SAlexey Charkov 	tm->tm_sec = bcd2bin(time & TIME_SEC_MASK);
119f77fbdf9SAlexey Charkov 	tm->tm_min = bcd2bin((time & TIME_MIN_MASK) >> TIME_MIN_S);
120f77fbdf9SAlexey Charkov 	tm->tm_hour = bcd2bin((time & TIME_HOUR_MASK) >> TIME_HOUR_S);
121f77fbdf9SAlexey Charkov 	tm->tm_mday = bcd2bin(date & DATE_DAY_MASK);
122*2f90b683STony Prisk 	tm->tm_mon = bcd2bin((date & DATE_MONTH_MASK) >> DATE_MONTH_S) - 1;
123f77fbdf9SAlexey Charkov 	tm->tm_year = bcd2bin((date & DATE_YEAR_MASK) >> DATE_YEAR_S)
124f77fbdf9SAlexey Charkov 			+ ((date >> DATE_CENTURY_S) & 1 ? 200 : 100);
125f77fbdf9SAlexey Charkov 	tm->tm_wday = (time & TIME_DOW_MASK) >> TIME_DOW_S;
126f77fbdf9SAlexey Charkov 
127f77fbdf9SAlexey Charkov 	return 0;
128f77fbdf9SAlexey Charkov }
129f77fbdf9SAlexey Charkov 
130f77fbdf9SAlexey Charkov static int vt8500_rtc_set_time(struct device *dev, struct rtc_time *tm)
131f77fbdf9SAlexey Charkov {
132f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = dev_get_drvdata(dev);
133f77fbdf9SAlexey Charkov 
134f77fbdf9SAlexey Charkov 	if (tm->tm_year < 100) {
135f77fbdf9SAlexey Charkov 		dev_warn(dev, "Only years 2000-2199 are supported by the "
136f77fbdf9SAlexey Charkov 			      "hardware!\n");
137f77fbdf9SAlexey Charkov 		return -EINVAL;
138f77fbdf9SAlexey Charkov 	}
139f77fbdf9SAlexey Charkov 
140f77fbdf9SAlexey Charkov 	writel((bin2bcd(tm->tm_year - 100) << DATE_YEAR_S)
141*2f90b683STony Prisk 		| (bin2bcd(tm->tm_mon + 1) << DATE_MONTH_S)
142*2f90b683STony Prisk 		| (bin2bcd(tm->tm_mday))
143*2f90b683STony Prisk 		| ((tm->tm_year >= 200) << DATE_CENTURY_S),
144f77fbdf9SAlexey Charkov 		vt8500_rtc->regbase + VT8500_RTC_DS);
145f77fbdf9SAlexey Charkov 	writel((bin2bcd(tm->tm_wday) << TIME_DOW_S)
146f77fbdf9SAlexey Charkov 		| (bin2bcd(tm->tm_hour) << TIME_HOUR_S)
147f77fbdf9SAlexey Charkov 		| (bin2bcd(tm->tm_min) << TIME_MIN_S)
148f77fbdf9SAlexey Charkov 		| (bin2bcd(tm->tm_sec)),
149f77fbdf9SAlexey Charkov 		vt8500_rtc->regbase + VT8500_RTC_TS);
150f77fbdf9SAlexey Charkov 
151f77fbdf9SAlexey Charkov 	return 0;
152f77fbdf9SAlexey Charkov }
153f77fbdf9SAlexey Charkov 
154f77fbdf9SAlexey Charkov static int vt8500_rtc_read_alarm(struct device *dev, struct rtc_wkalrm *alrm)
155f77fbdf9SAlexey Charkov {
156f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = dev_get_drvdata(dev);
157f77fbdf9SAlexey Charkov 	u32 isr, alarm;
158f77fbdf9SAlexey Charkov 
159f77fbdf9SAlexey Charkov 	alarm = readl(vt8500_rtc->regbase + VT8500_RTC_AS);
160f77fbdf9SAlexey Charkov 	isr = readl(vt8500_rtc->regbase + VT8500_RTC_IS);
161f77fbdf9SAlexey Charkov 
162f77fbdf9SAlexey Charkov 	alrm->time.tm_mday = bcd2bin((alarm & ALARM_DAY_MASK) >> ALARM_DAY_S);
163f77fbdf9SAlexey Charkov 	alrm->time.tm_hour = bcd2bin((alarm & TIME_HOUR_MASK) >> TIME_HOUR_S);
164f77fbdf9SAlexey Charkov 	alrm->time.tm_min = bcd2bin((alarm & TIME_MIN_MASK) >> TIME_MIN_S);
165f77fbdf9SAlexey Charkov 	alrm->time.tm_sec = bcd2bin((alarm & TIME_SEC_MASK));
166f77fbdf9SAlexey Charkov 
167f77fbdf9SAlexey Charkov 	alrm->enabled = (alarm & ALARM_ENABLE_MASK) ? 1 : 0;
16807187ee1SWolfram Sang 	alrm->pending = (isr & VT8500_RTC_IS_ALARM) ? 1 : 0;
169f77fbdf9SAlexey Charkov 
170f77fbdf9SAlexey Charkov 	return rtc_valid_tm(&alrm->time);
171f77fbdf9SAlexey Charkov }
172f77fbdf9SAlexey Charkov 
173f77fbdf9SAlexey Charkov static int vt8500_rtc_set_alarm(struct device *dev, struct rtc_wkalrm *alrm)
174f77fbdf9SAlexey Charkov {
175f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = dev_get_drvdata(dev);
176f77fbdf9SAlexey Charkov 
177f77fbdf9SAlexey Charkov 	writel((alrm->enabled ? ALARM_ENABLE_MASK : 0)
178f77fbdf9SAlexey Charkov 		| (bin2bcd(alrm->time.tm_mday) << ALARM_DAY_S)
179f77fbdf9SAlexey Charkov 		| (bin2bcd(alrm->time.tm_hour) << TIME_HOUR_S)
180f77fbdf9SAlexey Charkov 		| (bin2bcd(alrm->time.tm_min) << TIME_MIN_S)
181f77fbdf9SAlexey Charkov 		| (bin2bcd(alrm->time.tm_sec)),
182f77fbdf9SAlexey Charkov 		vt8500_rtc->regbase + VT8500_RTC_AS);
183f77fbdf9SAlexey Charkov 
184f77fbdf9SAlexey Charkov 	return 0;
185f77fbdf9SAlexey Charkov }
186f77fbdf9SAlexey Charkov 
187f77fbdf9SAlexey Charkov static int vt8500_alarm_irq_enable(struct device *dev, unsigned int enabled)
188f77fbdf9SAlexey Charkov {
189f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = dev_get_drvdata(dev);
190f77fbdf9SAlexey Charkov 	unsigned long tmp = readl(vt8500_rtc->regbase + VT8500_RTC_AS);
191f77fbdf9SAlexey Charkov 
192f77fbdf9SAlexey Charkov 	if (enabled)
193f77fbdf9SAlexey Charkov 		tmp |= ALARM_ENABLE_MASK;
194f77fbdf9SAlexey Charkov 	else
195f77fbdf9SAlexey Charkov 		tmp &= ~ALARM_ENABLE_MASK;
196f77fbdf9SAlexey Charkov 
197f77fbdf9SAlexey Charkov 	writel(tmp, vt8500_rtc->regbase + VT8500_RTC_AS);
198f77fbdf9SAlexey Charkov 	return 0;
199f77fbdf9SAlexey Charkov }
200f77fbdf9SAlexey Charkov 
201f77fbdf9SAlexey Charkov static const struct rtc_class_ops vt8500_rtc_ops = {
202f77fbdf9SAlexey Charkov 	.read_time = vt8500_rtc_read_time,
203f77fbdf9SAlexey Charkov 	.set_time = vt8500_rtc_set_time,
204f77fbdf9SAlexey Charkov 	.read_alarm = vt8500_rtc_read_alarm,
205f77fbdf9SAlexey Charkov 	.set_alarm = vt8500_rtc_set_alarm,
206f77fbdf9SAlexey Charkov 	.alarm_irq_enable = vt8500_alarm_irq_enable,
207f77fbdf9SAlexey Charkov };
208f77fbdf9SAlexey Charkov 
2095a167f45SGreg Kroah-Hartman static int vt8500_rtc_probe(struct platform_device *pdev)
210f77fbdf9SAlexey Charkov {
211f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc;
212f77fbdf9SAlexey Charkov 	int ret;
213f77fbdf9SAlexey Charkov 
2140d7ecb83SDevendra Naga 	vt8500_rtc = devm_kzalloc(&pdev->dev,
2150d7ecb83SDevendra Naga 			   sizeof(struct vt8500_rtc), GFP_KERNEL);
216f77fbdf9SAlexey Charkov 	if (!vt8500_rtc)
217f77fbdf9SAlexey Charkov 		return -ENOMEM;
218f77fbdf9SAlexey Charkov 
219f77fbdf9SAlexey Charkov 	spin_lock_init(&vt8500_rtc->lock);
220f77fbdf9SAlexey Charkov 	platform_set_drvdata(pdev, vt8500_rtc);
221f77fbdf9SAlexey Charkov 
222f77fbdf9SAlexey Charkov 	vt8500_rtc->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
223f77fbdf9SAlexey Charkov 	if (!vt8500_rtc->res) {
224f77fbdf9SAlexey Charkov 		dev_err(&pdev->dev, "No I/O memory resource defined\n");
2250d7ecb83SDevendra Naga 		return -ENXIO;
226f77fbdf9SAlexey Charkov 	}
227f77fbdf9SAlexey Charkov 
228f77fbdf9SAlexey Charkov 	vt8500_rtc->irq_alarm = platform_get_irq(pdev, 0);
229f77fbdf9SAlexey Charkov 	if (vt8500_rtc->irq_alarm < 0) {
230f77fbdf9SAlexey Charkov 		dev_err(&pdev->dev, "No alarm IRQ resource defined\n");
2310d7ecb83SDevendra Naga 		return -ENXIO;
232f77fbdf9SAlexey Charkov 	}
233f77fbdf9SAlexey Charkov 
234f77fbdf9SAlexey Charkov 	vt8500_rtc->res = request_mem_region(vt8500_rtc->res->start,
235f77fbdf9SAlexey Charkov 					     resource_size(vt8500_rtc->res),
236f77fbdf9SAlexey Charkov 					     "vt8500-rtc");
237f77fbdf9SAlexey Charkov 	if (vt8500_rtc->res == NULL) {
238f77fbdf9SAlexey Charkov 		dev_err(&pdev->dev, "failed to request I/O memory\n");
2390d7ecb83SDevendra Naga 		return -EBUSY;
240f77fbdf9SAlexey Charkov 	}
241f77fbdf9SAlexey Charkov 
242f77fbdf9SAlexey Charkov 	vt8500_rtc->regbase = ioremap(vt8500_rtc->res->start,
243f77fbdf9SAlexey Charkov 				      resource_size(vt8500_rtc->res));
244f77fbdf9SAlexey Charkov 	if (!vt8500_rtc->regbase) {
245f77fbdf9SAlexey Charkov 		dev_err(&pdev->dev, "Unable to map RTC I/O memory\n");
246f77fbdf9SAlexey Charkov 		ret = -EBUSY;
247f77fbdf9SAlexey Charkov 		goto err_release;
248f77fbdf9SAlexey Charkov 	}
249f77fbdf9SAlexey Charkov 
25003ad2d50SAlexey Charkov 	/* Enable RTC and set it to 24-hour mode */
251532db570STony Prisk 	writel(VT8500_RTC_CR_ENABLE,
252f77fbdf9SAlexey Charkov 	       vt8500_rtc->regbase + VT8500_RTC_CR);
253f77fbdf9SAlexey Charkov 
254f77fbdf9SAlexey Charkov 	vt8500_rtc->rtc = rtc_device_register("vt8500-rtc", &pdev->dev,
255f77fbdf9SAlexey Charkov 					      &vt8500_rtc_ops, THIS_MODULE);
256f77fbdf9SAlexey Charkov 	if (IS_ERR(vt8500_rtc->rtc)) {
257f77fbdf9SAlexey Charkov 		ret = PTR_ERR(vt8500_rtc->rtc);
258f77fbdf9SAlexey Charkov 		dev_err(&pdev->dev,
259f77fbdf9SAlexey Charkov 			"Failed to register RTC device -> %d\n", ret);
260f77fbdf9SAlexey Charkov 		goto err_unmap;
261f77fbdf9SAlexey Charkov 	}
262f77fbdf9SAlexey Charkov 
263f77fbdf9SAlexey Charkov 	ret = request_irq(vt8500_rtc->irq_alarm, vt8500_rtc_irq, 0,
264f77fbdf9SAlexey Charkov 			  "rtc alarm", vt8500_rtc);
265f77fbdf9SAlexey Charkov 	if (ret < 0) {
266f77fbdf9SAlexey Charkov 		dev_err(&pdev->dev, "can't get irq %i, err %d\n",
267f77fbdf9SAlexey Charkov 			vt8500_rtc->irq_alarm, ret);
26803ad2d50SAlexey Charkov 		goto err_unreg;
269f77fbdf9SAlexey Charkov 	}
270f77fbdf9SAlexey Charkov 
271f77fbdf9SAlexey Charkov 	return 0;
272f77fbdf9SAlexey Charkov 
273f77fbdf9SAlexey Charkov err_unreg:
274f77fbdf9SAlexey Charkov 	rtc_device_unregister(vt8500_rtc->rtc);
275f77fbdf9SAlexey Charkov err_unmap:
276f77fbdf9SAlexey Charkov 	iounmap(vt8500_rtc->regbase);
277f77fbdf9SAlexey Charkov err_release:
278f77fbdf9SAlexey Charkov 	release_mem_region(vt8500_rtc->res->start,
279f77fbdf9SAlexey Charkov 			   resource_size(vt8500_rtc->res));
280f77fbdf9SAlexey Charkov 	return ret;
281f77fbdf9SAlexey Charkov }
282f77fbdf9SAlexey Charkov 
2835a167f45SGreg Kroah-Hartman static int vt8500_rtc_remove(struct platform_device *pdev)
284f77fbdf9SAlexey Charkov {
285f77fbdf9SAlexey Charkov 	struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev);
286f77fbdf9SAlexey Charkov 
287f77fbdf9SAlexey Charkov 	free_irq(vt8500_rtc->irq_alarm, vt8500_rtc);
288f77fbdf9SAlexey Charkov 
289f77fbdf9SAlexey Charkov 	rtc_device_unregister(vt8500_rtc->rtc);
290f77fbdf9SAlexey Charkov 
291f77fbdf9SAlexey Charkov 	/* Disable alarm matching */
292f77fbdf9SAlexey Charkov 	writel(0, vt8500_rtc->regbase + VT8500_RTC_IS);
293f77fbdf9SAlexey Charkov 	iounmap(vt8500_rtc->regbase);
294f77fbdf9SAlexey Charkov 	release_mem_region(vt8500_rtc->res->start,
295f77fbdf9SAlexey Charkov 			   resource_size(vt8500_rtc->res));
296f77fbdf9SAlexey Charkov 
297f77fbdf9SAlexey Charkov 	platform_set_drvdata(pdev, NULL);
298f77fbdf9SAlexey Charkov 
299f77fbdf9SAlexey Charkov 	return 0;
300f77fbdf9SAlexey Charkov }
301f77fbdf9SAlexey Charkov 
3027f4b48b3STony Prisk static const struct of_device_id wmt_dt_ids[] = {
3037f4b48b3STony Prisk 	{ .compatible = "via,vt8500-rtc", },
3047f4b48b3STony Prisk 	{}
3057f4b48b3STony Prisk };
3067f4b48b3STony Prisk 
307f77fbdf9SAlexey Charkov static struct platform_driver vt8500_rtc_driver = {
308f77fbdf9SAlexey Charkov 	.probe		= vt8500_rtc_probe,
3095a167f45SGreg Kroah-Hartman 	.remove		= vt8500_rtc_remove,
310f77fbdf9SAlexey Charkov 	.driver		= {
311f77fbdf9SAlexey Charkov 		.name	= "vt8500-rtc",
312f77fbdf9SAlexey Charkov 		.owner	= THIS_MODULE,
3137f4b48b3STony Prisk 		.of_match_table = of_match_ptr(wmt_dt_ids),
314f77fbdf9SAlexey Charkov 	},
315f77fbdf9SAlexey Charkov };
316f77fbdf9SAlexey Charkov 
3170c4eae66SAxel Lin module_platform_driver(vt8500_rtc_driver);
318f77fbdf9SAlexey Charkov 
319f77fbdf9SAlexey Charkov MODULE_AUTHOR("Alexey Charkov <alchark@gmail.com>");
320f77fbdf9SAlexey Charkov MODULE_DESCRIPTION("VIA VT8500 SoC Realtime Clock Driver (RTC)");
3217f4b48b3STony Prisk MODULE_LICENSE("GPL v2");
322f77fbdf9SAlexey Charkov MODULE_ALIAS("platform:vt8500-rtc");
323