aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/rtc/interface.c')
-rw-r--r--drivers/rtc/interface.c86
1 files changed, 42 insertions, 44 deletions
diff --git a/drivers/rtc/interface.c b/drivers/rtc/interface.c
index ef40df0f169d..ad66c6ecf365 100644
--- a/drivers/rtc/interface.c
+++ b/drivers/rtc/interface.c
@@ -13,10 +13,9 @@
13 13
14#include <linux/rtc.h> 14#include <linux/rtc.h>
15 15
16int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm) 16int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
17{ 17{
18 int err; 18 int err;
19 struct rtc_device *rtc = to_rtc_device(class_dev);
20 19
21 err = mutex_lock_interruptible(&rtc->ops_lock); 20 err = mutex_lock_interruptible(&rtc->ops_lock);
22 if (err) 21 if (err)
@@ -28,7 +27,7 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
28 err = -EINVAL; 27 err = -EINVAL;
29 else { 28 else {
30 memset(tm, 0, sizeof(struct rtc_time)); 29 memset(tm, 0, sizeof(struct rtc_time));
31 err = rtc->ops->read_time(class_dev->dev, tm); 30 err = rtc->ops->read_time(rtc->dev.parent, tm);
32 } 31 }
33 32
34 mutex_unlock(&rtc->ops_lock); 33 mutex_unlock(&rtc->ops_lock);
@@ -36,10 +35,9 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
36} 35}
37EXPORT_SYMBOL_GPL(rtc_read_time); 36EXPORT_SYMBOL_GPL(rtc_read_time);
38 37
39int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm) 38int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
40{ 39{
41 int err; 40 int err;
42 struct rtc_device *rtc = to_rtc_device(class_dev);
43 41
44 err = rtc_valid_tm(tm); 42 err = rtc_valid_tm(tm);
45 if (err != 0) 43 if (err != 0)
@@ -54,17 +52,16 @@ int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm)
54 else if (!rtc->ops->set_time) 52 else if (!rtc->ops->set_time)
55 err = -EINVAL; 53 err = -EINVAL;
56 else 54 else
57 err = rtc->ops->set_time(class_dev->dev, tm); 55 err = rtc->ops->set_time(rtc->dev.parent, tm);
58 56
59 mutex_unlock(&rtc->ops_lock); 57 mutex_unlock(&rtc->ops_lock);
60 return err; 58 return err;
61} 59}
62EXPORT_SYMBOL_GPL(rtc_set_time); 60EXPORT_SYMBOL_GPL(rtc_set_time);
63 61
64int rtc_set_mmss(struct class_device *class_dev, unsigned long secs) 62int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
65{ 63{
66 int err; 64 int err;
67 struct rtc_device *rtc = to_rtc_device(class_dev);
68 65
69 err = mutex_lock_interruptible(&rtc->ops_lock); 66 err = mutex_lock_interruptible(&rtc->ops_lock);
70 if (err) 67 if (err)
@@ -73,11 +70,11 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
73 if (!rtc->ops) 70 if (!rtc->ops)
74 err = -ENODEV; 71 err = -ENODEV;
75 else if (rtc->ops->set_mmss) 72 else if (rtc->ops->set_mmss)
76 err = rtc->ops->set_mmss(class_dev->dev, secs); 73 err = rtc->ops->set_mmss(rtc->dev.parent, secs);
77 else if (rtc->ops->read_time && rtc->ops->set_time) { 74 else if (rtc->ops->read_time && rtc->ops->set_time) {
78 struct rtc_time new, old; 75 struct rtc_time new, old;
79 76
80 err = rtc->ops->read_time(class_dev->dev, &old); 77 err = rtc->ops->read_time(rtc->dev.parent, &old);
81 if (err == 0) { 78 if (err == 0) {
82 rtc_time_to_tm(secs, &new); 79 rtc_time_to_tm(secs, &new);
83 80
@@ -89,7 +86,8 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
89 */ 86 */
90 if (!((old.tm_hour == 23 && old.tm_min == 59) || 87 if (!((old.tm_hour == 23 && old.tm_min == 59) ||
91 (new.tm_hour == 23 && new.tm_min == 59))) 88 (new.tm_hour == 23 && new.tm_min == 59)))
92 err = rtc->ops->set_time(class_dev->dev, &new); 89 err = rtc->ops->set_time(rtc->dev.parent,
90 &new);
93 } 91 }
94 } 92 }
95 else 93 else
@@ -101,10 +99,9 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
101} 99}
102EXPORT_SYMBOL_GPL(rtc_set_mmss); 100EXPORT_SYMBOL_GPL(rtc_set_mmss);
103 101
104int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) 102int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
105{ 103{
106 int err; 104 int err;
107 struct rtc_device *rtc = to_rtc_device(class_dev);
108 105
109 err = mutex_lock_interruptible(&rtc->ops_lock); 106 err = mutex_lock_interruptible(&rtc->ops_lock);
110 if (err) 107 if (err)
@@ -116,7 +113,7 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
116 err = -EINVAL; 113 err = -EINVAL;
117 else { 114 else {
118 memset(alarm, 0, sizeof(struct rtc_wkalrm)); 115 memset(alarm, 0, sizeof(struct rtc_wkalrm));
119 err = rtc->ops->read_alarm(class_dev->dev, alarm); 116 err = rtc->ops->read_alarm(rtc->dev.parent, alarm);
120 } 117 }
121 118
122 mutex_unlock(&rtc->ops_lock); 119 mutex_unlock(&rtc->ops_lock);
@@ -124,10 +121,13 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
124} 121}
125EXPORT_SYMBOL_GPL(rtc_read_alarm); 122EXPORT_SYMBOL_GPL(rtc_read_alarm);
126 123
127int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm) 124int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
128{ 125{
129 int err; 126 int err;
130 struct rtc_device *rtc = to_rtc_device(class_dev); 127
128 err = rtc_valid_tm(&alarm->time);
129 if (err != 0)
130 return err;
131 131
132 err = mutex_lock_interruptible(&rtc->ops_lock); 132 err = mutex_lock_interruptible(&rtc->ops_lock);
133 if (err) 133 if (err)
@@ -138,7 +138,7 @@ int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
138 else if (!rtc->ops->set_alarm) 138 else if (!rtc->ops->set_alarm)
139 err = -EINVAL; 139 err = -EINVAL;
140 else 140 else
141 err = rtc->ops->set_alarm(class_dev->dev, alarm); 141 err = rtc->ops->set_alarm(rtc->dev.parent, alarm);
142 142
143 mutex_unlock(&rtc->ops_lock); 143 mutex_unlock(&rtc->ops_lock);
144 return err; 144 return err;
@@ -147,16 +147,14 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm);
147 147
148/** 148/**
149 * rtc_update_irq - report RTC periodic, alarm, and/or update irqs 149 * rtc_update_irq - report RTC periodic, alarm, and/or update irqs
150 * @class_dev: the rtc's class device 150 * @rtc: the rtc device
151 * @num: how many irqs are being reported (usually one) 151 * @num: how many irqs are being reported (usually one)
152 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF 152 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
153 * Context: in_interrupt(), irqs blocked 153 * Context: in_interrupt(), irqs blocked
154 */ 154 */
155void rtc_update_irq(struct class_device *class_dev, 155void rtc_update_irq(struct rtc_device *rtc,
156 unsigned long num, unsigned long events) 156 unsigned long num, unsigned long events)
157{ 157{
158 struct rtc_device *rtc = to_rtc_device(class_dev);
159
160 spin_lock(&rtc->irq_lock); 158 spin_lock(&rtc->irq_lock);
161 rtc->irq_data = (rtc->irq_data + (num << 8)) | events; 159 rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
162 spin_unlock(&rtc->irq_lock); 160 spin_unlock(&rtc->irq_lock);
@@ -171,40 +169,43 @@ void rtc_update_irq(struct class_device *class_dev,
171} 169}
172EXPORT_SYMBOL_GPL(rtc_update_irq); 170EXPORT_SYMBOL_GPL(rtc_update_irq);
173 171
174struct class_device *rtc_class_open(char *name) 172struct rtc_device *rtc_class_open(char *name)
175{ 173{
176 struct class_device *class_dev = NULL, 174 struct device *dev;
177 *class_dev_tmp; 175 struct rtc_device *rtc = NULL;
178 176
179 down(&rtc_class->sem); 177 down(&rtc_class->sem);
180 list_for_each_entry(class_dev_tmp, &rtc_class->children, node) { 178 list_for_each_entry(dev, &rtc_class->devices, node) {
181 if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) { 179 if (strncmp(dev->bus_id, name, BUS_ID_SIZE) == 0) {
182 class_dev = class_device_get(class_dev_tmp); 180 dev = get_device(dev);
181 if (dev)
182 rtc = to_rtc_device(dev);
183 break; 183 break;
184 } 184 }
185 } 185 }
186 186
187 if (class_dev) { 187 if (rtc) {
188 if (!try_module_get(to_rtc_device(class_dev)->owner)) 188 if (!try_module_get(rtc->owner)) {
189 class_dev = NULL; 189 put_device(dev);
190 rtc = NULL;
191 }
190 } 192 }
191 up(&rtc_class->sem); 193 up(&rtc_class->sem);
192 194
193 return class_dev; 195 return rtc;
194} 196}
195EXPORT_SYMBOL_GPL(rtc_class_open); 197EXPORT_SYMBOL_GPL(rtc_class_open);
196 198
197void rtc_class_close(struct class_device *class_dev) 199void rtc_class_close(struct rtc_device *rtc)
198{ 200{
199 module_put(to_rtc_device(class_dev)->owner); 201 module_put(rtc->owner);
200 class_device_put(class_dev); 202 put_device(&rtc->dev);
201} 203}
202EXPORT_SYMBOL_GPL(rtc_class_close); 204EXPORT_SYMBOL_GPL(rtc_class_close);
203 205
204int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task) 206int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
205{ 207{
206 int retval = -EBUSY; 208 int retval = -EBUSY;
207 struct rtc_device *rtc = to_rtc_device(class_dev);
208 209
209 if (task == NULL || task->func == NULL) 210 if (task == NULL || task->func == NULL)
210 return -EINVAL; 211 return -EINVAL;
@@ -220,9 +221,8 @@ int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task)
220} 221}
221EXPORT_SYMBOL_GPL(rtc_irq_register); 222EXPORT_SYMBOL_GPL(rtc_irq_register);
222 223
223void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task) 224void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task)
224{ 225{
225 struct rtc_device *rtc = to_rtc_device(class_dev);
226 226
227 spin_lock_irq(&rtc->irq_task_lock); 227 spin_lock_irq(&rtc->irq_task_lock);
228 if (rtc->irq_task == task) 228 if (rtc->irq_task == task)
@@ -231,11 +231,10 @@ void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task)
231} 231}
232EXPORT_SYMBOL_GPL(rtc_irq_unregister); 232EXPORT_SYMBOL_GPL(rtc_irq_unregister);
233 233
234int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int enabled) 234int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled)
235{ 235{
236 int err = 0; 236 int err = 0;
237 unsigned long flags; 237 unsigned long flags;
238 struct rtc_device *rtc = to_rtc_device(class_dev);
239 238
240 if (rtc->ops->irq_set_state == NULL) 239 if (rtc->ops->irq_set_state == NULL)
241 return -ENXIO; 240 return -ENXIO;
@@ -246,17 +245,16 @@ int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int
246 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 245 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
247 246
248 if (err == 0) 247 if (err == 0)
249 err = rtc->ops->irq_set_state(class_dev->dev, enabled); 248 err = rtc->ops->irq_set_state(rtc->dev.parent, enabled);
250 249
251 return err; 250 return err;
252} 251}
253EXPORT_SYMBOL_GPL(rtc_irq_set_state); 252EXPORT_SYMBOL_GPL(rtc_irq_set_state);
254 253
255int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int freq) 254int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
256{ 255{
257 int err = 0; 256 int err = 0;
258 unsigned long flags; 257 unsigned long flags;
259 struct rtc_device *rtc = to_rtc_device(class_dev);
260 258
261 if (rtc->ops->irq_set_freq == NULL) 259 if (rtc->ops->irq_set_freq == NULL)
262 return -ENXIO; 260 return -ENXIO;
@@ -267,7 +265,7 @@ int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int
267 spin_unlock_irqrestore(&rtc->irq_task_lock, flags); 265 spin_unlock_irqrestore(&rtc->irq_task_lock, flags);
268 266
269 if (err == 0) { 267 if (err == 0) {
270 err = rtc->ops->irq_set_freq(class_dev->dev, freq); 268 err = rtc->ops->irq_set_freq(rtc->dev.parent, freq);
271 if (err == 0) 269 if (err == 0)
272 rtc->irq_freq = freq; 270 rtc->irq_freq = freq;
273 } 271 }