From: Dmitry Torokhov <dtor_core@ameritech.net>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Massimo Dal Zotto <dz@debian.org>
Subject: [PATCH 5/5] I8K - convert to platform device (sysfs)
Date: Thu, 24 Feb 2005 01:14:44 -0500 [thread overview]
Message-ID: <200502240114.44662.dtor_core@ameritech.net> (raw)
In-Reply-To: <200502240114.04067.dtor_core@ameritech.net>
i8k.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 117 insertions(+)
Index: dtor/drivers/char/i8k.c
===================================================================
--- dtor.orig/drivers/char/i8k.c
+++ dtor/drivers/char/i8k.c
@@ -22,6 +22,7 @@
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/dmi.h>
+#include <linux/device.h>
#include <asm/uaccess.h>
#include <asm/io.h>
@@ -87,6 +88,13 @@ static struct file_operations i8k_fops =
.ioctl = i8k_ioctl,
};
+static struct device_driver i8k_driver = {
+ .name = "i8k",
+ .bus = &platform_bus_type,
+};
+
+static struct platform_device *i8k_device;
+
struct smm_regs {
unsigned int eax;
unsigned int ebx __attribute__ ((packed));
@@ -406,6 +414,89 @@ static int i8k_open_fs(struct inode *ino
return single_open(file, i8k_proc_show, NULL);
}
+static ssize_t i8k_sysfs_cpu_temp_show(struct device *dev, char *buf)
+{
+ int temp = i8k_get_cpu_temp();
+
+ return temp < 0 ? -EIO : sprintf(buf, "%d\n", temp);
+}
+
+static ssize_t i8k_sysfs_fan1_show(struct device *dev, char *buf)
+{
+ int status = i8k_get_fan_status(0);
+ return status < 0 ? -EIO : sprintf(buf, "%d\n", status);
+}
+
+static ssize_t i8k_sysfs_fan1_set(struct device *dev, const char *buf, size_t count)
+{
+ unsigned long state;
+ char *rest;
+
+ if (restricted && !capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ state = simple_strtoul(buf, &rest, 10);
+ if (*rest || state > I8K_FAN_MAX)
+ return -EINVAL;
+
+ if (i8k_set_fan(0, state) < 0)
+ return -EIO;
+
+ return count;
+}
+
+static ssize_t i8k_sysfs_fan2_show(struct device *dev, char *buf)
+{
+ int status = i8k_get_fan_status(1);
+ return status < 0 ? -EIO : sprintf(buf, "%d\n", status);
+}
+
+static ssize_t i8k_sysfs_fan2_set(struct device *dev, const char *buf, size_t count)
+{
+ unsigned long state;
+ char *rest;
+
+ if (restricted && !capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ state = simple_strtoul(buf, &rest, 10);
+ if (*rest || state > I8K_FAN_MAX)
+ return -EINVAL;
+
+ if (i8k_set_fan(1, state) < 0)
+ return -EIO;
+
+ return count;
+}
+
+static ssize_t i8k_sysfs_fan1_speed_show(struct device *dev, char *buf)
+{
+ int speed = i8k_get_fan_speed(0);
+ return speed < 0 ? -EIO : sprintf(buf, "%d\n", speed);
+}
+
+static ssize_t i8k_sysfs_fan2_speed_show(struct device *dev, char *buf)
+{
+ int speed = i8k_get_fan_speed(1);
+ return speed < 0 ? -EIO : sprintf(buf, "%d\n", speed);
+}
+
+static ssize_t i8k_sysfs_power_status_show(struct device *dev, char *buf)
+{
+ int status = power_status ? i8k_get_power_status() : -1;
+ return status < 0 ? -EIO : sprintf(buf, "%d\n", status);
+}
+
+static struct device_attribute i8k_device_attrs[] = {
+ __ATTR(cpu_temp, 0444, i8k_sysfs_cpu_temp_show, NULL),
+ __ATTR(fan1_state, 0644, i8k_sysfs_fan1_show, i8k_sysfs_fan1_set),
+ __ATTR(fan2_state, 0644, i8k_sysfs_fan2_show, i8k_sysfs_fan2_set),
+ __ATTR(fan1_speed, 0444, i8k_sysfs_fan1_speed_show, NULL),
+ __ATTR(fan2_speed, 0444, i8k_sysfs_fan2_speed_show, NULL),
+ __ATTR(power_status, 0444, i8k_sysfs_power_status_show, NULL),
+ __ATTR_NULL
+};
+
static struct dmi_system_id __initdata i8k_dmi_table[] = {
{
.ident = "Dell Inspiron",
@@ -490,6 +581,7 @@ static int __init i8k_probe(void)
static int __init i8k_init(void)
{
struct proc_dir_entry *proc_i8k;
+ int err, i;
/* Are we running on an supported laptop? */
if (i8k_probe())
@@ -503,15 +595,40 @@ static int __init i8k_init(void)
proc_i8k->proc_fops = &i8k_fops;
proc_i8k->owner = THIS_MODULE;
+ err = driver_register(&i8k_driver);
+ if (err)
+ goto fail1;
+
+ i8k_device = platform_device_register_simple("i8k", -1, NULL, 0);
+ if (IS_ERR(i8k_device)) {
+ err = PTR_ERR(i8k_device);
+ goto fail2;
+ }
+
+ for (i = 0; attr_name(i8k_device_attrs[i]); i++) {
+ err = device_create_file(&i8k_device->dev, &i8k_device_attrs[i]);
+ if (err)
+ goto fail3;
+ }
+
printk(KERN_INFO
"Dell laptop SMM driver v%s Massimo Dal Zotto (dz@debian.org)\n",
I8K_VERSION);
return 0;
+
+fail3: while (--i >= 0)
+ device_remove_file(&i8k_device->dev, &i8k_device_attrs[i]);
+ platform_device_unregister(i8k_device);
+fail2: driver_unregister(&i8k_driver);
+fail1: remove_proc_entry("i8k", NULL);
+ return err;
}
static void __exit i8k_exit(void)
{
+ platform_device_unregister(i8k_device);
+ driver_unregister(&i8k_driver);
remove_proc_entry("i8k", NULL);
}
next prev parent reply other threads:[~2005-02-24 6:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-02-24 6:10 [PATCH 0/5] I8K driver facelift Dmitry Torokhov
2005-02-24 6:11 ` [PATCH 1/5] I8K - pass though Lindent Dmitry Torokhov
2005-02-24 6:12 ` [PATCH 2/5] I8K - use standard DMI functions Dmitry Torokhov
2005-02-24 6:12 ` [PATCH 3/5] I8K - switch to seq_file Dmitry Torokhov
2005-02-24 6:14 ` [PATCH 4/5] I8K - switch to module_{init|exit} Dmitry Torokhov
2005-02-24 6:14 ` Dmitry Torokhov [this message]
2005-03-13 3:41 ` [PATCH 0/5] I8K driver facelift Frank Sorenson
2005-03-13 3:59 ` Dmitry Torokhov
2005-03-15 8:12 ` Valdis.Kletnieks
2005-03-15 10:59 ` Giuseppe Bilotta
2005-03-15 17:30 ` Valdis.Kletnieks
2005-03-15 22:34 ` Frank Sorenson
2005-03-16 21:38 ` Frank Sorenson
2005-03-17 6:40 ` Dmitry Torokhov
2005-03-17 9:37 ` Frank Sorenson
2005-03-17 15:05 ` Dmitry Torokhov
2005-03-17 9:46 ` Frank Sorenson
2005-03-21 5:12 ` Dmitry Torokhov
2005-03-21 22:53 ` Frank Sorenson
2005-03-21 23:55 ` Dmitry Torokhov
2005-03-24 7:25 ` Greg KH
2005-03-24 7:39 ` Dmitry Torokhov
2005-03-24 8:00 ` Greg KH
2005-03-24 14:44 ` Dmitry Torokhov
2005-03-17 8:16 ` Valdis.Kletnieks
2005-03-24 7:24 ` Greg KH
2005-04-13 6:33 ` Dmitry Torokhov
2005-04-13 8:00 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200502240114.44662.dtor_core@ameritech.net \
--to=dtor_core@ameritech.net \
--cc=dz@debian.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox