bbswitch: Use seq_file instead of deprecated proc_read/proc_write
Now works with dd if=/proc/acpi/bbswitch bs=1 seek=N and if the size passed to fread is larger than 1
This commit is contained in:
parent
96ff2ed501
commit
c6e50c9a37
27
bbswitch.c
27
bbswitch.c
@ -14,6 +14,7 @@
|
|||||||
#include <linux/module.h>
|
#include <linux/module.h>
|
||||||
#include <asm/uaccess.h>
|
#include <asm/uaccess.h>
|
||||||
#include <linux/suspend.h>
|
#include <linux/suspend.h>
|
||||||
|
#include <linux/seq_file.h>
|
||||||
|
|
||||||
MODULE_LICENSE("GPL");
|
MODULE_LICENSE("GPL");
|
||||||
MODULE_DESCRIPTION("Toggle the discrete graphics card");
|
MODULE_DESCRIPTION("Toggle the discrete graphics card");
|
||||||
@ -244,8 +245,8 @@ static void bbswitch_on(void) {
|
|||||||
pci_set_master(dis_dev);
|
pci_set_master(dis_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bbswitch_write(struct file *filp, const char __user *buff,
|
static ssize_t bbswitch_proc_write(struct file *fp, const char __user *buff,
|
||||||
unsigned long len, void *data) {
|
size_t len, loff_t *off) {
|
||||||
char cmd[8];
|
char cmd[8];
|
||||||
|
|
||||||
if (len >= sizeof(cmd)) {
|
if (len >= sizeof(cmd)) {
|
||||||
@ -265,11 +266,14 @@ static int bbswitch_write(struct file *filp, const char __user *buff,
|
|||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bbswitch_read(char *page, char **start, off_t off,
|
static int bbswitch_proc_show(struct seq_file *seqfp, void *p) {
|
||||||
int count, int *eof, void *data) {
|
|
||||||
// show the card state. Example output: 0000:01:00:00 ON
|
// show the card state. Example output: 0000:01:00:00 ON
|
||||||
return snprintf(page, count, "%s %s\n", dev_name(&dis_dev->dev),
|
seq_printf(seqfp, "%s %s\n", dev_name(&dis_dev->dev),
|
||||||
is_card_disabled() ? "OFF" : "ON");
|
is_card_disabled() ? "OFF" : "ON");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int bbswitch_proc_open(struct inode *inode, struct file *file) {
|
||||||
|
return single_open(file, bbswitch_proc_show, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int bbswitch_pm_handler(struct notifier_block *nbp,
|
static int bbswitch_pm_handler(struct notifier_block *nbp,
|
||||||
@ -300,6 +304,14 @@ static int bbswitch_pm_handler(struct notifier_block *nbp,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct file_operations bbswitch_fops = {
|
||||||
|
.open = bbswitch_proc_open,
|
||||||
|
.read = seq_read,
|
||||||
|
.write = bbswitch_proc_write,
|
||||||
|
.llseek = seq_lseek,
|
||||||
|
.release= single_release
|
||||||
|
};
|
||||||
|
|
||||||
static int __init bbswitch_init(void) {
|
static int __init bbswitch_init(void) {
|
||||||
struct proc_dir_entry *acpi_entry;
|
struct proc_dir_entry *acpi_entry;
|
||||||
struct pci_dev *pdev = NULL;
|
struct pci_dev *pdev = NULL;
|
||||||
@ -339,7 +351,7 @@ static int __init bbswitch_init(void) {
|
|||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
acpi_entry = create_proc_entry("bbswitch", 0660, acpi_root_dir);
|
acpi_entry = proc_create("bbswitch", 0660, acpi_root_dir, &bbswitch_fops);
|
||||||
if (acpi_entry == NULL) {
|
if (acpi_entry == NULL) {
|
||||||
printk(KERN_ERR "bbswitch: Couldn't create proc entry\n");
|
printk(KERN_ERR "bbswitch: Couldn't create proc entry\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -348,9 +360,6 @@ static int __init bbswitch_init(void) {
|
|||||||
printk(KERN_INFO "bbswitch: Succesfully loaded. Discrete card %s is %s\n",
|
printk(KERN_INFO "bbswitch: Succesfully loaded. Discrete card %s is %s\n",
|
||||||
dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
dev_name(&dis_dev->dev), is_card_disabled() ? "off" : "on");
|
||||||
|
|
||||||
acpi_entry->write_proc = bbswitch_write;
|
|
||||||
acpi_entry->read_proc = bbswitch_read;
|
|
||||||
|
|
||||||
nb.notifier_call = &bbswitch_pm_handler;
|
nb.notifier_call = &bbswitch_pm_handler;
|
||||||
register_pm_notifier(&nb);
|
register_pm_notifier(&nb);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user