Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 1 | /* |
| 2 | * drivers/input/touchscreen/jornada720_ts.c |
| 3 | * |
| 4 | * Copyright (C) 2007 Kristoffer Ericson <Kristoffer.Ericson@gmail.com> |
| 5 | * |
| 6 | * Copyright (C) 2006 Filip Zyzniewski <filip.zyzniewski@tefnet.pl> |
| 7 | * based on HP Jornada 56x touchscreen driver by Alex Lange <chicken@handhelds.org> |
| 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 version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * HP Jornada 710/720/729 Touchscreen Driver |
| 14 | */ |
| 15 | |
| 16 | #include <linux/platform_device.h> |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 17 | #include <linux/input.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 20 | #include <linux/slab.h> |
Russell King | 3169663 | 2012-06-06 11:42:36 +0100 | [diff] [blame] | 21 | #include <linux/io.h> |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 22 | |
Russell King | a09e64f | 2008-08-05 16:14:15 +0100 | [diff] [blame] | 23 | #include <mach/hardware.h> |
| 24 | #include <mach/jornada720.h> |
Rob Herring | 3638dd2 | 2012-02-23 14:28:36 +0100 | [diff] [blame] | 25 | #include <mach/irqs.h> |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 26 | |
| 27 | MODULE_AUTHOR("Kristoffer Ericson <kristoffer.ericson@gmail.com>"); |
| 28 | MODULE_DESCRIPTION("HP Jornada 710/720/728 touchscreen driver"); |
Al Viro | 839cd31 | 2008-05-21 06:32:11 +0100 | [diff] [blame] | 29 | MODULE_LICENSE("GPL v2"); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 30 | |
| 31 | struct jornada_ts { |
| 32 | struct input_dev *dev; |
| 33 | int x_data[4]; /* X sample values */ |
| 34 | int y_data[4]; /* Y sample values */ |
| 35 | }; |
| 36 | |
| 37 | static void jornada720_ts_collect_data(struct jornada_ts *jornada_ts) |
| 38 | { |
Pramod Gurav | fe96244 | 2014-07-30 22:14:46 -0700 | [diff] [blame^] | 39 | /* 3 low word X samples */ |
| 40 | jornada_ts->x_data[0] = jornada_ssp_byte(TXDUMMY); |
| 41 | jornada_ts->x_data[1] = jornada_ssp_byte(TXDUMMY); |
| 42 | jornada_ts->x_data[2] = jornada_ssp_byte(TXDUMMY); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 43 | |
Pramod Gurav | fe96244 | 2014-07-30 22:14:46 -0700 | [diff] [blame^] | 44 | /* 3 low word Y samples */ |
| 45 | jornada_ts->y_data[0] = jornada_ssp_byte(TXDUMMY); |
| 46 | jornada_ts->y_data[1] = jornada_ssp_byte(TXDUMMY); |
| 47 | jornada_ts->y_data[2] = jornada_ssp_byte(TXDUMMY); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 48 | |
Pramod Gurav | fe96244 | 2014-07-30 22:14:46 -0700 | [diff] [blame^] | 49 | /* combined x samples bits */ |
| 50 | jornada_ts->x_data[3] = jornada_ssp_byte(TXDUMMY); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 51 | |
Pramod Gurav | fe96244 | 2014-07-30 22:14:46 -0700 | [diff] [blame^] | 52 | /* combined y samples bits */ |
| 53 | jornada_ts->y_data[3] = jornada_ssp_byte(TXDUMMY); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static int jornada720_ts_average(int coords[4]) |
| 57 | { |
| 58 | int coord, high_bits = coords[3]; |
| 59 | |
| 60 | coord = coords[0] | ((high_bits & 0x03) << 8); |
| 61 | coord += coords[1] | ((high_bits & 0x0c) << 6); |
| 62 | coord += coords[2] | ((high_bits & 0x30) << 4); |
| 63 | |
| 64 | return coord / 3; |
| 65 | } |
| 66 | |
| 67 | static irqreturn_t jornada720_ts_interrupt(int irq, void *dev_id) |
| 68 | { |
| 69 | struct platform_device *pdev = dev_id; |
| 70 | struct jornada_ts *jornada_ts = platform_get_drvdata(pdev); |
| 71 | struct input_dev *input = jornada_ts->dev; |
| 72 | int x, y; |
| 73 | |
| 74 | /* If GPIO_GPIO9 is set to high then report pen up */ |
| 75 | if (GPLR & GPIO_GPIO(9)) { |
| 76 | input_report_key(input, BTN_TOUCH, 0); |
| 77 | input_sync(input); |
| 78 | } else { |
| 79 | jornada_ssp_start(); |
| 80 | |
| 81 | /* proper reply to request is always TXDUMMY */ |
| 82 | if (jornada_ssp_inout(GETTOUCHSAMPLES) == TXDUMMY) { |
| 83 | jornada720_ts_collect_data(jornada_ts); |
| 84 | |
| 85 | x = jornada720_ts_average(jornada_ts->x_data); |
| 86 | y = jornada720_ts_average(jornada_ts->y_data); |
| 87 | |
| 88 | input_report_key(input, BTN_TOUCH, 1); |
| 89 | input_report_abs(input, ABS_X, x); |
| 90 | input_report_abs(input, ABS_Y, y); |
| 91 | input_sync(input); |
| 92 | } |
| 93 | |
| 94 | jornada_ssp_end(); |
| 95 | } |
| 96 | |
| 97 | return IRQ_HANDLED; |
| 98 | } |
| 99 | |
Bill Pemberton | 5298cc4 | 2012-11-23 21:38:25 -0800 | [diff] [blame] | 100 | static int jornada720_ts_probe(struct platform_device *pdev) |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 101 | { |
| 102 | struct jornada_ts *jornada_ts; |
| 103 | struct input_dev *input_dev; |
| 104 | int error; |
| 105 | |
Pramod Gurav | 4b080e3 | 2014-07-30 22:13:58 -0700 | [diff] [blame] | 106 | jornada_ts = devm_kzalloc(&pdev->dev, sizeof(*jornada_ts), GFP_KERNEL); |
| 107 | if (!jornada_ts) |
| 108 | return -ENOMEM; |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 109 | |
Pramod Gurav | 4b080e3 | 2014-07-30 22:13:58 -0700 | [diff] [blame] | 110 | input_dev = devm_input_allocate_device(&pdev->dev); |
| 111 | if (!input_dev) |
| 112 | return -ENOMEM; |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 113 | |
| 114 | platform_set_drvdata(pdev, jornada_ts); |
| 115 | |
| 116 | jornada_ts->dev = input_dev; |
| 117 | |
| 118 | input_dev->name = "HP Jornada 7xx Touchscreen"; |
| 119 | input_dev->phys = "jornadats/input0"; |
| 120 | input_dev->id.bustype = BUS_HOST; |
| 121 | input_dev->dev.parent = &pdev->dev; |
| 122 | |
Kristoffer Ericson | 1577e4b | 2008-09-16 14:19:25 -0400 | [diff] [blame] | 123 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); |
| 124 | input_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 125 | input_set_abs_params(input_dev, ABS_X, 270, 3900, 0, 0); |
| 126 | input_set_abs_params(input_dev, ABS_Y, 180, 3700, 0, 0); |
| 127 | |
Pramod Gurav | 4b080e3 | 2014-07-30 22:13:58 -0700 | [diff] [blame] | 128 | error = devm_request_irq(&pdev->dev, IRQ_GPIO9, |
| 129 | jornada720_ts_interrupt, |
| 130 | IRQF_TRIGGER_RISING, |
| 131 | "HP7XX Touchscreen driver", pdev); |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 132 | if (error) { |
Pramod Gurav | 4b080e3 | 2014-07-30 22:13:58 -0700 | [diff] [blame] | 133 | dev_err(&pdev->dev, "HP7XX TS : Unable to acquire irq!\n"); |
| 134 | return error; |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | error = input_register_device(jornada_ts->dev); |
| 138 | if (error) |
Pramod Gurav | 4b080e3 | 2014-07-30 22:13:58 -0700 | [diff] [blame] | 139 | return error; |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 140 | |
| 141 | return 0; |
| 142 | } |
| 143 | |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 144 | /* work with hotplug and coldplug */ |
| 145 | MODULE_ALIAS("platform:jornada_ts"); |
| 146 | |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 147 | static struct platform_driver jornada720_ts_driver = { |
| 148 | .probe = jornada720_ts_probe, |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 149 | .driver = { |
| 150 | .name = "jornada_ts", |
Kay Sievers | d7b5247 | 2008-04-18 00:24:42 -0400 | [diff] [blame] | 151 | .owner = THIS_MODULE, |
Kristoffer Ericson | 5637f02 | 2007-09-26 00:02:56 -0400 | [diff] [blame] | 152 | }, |
| 153 | }; |
JJ Ding | cdcc96e | 2011-11-29 11:14:13 -0800 | [diff] [blame] | 154 | module_platform_driver(jornada720_ts_driver); |