Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab6a2d70 authored by David Brownell's avatar David Brownell Committed by Linus Torvalds
Browse files

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: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Acked-By: default avatarAlessandro Zummo <a.zummo@towertech.it>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5726fb20
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -26,15 +26,15 @@ static int __init rtc_hctosys(void)
{
	int err;
	struct rtc_time tm;
	struct class_device *class_dev = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);
	struct rtc_device *rtc = rtc_class_open(CONFIG_RTC_HCTOSYS_DEVICE);

	if (class_dev == NULL) {
	if (rtc == NULL) {
		printk("%s: unable to open rtc device (%s)\n",
			__FILE__, CONFIG_RTC_HCTOSYS_DEVICE);
		return -ENODEV;
	}

	err = rtc_read_time(class_dev, &tm);
	err = rtc_read_time(rtc, &tm);
	if (err == 0) {
		err = rtc_valid_tm(&tm);
		if (err == 0) {
@@ -46,7 +46,7 @@ static int __init rtc_hctosys(void)

			do_settimeofday(&tv);

			dev_info(class_dev->dev,
			dev_info(rtc->class_dev.dev,
				"setting the system clock to "
				"%d-%02d-%02d %02d:%02d:%02d (%u)\n",
				tm.tm_year + 1900, tm.tm_mon + 1, tm.tm_mday,
@@ -54,14 +54,14 @@ static int __init rtc_hctosys(void)
				(unsigned int) tv.tv_sec);
		}
		else
			dev_err(class_dev->dev,
			dev_err(rtc->class_dev.dev,
				"hctosys: invalid date/time\n");
	}
	else
		dev_err(class_dev->dev,
		dev_err(rtc->class_dev.dev,
			"hctosys: unable to read the hardware clock\n");

	rtc_class_close(class_dev);
	rtc_class_close(rtc);

	return 0;
}
+36 −42
Original line number Diff line number Diff line
@@ -13,10 +13,9 @@

#include <linux/rtc.h>

int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
int rtc_read_time(struct rtc_device *rtc, struct rtc_time *tm)
{
	int err;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	err = mutex_lock_interruptible(&rtc->ops_lock);
	if (err)
@@ -28,7 +27,7 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
		err = -EINVAL;
	else {
		memset(tm, 0, sizeof(struct rtc_time));
		err = rtc->ops->read_time(class_dev->dev, tm);
		err = rtc->ops->read_time(rtc->class_dev.dev, tm);
	}

	mutex_unlock(&rtc->ops_lock);
@@ -36,10 +35,9 @@ int rtc_read_time(struct class_device *class_dev, struct rtc_time *tm)
}
EXPORT_SYMBOL_GPL(rtc_read_time);

int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm)
int rtc_set_time(struct rtc_device *rtc, struct rtc_time *tm)
{
	int err;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	err = rtc_valid_tm(tm);
	if (err != 0)
@@ -54,17 +52,16 @@ int rtc_set_time(struct class_device *class_dev, struct rtc_time *tm)
	else if (!rtc->ops->set_time)
		err = -EINVAL;
	else
		err = rtc->ops->set_time(class_dev->dev, tm);
		err = rtc->ops->set_time(rtc->class_dev.dev, tm);

	mutex_unlock(&rtc->ops_lock);
	return err;
}
EXPORT_SYMBOL_GPL(rtc_set_time);

int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
int rtc_set_mmss(struct rtc_device *rtc, unsigned long secs)
{
	int err;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	err = mutex_lock_interruptible(&rtc->ops_lock);
	if (err)
@@ -73,11 +70,11 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
	if (!rtc->ops)
		err = -ENODEV;
	else if (rtc->ops->set_mmss)
		err = rtc->ops->set_mmss(class_dev->dev, secs);
		err = rtc->ops->set_mmss(rtc->class_dev.dev, secs);
	else if (rtc->ops->read_time && rtc->ops->set_time) {
		struct rtc_time new, old;

		err = rtc->ops->read_time(class_dev->dev, &old);
		err = rtc->ops->read_time(rtc->class_dev.dev, &old);
		if (err == 0) {
			rtc_time_to_tm(secs, &new);

@@ -89,7 +86,8 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
			 */
			if (!((old.tm_hour == 23 && old.tm_min == 59) ||
				(new.tm_hour == 23 && new.tm_min == 59)))
				err = rtc->ops->set_time(class_dev->dev, &new);
				err = rtc->ops->set_time(rtc->class_dev.dev,
						&new);
		}
	}
	else
@@ -101,10 +99,9 @@ int rtc_set_mmss(struct class_device *class_dev, unsigned long secs)
}
EXPORT_SYMBOL_GPL(rtc_set_mmss);

int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
int rtc_read_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
{
	int err;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	err = mutex_lock_interruptible(&rtc->ops_lock);
	if (err)
@@ -116,7 +113,7 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
		err = -EINVAL;
	else {
		memset(alarm, 0, sizeof(struct rtc_wkalrm));
		err = rtc->ops->read_alarm(class_dev->dev, alarm);
		err = rtc->ops->read_alarm(rtc->class_dev.dev, alarm);
	}

	mutex_unlock(&rtc->ops_lock);
@@ -124,10 +121,9 @@ int rtc_read_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
}
EXPORT_SYMBOL_GPL(rtc_read_alarm);

int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
int rtc_set_alarm(struct rtc_device *rtc, struct rtc_wkalrm *alarm)
{
	int err;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	err = mutex_lock_interruptible(&rtc->ops_lock);
	if (err)
@@ -138,7 +134,7 @@ int rtc_set_alarm(struct class_device *class_dev, struct rtc_wkalrm *alarm)
	else if (!rtc->ops->set_alarm)
		err = -EINVAL;
	else
		err = rtc->ops->set_alarm(class_dev->dev, alarm);
		err = rtc->ops->set_alarm(rtc->class_dev.dev, alarm);

	mutex_unlock(&rtc->ops_lock);
	return err;
@@ -147,16 +143,14 @@ EXPORT_SYMBOL_GPL(rtc_set_alarm);

/**
 * rtc_update_irq - report RTC periodic, alarm, and/or update irqs
 * @class_dev: the rtc's class device
 * @rtc: the rtc device
 * @num: how many irqs are being reported (usually one)
 * @events: mask of RTC_IRQF with one or more of RTC_PF, RTC_AF, RTC_UF
 * Context: in_interrupt(), irqs blocked
 */
void rtc_update_irq(struct class_device *class_dev,
void rtc_update_irq(struct rtc_device *rtc,
		unsigned long num, unsigned long events)
{
	struct rtc_device *rtc = to_rtc_device(class_dev);

	spin_lock(&rtc->irq_lock);
	rtc->irq_data = (rtc->irq_data + (num << 8)) | events;
	spin_unlock(&rtc->irq_lock);
@@ -171,40 +165,43 @@ void rtc_update_irq(struct class_device *class_dev,
}
EXPORT_SYMBOL_GPL(rtc_update_irq);

struct class_device *rtc_class_open(char *name)
struct rtc_device *rtc_class_open(char *name)
{
	struct class_device *class_dev = NULL,
				*class_dev_tmp;
	struct class_device *class_dev_tmp;
	struct rtc_device *rtc = NULL;

	down(&rtc_class->sem);
	list_for_each_entry(class_dev_tmp, &rtc_class->children, node) {
		if (strncmp(class_dev_tmp->class_id, name, BUS_ID_SIZE) == 0) {
			class_dev = class_device_get(class_dev_tmp);
			class_dev_tmp = class_device_get(class_dev_tmp);
			if (class_dev_tmp)
				rtc = to_rtc_device(class_dev_tmp);
			break;
		}
	}

	if (class_dev) {
		if (!try_module_get(to_rtc_device(class_dev)->owner))
			class_dev = NULL;
	if (rtc) {
		if (!try_module_get(rtc->owner)) {
			class_device_put(class_dev_tmp);
			rtc = NULL;
		}
	}
	up(&rtc_class->sem);

	return class_dev;
	return rtc;
}
EXPORT_SYMBOL_GPL(rtc_class_open);

void rtc_class_close(struct class_device *class_dev)
void rtc_class_close(struct rtc_device *rtc)
{
	module_put(to_rtc_device(class_dev)->owner);
	class_device_put(class_dev);
	module_put(rtc->owner);
	class_device_put(&rtc->class_dev);
}
EXPORT_SYMBOL_GPL(rtc_class_close);

int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task)
int rtc_irq_register(struct rtc_device *rtc, struct rtc_task *task)
{
	int retval = -EBUSY;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	if (task == NULL || task->func == NULL)
		return -EINVAL;
@@ -220,9 +217,8 @@ int rtc_irq_register(struct class_device *class_dev, struct rtc_task *task)
}
EXPORT_SYMBOL_GPL(rtc_irq_register);

void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task)
void rtc_irq_unregister(struct rtc_device *rtc, struct rtc_task *task)
{
	struct rtc_device *rtc = to_rtc_device(class_dev);

	spin_lock_irq(&rtc->irq_task_lock);
	if (rtc->irq_task == task)
@@ -231,11 +227,10 @@ void rtc_irq_unregister(struct class_device *class_dev, struct rtc_task *task)
}
EXPORT_SYMBOL_GPL(rtc_irq_unregister);

int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int enabled)
int rtc_irq_set_state(struct rtc_device *rtc, struct rtc_task *task, int enabled)
{
	int err = 0;
	unsigned long flags;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	if (rtc->ops->irq_set_state == NULL)
		return -ENXIO;
@@ -246,17 +241,16 @@ int rtc_irq_set_state(struct class_device *class_dev, struct rtc_task *task, int
	spin_unlock_irqrestore(&rtc->irq_task_lock, flags);

	if (err == 0)
		err = rtc->ops->irq_set_state(class_dev->dev, enabled);
		err = rtc->ops->irq_set_state(rtc->class_dev.dev, enabled);

	return err;
}
EXPORT_SYMBOL_GPL(rtc_irq_set_state);

int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int freq)
int rtc_irq_set_freq(struct rtc_device *rtc, struct rtc_task *task, int freq)
{
	int err = 0;
	unsigned long flags;
	struct rtc_device *rtc = to_rtc_device(class_dev);

	if (rtc->ops->irq_set_freq == NULL)
		return -ENXIO;
@@ -267,7 +261,7 @@ int rtc_irq_set_freq(struct class_device *class_dev, struct rtc_task *task, int
	spin_unlock_irqrestore(&rtc->irq_task_lock, flags);

	if (err == 0) {
		err = rtc->ops->irq_set_freq(class_dev->dev, freq);
		err = rtc->ops->irq_set_freq(rtc->class_dev.dev, freq);
		if (err == 0)
			rtc->irq_freq = freq;
	}
+1 −1
Original line number Diff line number Diff line
@@ -263,7 +263,7 @@ static irqreturn_t at91_rtc_interrupt(int irq, void *dev_id)

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

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

		pr_debug("%s(): num=%ld, events=0x%02lx\n", __FUNCTION__,
			events >> 8, events & 0x000000FF);
+6 −6
Original line number Diff line number Diff line
@@ -203,7 +203,7 @@ static int cmos_set_alarm(struct device *dev, struct rtc_wkalrm *t)
	rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
	rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
	if (is_intr(rtc_intr))
		rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
		rtc_update_irq(cmos->rtc, 1, rtc_intr);

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

	spin_unlock_irq(&rtc_lock);
@@ -304,7 +304,7 @@ cmos_rtc_ioctl(struct device *dev, unsigned int cmd, unsigned long arg)
	rtc_intr = CMOS_READ(RTC_INTR_FLAGS);
	rtc_intr &= (rtc_control & RTC_IRQMASK) | RTC_IRQF;
	if (is_intr(rtc_intr))
		rtc_update_irq(&cmos->rtc->class_dev, 1, rtc_intr);
		rtc_update_irq(cmos->rtc, 1, rtc_intr);
	spin_unlock_irqrestore(&rtc_lock, flags);
	return 0;
}
@@ -471,7 +471,7 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
	if (is_valid_irq(rtc_irq))
		retval = request_irq(rtc_irq, cmos_interrupt, IRQF_DISABLED,
				cmos_rtc.rtc->class_dev.class_id,
				&cmos_rtc.rtc->class_dev);
				cmos_rtc.rtc);
	if (retval < 0) {
		dev_dbg(dev, "IRQ %d is already in use\n", rtc_irq);
		goto cleanup1;
@@ -555,7 +555,7 @@ static int cmos_suspend(struct device *dev, pm_message_t mesg)
		irqstat = CMOS_READ(RTC_INTR_FLAGS);
		irqstat &= (tmp & RTC_IRQMASK) | RTC_IRQF;
		if (is_intr(irqstat))
			rtc_update_irq(&cmos->rtc->class_dev, 1, irqstat);
			rtc_update_irq(cmos->rtc, 1, irqstat);
	}
	spin_unlock_irq(&rtc_lock);

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

+2 −0
Original line number Diff line number Diff line
extern int rtc_interface_register(struct class_interface *intf);

#ifdef CONFIG_RTC_INTF_DEV

extern void __init rtc_dev_init(void);
Loading