Commit 99af1a94 authored by Patrick Mochel's avatar Patrick Mochel

driver model: convert interfaces to use kobject and sysfs.

parent 9cd52d59
...@@ -6,41 +6,6 @@ ...@@ -6,41 +6,6 @@
#include <linux/slab.h> #include <linux/slab.h>
#include "fs.h" #include "fs.h"
/**
* intf_dev_link - symlink from interface's directory to device's directory
*
*/
int intf_dev_link(struct intf_data * data)
{
char linkname[16];
char * path;
int length;
int error;
length = get_devpath_length(data->dev);
length += strlen("../../../root");
if (length > PATH_MAX)
return -ENAMETOOLONG;
if (!(path = kmalloc(length,GFP_KERNEL)))
return -ENOMEM;
memset(path,0,length);
strcpy(path,"../../../root");
fill_devpath(data->dev,path,length);
snprintf(linkname,16,"%u",data->intf_num);
error = driverfs_create_symlink(&data->intf->dir,linkname,path);
kfree(path);
return error;
}
void intf_dev_unlink(struct intf_data * data)
{
char linkname[16];
snprintf(linkname,16,"%u",data->intf_num);
driverfs_remove_file(&data->intf->dir,linkname);
}
void intf_remove_dir(struct device_interface * intf) void intf_remove_dir(struct device_interface * intf)
{ {
......
...@@ -11,6 +11,26 @@ ...@@ -11,6 +11,26 @@
#define to_intf(node) container_of(node,struct device_interface,node) #define to_intf(node) container_of(node,struct device_interface,node)
/**
* intf_dev_link - symlink from interface's directory to device's directory
*
*/
int intf_dev_link(struct intf_data * data)
{
char linkname[16];
snprintf(linkname,16,"%u",data->intf_num);
return sysfs_create_link(&data->intf->kobj,&data->dev->kobj,linkname);
}
void intf_dev_unlink(struct intf_data * data)
{
char linkname[16];
snprintf(linkname,16,"%u",data->intf_num);
sysfs_remove_link(&data->intf->kobj,linkname);
}
int interface_register(struct device_interface * intf) int interface_register(struct device_interface * intf)
{ {
struct device_class * cls = intf->devclass; struct device_class * cls = intf->devclass;
...@@ -19,6 +39,12 @@ int interface_register(struct device_interface * intf) ...@@ -19,6 +39,12 @@ int interface_register(struct device_interface * intf)
pr_debug("register interface '%s' with class '%s\n", pr_debug("register interface '%s' with class '%s\n",
intf->name,cls->name); intf->name,cls->name);
intf_make_dir(intf); intf_make_dir(intf);
kobject_init(&intf->kobj);
strncpy(intf->kobj.name,intf->name,KOBJ_NAME_LEN);
intf->kobj.subsys = &cls->subsys;
kobject_register(&intf->kobj);
spin_lock(&device_lock); spin_lock(&device_lock);
list_add_tail(&intf->node,&cls->intf_list); list_add_tail(&intf->node,&cls->intf_list);
spin_unlock(&device_lock); spin_unlock(&device_lock);
...@@ -31,6 +57,7 @@ void interface_unregister(struct device_interface * intf) ...@@ -31,6 +57,7 @@ void interface_unregister(struct device_interface * intf)
{ {
pr_debug("unregistering interface '%s' from class '%s'\n", pr_debug("unregistering interface '%s' from class '%s'\n",
intf->name,intf->devclass->name); intf->name,intf->devclass->name);
kobject_unregister(&intf->kobj);
spin_lock(&device_lock); spin_lock(&device_lock);
list_del_init(&intf->node); list_del_init(&intf->node);
spin_unlock(&device_lock); spin_unlock(&device_lock);
......
...@@ -240,6 +240,7 @@ struct device_interface { ...@@ -240,6 +240,7 @@ struct device_interface {
char * name; char * name;
struct device_class * devclass; struct device_class * devclass;
struct kobject kobj;
struct list_head node; struct list_head node;
struct list_head devices; struct list_head devices;
struct driver_dir_entry dir; struct driver_dir_entry dir;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment