public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] sysfs class patches - take 2 [0/5]
@ 2003-12-23 21:24 Greg KH
  2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
  2003-12-23 21:57 ` [PATCH] sysfs class patches - take 2 [0/5] Jeff Garzik
  0 siblings, 2 replies; 11+ messages in thread
From: Greg KH @ 2003-12-23 21:24 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel

Here are the sysfs class patches reworked against a clean 2.6.0 tree.
I've created a class_simple.c file that contains a "simple" class device
interface.  I've then converted the tty core to use this interface (the
combo of these two patches makes for no extra code added).

Then there are 3 patches, adding class support for misc, mem, and vc
class devices.  As the interface to add simple class support for devices
is now so low, I feel that we do need to have mem class support as to
not special case any char device.

With these patches, it's now much easier for others to implement class
support for remaining char drivers/subsystems that do not have it yet.

Andrew, can you please remove the following 3 patches from your
2.6.0-mm1 tree:
	sysfs-mem-device-support.patch
	sysfs-misc-device-support.patch
	sysfs-vc-device-support.patch

and add these 5 patches instead?  The sysfs-oops-fix.patch needs to
stay.

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] add "simple" class device support  [1/5]
  2003-12-23 21:24 [PATCH] sysfs class patches - take 2 [0/5] Greg KH
@ 2003-12-23 21:26 ` Greg KH
  2003-12-23 21:27   ` [PATCH] remove tty class device logic [2/5] Greg KH
  2003-12-23 21:57 ` [PATCH] sysfs class patches - take 2 [0/5] Jeff Garzik
  1 sibling, 1 reply; 11+ messages in thread
From: Greg KH @ 2003-12-23 21:26 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel

Adds a "simple" class device interface to the kernel for char devices
that don't want to roll their own struct class_device handling logic.


diff -Nru a/drivers/base/Makefile b/drivers/base/Makefile
--- a/drivers/base/Makefile	Tue Dec 23 12:53:40 2003
+++ b/drivers/base/Makefile	Tue Dec 23 12:53:40 2003
@@ -1,7 +1,7 @@
 # Makefile for the Linux device tree
 
 obj-y			:= core.o sys.o interface.o bus.o \
-			   driver.o class.o platform.o \
+			   driver.o class.o class_simple.o platform.o \
 			   cpu.o firmware.o init.o map.o
 obj-y			+= power/
 obj-$(CONFIG_FW_LOADER)	+= firmware_class.o
diff -Nru a/drivers/base/class_simple.c b/drivers/base/class_simple.c
--- /dev/null	Wed Dec 31 16:00:00 1969
+++ b/drivers/base/class_simple.c	Tue Dec 23 12:53:48 2003
@@ -0,0 +1,123 @@
+/*
+ * class_simple.c - basic char device support
+ *
+ * Copyright (c) 2003 Greg Kroah-Hartman <greg@kroah.com>
+ * Copyright (c) 2003 IBM Corp.
+ * 
+ * This file is released under the GPLv2
+ *
+ */
+
+#undef DEBUG
+
+#include <linux/device.h>
+#include <linux/kdev_t.h>
+#include <linux/err.h>
+
+struct simple_dev {
+	struct list_head node;
+	dev_t dev;
+	struct class_device class_dev;
+};
+#define to_simple_dev(d) container_of(d, struct simple_dev, class_dev)
+
+static LIST_HEAD(simple_dev_list);
+static spinlock_t simple_dev_list_lock = SPIN_LOCK_UNLOCKED;
+
+static void release_simple_dev(struct class_device *class_dev)
+{
+	struct simple_dev *s_dev = to_simple_dev(class_dev);
+	kfree(s_dev);
+}
+
+static ssize_t show_dev(struct class_device *class_dev, char *buf)
+{
+	struct simple_dev *s_dev = to_simple_dev(class_dev);
+	return print_dev_t(buf, s_dev->dev);
+}
+static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
+
+/**
+ * simple_add_class_device - adds a class device to sysfs for a character driver
+ * @class: pointer to the struct class that this device should be registered to.  
+ * @dev: the dev_t for the device to be added.
+ * @device: a pointer to a struct device that is assiociated with this class device.
+ * @fmt: string for the class device's name
+ *
+ * This function can be used by simple char device classes that do not
+ * implement their own class device registration.  A struct class_device will
+ * be created in sysfs, registered to the specified class.  A "dev" file will
+ * be created, showing the dev_t for the device.  The pointer to the struct
+ * class_device will be returned from the call.  Any further sysfs files that
+ * might be required can be created using this pointer.
+ * Note: the struct class passed to this function must have previously been
+ * registered with a call to register_class().
+ */
+struct class_device *simple_add_class_device(struct class *class, dev_t dev, struct device *device, const char *fmt, ...)
+{
+	va_list args;
+	struct simple_dev *s_dev;
+	int retval;
+
+	s_dev = kmalloc(sizeof(*s_dev), GFP_KERNEL);
+	if (!s_dev) {
+		retval = -ENOMEM;
+		goto error;
+	}
+	memset(s_dev, 0x00, sizeof(*s_dev));
+
+	class->release = &release_simple_dev;
+	s_dev->dev = dev;
+	s_dev->class_dev.dev = device;
+	s_dev->class_dev.class = class;
+	
+	va_start(args,fmt);
+	vsnprintf(s_dev->class_dev.class_id, BUS_ID_SIZE, fmt, args);
+	va_end(args);
+	retval = class_device_register(&s_dev->class_dev);
+	if (retval)
+		goto error;
+	class_device_create_file(&s_dev->class_dev, &class_device_attr_dev);
+	spin_lock(&simple_dev_list_lock);
+	list_add(&s_dev->node, &simple_dev_list);
+	spin_unlock(&simple_dev_list_lock);
+
+	return &s_dev->class_dev;
+
+error:
+	kfree(s_dev);
+	return ERR_PTR(retval);
+}
+EXPORT_SYMBOL(simple_add_class_device);
+
+/**
+ * simple_remove_class_device - removes a class device that was created with simple_add_class_device()
+ * @dev: the dev_t of the device that was previously registered.
+ *
+ * This call unregisters and cleans up a class device that was created with a
+ * call to simple_add_class_device()
+ */
+void simple_remove_class_device(dev_t dev)
+{
+	struct simple_dev *s_dev = NULL;
+	struct list_head *tmp;
+	int found = 0;
+
+	spin_lock(&simple_dev_list_lock);
+	list_for_each(tmp, &simple_dev_list) {
+		s_dev = list_entry(tmp, struct simple_dev, node);
+		if (s_dev->dev == dev) {
+			found = 1;
+			break;
+		}
+	}
+	if (found) {
+		list_del(&s_dev->node);
+		spin_unlock(&simple_dev_list_lock);
+		class_device_unregister(&s_dev->class_dev);
+	} else {
+		spin_unlock(&simple_dev_list_lock);
+	}
+}
+EXPORT_SYMBOL(simple_remove_class_device);
+
diff -Nru a/include/linux/device.h b/include/linux/device.h
--- a/include/linux/device.h	Tue Dec 23 12:53:36 2003
+++ b/include/linux/device.h	Tue Dec 23 12:53:36 2003
@@ -246,6 +246,11 @@
 extern int class_interface_register(struct class_interface *);
 extern void class_interface_unregister(struct class_interface *);
 
+/* interface for simple class devices */
+extern struct class_device *simple_add_class_device(struct class *class, dev_t dev, struct device *device, const char *fmt, ...)
+	__attribute__((format(printf,4,5)));
+extern void simple_remove_class_device(dev_t dev);
+
 
 struct device {
 	struct list_head node;		/* node in sibling list */

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] remove tty class device logic  [2/5]
  2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
@ 2003-12-23 21:27   ` Greg KH
  2003-12-23 21:29     ` [PATCH] add sysfs mem class [3/5] Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2003-12-23 21:27 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel


Remove the tty class device logic, as the simple class device interface
can now be used.


diff -Nru a/drivers/char/tty_io.c b/drivers/char/tty_io.c
--- a/drivers/char/tty_io.c	Tue Dec 23 12:53:19 2003
+++ b/drivers/char/tty_io.c	Tue Dec 23 12:53:19 2003
@@ -2069,80 +2069,10 @@
 	tty->driver->write(tty, 0, &ch, 1);
 }
 
-struct tty_dev {
-	struct list_head node;
-	dev_t dev;
-	struct class_device class_dev;
-};
-#define to_tty_dev(d) container_of(d, struct tty_dev, class_dev)
-
-static void release_tty_dev(struct class_device *class_dev)
-{
-	struct tty_dev *tty_dev = to_tty_dev(class_dev);
-	kfree(tty_dev);
-}
-
 static struct class tty_class = {
-	.name		= "tty",
-	.release	= &release_tty_dev,
+	.name	= "tty",
 };
 
-static LIST_HEAD(tty_dev_list);
-static spinlock_t tty_dev_list_lock = SPIN_LOCK_UNLOCKED;
-
-static ssize_t show_dev(struct class_device *class_dev, char *buf)
-{
-	struct tty_dev *tty_dev = to_tty_dev(class_dev);
-	return print_dev_t(buf, tty_dev->dev);
-}
-static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
-
-static void tty_add_class_device(char *name, dev_t dev, struct device *device)
-{
-	struct tty_dev *tty_dev = NULL;
-	int retval;
-
-	tty_dev = kmalloc(sizeof(*tty_dev), GFP_KERNEL);
-	if (!tty_dev)
-		return;
-	memset(tty_dev, 0x00, sizeof(*tty_dev));
-
-	tty_dev->class_dev.dev = device;
-	tty_dev->class_dev.class = &tty_class;
-	snprintf(tty_dev->class_dev.class_id, BUS_ID_SIZE, "%s", name);
-	retval = class_device_register(&tty_dev->class_dev);
-	if (retval)
-		goto error;
-	class_device_create_file (&tty_dev->class_dev, &class_device_attr_dev);
-	tty_dev->dev = dev;
-	spin_lock(&tty_dev_list_lock);
-	list_add(&tty_dev->node, &tty_dev_list);
-	spin_unlock(&tty_dev_list_lock);
-	return;
-error:
-	kfree(tty_dev);
-}
-
-static void tty_remove_class_device(dev_t dev)
-{
-	struct tty_dev *tty_dev = NULL;
-	struct list_head *tmp;
-	int found = 0;
-
-	spin_lock(&tty_dev_list_lock);
-	list_for_each (tmp, &tty_dev_list) {
-		tty_dev = list_entry(tmp, struct tty_dev, node);
-		if (tty_dev->dev == dev) {
-			list_del(&tty_dev->node);
-			found = 1;
-			break;
-		}
-	}
-	spin_unlock(&tty_dev_list_lock);
-	if (found)
-		class_device_unregister(&tty_dev->class_dev);
-}
-
 /**
  * tty_register_device - register a tty device
  * @driver: the tty driver that describes the tty device
@@ -2174,7 +2104,7 @@
 	if (driver->type != TTY_DRIVER_TYPE_PTY) {
 		char name[64];
 		tty_line_name(driver, index, name);
-		tty_add_class_device(name, dev, device);
+		simple_add_class_device(&tty_class, dev, device, name);
 	}
 }
 
@@ -2189,7 +2119,7 @@
 void tty_unregister_device(struct tty_driver *driver, unsigned index)
 {
 	devfs_remove("%s%d", driver->devfs_name, index + driver->name_base);
-	tty_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
+	simple_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
 }
 
 EXPORT_SYMBOL(tty_register_device);
@@ -2431,7 +2361,7 @@
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 0), 1, "/dev/tty") < 0)
 		panic("Couldn't register /dev/tty driver\n");
 	devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 0), S_IFCHR|S_IRUGO|S_IWUGO, "tty");
-	tty_add_class_device ("tty", MKDEV(TTYAUX_MAJOR, 0), NULL);
+	simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 0), NULL, "tty");
 
 	strcpy(console_cdev.kobj.name, "dev.console");
 	cdev_init(&console_cdev, &console_fops);
@@ -2439,7 +2369,7 @@
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 1), 1, "/dev/console") < 0)
 		panic("Couldn't register /dev/console driver\n");
 	devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 1), S_IFCHR|S_IRUSR|S_IWUSR, "console");
-	tty_add_class_device ("console", MKDEV(TTYAUX_MAJOR, 1), NULL);
+	simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 1), NULL, "console");
 
 	tty_kobj.kset = tty_cdev.kobj.kset;
 	kobject_register(&tty_kobj);
@@ -2451,7 +2381,7 @@
 	    register_chrdev_region(MKDEV(TTYAUX_MAJOR, 2), 1, "/dev/ptmx") < 0)
 		panic("Couldn't register /dev/ptmx driver\n");
 	devfs_mk_cdev(MKDEV(TTYAUX_MAJOR, 2), S_IFCHR|S_IRUGO|S_IWUGO, "ptmx");
-	tty_add_class_device ("ptmx", MKDEV(TTYAUX_MAJOR, 2), NULL);
+	simple_add_class_device(&tty_class, MKDEV(TTYAUX_MAJOR, 2), NULL, "ptmx");
 #endif
 	
 #ifdef CONFIG_VT
@@ -2461,7 +2391,7 @@
 	    register_chrdev_region(MKDEV(TTY_MAJOR, 0), 1, "/dev/vc/0") < 0)
 		panic("Couldn't register /dev/tty0 driver\n");
 	devfs_mk_cdev(MKDEV(TTY_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vc/0");
-	tty_add_class_device ("tty0", MKDEV(TTY_MAJOR, 0), NULL);
+	simple_add_class_device(&tty_class, MKDEV(TTY_MAJOR, 0), NULL, "tty0");
 
 	vty_init();
 #endif

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] add sysfs mem class  [3/5]
  2003-12-23 21:27   ` [PATCH] remove tty class device logic [2/5] Greg KH
@ 2003-12-23 21:29     ` Greg KH
  2003-12-23 21:30       ` [PATCH] add sysfs misc class [4/5] Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2003-12-23 21:29 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel


Adds support for mem class devices.  Hopefully one day the
/proc/sys/kernel/random files will move under sysfs into the location
created by this patch (yeah, I know about the sysctl logic...)



diff -Nru a/drivers/char/mem.c b/drivers/char/mem.c
--- a/drivers/char/mem.c	Tue Dec 23 12:53:45 2003
+++ b/drivers/char/mem.c	Tue Dec 23 12:53:45 2003
@@ -24,6 +24,7 @@
 #include <linux/smp_lock.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/ptrace.h>
+#include <linux/device.h>
 
 #include <asm/uaccess.h>
 #include <asm/io.h>
@@ -676,6 +677,10 @@
 	{11,"kmsg",    S_IRUGO | S_IWUSR,           &kmsg_fops},
 };
 
+static struct class mem_class = {
+	.name	= "mem",
+};
+
 static int __init chr_dev_init(void)
 {
 	int i;
@@ -683,7 +688,11 @@
 	if (register_chrdev(MEM_MAJOR,"mem",&memory_fops))
 		printk("unable to get major %d for memory devs\n", MEM_MAJOR);
 
+	class_register(&mem_class);
 	for (i = 0; i < ARRAY_SIZE(devlist); i++) {
+		simple_add_class_device(&mem_class,
+					MKDEV(MEM_MAJOR, devlist[i].minor),
+					NULL, devlist[i].name);
 		devfs_mk_cdev(MKDEV(MEM_MAJOR, devlist[i].minor),
 				S_IFCHR | devlist[i].mode, devlist[i].name);
 	}

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] add sysfs misc class  [4/5]
  2003-12-23 21:29     ` [PATCH] add sysfs mem class [3/5] Greg KH
@ 2003-12-23 21:30       ` Greg KH
  2003-12-23 21:31         ` [PATCH] add sysfs vc class [5/5] Greg KH
  0 siblings, 1 reply; 11+ messages in thread
From: Greg KH @ 2003-12-23 21:30 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel

Add sysfs misc class support, and fix bug where misc_init() was being
called to late in the boot process.

diff -Nru a/drivers/char/misc.c b/drivers/char/misc.c
--- a/drivers/char/misc.c	Tue Dec 23 12:53:35 2003
+++ b/drivers/char/misc.c	Tue Dec 23 12:53:35 2003
@@ -47,7 +47,7 @@
 #include <linux/devfs_fs_kernel.h>
 #include <linux/stat.h>
 #include <linux/init.h>
-
+#include <linux/device.h>
 #include <linux/tty.h>
 #include <linux/kmod.h>
 
@@ -180,6 +180,15 @@
 	return err;
 }
 
+/* 
+ * TODO for 2.7:
+ *  - add a struct class_device to struct miscdevice and make all usages of
+ *    them dynamic.
+ */
+static struct class misc_class = {
+	.name	= "misc",
+};
+
 static struct file_operations misc_fops = {
 	.owner		= THIS_MODULE,
 	.open		= misc_open,
@@ -234,6 +243,8 @@
 				"misc/%s", misc->name);
 	}
 
+	simple_add_class_device(&misc_class, MKDEV(MISC_MAJOR, misc->minor),
+				misc->dev, misc->name);
 	devfs_mk_cdev(MKDEV(MISC_MAJOR, misc->minor),
 			S_IFCHR|S_IRUSR|S_IWUSR|S_IRGRP, misc->devfs_name);
 
@@ -265,6 +276,7 @@
 
 	down(&misc_sem);
 	list_del(&misc->list);
+	simple_remove_class_device(MKDEV(MISC_MAJOR, misc->minor));
 	devfs_remove(misc->devfs_name);
 	if (i < DYNAMIC_MINORS && i>0) {
 		misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
@@ -285,6 +297,7 @@
 	if (ent)
 		ent->proc_fops = &misc_proc_fops;
 #endif
+	class_register(&misc_class);
 #ifdef CONFIG_MVME16x
 	rtc_MK48T08_init();
 #endif
@@ -319,4 +332,4 @@
 	}
 	return 0;
 }
-module_init(misc_init);
+subsys_initcall(misc_init);
diff -Nru a/include/linux/miscdevice.h b/include/linux/miscdevice.h
--- a/include/linux/miscdevice.h	Tue Dec 23 12:53:25 2003
+++ b/include/linux/miscdevice.h	Tue Dec 23 12:53:25 2003
@@ -36,12 +36,15 @@
 
 #define TUN_MINOR	     200
 
+struct device;
+
 struct miscdevice 
 {
 	int minor;
 	const char *name;
 	struct file_operations *fops;
 	struct list_head list;
+	struct device *dev;
 	char devfs_name[64];
 };
 

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] add sysfs vc class  [5/5]
  2003-12-23 21:30       ` [PATCH] add sysfs misc class [4/5] Greg KH
@ 2003-12-23 21:31         ` Greg KH
  0 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2003-12-23 21:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-kernel, linux-hotplug-devel


Add sysfs vc class support

diff -Nru a/drivers/char/vc_screen.c b/drivers/char/vc_screen.c
--- a/drivers/char/vc_screen.c	Tue Dec 23 12:53:14 2003
+++ b/drivers/char/vc_screen.c	Tue Dec 23 12:53:14 2003
@@ -36,6 +36,7 @@
 #include <linux/kbd_kern.h>
 #include <linux/console.h>
 #include <linux/smp_lock.h>
+#include <linux/device.h>
 #include <asm/uaccess.h>
 #include <asm/byteorder.h>
 #include <asm/unaligned.h>
@@ -469,6 +470,10 @@
 	.open		= vcs_open,
 };
 
+static struct class vc_class = {
+	.name	= "vc",
+};
+
 void vcs_make_devfs(struct tty_struct *tty)
 {
 	devfs_mk_cdev(MKDEV(VCS_MAJOR, tty->index + 1),
@@ -477,19 +482,26 @@
 	devfs_mk_cdev(MKDEV(VCS_MAJOR, tty->index + 129),
 			S_IFCHR|S_IRUSR|S_IWUSR,
 			"vcc/a%u", tty->index + 1);
+	simple_add_class_device(&vc_class, MKDEV(VCS_MAJOR, tty->index + 1), NULL, "vcs%u", tty->index + 1);
+	simple_add_class_device(&vc_class, MKDEV(VCS_MAJOR, tty->index + 129), NULL, "vcsa%u", tty->index + 1);
 }
 void vcs_remove_devfs(struct tty_struct *tty)
 {
 	devfs_remove("vcc/%u", tty->index + 1);
 	devfs_remove("vcc/a%u", tty->index + 1);
+	simple_remove_class_device(MKDEV(VCS_MAJOR, tty->index + 1));
+	simple_remove_class_device(MKDEV(VCS_MAJOR, tty->index + 129));
 }
 
 int __init vcs_init(void)
 {
 	if (register_chrdev(VCS_MAJOR, "vcs", &vcs_fops))
 		panic("unable to get major %d for vcs device", VCS_MAJOR);
+	class_register(&vc_class);
 
 	devfs_mk_cdev(MKDEV(VCS_MAJOR, 0), S_IFCHR|S_IRUSR|S_IWUSR, "vcc/0");
 	devfs_mk_cdev(MKDEV(VCS_MAJOR, 128), S_IFCHR|S_IRUSR|S_IWUSR, "vcc/a0");
+	simple_add_class_device(&vc_class, MKDEV(VCS_MAJOR, 0), NULL, "vcs");
+	simple_add_class_device(&vc_class, MKDEV(VCS_MAJOR, 128), NULL, "vcsa");
 	return 0;
 }

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs class patches - take 2 [0/5]
  2003-12-23 21:24 [PATCH] sysfs class patches - take 2 [0/5] Greg KH
  2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
@ 2003-12-23 21:57 ` Jeff Garzik
  2003-12-23 22:07   ` Greg KH
  1 sibling, 1 reply; 11+ messages in thread
From: Jeff Garzik @ 2003-12-23 21:57 UTC (permalink / raw)
  To: Greg KH; +Cc: Andrew Morton, linux-kernel, linux-hotplug-devel

Interesting...  I bet that will be useful to the iPAQ folks (I've been 
wading through their patches lately), as they have created a couple 
ultra-simple classes for SoC devices and such.



^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs class patches - take 2 [0/5]
  2003-12-23 21:57 ` [PATCH] sysfs class patches - take 2 [0/5] Jeff Garzik
@ 2003-12-23 22:07   ` Greg KH
  2003-12-23 23:01     ` [PATCH] add video sysfs class [6/5] Greg KH
  2003-12-24 14:27     ` [PATCH] sysfs class patches - take 2 [0/5] Kronos
  0 siblings, 2 replies; 11+ messages in thread
From: Greg KH @ 2003-12-23 22:07 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Andrew Morton, linux-kernel, linux-hotplug-devel

On Tue, Dec 23, 2003 at 04:57:56PM -0500, Jeff Garzik wrote:
> Interesting...  I bet that will be useful to the iPAQ folks (I've been 
> wading through their patches lately), as they have created a couple 
> ultra-simple classes for SoC devices and such.

I bet it will.  I've ported my old frame buffer patch to use it, and
it saved a lot of code.

Hm, I wonder if the frame buffer people ever intregrated that patch...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH] add video sysfs class [6/5]
  2003-12-23 22:07   ` Greg KH
@ 2003-12-23 23:01     ` Greg KH
  2003-12-24 14:27     ` [PATCH] sysfs class patches - take 2 [0/5] Kronos
  1 sibling, 0 replies; 11+ messages in thread
From: Greg KH @ 2003-12-23 23:01 UTC (permalink / raw)
  To: Andrew Morton, linux-kernel, linux-hotplug-devel

On Tue, Dec 23, 2003 at 02:07:07PM -0800, Greg KH wrote:
> On Tue, Dec 23, 2003 at 04:57:56PM -0500, Jeff Garzik wrote:
> > Interesting...  I bet that will be useful to the iPAQ folks (I've been 
> > wading through their patches lately), as they have created a couple 
> > ultra-simple classes for SoC devices and such.
> 
> I bet it will.  I've ported my old frame buffer patch to use it, and
> it saved a lot of code.

And here is that patch, against a clean 2.6.0 tree.

Andrew, feel free to add this to your -mm tree if you like.  If the "big
framebuffer" resync isn't ever going to happen, getting this patch into
the tree would be a good thing.

thanks,

greg k-h

diff -Nru a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
--- a/drivers/video/aty/aty128fb.c	Tue Dec 23 12:53:13 2003
+++ b/drivers/video/aty/aty128fb.c	Tue Dec 23 12:53:13 2003
@@ -1536,6 +1536,7 @@
 	/* fill in info */
 	info->fbops = &aty128fb_ops;
 	info->flags = FBINFO_FLAG_DEFAULT;
+	info->dev = &pdev->dev;
 
 #ifdef CONFIG_PMAC_PBOOK
 	par->lcd_on = default_lcd_on;
diff -Nru a/drivers/video/cirrusfb.c b/drivers/video/cirrusfb.c
--- a/drivers/video/cirrusfb.c	Tue Dec 23 12:53:13 2003
+++ b/drivers/video/cirrusfb.c	Tue Dec 23 12:53:13 2003
@@ -2787,6 +2787,7 @@
 	fb_info->gen.info.switch_con = &fbgen_switch;
 	fb_info->gen.info.updatevar = &fbgen_update_var;
 	fb_info->gen.info.flags = FBINFO_FLAG_DEFAULT;
+	fb_info->gen.info.dev = fb_info->pdev;
 
 	for (j = 0; j < 256; j++) {
 		if (j < 16) {
diff -Nru a/drivers/video/cyber2000fb.c b/drivers/video/cyber2000fb.c
--- a/drivers/video/cyber2000fb.c	Tue Dec 23 12:53:40 2003
+++ b/drivers/video/cyber2000fb.c	Tue Dec 23 12:53:40 2003
@@ -1366,6 +1366,7 @@
 	cfb->fb.fix.smem_len   = smem_size;
 	cfb->fb.fix.mmio_len   = MMIO_SIZE;
 	cfb->fb.screen_base    = cfb->region;
+	cfb->fb.dev            = &cfb->dev->dev;
 
 	err = -EINVAL;
 	if (!fb_find_mode(&cfb->fb.var, &cfb->fb, NULL, NULL, 0,
diff -Nru a/drivers/video/fbmem.c b/drivers/video/fbmem.c
--- a/drivers/video/fbmem.c	Tue Dec 23 12:53:40 2003
+++ b/drivers/video/fbmem.c	Tue Dec 23 12:53:40 2003
@@ -31,6 +31,7 @@
 #include <linux/kmod.h>
 #endif
 #include <linux/devfs_fs_kernel.h>
+#include <linux/device.h>
 
 #if defined(__mc68000__) || defined(CONFIG_APUS)
 #include <asm/setup.h>
@@ -1199,6 +1200,10 @@
 #endif
 };
 
+static struct class fb_class = {
+	.name	= "video",
+};
+
 /**
  *	register_framebuffer - registers a frame buffer device
  *	@fb_info: frame buffer info structure
@@ -1242,6 +1247,8 @@
 
 	devfs_mk_cdev(MKDEV(FB_MAJOR, i),
 			S_IFCHR | S_IRUGO | S_IWUGO, "fb/%d", i);
+
+	simple_add_class_device(&fb_class, MKDEV(FB_MAJOR, i), fb_info->dev, "fb%d", i);
 	return 0;
 }
 
@@ -1270,6 +1277,7 @@
 		kfree(fb_info->pixmap.addr);
 	registered_fb[i]=NULL;
 	num_registered_fb--;
+	simple_remove_class_device(MKDEV(FB_MAJOR, i));
 	return 0;
 }
 
@@ -1293,6 +1301,8 @@
 	devfs_mk_dir("fb");
 	if (register_chrdev(FB_MAJOR,"fb",&fb_fops))
 		printk("unable to get major %d for fb devs\n", FB_MAJOR);
+
+	class_register(&fb_class);
 
 #ifdef CONFIG_FB_OF
 	if (ofonly) {
diff -Nru a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
--- a/drivers/video/i810/i810_main.c	Tue Dec 23 12:53:19 2003
+++ b/drivers/video/i810/i810_main.c	Tue Dec 23 12:53:19 2003
@@ -1880,6 +1880,7 @@
 	info->fbops = &par->i810fb_ops;
 	info->pseudo_palette = par->pseudo_palette;
 	info->flags = FBINFO_FLAG_DEFAULT;
+	info->dev = &dev->dev;
 	
 	fb_alloc_cmap(&info->cmap, 256, 0);
 
diff -Nru a/drivers/video/igafb.c b/drivers/video/igafb.c
--- a/drivers/video/igafb.c	Tue Dec 23 12:53:19 2003
+++ b/drivers/video/igafb.c	Tue Dec 23 12:53:19 2003
@@ -332,7 +332,7 @@
 #endif
 };
 
-static int __init iga_init(struct fb_info *info, struct iga_par *par)
+static int __init iga_init(struct fb_info *info, struct iga_par *par, struct pci_dev *dev)
 {
         char vramsz = iga_inb(par, IGA_EXT_CNTRL, IGA_IDX_EXT_BUS_CNTL) 
 		                                         & MEM_SIZE_ALIAS;
@@ -358,6 +358,7 @@
 
 	info->fbops = &igafb_ops;
 	info->flags = FBINFO_FLAG_DEFAULT;
+	info->dev = &dev->dev;
 
 	fb_alloc_cmap(&info->cmap, video_cmap_len, 0);
 
@@ -529,7 +530,7 @@
 	info->fix = igafb_fix;
 	info->pseudo_palette = (void *)(par + 1);
 
-	if (!iga_init(info, par)) {
+	if (!iga_init(info, par, pdev)) {
 		iounmap((void *)par->io_base);
 		iounmap(info->screen_base);
 		if (par->mmap_map)
diff -Nru a/drivers/video/imsttfb.c b/drivers/video/imsttfb.c
--- a/drivers/video/imsttfb.c	Tue Dec 23 12:53:11 2003
+++ b/drivers/video/imsttfb.c	Tue Dec 23 12:53:11 2003
@@ -1348,7 +1348,7 @@
 };
 
 static void __init 
-init_imstt(struct fb_info *info)
+init_imstt(struct fb_info *info, struct pci_dev *pdev)
 {
 	struct imstt_par *par = (struct imstt_par *) info->par;
 	__u32 i, tmp, *ip, *end;
@@ -1442,6 +1442,7 @@
 
 	info->fbops = &imsttfb_ops;
 	info->flags = FBINFO_FLAG_DEFAULT;
+	info->dev = &pdev->dev;
 
 	fb_alloc_cmap(&info->cmap, 0, 0);
 
@@ -1520,7 +1521,7 @@
 	par->cmap_regs = (__u8 *)ioremap(addr + 0x840000, 0x1000);
 	info->par = par;
 	info->pseudo_palette = (void *) (par + 1);
-	init_imstt(info);
+	init_imstt(info, pdev);
 
 	pci_set_drvdata(pdev, info);
 	return 0;
diff -Nru a/drivers/video/matrox/matroxfb_crtc2.c b/drivers/video/matrox/matroxfb_crtc2.c
--- a/drivers/video/matrox/matroxfb_crtc2.c	Tue Dec 23 12:53:30 2003
+++ b/drivers/video/matrox/matroxfb_crtc2.c	Tue Dec 23 12:53:30 2003
@@ -605,6 +605,7 @@
 	m2info->fbcon.flags = FBINFO_FLAG_DEFAULT;
 	m2info->fbcon.currcon = -1;
 	m2info->fbcon.pseudo_palette = m2info->cmap;
+	m2info->fbcon.dev = &m2info->primary_dev->pcidev->dev;
 	fb_alloc_cmap(&m2info->fbcon.cmap, 256, 1);
 
 	if (mem < 64)
diff -Nru a/drivers/video/neofb.c b/drivers/video/neofb.c
--- a/drivers/video/neofb.c	Tue Dec 23 12:53:12 2003
+++ b/drivers/video/neofb.c	Tue Dec 23 12:53:12 2003
@@ -1943,6 +1943,7 @@
 	info->flags = FBINFO_FLAG_DEFAULT;
 	info->par = par;
 	info->pseudo_palette = (void *) (par + 1);
+	info->dev = &dev->dev;
 
 	fb_alloc_cmap(&info->cmap, NR_PALETTE, 0);
 
diff -Nru a/drivers/video/radeonfb.c b/drivers/video/radeonfb.c
--- a/drivers/video/radeonfb.c	Tue Dec 23 12:53:34 2003
+++ b/drivers/video/radeonfb.c	Tue Dec 23 12:53:34 2003
@@ -3033,6 +3033,7 @@
 	pci_set_drvdata(pdev, rinfo);
 	rinfo->next = board_list;
 	board_list = rinfo;
+	rinfo->info.dev = &pdev->dev;
 
 	if (register_framebuffer ((struct fb_info *) rinfo) < 0) {
 		printk ("radeonfb: could not register framebuffer\n");
diff -Nru a/drivers/video/riva/fbdev.c b/drivers/video/riva/fbdev.c
--- a/drivers/video/riva/fbdev.c	Tue Dec 23 12:53:31 2003
+++ b/drivers/video/riva/fbdev.c	Tue Dec 23 12:53:31 2003
@@ -1751,6 +1751,7 @@
 	if (info->pixmap.addr == NULL)
 		goto err_out_kfree1;
 	memset(info->pixmap.addr, 0, 64 * 1024);
+	info->dev = &pd->dev;
 
 	strcat(rivafb_fix.id, rci->name);
 	default_par->riva.Architecture = rci->arch_rev;
diff -Nru a/drivers/video/sis/sis_main.c b/drivers/video/sis/sis_main.c
--- a/drivers/video/sis/sis_main.c	Tue Dec 23 12:53:29 2003
+++ b/drivers/video/sis/sis_main.c	Tue Dec 23 12:53:29 2003
@@ -4507,6 +4507,7 @@
 		sis_fb_info.par = &ivideo;
 		sis_fb_info.screen_base = ivideo.video_vbase;
 		sis_fb_info.fbops = &sisfb_ops;
+		sis_fb_info.dev = &pdev->dev;
 		sisfb_get_fix(&sis_fb_info.fix, -1, &sis_fb_info);
 		sis_fb_info.pseudo_palette = pseudo_palette;
 		
diff -Nru a/drivers/video/sstfb.c b/drivers/video/sstfb.c
--- a/drivers/video/sstfb.c	Tue Dec 23 12:53:40 2003
+++ b/drivers/video/sstfb.c	Tue Dec 23 12:53:40 2003
@@ -1477,6 +1477,7 @@
 	info->fbops	= &sstfb_ops;
 	info->currcon	= -1;
 	info->pseudo_palette = &all->pseudo_palette;
+	info->dev	= &pdev->dev;
 
 	fix->type	= FB_TYPE_PACKED_PIXELS;
 	fix->visual	= FB_VISUAL_TRUECOLOR;
diff -Nru a/drivers/video/tdfxfb.c b/drivers/video/tdfxfb.c
--- a/drivers/video/tdfxfb.c	Tue Dec 23 12:53:46 2003
+++ b/drivers/video/tdfxfb.c	Tue Dec 23 12:53:46 2003
@@ -1248,6 +1248,7 @@
 	info->par		= default_par;
 	info->pseudo_palette	= (void *)(default_par + 1); 
 	info->flags		= FBINFO_FLAG_DEFAULT;
+	info->dev		= &pdev->dev;
 
 #ifndef MODULE
 	if (!mode_option)
diff -Nru a/drivers/video/tgafb.c b/drivers/video/tgafb.c
--- a/drivers/video/tgafb.c	Tue Dec 23 12:53:25 2003
+++ b/drivers/video/tgafb.c	Tue Dec 23 12:53:25 2003
@@ -1430,6 +1430,7 @@
 	all->info.currcon = -1;
 	all->info.par = &all->par;
 	all->info.pseudo_palette = all->pseudo_palette;
+	all->info.dev = &pdev->dev;
 
 	/* This should give a reasonable default video mode.  */
 
diff -Nru a/drivers/video/tridentfb.c b/drivers/video/tridentfb.c
--- a/drivers/video/tridentfb.c	Tue Dec 23 12:53:46 2003
+++ b/drivers/video/tridentfb.c	Tue Dec 23 12:53:46 2003
@@ -1156,6 +1156,7 @@
 		default_var.accel_flags &= ~FB_ACCELF_TEXT;
 	default_var.activate |= FB_ACTIVATE_NOW;
 	fb_info.var = default_var;
+	fb_info.dev = &dev->dev;
 	if (register_framebuffer(&fb_info) < 0) {
 		output("Could not register Trident framebuffer\n");
 		return -EINVAL;
diff -Nru a/include/linux/fb.h b/include/linux/fb.h
--- a/include/linux/fb.h	Tue Dec 23 12:53:34 2003
+++ b/include/linux/fb.h	Tue Dec 23 12:53:34 2003
@@ -352,6 +352,7 @@
 struct fb_info;
 struct vm_area_struct;
 struct file;
+struct device;
 
     /*
      *  Frame buffer operations
@@ -412,6 +413,7 @@
    struct vc_data *display_fg;		/* Console visible on this display */
    int currcon;				/* Current VC. */	
    void *pseudo_palette;                /* Fake palette of 16 colors */ 
+   struct device *dev;                  /* pointer to the device for this fb */
    /* From here on everything is device dependent */
    void *par;	
 };

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs class patches - take 2 [0/5]
  2003-12-23 22:07   ` Greg KH
  2003-12-23 23:01     ` [PATCH] add video sysfs class [6/5] Greg KH
@ 2003-12-24 14:27     ` Kronos
  2003-12-24 16:45       ` Greg KH
  1 sibling, 1 reply; 11+ messages in thread
From: Kronos @ 2003-12-24 14:27 UTC (permalink / raw)
  To: linux-kernel; +Cc: Greg KH

Greg KH <greg@kroah.com> ha scritto:
> > On Tue, Dec 23, 2003 at 04:57:56PM -0500, Jeff Garzik wrote:
> > Interesting...  I bet that will be useful to the iPAQ folks (I've been 
> > wading through their patches lately), as they have created a couple 
> > ultra-simple classes for SoC devices and such.
>
> I bet it will.  I've ported my old frame buffer patch to use it, and
> it saved a lot of code.
> 
> Hm, I wonder if the frame buffer people ever intregrated that patch...

I had a patch that add class_device to struct fb_info. This was 3-4 months ago. James merged some of them
and then disappeared...

Luca
-- 
Reply-To: kronos@kronoz.cjb.net
Home: http://kronoz.cjb.net
E' stato a causa di una donna che ho cominciato a bere e non ho mai
avuto la cortesia di ringraziarla.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH] sysfs class patches - take 2 [0/5]
  2003-12-24 14:27     ` [PATCH] sysfs class patches - take 2 [0/5] Kronos
@ 2003-12-24 16:45       ` Greg KH
  0 siblings, 0 replies; 11+ messages in thread
From: Greg KH @ 2003-12-24 16:45 UTC (permalink / raw)
  To: Kronos; +Cc: linux-kernel

On Wed, Dec 24, 2003 at 03:27:17PM +0100, Kronos wrote:
> Greg KH <greg@kroah.com> ha scritto:
> > > On Tue, Dec 23, 2003 at 04:57:56PM -0500, Jeff Garzik wrote:
> > > Interesting...  I bet that will be useful to the iPAQ folks (I've been 
> > > wading through their patches lately), as they have created a couple 
> > > ultra-simple classes for SoC devices and such.
> >
> > I bet it will.  I've ported my old frame buffer patch to use it, and
> > it saved a lot of code.
> > 
> > Hm, I wonder if the frame buffer people ever intregrated that patch...
> 
> I had a patch that add class_device to struct fb_info. This was 3-4
> months ago.

So all of the frame buffer drivers have to be changed to dynamically
allocate the fb_info structure?  That's the "proper" way to do this, but
I felt it was a bit too late in the 2.6 development cycle to try to
intregrate such a large change in...

Oh well,

greg k-h

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2003-12-24 16:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-12-23 21:24 [PATCH] sysfs class patches - take 2 [0/5] Greg KH
2003-12-23 21:26 ` [PATCH] add "simple" class device support [1/5] Greg KH
2003-12-23 21:27   ` [PATCH] remove tty class device logic [2/5] Greg KH
2003-12-23 21:29     ` [PATCH] add sysfs mem class [3/5] Greg KH
2003-12-23 21:30       ` [PATCH] add sysfs misc class [4/5] Greg KH
2003-12-23 21:31         ` [PATCH] add sysfs vc class [5/5] Greg KH
2003-12-23 21:57 ` [PATCH] sysfs class patches - take 2 [0/5] Jeff Garzik
2003-12-23 22:07   ` Greg KH
2003-12-23 23:01     ` [PATCH] add video sysfs class [6/5] Greg KH
2003-12-24 14:27     ` [PATCH] sysfs class patches - take 2 [0/5] Kronos
2003-12-24 16:45       ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox