summaryrefslogtreecommitdiff
path: root/drivers/base/interface.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 15:20:36 -0700
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/base/interface.c
Linux-2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/base/interface.c')
-rw-r--r--drivers/base/interface.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/drivers/base/interface.c b/drivers/base/interface.c
new file mode 100644
index 000000000000..bd515843a0cb
--- /dev/null
+++ b/drivers/base/interface.c
@@ -0,0 +1,51 @@
+/*
+ * drivers/base/interface.c - common driverfs interface that's exported to
+ * the world for all devices.
+ *
+ * Copyright (c) 2002-3 Patrick Mochel
+ * Copyright (c) 2002-3 Open Source Development Labs
+ *
+ * This file is released under the GPLv2
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/stat.h>
+#include <linux/string.h>
+
+/**
+ * detach_state - control the default power state for the device.
+ *
+ * This is the state the device enters when it's driver module is
+ * unloaded. The value is an unsigned integer, in the range of 0-4.
+ * '0' indicates 'On', so no action will be taken when the driver is
+ * unloaded. This is the default behavior.
+ * '4' indicates 'Off', meaning the driver core will call the driver's
+ * shutdown method to quiesce the device.
+ * 1-3 indicate a low-power state for the device to enter via the
+ * driver's suspend method.
+ */
+
+static ssize_t detach_show(struct device * dev, char * buf)
+{
+ return sprintf(buf, "%u\n", dev->detach_state);
+}
+
+static ssize_t detach_store(struct device * dev, const char * buf, size_t n)
+{
+ u32 state;
+ state = simple_strtoul(buf, NULL, 10);
+ if (state > 4)
+ return -EINVAL;
+ dev->detach_state = state;
+ return n;
+}
+
+static DEVICE_ATTR(detach_state, 0644, detach_show, detach_store);
+
+
+struct attribute * dev_default_attrs[] = {
+ &dev_attr_detach_state.attr,
+ NULL,
+};