Skip to content

Commit ab6a2d7

Browse files
David BrownellLinus Torvalds
authored andcommitted
rtc: rtc interfaces don't use class_device
This patch removes class_device from the programming interface that the RTC framework exposes to the rest of the kernel. Now an rtc_device is passed, which is more type-safe and streamlines all the relevant code. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Acked-by: Greg Kroah-Hartman <gregkh@suse.de> Acked-By: Alessandro Zummo <a.zummo@towertech.it> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5726fb2 commit ab6a2d7

17 files changed

Lines changed: 119 additions & 118 deletions

‎drivers/rtc/hctosys.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ static int __init rtc_hctosys(void)
2626
{
2727
int err;
2828
struct rtc_time tm;
29-
struct class_device *class_dev = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
29+
struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
3030

31-
if (class_dev == NULL) {
31+
if (rtc == NULL) {
3232
printk("%s: unable to open rtc device (%s)\n",
3333
__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
3434
return -ENODEV;
3535
}
3636

37-
err = rtc_read_time(class_dev, &tm);
37+
err = rtc_read_time(rtc, &tm);
3838
if (err == 0) {
3939
err = rtc_valid_tm(&tm);
4040
if (err == 0) {
@@ -46,22 +46,22 @@ static int __init rtc_hctosys(void)
4646

4747
do_settimeofday(&tv);
4848

49-
dev_info(class_dev->dev,
49+
dev_info(rtc->class_dev.dev,
5050
"setting the system clock to "
5151
"%d-%02d-%02d %02d:%02d:%02d (%u)\n",
5252
tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
5353
tm.tm_hour, tm.tm_min, tm.tm_sec,
5454
(unsigned int) tv.tv_sec);
5555
}
5656
else
57-
dev_err(class_dev->dev,
57+
dev_err(rtc->class_dev.dev,
5858
"hctosys: invalid date/time\n");
5959
}
6060
else
61-
dev_err(class_dev->dev,
61+
dev_err(rtc->class_dev.dev,
6262
"hctosys: unable to read the hardware clock\n");
6363

64-
rtc_class_close(class_dev);
64+
rtc_class_close(rtc);
6565

6666
return 0;
6767
}

‎drivers/rtc/interface.c‎

Lines changed: 36 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@
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
}
3736
EXPORT_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
}
6260
EXPORT_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
}
102100
EXPORT_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
}
125122
EXPORT_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
}
172166
EXPORT_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
}
195193
EXPORT_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
}
202200
EXPORT_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
}
221218
EXPORT_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
}
232228
EXPORT_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
}
253248
EXPORT_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
}

‎drivers/rtc/rtc-at91rm9200.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)
263263

264264
at91_sys_write(AT91_RTC_SCCR, rtsr); /* clear status reg */
265265

266-
rtc_update_irq(&rtc->class_dev, 1, events);
266+
rtc_update_irq(rtc, 1, events);
267267

268268
pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__,
269269
events >> 8, events & 0x000000FF);

‎drivers/rtc/rtc-cmos.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
203203
rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
204204
rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
205205
if (is_intr(rtc_intr))
206-
rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
206+
rtc_update_irq(cmos->rtc, 1, rtc_intr);
207207

208208
/* update alarm */
209209
CMOS_WRITE(hrs, RTC_HOURS_ALARM);
@@ -223,7 +223,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
223223
rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
224224
rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
225225
if (is_intr(rtc_intr))
226-
rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
226+
rtc_update_irq(cmos->rtc, 1, rtc_intr);
227227
}
228228

229229
spin_unlock_irq(&rtc_lock);
@@ -304,7 +304,7 @@ cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
304304
rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
305305
rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
306306
if (is_intr(rtc_intr))
307-
rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
307+
rtc_update_irq(cmos->rtc, 1, rtc_intr);
308308
spin_unlock_irqrestore(&rtc_lock, flags);
309309
return 0;
310310
}
@@ -471,7 +471,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
471471
if (is_valid_irq(rtc_irq))
472472
retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED,
473473
cmos_rtc.rtc->class_dev.class_id,
474-
&cmos_rtc.rtc->class_dev);
474+
cmos_rtc.rtc);
475475
if (retval < 0) {
476476
dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
477477
goto cleanup1;
@@ -555,7 +555,7 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
555555
irqstat = CMOS_READ(RTC_INTR_FLAGS);
556556
irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF;
557557
if (is_intr(irqstat))
558-
rtc_update_irq(&cmos->rtc->class_dev, 1, irqstat);
558+
rtc_update_irq(cmos->rtc, 1, irqstat);
559559
}
560560
spin_unlock_irq(&rtc_lock);
561561

@@ -590,7 +590,7 @@ static int cmos_resume(struct device *dev)
590590
tmp = CMOS_READ(RTC_INTR_FLAGS);
591591
tmp &= (cmos->suspend_ctrl & RTC_IRQMASK) | RTC_IRQF;
592592
if (is_intr(tmp))
593-
rtc_update_irq(&cmos->rtc->class_dev, 1, tmp);
593+
rtc_update_irq(cmos->rtc, 1, tmp);
594594
spin_unlock_irq(&rtc_lock);
595595
}
596596

‎drivers/rtc/rtc-core.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
extern int rtc_interface_register(struct class_interface *intf);
2+
13
#ifdef CONFIG_RTC_INTF_DEV
24

35
extern void __init rtc_dev_init(void);

0 commit comments

Comments
 (0)