rtc: ep93xx: stop setting platform_data
[linux-2.6-block.git] / drivers / rtc / rtc-ep93xx.c
CommitLineData
fd507e2f
AZ
1/*
2 * A driver for the RTC embedded in the Cirrus Logic EP93XX processors
3 * Copyright (c) 2006 Tower Technologies
4 *
5 * Author: Alessandro Zummo <a.zummo@towertech.it>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/rtc.h>
14#include <linux/platform_device.h>
38f7b009 15#include <linux/io.h>
5a0e3ad6 16#include <linux/gfp.h>
38f7b009
HS
17
18#define EP93XX_RTC_DATA 0x000
19#define EP93XX_RTC_MATCH 0x004
20#define EP93XX_RTC_STATUS 0x008
21#define EP93XX_RTC_STATUS_INTR (1<<0)
22#define EP93XX_RTC_LOAD 0x00C
23#define EP93XX_RTC_CONTROL 0x010
24#define EP93XX_RTC_CONTROL_MIE (1<<0)
25#define EP93XX_RTC_SWCOMP 0x108
26#define EP93XX_RTC_SWCOMP_DEL_MASK 0x001f0000
27#define EP93XX_RTC_SWCOMP_DEL_SHIFT 16
28#define EP93XX_RTC_SWCOMP_INT_MASK 0x0000ffff
29#define EP93XX_RTC_SWCOMP_INT_SHIFT 0
30
38f7b009
HS
31struct ep93xx_rtc {
32 void __iomem *mmio_base;
bf6ed027 33 struct rtc_device *rtc;
38f7b009 34};
fd507e2f 35
38f7b009 36static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
fd507e2f
AZ
37 unsigned short *delete)
38{
28dc5f80 39 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
38f7b009
HS
40 unsigned long comp;
41
ff32ff17 42 comp = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
fd507e2f
AZ
43
44 if (preload)
38f7b009
HS
45 *preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK)
46 >> EP93XX_RTC_SWCOMP_INT_SHIFT;
fd507e2f
AZ
47
48 if (delete)
38f7b009
HS
49 *delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK)
50 >> EP93XX_RTC_SWCOMP_DEL_SHIFT;
fd507e2f
AZ
51
52 return 0;
53}
54
55static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
56{
28dc5f80 57 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
38f7b009
HS
58 unsigned long time;
59
725412d9 60 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
fd507e2f
AZ
61
62 rtc_time_to_tm(time, tm);
63 return 0;
64}
65
66static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
67{
28dc5f80 68 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
38f7b009 69
ff32ff17 70 writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
fd507e2f
AZ
71 return 0;
72}
73
fd507e2f
AZ
74static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
75{
76 unsigned short preload, delete;
77
38f7b009 78 ep93xx_rtc_get_swcomp(dev, &preload, &delete);
fd507e2f 79
fd507e2f
AZ
80 seq_printf(seq, "preload\t\t: %d\n", preload);
81 seq_printf(seq, "delete\t\t: %d\n", delete);
82
83 return 0;
84}
85
ff8371ac 86static const struct rtc_class_ops ep93xx_rtc_ops = {
fd507e2f 87 .read_time = ep93xx_rtc_read_time,
fd507e2f
AZ
88 .set_mmss = ep93xx_rtc_set_mmss,
89 .proc = ep93xx_rtc_proc,
90};
91
38f7b009 92static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev,
fd507e2f
AZ
93 struct device_attribute *attr, char *buf)
94{
95 unsigned short preload;
96
38f7b009 97 ep93xx_rtc_get_swcomp(dev, &preload, NULL);
fd507e2f
AZ
98
99 return sprintf(buf, "%d\n", preload);
100}
38f7b009 101static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL);
fd507e2f 102
38f7b009 103static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
fd507e2f
AZ
104 struct device_attribute *attr, char *buf)
105{
106 unsigned short delete;
107
38f7b009 108 ep93xx_rtc_get_swcomp(dev, NULL, &delete);
fd507e2f
AZ
109
110 return sprintf(buf, "%d\n", delete);
111}
38f7b009 112static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
fd507e2f 113
b4877d2b
HS
114static struct attribute *ep93xx_rtc_attrs[] = {
115 &dev_attr_comp_preload.attr,
116 &dev_attr_comp_delete.attr,
117 NULL
118};
119
120static const struct attribute_group ep93xx_rtc_sysfs_files = {
121 .attrs = ep93xx_rtc_attrs,
122};
fd507e2f 123
5a167f45 124static int ep93xx_rtc_probe(struct platform_device *pdev)
fd507e2f 125{
38f7b009
HS
126 struct ep93xx_rtc *ep93xx_rtc;
127 struct resource *res;
38f7b009
HS
128 int err;
129
b4877d2b
HS
130 ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL);
131 if (!ep93xx_rtc)
38f7b009
HS
132 return -ENOMEM;
133
134 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7c1d69ee
JL
135 ep93xx_rtc->mmio_base = devm_ioremap_resource(&pdev->dev, res);
136 if (IS_ERR(ep93xx_rtc->mmio_base))
137 return PTR_ERR(ep93xx_rtc->mmio_base);
fd507e2f 138
bf6ed027 139 platform_set_drvdata(pdev, ep93xx_rtc);
38f7b009 140
5d65cbfb
JH
141 ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev,
142 pdev->name, &ep93xx_rtc_ops, THIS_MODULE);
b809d192
AB
143 if (IS_ERR(ep93xx_rtc->rtc))
144 return PTR_ERR(ep93xx_rtc->rtc);
fd507e2f 145
b4877d2b 146 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
38f7b009 147 if (err)
b809d192 148 return err;
fd507e2f
AZ
149
150 return 0;
151}
152
5a167f45 153static int ep93xx_rtc_remove(struct platform_device *pdev)
fd507e2f 154{
b4877d2b 155 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
fd507e2f 156
fd507e2f
AZ
157 return 0;
158}
159
38f7b009 160static struct platform_driver ep93xx_rtc_driver = {
fd507e2f
AZ
161 .driver = {
162 .name = "ep93xx-rtc",
fd507e2f 163 },
84d56b38 164 .probe = ep93xx_rtc_probe,
5a167f45 165 .remove = ep93xx_rtc_remove,
fd507e2f
AZ
166};
167
84d56b38 168module_platform_driver(ep93xx_rtc_driver);
fd507e2f
AZ
169
170MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
171MODULE_DESCRIPTION("EP93XX RTC driver");
172MODULE_LICENSE("GPL");
84d56b38 173MODULE_ALIAS("platform:ep93xx-rtc");