summaryrefslogtreecommitdiff
path: root/drivers/base/sys.c
diff options
context:
space:
mode:
authorPatrick Mochel <mochel@osdl.org>2003-06-09 21:58:22 -0700
committerPatrick Mochel <mochel@osdl.org>2003-06-09 21:58:22 -0700
commit35e5d23476e00fb2d709b90d8fb4cc4a9caa660c (patch)
treec861d88734a78684a2a44eae28f9c5f7819ce265 /drivers/base/sys.c
parente5496ae1e2caabe8b1d70e2199472b776c7745d5 (diff)
[driver model] Create include/linux/sysdev.h and define sysdev_attribute.
Split out all system device definitions from device.h into their own header sysdev.h Define struct sysdev_attribute and define functions to export attributes in sysfs.
Diffstat (limited to 'drivers/base/sys.c')
-rw-r--r--drivers/base/sys.c41
1 files changed, 39 insertions, 2 deletions
diff --git a/drivers/base/sys.c b/drivers/base/sys.c
index aa71e40a865e..6ae79a036f0f 100644
--- a/drivers/base/sys.c
+++ b/drivers/base/sys.c
@@ -14,7 +14,7 @@
#define DEBUG
-#include <linux/device.h>
+#include <linux/sysdev.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/kernel.h>
@@ -25,10 +25,47 @@
extern struct subsystem devices_subsys;
+#define to_sysdev(k) container_of(k,struct sys_device,kobj)
+#define to_sysdev_attr(a) container_of(a,struct sysdev_attribute,attr)
+
+
+static ssize_t
+sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer)
+{
+ struct sys_device * sysdev = to_sysdev(kobj);
+ struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
+
+ if (sysdev_attr->show)
+ return sysdev_attr->show(sysdev,buffer);
+ return 0;
+}
+
+
+static ssize_t
+sysdev_store(struct kobject * kobj, struct attribute * attr,
+ const char * buffer, size_t count)
+{
+ struct sys_device * sysdev = to_sysdev(kobj);
+ struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr);
+
+ if (sysdev_attr->store)
+ return sysdev_attr->store(sysdev,buffer,count);
+ return 0;
+}
+
+static struct sysfs_ops sysfs_ops = {
+ .show = sysdev_show,
+ .store = sysdev_store,
+};
+
+static struct kobj_type ktype_sysdev = {
+ .sysfs_ops = &sysfs_ops,
+};
+
/*
* declare system_subsys
*/
-decl_subsys(system,NULL,NULL);
+decl_subsys(system,&ktype_sysdev,NULL);
int sysdev_class_register(struct sysdev_class * cls)
{