ACPI / debugger: Fix regression introduced by IS_ERR_VALUE() removal
[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
31/*
32 * struct device dev.platform_data is used to store our private data
33 * because struct rtc_device does not have a variable to hold it.
34 */
35struct ep93xx_rtc {
36 void __iomem *mmio_base;
bf6ed027 37 struct rtc_device *rtc;
38f7b009 38};
fd507e2f 39
38f7b009 40static int ep93xx_rtc_get_swcomp(struct device *dev, unsigned short *preload,
fd507e2f
AZ
41 unsigned short *delete)
42{
28dc5f80 43 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
38f7b009
HS
44 unsigned long comp;
45
ff32ff17 46 comp = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_SWCOMP);
fd507e2f
AZ
47
48 if (preload)
38f7b009
HS
49 *preload = (comp & EP93XX_RTC_SWCOMP_INT_MASK)
50 >> EP93XX_RTC_SWCOMP_INT_SHIFT;
fd507e2f
AZ
51
52 if (delete)
38f7b009
HS
53 *delete = (comp & EP93XX_RTC_SWCOMP_DEL_MASK)
54 >> EP93XX_RTC_SWCOMP_DEL_SHIFT;
fd507e2f
AZ
55
56 return 0;
57}
58
59static int ep93xx_rtc_read_time(struct device *dev, struct rtc_time *tm)
60{
28dc5f80 61 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
38f7b009
HS
62 unsigned long time;
63
ff32ff17 64 time = readl(ep93xx_rtc->mmio_base + EP93XX_RTC_DATA);
fd507e2f
AZ
65
66 rtc_time_to_tm(time, tm);
67 return 0;
68}
69
70static int ep93xx_rtc_set_mmss(struct device *dev, unsigned long secs)
71{
28dc5f80 72 struct ep93xx_rtc *ep93xx_rtc = dev_get_platdata(dev);
38f7b009 73
ff32ff17 74 writel(secs + 1, ep93xx_rtc->mmio_base + EP93XX_RTC_LOAD);
fd507e2f
AZ
75 return 0;
76}
77
fd507e2f
AZ
78static int ep93xx_rtc_proc(struct device *dev, struct seq_file *seq)
79{
80 unsigned short preload, delete;
81
38f7b009 82 ep93xx_rtc_get_swcomp(dev, &preload, &delete);
fd507e2f 83
fd507e2f
AZ
84 seq_printf(seq, "preload\t\t: %d\n", preload);
85 seq_printf(seq, "delete\t\t: %d\n", delete);
86
87 return 0;
88}
89
ff8371ac 90static const struct rtc_class_ops ep93xx_rtc_ops = {
fd507e2f 91 .read_time = ep93xx_rtc_read_time,
fd507e2f
AZ
92 .set_mmss = ep93xx_rtc_set_mmss,
93 .proc = ep93xx_rtc_proc,
94};
95
38f7b009 96static ssize_t ep93xx_rtc_show_comp_preload(struct device *dev,
fd507e2f
AZ
97 struct device_attribute *attr, char *buf)
98{
99 unsigned short preload;
100
38f7b009 101 ep93xx_rtc_get_swcomp(dev, &preload, NULL);
fd507e2f
AZ
102
103 return sprintf(buf, "%d\n", preload);
104}
38f7b009 105static DEVICE_ATTR(comp_preload, S_IRUGO, ep93xx_rtc_show_comp_preload, NULL);
fd507e2f 106
38f7b009 107static ssize_t ep93xx_rtc_show_comp_delete(struct device *dev,
fd507e2f
AZ
108 struct device_attribute *attr, char *buf)
109{
110 unsigned short delete;
111
38f7b009 112 ep93xx_rtc_get_swcomp(dev, NULL, &delete);
fd507e2f
AZ
113
114 return sprintf(buf, "%d\n", delete);
115}
38f7b009 116static DEVICE_ATTR(comp_delete, S_IRUGO, ep93xx_rtc_show_comp_delete, NULL);
fd507e2f 117
b4877d2b
HS
118static struct attribute *ep93xx_rtc_attrs[] = {
119 &dev_attr_comp_preload.attr,
120 &dev_attr_comp_delete.attr,
121 NULL
122};
123
124static const struct attribute_group ep93xx_rtc_sysfs_files = {
125 .attrs = ep93xx_rtc_attrs,
126};
fd507e2f 127
5a167f45 128static int ep93xx_rtc_probe(struct platform_device *pdev)
fd507e2f 129{
38f7b009
HS
130 struct ep93xx_rtc *ep93xx_rtc;
131 struct resource *res;
38f7b009
HS
132 int err;
133
b4877d2b
HS
134 ep93xx_rtc = devm_kzalloc(&pdev->dev, sizeof(*ep93xx_rtc), GFP_KERNEL);
135 if (!ep93xx_rtc)
38f7b009
HS
136 return -ENOMEM;
137
138 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7c1d69ee
JL
139 ep93xx_rtc->mmio_base = devm_ioremap_resource(&pdev->dev, res);
140 if (IS_ERR(ep93xx_rtc->mmio_base))
141 return PTR_ERR(ep93xx_rtc->mmio_base);
fd507e2f 142
38f7b009 143 pdev->dev.platform_data = ep93xx_rtc;
bf6ed027 144 platform_set_drvdata(pdev, ep93xx_rtc);
38f7b009 145
5d65cbfb
JH
146 ep93xx_rtc->rtc = devm_rtc_device_register(&pdev->dev,
147 pdev->name, &ep93xx_rtc_ops, THIS_MODULE);
bf6ed027
AL
148 if (IS_ERR(ep93xx_rtc->rtc)) {
149 err = PTR_ERR(ep93xx_rtc->rtc);
b4877d2b 150 goto exit;
fd507e2f
AZ
151 }
152
b4877d2b 153 err = sysfs_create_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
38f7b009 154 if (err)
5d65cbfb 155 goto exit;
fd507e2f
AZ
156
157 return 0;
38f7b009 158
b4877d2b
HS
159exit:
160 pdev->dev.platform_data = NULL;
38f7b009 161 return err;
fd507e2f
AZ
162}
163
5a167f45 164static int ep93xx_rtc_remove(struct platform_device *pdev)
fd507e2f 165{
b4877d2b 166 sysfs_remove_group(&pdev->dev.kobj, &ep93xx_rtc_sysfs_files);
38f7b009 167 pdev->dev.platform_data = NULL;
fd507e2f 168
fd507e2f
AZ
169 return 0;
170}
171
38f7b009 172static struct platform_driver ep93xx_rtc_driver = {
fd507e2f
AZ
173 .driver = {
174 .name = "ep93xx-rtc",
fd507e2f 175 },
84d56b38 176 .probe = ep93xx_rtc_probe,
5a167f45 177 .remove = ep93xx_rtc_remove,
fd507e2f
AZ
178};
179
84d56b38 180module_platform_driver(ep93xx_rtc_driver);
fd507e2f
AZ
181
182MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
183MODULE_DESCRIPTION("EP93XX RTC driver");
184MODULE_LICENSE("GPL");
84d56b38 185MODULE_ALIAS("platform:ep93xx-rtc");