[PATCH 03/05] input: I2C physical layer

2012-12-18 Thread Christopher Heiny
Changes here are limited to those described in the 0/0 of this patchset, plus
some tweaks to debugging output.

Signed-off-by: Christopher Heiny 
Cc: Dmitry Torokhov 
Cc: Linus Walleij 
Cc: Joeri de Gram 
Acked-by: Jean Delvare 

---

 drivers/input/rmi4/rmi_i2c.c |  141 ++
 1 files changed, 20 insertions(+), 121 deletions(-)

diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
index ca32101..513791c 100644
--- a/drivers/input/rmi4/rmi_i2c.c
+++ b/drivers/input/rmi4/rmi_i2c.c
@@ -2,19 +2,9 @@
  * Copyright (c) 2011, 2012 Synaptics Incorporated
  * Copyright (c) 2011 Unixphere
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
  */

 #include 
@@ -58,7 +48,7 @@ struct rmi_i2c_data {
u8 *debug_buf;
int debug_buf_size;

-   bool comms_debug;
+   u32 comms_debug;
 #ifdef CONFIG_RMI4_DEBUG
struct dentry *debugfs_comms;
 #endif
@@ -66,107 +56,13 @@ struct rmi_i2c_data {

 #ifdef CONFIG_RMI4_DEBUG

-
-/**
- * struct i2c_debugfs_data - stores information for debugfs
- *
- * @done: Indicates that we are done reading debug data. Subsequent reads
- * will return EOF.
- * @i2c_data: Pointer to the i2c data
- *
- */
-struct i2c_debugfs_data {
-   bool done;
-   struct rmi_i2c_data *i2c_data;
-};
-
-static int debug_open(struct inode *inodep, struct file *filp)
-{
-   struct i2c_debugfs_data *data;
-
-   data = kzalloc(sizeof(struct i2c_debugfs_data), GFP_KERNEL);
-   if (!data)
-   return -ENOMEM;
-
-   data->i2c_data = inodep->i_private;
-   filp->private_data = data;
-   return 0;
-}
-
-static int debug_release(struct inode *inodep, struct file *filp)
-{
-   kfree(filp->private_data);
-   return 0;
-}
-
-static ssize_t comms_debug_read(struct file *filp, char __user *buffer,
-   size_t size, loff_t *offset) {
-   int retval;
-   char *local_buf;
-   struct i2c_debugfs_data *dfs = filp->private_data;
-   struct rmi_i2c_data *data = dfs->i2c_data;
-
-   if (dfs->done)
-   return 0;
-
-   local_buf = kcalloc(size, sizeof(u8), GFP_KERNEL);
-   if (!local_buf)
-   return -ENOMEM;
-
-   dfs->done = 1;
-
-   retval = snprintf(local_buf, PAGE_SIZE, "%u\n", data->comms_debug);
-
-   if (retval <= 0 || copy_to_user(buffer, local_buf, retval))
-   retval = -EFAULT;
-   kfree(local_buf);
-
-   return retval;
-}
-
-static ssize_t comms_debug_write(struct file *filp, const char __user *buffer,
-  size_t size, loff_t *offset) {
-   int retval;
-   char *local_buf;
-   unsigned int new_value;
-   struct i2c_debugfs_data *dfs = filp->private_data;
-   struct rmi_i2c_data *data = dfs->i2c_data;
-
-   local_buf = kcalloc(size, sizeof(u8), GFP_KERNEL);
-   if (!local_buf)
-   return -ENOMEM;
-   retval = copy_from_user(local_buf, buffer, size);
-   if (retval) {
-   kfree(local_buf);
-   return -EFAULT;
-   }
-
-   retval = sscanf(local_buf, "%u", _value);
-   kfree(local_buf);
-   if (retval != 1 || new_value > 1)
-   return -EINVAL;
-
-   data->comms_debug = new_value;
-
-   return size;
-}
-
-
-static const struct file_operations comms_debug_fops = {
-   .owner = THIS_MODULE,
-   .open = debug_open,
-   .release = debug_release,
-   .read = comms_debug_read,
-   .write = comms_debug_write,
-};
-
 static int setup_debugfs(struct rmi_device *rmi_dev, struct rmi_i2c_data *data)
 {
if (!rmi_dev->debugfs_root)
return -ENODEV;

-   data->debugfs_comms = debugfs_create_file("comms_debug", RMI_RW_ATTR,
-   rmi_dev->debugfs_root, data, _debug_fops);
+   data->debugfs_comms = debugfs_create_bool("comms_debug", RMI_RW_ATTR,
+   rmi_dev->debugfs_root, >comms_debug);
if (!data->debugfs_comms || IS_ERR(data->debugfs_comms)) {
dev_warn(_dev->dev, "Failed to create debugfs 
comms_debug.\n");
data->debugfs_comms = 

[PATCH 03/05] input: I2C physical layer

2012-12-18 Thread Christopher Heiny
Changes here are limited to those described in the 0/0 of this patchset, plus
some tweaks to debugging output.

Signed-off-by: Christopher Heiny che...@synaptics.com
Cc: Dmitry Torokhov dmitry.torok...@gmail.com
Cc: Linus Walleij linus.wall...@stericsson.com
Cc: Joeri de Gram j.de.g...@gmail.com
Acked-by: Jean Delvare kh...@linux-fr.org

---

 drivers/input/rmi4/rmi_i2c.c |  141 ++
 1 files changed, 20 insertions(+), 121 deletions(-)

diff --git a/drivers/input/rmi4/rmi_i2c.c b/drivers/input/rmi4/rmi_i2c.c
index ca32101..513791c 100644
--- a/drivers/input/rmi4/rmi_i2c.c
+++ b/drivers/input/rmi4/rmi_i2c.c
@@ -2,19 +2,9 @@
  * Copyright (c) 2011, 2012 Synaptics Incorporated
  * Copyright (c) 2011 Unixphere
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 as published by
+ * the Free Software Foundation.
  */

 #include linux/kernel.h
@@ -58,7 +48,7 @@ struct rmi_i2c_data {
u8 *debug_buf;
int debug_buf_size;

-   bool comms_debug;
+   u32 comms_debug;
 #ifdef CONFIG_RMI4_DEBUG
struct dentry *debugfs_comms;
 #endif
@@ -66,107 +56,13 @@ struct rmi_i2c_data {

 #ifdef CONFIG_RMI4_DEBUG

-
-/**
- * struct i2c_debugfs_data - stores information for debugfs
- *
- * @done: Indicates that we are done reading debug data. Subsequent reads
- * will return EOF.
- * @i2c_data: Pointer to the i2c data
- *
- */
-struct i2c_debugfs_data {
-   bool done;
-   struct rmi_i2c_data *i2c_data;
-};
-
-static int debug_open(struct inode *inodep, struct file *filp)
-{
-   struct i2c_debugfs_data *data;
-
-   data = kzalloc(sizeof(struct i2c_debugfs_data), GFP_KERNEL);
-   if (!data)
-   return -ENOMEM;
-
-   data-i2c_data = inodep-i_private;
-   filp-private_data = data;
-   return 0;
-}
-
-static int debug_release(struct inode *inodep, struct file *filp)
-{
-   kfree(filp-private_data);
-   return 0;
-}
-
-static ssize_t comms_debug_read(struct file *filp, char __user *buffer,
-   size_t size, loff_t *offset) {
-   int retval;
-   char *local_buf;
-   struct i2c_debugfs_data *dfs = filp-private_data;
-   struct rmi_i2c_data *data = dfs-i2c_data;
-
-   if (dfs-done)
-   return 0;
-
-   local_buf = kcalloc(size, sizeof(u8), GFP_KERNEL);
-   if (!local_buf)
-   return -ENOMEM;
-
-   dfs-done = 1;
-
-   retval = snprintf(local_buf, PAGE_SIZE, %u\n, data-comms_debug);
-
-   if (retval = 0 || copy_to_user(buffer, local_buf, retval))
-   retval = -EFAULT;
-   kfree(local_buf);
-
-   return retval;
-}
-
-static ssize_t comms_debug_write(struct file *filp, const char __user *buffer,
-  size_t size, loff_t *offset) {
-   int retval;
-   char *local_buf;
-   unsigned int new_value;
-   struct i2c_debugfs_data *dfs = filp-private_data;
-   struct rmi_i2c_data *data = dfs-i2c_data;
-
-   local_buf = kcalloc(size, sizeof(u8), GFP_KERNEL);
-   if (!local_buf)
-   return -ENOMEM;
-   retval = copy_from_user(local_buf, buffer, size);
-   if (retval) {
-   kfree(local_buf);
-   return -EFAULT;
-   }
-
-   retval = sscanf(local_buf, %u, new_value);
-   kfree(local_buf);
-   if (retval != 1 || new_value  1)
-   return -EINVAL;
-
-   data-comms_debug = new_value;
-
-   return size;
-}
-
-
-static const struct file_operations comms_debug_fops = {
-   .owner = THIS_MODULE,
-   .open = debug_open,
-   .release = debug_release,
-   .read = comms_debug_read,
-   .write = comms_debug_write,
-};
-
 static int setup_debugfs(struct rmi_device *rmi_dev, struct rmi_i2c_data *data)
 {
if (!rmi_dev-debugfs_root)
return -ENODEV;

-   data-debugfs_comms = debugfs_create_file(comms_debug, RMI_RW_ATTR,
-   rmi_dev-debugfs_root, data, comms_debug_fops);
+   data-debugfs_comms = debugfs_create_bool(comms_debug, RMI_RW_ATTR,
+   rmi_dev-debugfs_root, data-comms_debug);
if (!data-debugfs_comms || IS_ERR(data-debugfs_comms)) {