Touch: DA9052 touchscreen driver
Subsystems (2)
PATCH v2 8/11 Touch: DA9052 touchscreen driver
This driver add support for DA9052 4-wire resistive ADC interfaced touchscreen controller.
DA9052 is a MFD therefore this driver depends on DA9052 core driver for core functionalities.
---
Changes since v2:
- Replace kthreads with workqueue
- Remove kfifos
- Remove extra struct memebers
- Taken care for bus type
- Replace da9052_set/clear function with da9052_reg_update ( as DA9052 MFD got modified)
- Add open and close functionality
--- drivers/input/touchscreen/Kconfig | 7 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/da9052_tsi.c | 400 ++++++++++++++++++++++++++++++++ 3 files changed, 408 insertions(+), 0 deletions(-) create mode 100755 drivers/input/touchscreen/da9052_tsi.c
drivers/input/touchscreen/Kconfig +7 -0
@@ -144,6 +144,13 @@ config TOUCHSCREEN_DA9034 Say Y here to enable the support for the touchscreen found on Dialog Semiconductor DA9034 PMIC. +config TOUCHSCREEN_DA9052 + tristate "Dialog DA9052 TSI" + depends on PMIC_DA9052 + help + Say y here to support the touchscreen found on + Dialog Semiconductor DA9052 PMIC + config TOUCHSCREEN_DYNAPRO tristate "Dynapro serial touchscreen" select SERIO
drivers/input/touchscreen/Makefile +1 -0
@@ -18,6 +18,7 @@ obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o +obj-$(CONFIG_TOUCHSCREEN_DA9052) += da9052_tsi.o obj-$(CONFIG_TOUCHSCREEN_DYNAPRO) += dynapro.o obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE) += hampshire.o obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.o
drivers/input/touchscreen/da9052_tsi.c new file +400 -0
400 lines not on this page · raw message
Quoted 8 lines · On Fri, 2011-08-12 at 19:20 +0530, ashishj3 wrote:
This driver add support for DA9052 4-wire resistive ADC interfaced touchscreen controller.
DA9052 is a MFD therefore this driver depends on DA9052 core driver for core functionalities.
Signed-off-by David Dajun Chen <[email protected]>Signed-off-by Ashish Jangam <[email protected]>
Quoted 9 lines
---
Changes since v2:
- Replace kthreads with workqueue
- Remove kfifos
- Remove extra struct memebers
- Taken care for bus type
- Replace da9052_set/clear function withda9052_reg_update( as DA9052 MFD got modified)
- Add open and close functionality
---
In case there are no comments then can this patch get ACK?
Quoted 18 lines · On Mon, 2011-08-22 at 13:42 +0530, ashishj3 wrote:
Quoted 8 lines · On Fri, 2011-08-12 at 19:20 +0530, ashishj3 wrote:
This driver add support for DA9052 4-wire resistive ADC interfaced touchscreen controller.
DA9052 is a MFD therefore this driver depends on DA9052 core driver for core functionalities.
Signed-off-by David Dajun Chen <[email protected]>Signed-off-by Ashish Jangam <[email protected]>Quoted 9 lines
---
Changes since v2:
- Replace kthreads with workqueue
- Remove kfifos
- Remove extra struct memebers
- Taken care for bus type
- Replace da9052_set/clear function withda9052_reg_update( as DA9052 MFD got modified)
- Add open and close functionality
---
Quoted 1 line
In case there are no comments then can this patch get ACK?
Any comments that you like to share?
Dmitry Torokhov
maintainerHi Ashish,
Quoted 83 lines · On Fri, Aug 12, 2011 at 07:20:26PM +0530, ashishj3 wrote:
This driver add support for DA9052 4-wire resistive ADC interfaced touchscreen controller.
DA9052 is a MFD therefore this driver depends on DA9052 core driver for core functionalities.
Signed-off-by David Dajun Chen <[email protected]>Signed-off-by Ashish Jangam <[email protected]>---
Changes since v2:
- Replace kthreads with workqueue
- Remove kfifos
- Remove extra struct memebers
- Taken care for bus type
- Replace da9052_set/clear function withda9052_reg_update( as DA9052 MFD got modified)
- Add open and close functionality--- drivers/input/touchscreen/Kconfig | 7 + drivers/input/touchscreen/Makefile | 1 + drivers/input/touchscreen/da9052_tsi.c | 400 ++++++++++++++++++++++++++++++++ 3 files changed, 408 insertions(+), 0 deletions(-) create mode 100755 drivers/input/touchscreen/da9052_tsi.cdrivers/input/touchscreen/Kconfig +7
-0@@ -144,6 +144,13 @@ config TOUCHSCREEN_DA9034 Say Y here to enable the support for the touchscreen found on Dialog Semiconductor DA9034 PMIC. +config TOUCHSCREEN_DA9052 + tristate "Dialog DA9052 TSI" + depends on PMIC_DA9052 + help + Say y here to support the touchscreen found on + Dialog Semiconductor DA9052 PMIC + config TOUCHSCREEN_DYNAPRO tristate "Dynapro serial touchscreen" select SERIOdrivers/input/touchscreen/Makefile +1
-0@@ -18,6 +18,7 @@ obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o obj-$(CONFIG_TOUCHSCREEN_CY8CTMG110) += cy8ctmg110_ts.o obj-$(CONFIG_TOUCHSCREEN_DA9034) += da9034-ts.o +obj-$(CONFIG_TOUCHSCREEN_DA9052) += da9052_tsi.o obj-$(CONFIG_TOUCHSCREEN_DYNAPRO) += dynapro.o obj-$(CONFIG_TOUCHSCREEN_HAMPSHIRE) += hampshire.o obj-$(CONFIG_TOUCHSCREEN_GUNZE) += gunze.odrivers/input/touchscreen/da9052_tsi.c new file +25
-0@@ -0,0 +1,400 @@ +/* +* TSI driver for Dialog DA9052 +* +* Copyright(c) 2011 Dialog Semiconductor Ltd. +* +* Author: David Dajun Chen <[email protected]> +* +* 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. +* +*/ +#include <linux/module.h> +#include <linux/input.h> +#include <linux/delay.h> +#include <linux/platform_device.h> + +#include <linux/mfd/da9052/reg.h> +#include <linux/mfd/da9052/da9052.h> + +struct da9052_tsi_reg { +u16 x; +u16 y; +u16 z;
drivers/input/touchscreen/da9052_tsi.c line 35
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+}; + +struct da9052_tsi { +struct da9052 *da9052; +struct input_dev *dev; +struct workqueue_struct *ts_workq; +struct work_struct ts_report_penup; +int irq_pendwn; +int irq_datardy; +int pendown;
Bool maybe?
Quoted 8 lines
drivers/input/touchscreen/da9052_tsi.c new file +8
-0+int workschd; +uint8_t lsb; +}; + +static int da9052_ts_start (struct da9052_tsi *tsi) +{ +return da9052_reg_update (tsi->da9052,DA9052_TSI_CONT_A_REG , +1 <<0 ,1 <<0 );
drivers/input/touchscreen/da9052_tsi.c line 53
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+} + +static int da9052_ts_stop (struct da9052_tsi *tsi) +{ +return da9052_reg_update (tsi->da9052,DA9052_TSI_CONT_A_REG ,1 <<0 ,0 ); +} + +static irqreturn_t da9052_ts_pendwn_irq (int irq,void *data) +{ +struct da9052_tsi *tsi = (struct da9052_tsi *)data;
No need to cast.
Quoted 54 lines
drivers/input/touchscreen/da9052_tsi.c new file +54
-0+struct da9052 *da9052 = tsi->da9052; +int ret; + +/* Mask PEN_DOWN event and unmask TSI_READY event */ + da9052->events_mask |=DA9052_E_PEN_DOWN ; + da9052->events_mask &= ~DA9052_E_TSI_READY ; + ret =da9052_reg_update (da9052,DA9052_IRQ_MASK_B_REG ,0x80 ,0x40 ); +if (ret <0 ) +return IRQ_NONE ; + +da9052_ts_start (tsi); + tsi->pendown =1 ; + +input_report_key (tsi->dev,BTN_TOUCH ,1 ); + +return IRQ_HANDLED ; +} + +static int da9052_ts_read (struct da9052_tsi *tsi) +{ +struct da9052_tsi_reg co_ord = {0 ,0 ,0 }; +int ret; +uint8_t _x, _y, _z, _v; + + ret =da9052_reg_read (tsi->da9052,DA9052_TSI_X_MSB_REG ); +if (ret <0 ) +return ret; + + _x = (uint8_t ) ret; + + ret =da9052_reg_read (tsi->da9052,DA9052_TSI_Y_MSB_REG ); +if (ret <0 ) +return ret; + + _y = (uint8_t ) ret; + + ret =da9052_reg_read (tsi->da9052,DA9052_TSI_Z_MSB_REG ); +if (ret <0 ) +return ret; + + _z = (uint8_t ) ret; + + ret =da9052_reg_read (tsi->da9052,DA9052_TSI_LSB_REG ); +if (ret <0 ) +return ret; + + _v = tsi->lsb = (uint8_t ) ret; + + co_ord.x = ((_x <<2 ) &0x3fc ) | (_v &0x3 ); + co_ord.y = ((_y <<2 ) &0x3fc ) | ((_v &0xc ) >>2 ); + co_ord.z = ((_z <<2 ) &0x3fc ) | ((_v &0x30 ) >>4 ); + +input_report_abs (tsi->dev,ABS_X , co_ord.x); +input_report_abs (tsi->dev,ABS_Y , co_ord.y);
drivers/input/touchscreen/da9052_tsi.c line 117
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+input_report_abs (tsi->dev,ABS_PRESSURE , co_ord.z); +input_report_key (tsi->dev,BTN_TOUCH ,1 ); +input_sync (tsi->dev); + +return 0 ; +} + +static irqreturn_t da9052_ts_datardy_irq (int irq,void *data) +{ +struct da9052_tsi *tsi = (struct da9052_tsi *)data;
No need to cast.
drivers/input/touchscreen/da9052_tsi.c line 121
Quoted 4 lines
drivers/input/touchscreen/da9052_tsi.c new file +4
-0+ +/* Avoid multiple schedule of queue */ +if (tsi->pendown && !tsi->workschd) +queue_work (tsi->ts_workq, &tsi->ts_report_penup);
Workqueue infrastructure will not reschedule work if it is already scheduled, you do not need to check your own flags here.
Quoted 13 lines
drivers/input/touchscreen/da9052_tsi.c new file +13
-0+return IRQ_HANDLED ; +} + +static void da9052_ts_report_penup (struct work_struct *work) +{ + struct da9052_tsi *tsi = container_of(work, struct da9052_tsi, + ts_report_penup); +struct input_dev *ip_dev = tsi->dev; +struct da9052 *da9052 = tsi->da9052; + +/* Work queue is scheduled */ + tsi->workschd =1 ; +
drivers/input/touchscreen/da9052_tsi.c line 144
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+do { +da9052_ts_read (tsi); + +/* FixMe: At times TSI RDY IRQ does not get cleared causing +* toss to the PEN Detect Circuitry. Its safe to clear event +* here. +*/ +da9052_reg_update (tsi->da9052,DA9052_EVENT_B_REG ,0x80 ,0x80 ); + + }while (tsi->lsb &0x40 );
How long will it be spinning? Until you release the pen? You should reschedule the work if pen is still touching the surface.
Quoted 8 lines
drivers/input/touchscreen/da9052_tsi.c new file +8
-0+ +/* Pen up Detected */ + tsi->pendown =0 ; +/* Leaving work queue */ + tsi->workschd =0 ; + +da9052_ts_stop (tsi); +
drivers/input/touchscreen/da9052_tsi.c line 162
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+/* Unmask PEN_DOWN event */ + da9052->events_mask &= ~DA9052_E_PEN_DOWN ; +da9052_reg_update (da9052,DA9052_IRQ_MASK_B_REG ,0x40 ,0 ); + +input_report_abs (ip_dev,ABS_PRESSURE ,0 ); +input_report_key (ip_dev,BTN_TOUCH ,0 ); +input_sync (ip_dev); +} + +static int da9052_ts_configure_gpio (struct da9052 *da9052)
__devinit.
Quoted 7 lines
drivers/input/touchscreen/da9052_tsi.c new file +7
-0+{ +int ret; + + ret =da9052_reg_update (da9052,DA9052_GPIO_2_3_REG ,0x30 ,0 ); +if (ret <0 ) +return ret; +
drivers/input/touchscreen/da9052_tsi.c line 179
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+ ret =da9052_reg_update (da9052,DA9052_GPIO_4_5_REG ,0x33 ,0 ); +if (ret <0 ) +return ret; + + ret =da9052_reg_update (da9052,DA9052_GPIO_6_7_REG ,0x33 ,0 ); + +return ret; +} + +static int __init da9052_configure_tsi (struct da9052_tsi *tsi)
__devinit.
Quoted 36 lines
drivers/input/touchscreen/da9052_tsi.c new file +36
-0+{ +ssize_t ret; +struct da9052 *da9052 = tsi->da9052; + + ret =da9052_ts_configure_gpio (tsi->da9052); +if (ret <0 ) +return ret; + +/* Measure TSI sample every 1ms */ + ret =da9052_reg_update (tsi->da9052,DA9052_ADC_CONT_REG , +1 <<6 ,1 <<6 ); +if (ret <0 ) +return ret; + +/* TSI_DELAY: 3 slots, TSI_SKIP: 0 slots, TSI_MODE: XYZP */ + ret =da9052_reg_update (tsi->da9052,DA9052_TSI_CONT_A_REG ,0xFC ,0xC0 ); +if (ret <0 ) +return ret; + +/* Mask TSI_READY event */ + da9052->events_mask |=DA9052_E_TSI_READY ; + ret =da9052_reg_update (da9052,DA9052_IRQ_MASK_B_REG ,0 ,0x80 ); +if (ret <0 ) +return ret; + +/*Supply TSIRef through LD09 */ + ret =da9052_reg_write (tsi->da9052,DA9052_LDO9_REG ,0x59 ); + +return ret; +} + +static int da9052_ts_input_open (struct input_dev *input_dev) +{ +struct da9052_tsi *tsi =input_get_drvdata (input_dev); + +/* Enable Pen Detect Circuit */
drivers/input/touchscreen/da9052_tsi.c line 225
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+return da9052_reg_update (tsi->da9052,DA9052_TSI_CONT_A_REG , +1 <<1 ,1 <<1 ); +} + +static void da9052_ts_input_close (struct input_dev *input_dev) +{ +struct da9052_tsi *tsi =input_get_drvdata (input_dev); + +/* Disable Pen Detect Circuit */ +da9052_reg_update (tsi->da9052,DA9052_TSI_CONT_A_REG ,1 <<1 ,0 );
You should also wait for your dataready interrupt to complete and cancel your work.
drivers/input/touchscreen/da9052_tsi.c line 228
Quoted 3 lines
drivers/input/touchscreen/da9052_tsi.c new file +3
-0+} + +static s32 __devinit da9052_ts_probe (struct platform_device *pdev)
int.
Quoted 6 lines
drivers/input/touchscreen/da9052_tsi.c new file +6
-0+{ +struct da9052_tsi *tsi; +struct input_dev *input_dev; +struct da9052 *da9052; +int ret; +
drivers/input/touchscreen/da9052_tsi.c line 244
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+ tsi =kzalloc (sizeof (struct da9052_tsi ),GFP_KERNEL ); +if (!tsi) +return -ENOMEM ; + + da9052 =dev_get_drvdata (pdev->dev.parent); +if (da9052 ==NULL ) { +dev_err (tsi->da9052->dev,"Failed to get driver's data\n" ); + ret = -EINVAL ; + goto err_mem; + }
You might want to check this first, before allocating memory.
Quoted 4 lines
drivers/input/touchscreen/da9052_tsi.c new file +4
-0+ + input_dev =input_allocate_device (); +if (!input_dev) { +dev_err (tsi->da9052->dev,"Failed to allocate input device\n" );
drivers/input/touchscreen/da9052_tsi.c line 258
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+ ret = -ENOMEM ; + goto err_mem; + } + + tsi->ts_workq =create_singlethread_workqueue ("kda9052" ); +if (tsi->ts_workq ==NULL ) { +dev_err (tsi->da9052->dev,"Failed to create workqueue\n" ); + ret = -EINVAL ; + goto err_input; + }
Why do you need a separate workqueue? In mainline kernel we now have concurrency-managed workqueues so you should be able to use system workqueue.
Quoted 86 lines
drivers/input/touchscreen/da9052_tsi.c new file +86
-0+ +INIT_WORK (&tsi->ts_report_penup, da9052_ts_report_penup); + + tsi->da9052 = da9052; + + input_dev->id.version =0x0101 ; + input_dev->id.vendor =0x15B6 ; + input_dev->id.product =0x9052 ; + input_dev->id.bustype = tsi->da9052->bustype; + input_dev->name ="Dialog DA9052 TouchScreen Driver" ; + input_dev->dev.parent = &pdev->dev; + input_dev->open = da9052_ts_input_open; + input_dev->close = da9052_ts_input_close; +__set_bit (EV_ABS , input_dev->evbit); +__set_bit (EV_KEY , input_dev->evbit); +__set_bit (BTN_TOUCH , input_dev->keybit); +__set_bit (ABS_X , input_dev->absbit); +__set_bit (ABS_Y , input_dev->absbit); +__set_bit (ABS_PRESSURE , input_dev->absbit); + +input_set_abs_params (input_dev,ABS_X ,0 ,1023 ,0 ,0 ); +input_set_abs_params (input_dev,ABS_Y ,0 ,1023 ,0 ,0 ); +input_set_abs_params (input_dev,ABS_PRESSURE ,0 ,1023 ,0 ,0 ); + + tsi->dev = input_dev; +input_set_drvdata (input_dev, tsi); + + tsi->pendown = tsi->workschd =0 ; + + tsi->irq_pendwn =platform_get_irq_byname (pdev,"PENDWN" ); +if (tsi->irq_pendwn <0 ) { + ret = tsi->irq_pendwn; + goto err_workq; + } + + ret =request_threaded_irq (tsi->da9052->irq_base + tsi->irq_pendwn, +NULL , da9052_ts_pendwn_irq, +IRQF_TRIGGER_LOW |IRQF_ONESHOT , +"PENDWN" , tsi); +if (ret <0 ) { +dev_err (tsi->da9052->dev, +"Failed to register %s IRQ %d, error = %d\n" ,"PENDWN" , + tsi->da9052->irq_base + tsi->irq_pendwn, ret); + goto err_workq; + } + + tsi->irq_datardy =platform_get_irq_byname (pdev,"TSIRDY" ); +if (tsi->irq_datardy <0 ) { + ret = tsi->irq_datardy; + goto err_pendwn_irq; + } + + ret =request_threaded_irq (tsi->da9052->irq_base + tsi->irq_datardy, +NULL , da9052_ts_datardy_irq, +IRQF_TRIGGER_LOW |IRQF_ONESHOT , +"TSIRDY" , tsi); +if (ret <0 ) { +dev_err (tsi->da9052->dev, +"Failed to register %s IRQ %d, error = %d\n" ,"TSIRDY" , + tsi->da9052->irq_base + tsi->irq_datardy, ret); + goto err_pendwn_irq; + } + + ret =da9052_configure_tsi (tsi); +if (ret <0 ) + goto err_datardy_irq; + + ret =input_register_device (tsi->dev); +if (ret <0 ) + goto err_datardy_irq; + +platform_set_drvdata (pdev, tsi); + +return 0 ; + +err_datardy_irq: +free_irq (tsi->da9052->irq_base + tsi->irq_datardy, tsi); +err_pendwn_irq: +free_irq (tsi->da9052->irq_base + tsi->irq_pendwn, tsi); +err_workq: +destroy_workqueue (tsi->ts_workq); +err_input: +input_free_device (input_dev); +err_mem: +kfree (tsi); +return ret;
drivers/input/touchscreen/da9052_tsi.c line 354
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+} + +static int __devexit da9052_ts_remove(struct platform_device *pdev) +{ +struct da9052_tsi *tsi =platform_get_drvdata (pdev); +s32 ret; + + ret =da9052_reg_update (tsi->da9052,DA9052_TSI_CONT_A_REG ,1 <<0 ,0 ); +if (ret <0 ) +return ret;
You are doing this in da9052_ts_close() so you do not need to do it here.
drivers/input/touchscreen/da9052_tsi.c line 360
Quoted 6 lines
drivers/input/touchscreen/da9052_tsi.c new file +6
-0+ + ret =da9052_reg_write (tsi->da9052,DA9052_LDO9_REG ,0x19 ); +if (ret <0 ) +return ret; + +cancel_work_sync (&tsi->ts_report_penup);
This should be moved into da9052_ts_close().
Quoted 32 lines
drivers/input/touchscreen/da9052_tsi.c new file +30
-0+destroy_workqueue (tsi->ts_workq); + +free_irq (tsi->da9052->irq_base + tsi->irq_pendwn, tsi); +free_irq (tsi->da9052->irq_base + tsi->irq_datardy, tsi); + +input_unregister_device (tsi->dev); + +platform_set_drvdata (pdev,NULL ); + +kfree (tsi); + +return 0 ; +} + +static struct platform_driver da9052_tsi_driver = { + + .probe = da9052_ts_probe, + .remove =__devexit_p (da9052_ts_remove), + .driver = { + .name ="da9052-tsi" , + .owner =THIS_MODULE , + }, +}; + +static int __init da9052_ts_init (void ) +{ +return platform_driver_register (&da9052_tsi_driver); +} +module_init (da9052_ts_init); +
drivers/input/touchscreen/da9052_tsi.c line 400
Quoted 10 lines
drivers/input/touchscreen/da9052_tsi.c new file +10
-0+static void __exit da9052_ts_exit(void) +{ +platform_driver_unregister (&da9052_tsi_driver); +} +module_exit (da9052_ts_exit); + +MODULE_DESCRIPTION ("Touchscreen driver for Dialog Semiconductor DA9052" ); +MODULE_AUTHOR ("David Dajun Chen <[email protected]>" ); +MODULE_LICENSE ("GPL" ); +MODULE_ALIAS ("platform:da9052-tsi" );
Thanks.
Signature · 1 line
Dmitry