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