diff options
| author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-20 01:27:06 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-03-20 01:27:06 -0400 |
| commit | a952baa034ae7c2e4a66932005cbc7ebbccfe28d (patch) | |
| tree | ff5abe0c77f5b129946300677d9b57b00d926a1e /drivers/input/touchscreen | |
| parent | 5bab188a316718a26346cdb25c4cc6b319f8f907 (diff) | |
| parent | 97eb3f24352ec6632c2127b35d8087d2a809a9b9 (diff) | |
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (64 commits)
Input: tsc2005 - remove 'disable' sysfs attribute
Input: tsc2005 - add open/close
Input: tsc2005 - handle read errors from SPI layer
Input: tsc2005 - do not rearm timer in hardirq handler
Input: tsc2005 - don't use work for 'pen up' handling
Input: tsc2005 - do not use 0 in place of NULL
Input: tsc2005 - use true/false for boolean variables
Input: tsc2005 - hide selftest attribute if we can't reset
Input: tsc2005 - rework driver initialization code
Input: tsc2005 - set up bus type in input device
Input: tsc2005 - set up parent device
Input: tsc2005 - clear driver data after unbinding
Input: tsc2005 - add module description
Input: tsc2005 - remove driver banner message
Input: tsc2005 - remove incorrect module alias
Input: tsc2005 - convert to using dev_pm_ops
Input: tsc2005 - use spi_get/set_drvdata()
Input: introduce tsc2005 driver
Input: xen-kbdfront - move to drivers/input/misc
Input: xen-kbdfront - add grant reference for shared page
...
Diffstat (limited to 'drivers/input/touchscreen')
| -rw-r--r-- | drivers/input/touchscreen/Kconfig | 45 | ||||
| -rw-r--r-- | drivers/input/touchscreen/Makefile | 4 | ||||
| -rw-r--r-- | drivers/input/touchscreen/ad7877.c | 19 | ||||
| -rw-r--r-- | drivers/input/touchscreen/ad7879-spi.c | 17 | ||||
| -rw-r--r-- | drivers/input/touchscreen/ads7846.c | 16 | ||||
| -rw-r--r-- | drivers/input/touchscreen/atmel_mxt_ts.c | 1211 | ||||
| -rw-r--r-- | drivers/input/touchscreen/qt602240_ts.c | 1406 | ||||
| -rw-r--r-- | drivers/input/touchscreen/tsc2005.c | 756 | ||||
| -rw-r--r-- | drivers/input/touchscreen/wm831x-ts.c | 368 |
9 files changed, 2399 insertions, 1443 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 61834ae282e..112ec55f293 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig | |||
| @@ -86,6 +86,18 @@ config TOUCHSCREEN_AD7879_SPI | |||
| 86 | To compile this driver as a module, choose M here: the | 86 | To compile this driver as a module, choose M here: the |
| 87 | module will be called ad7879-spi. | 87 | module will be called ad7879-spi. |
| 88 | 88 | ||
| 89 | config TOUCHSCREEN_ATMEL_MXT | ||
| 90 | tristate "Atmel mXT I2C Touchscreen" | ||
| 91 | depends on I2C | ||
| 92 | help | ||
| 93 | Say Y here if you have Atmel mXT series I2C touchscreen, | ||
| 94 | such as AT42QT602240/ATMXT224, connected to your system. | ||
| 95 | |||
| 96 | If unsure, say N. | ||
| 97 | |||
| 98 | To compile this driver as a module, choose M here: the | ||
| 99 | module will be called atmel_mxt_ts. | ||
| 100 | |||
| 89 | config TOUCHSCREEN_BITSY | 101 | config TOUCHSCREEN_BITSY |
| 90 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" | 102 | tristate "Compaq iPAQ H3600 (Bitsy) touchscreen" |
| 91 | depends on SA1100_BITSY | 103 | depends on SA1100_BITSY |
| @@ -339,18 +351,6 @@ config TOUCHSCREEN_PENMOUNT | |||
| 339 | To compile this driver as a module, choose M here: the | 351 | To compile this driver as a module, choose M here: the |
| 340 | module will be called penmount. | 352 | module will be called penmount. |
| 341 | 353 | ||
| 342 | config TOUCHSCREEN_QT602240 | ||
| 343 | tristate "QT602240 I2C Touchscreen" | ||
| 344 | depends on I2C | ||
| 345 | help | ||
| 346 | Say Y here if you have the AT42QT602240/ATMXT224 I2C touchscreen | ||
| 347 | connected to your system. | ||
| 348 | |||
| 349 | If unsure, say N. | ||
| 350 | |||
| 351 | To compile this driver as a module, choose M here: the | ||
| 352 | module will be called qt602240_ts. | ||
| 353 | |||
| 354 | config TOUCHSCREEN_MIGOR | 354 | config TOUCHSCREEN_MIGOR |
| 355 | tristate "Renesas MIGO-R touchscreen" | 355 | tristate "Renesas MIGO-R touchscreen" |
| 356 | depends on SH_MIGOR && I2C | 356 | depends on SH_MIGOR && I2C |
| @@ -423,6 +423,16 @@ config TOUCHSCREEN_UCB1400 | |||
| 423 | To compile this driver as a module, choose M here: the | 423 | To compile this driver as a module, choose M here: the |
| 424 | module will be called ucb1400_ts. | 424 | module will be called ucb1400_ts. |
| 425 | 425 | ||
| 426 | config TOUCHSCREEN_WM831X | ||
| 427 | tristate "Support for WM831x touchscreen controllers" | ||
| 428 | depends on MFD_WM831X | ||
| 429 | help | ||
| 430 | This enables support for the touchscreen controller on the WM831x | ||
| 431 | series of PMICs. | ||
| 432 | |||
| 433 | To compile this driver as a module, choose M here: the | ||
| 434 | module will be called wm831x-ts. | ||
| 435 | |||
| 426 | config TOUCHSCREEN_WM97XX | 436 | config TOUCHSCREEN_WM97XX |
| 427 | tristate "Support for WM97xx AC97 touchscreen controllers" | 437 | tristate "Support for WM97xx AC97 touchscreen controllers" |
| 428 | depends on AC97_BUS | 438 | depends on AC97_BUS |
| @@ -629,6 +639,17 @@ config TOUCHSCREEN_TOUCHIT213 | |||
| 629 | To compile this driver as a module, choose M here: the | 639 | To compile this driver as a module, choose M here: the |
| 630 | module will be called touchit213. | 640 | module will be called touchit213. |
| 631 | 641 | ||
| 642 | config TOUCHSCREEN_TSC2005 | ||
| 643 | tristate "TSC2005 based touchscreens" | ||
| 644 | depends on SPI_MASTER | ||
| 645 | help | ||
| 646 | Say Y here if you have a TSC2005 based touchscreen. | ||
| 647 | |||
| 648 | If unsure, say N. | ||
| 649 | |||
| 650 | To compile this driver as a module, choose M here: the | ||
| 651 | module will be called tsc2005. | ||
| 652 | |||
| 632 | config TOUCHSCREEN_TSC2007 | 653 | config TOUCHSCREEN_TSC2007 |
| 633 | tristate "TSC2007 based touchscreens" | 654 | tristate "TSC2007 based touchscreens" |
| 634 | depends on I2C | 655 | depends on I2C |
diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 718bcc81495..ca94098d4c9 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile | |||
| @@ -12,6 +12,7 @@ obj-$(CONFIG_TOUCHSCREEN_AD7879) += ad7879.o | |||
| 12 | obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o | 12 | obj-$(CONFIG_TOUCHSCREEN_AD7879_I2C) += ad7879-i2c.o |
| 13 | obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o | 13 | obj-$(CONFIG_TOUCHSCREEN_AD7879_SPI) += ad7879-spi.o |
| 14 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o | 14 | obj-$(CONFIG_TOUCHSCREEN_ADS7846) += ads7846.o |
| 15 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_MXT) += atmel_mxt_ts.o | ||
| 15 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o | 16 | obj-$(CONFIG_TOUCHSCREEN_ATMEL_TSADCC) += atmel_tsadcc.o |
| 16 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o | 17 | obj-$(CONFIG_TOUCHSCREEN_BITSY) += h3600_ts_input.o |
| 17 | obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o | 18 | obj-$(CONFIG_TOUCHSCREEN_BU21013) += bu21013_ts.o |
| @@ -37,7 +38,6 @@ obj-$(CONFIG_TOUCHSCREEN_HTCPEN) += htcpen.o | |||
| 37 | obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o | 38 | obj-$(CONFIG_TOUCHSCREEN_USB_COMPOSITE) += usbtouchscreen.o |
| 38 | obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o | 39 | obj-$(CONFIG_TOUCHSCREEN_PCAP) += pcap_ts.o |
| 39 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o | 40 | obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o |
| 40 | obj-$(CONFIG_TOUCHSCREEN_QT602240) += qt602240_ts.o | ||
| 41 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o | 41 | obj-$(CONFIG_TOUCHSCREEN_S3C2410) += s3c2410_ts.o |
| 42 | obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o | 42 | obj-$(CONFIG_TOUCHSCREEN_ST1232) += st1232.o |
| 43 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o | 43 | obj-$(CONFIG_TOUCHSCREEN_STMPE) += stmpe-ts.o |
| @@ -45,9 +45,11 @@ obj-$(CONFIG_TOUCHSCREEN_TNETV107X) += tnetv107x-ts.o | |||
| 45 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o | 45 | obj-$(CONFIG_TOUCHSCREEN_TOUCHIT213) += touchit213.o |
| 46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o | 46 | obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o |
| 47 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o | 47 | obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o |
| 48 | obj-$(CONFIG_TOUCHSCREEN_TSC2005) += tsc2005.o | ||
| 48 | obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o | 49 | obj-$(CONFIG_TOUCHSCREEN_TSC2007) += tsc2007.o |
| 49 | obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o | 50 | obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o |
| 50 | obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o | 51 | obj-$(CONFIG_TOUCHSCREEN_WACOM_W8001) += wacom_w8001.o |
| 52 | obj-$(CONFIG_TOUCHSCREEN_WM831X) += wm831x-ts.o | ||
| 51 | obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o | 53 | obj-$(CONFIG_TOUCHSCREEN_WM97XX) += wm97xx-ts.o |
| 52 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o | 54 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9705) += wm9705.o |
| 53 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o | 55 | wm97xx-ts-$(CONFIG_TOUCHSCREEN_WM9712) += wm9712.o |
diff --git a/drivers/input/touchscreen/ad7877.c b/drivers/input/touchscreen/ad7877.c index a1952fcc083..714d4e0f9f9 100644 --- a/drivers/input/touchscreen/ad7877.c +++ b/drivers/input/touchscreen/ad7877.c | |||
| @@ -41,6 +41,7 @@ | |||
| 41 | #include <linux/delay.h> | 41 | #include <linux/delay.h> |
| 42 | #include <linux/input.h> | 42 | #include <linux/input.h> |
| 43 | #include <linux/interrupt.h> | 43 | #include <linux/interrupt.h> |
| 44 | #include <linux/pm.h> | ||
| 44 | #include <linux/slab.h> | 45 | #include <linux/slab.h> |
| 45 | #include <linux/spi/spi.h> | 46 | #include <linux/spi/spi.h> |
| 46 | #include <linux/spi/ad7877.h> | 47 | #include <linux/spi/ad7877.h> |
| @@ -826,39 +827,37 @@ static int __devexit ad7877_remove(struct spi_device *spi) | |||
| 826 | return 0; | 827 | return 0; |
| 827 | } | 828 | } |
| 828 | 829 | ||
| 829 | #ifdef CONFIG_PM | 830 | #ifdef CONFIG_PM_SLEEP |
| 830 | static int ad7877_suspend(struct spi_device *spi, pm_message_t message) | 831 | static int ad7877_suspend(struct device *dev) |
| 831 | { | 832 | { |
| 832 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | 833 | struct ad7877 *ts = dev_get_drvdata(dev); |
| 833 | 834 | ||
| 834 | ad7877_disable(ts); | 835 | ad7877_disable(ts); |
| 835 | 836 | ||
| 836 | return 0; | 837 | return 0; |
| 837 | } | 838 | } |
| 838 | 839 | ||
| 839 | static int ad7877_resume(struct spi_device *spi) | 840 | static int ad7877_resume(struct device *dev) |
| 840 | { | 841 | { |
| 841 | struct ad7877 *ts = dev_get_drvdata(&spi->dev); | 842 | struct ad7877 *ts = dev_get_drvdata(dev); |
| 842 | 843 | ||
| 843 | ad7877_enable(ts); | 844 | ad7877_enable(ts); |
| 844 | 845 | ||
| 845 | return 0; | 846 | return 0; |
| 846 | } | 847 | } |
| 847 | #else | ||
| 848 | #define ad7877_suspend NULL | ||
| 849 | #define ad7877_resume NULL | ||
| 850 | #endif | 848 | #endif |
| 851 | 849 | ||
| 850 | static SIMPLE_DEV_PM_OPS(ad7877_pm, ad7877_suspend, ad7877_resume); | ||
| 851 | |||
| 852 | static struct spi_driver ad7877_driver = { | 852 | static struct spi_driver ad7877_driver = { |
| 853 | .driver = { | 853 | .driver = { |
| 854 | .name = "ad7877", | 854 | .name = "ad7877", |
| 855 | .bus = &spi_bus_type, | 855 | .bus = &spi_bus_type, |
| 856 | .owner = THIS_MODULE, | 856 | .owner = THIS_MODULE, |
| 857 | .pm = &ad7877_pm, | ||
| 857 | }, | 858 | }, |
| 858 | .probe = ad7877_probe, | 859 | .probe = ad7877_probe, |
| 859 | .remove = __devexit_p(ad7877_remove), | 860 | .remove = __devexit_p(ad7877_remove), |
| 860 | .suspend = ad7877_suspend, | ||
| 861 | .resume = ad7877_resume, | ||
| 862 | }; | 861 | }; |
| 863 | 862 | ||
| 864 | static int __init ad7877_init(void) | 863 | static int __init ad7877_init(void) |
diff --git a/drivers/input/touchscreen/ad7879-spi.c b/drivers/input/touchscreen/ad7879-spi.c index 59c6e68c432..ddf732f3caf 100644 --- a/drivers/input/touchscreen/ad7879-spi.c +++ b/drivers/input/touchscreen/ad7879-spi.c | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | */ | 7 | */ |
| 8 | 8 | ||
| 9 | #include <linux/input.h> /* BUS_SPI */ | 9 | #include <linux/input.h> /* BUS_SPI */ |
| 10 | #include <linux/pm.h> | ||
| 10 | #include <linux/spi/spi.h> | 11 | #include <linux/spi/spi.h> |
| 11 | 12 | ||
| 12 | #include "ad7879.h" | 13 | #include "ad7879.h" |
| @@ -20,9 +21,10 @@ | |||
| 20 | #define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) | 21 | #define AD7879_WRITECMD(reg) (AD7879_CMD(reg)) |
| 21 | #define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) | 22 | #define AD7879_READCMD(reg) (AD7879_CMD(reg) | AD7879_CMD_READ) |
| 22 | 23 | ||
| 23 | #ifdef CONFIG_PM | 24 | #ifdef CONFIG_PM_SLEEP |
| 24 | static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) | 25 | static int ad7879_spi_suspend(struct device *dev) |
| 25 | { | 26 | { |
| 27 | struct spi_device *spi = to_spi_device(dev); | ||
| 26 | struct ad7879 *ts = spi_get_drvdata(spi); | 28 | struct ad7879 *ts = spi_get_drvdata(spi); |
| 27 | 29 | ||
| 28 | ad7879_suspend(ts); | 30 | ad7879_suspend(ts); |
| @@ -30,19 +32,19 @@ static int ad7879_spi_suspend(struct spi_device *spi, pm_message_t message) | |||
| 30 | return 0; | 32 | return 0; |
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | static int ad7879_spi_resume(struct spi_device *spi) | 35 | static int ad7879_spi_resume(struct device *dev) |
| 34 | { | 36 | { |
| 37 | struct spi_device *spi = to_spi_device(dev); | ||
| 35 | struct ad7879 *ts = spi_get_drvdata(spi); | 38 | struct ad7879 *ts = spi_get_drvdata(spi); |
| 36 | 39 | ||
| 37 | ad7879_resume(ts); | 40 | ad7879_resume(ts); |
| 38 | 41 | ||
| 39 | return 0; | 42 | return 0; |
| 40 | } | 43 | } |
| 41 | #else | ||
| 42 | # define ad7879_spi_suspend NULL | ||
| 43 | # define ad7879_spi_resume NULL | ||
| 44 | #endif | 44 | #endif |
| 45 | 45 | ||
| 46 | static SIMPLE_DEV_PM_OPS(ad7879_spi_pm, ad7879_spi_suspend, ad7879_spi_resume); | ||
| 47 | |||
| 46 | /* | 48 | /* |
| 47 | * ad7879_read/write are only used for initial setup and for sysfs controls. | 49 | * ad7879_read/write are only used for initial setup and for sysfs controls. |
| 48 | * The main traffic is done in ad7879_collect(). | 50 | * The main traffic is done in ad7879_collect(). |
| @@ -173,11 +175,10 @@ static struct spi_driver ad7879_spi_driver = { | |||
| 173 | .name = "ad7879", | 175 | .name = "ad7879", |
| 174 | .bus = &spi_bus_type, | 176 | .bus = &spi_bus_type, |
| 175 | .owner = THIS_MODULE, | 177 | .owner = THIS_MODULE, |
| 178 | .pm = &ad7879_spi_pm, | ||
| 176 | }, | 179 | }, |
| 177 | .probe = ad7879_spi_probe, | 180 | .probe = ad7879_spi_probe, |
| 178 | .remove = __devexit_p(ad7879_spi_remove), | 181 | .remove = __devexit_p(ad7879_spi_remove), |
| 179 | .suspend = ad7879_spi_suspend, | ||
| 180 | .resume = ad7879_spi_resume, | ||
| 181 | }; | 182 | }; |
| 182 | 183 | ||
| 183 | static int __init ad7879_spi_init(void) | 184 | static int __init ad7879_spi_init(void) |
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 4bf2316e328..c24946f5125 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c | |||
| @@ -26,6 +26,7 @@ | |||
| 26 | #include <linux/input.h> | 26 | #include <linux/input.h> |
| 27 | #include <linux/interrupt.h> | 27 | #include <linux/interrupt.h> |
| 28 | #include <linux/slab.h> | 28 | #include <linux/slab.h> |
| 29 | #include <linux/pm.h> | ||
| 29 | #include <linux/gpio.h> | 30 | #include <linux/gpio.h> |
| 30 | #include <linux/spi/spi.h> | 31 | #include <linux/spi/spi.h> |
| 31 | #include <linux/spi/ads7846.h> | 32 | #include <linux/spi/ads7846.h> |
| @@ -892,9 +893,10 @@ static irqreturn_t ads7846_irq(int irq, void *handle) | |||
| 892 | return IRQ_HANDLED; | 893 | return IRQ_HANDLED; |
| 893 | } | 894 | } |
| 894 | 895 | ||
| 895 | static int ads7846_suspend(struct spi_device *spi, pm_message_t message) | 896 | #ifdef CONFIG_PM_SLEEP |
| 897 | static int ads7846_suspend(struct device *dev) | ||
| 896 | { | 898 | { |
| 897 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); | 899 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 898 | 900 | ||
| 899 | mutex_lock(&ts->lock); | 901 | mutex_lock(&ts->lock); |
| 900 | 902 | ||
| @@ -914,9 +916,9 @@ static int ads7846_suspend(struct spi_device *spi, pm_message_t message) | |||
| 914 | return 0; | 916 | return 0; |
| 915 | } | 917 | } |
| 916 | 918 | ||
| 917 | static int ads7846_resume(struct spi_device *spi) | 919 | static int ads7846_resume(struct device *dev) |
| 918 | { | 920 | { |
| 919 | struct ads7846 *ts = dev_get_drvdata(&spi->dev); | 921 | struct ads7846 *ts = dev_get_drvdata(dev); |
| 920 | 922 | ||
| 921 | mutex_lock(&ts->lock); | 923 | mutex_lock(&ts->lock); |
| 922 | 924 | ||
| @@ -935,6 +937,9 @@ static int ads7846_resume(struct spi_device *spi) | |||
| 935 | 937 | ||
| 936 | return 0; | 938 | return 0; |
| 937 | } | 939 | } |
| 940 | #endif | ||
| 941 | |||
| 942 | static SIMPLE_DEV_PM_OPS(ads7846_pm, ads7846_suspend, ads7846_resume); | ||
| 938 | 943 | ||
| 939 | static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) | 944 | static int __devinit ads7846_setup_pendown(struct spi_device *spi, struct ads7846 *ts) |
| 940 | { | 945 | { |
| @@ -1408,11 +1413,10 @@ static struct spi_driver ads7846_driver = { | |||
| 1408 | .name = "ads7846", | 1413 | .name = "ads7846", |
| 1409 | .bus = &spi_bus_type, | 1414 | .bus = &spi_bus_type, |
| 1410 | .owner = THIS_MODULE, | 1415 | .owner = THIS_MODULE, |
| 1416 | .pm = &ads7846_pm, | ||
| 1411 | }, | 1417 | }, |
| 1412 | .probe = ads7846_probe, | 1418 | .probe = ads7846_probe, |
| 1413 | .remove = __devexit_p(ads7846_remove), | 1419 | .remove = __devexit_p(ads7846_remove), |
| 1414 | .suspend = ads7846_suspend, | ||
| 1415 | .resume = ads7846_resume, | ||
| 1416 | }; | 1420 | }; |
| 1417 | 1421 | ||
| 1418 | static int __init ads7846_init(void) | 1422 | static int __init ads7846_init(void) |
diff --git a/drivers/input/touchscreen/atmel_mxt_ts.c b/drivers/input/touchscreen/atmel_mxt_ts.c new file mode 100644 index 00000000000..4012436633b --- /dev/null +++ b/drivers/input/touchscreen/atmel_mxt_ts.c | |||
| @@ -0,0 +1,1211 @@ | |||
| 1 | /* | ||
| 2 | * Atmel maXTouch Touchscreen driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | ||
| 5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the | ||
| 9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/delay.h> | ||
| 17 | #include <linux/firmware.h> | ||
| 18 | #include <linux/i2c.h> | ||
| 19 | #include <linux/i2c/atmel_mxt_ts.h> | ||
| 20 | #include <linux/input.h> | ||
| 21 | #include <linux/interrupt.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | |||
| 24 | /* Version */ | ||
| 25 | #define MXT_VER_20 20 | ||
| 26 | #define MXT_VER_21 21 | ||
| 27 | #define MXT_VER_22 22 | ||
| 28 | |||
| 29 | /* Slave addresses */ | ||
| 30 | #define MXT_APP_LOW 0x4a | ||
| 31 | #define MXT_APP_HIGH 0x4b | ||
| 32 | #define MXT_BOOT_LOW 0x24 | ||
| 33 | #define MXT_BOOT_HIGH 0x25 | ||
| 34 | |||
| 35 | /* Firmware */ | ||
| 36 | #define MXT_FW_NAME "maxtouch.fw" | ||
| 37 | |||
| 38 | /* Registers */ | ||
| 39 | #define MXT_FAMILY_ID 0x00 | ||
| 40 | #define MXT_VARIANT_ID 0x01 | ||
| 41 | #define MXT_VERSION 0x02 | ||
| 42 | #define MXT_BUILD 0x03 | ||
| 43 | #define MXT_MATRIX_X_SIZE 0x04 | ||
| 44 | #define MXT_MATRIX_Y_SIZE 0x05 | ||
| 45 | #define MXT_OBJECT_NUM 0x06 | ||
| 46 | #define MXT_OBJECT_START 0x07 | ||
| 47 | |||
| 48 | #define MXT_OBJECT_SIZE 6 | ||
| 49 | |||
| 50 | /* Object types */ | ||
| 51 | #define MXT_DEBUG_DIAGNOSTIC 37 | ||
| 52 | #define MXT_GEN_MESSAGE 5 | ||
| 53 | #define MXT_GEN_COMMAND 6 | ||
| 54 | #define MXT_GEN_POWER 7 | ||
| 55 | #define MXT_GEN_ACQUIRE 8 | ||
| 56 | #define MXT_TOUCH_MULTI 9 | ||
| 57 | #define MXT_TOUCH_KEYARRAY 15 | ||
| 58 | #define MXT_TOUCH_PROXIMITY 23 | ||
| 59 | #define MXT_PROCI_GRIPFACE 20 | ||
| 60 | #define MXT_PROCG_NOISE 22 | ||
| 61 | #define MXT_PROCI_ONETOUCH 24 | ||
| 62 | #define MXT_PROCI_TWOTOUCH 27 | ||
| 63 | #define MXT_PROCI_GRIP 40 | ||
| 64 | #define MXT_PROCI_PALM 41 | ||
| 65 | #define MXT_SPT_COMMSCONFIG 18 | ||
| 66 | #define MXT_SPT_GPIOPWM 19 | ||
| 67 | #define MXT_SPT_SELFTEST 25 | ||
| 68 | #define MXT_SPT_CTECONFIG 28 | ||
| 69 | #define MXT_SPT_USERDATA 38 | ||
| 70 | #define MXT_SPT_DIGITIZER 43 | ||
| 71 | #define MXT_SPT_MESSAGECOUNT 44 | ||
| 72 | |||
| 73 | /* MXT_GEN_COMMAND field */ | ||
| 74 | #define MXT_COMMAND_RESET 0 | ||
| 75 | #define MXT_COMMAND_BACKUPNV 1 | ||
| 76 | #define MXT_COMMAND_CALIBRATE 2 | ||
| 77 | #define MXT_COMMAND_REPORTALL 3 | ||
| 78 | #define MXT_COMMAND_DIAGNOSTIC 5 | ||
| 79 | |||
| 80 | /* MXT_GEN_POWER field */ | ||
| 81 | #define MXT_POWER_IDLEACQINT 0 | ||
| 82 | #define MXT_POWER_ACTVACQINT 1 | ||
| 83 | #define MXT_POWER_ACTV2IDLETO 2 | ||
| 84 | |||
| 85 | /* MXT_GEN_ACQUIRE field */ | ||
| 86 | #define MXT_ACQUIRE_CHRGTIME 0 | ||
| 87 | #define MXT_ACQUIRE_TCHDRIFT 2 | ||
| 88 | #define MXT_ACQUIRE_DRIFTST 3 | ||
| 89 | #define MXT_ACQUIRE_TCHAUTOCAL 4 | ||
| 90 | #define MXT_ACQUIRE_SYNC 5 | ||
| 91 | #define MXT_ACQUIRE_ATCHCALST 6 | ||
| 92 | #define MXT_ACQUIRE_ATCHCALSTHR 7 | ||
| 93 | |||
| 94 | /* MXT_TOUCH_MULTI field */ | ||
| 95 | #define MXT_TOUCH_CTRL 0 | ||
| 96 | #define MXT_TOUCH_XORIGIN 1 | ||
| 97 | #define MXT_TOUCH_YORIGIN 2 | ||
| 98 | #define MXT_TOUCH_XSIZE 3 | ||
| 99 | #define MXT_TOUCH_YSIZE 4 | ||
| 100 | #define MXT_TOUCH_BLEN 6 | ||
| 101 | #define MXT_TOUCH_TCHTHR 7 | ||
| 102 | #define MXT_TOUCH_TCHDI 8 | ||
| 103 | #define MXT_TOUCH_ORIENT 9 | ||
| 104 | #define MXT_TOUCH_MOVHYSTI 11 | ||
| 105 | #define MXT_TOUCH_MOVHYSTN 12 | ||
| 106 | #define MXT_TOUCH_NUMTOUCH 14 | ||
| 107 | #define MXT_TOUCH_MRGHYST 15 | ||
| 108 | #define MXT_TOUCH_MRGTHR 16 | ||
| 109 | #define MXT_TOUCH_AMPHYST 17 | ||
| 110 | #define MXT_TOUCH_XRANGE_LSB 18 | ||
| 111 | #define MXT_TOUCH_XRANGE_MSB 19 | ||
| 112 | #define MXT_TOUCH_YRANGE_LSB 20 | ||
| 113 | #define MXT_TOUCH_YRANGE_MSB 21 | ||
| 114 | #define MXT_TOUCH_XLOCLIP 22 | ||
| 115 | #define MXT_TOUCH_XHICLIP 23 | ||
| 116 | #define MXT_TOUCH_YLOCLIP 24 | ||
| 117 | #define MXT_TOUCH_YHICLIP 25 | ||
| 118 | #define MXT_TOUCH_XEDGECTRL 26 | ||
| 119 | #define MXT_TOUCH_XEDGEDIST 27 | ||
| 120 | #define MXT_TOUCH_YEDGECTRL 28 | ||
| 121 | #define MXT_TOUCH_YEDGEDIST 29 | ||
| 122 | #define MXT_TOUCH_JUMPLIMIT 30 | ||
| 123 | |||
| 124 | /* MXT_PROCI_GRIPFACE field */ | ||
| 125 | #define MXT_GRIPFACE_CTRL 0 | ||
| 126 | #define MXT_GRIPFACE_XLOGRIP 1 | ||
| 127 | #define MXT_GRIPFACE_XHIGRIP 2 | ||
| 128 | #define MXT_GRIPFACE_YLOGRIP 3 | ||
| 129 | #define MXT_GRIPFACE_YHIGRIP 4 | ||
| 130 | #define MXT_GRIPFACE_MAXTCHS 5 | ||
| 131 | #define MXT_GRIPFACE_SZTHR1 7 | ||
| 132 | #define MXT_GRIPFACE_SZTHR2 8 | ||
| 133 | #define MXT_GRIPFACE_SHPTHR1 9 | ||
| 134 | #define MXT_GRIPFACE_SHPTHR2 10 | ||
| 135 | #define MXT_GRIPFACE_SUPEXTTO 11 | ||
| 136 | |||
| 137 | /* MXT_PROCI_NOISE field */ | ||
| 138 | #define MXT_NOISE_CTRL 0 | ||
| 139 | #define MXT_NOISE_OUTFLEN 1 | ||
| 140 | #define MXT_NOISE_GCAFUL_LSB 3 | ||
| 141 | #define MXT_NOISE_GCAFUL_MSB 4 | ||
| 142 | #define MXT_NOISE_GCAFLL_LSB 5 | ||
| 143 | #define MXT_NOISE_GCAFLL_MSB 6 | ||
| 144 | #define MXT_NOISE_ACTVGCAFVALID 7 | ||
| 145 | #define MXT_NOISE_NOISETHR 8 | ||
| 146 | #define MXT_NOISE_FREQHOPSCALE 10 | ||
| 147 | #define MXT_NOISE_FREQ0 11 | ||
| 148 | #define MXT_NOISE_FREQ1 12 | ||
| 149 | #define MXT_NOISE_FREQ2 13 | ||
| 150 | #define MXT_NOISE_FREQ3 14 | ||
| 151 | #define MXT_NOISE_FREQ4 15 | ||
| 152 | #define MXT_NOISE_IDLEGCAFVALID 16 | ||
| 153 | |||
| 154 | /* MXT_SPT_COMMSCONFIG */ | ||
| 155 | #define MXT_COMMS_CTRL 0 | ||
| 156 | #define MXT_COMMS_CMD 1 | ||
| 157 | |||
| 158 | /* MXT_SPT_CTECONFIG field */ | ||
| 159 | #define MXT_CTE_CTRL 0 | ||
| 160 | #define MXT_CTE_CMD 1 | ||
| 161 | #define MXT_CTE_MODE 2 | ||
| 162 | #define MXT_CTE_IDLEGCAFDEPTH 3 | ||
| 163 | #define MXT_CTE_ACTVGCAFDEPTH 4 | ||
| 164 | #define MXT_CTE_VOLTAGE 5 | ||
| 165 | |||
| 166 | #define MXT_VOLTAGE_DEFAULT 2700000 | ||
| 167 | #define MXT_VOLTAGE_STEP 10000 | ||
| 168 | |||
| 169 | /* Define for MXT_GEN_COMMAND */ | ||
| 170 | #define MXT_BOOT_VALUE 0xa5 | ||
| 171 | #define MXT_BACKUP_VALUE 0x55 | ||
| 172 | #define MXT_BACKUP_TIME 25 /* msec */ | ||
| 173 | #define MXT_RESET_TIME 65 /* msec */ | ||
| 174 | |||
| 175 | #define MXT_FWRESET_TIME 175 /* msec */ | ||
| 176 | |||
| 177 | /* Command to unlock bootloader */ | ||
| 178 | #define MXT_UNLOCK_CMD_MSB 0xaa | ||
| 179 | #define MXT_UNLOCK_CMD_LSB 0xdc | ||
| 180 | |||
| 181 | /* Bootloader mode status */ | ||
| 182 | #define MXT_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ | ||
| 183 | #define MXT_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ | ||
| 184 | #define MXT_FRAME_CRC_CHECK 0x02 | ||
| 185 | #define MXT_FRAME_CRC_FAIL 0x03 | ||
| 186 | #define MXT_FRAME_CRC_PASS 0x04 | ||
| 187 | #define MXT_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ | ||
| 188 | #define MXT_BOOT_STATUS_MASK 0x3f | ||
| 189 | |||
| 190 | /* Touch status */ | ||
| 191 | #define MXT_SUPPRESS (1 << 1) | ||
| 192 | #define MXT_AMP (1 << 2) | ||
| 193 | #define MXT_VECTOR (1 << 3) | ||
| 194 | #define MXT_MOVE (1 << 4) | ||
| 195 | #define MXT_RELEASE (1 << 5) | ||
| 196 | #define MXT_PRESS (1 << 6) | ||
| 197 | #define MXT_DETECT (1 << 7) | ||
| 198 | |||
| 199 | /* Touchscreen absolute values */ | ||
| 200 | #define MXT_MAX_XC 0x3ff | ||
| 201 | #define MXT_MAX_YC 0x3ff | ||
| 202 | #define MXT_MAX_AREA 0xff | ||
| 203 | |||
| 204 | #define MXT_MAX_FINGER 10 | ||
| 205 | |||
| 206 | struct mxt_info { | ||
| 207 | u8 family_id; | ||
| 208 | u8 variant_id; | ||
| 209 | u8 version; | ||
| 210 | u8 build; | ||
| 211 | u8 matrix_xsize; | ||
| 212 | u8 matrix_ysize; | ||
| 213 | u8 object_num; | ||
| 214 | }; | ||
| 215 | |||
| 216 | struct mxt_object { | ||
| 217 | u8 type; | ||
| 218 | u16 start_address; | ||
| 219 | u8 size; | ||
| 220 | u8 instances; | ||
| 221 | u8 num_report_ids; | ||
| 222 | |||
| 223 | /* to map object and message */ | ||
| 224 | u8 max_reportid; | ||
| 225 | }; | ||
| 226 | |||
| 227 | struct mxt_message { | ||
| 228 | u8 reportid; | ||
| 229 | u8 message[7]; | ||
| 230 | u8 checksum; | ||
| 231 | }; | ||
| 232 | |||
| 233 | struct mxt_finger { | ||
| 234 | int status; | ||
| 235 | int x; | ||
| 236 | int y; | ||
| 237 | int area; | ||
| 238 | }; | ||
| 239 | |||
| 240 | /* Each client has this additional data */ | ||
| 241 | struct mxt_data { | ||
| 242 | struct i2c_client *client; | ||
| 243 | struct input_dev *input_dev; | ||
| 244 | const struct mxt_platform_data *pdata; | ||
| 245 | struct mxt_object *object_table; | ||
| 246 | struct mxt_info info; | ||
| 247 | struct mxt_finger finger[MXT_MAX_FINGER]; | ||
| 248 | unsigned int irq; | ||
| 249 | }; | ||
| 250 | |||
| 251 | static bool mxt_object_readable(unsigned int type) | ||
| 252 | { | ||
| 253 | switch (type) { | ||
| 254 | case MXT_GEN_MESSAGE: | ||
| 255 | case MXT_GEN_COMMAND: | ||
| 256 | case MXT_GEN_POWER: | ||
| 257 | case MXT_GEN_ACQUIRE: | ||
| 258 | case MXT_TOUCH_MULTI: | ||
| 259 | case MXT_TOUCH_KEYARRAY: | ||
| 260 | case MXT_TOUCH_PROXIMITY: | ||
| 261 | case MXT_PROCI_GRIPFACE: | ||
| 262 | case MXT_PROCG_NOISE: | ||
| 263 | case MXT_PROCI_ONETOUCH: | ||
| 264 | case MXT_PROCI_TWOTOUCH: | ||
| 265 | case MXT_PROCI_GRIP: | ||
| 266 | case MXT_PROCI_PALM: | ||
| 267 | case MXT_SPT_COMMSCONFIG: | ||
| 268 | case MXT_SPT_GPIOPWM: | ||
| 269 | case MXT_SPT_SELFTEST: | ||
| 270 | case MXT_SPT_CTECONFIG: | ||
| 271 | case MXT_SPT_USERDATA: | ||
| 272 | return true; | ||
| 273 | default: | ||
| 274 | return false; | ||
| 275 | } | ||
| 276 | } | ||
| 277 | |||
| 278 | static bool mxt_object_writable(unsigned int type) | ||
| 279 | { | ||
| 280 | switch (type) { | ||
| 281 | case MXT_GEN_COMMAND: | ||
| 282 | case MXT_GEN_POWER: | ||
| 283 | case MXT_GEN_ACQUIRE: | ||
| 284 | case MXT_TOUCH_MULTI: | ||
| 285 | case MXT_TOUCH_KEYARRAY: | ||
| 286 | case MXT_TOUCH_PROXIMITY: | ||
| 287 | case MXT_PROCI_GRIPFACE: | ||
| 288 | case MXT_PROCG_NOISE: | ||
| 289 | case MXT_PROCI_ONETOUCH: | ||
| 290 | case MXT_PROCI_TWOTOUCH: | ||
| 291 | case MXT_PROCI_GRIP: | ||
| 292 | case MXT_PROCI_PALM: | ||
| 293 | case MXT_SPT_GPIOPWM: | ||
| 294 | case MXT_SPT_SELFTEST: | ||
| 295 | case MXT_SPT_CTECONFIG: | ||
| 296 | return true; | ||
| 297 | default: | ||
| 298 | return false; | ||
| 299 | } | ||
| 300 | } | ||
| 301 | |||
| 302 | static void mxt_dump_message(struct device *dev, | ||
| 303 | struct mxt_message *message) | ||
| 304 | { | ||
| 305 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); | ||
| 306 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); | ||
| 307 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); | ||
| 308 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); | ||
| 309 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); | ||
| 310 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); | ||
| 311 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); | ||
| 312 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); | ||
| 313 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); | ||
| 314 | } | ||
| 315 | |||
| 316 | static int mxt_check_bootloader(struct i2c_client *client, | ||
| 317 | unsigned int state) | ||
| 318 | { | ||
| 319 | u8 val; | ||
| 320 | |||
| 321 | recheck: | ||
| 322 | if (i2c_master_recv(client, &val, 1) != 1) { | ||
| 323 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); | ||
| 324 | return -EIO; | ||
| 325 | } | ||
| 326 | |||
| 327 | switch (state) { | ||
| 328 | case MXT_WAITING_BOOTLOAD_CMD: | ||
| 329 | case MXT_WAITING_FRAME_DATA: | ||
| 330 | val &= ~MXT_BOOT_STATUS_MASK; | ||
| 331 | break; | ||
| 332 | case MXT_FRAME_CRC_PASS: | ||
| 333 | if (val == MXT_FRAME_CRC_CHECK) | ||
| 334 | goto recheck; | ||
| 335 | break; | ||
| 336 | default: | ||
| 337 | return -EINVAL; | ||
| 338 | } | ||
| 339 | |||
| 340 | if (val != state) { | ||
| 341 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); | ||
| 342 | return -EINVAL; | ||
| 343 | } | ||
| 344 | |||
| 345 | return 0; | ||
| 346 | } | ||
| 347 | |||
| 348 | static int mxt_unlock_bootloader(struct i2c_client *client) | ||
| 349 | { | ||
| 350 | u8 buf[2]; | ||
| 351 | |||
| 352 | buf[0] = MXT_UNLOCK_CMD_LSB; | ||
| 353 | buf[1] = MXT_UNLOCK_CMD_MSB; | ||
| 354 | |||
| 355 | if (i2c_master_send(client, buf, 2) != 2) { | ||
| 356 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 357 | return -EIO; | ||
| 358 | } | ||
| 359 | |||
| 360 | return 0; | ||
| 361 | } | ||
| 362 | |||
| 363 | static int mxt_fw_write(struct i2c_client *client, | ||
| 364 | const u8 *data, unsigned int frame_size) | ||
| 365 | { | ||
| 366 | if (i2c_master_send(client, data, frame_size) != frame_size) { | ||
| 367 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 368 | return -EIO; | ||
| 369 | } | ||
| 370 | |||
| 371 | return 0; | ||
| 372 | } | ||
| 373 | |||
| 374 | static int __mxt_read_reg(struct i2c_client *client, | ||
| 375 | u16 reg, u16 len, void *val) | ||
| 376 | { | ||
| 377 | struct i2c_msg xfer[2]; | ||
| 378 | u8 buf[2]; | ||
| 379 | |||
| 380 | buf[0] = reg & 0xff; | ||
| 381 | buf[1] = (reg >> 8) & 0xff; | ||
| 382 | |||
| 383 | /* Write register */ | ||
| 384 | xfer[0].addr = client->addr; | ||
| 385 | xfer[0].flags = 0; | ||
| 386 | xfer[0].len = 2; | ||
| 387 | xfer[0].buf = buf; | ||
| 388 | |||
| 389 | /* Read data */ | ||
| 390 | xfer[1].addr = client->addr; | ||
| 391 | xfer[1].flags = I2C_M_RD; | ||
| 392 | xfer[1].len = len; | ||
| 393 | xfer[1].buf = val; | ||
| 394 | |||
| 395 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { | ||
| 396 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); | ||
| 397 | return -EIO; | ||
| 398 | } | ||
| 399 | |||
| 400 | return 0; | ||
| 401 | } | ||
| 402 | |||
| 403 | static int mxt_read_reg(struct i2c_client *client, u16 reg, u8 *val) | ||
| 404 | { | ||
| 405 | return __mxt_read_reg(client, reg, 1, val); | ||
| 406 | } | ||
| 407 | |||
| 408 | static int mxt_write_reg(struct i2c_client *client, u16 reg, u8 val) | ||
| 409 | { | ||
| 410 | u8 buf[3]; | ||
| 411 | |||
| 412 | buf[0] = reg & 0xff; | ||
| 413 | buf[1] = (reg >> 8) & 0xff; | ||
| 414 | buf[2] = val; | ||
| 415 | |||
| 416 | if (i2c_master_send(client, buf, 3) != 3) { | ||
| 417 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 418 | return -EIO; | ||
| 419 | } | ||
| 420 | |||
| 421 | return 0; | ||
| 422 | } | ||
| 423 | |||
| 424 | static int mxt_read_object_table(struct i2c_client *client, | ||
| 425 | u16 reg, u8 *object_buf) | ||
| 426 | { | ||
| 427 | return __mxt_read_reg(client, reg, MXT_OBJECT_SIZE, | ||
| 428 | object_buf); | ||
| 429 | } | ||
| 430 | |||
| 431 | static struct mxt_object * | ||
| 432 | mxt_get_object(struct mxt_data *data, u8 type) | ||
| 433 | { | ||
| 434 | struct mxt_object *object; | ||
| 435 | int i; | ||
| 436 | |||
| 437 | for (i = 0; i < data->info.object_num; i++) { | ||
| 438 | object = data->object_table + i; | ||
| 439 | if (object->type == type) | ||
| 440 | return object; | ||
| 441 | } | ||
| 442 | |||
| 443 | dev_err(&data->client->dev, "Invalid object type\n"); | ||
| 444 | return NULL; | ||
| 445 | } | ||
| 446 | |||
| 447 | static int mxt_read_message(struct mxt_data *data, | ||
| 448 | struct mxt_message *message) | ||
| 449 | { | ||
| 450 | struct mxt_object *object; | ||
| 451 | u16 reg; | ||
| 452 | |||
| 453 | object = mxt_get_object(data, MXT_GEN_MESSAGE); | ||
| 454 | if (!object) | ||
| 455 | return -EINVAL; | ||
| 456 | |||
| 457 | reg = object->start_address; | ||
| 458 | return __mxt_read_reg(data->client, reg, | ||
| 459 | sizeof(struct mxt_message), message); | ||
| 460 | } | ||
| 461 | |||
| 462 | static int mxt_read_object(struct mxt_data *data, | ||
| 463 | u8 type, u8 offset, u8 *val) | ||
| 464 | { | ||
| 465 | struct mxt_object *object; | ||
| 466 | u16 reg; | ||
| 467 | |||
| 468 | object = mxt_get_object(data, type); | ||
| 469 | if (!object) | ||
| 470 | return -EINVAL; | ||
| 471 | |||
| 472 | reg = object->start_address; | ||
| 473 | return __mxt_read_reg(data->client, reg + offset, 1, val); | ||
| 474 | } | ||
| 475 | |||
| 476 | static int mxt_write_object(struct mxt_data *data, | ||
| 477 | u8 type, u8 offset, u8 val) | ||
| 478 | { | ||
| 479 | struct mxt_object *object; | ||
| 480 | u16 reg; | ||
| 481 | |||
| 482 | object = mxt_get_object(data, type); | ||
| 483 | if (!object) | ||
| 484 | return -EINVAL; | ||
| 485 | |||
| 486 | reg = object->start_address; | ||
| 487 | return mxt_write_reg(data->client, reg + offset, val); | ||
| 488 | } | ||
| 489 | |||
| 490 | static void mxt_input_report(struct mxt_data *data, int single_id) | ||
| 491 | { | ||
| 492 | struct mxt_finger *finger = data->finger; | ||
| 493 | struct input_dev *input_dev = data->input_dev; | ||
| 494 | int status = finger[single_id].status; | ||
| 495 | int finger_num = 0; | ||
| 496 | int id; | ||
| 497 | |||
| 498 | for (id = 0; id < MXT_MAX_FINGER; id++) { | ||
| 499 | if (!finger[id].status) | ||
| 500 | continue; | ||
| 501 | |||
| 502 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, | ||
| 503 | finger[id].status != MXT_RELEASE ? | ||
| 504 | finger[id].area : 0); | ||
| 505 | input_report_abs(input_dev, ABS_MT_POSITION_X, | ||
| 506 | finger[id].x); | ||
| 507 | input_report_abs(input_dev, ABS_MT_POSITION_Y, | ||
| 508 | finger[id].y); | ||
| 509 | input_mt_sync(input_dev); | ||
| 510 | |||
| 511 | if (finger[id].status == MXT_RELEASE) | ||
| 512 | finger[id].status = 0; | ||
| 513 | else | ||
| 514 | finger_num++; | ||
| 515 | } | ||
| 516 | |||
| 517 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); | ||
| 518 | |||
| 519 | if (status != MXT_RELEASE) { | ||
| 520 | input_report_abs(input_dev, ABS_X, finger[single_id].x); | ||
| 521 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); | ||
| 522 | } | ||
| 523 | |||
| 524 | input_sync(input_dev); | ||
| 525 | } | ||
| 526 | |||
| 527 | static void mxt_input_touchevent(struct mxt_data *data, | ||
| 528 | struct mxt_message *message, int id) | ||
| 529 | { | ||
| 530 | struct mxt_finger *finger = data->finger; | ||
| 531 | struct device *dev = &data->client->dev; | ||
| 532 | u8 status = message->message[0]; | ||
| 533 | int x; | ||
| 534 | int y; | ||
| 535 | int area; | ||
| 536 | |||
| 537 | /* Check the touch is present on the screen */ | ||
| 538 | if (!(status & MXT_DETECT)) { | ||
| 539 | if (status & MXT_RELEASE) { | ||
| 540 | dev_dbg(dev, "[%d] released\n", id); | ||
| 541 | |||
| 542 | finger[id].status = MXT_RELEASE; | ||
| 543 | mxt_input_report(data, id); | ||
| 544 | } | ||
| 545 | return; | ||
| 546 | } | ||
| 547 | |||
| 548 | /* Check only AMP detection */ | ||
| 549 | if (!(status & (MXT_PRESS | MXT_MOVE))) | ||
| 550 | return; | ||
| 551 | |||
| 552 | x = (message->message[1] << 2) | ((message->message[3] & ~0x3f) >> 6); | ||
| 553 | y = (message->message[2] << 2) | ((message->message[3] & ~0xf3) >> 2); | ||
| 554 | area = message->message[4]; | ||
| 555 | |||
| 556 | dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, | ||
| 557 | status & MXT_MOVE ? "moved" : "pressed", | ||
| 558 | x, y, area); | ||
| 559 | |||
| 560 | finger[id].status = status & MXT_MOVE ? | ||
| 561 | MXT_MOVE : MXT_PRESS; | ||
| 562 | finger[id].x = x; | ||
| 563 | finger[id].y = y; | ||
| 564 | finger[id].area = area; | ||
| 565 | |||
| 566 | mxt_input_report(data, id); | ||
| 567 | } | ||
| 568 | |||
| 569 | static irqreturn_t mxt_interrupt(int irq, void *dev_id) | ||
| 570 | { | ||
| 571 | struct mxt_data *data = dev_id; | ||
| 572 | struct mxt_message message; | ||
| 573 | struct mxt_object *object; | ||
| 574 | struct device *dev = &data->client->dev; | ||
| 575 | int id; | ||
| 576 | u8 reportid; | ||
| 577 | u8 max_reportid; | ||
| 578 | u8 min_reportid; | ||
| 579 | |||
| 580 | do { | ||
| 581 | if (mxt_read_message(data, &message)) { | ||
| 582 | dev_err(dev, "Failed to read message\n"); | ||
| 583 | goto end; | ||
| 584 | } | ||
| 585 | |||
| 586 | reportid = message.reportid; | ||
| 587 | |||
| 588 | /* whether reportid is thing of MXT_TOUCH_MULTI */ | ||
| 589 | object = mxt_get_object(data, MXT_TOUCH_MULTI); | ||
| 590 | if (!object) | ||
| 591 | goto end; | ||
| 592 | |||
| 593 | max_reportid = object->max_reportid; | ||
| 594 | min_reportid = max_reportid - object->num_report_ids + 1; | ||
| 595 | id = reportid - min_reportid; | ||
| 596 | |||
| 597 | if (reportid >= min_reportid && reportid <= max_reportid) | ||
| 598 | mxt_input_touchevent(data, &message, id); | ||
| 599 | else | ||
| 600 | mxt_dump_message(dev, &message); | ||
| 601 | } while (reportid != 0xff); | ||
| 602 | |||
| 603 | end: | ||
| 604 | return IRQ_HANDLED; | ||
| 605 | } | ||
| 606 | |||
| 607 | static int mxt_check_reg_init(struct mxt_data *data) | ||
| 608 | { | ||
| 609 | const struct mxt_platform_data *pdata = data->pdata; | ||
| 610 | struct mxt_object *object; | ||
| 611 | struct device *dev = &data->client->dev; | ||
| 612 | int index = 0; | ||
| 613 | int i, j, config_offset; | ||
| 614 | |||
| 615 | if (!pdata->config) { | ||
| 616 | dev_dbg(dev, "No cfg data defined, skipping reg init\n"); | ||
| 617 | return 0; | ||
| 618 | } | ||
| 619 | |||
| 620 | for (i = 0; i < data->info.object_num; i++) { | ||
| 621 | object = data->object_table + i; | ||
| 622 | |||
| 623 | if (!mxt_object_writable(object->type)) | ||
| 624 | continue; | ||
| 625 | |||
| 626 | for (j = 0; j < object->size + 1; j++) { | ||
| 627 | config_offset = index + j; | ||
| 628 | if (config_offset > pdata->config_length) { | ||
| 629 | dev_err(dev, "Not enough config data!\n"); | ||
| 630 | return -EINVAL; | ||
| 631 | } | ||
| 632 | mxt_write_object(data, object->type, j, | ||
| 633 | pdata->config[config_offset]); | ||
| 634 | } | ||
| 635 | index += object->size + 1; | ||
| 636 | } | ||
| 637 | |||
| 638 | return 0; | ||
| 639 | } | ||
| 640 | |||
| 641 | static int mxt_make_highchg(struct mxt_data *data) | ||
| 642 | { | ||
| 643 | struct device *dev = &data->client->dev; | ||
| 644 | struct mxt_message message; | ||
| 645 | int count = 10; | ||
| 646 | int error; | ||
| 647 | |||
| 648 | /* Read dummy message to make high CHG pin */ | ||
| 649 | do { | ||
| 650 | error = mxt_read_message(data, &message); | ||
| 651 | if (error) | ||
| 652 | return error; | ||
| 653 | } while (message.reportid != 0xff && --count); | ||
| 654 | |||
| 655 | if (!count) { | ||
| 656 | dev_err(dev, "CHG pin isn't cleared\n"); | ||
| 657 | return -EBUSY; | ||
| 658 | } | ||
| 659 | |||
| 660 | return 0; | ||
| 661 | } | ||
| 662 | |||
| 663 | static void mxt_handle_pdata(struct mxt_data *data) | ||
| 664 | { | ||
| 665 | const struct mxt_platform_data *pdata = data->pdata; | ||
| 666 | u8 voltage; | ||
| 667 | |||
| 668 | /* Set touchscreen lines */ | ||
| 669 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_XSIZE, | ||
| 670 | pdata->x_line); | ||
| 671 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_YSIZE, | ||
| 672 | pdata->y_line); | ||
| 673 | |||
| 674 | /* Set touchscreen orient */ | ||
| 675 | mxt_write_object(data, MXT_TOUCH_MULTI, MXT_TOUCH_ORIENT, | ||
| 676 | pdata->orient); | ||
| 677 | |||
| 678 | /* Set touchscreen burst length */ | ||
| 679 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 680 | MXT_TOUCH_BLEN, pdata->blen); | ||
| 681 | |||
| 682 | /* Set touchscreen threshold */ | ||
| 683 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 684 | MXT_TOUCH_TCHTHR, pdata->threshold); | ||
| 685 | |||
| 686 | /* Set touchscreen resolution */ | ||
| 687 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 688 | MXT_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff); | ||
| 689 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 690 | MXT_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8); | ||
| 691 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 692 | MXT_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff); | ||
| 693 | mxt_write_object(data, MXT_TOUCH_MULTI, | ||
| 694 | MXT_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8); | ||
| 695 | |||
| 696 | /* Set touchscreen voltage */ | ||
| 697 | if (pdata->voltage) { | ||
| 698 | if (pdata->voltage < MXT_VOLTAGE_DEFAULT) { | ||
| 699 | voltage = (MXT_VOLTAGE_DEFAULT - pdata->voltage) / | ||
| 700 | MXT_VOLTAGE_STEP; | ||
| 701 | voltage = 0xff - voltage + 1; | ||
| 702 | } else | ||
| 703 | voltage = (pdata->voltage - MXT_VOLTAGE_DEFAULT) / | ||
| 704 | MXT_VOLTAGE_STEP; | ||
| 705 | |||
| 706 | mxt_write_object(data, MXT_SPT_CTECONFIG, | ||
| 707 | MXT_CTE_VOLTAGE, voltage); | ||
| 708 | } | ||
| 709 | } | ||
| 710 | |||
| 711 | static int mxt_get_info(struct mxt_data *data) | ||
| 712 | { | ||
| 713 | struct i2c_client *client = data->client; | ||
| 714 | struct mxt_info *info = &data->info; | ||
| 715 | int error; | ||
| 716 | u8 val; | ||
| 717 | |||
| 718 | error = mxt_read_reg(client, MXT_FAMILY_ID, &val); | ||
| 719 | if (error) | ||
| 720 | return error; | ||
| 721 | info->family_id = val; | ||
| 722 | |||
| 723 | error = mxt_read_reg(client, MXT_VARIANT_ID, &val); | ||
| 724 | if (error) | ||
| 725 | return error; | ||
| 726 | info->variant_id = val; | ||
| 727 | |||
| 728 | error = mxt_read_reg(client, MXT_VERSION, &val); | ||
| 729 | if (error) | ||
| 730 | return error; | ||
| 731 | info->version = val; | ||
| 732 | |||
| 733 | error = mxt_read_reg(client, MXT_BUILD, &val); | ||
| 734 | if (error) | ||
| 735 | return error; | ||
| 736 | info->build = val; | ||
| 737 | |||
| 738 | error = mxt_read_reg(client, MXT_OBJECT_NUM, &val); | ||
| 739 | if (error) | ||
| 740 | return error; | ||
| 741 | info->object_num = val; | ||
| 742 | |||
| 743 | return 0; | ||
| 744 | } | ||
| 745 | |||
| 746 | static int mxt_get_object_table(struct mxt_data *data) | ||
| 747 | { | ||
| 748 | int error; | ||
| 749 | int i; | ||
| 750 | u16 reg; | ||
| 751 | u8 reportid = 0; | ||
| 752 | u8 buf[MXT_OBJECT_SIZE]; | ||
| 753 | |||
| 754 | for (i = 0; i < data->info.object_num; i++) { | ||
| 755 | struct mxt_object *object = data->object_table + i; | ||
| 756 | |||
| 757 | reg = MXT_OBJECT_START + MXT_OBJECT_SIZE * i; | ||
| 758 | error = mxt_read_object_table(data->client, reg, buf); | ||
| 759 | if (error) | ||
| 760 | return error; | ||
| 761 | |||
| 762 | object->type = buf[0]; | ||
| 763 | object->start_address = (buf[2] << 8) | buf[1]; | ||
| 764 | object->size = buf[3]; | ||
| 765 | object->instances = buf[4]; | ||
| 766 | object->num_report_ids = buf[5]; | ||
| 767 | |||
| 768 | if (object->num_report_ids) { | ||
| 769 | reportid += object->num_report_ids * | ||
| 770 | (object->instances + 1); | ||
| 771 | object->max_reportid = reportid; | ||
| 772 | } | ||
| 773 | } | ||
| 774 | |||
| 775 | return 0; | ||
| 776 | } | ||
| 777 | |||
| 778 | static int mxt_initialize(struct mxt_data *data) | ||
| 779 | { | ||
| 780 | struct i2c_client *client = data->client; | ||
| 781 | struct mxt_info *info = &data->info; | ||
| 782 | int error; | ||
| 783 | u8 val; | ||
| 784 | |||
| 785 | error = mxt_get_info(data); | ||
| 786 | if (error) | ||
| 787 | return error; | ||
| 788 | |||
| 789 | data->object_table = kcalloc(info->object_num, | ||
| 790 | sizeof(struct mxt_object), | ||
| 791 | GFP_KERNEL); | ||
| 792 | if (!data->object_table) { | ||
| 793 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 794 | return -ENOMEM; | ||
| 795 | } | ||
| 796 | |||
| 797 | /* Get object table information */ | ||
| 798 | error = mxt_get_object_table(data); | ||
| 799 | if (error) | ||
| 800 | return error; | ||
| 801 | |||
| 802 | /* Check register init values */ | ||
| 803 | error = mxt_check_reg_init(data); | ||
| 804 | if (error) | ||
| 805 | return error; | ||
| 806 | |||
| 807 | error = mxt_make_highchg(data); | ||
| 808 | if (error) | ||
| 809 | return error; | ||
| 810 | |||
| 811 | mxt_handle_pdata(data); | ||
| 812 | |||
| 813 | /* Backup to memory */ | ||
| 814 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 815 | MXT_COMMAND_BACKUPNV, | ||
| 816 | MXT_BACKUP_VALUE); | ||
| 817 | msleep(MXT_BACKUP_TIME); | ||
| 818 | |||
| 819 | /* Soft reset */ | ||
| 820 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 821 | MXT_COMMAND_RESET, 1); | ||
| 822 | msleep(MXT_RESET_TIME); | ||
| 823 | |||
| 824 | /* Update matrix size at info struct */ | ||
| 825 | error = mxt_read_reg(client, MXT_MATRIX_X_SIZE, &val); | ||
| 826 | if (error) | ||
| 827 | return error; | ||
| 828 | info->matrix_xsize = val; | ||
| 829 | |||
| 830 | error = mxt_read_reg(client, MXT_MATRIX_Y_SIZE, &val); | ||
| 831 | if (error) | ||
| 832 | return error; | ||
| 833 | info->matrix_ysize = val; | ||
| 834 | |||
| 835 | dev_info(&client->dev, | ||
| 836 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", | ||
| 837 | info->family_id, info->variant_id, info->version, | ||
| 838 | info->build); | ||
| 839 | |||
| 840 | dev_info(&client->dev, | ||
| 841 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", | ||
| 842 | info->matrix_xsize, info->matrix_ysize, | ||
| 843 | info->object_num); | ||
| 844 | |||
| 845 | return 0; | ||
| 846 | } | ||
| 847 | |||
| 848 | static ssize_t mxt_object_show(struct device *dev, | ||
| 849 | struct device_attribute *attr, char *buf) | ||
| 850 | { | ||
| 851 | struct mxt_data *data = dev_get_drvdata(dev); | ||
| 852 | struct mxt_object *object; | ||
| 853 | int count = 0; | ||
| 854 | int i, j; | ||
| 855 | int error; | ||
| 856 | u8 val; | ||
| 857 | |||
| 858 | for (i = 0; i < data->info.object_num; i++) { | ||
| 859 | object = data->object_table + i; | ||
| 860 | |||
| 861 | count += sprintf(buf + count, | ||
| 862 | "Object Table Element %d(Type %d)\n", | ||
| 863 | i + 1, object->type); | ||
| 864 | |||
| 865 | if (!mxt_object_readable(object->type)) { | ||
| 866 | count += sprintf(buf + count, "\n"); | ||
| 867 | continue; | ||
| 868 | } | ||
| 869 | |||
| 870 | for (j = 0; j < object->size + 1; j++) { | ||
| 871 | error = mxt_read_object(data, | ||
| 872 | object->type, j, &val); | ||
| 873 | if (error) | ||
| 874 | return error; | ||
| 875 | |||
| 876 | count += sprintf(buf + count, | ||
| 877 | " Byte %d: 0x%x (%d)\n", j, val, val); | ||
| 878 | } | ||
| 879 | |||
| 880 | count += sprintf(buf + count, "\n"); | ||
| 881 | } | ||
| 882 | |||
| 883 | return count; | ||
| 884 | } | ||
| 885 | |||
| 886 | static int mxt_load_fw(struct device *dev, const char *fn) | ||
| 887 | { | ||
| 888 | struct mxt_data *data = dev_get_drvdata(dev); | ||
| 889 | struct i2c_client *client = data->client; | ||
| 890 | const struct firmware *fw = NULL; | ||
| 891 | unsigned int frame_size; | ||
| 892 | unsigned int pos = 0; | ||
| 893 | int ret; | ||
| 894 | |||
| 895 | ret = request_firmware(&fw, fn, dev); | ||
| 896 | if (ret) { | ||
| 897 | dev_err(dev, "Unable to open firmware %s\n", fn); | ||
| 898 | return ret; | ||
| 899 | } | ||
| 900 | |||
| 901 | /* Change to the bootloader mode */ | ||
| 902 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 903 | MXT_COMMAND_RESET, MXT_BOOT_VALUE); | ||
| 904 | msleep(MXT_RESET_TIME); | ||
| 905 | |||
| 906 | /* Change to slave address of bootloader */ | ||
| 907 | if (client->addr == MXT_APP_LOW) | ||
| 908 | client->addr = MXT_BOOT_LOW; | ||
| 909 | else | ||
| 910 | client->addr = MXT_BOOT_HIGH; | ||
| 911 | |||
| 912 | ret = mxt_check_bootloader(client, MXT_WAITING_BOOTLOAD_CMD); | ||
| 913 | if (ret) | ||
| 914 | goto out; | ||
| 915 | |||
| 916 | /* Unlock bootloader */ | ||
| 917 | mxt_unlock_bootloader(client); | ||
| 918 | |||
| 919 | while (pos < fw->size) { | ||
| 920 | ret = mxt_check_bootloader(client, | ||
| 921 | MXT_WAITING_FRAME_DATA); | ||
| 922 | if (ret) | ||
| 923 | goto out; | ||
| 924 | |||
| 925 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); | ||
| 926 | |||
| 927 | /* We should add 2 at frame size as the the firmware data is not | ||
| 928 | * included the CRC bytes. | ||
| 929 | */ | ||
| 930 | frame_size += 2; | ||
| 931 | |||
| 932 | /* Write one frame to device */ | ||
| 933 | mxt_fw_write(client, fw->data + pos, frame_size); | ||
| 934 | |||
| 935 | ret = mxt_check_bootloader(client, | ||
| 936 | MXT_FRAME_CRC_PASS); | ||
| 937 | if (ret) | ||
| 938 | goto out; | ||
| 939 | |||
| 940 | pos += frame_size; | ||
| 941 | |||
| 942 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); | ||
| 943 | } | ||
| 944 | |||
| 945 | out: | ||
| 946 | release_firmware(fw); | ||
| 947 | |||
| 948 | /* Change to slave address of application */ | ||
| 949 | if (client->addr == MXT_BOOT_LOW) | ||
| 950 | client->addr = MXT_APP_LOW; | ||
| 951 | else | ||
| 952 | client->addr = MXT_APP_HIGH; | ||
| 953 | |||
| 954 | return ret; | ||
| 955 | } | ||
| 956 | |||
| 957 | static ssize_t mxt_update_fw_store(struct device *dev, | ||
| 958 | struct device_attribute *attr, | ||
| 959 | const char *buf, size_t count) | ||
| 960 | { | ||
| 961 | struct mxt_data *data = dev_get_drvdata(dev); | ||
| 962 | int error; | ||
| 963 | |||
| 964 | disable_irq(data->irq); | ||
| 965 | |||
| 966 | error = mxt_load_fw(dev, MXT_FW_NAME); | ||
| 967 | if (error) { | ||
| 968 | dev_err(dev, "The firmware update failed(%d)\n", error); | ||
| 969 | count = error; | ||
| 970 | } else { | ||
| 971 | dev_dbg(dev, "The firmware update succeeded\n"); | ||
| 972 | |||
| 973 | /* Wait for reset */ | ||
| 974 | msleep(MXT_FWRESET_TIME); | ||
| 975 | |||
| 976 | kfree(data->object_table); | ||
| 977 | data->object_table = NULL; | ||
| 978 | |||
| 979 | mxt_initialize(data); | ||
| 980 | } | ||
| 981 | |||
| 982 | enable_irq(data->irq); | ||
| 983 | |||
| 984 | return count; | ||
| 985 | } | ||
| 986 | |||
| 987 | static DEVICE_ATTR(object, 0444, mxt_object_show, NULL); | ||
| 988 | static DEVICE_ATTR(update_fw, 0664, NULL, mxt_update_fw_store); | ||
| 989 | |||
| 990 | static struct attribute *mxt_attrs[] = { | ||
| 991 | &dev_attr_object.attr, | ||
| 992 | &dev_attr_update_fw.attr, | ||
| 993 | NULL | ||
| 994 | }; | ||
| 995 | |||
| 996 | static const struct attribute_group mxt_attr_group = { | ||
| 997 | .attrs = mxt_attrs, | ||
| 998 | }; | ||
| 999 | |||
| 1000 | static void mxt_start(struct mxt_data *data) | ||
| 1001 | { | ||
| 1002 | /* Touch enable */ | ||
| 1003 | mxt_write_object(data, | ||
| 1004 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0x83); | ||
| 1005 | } | ||
| 1006 | |||
| 1007 | static void mxt_stop(struct mxt_data *data) | ||
| 1008 | { | ||
| 1009 | /* Touch disable */ | ||
| 1010 | mxt_write_object(data, | ||
| 1011 | MXT_TOUCH_MULTI, MXT_TOUCH_CTRL, 0); | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | static int mxt_input_open(struct input_dev *dev) | ||
| 1015 | { | ||
| 1016 | struct mxt_data *data = input_get_drvdata(dev); | ||
| 1017 | |||
| 1018 | mxt_start(data); | ||
| 1019 | |||
| 1020 | return 0; | ||
| 1021 | } | ||
| 1022 | |||
| 1023 | static void mxt_input_close(struct input_dev *dev) | ||
| 1024 | { | ||
| 1025 | struct mxt_data *data = input_get_drvdata(dev); | ||
| 1026 | |||
| 1027 | mxt_stop(data); | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | static int __devinit mxt_probe(struct i2c_client *client, | ||
| 1031 | const struct i2c_device_id *id) | ||
| 1032 | { | ||
| 1033 | const struct mxt_platform_data *pdata = client->dev.platform_data; | ||
| 1034 | struct mxt_data *data; | ||
| 1035 | struct input_dev *input_dev; | ||
| 1036 | int error; | ||
| 1037 | |||
| 1038 | if (!pdata) | ||
| 1039 | return -EINVAL; | ||
| 1040 | |||
| 1041 | data = kzalloc(sizeof(struct mxt_data), GFP_KERNEL); | ||
| 1042 | input_dev = input_allocate_device(); | ||
| 1043 | if (!data || !input_dev) { | ||
| 1044 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 1045 | error = -ENOMEM; | ||
| 1046 | goto err_free_mem; | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | input_dev->name = "Atmel maXTouch Touchscreen"; | ||
| 1050 | input_dev->id.bustype = BUS_I2C; | ||
| 1051 | input_dev->dev.parent = &client->dev; | ||
| 1052 | input_dev->open = mxt_input_open; | ||
| 1053 | input_dev->close = mxt_input_close; | ||
| 1054 | |||
| 1055 | __set_bit(EV_ABS, input_dev->evbit); | ||
| 1056 | __set_bit(EV_KEY, input_dev->evbit); | ||
| 1057 | __set_bit(BTN_TOUCH, input_dev->keybit); | ||
| 1058 | |||
| 1059 | /* For single touch */ | ||
| 1060 | input_set_abs_params(input_dev, ABS_X, | ||
| 1061 | 0, MXT_MAX_XC, 0, 0); | ||
| 1062 | input_set_abs_params(input_dev, ABS_Y, | ||
| 1063 | 0, MXT_MAX_YC, 0, 0); | ||
| 1064 | |||
| 1065 | /* For multi touch */ | ||
| 1066 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, | ||
| 1067 | 0, MXT_MAX_AREA, 0, 0); | ||
| 1068 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, | ||
| 1069 | 0, MXT_MAX_XC, 0, 0); | ||
| 1070 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, | ||
| 1071 | 0, MXT_MAX_YC, 0, 0); | ||
| 1072 | |||
| 1073 | input_set_drvdata(input_dev, data); | ||
| 1074 | |||
| 1075 | data->client = client; | ||
| 1076 | data->input_dev = input_dev; | ||
| 1077 | data->pdata = pdata; | ||
| 1078 | data->irq = client->irq; | ||
| 1079 | |||
| 1080 | i2c_set_clientdata(client, data); | ||
| 1081 | |||
| 1082 | error = mxt_initialize(data); | ||
| 1083 | if (error) | ||
| 1084 | goto err_free_object; | ||
| 1085 | |||
| 1086 | error = request_threaded_irq(client->irq, NULL, mxt_interrupt, | ||
| 1087 | pdata->irqflags, client->dev.driver->name, data); | ||
| 1088 | if (error) { | ||
| 1089 | dev_err(&client->dev, "Failed to register interrupt\n"); | ||
| 1090 | goto err_free_object; | ||
| 1091 | } | ||
| 1092 | |||
| 1093 | error = input_register_device(input_dev); | ||
| 1094 | if (error) | ||
| 1095 | goto err_free_irq; | ||
| 1096 | |||
| 1097 | error = sysfs_create_group(&client->dev.kobj, &mxt_attr_group); | ||
| 1098 | if (error) | ||
| 1099 | goto err_unregister_device; | ||
| 1100 | |||
| 1101 | return 0; | ||
| 1102 | |||
| 1103 | err_unregister_device: | ||
| 1104 | input_unregister_device(input_dev); | ||
| 1105 | input_dev = NULL; | ||
| 1106 | err_free_irq: | ||
| 1107 | free_irq(client->irq, data); | ||
| 1108 | err_free_object: | ||
| 1109 | kfree(data->object_table); | ||
| 1110 | err_free_mem: | ||
| 1111 | input_free_device(input_dev); | ||
| 1112 | kfree(data); | ||
| 1113 | return error; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | static int __devexit mxt_remove(struct i2c_client *client) | ||
| 1117 | { | ||
| 1118 | struct mxt_data *data = i2c_get_clientdata(client); | ||
| 1119 | |||
| 1120 | sysfs_remove_group(&client->dev.kobj, &mxt_attr_group); | ||
| 1121 | free_irq(data->irq, data); | ||
| 1122 | input_unregister_device(data->input_dev); | ||
| 1123 | kfree(data->object_table); | ||
| 1124 | kfree(data); | ||
| 1125 | |||
| 1126 | return 0; | ||
| 1127 | } | ||
| 1128 | |||
| 1129 | #ifdef CONFIG_PM | ||
| 1130 | static int mxt_suspend(struct device *dev) | ||
| 1131 | { | ||
| 1132 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1133 | struct mxt_data *data = i2c_get_clientdata(client); | ||
| 1134 | struct input_dev *input_dev = data->input_dev; | ||
| 1135 | |||
| 1136 | mutex_lock(&input_dev->mutex); | ||
| 1137 | |||
| 1138 | if (input_dev->users) | ||
| 1139 | mxt_stop(data); | ||
| 1140 | |||
| 1141 | mutex_unlock(&input_dev->mutex); | ||
| 1142 | |||
| 1143 | return 0; | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | static int mxt_resume(struct device *dev) | ||
| 1147 | { | ||
| 1148 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1149 | struct mxt_data *data = i2c_get_clientdata(client); | ||
| 1150 | struct input_dev *input_dev = data->input_dev; | ||
| 1151 | |||
| 1152 | /* Soft reset */ | ||
| 1153 | mxt_write_object(data, MXT_GEN_COMMAND, | ||
| 1154 | MXT_COMMAND_RESET, 1); | ||
| 1155 | |||
| 1156 | msleep(MXT_RESET_TIME); | ||
| 1157 | |||
| 1158 | mutex_lock(&input_dev->mutex); | ||
| 1159 | |||
| 1160 | if (input_dev->users) | ||
| 1161 | mxt_start(data); | ||
| 1162 | |||
| 1163 | mutex_unlock(&input_dev->mutex); | ||
| 1164 | |||
| 1165 | return 0; | ||
| 1166 | } | ||
| 1167 | |||
| 1168 | static const struct dev_pm_ops mxt_pm_ops = { | ||
| 1169 | .suspend = mxt_suspend, | ||
| 1170 | .resume = mxt_resume, | ||
| 1171 | }; | ||
| 1172 | #endif | ||
| 1173 | |||
| 1174 | static const struct i2c_device_id mxt_id[] = { | ||
| 1175 | { "qt602240_ts", 0 }, | ||
| 1176 | { "atmel_mxt_ts", 0 }, | ||
| 1177 | { "mXT224", 0 }, | ||
| 1178 | { } | ||
| 1179 | }; | ||
| 1180 | MODULE_DEVICE_TABLE(i2c, mxt_id); | ||
| 1181 | |||
| 1182 | static struct i2c_driver mxt_driver = { | ||
| 1183 | .driver = { | ||
| 1184 | .name = "atmel_mxt_ts", | ||
| 1185 | .owner = THIS_MODULE, | ||
| 1186 | #ifdef CONFIG_PM | ||
| 1187 | .pm = &mxt_pm_ops, | ||
| 1188 | #endif | ||
| 1189 | }, | ||
| 1190 | .probe = mxt_probe, | ||
| 1191 | .remove = __devexit_p(mxt_remove), | ||
| 1192 | .id_table = mxt_id, | ||
| 1193 | }; | ||
| 1194 | |||
| 1195 | static int __init mxt_init(void) | ||
| 1196 | { | ||
| 1197 | return i2c_add_driver(&mxt_driver); | ||
| 1198 | } | ||
| 1199 | |||
| 1200 | static void __exit mxt_exit(void) | ||
| 1201 | { | ||
| 1202 | i2c_del_driver(&mxt_driver); | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | module_init(mxt_init); | ||
| 1206 | module_exit(mxt_exit); | ||
| 1207 | |||
| 1208 | /* Module information */ | ||
| 1209 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | ||
| 1210 | MODULE_DESCRIPTION("Atmel maXTouch Touchscreen driver"); | ||
| 1211 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/qt602240_ts.c b/drivers/input/touchscreen/qt602240_ts.c deleted file mode 100644 index 4dcb0e872f6..00000000000 --- a/drivers/input/touchscreen/qt602240_ts.c +++ /dev/null | |||
| @@ -1,1406 +0,0 @@ | |||
| 1 | /* | ||
| 2 | * AT42QT602240/ATMXT224 Touchscreen driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2010 Samsung Electronics Co.Ltd | ||
| 5 | * Author: Joonyoung Shim <jy0922.shim@samsung.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the | ||
| 9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/init.h> | ||
| 16 | #include <linux/delay.h> | ||
| 17 | #include <linux/firmware.h> | ||
| 18 | #include <linux/i2c.h> | ||
| 19 | #include <linux/i2c/qt602240_ts.h> | ||
| 20 | #include <linux/input.h> | ||
| 21 | #include <linux/interrupt.h> | ||
| 22 | #include <linux/slab.h> | ||
| 23 | |||
| 24 | /* Version */ | ||
| 25 | #define QT602240_VER_20 20 | ||
| 26 | #define QT602240_VER_21 21 | ||
| 27 | #define QT602240_VER_22 22 | ||
| 28 | |||
| 29 | /* Slave addresses */ | ||
| 30 | #define QT602240_APP_LOW 0x4a | ||
| 31 | #define QT602240_APP_HIGH 0x4b | ||
| 32 | #define QT602240_BOOT_LOW 0x24 | ||
| 33 | #define QT602240_BOOT_HIGH 0x25 | ||
| 34 | |||
| 35 | /* Firmware */ | ||
| 36 | #define QT602240_FW_NAME "qt602240.fw" | ||
| 37 | |||
| 38 | /* Registers */ | ||
| 39 | #define QT602240_FAMILY_ID 0x00 | ||
| 40 | #define QT602240_VARIANT_ID 0x01 | ||
| 41 | #define QT602240_VERSION 0x02 | ||
| 42 | #define QT602240_BUILD 0x03 | ||
| 43 | #define QT602240_MATRIX_X_SIZE 0x04 | ||
| 44 | #define QT602240_MATRIX_Y_SIZE 0x05 | ||
| 45 | #define QT602240_OBJECT_NUM 0x06 | ||
| 46 | #define QT602240_OBJECT_START 0x07 | ||
| 47 | |||
| 48 | #define QT602240_OBJECT_SIZE 6 | ||
| 49 | |||
| 50 | /* Object types */ | ||
| 51 | #define QT602240_DEBUG_DIAGNOSTIC 37 | ||
| 52 | #define QT602240_GEN_MESSAGE 5 | ||
| 53 | #define QT602240_GEN_COMMAND 6 | ||
| 54 | #define QT602240_GEN_POWER 7 | ||
| 55 | #define QT602240_GEN_ACQUIRE 8 | ||
| 56 | #define QT602240_TOUCH_MULTI 9 | ||
| 57 | #define QT602240_TOUCH_KEYARRAY 15 | ||
| 58 | #define QT602240_TOUCH_PROXIMITY 23 | ||
| 59 | #define QT602240_PROCI_GRIPFACE 20 | ||
| 60 | #define QT602240_PROCG_NOISE 22 | ||
| 61 | #define QT602240_PROCI_ONETOUCH 24 | ||
| 62 | #define QT602240_PROCI_TWOTOUCH 27 | ||
| 63 | #define QT602240_SPT_COMMSCONFIG 18 /* firmware ver 21 over */ | ||
| 64 | #define QT602240_SPT_GPIOPWM 19 | ||
| 65 | #define QT602240_SPT_SELFTEST 25 | ||
| 66 | #define QT602240_SPT_CTECONFIG 28 | ||
| 67 | #define QT602240_SPT_USERDATA 38 /* firmware ver 21 over */ | ||
| 68 | |||
| 69 | /* QT602240_GEN_COMMAND field */ | ||
| 70 | #define QT602240_COMMAND_RESET 0 | ||
| 71 | #define QT602240_COMMAND_BACKUPNV 1 | ||
| 72 | #define QT602240_COMMAND_CALIBRATE 2 | ||
| 73 | #define QT602240_COMMAND_REPORTALL 3 | ||
| 74 | #define QT602240_COMMAND_DIAGNOSTIC 5 | ||
| 75 | |||
| 76 | /* QT602240_GEN_POWER field */ | ||
| 77 | #define QT602240_POWER_IDLEACQINT 0 | ||
| 78 | #define QT602240_POWER_ACTVACQINT 1 | ||
| 79 | #define QT602240_POWER_ACTV2IDLETO 2 | ||
| 80 | |||
| 81 | /* QT602240_GEN_ACQUIRE field */ | ||
| 82 | #define QT602240_ACQUIRE_CHRGTIME 0 | ||
| 83 | #define QT602240_ACQUIRE_TCHDRIFT 2 | ||
| 84 | #define QT602240_ACQUIRE_DRIFTST 3 | ||
| 85 | #define QT602240_ACQUIRE_TCHAUTOCAL 4 | ||
| 86 | #define QT602240_ACQUIRE_SYNC 5 | ||
| 87 | #define QT602240_ACQUIRE_ATCHCALST 6 | ||
| 88 | #define QT602240_ACQUIRE_ATCHCALSTHR 7 | ||
| 89 | |||
| 90 | /* QT602240_TOUCH_MULTI field */ | ||
| 91 | #define QT602240_TOUCH_CTRL 0 | ||
| 92 | #define QT602240_TOUCH_XORIGIN 1 | ||
| 93 | #define QT602240_TOUCH_YORIGIN 2 | ||
| 94 | #define QT602240_TOUCH_XSIZE 3 | ||
| 95 | #define QT602240_TOUCH_YSIZE 4 | ||
| 96 | #define QT602240_TOUCH_BLEN 6 | ||
| 97 | #define QT602240_TOUCH_TCHTHR 7 | ||
| 98 | #define QT602240_TOUCH_TCHDI 8 | ||
| 99 | #define QT602240_TOUCH_ORIENT 9 | ||
| 100 | #define QT602240_TOUCH_MOVHYSTI 11 | ||
| 101 | #define QT602240_TOUCH_MOVHYSTN 12 | ||
| 102 | #define QT602240_TOUCH_NUMTOUCH 14 | ||
| 103 | #define QT602240_TOUCH_MRGHYST 15 | ||
| 104 | #define QT602240_TOUCH_MRGTHR 16 | ||
| 105 | #define QT602240_TOUCH_AMPHYST 17 | ||
| 106 | #define QT602240_TOUCH_XRANGE_LSB 18 | ||
| 107 | #define QT602240_TOUCH_XRANGE_MSB 19 | ||
| 108 | #define QT602240_TOUCH_YRANGE_LSB 20 | ||
| 109 | #define QT602240_TOUCH_YRANGE_MSB 21 | ||
| 110 | #define QT602240_TOUCH_XLOCLIP 22 | ||
| 111 | #define QT602240_TOUCH_XHICLIP 23 | ||
| 112 | #define QT602240_TOUCH_YLOCLIP 24 | ||
| 113 | #define QT602240_TOUCH_YHICLIP 25 | ||
| 114 | #define QT602240_TOUCH_XEDGECTRL 26 | ||
| 115 | #define QT602240_TOUCH_XEDGEDIST 27 | ||
| 116 | #define QT602240_TOUCH_YEDGECTRL 28 | ||
| 117 | #define QT602240_TOUCH_YEDGEDIST 29 | ||
| 118 | #define QT602240_TOUCH_JUMPLIMIT 30 /* firmware ver 22 over */ | ||
| 119 | |||
| 120 | /* QT602240_PROCI_GRIPFACE field */ | ||
| 121 | #define QT602240_GRIPFACE_CTRL 0 | ||
| 122 | #define QT602240_GRIPFACE_XLOGRIP 1 | ||
| 123 | #define QT602240_GRIPFACE_XHIGRIP 2 | ||
| 124 | #define QT602240_GRIPFACE_YLOGRIP 3 | ||
| 125 | #define QT602240_GRIPFACE_YHIGRIP 4 | ||
| 126 | #define QT602240_GRIPFACE_MAXTCHS 5 | ||
| 127 | #define QT602240_GRIPFACE_SZTHR1 7 | ||
| 128 | #define QT602240_GRIPFACE_SZTHR2 8 | ||
| 129 | #define QT602240_GRIPFACE_SHPTHR1 9 | ||
| 130 | #define QT602240_GRIPFACE_SHPTHR2 10 | ||
| 131 | #define QT602240_GRIPFACE_SUPEXTTO 11 | ||
| 132 | |||
| 133 | /* QT602240_PROCI_NOISE field */ | ||
| 134 | #define QT602240_NOISE_CTRL 0 | ||
| 135 | #define QT602240_NOISE_OUTFLEN 1 | ||
| 136 | #define QT602240_NOISE_GCAFUL_LSB 3 | ||
| 137 | #define QT602240_NOISE_GCAFUL_MSB 4 | ||
| 138 | #define QT602240_NOISE_GCAFLL_LSB 5 | ||
| 139 | #define QT602240_NOISE_GCAFLL_MSB 6 | ||
| 140 | #define QT602240_NOISE_ACTVGCAFVALID 7 | ||
| 141 | #define QT602240_NOISE_NOISETHR 8 | ||
| 142 | #define QT602240_NOISE_FREQHOPSCALE 10 | ||
| 143 | #define QT602240_NOISE_FREQ0 11 | ||
| 144 | #define QT602240_NOISE_FREQ1 12 | ||
| 145 | #define QT602240_NOISE_FREQ2 13 | ||
| 146 | #define QT602240_NOISE_FREQ3 14 | ||
| 147 | #define QT602240_NOISE_FREQ4 15 | ||
| 148 | #define QT602240_NOISE_IDLEGCAFVALID 16 | ||
| 149 | |||
| 150 | /* QT602240_SPT_COMMSCONFIG */ | ||
| 151 | #define QT602240_COMMS_CTRL 0 | ||
| 152 | #define QT602240_COMMS_CMD 1 | ||
| 153 | |||
| 154 | /* QT602240_SPT_CTECONFIG field */ | ||
| 155 | #define QT602240_CTE_CTRL 0 | ||
| 156 | #define QT602240_CTE_CMD 1 | ||
| 157 | #define QT602240_CTE_MODE 2 | ||
| 158 | #define QT602240_CTE_IDLEGCAFDEPTH 3 | ||
| 159 | #define QT602240_CTE_ACTVGCAFDEPTH 4 | ||
| 160 | #define QT602240_CTE_VOLTAGE 5 /* firmware ver 21 over */ | ||
| 161 | |||
| 162 | #define QT602240_VOLTAGE_DEFAULT 2700000 | ||
| 163 | #define QT602240_VOLTAGE_STEP 10000 | ||
| 164 | |||
| 165 | /* Define for QT602240_GEN_COMMAND */ | ||
| 166 | #define QT602240_BOOT_VALUE 0xa5 | ||
| 167 | #define QT602240_BACKUP_VALUE 0x55 | ||
| 168 | #define QT602240_BACKUP_TIME 25 /* msec */ | ||
| 169 | #define QT602240_RESET_TIME 65 /* msec */ | ||
| 170 | |||
| 171 | #define QT602240_FWRESET_TIME 175 /* msec */ | ||
| 172 | |||
| 173 | /* Command to unlock bootloader */ | ||
| 174 | #define QT602240_UNLOCK_CMD_MSB 0xaa | ||
| 175 | #define QT602240_UNLOCK_CMD_LSB 0xdc | ||
| 176 | |||
| 177 | /* Bootloader mode status */ | ||
| 178 | #define QT602240_WAITING_BOOTLOAD_CMD 0xc0 /* valid 7 6 bit only */ | ||
| 179 | #define QT602240_WAITING_FRAME_DATA 0x80 /* valid 7 6 bit only */ | ||
| 180 | #define QT602240_FRAME_CRC_CHECK 0x02 | ||
| 181 | #define QT602240_FRAME_CRC_FAIL 0x03 | ||
| 182 | #define QT602240_FRAME_CRC_PASS 0x04 | ||
| 183 | #define QT602240_APP_CRC_FAIL 0x40 /* valid 7 8 bit only */ | ||
| 184 | #define QT602240_BOOT_STATUS_MASK 0x3f | ||
| 185 | |||
| 186 | /* Touch status */ | ||
| 187 | #define QT602240_SUPPRESS (1 << 1) | ||
| 188 | #define QT602240_AMP (1 << 2) | ||
| 189 | #define QT602240_VECTOR (1 << 3) | ||
| 190 | #define QT602240_MOVE (1 << 4) | ||
| 191 | #define QT602240_RELEASE (1 << 5) | ||
| 192 | #define QT602240_PRESS (1 << 6) | ||
| 193 | #define QT602240_DETECT (1 << 7) | ||
| 194 | |||
| 195 | /* Touchscreen absolute values */ | ||
| 196 | #define QT602240_MAX_XC 0x3ff | ||
| 197 | #define QT602240_MAX_YC 0x3ff | ||
| 198 | #define QT602240_MAX_AREA 0xff | ||
| 199 | |||
| 200 | #define QT602240_MAX_FINGER 10 | ||
| 201 | |||
| 202 | /* Initial register values recommended from chip vendor */ | ||
| 203 | static const u8 init_vals_ver_20[] = { | ||
| 204 | /* QT602240_GEN_COMMAND(6) */ | ||
| 205 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 206 | /* QT602240_GEN_POWER(7) */ | ||
| 207 | 0x20, 0xff, 0x32, | ||
| 208 | /* QT602240_GEN_ACQUIRE(8) */ | ||
| 209 | 0x08, 0x05, 0x05, 0x00, 0x00, 0x00, 0x05, 0x14, | ||
| 210 | /* QT602240_TOUCH_MULTI(9) */ | ||
| 211 | 0x00, 0x00, 0x00, 0x11, 0x0a, 0x00, 0x00, 0x00, 0x02, 0x00, | ||
| 212 | 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00, | ||
| 213 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x88, 0x64, | ||
| 214 | /* QT602240_TOUCH_KEYARRAY(15) */ | ||
| 215 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 216 | 0x00, | ||
| 217 | /* QT602240_SPT_GPIOPWM(19) */ | ||
| 218 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 219 | 0x00, 0x00, | ||
| 220 | /* QT602240_PROCI_GRIPFACE(20) */ | ||
| 221 | 0x00, 0x64, 0x64, 0x64, 0x64, 0x00, 0x00, 0x1e, 0x14, 0x04, | ||
| 222 | 0x1e, 0x00, | ||
| 223 | /* QT602240_PROCG_NOISE(22) */ | ||
| 224 | 0x05, 0x00, 0x00, 0x19, 0x00, 0xe7, 0xff, 0x04, 0x32, 0x00, | ||
| 225 | 0x01, 0x0a, 0x0f, 0x14, 0x00, 0x00, 0xe8, | ||
| 226 | /* QT602240_TOUCH_PROXIMITY(23) */ | ||
| 227 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 228 | 0x00, 0x00, 0x00, | ||
| 229 | /* QT602240_PROCI_ONETOUCH(24) */ | ||
| 230 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 231 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 232 | /* QT602240_SPT_SELFTEST(25) */ | ||
| 233 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 234 | 0x00, 0x00, 0x00, 0x00, | ||
| 235 | /* QT602240_PROCI_TWOTOUCH(27) */ | ||
| 236 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 237 | /* QT602240_SPT_CTECONFIG(28) */ | ||
| 238 | 0x00, 0x00, 0x00, 0x04, 0x08, | ||
| 239 | }; | ||
| 240 | |||
| 241 | static const u8 init_vals_ver_21[] = { | ||
| 242 | /* QT602240_GEN_COMMAND(6) */ | ||
| 243 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 244 | /* QT602240_GEN_POWER(7) */ | ||
| 245 | 0x20, 0xff, 0x32, | ||
| 246 | /* QT602240_GEN_ACQUIRE(8) */ | ||
| 247 | 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23, | ||
| 248 | /* QT602240_TOUCH_MULTI(9) */ | ||
| 249 | 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, | ||
| 250 | 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00, | ||
| 251 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 252 | /* QT602240_TOUCH_KEYARRAY(15) */ | ||
| 253 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 254 | 0x00, | ||
| 255 | /* QT602240_SPT_GPIOPWM(19) */ | ||
| 256 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 257 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 258 | /* QT602240_PROCI_GRIPFACE(20) */ | ||
| 259 | 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04, | ||
| 260 | 0x0f, 0x0a, | ||
| 261 | /* QT602240_PROCG_NOISE(22) */ | ||
| 262 | 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00, | ||
| 263 | 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03, | ||
| 264 | /* QT602240_TOUCH_PROXIMITY(23) */ | ||
| 265 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 266 | 0x00, 0x00, 0x00, | ||
| 267 | /* QT602240_PROCI_ONETOUCH(24) */ | ||
| 268 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 269 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 270 | /* QT602240_SPT_SELFTEST(25) */ | ||
| 271 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 272 | 0x00, 0x00, 0x00, 0x00, | ||
| 273 | /* QT602240_PROCI_TWOTOUCH(27) */ | ||
| 274 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 275 | /* QT602240_SPT_CTECONFIG(28) */ | ||
| 276 | 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, | ||
| 277 | }; | ||
| 278 | |||
| 279 | static const u8 init_vals_ver_22[] = { | ||
| 280 | /* QT602240_GEN_COMMAND(6) */ | ||
| 281 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 282 | /* QT602240_GEN_POWER(7) */ | ||
| 283 | 0x20, 0xff, 0x32, | ||
| 284 | /* QT602240_GEN_ACQUIRE(8) */ | ||
| 285 | 0x0a, 0x00, 0x05, 0x00, 0x00, 0x00, 0x09, 0x23, | ||
| 286 | /* QT602240_TOUCH_MULTI(9) */ | ||
| 287 | 0x00, 0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, | ||
| 288 | 0x00, 0x01, 0x01, 0x0e, 0x0a, 0x0a, 0x0a, 0x0a, 0x00, 0x00, | ||
| 289 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 290 | 0x00, | ||
| 291 | /* QT602240_TOUCH_KEYARRAY(15) */ | ||
| 292 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 293 | 0x00, | ||
| 294 | /* QT602240_SPT_GPIOPWM(19) */ | ||
| 295 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 296 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 297 | /* QT602240_PROCI_GRIPFACE(20) */ | ||
| 298 | 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x28, 0x04, | ||
| 299 | 0x0f, 0x0a, | ||
| 300 | /* QT602240_PROCG_NOISE(22) */ | ||
| 301 | 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x23, 0x00, | ||
| 302 | 0x00, 0x05, 0x0f, 0x19, 0x23, 0x2d, 0x03, | ||
| 303 | /* QT602240_TOUCH_PROXIMITY(23) */ | ||
| 304 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 305 | 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 306 | /* QT602240_PROCI_ONETOUCH(24) */ | ||
| 307 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 308 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 309 | /* QT602240_SPT_SELFTEST(25) */ | ||
| 310 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 311 | 0x00, 0x00, 0x00, 0x00, | ||
| 312 | /* QT602240_PROCI_TWOTOUCH(27) */ | ||
| 313 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | ||
| 314 | /* QT602240_SPT_CTECONFIG(28) */ | ||
| 315 | 0x00, 0x00, 0x00, 0x08, 0x10, 0x00, | ||
| 316 | }; | ||
| 317 | |||
| 318 | struct qt602240_info { | ||
| 319 | u8 family_id; | ||
| 320 | u8 variant_id; | ||
| 321 | u8 version; | ||
| 322 | u8 build; | ||
| 323 | u8 matrix_xsize; | ||
| 324 | u8 matrix_ysize; | ||
| 325 | u8 object_num; | ||
| 326 | }; | ||
| 327 | |||
| 328 | struct qt602240_object { | ||
| 329 | u8 type; | ||
| 330 | u16 start_address; | ||
| 331 | u8 size; | ||
| 332 | u8 instances; | ||
| 333 | u8 num_report_ids; | ||
| 334 | |||
| 335 | /* to map object and message */ | ||
| 336 | u8 max_reportid; | ||
| 337 | }; | ||
| 338 | |||
| 339 | struct qt602240_message { | ||
| 340 | u8 reportid; | ||
| 341 | u8 message[7]; | ||
| 342 | u8 checksum; | ||
| 343 | }; | ||
| 344 | |||
| 345 | struct qt602240_finger { | ||
| 346 | int status; | ||
| 347 | int x; | ||
| 348 | int y; | ||
| 349 | int area; | ||
| 350 | }; | ||
| 351 | |||
| 352 | /* Each client has this additional data */ | ||
| 353 | struct qt602240_data { | ||
| 354 | struct i2c_client *client; | ||
| 355 | struct input_dev *input_dev; | ||
| 356 | const struct qt602240_platform_data *pdata; | ||
| 357 | struct qt602240_object *object_table; | ||
| 358 | struct qt602240_info info; | ||
| 359 | struct qt602240_finger finger[QT602240_MAX_FINGER]; | ||
| 360 | unsigned int irq; | ||
| 361 | }; | ||
| 362 | |||
| 363 | static bool qt602240_object_readable(unsigned int type) | ||
| 364 | { | ||
| 365 | switch (type) { | ||
| 366 | case QT602240_GEN_MESSAGE: | ||
| 367 | case QT602240_GEN_COMMAND: | ||
| 368 | case QT602240_GEN_POWER: | ||
| 369 | case QT602240_GEN_ACQUIRE: | ||
| 370 | case QT602240_TOUCH_MULTI: | ||
| 371 | case QT602240_TOUCH_KEYARRAY: | ||
| 372 | case QT602240_TOUCH_PROXIMITY: | ||
| 373 | case QT602240_PROCI_GRIPFACE: | ||
| 374 | case QT602240_PROCG_NOISE: | ||
| 375 | case QT602240_PROCI_ONETOUCH: | ||
| 376 | case QT602240_PROCI_TWOTOUCH: | ||
| 377 | case QT602240_SPT_COMMSCONFIG: | ||
| 378 | case QT602240_SPT_GPIOPWM: | ||
| 379 | case QT602240_SPT_SELFTEST: | ||
| 380 | case QT602240_SPT_CTECONFIG: | ||
| 381 | case QT602240_SPT_USERDATA: | ||
| 382 | return true; | ||
| 383 | default: | ||
| 384 | return false; | ||
| 385 | } | ||
| 386 | } | ||
| 387 | |||
| 388 | static bool qt602240_object_writable(unsigned int type) | ||
| 389 | { | ||
| 390 | switch (type) { | ||
| 391 | case QT602240_GEN_COMMAND: | ||
| 392 | case QT602240_GEN_POWER: | ||
| 393 | case QT602240_GEN_ACQUIRE: | ||
| 394 | case QT602240_TOUCH_MULTI: | ||
| 395 | case QT602240_TOUCH_KEYARRAY: | ||
| 396 | case QT602240_TOUCH_PROXIMITY: | ||
| 397 | case QT602240_PROCI_GRIPFACE: | ||
| 398 | case QT602240_PROCG_NOISE: | ||
| 399 | case QT602240_PROCI_ONETOUCH: | ||
| 400 | case QT602240_PROCI_TWOTOUCH: | ||
| 401 | case QT602240_SPT_GPIOPWM: | ||
| 402 | case QT602240_SPT_SELFTEST: | ||
| 403 | case QT602240_SPT_CTECONFIG: | ||
| 404 | return true; | ||
| 405 | default: | ||
| 406 | return false; | ||
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | static void qt602240_dump_message(struct device *dev, | ||
| 411 | struct qt602240_message *message) | ||
| 412 | { | ||
| 413 | dev_dbg(dev, "reportid:\t0x%x\n", message->reportid); | ||
| 414 | dev_dbg(dev, "message1:\t0x%x\n", message->message[0]); | ||
| 415 | dev_dbg(dev, "message2:\t0x%x\n", message->message[1]); | ||
| 416 | dev_dbg(dev, "message3:\t0x%x\n", message->message[2]); | ||
| 417 | dev_dbg(dev, "message4:\t0x%x\n", message->message[3]); | ||
| 418 | dev_dbg(dev, "message5:\t0x%x\n", message->message[4]); | ||
| 419 | dev_dbg(dev, "message6:\t0x%x\n", message->message[5]); | ||
| 420 | dev_dbg(dev, "message7:\t0x%x\n", message->message[6]); | ||
| 421 | dev_dbg(dev, "checksum:\t0x%x\n", message->checksum); | ||
| 422 | } | ||
| 423 | |||
| 424 | static int qt602240_check_bootloader(struct i2c_client *client, | ||
| 425 | unsigned int state) | ||
| 426 | { | ||
| 427 | u8 val; | ||
| 428 | |||
| 429 | recheck: | ||
| 430 | if (i2c_master_recv(client, &val, 1) != 1) { | ||
| 431 | dev_err(&client->dev, "%s: i2c recv failed\n", __func__); | ||
| 432 | return -EIO; | ||
| 433 | } | ||
| 434 | |||
| 435 | switch (state) { | ||
| 436 | case QT602240_WAITING_BOOTLOAD_CMD: | ||
| 437 | case QT602240_WAITING_FRAME_DATA: | ||
| 438 | val &= ~QT602240_BOOT_STATUS_MASK; | ||
| 439 | break; | ||
| 440 | case QT602240_FRAME_CRC_PASS: | ||
| 441 | if (val == QT602240_FRAME_CRC_CHECK) | ||
| 442 | goto recheck; | ||
| 443 | break; | ||
| 444 | default: | ||
| 445 | return -EINVAL; | ||
| 446 | } | ||
| 447 | |||
| 448 | if (val != state) { | ||
| 449 | dev_err(&client->dev, "Unvalid bootloader mode state\n"); | ||
| 450 | return -EINVAL; | ||
| 451 | } | ||
| 452 | |||
| 453 | return 0; | ||
| 454 | } | ||
| 455 | |||
| 456 | static int qt602240_unlock_bootloader(struct i2c_client *client) | ||
| 457 | { | ||
| 458 | u8 buf[2]; | ||
| 459 | |||
| 460 | buf[0] = QT602240_UNLOCK_CMD_LSB; | ||
| 461 | buf[1] = QT602240_UNLOCK_CMD_MSB; | ||
| 462 | |||
| 463 | if (i2c_master_send(client, buf, 2) != 2) { | ||
| 464 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 465 | return -EIO; | ||
| 466 | } | ||
| 467 | |||
| 468 | return 0; | ||
| 469 | } | ||
| 470 | |||
| 471 | static int qt602240_fw_write(struct i2c_client *client, | ||
| 472 | const u8 *data, unsigned int frame_size) | ||
| 473 | { | ||
| 474 | if (i2c_master_send(client, data, frame_size) != frame_size) { | ||
| 475 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 476 | return -EIO; | ||
| 477 | } | ||
| 478 | |||
| 479 | return 0; | ||
| 480 | } | ||
| 481 | |||
| 482 | static int __qt602240_read_reg(struct i2c_client *client, | ||
| 483 | u16 reg, u16 len, void *val) | ||
| 484 | { | ||
| 485 | struct i2c_msg xfer[2]; | ||
| 486 | u8 buf[2]; | ||
| 487 | |||
| 488 | buf[0] = reg & 0xff; | ||
| 489 | buf[1] = (reg >> 8) & 0xff; | ||
| 490 | |||
| 491 | /* Write register */ | ||
| 492 | xfer[0].addr = client->addr; | ||
| 493 | xfer[0].flags = 0; | ||
| 494 | xfer[0].len = 2; | ||
| 495 | xfer[0].buf = buf; | ||
| 496 | |||
| 497 | /* Read data */ | ||
| 498 | xfer[1].addr = client->addr; | ||
| 499 | xfer[1].flags = I2C_M_RD; | ||
| 500 | xfer[1].len = len; | ||
| 501 | xfer[1].buf = val; | ||
| 502 | |||
| 503 | if (i2c_transfer(client->adapter, xfer, 2) != 2) { | ||
| 504 | dev_err(&client->dev, "%s: i2c transfer failed\n", __func__); | ||
| 505 | return -EIO; | ||
| 506 | } | ||
| 507 | |||
| 508 | return 0; | ||
| 509 | } | ||
| 510 | |||
| 511 | static int qt602240_read_reg(struct i2c_client *client, u16 reg, u8 *val) | ||
| 512 | { | ||
| 513 | return __qt602240_read_reg(client, reg, 1, val); | ||
| 514 | } | ||
| 515 | |||
| 516 | static int qt602240_write_reg(struct i2c_client *client, u16 reg, u8 val) | ||
| 517 | { | ||
| 518 | u8 buf[3]; | ||
| 519 | |||
| 520 | buf[0] = reg & 0xff; | ||
| 521 | buf[1] = (reg >> 8) & 0xff; | ||
| 522 | buf[2] = val; | ||
| 523 | |||
| 524 | if (i2c_master_send(client, buf, 3) != 3) { | ||
| 525 | dev_err(&client->dev, "%s: i2c send failed\n", __func__); | ||
| 526 | return -EIO; | ||
| 527 | } | ||
| 528 | |||
| 529 | return 0; | ||
| 530 | } | ||
| 531 | |||
| 532 | static int qt602240_read_object_table(struct i2c_client *client, | ||
| 533 | u16 reg, u8 *object_buf) | ||
| 534 | { | ||
| 535 | return __qt602240_read_reg(client, reg, QT602240_OBJECT_SIZE, | ||
| 536 | object_buf); | ||
| 537 | } | ||
| 538 | |||
| 539 | static struct qt602240_object * | ||
| 540 | qt602240_get_object(struct qt602240_data *data, u8 type) | ||
| 541 | { | ||
| 542 | struct qt602240_object *object; | ||
| 543 | int i; | ||
| 544 | |||
| 545 | for (i = 0; i < data->info.object_num; i++) { | ||
| 546 | object = data->object_table + i; | ||
| 547 | if (object->type == type) | ||
| 548 | return object; | ||
| 549 | } | ||
| 550 | |||
| 551 | dev_err(&data->client->dev, "Invalid object type\n"); | ||
| 552 | return NULL; | ||
| 553 | } | ||
| 554 | |||
| 555 | static int qt602240_read_message(struct qt602240_data *data, | ||
| 556 | struct qt602240_message *message) | ||
| 557 | { | ||
| 558 | struct qt602240_object *object; | ||
| 559 | u16 reg; | ||
| 560 | |||
| 561 | object = qt602240_get_object(data, QT602240_GEN_MESSAGE); | ||
| 562 | if (!object) | ||
| 563 | return -EINVAL; | ||
| 564 | |||
| 565 | reg = object->start_address; | ||
| 566 | return __qt602240_read_reg(data->client, reg, | ||
| 567 | sizeof(struct qt602240_message), message); | ||
| 568 | } | ||
| 569 | |||
| 570 | static int qt602240_read_object(struct qt602240_data *data, | ||
| 571 | u8 type, u8 offset, u8 *val) | ||
| 572 | { | ||
| 573 | struct qt602240_object *object; | ||
| 574 | u16 reg; | ||
| 575 | |||
| 576 | object = qt602240_get_object(data, type); | ||
| 577 | if (!object) | ||
| 578 | return -EINVAL; | ||
| 579 | |||
| 580 | reg = object->start_address; | ||
| 581 | return __qt602240_read_reg(data->client, reg + offset, 1, val); | ||
| 582 | } | ||
| 583 | |||
| 584 | static int qt602240_write_object(struct qt602240_data *data, | ||
| 585 | u8 type, u8 offset, u8 val) | ||
| 586 | { | ||
| 587 | struct qt602240_object *object; | ||
| 588 | u16 reg; | ||
| 589 | |||
| 590 | object = qt602240_get_object(data, type); | ||
| 591 | if (!object) | ||
| 592 | return -EINVAL; | ||
| 593 | |||
| 594 | reg = object->start_address; | ||
| 595 | return qt602240_write_reg(data->client, reg + offset, val); | ||
| 596 | } | ||
| 597 | |||
| 598 | static void qt602240_input_report(struct qt602240_data *data, int single_id) | ||
| 599 | { | ||
| 600 | struct qt602240_finger *finger = data->finger; | ||
| 601 | struct input_dev *input_dev = data->input_dev; | ||
| 602 | int status = finger[single_id].status; | ||
| 603 | int finger_num = 0; | ||
| 604 | int id; | ||
| 605 | |||
| 606 | for (id = 0; id < QT602240_MAX_FINGER; id++) { | ||
| 607 | if (!finger[id].status) | ||
| 608 | continue; | ||
| 609 | |||
| 610 | input_report_abs(input_dev, ABS_MT_TOUCH_MAJOR, | ||
| 611 | finger[id].status != QT602240_RELEASE ? | ||
| 612 | finger[id].area : 0); | ||
| 613 | input_report_abs(input_dev, ABS_MT_POSITION_X, | ||
| 614 | finger[id].x); | ||
| 615 | input_report_abs(input_dev, ABS_MT_POSITION_Y, | ||
| 616 | finger[id].y); | ||
| 617 | input_mt_sync(input_dev); | ||
| 618 | |||
| 619 | if (finger[id].status == QT602240_RELEASE) | ||
| 620 | finger[id].status = 0; | ||
| 621 | else | ||
| 622 | finger_num++; | ||
| 623 | } | ||
| 624 | |||
| 625 | input_report_key(input_dev, BTN_TOUCH, finger_num > 0); | ||
| 626 | |||
| 627 | if (status != QT602240_RELEASE) { | ||
| 628 | input_report_abs(input_dev, ABS_X, finger[single_id].x); | ||
| 629 | input_report_abs(input_dev, ABS_Y, finger[single_id].y); | ||
| 630 | } | ||
| 631 | |||
| 632 | input_sync(input_dev); | ||
| 633 | } | ||
| 634 | |||
| 635 | static void qt602240_input_touchevent(struct qt602240_data *data, | ||
| 636 | struct qt602240_message *message, int id) | ||
| 637 | { | ||
| 638 | struct qt602240_finger *finger = data->finger; | ||
| 639 | struct device *dev = &data->client->dev; | ||
| 640 | u8 status = message->message[0]; | ||
| 641 | int x; | ||
| 642 | int y; | ||
| 643 | int area; | ||
| 644 | |||
| 645 | /* Check the touch is present on the screen */ | ||
| 646 | if (!(status & QT602240_DETECT)) { | ||
| 647 | if (status & QT602240_RELEASE) { | ||
| 648 | dev_dbg(dev, "[%d] released\n", id); | ||
| 649 | |||
| 650 | finger[id].status = QT602240_RELEASE; | ||
| 651 | qt602240_input_report(data, id); | ||
| 652 | } | ||
| 653 | return; | ||
| 654 | } | ||
| 655 | |||
| 656 | /* Check only AMP detection */ | ||
| 657 | if (!(status & (QT602240_PRESS | QT602240_MOVE))) | ||
| 658 | return; | ||
| 659 | |||
| 660 | x = (message->message[1] << 2) | ((message->message[3] & ~0x3f) >> 6); | ||
| 661 | y = (message->message[2] << 2) | ((message->message[3] & ~0xf3) >> 2); | ||
| 662 | area = message->message[4]; | ||
| 663 | |||
| 664 | dev_dbg(dev, "[%d] %s x: %d, y: %d, area: %d\n", id, | ||
| 665 | status & QT602240_MOVE ? "moved" : "pressed", | ||
| 666 | x, y, area); | ||
| 667 | |||
| 668 | finger[id].status = status & QT602240_MOVE ? | ||
| 669 | QT602240_MOVE : QT602240_PRESS; | ||
| 670 | finger[id].x = x; | ||
| 671 | finger[id].y = y; | ||
| 672 | finger[id].area = area; | ||
| 673 | |||
| 674 | qt602240_input_report(data, id); | ||
| 675 | } | ||
| 676 | |||
| 677 | static irqreturn_t qt602240_interrupt(int irq, void *dev_id) | ||
| 678 | { | ||
| 679 | struct qt602240_data *data = dev_id; | ||
| 680 | struct qt602240_message message; | ||
| 681 | struct qt602240_object *object; | ||
| 682 | struct device *dev = &data->client->dev; | ||
| 683 | int id; | ||
| 684 | u8 reportid; | ||
| 685 | u8 max_reportid; | ||
| 686 | u8 min_reportid; | ||
| 687 | |||
| 688 | do { | ||
| 689 | if (qt602240_read_message(data, &message)) { | ||
| 690 | dev_err(dev, "Failed to read message\n"); | ||
| 691 | goto end; | ||
| 692 | } | ||
| 693 | |||
| 694 | reportid = message.reportid; | ||
| 695 | |||
| 696 | /* whether reportid is thing of QT602240_TOUCH_MULTI */ | ||
| 697 | object = qt602240_get_object(data, QT602240_TOUCH_MULTI); | ||
| 698 | if (!object) | ||
| 699 | goto end; | ||
| 700 | |||
| 701 | max_reportid = object->max_reportid; | ||
| 702 | min_reportid = max_reportid - object->num_report_ids + 1; | ||
| 703 | id = reportid - min_reportid; | ||
| 704 | |||
| 705 | if (reportid >= min_reportid && reportid <= max_reportid) | ||
| 706 | qt602240_input_touchevent(data, &message, id); | ||
| 707 | else | ||
| 708 | qt602240_dump_message(dev, &message); | ||
| 709 | } while (reportid != 0xff); | ||
| 710 | |||
| 711 | end: | ||
| 712 | return IRQ_HANDLED; | ||
| 713 | } | ||
| 714 | |||
| 715 | static int qt602240_check_reg_init(struct qt602240_data *data) | ||
| 716 | { | ||
| 717 | struct qt602240_object *object; | ||
| 718 | struct device *dev = &data->client->dev; | ||
| 719 | int index = 0; | ||
| 720 | int i, j; | ||
| 721 | u8 version = data->info.version; | ||
| 722 | u8 *init_vals; | ||
| 723 | |||
| 724 | switch (version) { | ||
| 725 | case QT602240_VER_20: | ||
| 726 | init_vals = (u8 *)init_vals_ver_20; | ||
| 727 | break; | ||
| 728 | case QT602240_VER_21: | ||
| 729 | init_vals = (u8 *)init_vals_ver_21; | ||
| 730 | break; | ||
| 731 | case QT602240_VER_22: | ||
| 732 | init_vals = (u8 *)init_vals_ver_22; | ||
| 733 | break; | ||
| 734 | default: | ||
| 735 | dev_err(dev, "Firmware version %d doesn't support\n", version); | ||
| 736 | return -EINVAL; | ||
| 737 | } | ||
| 738 | |||
| 739 | for (i = 0; i < data->info.object_num; i++) { | ||
| 740 | object = data->object_table + i; | ||
| 741 | |||
| 742 | if (!qt602240_object_writable(object->type)) | ||
| 743 | continue; | ||
| 744 | |||
| 745 | for (j = 0; j < object->size + 1; j++) | ||
| 746 | qt602240_write_object(data, object->type, j, | ||
| 747 | init_vals[index + j]); | ||
| 748 | |||
| 749 | index += object->size + 1; | ||
| 750 | } | ||
| 751 | |||
| 752 | return 0; | ||
| 753 | } | ||
| 754 | |||
| 755 | static int qt602240_check_matrix_size(struct qt602240_data *data) | ||
| 756 | { | ||
| 757 | const struct qt602240_platform_data *pdata = data->pdata; | ||
| 758 | struct device *dev = &data->client->dev; | ||
| 759 | int mode = -1; | ||
| 760 | int error; | ||
| 761 | u8 val; | ||
| 762 | |||
| 763 | dev_dbg(dev, "Number of X lines: %d\n", pdata->x_line); | ||
| 764 | dev_dbg(dev, "Number of Y lines: %d\n", pdata->y_line); | ||
| 765 | |||
| 766 | switch (pdata->x_line) { | ||
| 767 | case 0 ... 15: | ||
| 768 | if (pdata->y_line <= 14) | ||
| 769 | mode = 0; | ||
| 770 | break; | ||
| 771 | case 16: | ||
| 772 | if (pdata->y_line <= 12) | ||
| 773 | mode = 1; | ||
| 774 | if (pdata->y_line == 13 || pdata->y_line == 14) | ||
| 775 | mode = 0; | ||
| 776 | break; | ||
| 777 | case 17: | ||
| 778 | if (pdata->y_line <= 11) | ||
| 779 | mode = 2; | ||
| 780 | if (pdata->y_line == 12 || pdata->y_line == 13) | ||
| 781 | mode = 1; | ||
| 782 | break; | ||
| 783 | case 18: | ||
| 784 | if (pdata->y_line <= 10) | ||
| 785 | mode = 3; | ||
| 786 | if (pdata->y_line == 11 || pdata->y_line == 12) | ||
| 787 | mode = 2; | ||
| 788 | break; | ||
| 789 | case 19: | ||
| 790 | if (pdata->y_line <= 9) | ||
| 791 | mode = 4; | ||
| 792 | if (pdata->y_line == 10 || pdata->y_line == 11) | ||
| 793 | mode = 3; | ||
| 794 | break; | ||
| 795 | case 20: | ||
| 796 | mode = 4; | ||
| 797 | } | ||
| 798 | |||
| 799 | if (mode < 0) { | ||
| 800 | dev_err(dev, "Invalid X/Y lines\n"); | ||
| 801 | return -EINVAL; | ||
| 802 | } | ||
| 803 | |||
| 804 | error = qt602240_read_object(data, QT602240_SPT_CTECONFIG, | ||
| 805 | QT602240_CTE_MODE, &val); | ||
| 806 | if (error) | ||
| 807 | return error; | ||
| 808 | |||
| 809 | if (mode == val) | ||
| 810 | return 0; | ||
| 811 | |||
| 812 | /* Change the CTE configuration */ | ||
| 813 | qt602240_write_object(data, QT602240_SPT_CTECONFIG, | ||
| 814 | QT602240_CTE_CTRL, 1); | ||
| 815 | qt602240_write_object(data, QT602240_SPT_CTECONFIG, | ||
| 816 | QT602240_CTE_MODE, mode); | ||
| 817 | qt602240_write_object(data, QT602240_SPT_CTECONFIG, | ||
| 818 | QT602240_CTE_CTRL, 0); | ||
| 819 | |||
| 820 | return 0; | ||
| 821 | } | ||
| 822 | |||
| 823 | static int qt602240_make_highchg(struct qt602240_data *data) | ||
| 824 | { | ||
| 825 | struct device *dev = &data->client->dev; | ||
| 826 | int count = 10; | ||
| 827 | int error; | ||
| 828 | u8 val; | ||
| 829 | |||
| 830 | /* Read dummy message to make high CHG pin */ | ||
| 831 | do { | ||
| 832 | error = qt602240_read_object(data, QT602240_GEN_MESSAGE, 0, &val); | ||
| 833 | if (error) | ||
| 834 | return error; | ||
| 835 | } while ((val != 0xff) && --count); | ||
| 836 | |||
| 837 | if (!count) { | ||
| 838 | dev_err(dev, "CHG pin isn't cleared\n"); | ||
| 839 | return -EBUSY; | ||
| 840 | } | ||
| 841 | |||
| 842 | return 0; | ||
| 843 | } | ||
| 844 | |||
| 845 | static void qt602240_handle_pdata(struct qt602240_data *data) | ||
| 846 | { | ||
| 847 | const struct qt602240_platform_data *pdata = data->pdata; | ||
| 848 | u8 voltage; | ||
| 849 | |||
| 850 | /* Set touchscreen lines */ | ||
| 851 | qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_XSIZE, | ||
| 852 | pdata->x_line); | ||
| 853 | qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_YSIZE, | ||
| 854 | pdata->y_line); | ||
| 855 | |||
| 856 | /* Set touchscreen orient */ | ||
| 857 | qt602240_write_object(data, QT602240_TOUCH_MULTI, QT602240_TOUCH_ORIENT, | ||
| 858 | pdata->orient); | ||
| 859 | |||
| 860 | /* Set touchscreen burst length */ | ||
| 861 | qt602240_write_object(data, QT602240_TOUCH_MULTI, | ||
| 862 | QT602240_TOUCH_BLEN, pdata->blen); | ||
| 863 | |||
| 864 | /* Set touchscreen threshold */ | ||
| 865 | qt602240_write_object(data, QT602240_TOUCH_MULTI, | ||
| 866 | QT602240_TOUCH_TCHTHR, pdata->threshold); | ||
| 867 | |||
| 868 | /* Set touchscreen resolution */ | ||
| 869 | qt602240_write_object(data, QT602240_TOUCH_MULTI, | ||
| 870 | QT602240_TOUCH_XRANGE_LSB, (pdata->x_size - 1) & 0xff); | ||
| 871 | qt602240_write_object(data, QT602240_TOUCH_MULTI, | ||
| 872 | QT602240_TOUCH_XRANGE_MSB, (pdata->x_size - 1) >> 8); | ||
| 873 | qt602240_write_object(data, QT602240_TOUCH_MULTI, | ||
| 874 | QT602240_TOUCH_YRANGE_LSB, (pdata->y_size - 1) & 0xff); | ||
| 875 | qt602240_write_object(data, QT602240_TOUCH_MULTI, | ||
| 876 | QT602240_TOUCH_YRANGE_MSB, (pdata->y_size - 1) >> 8); | ||
| 877 | |||
| 878 | /* Set touchscreen voltage */ | ||
| 879 | if (data->info.version >= QT602240_VER_21 && pdata->voltage) { | ||
| 880 | if (pdata->voltage < QT602240_VOLTAGE_DEFAULT) { | ||
| 881 | voltage = (QT602240_VOLTAGE_DEFAULT - pdata->voltage) / | ||
| 882 | QT602240_VOLTAGE_STEP; | ||
| 883 | voltage = 0xff - voltage + 1; | ||
| 884 | } else | ||
| 885 | voltage = (pdata->voltage - QT602240_VOLTAGE_DEFAULT) / | ||
| 886 | QT602240_VOLTAGE_STEP; | ||
| 887 | |||
| 888 | qt602240_write_object(data, QT602240_SPT_CTECONFIG, | ||
| 889 | QT602240_CTE_VOLTAGE, voltage); | ||
| 890 | } | ||
| 891 | } | ||
| 892 | |||
| 893 | static int qt602240_get_info(struct qt602240_data *data) | ||
| 894 | { | ||
| 895 | struct i2c_client *client = data->client; | ||
| 896 | struct qt602240_info *info = &data->info; | ||
| 897 | int error; | ||
| 898 | u8 val; | ||
| 899 | |||
| 900 | error = qt602240_read_reg(client, QT602240_FAMILY_ID, &val); | ||
| 901 | if (error) | ||
| 902 | return error; | ||
| 903 | info->family_id = val; | ||
| 904 | |||
| 905 | error = qt602240_read_reg(client, QT602240_VARIANT_ID, &val); | ||
| 906 | if (error) | ||
| 907 | return error; | ||
| 908 | info->variant_id = val; | ||
| 909 | |||
| 910 | error = qt602240_read_reg(client, QT602240_VERSION, &val); | ||
| 911 | if (error) | ||
| 912 | return error; | ||
| 913 | info->version = val; | ||
| 914 | |||
| 915 | error = qt602240_read_reg(client, QT602240_BUILD, &val); | ||
| 916 | if (error) | ||
| 917 | return error; | ||
| 918 | info->build = val; | ||
| 919 | |||
| 920 | error = qt602240_read_reg(client, QT602240_OBJECT_NUM, &val); | ||
| 921 | if (error) | ||
| 922 | return error; | ||
| 923 | info->object_num = val; | ||
| 924 | |||
| 925 | return 0; | ||
| 926 | } | ||
| 927 | |||
| 928 | static int qt602240_get_object_table(struct qt602240_data *data) | ||
| 929 | { | ||
| 930 | int error; | ||
| 931 | int i; | ||
| 932 | u16 reg; | ||
| 933 | u8 reportid = 0; | ||
| 934 | u8 buf[QT602240_OBJECT_SIZE]; | ||
| 935 | |||
| 936 | for (i = 0; i < data->info.object_num; i++) { | ||
| 937 | struct qt602240_object *object = data->object_table + i; | ||
| 938 | |||
| 939 | reg = QT602240_OBJECT_START + QT602240_OBJECT_SIZE * i; | ||
| 940 | error = qt602240_read_object_table(data->client, reg, buf); | ||
| 941 | if (error) | ||
| 942 | return error; | ||
| 943 | |||
| 944 | object->type = buf[0]; | ||
| 945 | object->start_address = (buf[2] << 8) | buf[1]; | ||
| 946 | object->size = buf[3]; | ||
| 947 | object->instances = buf[4]; | ||
| 948 | object->num_report_ids = buf[5]; | ||
| 949 | |||
| 950 | if (object->num_report_ids) { | ||
| 951 | reportid += object->num_report_ids * | ||
| 952 | (object->instances + 1); | ||
| 953 | object->max_reportid = reportid; | ||
| 954 | } | ||
| 955 | } | ||
| 956 | |||
| 957 | return 0; | ||
| 958 | } | ||
| 959 | |||
| 960 | static int qt602240_initialize(struct qt602240_data *data) | ||
| 961 | { | ||
| 962 | struct i2c_client *client = data->client; | ||
| 963 | struct qt602240_info *info = &data->info; | ||
| 964 | int error; | ||
| 965 | u8 val; | ||
| 966 | |||
| 967 | error = qt602240_get_info(data); | ||
| 968 | if (error) | ||
| 969 | return error; | ||
| 970 | |||
| 971 | data->object_table = kcalloc(info->object_num, | ||
| 972 | sizeof(struct qt602240_object), | ||
| 973 | GFP_KERNEL); | ||
| 974 | if (!data->object_table) { | ||
| 975 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 976 | return -ENOMEM; | ||
| 977 | } | ||
| 978 | |||
| 979 | /* Get object table information */ | ||
| 980 | error = qt602240_get_object_table(data); | ||
| 981 | if (error) | ||
| 982 | return error; | ||
| 983 | |||
| 984 | /* Check register init values */ | ||
| 985 | error = qt602240_check_reg_init(data); | ||
| 986 | if (error) | ||
| 987 | return error; | ||
| 988 | |||
| 989 | /* Check X/Y matrix size */ | ||
| 990 | error = qt602240_check_matrix_size(data); | ||
| 991 | if (error) | ||
| 992 | return error; | ||
| 993 | |||
| 994 | error = qt602240_make_highchg(data); | ||
| 995 | if (error) | ||
| 996 | return error; | ||
| 997 | |||
| 998 | qt602240_handle_pdata(data); | ||
| 999 | |||
| 1000 | /* Backup to memory */ | ||
| 1001 | qt602240_write_object(data, QT602240_GEN_COMMAND, | ||
| 1002 | QT602240_COMMAND_BACKUPNV, | ||
| 1003 | QT602240_BACKUP_VALUE); | ||
| 1004 | msleep(QT602240_BACKUP_TIME); | ||
| 1005 | |||
| 1006 | /* Soft reset */ | ||
| 1007 | qt602240_write_object(data, QT602240_GEN_COMMAND, | ||
| 1008 | QT602240_COMMAND_RESET, 1); | ||
| 1009 | msleep(QT602240_RESET_TIME); | ||
| 1010 | |||
| 1011 | /* Update matrix size at info struct */ | ||
| 1012 | error = qt602240_read_reg(client, QT602240_MATRIX_X_SIZE, &val); | ||
| 1013 | if (error) | ||
| 1014 | return error; | ||
| 1015 | info->matrix_xsize = val; | ||
| 1016 | |||
| 1017 | error = qt602240_read_reg(client, QT602240_MATRIX_Y_SIZE, &val); | ||
| 1018 | if (error) | ||
| 1019 | return error; | ||
| 1020 | info->matrix_ysize = val; | ||
| 1021 | |||
| 1022 | dev_info(&client->dev, | ||
| 1023 | "Family ID: %d Variant ID: %d Version: %d Build: %d\n", | ||
| 1024 | info->family_id, info->variant_id, info->version, | ||
| 1025 | info->build); | ||
| 1026 | |||
| 1027 | dev_info(&client->dev, | ||
| 1028 | "Matrix X Size: %d Matrix Y Size: %d Object Num: %d\n", | ||
| 1029 | info->matrix_xsize, info->matrix_ysize, | ||
| 1030 | info->object_num); | ||
| 1031 | |||
| 1032 | return 0; | ||
| 1033 | } | ||
| 1034 | |||
| 1035 | static ssize_t qt602240_object_show(struct device *dev, | ||
| 1036 | struct device_attribute *attr, char *buf) | ||
| 1037 | { | ||
| 1038 | struct qt602240_data *data = dev_get_drvdata(dev); | ||
| 1039 | struct qt602240_object *object; | ||
| 1040 | int count = 0; | ||
| 1041 | int i, j; | ||
| 1042 | int error; | ||
| 1043 | u8 val; | ||
| 1044 | |||
| 1045 | for (i = 0; i < data->info.object_num; i++) { | ||
| 1046 | object = data->object_table + i; | ||
| 1047 | |||
| 1048 | count += sprintf(buf + count, | ||
| 1049 | "Object Table Element %d(Type %d)\n", | ||
| 1050 | i + 1, object->type); | ||
| 1051 | |||
| 1052 | if (!qt602240_object_readable(object->type)) { | ||
| 1053 | count += sprintf(buf + count, "\n"); | ||
| 1054 | continue; | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | for (j = 0; j < object->size + 1; j++) { | ||
| 1058 | error = qt602240_read_object(data, | ||
| 1059 | object->type, j, &val); | ||
| 1060 | if (error) | ||
| 1061 | return error; | ||
| 1062 | |||
| 1063 | count += sprintf(buf + count, | ||
| 1064 | " Byte %d: 0x%x (%d)\n", j, val, val); | ||
| 1065 | } | ||
| 1066 | |||
| 1067 | count += sprintf(buf + count, "\n"); | ||
| 1068 | } | ||
| 1069 | |||
| 1070 | return count; | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | static int qt602240_load_fw(struct device *dev, const char *fn) | ||
| 1074 | { | ||
| 1075 | struct qt602240_data *data = dev_get_drvdata(dev); | ||
| 1076 | struct i2c_client *client = data->client; | ||
| 1077 | const struct firmware *fw = NULL; | ||
| 1078 | unsigned int frame_size; | ||
| 1079 | unsigned int pos = 0; | ||
| 1080 | int ret; | ||
| 1081 | |||
| 1082 | ret = request_firmware(&fw, fn, dev); | ||
| 1083 | if (ret) { | ||
| 1084 | dev_err(dev, "Unable to open firmware %s\n", fn); | ||
| 1085 | return ret; | ||
| 1086 | } | ||
| 1087 | |||
| 1088 | /* Change to the bootloader mode */ | ||
| 1089 | qt602240_write_object(data, QT602240_GEN_COMMAND, | ||
| 1090 | QT602240_COMMAND_RESET, QT602240_BOOT_VALUE); | ||
| 1091 | msleep(QT602240_RESET_TIME); | ||
| 1092 | |||
| 1093 | /* Change to slave address of bootloader */ | ||
| 1094 | if (client->addr == QT602240_APP_LOW) | ||
| 1095 | client->addr = QT602240_BOOT_LOW; | ||
| 1096 | else | ||
| 1097 | client->addr = QT602240_BOOT_HIGH; | ||
| 1098 | |||
| 1099 | ret = qt602240_check_bootloader(client, QT602240_WAITING_BOOTLOAD_CMD); | ||
| 1100 | if (ret) | ||
| 1101 | goto out; | ||
| 1102 | |||
| 1103 | /* Unlock bootloader */ | ||
| 1104 | qt602240_unlock_bootloader(client); | ||
| 1105 | |||
| 1106 | while (pos < fw->size) { | ||
| 1107 | ret = qt602240_check_bootloader(client, | ||
| 1108 | QT602240_WAITING_FRAME_DATA); | ||
| 1109 | if (ret) | ||
| 1110 | goto out; | ||
| 1111 | |||
| 1112 | frame_size = ((*(fw->data + pos) << 8) | *(fw->data + pos + 1)); | ||
| 1113 | |||
| 1114 | /* We should add 2 at frame size as the the firmware data is not | ||
| 1115 | * included the CRC bytes. | ||
| 1116 | */ | ||
| 1117 | frame_size += 2; | ||
| 1118 | |||
| 1119 | /* Write one frame to device */ | ||
| 1120 | qt602240_fw_write(client, fw->data + pos, frame_size); | ||
| 1121 | |||
| 1122 | ret = qt602240_check_bootloader(client, | ||
| 1123 | QT602240_FRAME_CRC_PASS); | ||
| 1124 | if (ret) | ||
| 1125 | goto out; | ||
| 1126 | |||
| 1127 | pos += frame_size; | ||
| 1128 | |||
| 1129 | dev_dbg(dev, "Updated %d bytes / %zd bytes\n", pos, fw->size); | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | out: | ||
| 1133 | release_firmware(fw); | ||
| 1134 | |||
| 1135 | /* Change to slave address of application */ | ||
| 1136 | if (client->addr == QT602240_BOOT_LOW) | ||
| 1137 | client->addr = QT602240_APP_LOW; | ||
| 1138 | else | ||
| 1139 | client->addr = QT602240_APP_HIGH; | ||
| 1140 | |||
| 1141 | return ret; | ||
| 1142 | } | ||
| 1143 | |||
| 1144 | static ssize_t qt602240_update_fw_store(struct device *dev, | ||
| 1145 | struct device_attribute *attr, | ||
| 1146 | const char *buf, size_t count) | ||
| 1147 | { | ||
| 1148 | struct qt602240_data *data = dev_get_drvdata(dev); | ||
| 1149 | unsigned int version; | ||
| 1150 | int error; | ||
| 1151 | |||
| 1152 | if (sscanf(buf, "%u", &version) != 1) { | ||
| 1153 | dev_err(dev, "Invalid values\n"); | ||
| 1154 | return -EINVAL; | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | if (data->info.version < QT602240_VER_21 || version < QT602240_VER_21) { | ||
| 1158 | dev_err(dev, "FW update supported starting with version 21\n"); | ||
| 1159 | return -EINVAL; | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | disable_irq(data->irq); | ||
| 1163 | |||
| 1164 | error = qt602240_load_fw(dev, QT602240_FW_NAME); | ||
| 1165 | if (error) { | ||
| 1166 | dev_err(dev, "The firmware update failed(%d)\n", error); | ||
| 1167 | count = error; | ||
| 1168 | } else { | ||
| 1169 | dev_dbg(dev, "The firmware update succeeded\n"); | ||
| 1170 | |||
| 1171 | /* Wait for reset */ | ||
| 1172 | msleep(QT602240_FWRESET_TIME); | ||
| 1173 | |||
| 1174 | kfree(data->object_table); | ||
| 1175 | data->object_table = NULL; | ||
| 1176 | |||
| 1177 | qt602240_initialize(data); | ||
| 1178 | } | ||
| 1179 | |||
| 1180 | enable_irq(data->irq); | ||
| 1181 | |||
| 1182 | return count; | ||
| 1183 | } | ||
| 1184 | |||
| 1185 | static DEVICE_ATTR(object, 0444, qt602240_object_show, NULL); | ||
| 1186 | static DEVICE_ATTR(update_fw, 0664, NULL, qt602240_update_fw_store); | ||
| 1187 | |||
| 1188 | static struct attribute *qt602240_attrs[] = { | ||
| 1189 | &dev_attr_object.attr, | ||
| 1190 | &dev_attr_update_fw.attr, | ||
| 1191 | NULL | ||
| 1192 | }; | ||
| 1193 | |||
| 1194 | static const struct attribute_group qt602240_attr_group = { | ||
| 1195 | .attrs = qt602240_attrs, | ||
| 1196 | }; | ||
| 1197 | |||
| 1198 | static void qt602240_start(struct qt602240_data *data) | ||
| 1199 | { | ||
| 1200 | /* Touch enable */ | ||
| 1201 | qt602240_write_object(data, | ||
| 1202 | QT602240_TOUCH_MULTI, QT602240_TOUCH_CTRL, 0x83); | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | static void qt602240_stop(struct qt602240_data *data) | ||
| 1206 | { | ||
| 1207 | /* Touch disable */ | ||
| 1208 | qt602240_write_object(data, | ||
| 1209 | QT602240_TOUCH_MULTI, QT602240_TOUCH_CTRL, 0); | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | static int qt602240_input_open(struct input_dev *dev) | ||
| 1213 | { | ||
| 1214 | struct qt602240_data *data = input_get_drvdata(dev); | ||
| 1215 | |||
| 1216 | qt602240_start(data); | ||
| 1217 | |||
| 1218 | return 0; | ||
| 1219 | } | ||
| 1220 | |||
| 1221 | static void qt602240_input_close(struct input_dev *dev) | ||
| 1222 | { | ||
| 1223 | struct qt602240_data *data = input_get_drvdata(dev); | ||
| 1224 | |||
| 1225 | qt602240_stop(data); | ||
| 1226 | } | ||
| 1227 | |||
| 1228 | static int __devinit qt602240_probe(struct i2c_client *client, | ||
| 1229 | const struct i2c_device_id *id) | ||
| 1230 | { | ||
| 1231 | struct qt602240_data *data; | ||
| 1232 | struct input_dev *input_dev; | ||
| 1233 | int error; | ||
| 1234 | |||
| 1235 | if (!client->dev.platform_data) | ||
| 1236 | return -EINVAL; | ||
| 1237 | |||
| 1238 | data = kzalloc(sizeof(struct qt602240_data), GFP_KERNEL); | ||
| 1239 | input_dev = input_allocate_device(); | ||
| 1240 | if (!data || !input_dev) { | ||
| 1241 | dev_err(&client->dev, "Failed to allocate memory\n"); | ||
| 1242 | error = -ENOMEM; | ||
| 1243 | goto err_free_mem; | ||
| 1244 | } | ||
| 1245 | |||
| 1246 | input_dev->name = "AT42QT602240/ATMXT224 Touchscreen"; | ||
| 1247 | input_dev->id.bustype = BUS_I2C; | ||
| 1248 | input_dev->dev.parent = &client->dev; | ||
| 1249 | input_dev->open = qt602240_input_open; | ||
| 1250 | input_dev->close = qt602240_input_close; | ||
| 1251 | |||
| 1252 | __set_bit(EV_ABS, input_dev->evbit); | ||
| 1253 | __set_bit(EV_KEY, input_dev->evbit); | ||
| 1254 | __set_bit(BTN_TOUCH, input_dev->keybit); | ||
| 1255 | |||
| 1256 | /* For single touch */ | ||
| 1257 | input_set_abs_params(input_dev, ABS_X, | ||
| 1258 | 0, QT602240_MAX_XC, 0, 0); | ||
| 1259 | input_set_abs_params(input_dev, ABS_Y, | ||
| 1260 | 0, QT602240_MAX_YC, 0, 0); | ||
| 1261 | |||
| 1262 | /* For multi touch */ | ||
| 1263 | input_set_abs_params(input_dev, ABS_MT_TOUCH_MAJOR, | ||
| 1264 | 0, QT602240_MAX_AREA, 0, 0); | ||
| 1265 | input_set_abs_params(input_dev, ABS_MT_POSITION_X, | ||
| 1266 | 0, QT602240_MAX_XC, 0, 0); | ||
| 1267 | input_set_abs_params(input_dev, ABS_MT_POSITION_Y, | ||
| 1268 | 0, QT602240_MAX_YC, 0, 0); | ||
| 1269 | |||
| 1270 | input_set_drvdata(input_dev, data); | ||
| 1271 | |||
| 1272 | data->client = client; | ||
| 1273 | data->input_dev = input_dev; | ||
| 1274 | data->pdata = client->dev.platform_data; | ||
| 1275 | data->irq = client->irq; | ||
| 1276 | |||
| 1277 | i2c_set_clientdata(client, data); | ||
| 1278 | |||
| 1279 | error = qt602240_initialize(data); | ||
| 1280 | if (error) | ||
| 1281 | goto err_free_object; | ||
| 1282 | |||
| 1283 | error = request_threaded_irq(client->irq, NULL, qt602240_interrupt, | ||
| 1284 | IRQF_TRIGGER_FALLING, client->dev.driver->name, data); | ||
| 1285 | if (error) { | ||
| 1286 | dev_err(&client->dev, "Failed to register interrupt\n"); | ||
| 1287 | goto err_free_object; | ||
| 1288 | } | ||
| 1289 | |||
| 1290 | error = input_register_device(input_dev); | ||
| 1291 | if (error) | ||
| 1292 | goto err_free_irq; | ||
| 1293 | |||
| 1294 | error = sysfs_create_group(&client->dev.kobj, &qt602240_attr_group); | ||
| 1295 | if (error) | ||
| 1296 | goto err_unregister_device; | ||
| 1297 | |||
| 1298 | return 0; | ||
| 1299 | |||
| 1300 | err_unregister_device: | ||
| 1301 | input_unregister_device(input_dev); | ||
| 1302 | input_dev = NULL; | ||
| 1303 | err_free_irq: | ||
| 1304 | free_irq(client->irq, data); | ||
| 1305 | err_free_object: | ||
| 1306 | kfree(data->object_table); | ||
| 1307 | err_free_mem: | ||
| 1308 | input_free_device(input_dev); | ||
| 1309 | kfree(data); | ||
| 1310 | return error; | ||
| 1311 | } | ||
| 1312 | |||
| 1313 | static int __devexit qt602240_remove(struct i2c_client *client) | ||
| 1314 | { | ||
| 1315 | struct qt602240_data *data = i2c_get_clientdata(client); | ||
| 1316 | |||
| 1317 | sysfs_remove_group(&client->dev.kobj, &qt602240_attr_group); | ||
| 1318 | free_irq(data->irq, data); | ||
| 1319 | input_unregister_device(data->input_dev); | ||
| 1320 | kfree(data->object_table); | ||
| 1321 | kfree(data); | ||
| 1322 | |||
| 1323 | return 0; | ||
| 1324 | } | ||
| 1325 | |||
| 1326 | #ifdef CONFIG_PM | ||
| 1327 | static int qt602240_suspend(struct device *dev) | ||
| 1328 | { | ||
| 1329 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1330 | struct qt602240_data *data = i2c_get_clientdata(client); | ||
| 1331 | struct input_dev *input_dev = data->input_dev; | ||
| 1332 | |||
| 1333 | mutex_lock(&input_dev->mutex); | ||
| 1334 | |||
| 1335 | if (input_dev->users) | ||
| 1336 | qt602240_stop(data); | ||
| 1337 | |||
| 1338 | mutex_unlock(&input_dev->mutex); | ||
| 1339 | |||
| 1340 | return 0; | ||
| 1341 | } | ||
| 1342 | |||
| 1343 | static int qt602240_resume(struct device *dev) | ||
| 1344 | { | ||
| 1345 | struct i2c_client *client = to_i2c_client(dev); | ||
| 1346 | struct qt602240_data *data = i2c_get_clientdata(client); | ||
| 1347 | struct input_dev *input_dev = data->input_dev; | ||
| 1348 | |||
| 1349 | /* Soft reset */ | ||
| 1350 | qt602240_write_object(data, QT602240_GEN_COMMAND, | ||
| 1351 | QT602240_COMMAND_RESET, 1); | ||
| 1352 | |||
| 1353 | msleep(QT602240_RESET_TIME); | ||
| 1354 | |||
| 1355 | mutex_lock(&input_dev->mutex); | ||
| 1356 | |||
| 1357 | if (input_dev->users) | ||
| 1358 | qt602240_start(data); | ||
| 1359 | |||
| 1360 | mutex_unlock(&input_dev->mutex); | ||
| 1361 | |||
| 1362 | return 0; | ||
| 1363 | } | ||
| 1364 | |||
| 1365 | static const struct dev_pm_ops qt602240_pm_ops = { | ||
| 1366 | .suspend = qt602240_suspend, | ||
| 1367 | .resume = qt602240_resume, | ||
| 1368 | }; | ||
| 1369 | #endif | ||
| 1370 | |||
| 1371 | static const struct i2c_device_id qt602240_id[] = { | ||
| 1372 | { "qt602240_ts", 0 }, | ||
| 1373 | { } | ||
| 1374 | }; | ||
| 1375 | MODULE_DEVICE_TABLE(i2c, qt602240_id); | ||
| 1376 | |||
| 1377 | static struct i2c_driver qt602240_driver = { | ||
| 1378 | .driver = { | ||
| 1379 | .name = "qt602240_ts", | ||
| 1380 | .owner = THIS_MODULE, | ||
| 1381 | #ifdef CONFIG_PM | ||
| 1382 | .pm = &qt602240_pm_ops, | ||
| 1383 | #endif | ||
| 1384 | }, | ||
| 1385 | .probe = qt602240_probe, | ||
| 1386 | .remove = __devexit_p(qt602240_remove), | ||
| 1387 | .id_table = qt602240_id, | ||
| 1388 | }; | ||
| 1389 | |||
| 1390 | static int __init qt602240_init(void) | ||
| 1391 | { | ||
| 1392 | return i2c_add_driver(&qt602240_driver); | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | static void __exit qt602240_exit(void) | ||
| 1396 | { | ||
| 1397 | i2c_del_driver(&qt602240_driver); | ||
| 1398 | } | ||
| 1399 | |||
| 1400 | module_init(qt602240_init); | ||
| 1401 | module_exit(qt602240_exit); | ||
| 1402 | |||
| 1403 | /* Module information */ | ||
| 1404 | MODULE_AUTHOR("Joonyoung Shim <jy0922.shim@samsung.com>"); | ||
| 1405 | MODULE_DESCRIPTION("AT42QT602240/ATMXT224 Touchscreen driver"); | ||
| 1406 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/tsc2005.c b/drivers/input/touchscreen/tsc2005.c new file mode 100644 index 00000000000..87420616efa --- /dev/null +++ b/drivers/input/touchscreen/tsc2005.c | |||
| @@ -0,0 +1,756 @@ | |||
| 1 | /* | ||
| 2 | * TSC2005 touchscreen driver | ||
| 3 | * | ||
| 4 | * Copyright (C) 2006-2010 Nokia Corporation | ||
| 5 | * | ||
| 6 | * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com> | ||
| 7 | * based on TSC2301 driver by Klaus K. Pedersen <klaus.k.pedersen@nokia.com> | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License as published by | ||
| 11 | * the Free Software Foundation; either version 2 of the License, or | ||
| 12 | * (at your option) any later version. | ||
| 13 | * | ||
| 14 | * This program is distributed in the hope that it will be useful, | ||
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 17 | * GNU General Public License for more details. | ||
| 18 | * | ||
| 19 | * You should have received a copy of the GNU General Public License | ||
| 20 | * along with this program; if not, write to the Free Software | ||
| 21 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
| 22 | * | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <linux/kernel.h> | ||
| 26 | #include <linux/module.h> | ||
| 27 | #include <linux/input.h> | ||
| 28 | #include <linux/interrupt.h> | ||
| 29 | #include <linux/delay.h> | ||
| 30 | #include <linux/pm.h> | ||
| 31 | #include <linux/spi/spi.h> | ||
| 32 | #include <linux/spi/tsc2005.h> | ||
| 33 | |||
| 34 | /* | ||
| 35 | * The touchscreen interface operates as follows: | ||
| 36 | * | ||
| 37 | * 1) Pen is pressed against the touchscreen. | ||
| 38 | * 2) TSC2005 performs AD conversion. | ||
| 39 | * 3) After the conversion is done TSC2005 drives DAV line down. | ||
| 40 | * 4) GPIO IRQ is received and tsc2005_irq_thread() is scheduled. | ||
| 41 | * 5) tsc2005_irq_thread() queues up an spi transfer to fetch the x, y, z1, z2 | ||
| 42 | * values. | ||
| 43 | * 6) tsc2005_irq_thread() reports coordinates to input layer and sets up | ||
| 44 | * tsc2005_penup_timer() to be called after TSC2005_PENUP_TIME_MS (40ms). | ||
| 45 | * 7) When the penup timer expires, there have not been touch or DAV interrupts | ||
| 46 | * during the last 40ms which means the pen has been lifted. | ||
| 47 | * | ||
| 48 | * ESD recovery via a hardware reset is done if the TSC2005 doesn't respond | ||
| 49 | * after a configurable period (in ms) of activity. If esd_timeout is 0, the | ||
| 50 | * watchdog is disabled. | ||
| 51 | */ | ||
| 52 | |||
| 53 | /* control byte 1 */ | ||
| 54 | #define TSC2005_CMD 0x80 | ||
| 55 | #define TSC2005_CMD_NORMAL 0x00 | ||
| 56 | #define TSC2005_CMD_STOP 0x01 | ||
| 57 | #define TSC2005_CMD_12BIT 0x04 | ||
| 58 | |||
| 59 | /* control byte 0 */ | ||
| 60 | #define TSC2005_REG_READ 0x0001 | ||
| 61 | #define TSC2005_REG_PND0 0x0002 | ||
| 62 | #define TSC2005_REG_X 0x0000 | ||
| 63 | #define TSC2005_REG_Y 0x0008 | ||
| 64 | #define TSC2005_REG_Z1 0x0010 | ||
| 65 | #define TSC2005_REG_Z2 0x0018 | ||
| 66 | #define TSC2005_REG_TEMP_HIGH 0x0050 | ||
| 67 | #define TSC2005_REG_CFR0 0x0060 | ||
| 68 | #define TSC2005_REG_CFR1 0x0068 | ||
| 69 | #define TSC2005_REG_CFR2 0x0070 | ||
| 70 | |||
| 71 | /* configuration register 0 */ | ||
| 72 | #define TSC2005_CFR0_PRECHARGE_276US 0x0040 | ||
| 73 | #define TSC2005_CFR0_STABTIME_1MS 0x0300 | ||
| 74 | #define TSC2005_CFR0_CLOCK_1MHZ 0x1000 | ||
| 75 | #define TSC2005_CFR0_RESOLUTION12 0x2000 | ||
| 76 | #define TSC2005_CFR0_PENMODE 0x8000 | ||
| 77 | #define TSC2005_CFR0_INITVALUE (TSC2005_CFR0_STABTIME_1MS | \ | ||
| 78 | TSC2005_CFR0_CLOCK_1MHZ | \ | ||
| 79 | TSC2005_CFR0_RESOLUTION12 | \ | ||
| 80 | TSC2005_CFR0_PRECHARGE_276US | \ | ||
| 81 | TSC2005_CFR0_PENMODE) | ||
| 82 | |||
| 83 | /* bits common to both read and write of configuration register 0 */ | ||
| 84 | #define TSC2005_CFR0_RW_MASK 0x3fff | ||
| 85 | |||
| 86 | /* configuration register 1 */ | ||
| 87 | #define TSC2005_CFR1_BATCHDELAY_4MS 0x0003 | ||
| 88 | #define TSC2005_CFR1_INITVALUE TSC2005_CFR1_BATCHDELAY_4MS | ||
| 89 | |||
| 90 | /* configuration register 2 */ | ||
| 91 | #define TSC2005_CFR2_MAVE_Z 0x0004 | ||
| 92 | #define TSC2005_CFR2_MAVE_Y 0x0008 | ||
| 93 | #define TSC2005_CFR2_MAVE_X 0x0010 | ||
| 94 | #define TSC2005_CFR2_AVG_7 0x0800 | ||
| 95 | #define TSC2005_CFR2_MEDIUM_15 0x3000 | ||
| 96 | #define TSC2005_CFR2_INITVALUE (TSC2005_CFR2_MAVE_X | \ | ||
| 97 | TSC2005_CFR2_MAVE_Y | \ | ||
| 98 | TSC2005_CFR2_MAVE_Z | \ | ||
| 99 | TSC2005_CFR2_MEDIUM_15 | \ | ||
| 100 | TSC2005_CFR2_AVG_7) | ||
| 101 | |||
| 102 | #define MAX_12BIT 0xfff | ||
| 103 | #define TSC2005_SPI_MAX_SPEED_HZ 10000000 | ||
| 104 | #define TSC2005_PENUP_TIME_MS 40 | ||
| 105 | |||
| 106 | struct tsc2005_spi_rd { | ||
| 107 | struct spi_transfer spi_xfer; | ||
| 108 | u32 spi_tx; | ||
| 109 | u32 spi_rx; | ||
| 110 | }; | ||
| 111 | |||
| 112 | struct tsc2005 { | ||
| 113 | struct spi_device *spi; | ||
| 114 | |||
| 115 | struct spi_message spi_read_msg; | ||
| 116 | struct tsc2005_spi_rd spi_x; | ||
| 117 | struct tsc2005_spi_rd spi_y; | ||
| 118 | struct tsc2005_spi_rd spi_z1; | ||
| 119 | struct tsc2005_spi_rd spi_z2; | ||
| 120 | |||
| 121 | struct input_dev *idev; | ||
| 122 | char phys[32]; | ||
| 123 | |||
| 124 | struct mutex mutex; | ||
| 125 | |||
| 126 | /* raw copy of previous x,y,z */ | ||
| 127 | int in_x; | ||
| 128 | int in_y; | ||
| 129 | int in_z1; | ||
| 130 | int in_z2; | ||
| 131 | |||
| 132 | spinlock_t lock; | ||
| 133 | struct timer_list penup_timer; | ||
| 134 | |||
| 135 | unsigned int esd_timeout; | ||
| 136 | struct delayed_work esd_work; | ||
| 137 | unsigned long last_valid_interrupt; | ||
| 138 | |||
| 139 | unsigned int x_plate_ohm; | ||
| 140 | |||
| 141 | bool opened; | ||
| 142 | bool suspended; | ||
| 143 | |||
| 144 | bool pen_down; | ||
| 145 | |||
| 146 | void (*set_reset)(bool enable); | ||
| 147 | }; | ||
| 148 | |||
| 149 | static int tsc2005_cmd(struct tsc2005 *ts, u8 cmd) | ||
| 150 | { | ||
| 151 | u8 tx = TSC2005_CMD | TSC2005_CMD_12BIT | cmd; | ||
| 152 | struct spi_transfer xfer = { | ||
| 153 | .tx_buf = &tx, | ||
| 154 | .len = 1, | ||
| 155 | .bits_per_word = 8, | ||
| 156 | }; | ||
| 157 | struct spi_message msg; | ||
| 158 | int error; | ||
| 159 | |||
| 160 | spi_message_init(&msg); | ||
| 161 | spi_message_add_tail(&xfer, &msg); | ||
| 162 | |||
| 163 | error = spi_sync(ts->spi, &msg); | ||
| 164 | if (error) { | ||
| 165 | dev_err(&ts->spi->dev, "%s: failed, command: %x, error: %d\n", | ||
| 166 | __func__, cmd, error); | ||
| 167 | return error; | ||
| 168 | } | ||
| 169 | |||
| 170 | return 0; | ||
| 171 | } | ||
| 172 | |||
| 173 | static int tsc2005_write(struct tsc2005 *ts, u8 reg, u16 value) | ||
| 174 | { | ||
| 175 | u32 tx = ((reg | TSC2005_REG_PND0) << 16) | value; | ||
| 176 | struct spi_transfer xfer = { | ||
| 177 | .tx_buf = &tx, | ||
| 178 | .len = 4, | ||
| 179 | .bits_per_word = 24, | ||
| 180 | }; | ||
| 181 | struct spi_message msg; | ||
| 182 | int error; | ||
| 183 | |||
| 184 | spi_message_init(&msg); | ||
| 185 | spi_message_add_tail(&xfer, &msg); | ||
| 186 | |||
| 187 | error = spi_sync(ts->spi, &msg); | ||
| 188 | if (error) { | ||
| 189 | dev_err(&ts->spi->dev, | ||
| 190 | "%s: failed, register: %x, value: %x, error: %d\n", | ||
| 191 | __func__, reg, value, error); | ||
| 192 | return error; | ||
| 193 | } | ||
| 194 | |||
| 195 | return 0; | ||
| 196 | } | ||
| 197 | |||
| 198 | static void tsc2005_setup_read(struct tsc2005_spi_rd *rd, u8 reg, bool last) | ||
| 199 | { | ||
| 200 | memset(rd, 0, sizeof(*rd)); | ||
| 201 | |||
| 202 | rd->spi_tx = (reg | TSC2005_REG_READ) << 16; | ||
| 203 | rd->spi_xfer.tx_buf = &rd->spi_tx; | ||
| 204 | rd->spi_xfer.rx_buf = &rd->spi_rx; | ||
| 205 | rd->spi_xfer.len = 4; | ||
| 206 | rd->spi_xfer.bits_per_word = 24; | ||
| 207 | rd->spi_xfer.cs_change = !last; | ||
| 208 | } | ||
| 209 | |||
| 210 | static int tsc2005_read(struct tsc2005 *ts, u8 reg, u16 *value) | ||
| 211 | { | ||
| 212 | struct tsc2005_spi_rd spi_rd; | ||
| 213 | struct spi_message msg; | ||
| 214 | int error; | ||
| 215 | |||
| 216 | tsc2005_setup_read(&spi_rd, reg, true); | ||
| 217 | |||
| 218 | spi_message_init(&msg); | ||
| 219 | spi_message_add_tail(&spi_rd.spi_xfer, &msg); | ||
| 220 | |||
| 221 | error = spi_sync(ts->spi, &msg); | ||
| 222 | if (error) | ||
| 223 | return error; | ||
| 224 | |||
| 225 | *value = spi_rd.spi_rx; | ||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | |||
| 229 | static void tsc2005_update_pen_state(struct tsc2005 *ts, | ||
| 230 | int x, int y, int pressure) | ||
| 231 | { | ||
| 232 | if (pressure) { | ||
| 233 | input_report_abs(ts->idev, ABS_X, x); | ||
| 234 | input_report_abs(ts->idev, ABS_Y, y); | ||
| 235 | input_report_abs(ts->idev, ABS_PRESSURE, pressure); | ||
| 236 | if (!ts->pen_down) { | ||
| 237 | input_report_key(ts->idev, BTN_TOUCH, !!pressure); | ||
| 238 | ts->pen_down = true; | ||
| 239 | } | ||
| 240 | } else { | ||
| 241 | input_report_abs(ts->idev, ABS_PRESSURE, 0); | ||
| 242 | if (ts->pen_down) { | ||
| 243 | input_report_key(ts->idev, BTN_TOUCH, 0); | ||
| 244 | ts->pen_down = false; | ||
| 245 | } | ||
| 246 | } | ||
| 247 | input_sync(ts->idev); | ||
| 248 | dev_dbg(&ts->spi->dev, "point(%4d,%4d), pressure (%4d)\n", x, y, | ||
| 249 | pressure); | ||
| 250 | } | ||
| 251 | |||
| 252 | static irqreturn_t tsc2005_irq_thread(int irq, void *_ts) | ||
| 253 | { | ||
| 254 | struct tsc2005 *ts = _ts; | ||
| 255 | unsigned long flags; | ||
| 256 | unsigned int pressure; | ||
| 257 | u32 x, y; | ||
| 258 | u32 z1, z2; | ||
| 259 | int error; | ||
| 260 | |||
| 261 | /* read the coordinates */ | ||
| 262 | error = spi_sync(ts->spi, &ts->spi_read_msg); | ||
| 263 | if (unlikely(error)) | ||
| 264 | goto out; | ||
| 265 | |||
| 266 | x = ts->spi_x.spi_rx; | ||
| 267 | y = ts->spi_y.spi_rx; | ||
| 268 | z1 = ts->spi_z1.spi_rx; | ||
| 269 | z2 = ts->spi_z2.spi_rx; | ||
| 270 | |||
| 271 | /* validate position */ | ||
| 272 | if (unlikely(x > MAX_12BIT || y > MAX_12BIT)) | ||
| 273 | goto out; | ||
| 274 | |||
| 275 | /* Skip reading if the pressure components are out of range */ | ||
| 276 | if (unlikely(z1 == 0 || z2 > MAX_12BIT || z1 >= z2)) | ||
| 277 | goto out; | ||
| 278 | |||
| 279 | /* | ||
| 280 | * Skip point if this is a pen down with the exact same values as | ||
| 281 | * the value before pen-up - that implies SPI fed us stale data | ||
| 282 | */ | ||
| 283 | if (!ts->pen_down && | ||
| 284 | ts->in_x == x && ts->in_y == y && | ||
| 285 | ts->in_z1 == z1 && ts->in_z2 == z2) { | ||
| 286 | goto out; | ||
| 287 | } | ||
| 288 | |||
| 289 | /* | ||
| 290 | * At this point we are happy we have a valid and useful reading. | ||
| 291 | * Remember it for later comparisons. We may now begin downsampling. | ||
| 292 | */ | ||
| 293 | ts->in_x = x; | ||
| 294 | ts->in_y = y; | ||
| 295 | ts->in_z1 = z1; | ||
| 296 | ts->in_z2 = z2; | ||
| 297 | |||
| 298 | /* Compute touch pressure resistance using equation #1 */ | ||
| 299 | pressure = x * (z2 - z1) / z1; | ||
| 300 | pressure = pressure * ts->x_plate_ohm / 4096; | ||
| 301 | if (unlikely(pressure > MAX_12BIT)) | ||
| 302 | goto out; | ||
| 303 | |||
| 304 | spin_lock_irqsave(&ts->lock, flags); | ||
| 305 | |||
| 306 | tsc2005_update_pen_state(ts, x, y, pressure); | ||
| 307 | mod_timer(&ts->penup_timer, | ||
| 308 | jiffies + msecs_to_jiffies(TSC2005_PENUP_TIME_MS)); | ||
| 309 | |||
| 310 | spin_unlock_irqrestore(&ts->lock, flags); | ||
| 311 | |||
| 312 | ts->last_valid_interrupt = jiffies; | ||
| 313 | out: | ||
| 314 | return IRQ_HANDLED; | ||
| 315 | } | ||
| 316 | |||
| 317 | static void tsc2005_penup_timer(unsigned long data) | ||
| 318 | { | ||
| 319 | struct tsc2005 *ts = (struct tsc2005 *)data; | ||
| 320 | unsigned long flags; | ||
| 321 | |||
| 322 | spin_lock_irqsave(&ts->lock, flags); | ||
| 323 | tsc2005_update_pen_state(ts, 0, 0, 0); | ||
| 324 | spin_unlock_irqrestore(&ts->lock, flags); | ||
| 325 | } | ||
| 326 | |||
| 327 | static void tsc2005_start_scan(struct tsc2005 *ts) | ||
| 328 | { | ||
| 329 | tsc2005_write(ts, TSC2005_REG_CFR0, TSC2005_CFR0_INITVALUE); | ||
| 330 | tsc2005_write(ts, TSC2005_REG_CFR1, TSC2005_CFR1_INITVALUE); | ||
| 331 | tsc2005_write(ts, TSC2005_REG_CFR2, TSC2005_CFR2_INITVALUE); | ||
| 332 | tsc2005_cmd(ts, TSC2005_CMD_NORMAL); | ||
| 333 | } | ||
| 334 | |||
| 335 | static void tsc2005_stop_scan(struct tsc2005 *ts) | ||
| 336 | { | ||
| 337 | tsc2005_cmd(ts, TSC2005_CMD_STOP); | ||
| 338 | } | ||
| 339 | |||
| 340 | /* must be called with ts->mutex held */ | ||
| 341 | static void __tsc2005_disable(struct tsc2005 *ts) | ||
| 342 | { | ||
| 343 | tsc2005_stop_scan(ts); | ||
| 344 | |||
| 345 | disable_irq(ts->spi->irq); | ||
| 346 | del_timer_sync(&ts->penup_timer); | ||
| 347 | |||
| 348 | cancel_delayed_work_sync(&ts->esd_work); | ||
| 349 | |||
| 350 | enable_irq(ts->spi->irq); | ||
| 351 | } | ||
| 352 | |||
| 353 | /* must be called with ts->mutex held */ | ||
| 354 | static void __tsc2005_enable(struct tsc2005 *ts) | ||
| 355 | { | ||
| 356 | tsc2005_start_scan(ts); | ||
| 357 | |||
| 358 | if (ts->esd_timeout && ts->set_reset) { | ||
| 359 | ts->last_valid_interrupt = jiffies; | ||
| 360 | schedule_delayed_work(&ts->esd_work, | ||
| 361 | round_jiffies(jiffies + | ||
| 362 | msecs_to_jiffies(ts->esd_timeout))); | ||
| 363 | } | ||
| 364 | |||
| 365 | } | ||
| 366 | |||
| 367 | static ssize_t tsc2005_selftest_show(struct device *dev, | ||
| 368 | struct device_attribute *attr, | ||
| 369 | char *buf) | ||
| 370 | { | ||
| 371 | struct spi_device *spi = to_spi_device(dev); | ||
| 372 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 373 | u16 temp_high; | ||
| 374 | u16 temp_high_orig; | ||
| 375 | u16 temp_high_test; | ||
| 376 | bool success = true; | ||
| 377 | int error; | ||
| 378 | |||
| 379 | mutex_lock(&ts->mutex); | ||
| 380 | |||
| 381 | /* | ||
| 382 | * Test TSC2005 communications via temp high register. | ||
| 383 | */ | ||
| 384 | __tsc2005_disable(ts); | ||
| 385 | |||
| 386 | error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high_orig); | ||
| 387 | if (error) { | ||
| 388 | dev_warn(dev, "selftest failed: read error %d\n", error); | ||
| 389 | success = false; | ||
| 390 | goto out; | ||
| 391 | } | ||
| 392 | |||
| 393 | temp_high_test = (temp_high_orig - 1) & MAX_12BIT; | ||
| 394 | |||
| 395 | error = tsc2005_write(ts, TSC2005_REG_TEMP_HIGH, temp_high_test); | ||
| 396 | if (error) { | ||
| 397 | dev_warn(dev, "selftest failed: write error %d\n", error); | ||
| 398 | success = false; | ||
| 399 | goto out; | ||
| 400 | } | ||
| 401 | |||
| 402 | error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high); | ||
| 403 | if (error) { | ||
| 404 | dev_warn(dev, "selftest failed: read error %d after write\n", | ||
| 405 | error); | ||
| 406 | success = false; | ||
| 407 | goto out; | ||
| 408 | } | ||
| 409 | |||
| 410 | if (temp_high != temp_high_test) { | ||
| 411 | dev_warn(dev, "selftest failed: %d != %d\n", | ||
| 412 | temp_high, temp_high_test); | ||
| 413 | success = false; | ||
| 414 | } | ||
| 415 | |||
| 416 | /* hardware reset */ | ||
| 417 | ts->set_reset(false); | ||
| 418 | usleep_range(100, 500); /* only 10us required */ | ||
| 419 | ts->set_reset(true); | ||
| 420 | |||
| 421 | if (!success) | ||
| 422 | goto out; | ||
| 423 | |||
| 424 | /* test that the reset really happened */ | ||
| 425 | error = tsc2005_read(ts, TSC2005_REG_TEMP_HIGH, &temp_high); | ||
| 426 | if (error) { | ||
| 427 | dev_warn(dev, "selftest failed: read error %d after reset\n", | ||
| 428 | error); | ||
| 429 | success = false; | ||
| 430 | goto out; | ||
| 431 | } | ||
| 432 | |||
| 433 | if (temp_high != temp_high_orig) { | ||
| 434 | dev_warn(dev, "selftest failed after reset: %d != %d\n", | ||
| 435 | temp_high, temp_high_orig); | ||
| 436 | success = false; | ||
| 437 | } | ||
| 438 | |||
| 439 | out: | ||
| 440 | __tsc2005_enable(ts); | ||
| 441 | mutex_unlock(&ts->mutex); | ||
| 442 | |||
| 443 | return sprintf(buf, "%d\n", success); | ||
| 444 | } | ||
| 445 | |||
| 446 | static DEVICE_ATTR(selftest, S_IRUGO, tsc2005_selftest_show, NULL); | ||
| 447 | |||
| 448 | static struct attribute *tsc2005_attrs[] = { | ||
| 449 | &dev_attr_selftest.attr, | ||
| 450 | NULL | ||
| 451 | }; | ||
| 452 | |||
| 453 | static mode_t tsc2005_attr_is_visible(struct kobject *kobj, | ||
| 454 | struct attribute *attr, int n) | ||
| 455 | { | ||
| 456 | struct device *dev = container_of(kobj, struct device, kobj); | ||
| 457 | struct spi_device *spi = to_spi_device(dev); | ||
| 458 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 459 | mode_t mode = attr->mode; | ||
| 460 | |||
| 461 | if (attr == &dev_attr_selftest.attr) { | ||
| 462 | if (!ts->set_reset) | ||
| 463 | mode = 0; | ||
| 464 | } | ||
| 465 | |||
| 466 | return mode; | ||
| 467 | } | ||
| 468 | |||
| 469 | static const struct attribute_group tsc2005_attr_group = { | ||
| 470 | .is_visible = tsc2005_attr_is_visible, | ||
| 471 | .attrs = tsc2005_attrs, | ||
| 472 | }; | ||
| 473 | |||
| 474 | static void tsc2005_esd_work(struct work_struct *work) | ||
| 475 | { | ||
| 476 | struct tsc2005 *ts = container_of(work, struct tsc2005, esd_work.work); | ||
| 477 | int error; | ||
| 478 | u16 r; | ||
| 479 | |||
| 480 | mutex_lock(&ts->mutex); | ||
| 481 | |||
| 482 | if (time_is_after_jiffies(ts->last_valid_interrupt + | ||
| 483 | msecs_to_jiffies(ts->esd_timeout))) | ||
| 484 | goto out; | ||
| 485 | |||
| 486 | /* We should be able to read register without disabling interrupts. */ | ||
| 487 | error = tsc2005_read(ts, TSC2005_REG_CFR0, &r); | ||
| 488 | if (!error && | ||
| 489 | !((r ^ TSC2005_CFR0_INITVALUE) & TSC2005_CFR0_RW_MASK)) { | ||
| 490 | goto out; | ||
| 491 | } | ||
| 492 | |||
| 493 | /* | ||
| 494 | * If we could not read our known value from configuration register 0 | ||
| 495 | * then we should reset the controller as if from power-up and start | ||
| 496 | * scanning again. | ||
| 497 | */ | ||
| 498 | dev_info(&ts->spi->dev, "TSC2005 not responding - resetting\n"); | ||
| 499 | |||
| 500 | disable_irq(ts->spi->irq); | ||
| 501 | del_timer_sync(&ts->penup_timer); | ||
| 502 | |||
| 503 | tsc2005_update_pen_state(ts, 0, 0, 0); | ||
| 504 | |||
| 505 | ts->set_reset(false); | ||
| 506 | usleep_range(100, 500); /* only 10us required */ | ||
| 507 | ts->set_reset(true); | ||
| 508 | |||
| 509 | enable_irq(ts->spi->irq); | ||
| 510 | tsc2005_start_scan(ts); | ||
| 511 | |||
| 512 | out: | ||
| 513 | /* re-arm the watchdog */ | ||
| 514 | schedule_delayed_work(&ts->esd_work, | ||
| 515 | round_jiffies(jiffies + | ||
| 516 | msecs_to_jiffies(ts->esd_timeout))); | ||
| 517 | mutex_unlock(&ts->mutex); | ||
| 518 | } | ||
| 519 | |||
| 520 | static int tsc2005_open(struct input_dev *input) | ||
| 521 | { | ||
| 522 | struct tsc2005 *ts = input_get_drvdata(input); | ||
| 523 | |||
| 524 | mutex_lock(&ts->mutex); | ||
| 525 | |||
| 526 | if (!ts->suspended) | ||
| 527 | __tsc2005_enable(ts); | ||
| 528 | |||
| 529 | ts->opened = true; | ||
| 530 | |||
| 531 | mutex_unlock(&ts->mutex); | ||
| 532 | |||
| 533 | return 0; | ||
| 534 | } | ||
| 535 | |||
| 536 | static void tsc2005_close(struct input_dev *input) | ||
| 537 | { | ||
| 538 | struct tsc2005 *ts = input_get_drvdata(input); | ||
| 539 | |||
| 540 | mutex_lock(&ts->mutex); | ||
| 541 | |||
| 542 | if (!ts->suspended) | ||
| 543 | __tsc2005_disable(ts); | ||
| 544 | |||
| 545 | ts->opened = false; | ||
| 546 | |||
| 547 | mutex_unlock(&ts->mutex); | ||
| 548 | } | ||
| 549 | |||
| 550 | static void __devinit tsc2005_setup_spi_xfer(struct tsc2005 *ts) | ||
| 551 | { | ||
| 552 | tsc2005_setup_read(&ts->spi_x, TSC2005_REG_X, false); | ||
| 553 | tsc2005_setup_read(&ts->spi_y, TSC2005_REG_Y, false); | ||
| 554 | tsc2005_setup_read(&ts->spi_z1, TSC2005_REG_Z1, false); | ||
| 555 | tsc2005_setup_read(&ts->spi_z2, TSC2005_REG_Z2, true); | ||
| 556 | |||
| 557 | spi_message_init(&ts->spi_read_msg); | ||
| 558 | spi_message_add_tail(&ts->spi_x.spi_xfer, &ts->spi_read_msg); | ||
| 559 | spi_message_add_tail(&ts->spi_y.spi_xfer, &ts->spi_read_msg); | ||
| 560 | spi_message_add_tail(&ts->spi_z1.spi_xfer, &ts->spi_read_msg); | ||
| 561 | spi_message_add_tail(&ts->spi_z2.spi_xfer, &ts->spi_read_msg); | ||
| 562 | } | ||
| 563 | |||
| 564 | static int __devinit tsc2005_probe(struct spi_device *spi) | ||
| 565 | { | ||
| 566 | const struct tsc2005_platform_data *pdata = spi->dev.platform_data; | ||
| 567 | struct tsc2005 *ts; | ||
| 568 | struct input_dev *input_dev; | ||
| 569 | unsigned int max_x, max_y, max_p; | ||
| 570 | unsigned int fudge_x, fudge_y, fudge_p; | ||
| 571 | int error; | ||
| 572 | |||
| 573 | if (!pdata) { | ||
| 574 | dev_dbg(&spi->dev, "no platform data\n"); | ||
| 575 | return -ENODEV; | ||
| 576 | } | ||
| 577 | |||
| 578 | fudge_x = pdata->ts_x_fudge ? : 4; | ||
| 579 | fudge_y = pdata->ts_y_fudge ? : 8; | ||
| 580 | fudge_p = pdata->ts_pressure_fudge ? : 2; | ||
| 581 | max_x = pdata->ts_x_max ? : MAX_12BIT; | ||
| 582 | max_y = pdata->ts_y_max ? : MAX_12BIT; | ||
| 583 | max_p = pdata->ts_pressure_max ? : MAX_12BIT; | ||
| 584 | |||
| 585 | if (spi->irq <= 0) { | ||
| 586 | dev_dbg(&spi->dev, "no irq\n"); | ||
| 587 | return -ENODEV; | ||
| 588 | } | ||
| 589 | |||
| 590 | spi->mode = SPI_MODE_0; | ||
| 591 | spi->bits_per_word = 8; | ||
| 592 | if (!spi->max_speed_hz) | ||
| 593 | spi->max_speed_hz = TSC2005_SPI_MAX_SPEED_HZ; | ||
| 594 | |||
| 595 | error = spi_setup(spi); | ||
| 596 | if (error) | ||
| 597 | return error; | ||
| 598 | |||
| 599 | ts = kzalloc(sizeof(*ts), GFP_KERNEL); | ||
| 600 | input_dev = input_allocate_device(); | ||
| 601 | if (!ts || !input_dev) { | ||
| 602 | error = -ENOMEM; | ||
| 603 | goto err_free_mem; | ||
| 604 | } | ||
| 605 | |||
| 606 | ts->spi = spi; | ||
| 607 | ts->idev = input_dev; | ||
| 608 | |||
| 609 | ts->x_plate_ohm = pdata->ts_x_plate_ohm ? : 280; | ||
| 610 | ts->esd_timeout = pdata->esd_timeout_ms; | ||
| 611 | ts->set_reset = pdata->set_reset; | ||
| 612 | |||
| 613 | mutex_init(&ts->mutex); | ||
| 614 | |||
| 615 | spin_lock_init(&ts->lock); | ||
| 616 | setup_timer(&ts->penup_timer, tsc2005_penup_timer, (unsigned long)ts); | ||
| 617 | |||
| 618 | INIT_DELAYED_WORK(&ts->esd_work, tsc2005_esd_work); | ||
| 619 | |||
| 620 | tsc2005_setup_spi_xfer(ts); | ||
| 621 | |||
| 622 | snprintf(ts->phys, sizeof(ts->phys), | ||
| 623 | "%s/input-ts", dev_name(&spi->dev)); | ||
| 624 | |||
| 625 | input_dev->name = "TSC2005 touchscreen"; | ||
| 626 | input_dev->phys = ts->phys; | ||
| 627 | input_dev->id.bustype = BUS_SPI; | ||
| 628 | input_dev->dev.parent = &spi->dev; | ||
| 629 | input_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); | ||
| 630 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); | ||
| 631 | |||
| 632 | input_set_abs_params(input_dev, ABS_X, 0, max_x, fudge_x, 0); | ||
| 633 | input_set_abs_params(input_dev, ABS_Y, 0, max_y, fudge_y, 0); | ||
| 634 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, max_p, fudge_p, 0); | ||
| 635 | |||
| 636 | input_dev->open = tsc2005_open; | ||
| 637 | input_dev->close = tsc2005_close; | ||
| 638 | |||
| 639 | input_set_drvdata(input_dev, ts); | ||
| 640 | |||
| 641 | /* Ensure the touchscreen is off */ | ||
| 642 | tsc2005_stop_scan(ts); | ||
| 643 | |||
| 644 | error = request_threaded_irq(spi->irq, NULL, tsc2005_irq_thread, | ||
| 645 | IRQF_TRIGGER_RISING, "tsc2005", ts); | ||
| 646 | if (error) { | ||
| 647 | dev_err(&spi->dev, "Failed to request irq, err: %d\n", error); | ||
| 648 | goto err_free_mem; | ||
| 649 | } | ||
| 650 | |||
| 651 | spi_set_drvdata(spi, ts); | ||
| 652 | error = sysfs_create_group(&spi->dev.kobj, &tsc2005_attr_group); | ||
| 653 | if (error) { | ||
| 654 | dev_err(&spi->dev, | ||
| 655 | "Failed to create sysfs attributes, err: %d\n", error); | ||
| 656 | goto err_clear_drvdata; | ||
| 657 | } | ||
| 658 | |||
| 659 | error = input_register_device(ts->idev); | ||
| 660 | if (error) { | ||
| 661 | dev_err(&spi->dev, | ||
| 662 | "Failed to register input device, err: %d\n", error); | ||
| 663 | goto err_remove_sysfs; | ||
| 664 | } | ||
| 665 | |||
| 666 | set_irq_wake(spi->irq, 1); | ||
| 667 | return 0; | ||
| 668 | |||
| 669 | err_remove_sysfs: | ||
| 670 | sysfs_remove_group(&spi->dev.kobj, &tsc2005_attr_group); | ||
| 671 | err_clear_drvdata: | ||
| 672 | spi_set_drvdata(spi, NULL); | ||
| 673 | free_irq(spi->irq, ts); | ||
| 674 | err_free_mem: | ||
| 675 | input_free_device(input_dev); | ||
| 676 | kfree(ts); | ||
| 677 | return error; | ||
| 678 | } | ||
| 679 | |||
| 680 | static int __devexit tsc2005_remove(struct spi_device *spi) | ||
| 681 | { | ||
| 682 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 683 | |||
| 684 | sysfs_remove_group(&ts->spi->dev.kobj, &tsc2005_attr_group); | ||
| 685 | |||
| 686 | free_irq(ts->spi->irq, ts); | ||
| 687 | input_unregister_device(ts->idev); | ||
| 688 | kfree(ts); | ||
| 689 | |||
| 690 | spi_set_drvdata(spi, NULL); | ||
| 691 | return 0; | ||
| 692 | } | ||
| 693 | |||
| 694 | #ifdef CONFIG_PM_SLEEP | ||
| 695 | static int tsc2005_suspend(struct device *dev) | ||
| 696 | { | ||
| 697 | struct spi_device *spi = to_spi_device(dev); | ||
| 698 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 699 | |||
| 700 | mutex_lock(&ts->mutex); | ||
| 701 | |||
| 702 | if (!ts->suspended && ts->opened) | ||
| 703 | __tsc2005_disable(ts); | ||
| 704 | |||
| 705 | ts->suspended = true; | ||
| 706 | |||
| 707 | mutex_unlock(&ts->mutex); | ||
| 708 | |||
| 709 | return 0; | ||
| 710 | } | ||
| 711 | |||
| 712 | static int tsc2005_resume(struct device *dev) | ||
| 713 | { | ||
| 714 | struct spi_device *spi = to_spi_device(dev); | ||
| 715 | struct tsc2005 *ts = spi_get_drvdata(spi); | ||
| 716 | |||
| 717 | mutex_lock(&ts->mutex); | ||
| 718 | |||
| 719 | if (ts->suspended && ts->opened) | ||
| 720 | __tsc2005_enable(ts); | ||
| 721 | |||
| 722 | ts->suspended = false; | ||
| 723 | |||
| 724 | mutex_unlock(&ts->mutex); | ||
| 725 | |||
| 726 | return 0; | ||
| 727 | } | ||
| 728 | #endif | ||
| 729 | |||
| 730 | static SIMPLE_DEV_PM_OPS(tsc2005_pm_ops, tsc2005_suspend, tsc2005_resume); | ||
| 731 | |||
| 732 | static struct spi_driver tsc2005_driver = { | ||
| 733 | .driver = { | ||
| 734 | .name = "tsc2005", | ||
| 735 | .owner = THIS_MODULE, | ||
| 736 | .pm = &tsc2005_pm_ops, | ||
| 737 | }, | ||
| 738 | .probe = tsc2005_probe, | ||
| 739 | .remove = __devexit_p(tsc2005_remove), | ||
| 740 | }; | ||
| 741 | |||
| 742 | static int __init tsc2005_init(void) | ||
| 743 | { | ||
| 744 | return spi_register_driver(&tsc2005_driver); | ||
| 745 | } | ||
| 746 | module_init(tsc2005_init); | ||
| 747 | |||
| 748 | static void __exit tsc2005_exit(void) | ||
| 749 | { | ||
| 750 | spi_unregister_driver(&tsc2005_driver); | ||
| 751 | } | ||
| 752 | module_exit(tsc2005_exit); | ||
| 753 | |||
| 754 | MODULE_AUTHOR("Lauri Leukkunen <lauri.leukkunen@nokia.com>"); | ||
| 755 | MODULE_DESCRIPTION("TSC2005 Touchscreen Driver"); | ||
| 756 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/input/touchscreen/wm831x-ts.c b/drivers/input/touchscreen/wm831x-ts.c new file mode 100644 index 00000000000..6ae054f8e0a --- /dev/null +++ b/drivers/input/touchscreen/wm831x-ts.c | |||
| @@ -0,0 +1,368 @@ | |||
| 1 | /* | ||
| 2 | * Touchscreen driver for WM831x PMICs | ||
| 3 | * | ||
| 4 | * Copyright 2011 Wolfson Microelectronics plc. | ||
| 5 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify it | ||
| 8 | * under the terms of the GNU General Public License as published by the | ||
| 9 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 10 | * option) any later version. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <linux/module.h> | ||
| 14 | #include <linux/moduleparam.h> | ||
| 15 | #include <linux/kernel.h> | ||
| 16 | #include <linux/init.h> | ||
| 17 | #include <linux/string.h> | ||
| 18 | #include <linux/pm.h> | ||
| 19 | #include <linux/input.h> | ||
| 20 | #include <linux/interrupt.h> | ||
| 21 | #include <linux/io.h> | ||
| 22 | #include <linux/mfd/wm831x/core.h> | ||
| 23 | #include <linux/mfd/wm831x/irq.h> | ||
| 24 | #include <linux/mfd/wm831x/pdata.h> | ||
| 25 | #include <linux/platform_device.h> | ||
| 26 | #include <linux/slab.h> | ||
| 27 | #include <linux/types.h> | ||
| 28 | |||
| 29 | /* | ||
| 30 | * R16424 (0x4028) - Touch Control 1 | ||
| 31 | */ | ||
| 32 | #define WM831X_TCH_ENA 0x8000 /* TCH_ENA */ | ||
| 33 | #define WM831X_TCH_CVT_ENA 0x4000 /* TCH_CVT_ENA */ | ||
| 34 | #define WM831X_TCH_SLPENA 0x1000 /* TCH_SLPENA */ | ||
| 35 | #define WM831X_TCH_Z_ENA 0x0400 /* TCH_Z_ENA */ | ||
| 36 | #define WM831X_TCH_Y_ENA 0x0200 /* TCH_Y_ENA */ | ||
| 37 | #define WM831X_TCH_X_ENA 0x0100 /* TCH_X_ENA */ | ||
| 38 | #define WM831X_TCH_DELAY_MASK 0x00E0 /* TCH_DELAY - [7:5] */ | ||
| 39 | #define WM831X_TCH_DELAY_SHIFT 5 /* TCH_DELAY - [7:5] */ | ||
| 40 | #define WM831X_TCH_DELAY_WIDTH 3 /* TCH_DELAY - [7:5] */ | ||
| 41 | #define WM831X_TCH_RATE_MASK 0x001F /* TCH_RATE - [4:0] */ | ||
| 42 | #define WM831X_TCH_RATE_SHIFT 0 /* TCH_RATE - [4:0] */ | ||
| 43 | #define WM831X_TCH_RATE_WIDTH 5 /* TCH_RATE - [4:0] */ | ||
| 44 | |||
| 45 | /* | ||
| 46 | * R16425 (0x4029) - Touch Control 2 | ||
| 47 | */ | ||
| 48 | #define WM831X_TCH_PD_WK 0x2000 /* TCH_PD_WK */ | ||
| 49 | #define WM831X_TCH_5WIRE 0x1000 /* TCH_5WIRE */ | ||
| 50 | #define WM831X_TCH_PDONLY 0x0800 /* TCH_PDONLY */ | ||
| 51 | #define WM831X_TCH_ISEL 0x0100 /* TCH_ISEL */ | ||
| 52 | #define WM831X_TCH_RPU_MASK 0x000F /* TCH_RPU - [3:0] */ | ||
| 53 | #define WM831X_TCH_RPU_SHIFT 0 /* TCH_RPU - [3:0] */ | ||
| 54 | #define WM831X_TCH_RPU_WIDTH 4 /* TCH_RPU - [3:0] */ | ||
| 55 | |||
| 56 | /* | ||
| 57 | * R16426-8 (0x402A-C) - Touch Data X/Y/X | ||
| 58 | */ | ||
| 59 | #define WM831X_TCH_PD 0x8000 /* TCH_PD1 */ | ||
| 60 | #define WM831X_TCH_DATA_MASK 0x0FFF /* TCH_DATA - [11:0] */ | ||
| 61 | #define WM831X_TCH_DATA_SHIFT 0 /* TCH_DATA - [11:0] */ | ||
| 62 | #define WM831X_TCH_DATA_WIDTH 12 /* TCH_DATA - [11:0] */ | ||
| 63 | |||
| 64 | struct wm831x_ts { | ||
| 65 | struct input_dev *input_dev; | ||
| 66 | struct wm831x *wm831x; | ||
| 67 | unsigned int data_irq; | ||
| 68 | unsigned int pd_irq; | ||
| 69 | bool pressure; | ||
| 70 | bool pen_down; | ||
| 71 | }; | ||
| 72 | |||
| 73 | static irqreturn_t wm831x_ts_data_irq(int irq, void *irq_data) | ||
| 74 | { | ||
| 75 | struct wm831x_ts *wm831x_ts = irq_data; | ||
| 76 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 77 | static int data_types[] = { ABS_X, ABS_Y, ABS_PRESSURE }; | ||
| 78 | u16 data[3]; | ||
| 79 | int count; | ||
| 80 | int i, ret; | ||
| 81 | |||
| 82 | if (wm831x_ts->pressure) | ||
| 83 | count = 3; | ||
| 84 | else | ||
| 85 | count = 2; | ||
| 86 | |||
| 87 | wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1, | ||
| 88 | WM831X_TCHDATA_EINT, WM831X_TCHDATA_EINT); | ||
| 89 | |||
| 90 | ret = wm831x_bulk_read(wm831x, WM831X_TOUCH_DATA_X, count, | ||
| 91 | data); | ||
| 92 | if (ret != 0) { | ||
| 93 | dev_err(wm831x->dev, "Failed to read touch data: %d\n", | ||
| 94 | ret); | ||
| 95 | return IRQ_NONE; | ||
| 96 | } | ||
| 97 | |||
| 98 | /* | ||
| 99 | * We get a pen down reading on every reading, report pen up if any | ||
| 100 | * individual reading does so. | ||
| 101 | */ | ||
| 102 | wm831x_ts->pen_down = true; | ||
| 103 | for (i = 0; i < count; i++) { | ||
| 104 | if (!(data[i] & WM831X_TCH_PD)) { | ||
| 105 | wm831x_ts->pen_down = false; | ||
| 106 | continue; | ||
| 107 | } | ||
| 108 | input_report_abs(wm831x_ts->input_dev, data_types[i], | ||
| 109 | data[i] & WM831X_TCH_DATA_MASK); | ||
| 110 | } | ||
| 111 | |||
| 112 | if (!wm831x_ts->pen_down) { | ||
| 113 | disable_irq_nosync(wm831x_ts->data_irq); | ||
| 114 | |||
| 115 | /* Don't need data any more */ | ||
| 116 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 117 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | | ||
| 118 | WM831X_TCH_Z_ENA, 0); | ||
| 119 | |||
| 120 | /* Flush any final samples that arrived while reading */ | ||
| 121 | wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1, | ||
| 122 | WM831X_TCHDATA_EINT, WM831X_TCHDATA_EINT); | ||
| 123 | |||
| 124 | wm831x_bulk_read(wm831x, WM831X_TOUCH_DATA_X, count, data); | ||
| 125 | |||
| 126 | if (wm831x_ts->pressure) | ||
| 127 | input_report_abs(wm831x_ts->input_dev, | ||
| 128 | ABS_PRESSURE, 0); | ||
| 129 | |||
| 130 | input_report_key(wm831x_ts->input_dev, BTN_TOUCH, 0); | ||
| 131 | } | ||
| 132 | |||
| 133 | input_sync(wm831x_ts->input_dev); | ||
| 134 | |||
| 135 | return IRQ_HANDLED; | ||
| 136 | } | ||
| 137 | |||
| 138 | static irqreturn_t wm831x_ts_pen_down_irq(int irq, void *irq_data) | ||
| 139 | { | ||
| 140 | struct wm831x_ts *wm831x_ts = irq_data; | ||
| 141 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 142 | int ena = 0; | ||
| 143 | |||
| 144 | /* Start collecting data */ | ||
| 145 | if (wm831x_ts->pressure) | ||
| 146 | ena |= WM831X_TCH_Z_ENA; | ||
| 147 | |||
| 148 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 149 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | WM831X_TCH_Z_ENA, | ||
| 150 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | ena); | ||
| 151 | |||
| 152 | input_report_key(wm831x_ts->input_dev, BTN_TOUCH, 1); | ||
| 153 | input_sync(wm831x_ts->input_dev); | ||
| 154 | |||
| 155 | wm831x_set_bits(wm831x, WM831X_INTERRUPT_STATUS_1, | ||
| 156 | WM831X_TCHPD_EINT, WM831X_TCHPD_EINT); | ||
| 157 | |||
| 158 | wm831x_ts->pen_down = true; | ||
| 159 | enable_irq(wm831x_ts->data_irq); | ||
| 160 | |||
| 161 | return IRQ_HANDLED; | ||
| 162 | } | ||
| 163 | |||
| 164 | static int wm831x_ts_input_open(struct input_dev *idev) | ||
| 165 | { | ||
| 166 | struct wm831x_ts *wm831x_ts = input_get_drvdata(idev); | ||
| 167 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 168 | |||
| 169 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 170 | WM831X_TCH_ENA | WM831X_TCH_CVT_ENA | | ||
| 171 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | | ||
| 172 | WM831X_TCH_Z_ENA, WM831X_TCH_ENA); | ||
| 173 | |||
| 174 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 175 | WM831X_TCH_CVT_ENA, WM831X_TCH_CVT_ENA); | ||
| 176 | |||
| 177 | return 0; | ||
| 178 | } | ||
| 179 | |||
| 180 | static void wm831x_ts_input_close(struct input_dev *idev) | ||
| 181 | { | ||
| 182 | struct wm831x_ts *wm831x_ts = input_get_drvdata(idev); | ||
| 183 | struct wm831x *wm831x = wm831x_ts->wm831x; | ||
| 184 | |||
| 185 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 186 | WM831X_TCH_ENA | WM831X_TCH_CVT_ENA | | ||
| 187 | WM831X_TCH_X_ENA | WM831X_TCH_Y_ENA | | ||
| 188 | WM831X_TCH_Z_ENA, 0); | ||
| 189 | |||
| 190 | if (wm831x_ts->pen_down) | ||
| 191 | disable_irq(wm831x_ts->data_irq); | ||
| 192 | } | ||
| 193 | |||
| 194 | static __devinit int wm831x_ts_probe(struct platform_device *pdev) | ||
| 195 | { | ||
| 196 | struct wm831x_ts *wm831x_ts; | ||
| 197 | struct wm831x *wm831x = dev_get_drvdata(pdev->dev.parent); | ||
| 198 | struct wm831x_pdata *core_pdata = dev_get_platdata(pdev->dev.parent); | ||
| 199 | struct wm831x_touch_pdata *pdata = NULL; | ||
| 200 | struct input_dev *input_dev; | ||
| 201 | int error; | ||
| 202 | |||
| 203 | if (core_pdata) | ||
| 204 | pdata = core_pdata->touch; | ||
| 205 | |||
| 206 | wm831x_ts = kzalloc(sizeof(struct wm831x_ts), GFP_KERNEL); | ||
| 207 | input_dev = input_allocate_device(); | ||
| 208 | if (!wm831x_ts || !input_dev) { | ||
| 209 | error = -ENOMEM; | ||
| 210 | goto err_alloc; | ||
| 211 | } | ||
| 212 | |||
| 213 | wm831x_ts->wm831x = wm831x; | ||
| 214 | wm831x_ts->input_dev = input_dev; | ||
| 215 | |||
| 216 | /* | ||
| 217 | * If we have a direct IRQ use it, otherwise use the interrupt | ||
| 218 | * from the WM831x IRQ controller. | ||
| 219 | */ | ||
| 220 | if (pdata && pdata->data_irq) | ||
| 221 | wm831x_ts->data_irq = pdata->data_irq; | ||
| 222 | else | ||
| 223 | wm831x_ts->data_irq = platform_get_irq_byname(pdev, "TCHDATA"); | ||
| 224 | |||
| 225 | if (pdata && pdata->pd_irq) | ||
| 226 | wm831x_ts->pd_irq = pdata->pd_irq; | ||
| 227 | else | ||
| 228 | wm831x_ts->pd_irq = platform_get_irq_byname(pdev, "TCHPD"); | ||
| 229 | |||
| 230 | if (pdata) | ||
| 231 | wm831x_ts->pressure = pdata->pressure; | ||
| 232 | else | ||
| 233 | wm831x_ts->pressure = true; | ||
| 234 | |||
| 235 | /* Five wire touchscreens can't report pressure */ | ||
| 236 | if (pdata && pdata->fivewire) { | ||
| 237 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 238 | WM831X_TCH_5WIRE, WM831X_TCH_5WIRE); | ||
| 239 | |||
| 240 | /* Pressure measurements are not possible for five wire mode */ | ||
| 241 | WARN_ON(pdata->pressure && pdata->fivewire); | ||
| 242 | wm831x_ts->pressure = false; | ||
| 243 | } else { | ||
| 244 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 245 | WM831X_TCH_5WIRE, 0); | ||
| 246 | } | ||
| 247 | |||
| 248 | if (pdata) { | ||
| 249 | switch (pdata->isel) { | ||
| 250 | default: | ||
| 251 | dev_err(&pdev->dev, "Unsupported ISEL setting: %d\n", | ||
| 252 | pdata->isel); | ||
| 253 | /* Fall through */ | ||
| 254 | case 200: | ||
| 255 | case 0: | ||
| 256 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 257 | WM831X_TCH_ISEL, 0); | ||
| 258 | break; | ||
| 259 | case 400: | ||
| 260 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 261 | WM831X_TCH_ISEL, WM831X_TCH_ISEL); | ||
| 262 | break; | ||
| 263 | } | ||
| 264 | } | ||
| 265 | |||
| 266 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_2, | ||
| 267 | WM831X_TCH_PDONLY, 0); | ||
| 268 | |||
| 269 | /* Default to 96 samples/sec */ | ||
| 270 | wm831x_set_bits(wm831x, WM831X_TOUCH_CONTROL_1, | ||
| 271 | WM831X_TCH_RATE_MASK, 6); | ||
| 272 | |||
| 273 | error = request_threaded_irq(wm831x_ts->data_irq, | ||
| 274 | NULL, wm831x_ts_data_irq, | ||
| 275 | IRQF_ONESHOT, | ||
| 276 | "Touchscreen data", wm831x_ts); | ||
| 277 | if (error) { | ||
| 278 | dev_err(&pdev->dev, "Failed to request data IRQ %d: %d\n", | ||
| 279 | wm831x_ts->data_irq, error); | ||
| 280 | goto err_alloc; | ||
| 281 | } | ||
| 282 | disable_irq(wm831x_ts->data_irq); | ||
| 283 | |||
| 284 | error = request_threaded_irq(wm831x_ts->pd_irq, | ||
| 285 | NULL, wm831x_ts_pen_down_irq, | ||
| 286 | IRQF_ONESHOT, | ||
| 287 | "Touchscreen pen down", wm831x_ts); | ||
| 288 | if (error) { | ||
| 289 | dev_err(&pdev->dev, "Failed to request pen down IRQ %d: %d\n", | ||
| 290 | wm831x_ts->pd_irq, error); | ||
| 291 | goto err_data_irq; | ||
| 292 | } | ||
| 293 | |||
| 294 | /* set up touch configuration */ | ||
| 295 | input_dev->name = "WM831x touchscreen"; | ||
| 296 | input_dev->phys = "wm831x"; | ||
| 297 | input_dev->open = wm831x_ts_input_open; | ||
| 298 | input_dev->close = wm831x_ts_input_close; | ||
| 299 | |||
| 300 | __set_bit(EV_ABS, input_dev->evbit); | ||
| 301 | __set_bit(EV_KEY, input_dev->evbit); | ||
| 302 | __set_bit(BTN_TOUCH, input_dev->keybit); | ||
| 303 | |||
| 304 | input_set_abs_params(input_dev, ABS_X, 0, 4095, 5, 0); | ||
| 305 | input_set_abs_params(input_dev, ABS_Y, 0, 4095, 5, 0); | ||
| 306 | if (wm831x_ts->pressure) | ||
| 307 | input_set_abs_params(input_dev, ABS_PRESSURE, 0, 4095, 5, 0); | ||
| 308 | |||
| 309 | input_set_drvdata(input_dev, wm831x_ts); | ||
| 310 | input_dev->dev.parent = &pdev->dev; | ||
| 311 | |||
| 312 | error = input_register_device(input_dev); | ||
| 313 | if (error) | ||
| 314 | goto err_pd_irq; | ||
| 315 | |||
| 316 | platform_set_drvdata(pdev, wm831x_ts); | ||
| 317 | return 0; | ||
| 318 | |||
| 319 | err_pd_irq: | ||
| 320 | free_irq(wm831x_ts->pd_irq, wm831x_ts); | ||
| 321 | err_data_irq: | ||
| 322 | free_irq(wm831x_ts->data_irq, wm831x_ts); | ||
| 323 | err_alloc: | ||
| 324 | input_free_device(input_dev); | ||
| 325 | kfree(wm831x_ts); | ||
| 326 | |||
| 327 | return error; | ||
| 328 | } | ||
| 329 | |||
| 330 | static __devexit int wm831x_ts_remove(struct platform_device *pdev) | ||
| 331 | { | ||
| 332 | struct wm831x_ts *wm831x_ts = platform_get_drvdata(pdev); | ||
| 333 | |||
| 334 | free_irq(wm831x_ts->pd_irq, wm831x_ts); | ||
| 335 | free_irq(wm831x_ts->data_irq, wm831x_ts); | ||
| 336 | input_unregister_device(wm831x_ts->input_dev); | ||
| 337 | kfree(wm831x_ts); | ||
| 338 | |||
| 339 | platform_set_drvdata(pdev, NULL); | ||
| 340 | return 0; | ||
| 341 | } | ||
| 342 | |||
| 343 | static struct platform_driver wm831x_ts_driver = { | ||
| 344 | .driver = { | ||
| 345 | .name = "wm831x-touch", | ||
| 346 | .owner = THIS_MODULE, | ||
| 347 | }, | ||
| 348 | .probe = wm831x_ts_probe, | ||
| 349 | .remove = __devexit_p(wm831x_ts_remove), | ||
| 350 | }; | ||
| 351 | |||
| 352 | static int __init wm831x_ts_init(void) | ||
| 353 | { | ||
| 354 | return platform_driver_register(&wm831x_ts_driver); | ||
| 355 | } | ||
| 356 | module_init(wm831x_ts_init); | ||
| 357 | |||
| 358 | static void __exit wm831x_ts_exit(void) | ||
| 359 | { | ||
| 360 | platform_driver_unregister(&wm831x_ts_driver); | ||
| 361 | } | ||
| 362 | module_exit(wm831x_ts_exit); | ||
| 363 | |||
| 364 | /* Module information */ | ||
| 365 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
| 366 | MODULE_DESCRIPTION("WM831x PMIC touchscreen driver"); | ||
| 367 | MODULE_LICENSE("GPL"); | ||
| 368 | MODULE_ALIAS("platform:wm831x-touch"); | ||
