1313
1414#include <linux/rtc.h>
1515
16- int rtc_read_time (struct class_device * class_dev , struct rtc_time * tm )
16+ int rtc_read_time (struct rtc_device * rtc , struct rtc_time * tm )
1717{
1818 int err ;
19- struct rtc_device * rtc = to_rtc_device (class_dev );
2019
2120 err = mutex_lock_interruptible (& rtc -> ops_lock );
2221 if (err )
@@ -28,18 +27,17 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
2827 err = - EINVAL ;
2928 else {
3029 memset (tm , 0 , sizeof (struct rtc_time ));
31- err = rtc -> ops -> read_time (class_dev -> dev , tm );
30+ err = rtc -> ops -> read_time (rtc -> class_dev . dev , tm );
3231 }
3332
3433 mutex_unlock (& rtc -> ops_lock );
3534 return err ;
3635}
3736EXPORT_SYMBOL_GPL (rtc_read_time );
3837
39- int rtc_set_time (struct class_device * class_dev , struct rtc_time * tm )
38+ int rtc_set_time (struct rtc_device * rtc , struct rtc_time * tm )
4039{
4140 int err ;
42- struct rtc_device * rtc = to_rtc_device (class_dev );
4341
4442 err = rtc_valid_tm (tm );
4543 if (err != 0 )
@@ -54,17 +52,16 @@ int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm)
5452 else if (!rtc -> ops -> set_time )
5553 err = - EINVAL ;
5654 else
57- err = rtc -> ops -> set_time (class_dev -> dev , tm );
55+ err = rtc -> ops -> set_time (rtc -> class_dev . dev , tm );
5856
5957 mutex_unlock (& rtc -> ops_lock );
6058 return err ;
6159}
6260EXPORT_SYMBOL_GPL (rtc_set_time );
6361
64- int rtc_set_mmss (struct class_device * class_dev , unsigned long secs )
62+ int rtc_set_mmss (struct rtc_device * rtc , unsigned long secs )
6563{
6664 int err ;
67- struct rtc_device * rtc = to_rtc_device (class_dev );
6865
6966 err = mutex_lock_interruptible (& rtc -> ops_lock );
7067 if (err )
@@ -73,11 +70,11 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
7370 if (!rtc -> ops )
7471 err = - ENODEV ;
7572 else if (rtc -> ops -> set_mmss )
76- err = rtc -> ops -> set_mmss (class_dev -> dev , secs );
73+ err = rtc -> ops -> set_mmss (rtc -> class_dev . dev , secs );
7774 else if (rtc -> ops -> read_time && rtc -> ops -> set_time ) {
7875 struct rtc_time new , old ;
7976
80- err = rtc -> ops -> read_time (class_dev -> dev , & old );
77+ err = rtc -> ops -> read_time (rtc -> class_dev . dev , & old );
8178 if (err == 0 ) {
8279 rtc_time_to_tm (secs , & new );
8380
@@ -89,7 +86,8 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
8986 */
9087 if (!((old .tm_hour == 23 && old .tm_min == 59 ) ||
9188 (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 -> class_dev .dev ,
90+ & new );
9391 }
9492 }
9593 else
@@ -101,10 +99,9 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
10199}
102100EXPORT_SYMBOL_GPL (rtc_set_mmss );
103101
104- int rtc_read_alarm (struct class_device * class_dev , struct rtc_wkalrm * alarm )
102+ int rtc_read_alarm (struct rtc_device * rtc , struct rtc_wkalrm * alarm )
105103{
106104 int err ;
107- struct rtc_device * rtc = to_rtc_device (class_dev );
108105
109106 err = mutex_lock_interruptible (& rtc -> ops_lock );
110107 if (err )
@@ -116,18 +113,17 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
116113 err = - EINVAL ;
117114 else {
118115 memset (alarm , 0 , sizeof (struct rtc_wkalrm ));
119- err = rtc -> ops -> read_alarm (class_dev -> dev , alarm );
116+ err = rtc -> ops -> read_alarm (rtc -> class_dev . dev , alarm );
120117 }
121118
122119 mutex_unlock (& rtc -> ops_lock );
123120 return err ;
124121}
125122EXPORT_SYMBOL_GPL (rtc_read_alarm );
126123
127- int rtc_set_alarm (struct class_device * class_dev , struct rtc_wkalrm * alarm )
124+ int rtc_set_alarm (struct rtc_device * rtc , struct rtc_wkalrm * alarm )
128125{
129126 int err ;
130- struct rtc_device * rtc = to_rtc_device (class_dev );
131127
132128 err = mutex_lock_interruptible (& rtc -> ops_lock );
133129 if (err )
@@ -138,7 +134,7 @@ int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
138134 else if (!rtc -> ops -> set_alarm )
139135 err = - EINVAL ;
140136 else
141- err = rtc -> ops -> set_alarm (class_dev -> dev , alarm );
137+ err = rtc -> ops -> set_alarm (rtc -> class_dev . dev , alarm );
142138
143139 mutex_unlock (& rtc -> ops_lock );
144140 return err ;
@@ -147,16 +143,14 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm);
147143
148144/**
149145 * rtc_update_irq - report RTC periodic, alarm, and/or update irqs
150- * @class_dev : the rtc's class device
146+ * @rtc : the rtc device
151147 * @num: how many irqs are being reported (usually one)
152148 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
153149 * Context: in_interrupt(), irqs blocked
154150 */
155- void rtc_update_irq (struct class_device * class_dev ,
151+ void rtc_update_irq (struct rtc_device * rtc ,
156152 unsigned long num , unsigned long events )
157153{
158- struct rtc_device * rtc = to_rtc_device (class_dev );
159-
160154 spin_lock (& rtc -> irq_lock );
161155 rtc -> irq_data = (rtc -> irq_data + (num << 8 )) | events ;
162156 spin_unlock (& rtc -> irq_lock );
@@ -171,40 +165,43 @@ void rtc_update_irq(struct class_device *class_dev,
171165}
172166EXPORT_SYMBOL_GPL (rtc_update_irq );
173167
174- struct class_device * rtc_class_open (char * name )
168+ struct rtc_device * rtc_class_open (char * name )
175169{
176- struct class_device * class_dev = NULL ,
177- * class_dev_tmp ;
170+ struct class_device * class_dev_tmp ;
171+ struct rtc_device * rtc = NULL ;
178172
179173 down (& rtc_class -> sem );
180174 list_for_each_entry (class_dev_tmp , & rtc_class -> children , node ) {
181175 if (strncmp (class_dev_tmp -> class_id , name , BUS_ID_SIZE ) == 0 ) {
182- class_dev = class_device_get (class_dev_tmp );
176+ class_dev_tmp = class_device_get (class_dev_tmp );
177+ if (class_dev_tmp )
178+ rtc = to_rtc_device (class_dev_tmp );
183179 break ;
184180 }
185181 }
186182
187- if (class_dev ) {
188- if (!try_module_get (to_rtc_device (class_dev )-> owner ))
189- class_dev = NULL ;
183+ if (rtc ) {
184+ if (!try_module_get (rtc -> owner )) {
185+ class_device_put (class_dev_tmp );
186+ rtc = NULL ;
187+ }
190188 }
191189 up (& rtc_class -> sem );
192190
193- return class_dev ;
191+ return rtc ;
194192}
195193EXPORT_SYMBOL_GPL (rtc_class_open );
196194
197- void rtc_class_close (struct class_device * class_dev )
195+ void rtc_class_close (struct rtc_device * rtc )
198196{
199- module_put (to_rtc_device ( class_dev ) -> owner );
200- class_device_put (class_dev );
197+ module_put (rtc -> owner );
198+ class_device_put (& rtc -> class_dev );
201199}
202200EXPORT_SYMBOL_GPL (rtc_class_close );
203201
204- int rtc_irq_register (struct class_device * class_dev , struct rtc_task * task )
202+ int rtc_irq_register (struct rtc_device * rtc , struct rtc_task * task )
205203{
206204 int retval = - EBUSY ;
207- struct rtc_device * rtc = to_rtc_device (class_dev );
208205
209206 if (task == NULL || task -> func == NULL )
210207 return - EINVAL ;
@@ -220,9 +217,8 @@ int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task)
220217}
221218EXPORT_SYMBOL_GPL (rtc_irq_register );
222219
223- void rtc_irq_unregister (struct class_device * class_dev , struct rtc_task * task )
220+ void rtc_irq_unregister (struct rtc_device * rtc , struct rtc_task * task )
224221{
225- struct rtc_device * rtc = to_rtc_device (class_dev );
226222
227223 spin_lock_irq (& rtc -> irq_task_lock );
228224 if (rtc -> irq_task == task )
@@ -231,11 +227,10 @@ void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task)
231227}
232228EXPORT_SYMBOL_GPL (rtc_irq_unregister );
233229
234- int rtc_irq_set_state (struct class_device * class_dev , struct rtc_task * task , int enabled )
230+ int rtc_irq_set_state (struct rtc_device * rtc , struct rtc_task * task , int enabled )
235231{
236232 int err = 0 ;
237233 unsigned long flags ;
238- struct rtc_device * rtc = to_rtc_device (class_dev );
239234
240235 if (rtc -> ops -> irq_set_state == NULL )
241236 return - ENXIO ;
@@ -246,17 +241,16 @@ int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int
246241 spin_unlock_irqrestore (& rtc -> irq_task_lock , flags );
247242
248243 if (err == 0 )
249- err = rtc -> ops -> irq_set_state (class_dev -> dev , enabled );
244+ err = rtc -> ops -> irq_set_state (rtc -> class_dev . dev , enabled );
250245
251246 return err ;
252247}
253248EXPORT_SYMBOL_GPL (rtc_irq_set_state );
254249
255- int rtc_irq_set_freq (struct class_device * class_dev , struct rtc_task * task , int freq )
250+ int rtc_irq_set_freq (struct rtc_device * rtc , struct rtc_task * task , int freq )
256251{
257252 int err = 0 ;
258253 unsigned long flags ;
259- struct rtc_device * rtc = to_rtc_device (class_dev );
260254
261255 if (rtc -> ops -> irq_set_freq == NULL )
262256 return - ENXIO ;
@@ -267,7 +261,7 @@ int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int
267261 spin_unlock_irqrestore (& rtc -> irq_task_lock , flags );
268262
269263 if (err == 0 ) {
270- err = rtc -> ops -> irq_set_freq (class_dev -> dev , freq );
264+ err = rtc -> ops -> irq_set_freq (rtc -> class_dev . dev , freq );
271265 if (err == 0 )
272266 rtc -> irq_freq = freq ;
273267 }
0 commit comments