Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 54766
b: refs/heads/master
c: 5726fb2
h: refs/heads/master
v: v3
  • Loading branch information
David Brownell authored and Linus Torvalds committed May 8, 2007
1 parent e711fe7 commit e539b50
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 90 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 1c710c896eb461895d3c399e15bb5f20b39c9073
refs/heads/master: 5726fb2012f0d96153113ddb7f988a0daea587ce
2 changes: 1 addition & 1 deletion trunk/drivers/rtc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ config RTC_INTF_PROC
will be called rtc-proc.

config RTC_INTF_DEV
tristate "dev"
boolean "dev"
depends on RTC_CLASS
default RTC_CLASS
help
Expand Down
3 changes: 2 additions & 1 deletion trunk/drivers/rtc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ obj-$(CONFIG_RTC_HCTOSYS) += hctosys.o
obj-$(CONFIG_RTC_CLASS) += rtc-core.o
rtc-core-y := class.o interface.o

rtc-core-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o

obj-$(CONFIG_RTC_INTF_SYSFS) += rtc-sysfs.o
obj-$(CONFIG_RTC_INTF_PROC) += rtc-proc.o
obj-$(CONFIG_RTC_INTF_DEV) += rtc-dev.o

obj-$(CONFIG_RTC_DRV_CMOS) += rtc-cmos.o
obj-$(CONFIG_RTC_DRV_X1205) += rtc-x1205.o
Expand Down
8 changes: 8 additions & 0 deletions trunk/drivers/rtc/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#include <linux/kdev_t.h>
#include <linux/idr.h>

#include "rtc-core.h"


static DEFINE_IDR(rtc_idr);
static DEFINE_MUTEX(idr_lock);
struct class *rtc_class;
Expand Down Expand Up @@ -85,6 +88,8 @@ struct rtc_device *rtc_device_register(const char *name, struct device *dev,
if (err)
goto exit_kfree;

rtc_dev_add_device(rtc);

dev_info(dev, "rtc core: registered %s as %s\n",
rtc->name, rtc->class_dev.class_id);

Expand Down Expand Up @@ -118,6 +123,7 @@ void rtc_device_unregister(struct rtc_device *rtc)
/* remove innards of this RTC, then disable it, before
* letting any rtc_class_open() users access it again
*/
rtc_dev_del_device(rtc);
class_device_unregister(&rtc->class_dev);
rtc->ops = NULL;
mutex_unlock(&rtc->ops_lock);
Expand All @@ -140,11 +146,13 @@ static int __init rtc_init(void)
printk(KERN_ERR "%s: couldn't create class\n", __FILE__);
return PTR_ERR(rtc_class);
}
rtc_dev_init();
return 0;
}

static void __exit rtc_exit(void)
{
rtc_dev_exit();
class_destroy(rtc_class);
}

Expand Down
15 changes: 15 additions & 0 deletions trunk/drivers/rtc/rtc-core.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#ifdef CONFIG_RTC_INTF_DEV

extern void __init rtc_dev_init(void);
extern void __exit rtc_dev_exit(void);
extern void rtc_dev_add_device(struct rtc_device *rtc);
extern void rtc_dev_del_device(struct rtc_device *rtc);

#else

#define rtc_dev_init() do{}while(0)
#define rtc_dev_exit() do{}while(0)
#define rtc_dev_add_device(r) do{}while(0)
#define rtc_dev_del_device(r) do{}while(0)

#endif
106 changes: 20 additions & 86 deletions trunk/drivers/rtc/rtc-dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

#include <linux/module.h>
#include <linux/rtc.h>
#include "rtc-core.h"

static struct class *rtc_dev_class;
static dev_t rtc_devt;

#define RTC_DEV_MAX 16 /* 16 RTCs should be enough for everyone... */
Expand Down Expand Up @@ -397,17 +397,18 @@ static const struct file_operations rtc_dev_fops = {

/* insertion/removal hooks */

static int rtc_dev_add_device(struct class_device *class_dev,
struct class_interface *class_intf)
void rtc_dev_add_device(struct rtc_device *rtc)
{
int err = 0;
struct rtc_device *rtc = to_rtc_device(class_dev);
if (!rtc_devt)
return;

if (rtc->id >= RTC_DEV_MAX) {
dev_err(class_dev->dev, "too many RTCs\n");
return -EINVAL;
pr_debug("%s: too many RTC devices\n", rtc->name);
return;
}

rtc->class_dev.devt = MKDEV(MAJOR(rtc_devt), rtc->id);

mutex_init(&rtc->char_lock);
spin_lock_init(&rtc->irq_lock);
init_waitqueue_head(&rtc->irq_queue);
Expand All @@ -419,99 +420,32 @@ static int rtc_dev_add_device(struct class_device *class_dev,
cdev_init(&rtc->char_dev, &rtc_dev_fops);
rtc->char_dev.owner = rtc->owner;

if (cdev_add(&rtc->char_dev, MKDEV(MAJOR(rtc_devt), rtc->id), 1)) {
dev_err(class_dev->dev,
"failed to add char device %d:%d\n",
if (cdev_add(&rtc->char_dev, rtc->class_dev.devt, 1))
printk(KERN_WARNING "%s: failed to add char device %d:%d\n",
rtc->name, MAJOR(rtc_devt), rtc->id);
else
pr_debug("%s: dev (%d:%d)\n", rtc->name,
MAJOR(rtc_devt), rtc->id);
return -ENODEV;
}

rtc->rtc_dev = class_device_create(rtc_dev_class, NULL,
MKDEV(MAJOR(rtc_devt), rtc->id),
class_dev->dev, "rtc%d", rtc->id);
if (IS_ERR(rtc->rtc_dev)) {
dev_err(class_dev->dev, "cannot create rtc_dev device\n");
err = PTR_ERR(rtc->rtc_dev);
goto err_cdev_del;
}

dev_dbg(class_dev->dev, "rtc intf: dev (%d:%d)\n",
MAJOR(rtc->rtc_dev->devt),
MINOR(rtc->rtc_dev->devt));

return 0;

err_cdev_del:

cdev_del(&rtc->char_dev);
return err;
}

static void rtc_dev_remove_device(struct class_device *class_dev,
struct class_interface *class_intf)
void rtc_dev_del_device(struct rtc_device *rtc)
{
struct rtc_device *rtc = to_rtc_device(class_dev);

if (rtc->rtc_dev) {
dev_dbg(class_dev->dev, "removing char %d:%d\n",
MAJOR(rtc->rtc_dev->devt),
MINOR(rtc->rtc_dev->devt));

class_device_unregister(rtc->rtc_dev);
if (rtc->class_dev.devt)
cdev_del(&rtc->char_dev);
}
}

/* interface registration */

static struct class_interface rtc_dev_interface = {
.add = &rtc_dev_add_device,
.remove = &rtc_dev_remove_device,
};

static int __init rtc_dev_init(void)
void __init rtc_dev_init(void)
{
int err;

rtc_dev_class = class_create(THIS_MODULE, "rtc-dev");
if (IS_ERR(rtc_dev_class))
return PTR_ERR(rtc_dev_class);

err = alloc_chrdev_region(&rtc_devt, 0, RTC_DEV_MAX, "rtc");
if (err < 0) {
if (err < 0)
printk(KERN_ERR "%s: failed to allocate char dev region\n",
__FILE__);
goto err_destroy_class;
}

err = rtc_interface_register(&rtc_dev_interface);
if (err < 0) {
printk(KERN_ERR "%s: failed to register the interface\n",
__FILE__);
goto err_unregister_chrdev;
}

return 0;

err_unregister_chrdev:
unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);

err_destroy_class:
class_destroy(rtc_dev_class);

return err;
}

static void __exit rtc_dev_exit(void)
void __exit rtc_dev_exit(void)
{
class_interface_unregister(&rtc_dev_interface);
class_destroy(rtc_dev_class);
unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
if (rtc_devt)
unregister_chrdev_region(rtc_devt, RTC_DEV_MAX);
}

subsys_initcall(rtc_dev_init);
module_exit(rtc_dev_exit);

MODULE_AUTHOR("Alessandro Zummo <a.zummo@towertech.it>");
MODULE_DESCRIPTION("RTC class dev interface");
MODULE_LICENSE("GPL");
1 change: 0 additions & 1 deletion trunk/include/linux/rtc.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ struct rtc_device
const struct rtc_class_ops *ops;
struct mutex ops_lock;

struct class_device *rtc_dev;
struct cdev char_dev;
struct mutex char_lock;

Expand Down

0 comments on commit e539b50

Please sign in to comment.