[PATCH 02/05] input: Core files

2012-12-18 Thread Christopher Heiny
In addition to the changes described in 0/0 of this patch set, these files
are updated as follows:

* initialization sequence rearranged to support the merging of rmi_f01 and
rmi_driver into the RMI4 core.

* the initial reset and firmware update PDT scans are split into their own
functions in order to account for the fact that the PDT may change after
the initial reset.

* Problems with release_rmidev_device() identified by Greg KH are fixed and
tested.

* EXPORT_SYMBOL() changed to EXPORT_SYMBOL_GPL(), per Greg KH input.

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

---

 drivers/input/rmi4/rmi_bus.c|  232 ---
 drivers/input/rmi4/rmi_driver.c |  655 ---
 drivers/input/rmi4/rmi_driver.h |   32 +--
 3 files changed, 468 insertions(+), 451 deletions(-)

diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index acbfd3d..71bc201 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.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 
@@ -75,7 +65,8 @@ static struct dentry *rmi_debugfs_root;

 static void release_rmidev_device(struct device *dev)
 {
-   device_unregister(dev);
+   struct rmi_device *rmi_dev = to_rmi_device(dev);
+   kfree(rmi_dev);
 }

 /**
@@ -110,17 +101,19 @@ int rmi_register_phys_device(struct rmi_phys_device *phys)
dev_dbg(phys->dev, "%s: Registered %s as %s.\n", __func__,
pdata->sensor_name, dev_name(_dev->dev));

-   if (IS_ENABLED(CONFIG_RMI4_DEBUG) && rmi_debugfs_root) {
+#ifdef CONFIG_RMI4_DEBUG
+   if (rmi_debugfs_root) {
rmi_dev->debugfs_root = debugfs_create_dir(
dev_name(_dev->dev), rmi_debugfs_root);
if (!rmi_dev->debugfs_root)
dev_err(_dev->dev, "Failed to create debugfs 
root.\n");
}
+#endif

phys->rmi_dev = rmi_dev;
return device_register(_dev->dev);
 }
-EXPORT_SYMBOL(rmi_register_phys_device);
+EXPORT_SYMBOL_GPL(rmi_register_phys_device);

 /**
  * rmi_unregister_phys_device - unregister a physical device connection
@@ -131,102 +124,84 @@ void rmi_unregister_phys_device(struct rmi_phys_device 
*phys)
 {
struct rmi_device *rmi_dev = phys->rmi_dev;

-   if (IS_ENABLED(CONFIG_RMI4_DEBUG) && rmi_dev->debugfs_root)
+#ifdef CONFIG_RMI4_DEBUG
+   if (rmi_dev->debugfs_root)
debugfs_remove(rmi_dev->debugfs_root);
+#endif

-   kfree(rmi_dev);
+   device_unregister(_dev->dev);
 }
-EXPORT_SYMBOL(rmi_unregister_phys_device);
+EXPORT_SYMBOL_GPL(rmi_unregister_phys_device);

-/**
- * rmi_register_function_handler - register a handler for an RMI function
- * @handler: RMI handler that should be registered.
- * @module: pointer to module that implements the handler
- * @mod_name: name of the module implementing the handler
- *
- * This function performs additional setup of RMI function handler and
- * registers it with the RMI core so that it can be bound to
- * RMI function devices.
- */
-int __rmi_register_function_handler(struct rmi_function_handler *handler,
-struct module *owner,
-const char *mod_name)
+static int rmi_bus_match(struct device *dev, struct device_driver *drv)
 {
-   int error;
+   struct rmi_function_driver *fn_drv;
+   struct rmi_function_dev *fn;

-   handler->driver.bus = _bus_type;
-   handler->driver.owner = owner;
-   handler->driver.mod_name = mod_name;
+   /*
+* This seems a little broken to me.  It  means a system can only ever
+* have one kind of sensor driver.  It'll work for now, but I think in
+* the long run we need to revisit this.
+*/
+   if (dev->type == _sensor_type && drv == _sensor_driver.driver)
+   return 1;

-   error = driver_register(>driver);
-   if (error) {
-

[PATCH 02/05] input: Core files

2012-12-18 Thread Christopher Heiny
In addition to the changes described in 0/0 of this patch set, these files
are updated as follows:

* initialization sequence rearranged to support the merging of rmi_f01 and
rmi_driver into the RMI4 core.

* the initial reset and firmware update PDT scans are split into their own
functions in order to account for the fact that the PDT may change after
the initial reset.

* Problems with release_rmidev_device() identified by Greg KH are fixed and
tested.

* EXPORT_SYMBOL() changed to EXPORT_SYMBOL_GPL(), per Greg KH input.

Signed-off-by: Christopher Heiny che...@synaptics.com
Cc: Greg Kroah-Hartman gre...@linuxfoundation.org
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_bus.c|  232 ---
 drivers/input/rmi4/rmi_driver.c |  655 ---
 drivers/input/rmi4/rmi_driver.h |   32 +--
 3 files changed, 468 insertions(+), 451 deletions(-)

diff --git a/drivers/input/rmi4/rmi_bus.c b/drivers/input/rmi4/rmi_bus.c
index acbfd3d..71bc201 100644
--- a/drivers/input/rmi4/rmi_bus.c
+++ b/drivers/input/rmi4/rmi_bus.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
@@ -75,7 +65,8 @@ static struct dentry *rmi_debugfs_root;

 static void release_rmidev_device(struct device *dev)
 {
-   device_unregister(dev);
+   struct rmi_device *rmi_dev = to_rmi_device(dev);
+   kfree(rmi_dev);
 }

 /**
@@ -110,17 +101,19 @@ int rmi_register_phys_device(struct rmi_phys_device *phys)
dev_dbg(phys-dev, %s: Registered %s as %s.\n, __func__,
pdata-sensor_name, dev_name(rmi_dev-dev));

-   if (IS_ENABLED(CONFIG_RMI4_DEBUG)  rmi_debugfs_root) {
+#ifdef CONFIG_RMI4_DEBUG
+   if (rmi_debugfs_root) {
rmi_dev-debugfs_root = debugfs_create_dir(
dev_name(rmi_dev-dev), rmi_debugfs_root);
if (!rmi_dev-debugfs_root)
dev_err(rmi_dev-dev, Failed to create debugfs 
root.\n);
}
+#endif

phys-rmi_dev = rmi_dev;
return device_register(rmi_dev-dev);
 }
-EXPORT_SYMBOL(rmi_register_phys_device);
+EXPORT_SYMBOL_GPL(rmi_register_phys_device);

 /**
  * rmi_unregister_phys_device - unregister a physical device connection
@@ -131,102 +124,84 @@ void rmi_unregister_phys_device(struct rmi_phys_device 
*phys)
 {
struct rmi_device *rmi_dev = phys-rmi_dev;

-   if (IS_ENABLED(CONFIG_RMI4_DEBUG)  rmi_dev-debugfs_root)
+#ifdef CONFIG_RMI4_DEBUG
+   if (rmi_dev-debugfs_root)
debugfs_remove(rmi_dev-debugfs_root);
+#endif

-   kfree(rmi_dev);
+   device_unregister(rmi_dev-dev);
 }
-EXPORT_SYMBOL(rmi_unregister_phys_device);
+EXPORT_SYMBOL_GPL(rmi_unregister_phys_device);

-/**
- * rmi_register_function_handler - register a handler for an RMI function
- * @handler: RMI handler that should be registered.
- * @module: pointer to module that implements the handler
- * @mod_name: name of the module implementing the handler
- *
- * This function performs additional setup of RMI function handler and
- * registers it with the RMI core so that it can be bound to
- * RMI function devices.
- */
-int __rmi_register_function_handler(struct rmi_function_handler *handler,
-struct module *owner,
-const char *mod_name)
+static int rmi_bus_match(struct device *dev, struct device_driver *drv)
 {
-   int error;
+   struct rmi_function_driver *fn_drv;
+   struct rmi_function_dev *fn;

-   handler-driver.bus = rmi_bus_type;
-   handler-driver.owner = owner;
-   handler-driver.mod_name = mod_name;
+   /*
+* This seems a little broken to me.  It  means a system can only ever
+* have one kind of sensor driver.  It'll work for now, but I think in
+* the long run we need to revisit this.
+*/
+   if (dev-type ==