From: <jsi...@us...> - 2007-04-15 00:52:36
|
Revision: 2374 http://linuxconsole.svn.sourceforge.net/linuxconsole/?rev=2374&view=rev Author: jsimmons Date: 2007-04-14 17:52:34 -0700 (Sat, 14 Apr 2007) Log Message: ----------- Parital merged with VT sysfs code Modified Paths: -------------- branches/ruby-2.6.21/ruby-2.6/drivers/char/vt_sysfs.c Modified: branches/ruby-2.6.21/ruby-2.6/drivers/char/vt_sysfs.c =================================================================== --- branches/ruby-2.6.21/ruby-2.6/drivers/char/vt_sysfs.c 2007-04-14 23:31:33 UTC (rev 2373) +++ branches/ruby-2.6.21/ruby-2.6/drivers/char/vt_sysfs.c 2007-04-15 00:52:34 UTC (rev 2374) @@ -10,61 +10,105 @@ #include <linux/vt_kern.h> #include <linux/input.h> -/* show configuration fields */ -#define vt_config_attr(field, format_string) \ -static ssize_t \ -vt_show_##field (struct class_device *dev, char *buf) \ -{ \ - struct vt_struct *vt; \ - \ - vt = to_vt_struct (dev); \ - return sprintf (buf, format_string, vt->field); \ -} \ -static CLASS_DEVICE_ATTR(field, S_IRUGO, vt_show_##field, NULL); +static struct class *vt_class; -struct class vt_class = { - .name = "vt", -}; +//vt_config_attr(first_vc, "%d\n"); +//vt_config_attr(vc_count, "%d\n"); -vt_config_attr(display_desc, "%s\n"); -vt_config_attr(first_vc, "%d\n"); -vt_config_attr(vc_count, "%d\n"); +static inline int vt_bind(struct vt_struct *vt) +{ + return 0; +} +static inline int vt_unbind(struct vt_struct *vt) +{ + return 0; +} -static ssize_t -vt_show_keyboard (struct class_device *dev, char *buf) +static ssize_t show_keyboard(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { - struct vt_struct *vt; - struct input_handle *handle; + struct vt_struct *vt = dev_get_drvdata(dev); + struct input_handle *handle = vt->keyboard; - vt = to_vt_struct (dev); - handle = vt->keyboard; if (handle && handle->dev->phys) return sprintf (buf, "%s\n", handle->dev->phys); return sprintf (buf, "%s\n", ""); } -static CLASS_DEVICE_ATTR(keyboard, S_IRUGO, vt_show_keyboard, NULL); -int __init vt_create_sysfs_dev_files (struct vt_struct *vt) +static ssize_t store_bind(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) { - struct class_device *dev = &vt->dev; + struct vt_struct *vt = dev_get_drvdata(dev); + int bind = simple_strtoul(buf, NULL, 0); - dev->class = &vt_class; - sprintf (dev->class_id, "%02x", vt->vt_num); - class_device_register(dev); + if (bind) + vt_bind(vt); + else + vt_unbind(con); + return count; +} - /* current configuration's attributes */ - class_device_create_file (dev, &class_device_attr_display_desc); - class_device_create_file (dev, &class_device_attr_first_vc); - class_device_create_file (dev, &class_device_attr_vc_count); - class_device_create_file (dev, &class_device_attr_keyboard); +static ssize_t show_bind(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct vt_struct *vt = dev_get_drvdata(dev); + int bind = (vt->vt_sw != NULL) ? 1 : 0; - return 0; + return snprintf(buf, PAGE_SIZE, "%i\n", bind); } +static ssize_t show_name(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct vt_struct *vt = dev_get_drvdata(dev); + + return snprintf(buf, PAGE_SIZE, "%s %s\n", + (vt->flag & CON_DRIVER_FLAG_MODULE) ? "(M)" : "(S)", + vt->desc); +} + +static struct device_attribute vt_device_attrs[] = { + __ATTR(bind, S_IRUGO|S_IWUSR, show_bind, store_bind), + __ATTR(keyboard, S_IRUGO, show_keyboard, NULL), + __ATTR(name, S_IRUGO, show_name, NULL), +}; + +static int vt_init_device(struct vt_struct *vt) +{ + int err = 0; + + vt->dev = device_create(vt_class, NULL, MKDEV(0, vt->count), + "vtcon%i", vt->count); + if (IS_ERR(vt->dev)) { + vt->flag &= ~CON_DRIVER_FLAG_ATTR; + vt->dev = NULL; + error = -EINVAL; + } else { + dev_set_drvdata(vt->dev, vt); + fb_info->flag |= CON_DRIVER_FLAG_ATTR; + } + return err; +} + +static void vt_deinit_device(struct vt_struct *vt) +{ + vt->flag &= ~CON_DRIVER_FLAG_ATTR; + dev_set_drvdata(vt->dev, NULL); + device_destroy(vt_class, MKDEV(0, vt->count)); +} + void __init vt_sysfs_init(void) { /* we have only one boot time console - admin_vt*/ - class_register(&vt_class); - vt_create_sysfs_dev_files(admin_vt); + vt_class = class_create(THIS_MODULE, "vt"); + if (IS_ERR(vt_class)) { + printk(KERN_WARNING "Unable to create vt console class; " + "errno = %ld\n", PTR_ERR(vtconsole_class)); + vt_class = NULL; + } else { + vt_class->dev_attrs = vt_device_attrs + } } + +postcore_initcall(vtconsole_class_init); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |