* [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver
@ 2012-04-16 11:37 Paul Parsons
2012-04-16 20:16 ` Philipp Zabel
2012-05-09 8:00 ` Dmitry Torokhov
0 siblings, 2 replies; 6+ messages in thread
From: Paul Parsons @ 2012-04-16 11:37 UTC (permalink / raw)
To: dmitry.torokhov; +Cc: philipp.zabel, linux-input
This driver adds support for the Synaptics NavPoint touchpad connected
to a PXA27x SSP port in SPI slave mode. The device emulates a mouse;
a tap or tap-and-a-half drag gesture emulates the left mouse button.
For example, use the xf86-input-evdev driver for an X pointing device.
Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
Cc: Philipp Zabel <philipp.zabel@gmail.com>
---
V8:
Converted from navigation pad (EV_KEY) driver to mouse (EV_ABS) driver.
Removed threaded irq handler.
Added up()/down(), called from open()/close() and resume()/suspend().
Use SIMPLE_DEV_PM_OPS().
Use dev_dbg() instead of dev_info().
Use module_platform_driver().
Added MODULE_ALIAS().
Added check for absent platform data.
Use gpio_request_one() instead of gpio_request()/gpio_direction_output()
drivers/input/mouse/Kconfig | 12 ++
drivers/input/mouse/Makefile | 1 +
drivers/input/mouse/navpoint.c | 380 ++++++++++++++++++++++++++++++++++++++++
include/linux/input/navpoint.h | 12 ++
4 files changed, 405 insertions(+), 0 deletions(-)
create mode 100644 drivers/input/mouse/navpoint.c
create mode 100644 include/linux/input/navpoint.h
diff --git a/drivers/input/mouse/Kconfig b/drivers/input/mouse/Kconfig
index 9b8db82..cd6268c 100644
--- a/drivers/input/mouse/Kconfig
+++ b/drivers/input/mouse/Kconfig
@@ -339,4 +339,16 @@ config MOUSE_SYNAPTICS_USB
To compile this driver as a module, choose M here: the
module will be called synaptics_usb.
+config MOUSE_NAVPOINT_PXA27x
+ tristate "Synaptics NavPoint (PXA27x SSP/SPI)"
+ depends on PXA27x && PXA_SSP
+ help
+ This driver adds support for the Synaptics NavPoint touchpad connected
+ to a PXA27x SSP port in SPI slave mode. The device emulates a mouse;
+ a tap or tap-and-a-half drag gesture emulates the left mouse button.
+ For example, use the xf86-input-evdev driver for an X pointing device.
+
+ To compile this driver as a module, choose M here: the
+ module will be called navpoint.
+
endif
diff --git a/drivers/input/mouse/Makefile b/drivers/input/mouse/Makefile
index 4718eff..46ba755 100644
--- a/drivers/input/mouse/Makefile
+++ b/drivers/input/mouse/Makefile
@@ -12,6 +12,7 @@ obj-$(CONFIG_MOUSE_GPIO) += gpio_mouse.o
obj-$(CONFIG_MOUSE_INPORT) += inport.o
obj-$(CONFIG_MOUSE_LOGIBM) += logibm.o
obj-$(CONFIG_MOUSE_MAPLE) += maplemouse.o
+obj-$(CONFIG_MOUSE_NAVPOINT_PXA27x) += navpoint.o
obj-$(CONFIG_MOUSE_PC110PAD) += pc110pad.o
obj-$(CONFIG_MOUSE_PS2) += psmouse.o
obj-$(CONFIG_MOUSE_PXA930_TRKBALL) += pxa930_trkball.o
diff --git a/drivers/input/mouse/navpoint.c b/drivers/input/mouse/navpoint.c
new file mode 100644
index 0000000..7d5db52
--- /dev/null
+++ b/drivers/input/mouse/navpoint.c
@@ -0,0 +1,380 @@
+/*
+ * Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
+ *
+ * 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>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/clk.h>
+#include <linux/delay.h>
+#include <linux/gpio.h>
+#include <linux/input.h>
+#include <linux/input/navpoint.h>
+#include <linux/interrupt.h>
+#include <linux/mutex.h>
+#include <linux/pxa2xx_ssp.h>
+#include <linux/slab.h>
+
+/*
+ * Synaptics NavPoint (PXA27x SSP/SPI) driver.
+ */
+
+/*
+ * Synaptics Modular Embedded Protocol: Module Packet Format.
+ * Module header byte 2:0 = Length (# bytes that follow)
+ * Module header byte 4:3 = Control
+ * Module header byte 7:5 = Module Address
+ */
+#define HEADER_LENGTH(byte) ((byte) & 0x07)
+#define HEADER_CONTROL(byte) (((byte) >> 3) & 0x03)
+#define HEADER_ADDRESS(byte) ((byte) >> 5)
+
+struct driver_data {
+ struct mutex mutex;
+ int opened;
+ struct ssp_device *ssp;
+ int gpio;
+ struct input_dev *input;
+ int index;
+ uint8_t data[1+HEADER_LENGTH(0xff)];
+};
+
+/*
+ * Initialization values for SSCR0_x, SSCR1_x, SSSR_x.
+ */
+static const u32 sscr0 = 0
+ | SSCR0_TUM /* TIM = 1; No TUR interrupts */
+ | SSCR0_RIM /* RIM = 1; No ROR interrupts */
+ | SSCR0_SSE /* SSE = 1; SSP enabled */
+ | SSCR0_Motorola /* FRF = 0; Motorola SPI */
+ | SSCR0_DataSize(16) /* DSS = 15; Data size = 16-bit */
+ ;
+static const u32 sscr1 = 0
+ | SSCR1_SCFR /* SCFR = 1; SSPSCLK only during transfers */
+ | SSCR1_SCLKDIR /* SCLKDIR = 1; Slave mode */
+ | SSCR1_SFRMDIR /* SFRMDIR = 1; Slave mode */
+ | SSCR1_RWOT /* RWOT = 1; Receive without transmit mode */
+ | SSCR1_RxTresh(1) /* RFT = 0; Receive FIFO threshold = 1 */
+ | SSCR1_SPH /* SPH = 1; SSPSCLK inactive 0.5 + 1 cycles */
+ | SSCR1_RIE /* RIE = 1; Receive FIFO interrupt enabled */
+ ;
+static const u32 sssr = 0
+ | SSSR_BCE /* BCE = 1; Clear BCE */
+ | SSSR_TUR /* TUR = 1; Clear TUR */
+ | SSSR_EOC /* EOC = 1; Clear EOC */
+ | SSSR_TINT /* TINT = 1; Clear TINT */
+ | SSSR_PINT /* PINT = 1; Clear PINT */
+ | SSSR_ROR /* ROR = 1; Clear ROR */
+ ;
+
+/*
+ * MEP Query $22: Touchpad Coordinate Range Query is not supported by
+ * the NavPoint module, so sampled values provide the default limits.
+ */
+static int xmin = 1278;
+module_param(xmin, int, 0644);
+MODULE_PARM_DESC(xmin, "Minimum X coordinate. Default = 1278");
+static int xmax = 5340;
+module_param(xmax, int, 0644);
+MODULE_PARM_DESC(xmax, "Maximum X coordinate. Default = 5340");
+static int ymin = 1572;
+module_param(ymin, int, 0644);
+MODULE_PARM_DESC(ymin, "Minimum Y coordinate. Default = 1572");
+static int ymax = 4396;
+module_param(ymax, int, 0644);
+MODULE_PARM_DESC(ymax, "Maximum Y coordinate. Default = 4396");
+static int pmin = 0;
+module_param(pmin, int, 0644);
+MODULE_PARM_DESC(pmin, "Minimum pressure. Default = 0");
+static int pmax = 255;
+module_param(pmax, int, 0644);
+MODULE_PARM_DESC(pmax, "Maximum pressure. Default = 255");
+
+static void navpoint_packet(struct device *dev)
+{
+ struct driver_data *drv_data = dev_get_drvdata(dev);
+ int finger;
+ int gesture;
+ int x, y, z;
+
+ switch (drv_data->data[0]) {
+ case 0xff: /* Garbage (packet?) between reset and Hello packet */
+ case 0x00: /* Module 0, NULL packet */
+ break;
+ case 0x0e: /* Module 0, Absolute packet */
+ finger = (drv_data->data[1] & 0x01);
+ gesture = (drv_data->data[1] & 0x02);
+ x = ((drv_data->data[2] & 0x1f) << 8) | drv_data->data[3];
+ y = ((drv_data->data[4] & 0x1f) << 8) | drv_data->data[5];
+ z = drv_data->data[6];
+ input_report_key(drv_data->input, BTN_TOUCH, finger);
+ input_report_abs(drv_data->input, ABS_X, x);
+ input_report_abs(drv_data->input, ABS_Y, y);
+ input_report_abs(drv_data->input, ABS_PRESSURE, z);
+ input_report_key(drv_data->input, BTN_TOOL_FINGER, finger);
+ input_report_key(drv_data->input, BTN_LEFT, gesture);
+ input_sync(drv_data->input);
+ break;
+ case 0x19: /* Module 0, Hello packet */
+ if ((drv_data->data[1] & 0xf0) == 0x10)
+ break;
+ /* FALLTHROUGH */
+ default:
+ dev_warn(dev, "spurious packet: data=0x%02x,0x%02x,...\n",
+ drv_data->data[0],
+ drv_data->data[1]);
+ break;
+ }
+}
+
+static irqreturn_t navpoint_int(int irq, void *dev_id)
+{
+ struct device *dev = dev_id;
+ struct driver_data *drv_data = dev_get_drvdata(dev);
+ struct ssp_device *ssp = drv_data->ssp;
+ u32 status;
+ irqreturn_t ret;
+
+ status = pxa_ssp_read_reg(ssp, SSSR);
+ ret = IRQ_NONE;
+
+ if (status & sssr) {
+ dev_warn(dev, "unexpected interrupt: status=0x%08x\n", status);
+ pxa_ssp_write_reg(ssp, SSSR, (status & sssr));
+ ret = IRQ_HANDLED;
+ }
+
+ while (status & SSSR_RNE) {
+ u32 data;
+
+ data = pxa_ssp_read_reg(ssp, SSDR);
+ drv_data->data[drv_data->index + 0] = (data >> 8);
+ drv_data->data[drv_data->index + 1] = data;
+ drv_data->index += 2;
+ if (HEADER_LENGTH(drv_data->data[0]) < drv_data->index) {
+ navpoint_packet(dev);
+ drv_data->index = 0;
+ }
+ status = pxa_ssp_read_reg(ssp, SSSR);
+ ret = IRQ_HANDLED;
+ }
+
+ return ret;
+}
+
+static void navpoint_up(struct device *dev)
+{
+ struct driver_data *drv_data = dev_get_drvdata(dev);
+ struct ssp_device *ssp = drv_data->ssp;
+ int timeout;
+
+ clk_prepare_enable(ssp->clk);
+
+ pxa_ssp_write_reg(ssp, SSCR1, sscr1);
+ pxa_ssp_write_reg(ssp, SSSR, sssr);
+ pxa_ssp_write_reg(ssp, SSTO, 0);
+ pxa_ssp_write_reg(ssp, SSCR0, sscr0); /* SSCR0_SSE written last */
+
+ /* Wait until SSP port is ready for slave clock operations */
+ for (timeout = 100; timeout != 0; --timeout) {
+ if (!(pxa_ssp_read_reg(ssp, SSSR) & SSSR_CSS))
+ break;
+ msleep(1);
+ }
+ if (timeout == 0)
+ dev_err(dev, "timeout waiting for SSSR[CSS] to clear\n");
+
+ if (gpio_is_valid(drv_data->gpio))
+ gpio_set_value(drv_data->gpio, 1);
+}
+
+static void navpoint_down(struct device *dev)
+{
+ struct driver_data *drv_data = dev_get_drvdata(dev);
+ struct ssp_device *ssp = drv_data->ssp;
+
+ if (gpio_is_valid(drv_data->gpio))
+ gpio_set_value(drv_data->gpio, 0);
+
+ pxa_ssp_write_reg(ssp, SSCR0, 0);
+
+ clk_disable_unprepare(ssp->clk);
+}
+
+static int navpoint_open(struct input_dev *input)
+{
+ struct driver_data *drv_data = dev_get_drvdata(input->dev.parent);
+
+ mutex_lock(&drv_data->mutex);
+ navpoint_up(input->dev.parent);
+ drv_data->opened = 1;
+ mutex_unlock(&drv_data->mutex);
+ return 0;
+}
+
+static void navpoint_close(struct input_dev *input)
+{
+ struct driver_data *drv_data = dev_get_drvdata(input->dev.parent);
+
+ mutex_lock(&drv_data->mutex);
+ navpoint_down(input->dev.parent);
+ drv_data->opened = 0;
+ mutex_unlock(&drv_data->mutex);
+}
+
+static int __devinit navpoint_probe(struct platform_device *pdev)
+{
+ struct navpoint_platform_data *pdata = pdev->dev.platform_data;
+ int ret;
+ struct ssp_device *ssp;
+ struct input_dev *input;
+ struct driver_data *drv_data;
+
+ if (!pdata) {
+ dev_err(&pdev->dev, "no platform data\n");
+ return -EINVAL;
+ }
+
+ if (gpio_is_valid(pdata->gpio)) {
+ ret = gpio_request_one(pdata->gpio, GPIOF_OUT_INIT_LOW,
+ "SYNAPTICS_ON");
+ if (ret)
+ return ret;
+ }
+
+ ssp = pxa_ssp_request(pdata->port, pdev->name);
+ if (!ssp) {
+ ret = -ENODEV;
+ goto ret1;
+ }
+
+ /* HaRET does not disable devices before jumping into Linux */
+ if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
+ pxa_ssp_write_reg(ssp, SSCR0, 0);
+ dev_warn(&pdev->dev, "ssp%d already enabled\n", pdata->port);
+ }
+
+ input = input_allocate_device();
+ if (!input) {
+ ret = -ENOMEM;
+ goto ret2;
+ }
+ input->name = pdev->name;
+ __set_bit(EV_KEY, input->evbit);
+ __set_bit(EV_ABS, input->evbit);
+ __set_bit(BTN_TOUCH, input->keybit);
+ input_set_abs_params(input, ABS_X, xmin, xmax, 0, 0);
+ input_set_abs_params(input, ABS_Y, ymin, ymax, 0, 0);
+ input_set_abs_params(input, ABS_PRESSURE, pmin, pmax, 0, 0);
+ __set_bit(BTN_TOOL_FINGER, input->keybit);
+ __set_bit(BTN_LEFT, input->keybit);
+ input->open = navpoint_open;
+ input->close = navpoint_close;
+ input->dev.parent = &pdev->dev;
+
+ drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
+ if (!drv_data) {
+ ret = -ENOMEM;
+ goto ret3;
+ }
+ mutex_init(&drv_data->mutex);
+ drv_data->ssp = ssp;
+ drv_data->gpio = pdata->gpio;
+ drv_data->input = input;
+ platform_set_drvdata(pdev, drv_data);
+
+ ret = request_irq(ssp->irq, navpoint_int, 0, pdev->name, &pdev->dev);
+ if (ret)
+ goto ret4;
+
+ ret = input_register_device(input);
+ if (ret)
+ goto ret5;
+
+ dev_dbg(&pdev->dev, "ssp%d, irq %d\n", pdata->port, ssp->irq);
+
+ return 0;
+
+ret5:
+ free_irq(ssp->irq, &pdev->dev);
+ret4:
+ kfree(drv_data);
+ret3:
+ input_free_device(input);
+ret2:
+ pxa_ssp_free(ssp);
+ret1:
+ if (gpio_is_valid(pdata->gpio))
+ gpio_free(pdata->gpio);
+
+ return ret;
+}
+
+static int __devexit navpoint_remove(struct platform_device *pdev)
+{
+ struct driver_data *drv_data = platform_get_drvdata(pdev);
+ struct input_dev *input = drv_data->input;
+ struct ssp_device *ssp = drv_data->ssp;
+ struct navpoint_platform_data *pdata = pdev->dev.platform_data;
+
+ input_unregister_device(input);
+
+ free_irq(ssp->irq, &pdev->dev);
+
+ kfree(drv_data);
+
+ pxa_ssp_free(ssp);
+
+ if (gpio_is_valid(pdata->gpio))
+ gpio_free(pdata->gpio);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM_SLEEP
+static int navpoint_suspend(struct device *dev)
+{
+ struct driver_data *drv_data = dev_get_drvdata(dev);
+
+ mutex_lock(&drv_data->mutex);
+ if (drv_data->opened)
+ navpoint_down(dev);
+ mutex_unlock(&drv_data->mutex);
+ return 0;
+}
+
+static int navpoint_resume(struct device *dev)
+{
+ struct driver_data *drv_data = dev_get_drvdata(dev);
+
+ mutex_lock(&drv_data->mutex);
+ if (drv_data->opened)
+ navpoint_up(dev);
+ mutex_unlock(&drv_data->mutex);
+ return 0;
+}
+#endif
+
+static SIMPLE_DEV_PM_OPS(navpoint_pm_ops, navpoint_suspend, navpoint_resume);
+
+static struct platform_driver navpoint_driver = {
+ .probe = navpoint_probe,
+ .remove = __devexit_p(navpoint_remove),
+ .driver = {
+ .name = "navpoint",
+ .owner = THIS_MODULE,
+ .pm = &navpoint_pm_ops,
+ },
+};
+
+module_platform_driver(navpoint_driver);
+
+MODULE_AUTHOR("Paul Parsons <lost.distance@yahoo.com>");
+MODULE_DESCRIPTION("Synaptics NavPoint (PXA27x SSP/SPI) driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:navpoint");
diff --git a/include/linux/input/navpoint.h b/include/linux/input/navpoint.h
new file mode 100644
index 0000000..45050eb
--- /dev/null
+++ b/include/linux/input/navpoint.h
@@ -0,0 +1,12 @@
+/*
+ * Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
+ *
+ * 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.
+ */
+
+struct navpoint_platform_data {
+ int port; /* PXA SSP port for pxa_ssp_request() */
+ int gpio; /* GPIO for power on/off */
+};
--
1.7.3.4
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver
2012-04-16 11:37 [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver Paul Parsons
@ 2012-04-16 20:16 ` Philipp Zabel
2012-05-09 8:00 ` Dmitry Torokhov
1 sibling, 0 replies; 6+ messages in thread
From: Philipp Zabel @ 2012-04-16 20:16 UTC (permalink / raw)
To: Paul Parsons; +Cc: dmitry.torokhov, linux-input
Am Montag, den 16.04.2012, 12:37 +0100 schrieb Paul Parsons:
> This driver adds support for the Synaptics NavPoint touchpad connected
> to a PXA27x SSP port in SPI slave mode. The device emulates a mouse;
> a tap or tap-and-a-half drag gesture emulates the left mouse button.
> For example, use the xf86-input-evdev driver for an X pointing device.
>
> Signed-off-by: Paul Parsons <lost.distance@yahoo.com>
> Cc: Philipp Zabel <philipp.zabel@gmail.com>
Tested-by: Philipp Zabel <philipp.zabel@gmail.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver
2012-04-16 11:37 [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver Paul Parsons
2012-04-16 20:16 ` Philipp Zabel
@ 2012-05-09 8:00 ` Dmitry Torokhov
2012-05-09 21:09 ` Paul Parsons
1 sibling, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2012-05-09 8:00 UTC (permalink / raw)
To: Paul Parsons; +Cc: philipp.zabel, linux-input
Hi Paul,
On Mon, Apr 16, 2012 at 12:37:01PM +0100, Paul Parsons wrote:
> This driver adds support for the Synaptics NavPoint touchpad connected
> to a PXA27x SSP port in SPI slave mode. The device emulates a mouse;
> a tap or tap-and-a-half drag gesture emulates the left mouse button.
> For example, use the xf86-input-evdev driver for an X pointing device.
>
The driver looks excellent now, I have just a few nits:
- you do not need separate mutex and counter; it is perfectly fine to
use input device's ones;
- we don't really need min/max for coordinates: the defaults are good
for your device and if more devices come with different limits one
could adjust limits via EVIOCSABS ioctls.
I also took libertu if rearranging the code a bit so it flows more like
the rest of the input drivers. Could you please tell me if the patch
below breaks your device or if it still works?
Thanks!
--
Dmitry
Input: navpoint - misc changes
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---
drivers/input/mouse/navpoint.c | 291 +++++++++++++++++++---------------------
1 files changed, 140 insertions(+), 151 deletions(-)
diff --git a/drivers/input/mouse/navpoint.c b/drivers/input/mouse/navpoint.c
index 7d5db52..c29ae76 100644
--- a/drivers/input/mouse/navpoint.c
+++ b/drivers/input/mouse/navpoint.c
@@ -1,9 +1,11 @@
/*
- * Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
+ * Synaptics NavPoint (PXA27x SSP/SPI) driver.
*
- * 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.
+ * Copyright (C) 2012 Paul Parsons <lost.distance@yahoo.com>
+ *
+ * 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>
@@ -21,31 +23,26 @@
#include <linux/slab.h>
/*
- * Synaptics NavPoint (PXA27x SSP/SPI) driver.
- */
-
-/*
- * Synaptics Modular Embedded Protocol: Module Packet Format.
- * Module header byte 2:0 = Length (# bytes that follow)
- * Module header byte 4:3 = Control
- * Module header byte 7:5 = Module Address
+ * Synaptics Modular Embedded Protocol: Module Packet Format.
+ * Module header byte 2:0 = Length (# bytes that follow)
+ * Module header byte 4:3 = Control
+ * Module header byte 7:5 = Module Address
*/
#define HEADER_LENGTH(byte) ((byte) & 0x07)
#define HEADER_CONTROL(byte) (((byte) >> 3) & 0x03)
#define HEADER_ADDRESS(byte) ((byte) >> 5)
-struct driver_data {
- struct mutex mutex;
- int opened;
+struct navpoint {
struct ssp_device *ssp;
- int gpio;
struct input_dev *input;
+ struct device *dev;
+ int gpio;
int index;
- uint8_t data[1+HEADER_LENGTH(0xff)];
+ u8 data[1 + HEADER_LENGTH(0xff)];
};
/*
- * Initialization values for SSCR0_x, SSCR1_x, SSSR_x.
+ * Initialization values for SSCR0_x, SSCR1_x, SSSR_x.
*/
static const u32 sscr0 = 0
| SSCR0_TUM /* TIM = 1; No TUR interrupts */
@@ -73,78 +70,65 @@ static const u32 sssr = 0
;
/*
- * MEP Query $22: Touchpad Coordinate Range Query is not supported by
- * the NavPoint module, so sampled values provide the default limits.
+ * MEP Query $22: Touchpad Coordinate Range Query is not supported by
+ * the NavPoint module, so sampled values provide the default limits.
*/
-static int xmin = 1278;
-module_param(xmin, int, 0644);
-MODULE_PARM_DESC(xmin, "Minimum X coordinate. Default = 1278");
-static int xmax = 5340;
-module_param(xmax, int, 0644);
-MODULE_PARM_DESC(xmax, "Maximum X coordinate. Default = 5340");
-static int ymin = 1572;
-module_param(ymin, int, 0644);
-MODULE_PARM_DESC(ymin, "Minimum Y coordinate. Default = 1572");
-static int ymax = 4396;
-module_param(ymax, int, 0644);
-MODULE_PARM_DESC(ymax, "Maximum Y coordinate. Default = 4396");
-static int pmin = 0;
-module_param(pmin, int, 0644);
-MODULE_PARM_DESC(pmin, "Minimum pressure. Default = 0");
-static int pmax = 255;
-module_param(pmax, int, 0644);
-MODULE_PARM_DESC(pmax, "Maximum pressure. Default = 255");
-
-static void navpoint_packet(struct device *dev)
+#define NAVPOINT_X_MIN 1278
+#define NAVPOINT_X_MAX 5340
+#define NAVPOINT_Y_MIN 1572
+#define NAVPOINT_Y_MAX 4396
+#define NAVPOINT_PRESSURE_MIN 0
+#define NAVPOINT_PRESSURE_MAX 255
+
+static void navpoint_packet(struct navpoint *navpoint)
{
- struct driver_data *drv_data = dev_get_drvdata(dev);
int finger;
int gesture;
int x, y, z;
- switch (drv_data->data[0]) {
+ switch (navpoint->data[0]) {
case 0xff: /* Garbage (packet?) between reset and Hello packet */
case 0x00: /* Module 0, NULL packet */
break;
+
case 0x0e: /* Module 0, Absolute packet */
- finger = (drv_data->data[1] & 0x01);
- gesture = (drv_data->data[1] & 0x02);
- x = ((drv_data->data[2] & 0x1f) << 8) | drv_data->data[3];
- y = ((drv_data->data[4] & 0x1f) << 8) | drv_data->data[5];
- z = drv_data->data[6];
- input_report_key(drv_data->input, BTN_TOUCH, finger);
- input_report_abs(drv_data->input, ABS_X, x);
- input_report_abs(drv_data->input, ABS_Y, y);
- input_report_abs(drv_data->input, ABS_PRESSURE, z);
- input_report_key(drv_data->input, BTN_TOOL_FINGER, finger);
- input_report_key(drv_data->input, BTN_LEFT, gesture);
- input_sync(drv_data->input);
+ finger = (navpoint->data[1] & 0x01);
+ gesture = (navpoint->data[1] & 0x02);
+ x = ((navpoint->data[2] & 0x1f) << 8) | navpoint->data[3];
+ y = ((navpoint->data[4] & 0x1f) << 8) | navpoint->data[5];
+ z = navpoint->data[6];
+ input_report_key(navpoint->input, BTN_TOUCH, finger);
+ input_report_abs(navpoint->input, ABS_X, x);
+ input_report_abs(navpoint->input, ABS_Y, y);
+ input_report_abs(navpoint->input, ABS_PRESSURE, z);
+ input_report_key(navpoint->input, BTN_TOOL_FINGER, finger);
+ input_report_key(navpoint->input, BTN_LEFT, gesture);
+ input_sync(navpoint->input);
break;
+
case 0x19: /* Module 0, Hello packet */
- if ((drv_data->data[1] & 0xf0) == 0x10)
+ if ((navpoint->data[1] & 0xf0) == 0x10)
break;
/* FALLTHROUGH */
default:
- dev_warn(dev, "spurious packet: data=0x%02x,0x%02x,...\n",
- drv_data->data[0],
- drv_data->data[1]);
+ dev_warn(navpoint->dev,
+ "spurious packet: data=0x%02x,0x%02x,...\n",
+ navpoint->data[0], navpoint->data[1]);
break;
}
}
-static irqreturn_t navpoint_int(int irq, void *dev_id)
+static irqreturn_t navpoint_irq(int irq, void *dev_id)
{
- struct device *dev = dev_id;
- struct driver_data *drv_data = dev_get_drvdata(dev);
- struct ssp_device *ssp = drv_data->ssp;
+ struct navpoint *navpoint = dev_id;
+ struct ssp_device *ssp = navpoint->ssp;
+ irqreturn_t ret = IRQ_NONE;
u32 status;
- irqreturn_t ret;
status = pxa_ssp_read_reg(ssp, SSSR);
- ret = IRQ_NONE;
-
if (status & sssr) {
- dev_warn(dev, "unexpected interrupt: status=0x%08x\n", status);
+ dev_warn(navpoint->dev,
+ "unexpected interrupt: status=0x%08x\n", status);
pxa_ssp_write_reg(ssp, SSSR, (status & sssr));
ret = IRQ_HANDLED;
}
@@ -153,12 +137,12 @@ static irqreturn_t navpoint_int(int irq, void *dev_id)
u32 data;
data = pxa_ssp_read_reg(ssp, SSDR);
- drv_data->data[drv_data->index + 0] = (data >> 8);
- drv_data->data[drv_data->index + 1] = data;
- drv_data->index += 2;
- if (HEADER_LENGTH(drv_data->data[0]) < drv_data->index) {
- navpoint_packet(dev);
- drv_data->index = 0;
+ navpoint->data[navpoint->index + 0] = (data >> 8);
+ navpoint->data[navpoint->index + 1] = data;
+ navpoint->index += 2;
+ if (HEADER_LENGTH(navpoint->data[0]) < navpoint->index) {
+ navpoint_packet(navpoint);
+ navpoint->index = 0;
}
status = pxa_ssp_read_reg(ssp, SSSR);
ret = IRQ_HANDLED;
@@ -167,10 +151,9 @@ static irqreturn_t navpoint_int(int irq, void *dev_id)
return ret;
}
-static void navpoint_up(struct device *dev)
+static void navpoint_up(struct navpoint *navpoint)
{
- struct driver_data *drv_data = dev_get_drvdata(dev);
- struct ssp_device *ssp = drv_data->ssp;
+ struct ssp_device *ssp = navpoint->ssp;
int timeout;
clk_prepare_enable(ssp->clk);
@@ -186,20 +169,21 @@ static void navpoint_up(struct device *dev)
break;
msleep(1);
}
+
if (timeout == 0)
- dev_err(dev, "timeout waiting for SSSR[CSS] to clear\n");
+ dev_err(navpoint->dev,
+ "timeout waiting for SSSR[CSS] to clear\n");
- if (gpio_is_valid(drv_data->gpio))
- gpio_set_value(drv_data->gpio, 1);
+ if (gpio_is_valid(navpoint->gpio))
+ gpio_set_value(navpoint->gpio, 1);
}
-static void navpoint_down(struct device *dev)
+static void navpoint_down(struct navpoint *navpoint)
{
- struct driver_data *drv_data = dev_get_drvdata(dev);
- struct ssp_device *ssp = drv_data->ssp;
+ struct ssp_device *ssp = navpoint->ssp;
- if (gpio_is_valid(drv_data->gpio))
- gpio_set_value(drv_data->gpio, 0);
+ if (gpio_is_valid(navpoint->gpio))
+ gpio_set_value(navpoint->gpio, 0);
pxa_ssp_write_reg(ssp, SSCR0, 0);
@@ -208,32 +192,28 @@ static void navpoint_down(struct device *dev)
static int navpoint_open(struct input_dev *input)
{
- struct driver_data *drv_data = dev_get_drvdata(input->dev.parent);
+ struct navpoint *navpoint = input_get_drvdata(input);
+
+ navpoint_up(navpoint);
- mutex_lock(&drv_data->mutex);
- navpoint_up(input->dev.parent);
- drv_data->opened = 1;
- mutex_unlock(&drv_data->mutex);
return 0;
}
static void navpoint_close(struct input_dev *input)
{
- struct driver_data *drv_data = dev_get_drvdata(input->dev.parent);
+ struct navpoint *navpoint = input_get_drvdata(input);
- mutex_lock(&drv_data->mutex);
- navpoint_down(input->dev.parent);
- drv_data->opened = 0;
- mutex_unlock(&drv_data->mutex);
+ navpoint_down(navpoint);
}
static int __devinit navpoint_probe(struct platform_device *pdev)
{
- struct navpoint_platform_data *pdata = pdev->dev.platform_data;
- int ret;
+ const struct navpoint_platform_data *pdata =
+ dev_get_platdata(&pdev->dev);
struct ssp_device *ssp;
struct input_dev *input;
- struct driver_data *drv_data;
+ struct navpoint *navpoint;
+ int error;
if (!pdata) {
dev_err(&pdev->dev, "no platform data\n");
@@ -241,16 +221,16 @@ static int __devinit navpoint_probe(struct platform_device *pdev)
}
if (gpio_is_valid(pdata->gpio)) {
- ret = gpio_request_one(pdata->gpio, GPIOF_OUT_INIT_LOW,
- "SYNAPTICS_ON");
- if (ret)
- return ret;
+ error = gpio_request_one(pdata->gpio, GPIOF_OUT_INIT_LOW,
+ "SYNAPTICS_ON");
+ if (error)
+ return error;
}
ssp = pxa_ssp_request(pdata->port, pdev->name);
if (!ssp) {
- ret = -ENODEV;
- goto ret1;
+ error = -ENODEV;
+ goto err_free_gpio;
}
/* HaRET does not disable devices before jumping into Linux */
@@ -259,74 +239,77 @@ static int __devinit navpoint_probe(struct platform_device *pdev)
dev_warn(&pdev->dev, "ssp%d already enabled\n", pdata->port);
}
+ navpoint = kzalloc(sizeof(*navpoint), GFP_KERNEL);
input = input_allocate_device();
- if (!input) {
- ret = -ENOMEM;
- goto ret2;
+ if (!navpoint || !input) {
+ error = -ENOMEM;
+ goto err_free_mem;
}
+
+ navpoint->ssp = ssp;
+ navpoint->input = input;
+ navpoint->dev = &pdev->dev;
+ navpoint->gpio = pdata->gpio;
+
input->name = pdev->name;
+ input->dev.parent = &pdev->dev;
+
__set_bit(EV_KEY, input->evbit);
__set_bit(EV_ABS, input->evbit);
+ __set_bit(BTN_LEFT, input->keybit);
__set_bit(BTN_TOUCH, input->keybit);
- input_set_abs_params(input, ABS_X, xmin, xmax, 0, 0);
- input_set_abs_params(input, ABS_Y, ymin, ymax, 0, 0);
- input_set_abs_params(input, ABS_PRESSURE, pmin, pmax, 0, 0);
__set_bit(BTN_TOOL_FINGER, input->keybit);
- __set_bit(BTN_LEFT, input->keybit);
+
+ input_set_abs_params(input, ABS_X,
+ NAVPOINT_X_MIN, NAVPOINT_X_MAX, 0, 0);
+ input_set_abs_params(input, ABS_Y,
+ NAVPOINT_Y_MIN, NAVPOINT_Y_MAX, 0, 0);
+ input_set_abs_params(input, ABS_PRESSURE,
+ NAVPOINT_PRESSURE_MIN, NAVPOINT_PRESSURE_MAX,
+ 0, 0);
+
input->open = navpoint_open;
input->close = navpoint_close;
- input->dev.parent = &pdev->dev;
- drv_data = kzalloc(sizeof(*drv_data), GFP_KERNEL);
- if (!drv_data) {
- ret = -ENOMEM;
- goto ret3;
- }
- mutex_init(&drv_data->mutex);
- drv_data->ssp = ssp;
- drv_data->gpio = pdata->gpio;
- drv_data->input = input;
- platform_set_drvdata(pdev, drv_data);
+ input_set_drvdata(input, navpoint);
- ret = request_irq(ssp->irq, navpoint_int, 0, pdev->name, &pdev->dev);
- if (ret)
- goto ret4;
+ error = request_irq(ssp->irq, navpoint_irq, 0, pdev->name, navpoint);
+ if (error)
+ goto err_free_mem;
- ret = input_register_device(input);
- if (ret)
- goto ret5;
+ error = input_register_device(input);
+ if (error)
+ goto err_free_irq;
+ platform_set_drvdata(pdev, navpoint);
dev_dbg(&pdev->dev, "ssp%d, irq %d\n", pdata->port, ssp->irq);
return 0;
-ret5:
+err_free_irq:
free_irq(ssp->irq, &pdev->dev);
-ret4:
- kfree(drv_data);
-ret3:
+err_free_mem:
input_free_device(input);
-ret2:
+ kfree(navpoint);
pxa_ssp_free(ssp);
-ret1:
+err_free_gpio:
if (gpio_is_valid(pdata->gpio))
gpio_free(pdata->gpio);
- return ret;
+ return error;
}
static int __devexit navpoint_remove(struct platform_device *pdev)
{
- struct driver_data *drv_data = platform_get_drvdata(pdev);
- struct input_dev *input = drv_data->input;
- struct ssp_device *ssp = drv_data->ssp;
- struct navpoint_platform_data *pdata = pdev->dev.platform_data;
-
- input_unregister_device(input);
+ const struct navpoint_platform_data *pdata =
+ dev_get_platdata(&pdev->dev);
+ struct navpoint *navpoint = platform_get_drvdata(pdev);
+ struct ssp_device *ssp = navpoint->ssp;
- free_irq(ssp->irq, &pdev->dev);
+ free_irq(ssp->irq, navpoint);
- kfree(drv_data);
+ input_unregister_device(navpoint->input);
+ kfree(navpoint);
pxa_ssp_free(ssp);
@@ -339,23 +322,29 @@ static int __devexit navpoint_remove(struct platform_device *pdev)
#ifdef CONFIG_PM_SLEEP
static int navpoint_suspend(struct device *dev)
{
- struct driver_data *drv_data = dev_get_drvdata(dev);
+ struct platform_device *pdev = to_platform_device(dev);
+ struct navpoint *navpoint = platform_get_drvdata(pdev);
+ struct input_dev *input = navpoint->input;
+
+ mutex_lock(&input->mutex);
+ if (input->users)
+ navpoint_down(navpoint);
+ mutex_unlock(&input->mutex);
- mutex_lock(&drv_data->mutex);
- if (drv_data->opened)
- navpoint_down(dev);
- mutex_unlock(&drv_data->mutex);
return 0;
}
static int navpoint_resume(struct device *dev)
{
- struct driver_data *drv_data = dev_get_drvdata(dev);
+ struct platform_device *pdev = to_platform_device(dev);
+ struct navpoint *navpoint = platform_get_drvdata(pdev);
+ struct input_dev *input = navpoint->input;
+
+ mutex_lock(&input->mutex);
+ if (input->users)
+ navpoint_up(navpoint);
+ mutex_unlock(&input->mutex);
- mutex_lock(&drv_data->mutex);
- if (drv_data->opened)
- navpoint_up(dev);
- mutex_unlock(&drv_data->mutex);
return 0;
}
#endif
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver
2012-05-09 8:00 ` Dmitry Torokhov
@ 2012-05-09 21:09 ` Paul Parsons
2012-05-09 21:23 ` Dmitry Torokhov
0 siblings, 1 reply; 6+ messages in thread
From: Paul Parsons @ 2012-05-09 21:09 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: philipp.zabel, linux-input
Hello Dmitry,
--- On Wed, 9/5/12, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> The driver looks excellent now, I have just a few nits:
>
> - you do not need separate mutex and counter; it is
> perfectly fine to
> use input device's ones;
>
> - we don't really need min/max for coordinates: the defaults
> are good
> for your device and if more devices come with
> different limits one
> could adjust limits via EVIOCSABS ioctls.
>
> I also took libertu if rearranging the code a bit so it
> flows more like
> the rest of the input drivers. Could you please tell me if
> the patch
> below breaks your device or if it still works?
It still works! Thanks.
Will you apply a combined patch (my patch v8 + your patch),
or should I submit them as patch v9?
Regards,
Paul
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver
2012-05-09 21:09 ` Paul Parsons
@ 2012-05-09 21:23 ` Dmitry Torokhov
2012-05-10 8:51 ` Paul Parsons
0 siblings, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2012-05-09 21:23 UTC (permalink / raw)
To: Paul Parsons; +Cc: philipp.zabel, linux-input
On Wednesday, May 09, 2012 10:09:55 PM Paul Parsons wrote:
> Hello Dmitry,
>
> --- On Wed, 9/5/12, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> > The driver looks excellent now, I have just a few nits:
> >
> > - you do not need separate mutex and counter; it is
> > perfectly fine to
> > use input device's ones;
> >
> > - we don't really need min/max for coordinates: the defaults
> > are good
> > for your device and if more devices come with
> > different limits one
> > could adjust limits via EVIOCSABS ioctls.
> >
> > I also took libertu if rearranging the code a bit so it
> > flows more like
> > the rest of the input drivers. Could you please tell me if
> > the patch
> > below breaks your device or if it still works?
>
> It still works! Thanks.
>
> Will you apply a combined patch (my patch v8 + your patch),
> or should I submit them as patch v9?
If you have not made any changes to the patch I sent then there is no need
to send v9, I'll fold everything together on my end.
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver
2012-05-09 21:23 ` Dmitry Torokhov
@ 2012-05-10 8:51 ` Paul Parsons
0 siblings, 0 replies; 6+ messages in thread
From: Paul Parsons @ 2012-05-10 8:51 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: philipp.zabel, linux-input
Hello Dmitry,
--- On Wed, 9/5/12, Dmitry Torokhov <dmitry.torokhov@gmail.com> wrote:
> If you have not made any changes to the patch I sent then
> there is no need
> to send v9, I'll fold everything together on my end.
Good; I did not make any changes to your patch.
As soon as it is applied I will be able to submit the
corresponding hx4700 platform glue to linux-arm-kernel.
Regards,
Paul
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2012-05-10 8:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-16 11:37 [PATCH v8] input: Add Synaptics NavPoint (PXA27x SSP/SPI) driver Paul Parsons
2012-04-16 20:16 ` Philipp Zabel
2012-05-09 8:00 ` Dmitry Torokhov
2012-05-09 21:09 ` Paul Parsons
2012-05-09 21:23 ` Dmitry Torokhov
2012-05-10 8:51 ` Paul Parsons
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).