From patchwork Fri Jul 16 11:11:32 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Renninger X-Patchwork-Id: 112400 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.4/8.14.3) with ESMTP id o6GBCPK7025128 for ; Fri, 16 Jul 2010 11:12:25 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965159Ab0GPLLn (ORCPT ); Fri, 16 Jul 2010 07:11:43 -0400 Received: from cantor2.suse.de ([195.135.220.15]:43425 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965122Ab0GPLLm (ORCPT ); Fri, 16 Jul 2010 07:11:42 -0400 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) by mx2.suse.de (Postfix) with ESMTP id 0F3FE8655F; Fri, 16 Jul 2010 13:11:41 +0200 (CEST) From: Thomas Renninger To: lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org, platform-driver-x86@vger.kernel.org, Thomas Renninger , Alexey Starikovskiy Subject: [PATCH 2/7] ACPI: Provide /sys/kernel/debug//ec/ec0/io for binary access to the EC Date: Fri, 16 Jul 2010 13:11:32 +0200 Message-Id: <1279278697-3694-3-git-send-email-trenn@suse.de> X-Mailer: git-send-email 1.6.3 In-Reply-To: <1279278697-3694-1-git-send-email-trenn@suse.de> References: <1279278697-3694-1-git-send-email-trenn@suse.de> Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter.kernel.org [140.211.167.41]); Fri, 16 Jul 2010 11:12:26 +0000 (UTC) diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c index 834c21a..3ef9781 100644 --- a/drivers/acpi/ec_sys.c +++ b/drivers/acpi/ec_sys.c @@ -1,3 +1,13 @@ +/* + * ec_sys.c + * + * Copyright (C) 2010 SUSE Products GmbH/Novell + * Author: + * Thomas Renninger + * + * This work is licensed under the terms of the GNU GPL, version 2. + */ + #include #include #include @@ -7,12 +17,87 @@ MODULE_AUTHOR("Thomas Renninger "); MODULE_DESCRIPTION("ACPI EC sysfs access driver"); MODULE_LICENSE("GPL"); +#define EC_SPACE_SIZE 256 + struct sysdev_class acpi_ec_sysdev_class = { .name = "ec", }; static struct dentry *acpi_ec_debugfs_dir; +static int acpi_ec_open_io(struct inode *i, struct file *f) +{ + f->private_data = i->i_private; + return 0; +} + +static ssize_t acpi_ec_read_io(struct file *f, char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + unsigned int size = EC_SPACE_SIZE; + u8 *data = (u8 *) buf; + loff_t init_off = *off; + int err = 0; + + if (*off >= size) + return 0; + if (*off + count >= size) { + size -= *off; + count = size; + } else + size = count; + + while (size) { + err = ec_read(*off, &data[*off - init_off]); + if (err) + return err; + *off += 1; + size--; + } + return count; +} + +static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf, + size_t count, loff_t *off) +{ + /* Use this if support reading/writing multiple ECs exists in ec.c: + * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private; + */ + + unsigned int size = count; + loff_t init_off = *off; + u8 *data = (u8 *) buf; + int err = 0; + + if (*off >= EC_SPACE_SIZE) + return 0; + if (*off + count >= EC_SPACE_SIZE) { + size = EC_SPACE_SIZE - *off; + count = size; + } + + while (size) { + u8 byte_write = data[*off - init_off]; + err = ec_write(*off, byte_write); + if (err) + return err; + + *off += 1; + size--; + } + return count; +} + +static struct file_operations acpi_ec_io_ops = { + .owner = THIS_MODULE, + .open = acpi_ec_open_io, + .read = acpi_ec_read_io, + .write = acpi_ec_write_io, +}; + int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) { struct dentry *dev_dir; @@ -35,6 +120,7 @@ int acpi_ec_add_debugfs(struct acpi_ec *ec, unsigned int ec_device_count) debugfs_create_x32("gpe", 0444, dev_dir, (u32 *)&first_ec->gpe); debugfs_create_bool("use_global_lock", 0444, dev_dir, (u32 *)&first_ec->global_lock); + debugfs_create_file("io", 0666, dev_dir, ec, &acpi_ec_io_ops); return 0; }