* input/touch: LPC32xx: Introduce touch driver for the LPC32xx (v2)
@ 2010-08-16 21:21 wellsk40
2010-08-16 21:21 ` [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2) wellsk40
0 siblings, 1 reply; 6+ messages in thread
From: wellsk40 @ 2010-08-16 21:21 UTC (permalink / raw)
To: linux-input; +Cc: linux-arm-kernel
This patch set introduces support for the LPC32xx touchscreen
controller driver. The LPC32xx touchscreen controller supports
automated event detection and conversion for resistive touchscreens.
The patch can be pulled from:
git://git.lpclinux.com/linux-2.6-lpc ts-lpc32xx_v2
v2 includes updates from the initial review of the TSC driver..
All local TSC_* macros have been prefixed with LCP32XX_
Added lpc32xx_ prefix to stop_tsc() and start_tsc()
Moved clk_enable and clk_disable into lpc32xx_start_tsc()
and lpc32xx_stop_tsc() functions
Added ->open and ->close methods using the start and
stop tsc functions
Removed use of devm_* functions. Modified error unwinding
and _remove() based on this change.
Fixed an error return condition from input_register_device()
Fixed use of input_free_device
Added a use count check for suspend and resume so device
state isn't altered if it isn't open
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2)
2010-08-16 21:21 input/touch: LPC32xx: Introduce touch driver for the LPC32xx (v2) wellsk40
@ 2010-08-16 21:21 ` wellsk40
2010-08-16 22:09 ` Ryan Mallon
2010-08-29 5:48 ` Dmitry Torokhov
0 siblings, 2 replies; 6+ messages in thread
From: wellsk40 @ 2010-08-16 21:21 UTC (permalink / raw)
To: linux-input; +Cc: linux-arm-kernel, Kevin Wells, Durgesh Pattamatta
From: Kevin Wells <wellsk40@gmail.com>
This patch set introduces support for the LPC32xx touchscreen
controller driver. The LPC32xx touchscreen controller supports
automated event detection and X/Y data conversion for resistive
touchscreens.
Signed-off-by: Kevin Wells <wellsk40@gmail.com>
Signed-off-by: Durgesh Pattamatta <durgesh.pattamatta@nxp.com>
---
drivers/input/touchscreen/Kconfig | 10 +
drivers/input/touchscreen/Makefile | 1 +
drivers/input/touchscreen/lpc32xx_ts.c | 404 ++++++++++++++++++++++++++++++++
3 files changed, 415 insertions(+), 0 deletions(-)
create mode 100644 drivers/input/touchscreen/lpc32xx_ts.c
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index 0069d97..400c99d 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -214,6 +214,16 @@ config TOUCHSCREEN_WACOM_W8001
To compile this driver as a module, choose M here: the
module will be called wacom_w8001.
+config TOUCHSCREEN_LPC32XX
+ tristate "LPC32XX touchscreen controller"
+ depends on ARCH_LPC32XX
+ help
+ Say Y here if you have a LPC32XX device and want
+ to support the built-in touchscreen.
+
+ To compile this driver as a module, choose M here: the
+ module will be called lpc32xx_ts.
+
config TOUCHSCREEN_MCS5000
tristate "MELFAS MCS-5000 touchscreen"
depends on I2C
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile
index 28217e1..22e2d59 100644
--- a/drivers/input/touchscreen/Makefile
+++ b/drivers/input/touchscreen/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_TOUCHSCREEN_EETI) += eeti_ts.o
obj-$(CONFIG_TOUCHSCREEN_ELO) += elo.o
obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fujitsu_ts.o
obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
+obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o
obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o
obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o
obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
diff --git a/drivers/input/touchscreen/lpc32xx_ts.c b/drivers/input/touchscreen/lpc32xx_ts.c
new file mode 100644
index 0000000..e67ce41
--- /dev/null
+++ b/drivers/input/touchscreen/lpc32xx_ts.c
@@ -0,0 +1,404 @@
+/*
+ * LPC32xx built-in touchscreen driver
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <linux/platform_device.h>
+#include <linux/init.h>
+#include <linux/input.h>
+#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+
+/*
+ * Touchscreen controller register offsets
+ */
+#define LPC32XX_TSC_STAT 0x00
+#define LPC32XX_TSC_SEL 0x04
+#define LPC32XX_TSC_CON 0x08
+#define LPC32XX_TSC_FIFO 0x0C
+#define LPC32XX_TSC_DTR 0x10
+#define LPC32XX_TSC_RTR 0x14
+#define LPC32XX_TSC_UTR 0x18
+#define LPC32XX_TSC_TTR 0x1C
+#define LPC32XX_TSC_DXP 0x20
+#define LPC32XX_TSC_MIN_X 0x24
+#define LPC32XX_TSC_MAX_X 0x28
+#define LPC32XX_TSC_MIN_Y 0x2C
+#define LPC32XX_TSC_MAX_Y 0x30
+#define LPC32XX_TSC_AUX_UTR 0x34
+#define LPC32XX_TSC_AUX_MIN 0x38
+#define LPC32XX_TSC_AUX_MAX 0x3C
+
+#define LPC32XX_TSC_STAT_FIFO_OVRRN (1 << 8)
+#define LPC32XX_TSC_STAT_FIFO_EMPTY (1 << 7)
+
+#define LPC32XX_TSC_SEL_DEFVAL 0x0284
+
+#define LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 (0x1 << 11)
+#define LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(s) ((10 - (s)) << 7)
+#define LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(s) ((10 - (s)) << 4)
+#define LPC32XX_TSC_ADCCON_POWER_UP (1 << 2)
+#define LPC32XX_TSC_ADCCON_AUTO_EN (1 << 0)
+
+#define LPC32XX_TSC_FIFO_TS_P_LEVEL (1 << 31)
+#define LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(x) (((x) & 0x03FF0000) >> 16)
+#define LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(y) ((y) & 0x000003FF)
+
+#define LPC32XX_TSC_ADCDAT_VALUE_MASK 0x000003FF
+
+#define LPC32XX_TSC_MIN_XY_VAL 0x0
+#define LPC32XX_TSC_MAX_XY_VAL 0x3FF
+
+#define MOD_NAME "ts-lpc32xx"
+
+#define tsc_readl(dev, reg) \
+ __raw_readl((dev)->tsc_base + (reg))
+#define tsc_writel(dev, reg, val) \
+ __raw_writel((val), (dev)->tsc_base + (reg))
+
+struct lpc32xx_tsc {
+ struct input_dev *dev;
+ void __iomem *tsc_base;
+ int irq;
+ struct clk *clk;
+};
+
+static void lpc32xx_fifo_clear(struct lpc32xx_tsc *tsc)
+{
+ while (!(tsc_readl(tsc, LPC32XX_TSC_STAT) &
+ LPC32XX_TSC_STAT_FIFO_EMPTY))
+ tsc_readl(tsc, LPC32XX_TSC_FIFO);
+}
+
+static irqreturn_t lpc32xx_ts_interrupt(int irq, void *dev_id)
+{
+ u32 tmp, rv[4], xs[4], ys[4];
+ int idx;
+ struct lpc32xx_tsc *tsc = dev_id;
+ struct input_dev *input = tsc->dev;
+
+ tmp = tsc_readl(tsc, LPC32XX_TSC_STAT);
+
+ if (tmp & LPC32XX_TSC_STAT_FIFO_OVRRN) {
+ /* FIFO overflow - throw away samples */
+ lpc32xx_fifo_clear(tsc);
+ return IRQ_HANDLED;
+ }
+
+ /*
+ * Gather and normalize 4 samples. Pen-up events may have less
+ * than 4 samples, but its ok to pop 4 and let the last sample
+ * pen status check drop the samples.
+ */
+ idx = 0;
+ while ((idx < 4) &&
+ (!(tsc_readl(tsc, LPC32XX_TSC_STAT) &
+ LPC32XX_TSC_STAT_FIFO_EMPTY))) {
+ tmp = tsc_readl(tsc, LPC32XX_TSC_FIFO);
+ xs[idx] = LPC32XX_TSC_ADCDAT_VALUE_MASK -
+ LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(tmp);
+ ys[idx] = LPC32XX_TSC_ADCDAT_VALUE_MASK -
+ LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(tmp);
+ rv[idx] = tmp;
+ idx++;
+ }
+
+ /* Data is only valid if pen is still down in last sample */
+ if ((!(rv[3] & LPC32XX_TSC_FIFO_TS_P_LEVEL)) && (idx == 4)) {
+ /* Use average of 2nd and 3rd sample for position */
+ input_report_abs(input, ABS_X, ((xs[1] + xs[2]) / 2));
+ input_report_abs(input, ABS_Y, ((ys[1] + ys[2]) / 2));
+ input_report_key(input, BTN_TOUCH, 1);
+ } else {
+ input_report_key(input, BTN_TOUCH, 0);
+ }
+
+ input_sync(input);
+
+ return IRQ_HANDLED;
+}
+
+static void lpc32xx_stop_tsc(struct lpc32xx_tsc *tsc)
+{
+ /* Disable auto mode */
+ tsc_writel(tsc, LPC32XX_TSC_CON,
+ tsc_readl(tsc, LPC32XX_TSC_CON) &
+ ~LPC32XX_TSC_ADCCON_AUTO_EN);
+
+ clk_disable(tsc->clk);
+}
+
+static void lpc32xx_setup_tsc(struct lpc32xx_tsc *tsc)
+{
+ u32 tmp;
+
+ clk_enable(tsc->clk);
+
+ tmp = tsc_readl(tsc, LPC32XX_TSC_CON) & ~LPC32XX_TSC_ADCCON_POWER_UP;
+
+ /* Set the TSC FIFO depth to 4 samples @ 10-bits per sample (max) */
+ tmp = (LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 |
+ LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(10) |
+ LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(10));
+ tsc_writel(tsc, LPC32XX_TSC_CON, tmp);
+
+ /* These values are all preset */
+ tsc_writel(tsc, LPC32XX_TSC_SEL, LPC32XX_TSC_SEL_DEFVAL);
+ tsc_writel(tsc, LPC32XX_TSC_MIN_X, LPC32XX_TSC_MIN_XY_VAL);
+ tsc_writel(tsc, LPC32XX_TSC_MAX_X, LPC32XX_TSC_MAX_XY_VAL);
+ tsc_writel(tsc, LPC32XX_TSC_MIN_Y, LPC32XX_TSC_MIN_XY_VAL);
+ tsc_writel(tsc, LPC32XX_TSC_MAX_Y, LPC32XX_TSC_MAX_XY_VAL);
+
+ /* Aux support is not used */
+ tsc_writel(tsc, LPC32XX_TSC_AUX_UTR, 0);
+ tsc_writel(tsc, LPC32XX_TSC_AUX_MIN, 0);
+ tsc_writel(tsc, LPC32XX_TSC_AUX_MAX, 0);
+
+ /*
+ * Set sample rate to about 240Hz per X/Y pair. A single measurement
+ * consists of 4 pairs which gives about a 60Hz sample rate based on
+ * a stable 32768Hz clock source. Values are in clocks.
+ * Rate is (32768 / (RTR + XCONV + RTR + YCONV + DXP + TTR + UTR) / 4
+ */
+ tsc_writel(tsc, LPC32XX_TSC_RTR, 0x2);
+ tsc_writel(tsc, LPC32XX_TSC_DTR, 0x2);
+ tsc_writel(tsc, LPC32XX_TSC_TTR, 0x10);
+ tsc_writel(tsc, LPC32XX_TSC_DXP, 0x4);
+ tsc_writel(tsc, LPC32XX_TSC_UTR, 88);
+
+ lpc32xx_fifo_clear(tsc);
+
+ /* Enable automatic ts event capture */
+ tsc_writel(tsc, LPC32XX_TSC_CON, tmp | LPC32XX_TSC_ADCCON_AUTO_EN);
+}
+
+static int lpc32xx_ts_open(struct input_dev *dev)
+{
+ struct lpc32xx_tsc *tsc = input_get_drvdata(dev);
+
+ lpc32xx_setup_tsc(tsc);
+
+ return 0;
+}
+
+static void lpc32xx_ts_close(struct input_dev *dev)
+{
+ struct lpc32xx_tsc *tsc = input_get_drvdata(dev);
+
+ lpc32xx_stop_tsc(tsc);
+}
+
+static int __devinit lpc32xx_ts_probe(struct platform_device *pdev)
+{
+ struct lpc32xx_tsc *tsc;
+ struct resource *res;
+ resource_size_t size;
+ int retval;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!res) {
+ dev_err(&pdev->dev, "Can't get memory resource\n");
+ return -ENOENT;
+ }
+
+ retval = platform_get_irq(pdev, 0);
+ if (retval < 0) {
+ dev_err(&pdev->dev, "Can't get interrupt resource\n");
+ return retval;
+ }
+
+ tsc = kzalloc(sizeof(*tsc), GFP_KERNEL);
+ if (unlikely(!tsc)) {
+ dev_err(&pdev->dev, "failed allocating memory\n");
+ return -ENOMEM;
+ }
+ tsc->irq = retval;
+
+ size = resource_size(res);
+
+ if (!request_mem_region(res->start, size, pdev->name)) {
+ dev_err(&pdev->dev, "TSC registers are not free\n");
+ retval = -EBUSY;
+ goto err_free_mem;
+ }
+
+ tsc->tsc_base = ioremap(res->start, size);
+ if (!tsc->tsc_base) {
+ dev_err(&pdev->dev, "Can't map memory\n");
+ retval = -ENOMEM;
+ goto err_release_mem;
+ }
+
+ tsc->dev = input_allocate_device();
+ if (!tsc->dev) {
+ dev_err(&pdev->dev, "failed allocating input device\n");
+ retval = -ENOMEM;
+ goto err_unmap;
+ }
+
+ tsc->clk = clk_get(&pdev->dev, NULL);
+ if (IS_ERR(tsc->clk)) {
+ dev_err(&pdev->dev, "failed getting clock\n");
+ retval = -ENOENT;
+ goto err_dealloc_dev;
+ }
+
+ platform_set_drvdata(pdev, tsc);
+ input_set_drvdata(tsc->dev, tsc);
+
+ tsc->dev->name = MOD_NAME;
+ tsc->dev->phys = "lpc32xx/input0";
+ tsc->dev->id.bustype = BUS_HOST;
+ tsc->dev->id.vendor = 0x0001;
+ tsc->dev->id.product = 0x0002;
+ tsc->dev->id.version = 0x0100;
+ tsc->dev->dev.parent = &pdev->dev;
+ tsc->dev->open = lpc32xx_ts_open;
+ tsc->dev->close = lpc32xx_ts_close;
+
+ tsc->dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
+ tsc->dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
+ input_set_abs_params(tsc->dev, ABS_X, LPC32XX_TSC_MIN_XY_VAL,
+ LPC32XX_TSC_MAX_XY_VAL, 0, 0);
+ input_set_abs_params(tsc->dev, ABS_Y, LPC32XX_TSC_MIN_XY_VAL,
+ LPC32XX_TSC_MAX_XY_VAL, 0, 0);
+
+ retval = input_register_device(tsc->dev);
+ if (retval) {
+ dev_err(&pdev->dev, "failed registering input device\n");
+ goto err_stop_clock;
+ }
+
+ retval = request_irq(tsc->irq, lpc32xx_ts_interrupt,
+ IRQF_DISABLED, pdev->name, tsc);
+ if (retval < 0) {
+ dev_err(&pdev->dev, "failed requesting interrupt\n");
+ goto err_unreg_dev;
+ }
+
+ device_init_wakeup(&pdev->dev, 1);
+
+ return 0;
+
+err_unreg_dev:
+ input_unregister_device(tsc->dev);
+ tsc->dev = NULL;
+err_stop_clock:
+ clk_put(tsc->clk);
+err_dealloc_dev:
+ input_free_device(tsc->dev);
+err_unmap:
+ iounmap(tsc->tsc_base);
+err_release_mem:
+ release_mem_region(res->start, size);
+err_free_mem:
+ kfree(tsc);
+
+ return retval;
+}
+
+static int __devexit lpc32xx_ts_remove(struct platform_device *pdev)
+{
+ struct lpc32xx_tsc *tsc = platform_get_drvdata(pdev);
+ struct resource *res;
+
+ device_init_wakeup(&pdev->dev, 0);
+ free_irq(tsc->irq, tsc);
+
+ input_unregister_device(tsc->dev);
+
+ clk_put(tsc->clk);
+
+ iounmap(tsc->tsc_base);
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ release_mem_region(res->start, resource_size(res));
+
+ kfree(tsc);
+
+ return 0;
+}
+
+#ifdef CONFIG_PM
+static int lpc32xx_ts_suspend(struct device *dev)
+{
+ struct lpc32xx_tsc *tsc = dev_get_drvdata(dev);
+
+ /*
+ * Suspend and resume can be called when the device hasn't been
+ * enabled. If there are no users that have the device open, then
+ * avoid calling the TSC stop and start functions as the TSC
+ * isn't yet clocked.
+ */
+ if (tsc->dev->users) {
+ if (device_may_wakeup(dev))
+ enable_irq_wake(tsc->irq);
+ else
+ lpc32xx_stop_tsc(tsc);
+ }
+
+ return 0;
+}
+
+static int lpc32xx_ts_resume(struct device *dev)
+{
+ struct lpc32xx_tsc *tsc = dev_get_drvdata(dev);
+
+ if (tsc->dev->users) {
+ if (device_may_wakeup(dev))
+ disable_irq_wake(tsc->irq);
+ else
+ lpc32xx_setup_tsc(tsc);
+ }
+
+ return 0;
+}
+
+static const struct dev_pm_ops lpc32xx_ts_pm_ops = {
+ .suspend = lpc32xx_ts_suspend,
+ .resume = lpc32xx_ts_resume,
+};
+#define LPC32XX_TS_PM_OPS (&lpc32xx_ts_pm_ops)
+#else
+#define LPC32XX_TS_PM_OPS NULL
+#endif
+
+static struct platform_driver lpc32xx_ts_driver = {
+ .probe = lpc32xx_ts_probe,
+ .remove = __devexit_p(lpc32xx_ts_remove),
+ .driver = {
+ .name = MOD_NAME,
+ .owner = THIS_MODULE,
+ .pm = LPC32XX_TS_PM_OPS,
+ },
+};
+
+static int __init lpc32xx_ts_init(void)
+{
+ return platform_driver_register(&lpc32xx_ts_driver);
+}
+module_init(lpc32xx_ts_init);
+
+static void __exit lpc32xx_ts_exit(void)
+{
+ platform_driver_unregister(&lpc32xx_ts_driver);
+}
+module_exit(lpc32xx_ts_exit);
+
+MODULE_AUTHOR("Kevin Wells <kevin.wells@nxp.com");
+MODULE_DESCRIPTION("LPC32XX TSC Driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:lpc32xx_ts");
--
1.7.1.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2)
2010-08-16 21:21 ` [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2) wellsk40
@ 2010-08-16 22:09 ` Ryan Mallon
2010-08-18 0:34 ` Kevin Wells
2010-08-29 5:48 ` Dmitry Torokhov
1 sibling, 1 reply; 6+ messages in thread
From: Ryan Mallon @ 2010-08-16 22:09 UTC (permalink / raw)
To: wellsk40; +Cc: linux-arm-kernel, Durgesh Pattamatta, linux-input
On 08/17/2010 09:21 AM, wellsk40@gmail.com wrote:
> From: Kevin Wells <wellsk40@gmail.com>
>
> This patch set introduces support for the LPC32xx touchscreen
> controller driver. The LPC32xx touchscreen controller supports
> automated event detection and X/Y data conversion for resistive
> touchscreens.
Hi Kevin,
A few comments below.
> +
> +#define LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 (0x1 << 11)
> +#define LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(s) ((10 - (s)) << 7)
> +#define LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(s) ((10 - (s)) << 4)
> +#define LPC32XX_TSC_ADCCON_POWER_UP (1 << 2)
> +#define LPC32XX_TSC_ADCCON_AUTO_EN (1 << 0)
> +
> +#define LPC32XX_TSC_FIFO_TS_P_LEVEL (1 << 31)
> +#define LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(x) (((x) & 0x03FF0000) >> 16)
> +#define LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(y) ((y) & 0x000003FF)
Some of these names are really long which causes lots of line breaks in
the code. Can you shorten some of the names to make it more readable.
> +#define LPC32XX_TSC_ADCDAT_VALUE_MASK 0x000003FF
> +
> +#define LPC32XX_TSC_MIN_XY_VAL 0x0
> +#define LPC32XX_TSC_MAX_XY_VAL 0x3FF
> +
> +#define MOD_NAME "ts-lpc32xx"
> +
> +#define tsc_readl(dev, reg) \
> + __raw_readl((dev)->tsc_base + (reg))
> +#define tsc_writel(dev, reg, val) \
> + __raw_writel((val), (dev)->tsc_base + (reg))
inline functions are better for this sort of thing.
> +
> +struct lpc32xx_tsc {
> + struct input_dev *dev;
> + void __iomem *tsc_base;
> + int irq;
> + struct clk *clk;
> +};
(Nitpicky) Tab delimit this to make it a bit more readable.
> +static void lpc32xx_fifo_clear(struct lpc32xx_tsc *tsc)
> +{
> + while (!(tsc_readl(tsc, LPC32XX_TSC_STAT) &
> + LPC32XX_TSC_STAT_FIFO_EMPTY))
> + tsc_readl(tsc, LPC32XX_TSC_FIFO);
> +}
The FIFO_EMTPY bit gets used a couple of times, so maybe:
static inline tsc_fifo_empty(struct lpc32xx_tsc *tsc)
{
return tsc_readl(tsc, LPC32XX_TSC_STAT) &
LPC32XX_TSC_STAT_FIFO_EMPTY;
}
Also, is it worth having a timeout on that while loop so that if the i2c
bus dies or something that you don't get stuck there forever?
> +static irqreturn_t lpc32xx_ts_interrupt(int irq, void *dev_id)
> +{
> + u32 tmp, rv[4], xs[4], ys[4];
> + int idx;
> + struct lpc32xx_tsc *tsc = dev_id;
> + struct input_dev *input = tsc->dev;
> +
> + tmp = tsc_readl(tsc, LPC32XX_TSC_STAT);
> +
> + if (tmp & LPC32XX_TSC_STAT_FIFO_OVRRN) {
> + /* FIFO overflow - throw away samples */
Should there be a dev_err/warn here to let the user know?
> + lpc32xx_fifo_clear(tsc);
> + return IRQ_HANDLED;
> + }
> +
> + /*
> + * Gather and normalize 4 samples. Pen-up events may have less
> + * than 4 samples, but its ok to pop 4 and let the last sample
> + * pen status check drop the samples.
> + */
> + idx = 0;
> + while ((idx < 4) &&
> + (!(tsc_readl(tsc, LPC32XX_TSC_STAT) &
> + LPC32XX_TSC_STAT_FIFO_EMPTY))) {
for (idx = 0; idx < 4 && !tsc_fifo_empty(); idx++) {
...
Is a bit more readable.
> + tmp = tsc_readl(tsc, LPC32XX_TSC_FIFO);
> + xs[idx] = LPC32XX_TSC_ADCDAT_VALUE_MASK -
> + LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(tmp);
> + ys[idx] = LPC32XX_TSC_ADCDAT_VALUE_MASK -
> + LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(tmp);
> + rv[idx] = tmp;
> + idx++;
> + }
> +
> + /* Data is only valid if pen is still down in last sample */
> + if ((!(rv[3] & LPC32XX_TSC_FIFO_TS_P_LEVEL)) && (idx == 4)) {
> + /* Use average of 2nd and 3rd sample for position */
> + input_report_abs(input, ABS_X, ((xs[1] + xs[2]) / 2));
> + input_report_abs(input, ABS_Y, ((ys[1] + ys[2]) / 2));
> + input_report_key(input, BTN_TOUCH, 1);
> + } else {
> + input_report_key(input, BTN_TOUCH, 0);
> + }
> +
> + input_sync(input);
> +
> + return IRQ_HANDLED;
> +}
> +
> +static void lpc32xx_stop_tsc(struct lpc32xx_tsc *tsc)
> +{
> + /* Disable auto mode */
> + tsc_writel(tsc, LPC32XX_TSC_CON,
> + tsc_readl(tsc, LPC32XX_TSC_CON) &
> + ~LPC32XX_TSC_ADCCON_AUTO_EN);
> +
> + clk_disable(tsc->clk);
> +}
> +
> +static void lpc32xx_setup_tsc(struct lpc32xx_tsc *tsc)
> +{
> + u32 tmp;
> +
> + clk_enable(tsc->clk);
> +
> + tmp = tsc_readl(tsc, LPC32XX_TSC_CON) & ~LPC32XX_TSC_ADCCON_POWER_UP;
> +
> + /* Set the TSC FIFO depth to 4 samples @ 10-bits per sample (max) */
> + tmp = (LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 |
> + LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(10) |
> + LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(10));
> + tsc_writel(tsc, LPC32XX_TSC_CON, tmp);
> +
> + /* These values are all preset */
> + tsc_writel(tsc, LPC32XX_TSC_SEL, LPC32XX_TSC_SEL_DEFVAL);
> + tsc_writel(tsc, LPC32XX_TSC_MIN_X, LPC32XX_TSC_MIN_XY_VAL);
> + tsc_writel(tsc, LPC32XX_TSC_MAX_X, LPC32XX_TSC_MAX_XY_VAL);
> + tsc_writel(tsc, LPC32XX_TSC_MIN_Y, LPC32XX_TSC_MIN_XY_VAL);
> + tsc_writel(tsc, LPC32XX_TSC_MAX_Y, LPC32XX_TSC_MAX_XY_VAL);
> +
> + /* Aux support is not used */
> + tsc_writel(tsc, LPC32XX_TSC_AUX_UTR, 0);
> + tsc_writel(tsc, LPC32XX_TSC_AUX_MIN, 0);
> + tsc_writel(tsc, LPC32XX_TSC_AUX_MAX, 0);
> +
> + /*
> + * Set sample rate to about 240Hz per X/Y pair. A single measurement
> + * consists of 4 pairs which gives about a 60Hz sample rate based on
> + * a stable 32768Hz clock source. Values are in clocks.
> + * Rate is (32768 / (RTR + XCONV + RTR + YCONV + DXP + TTR + UTR) / 4
> + */
Is the clock source internal, or at least always 32.768kHz? If not,
should the timing be controlled via some platform data so that this
driver is compatible with other board setups?
~Ryan
--
Bluewater Systems Ltd - ARM Technology Solution Centre
Ryan Mallon 5 Amuri Park, 404 Barbadoes St
ryan@bluewatersys.com PO Box 13 889, Christchurch 8013
http://www.bluewatersys.com New Zealand
Phone: +64 3 3779127 Freecall: Australia 1800 148 751
Fax: +64 3 3779135 USA 1800 261 2934
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2)
2010-08-16 22:09 ` Ryan Mallon
@ 2010-08-18 0:34 ` Kevin Wells
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wells @ 2010-08-18 0:34 UTC (permalink / raw)
To: Ryan Mallon; +Cc: linux-input, Durgesh Pattamatta, linux-arm-kernel
Hi Ryan,
Thanks for taking the time to review this.
>> +
>> + /*
>> + * Set sample rate to about 240Hz per X/Y pair. A single measurement
>> + * consists of 4 pairs which gives about a 60Hz sample rate based on
>> + * a stable 32768Hz clock source. Values are in clocks.
>> + * Rate is (32768 / (RTR + XCONV + RTR + YCONV + DXP + TTR + UTR) / 4
>> + */
>
> Is the clock source internal, or at least always 32.768kHz? If not,
> should the timing be controlled via some platform data so that this
> driver is compatible with other board setups?
>
The clock source for this is internal and locked in the driver and clock control
handler at 32768Hz.
As much as I want to argue not using platform data :), I can't think of one good
reason not to use it for this (the keyscanner driver has it). I
probably should of
used it from the start.
--
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] input/touch: Introduce the LPC32xx touchscreen controller driver (v2)
2010-08-16 21:21 ` [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2) wellsk40
2010-08-16 22:09 ` Ryan Mallon
@ 2010-08-29 5:48 ` Dmitry Torokhov
2010-08-31 22:46 ` Kevin Wells
1 sibling, 1 reply; 6+ messages in thread
From: Dmitry Torokhov @ 2010-08-29 5:48 UTC (permalink / raw)
To: wellsk40; +Cc: linux-input, linux-arm-kernel, Durgesh Pattamatta
On Mon, Aug 16, 2010 at 02:21:01PM -0700, wellsk40@gmail.com wrote:
> From: Kevin Wells <wellsk40@gmail.com>
>
> This patch set introduces support for the LPC32xx touchscreen
> controller driver. The LPC32xx touchscreen controller supports
> automated event detection and X/Y data conversion for resistive
> touchscreens.
>
> Signed-off-by: Kevin Wells <wellsk40@gmail.com>
> Signed-off-by: Durgesh Pattamatta <durgesh.pattamatta@nxp.com>
Applied to my .37 queue, thanks Kevin.
--
Dmitry
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2)
2010-08-29 5:48 ` Dmitry Torokhov
@ 2010-08-31 22:46 ` Kevin Wells
0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wells @ 2010-08-31 22:46 UTC (permalink / raw)
To: Dmitry Torokhov, wellsk40@gmail.com
Cc: linux-arm-kernel@lists.infradead.org, Durgesh Pattamatta,
linux-input@vger.kernel.org
> Subject: Re: [PATCH] input/touch: Introduce the LPC32xx touchscreen
> controller driver (v2)
>
> On Mon, Aug 16, 2010 at 02:21:01PM -0700, wellsk40@gmail.com wrote:
> > From: Kevin Wells <wellsk40@gmail.com>
> >
> > This patch set introduces support for the LPC32xx touchscreen
> > controller driver. The LPC32xx touchscreen controller supports
> > automated event detection and X/Y data conversion for resistive
> > touchscreens.
> >
> > Signed-off-by: Kevin Wells <wellsk40@gmail.com>
> > Signed-off-by: Durgesh Pattamatta <durgesh.pattamatta@nxp.com>
>
> Applied to my .37 queue, thanks Kevin.
>
Thanks for applying this Dmitry.
Ryan M also had some good comments about the v2 driver that I'll
resolve once some other associated fixes get pulled in.
> --
> Dmitry
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2010-08-31 22:46 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-16 21:21 input/touch: LPC32xx: Introduce touch driver for the LPC32xx (v2) wellsk40
2010-08-16 21:21 ` [PATCH] input/touch: Introduce the LPC32xx touchscreen controller driver (v2) wellsk40
2010-08-16 22:09 ` Ryan Mallon
2010-08-18 0:34 ` Kevin Wells
2010-08-29 5:48 ` Dmitry Torokhov
2010-08-31 22:46 ` Kevin Wells
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).