Linux Audio

Check our new training course

Loading...
v6.13.7
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * HTC Shift touchscreen driver
  4 *
  5 * Copyright (C) 2008 Pau Oliva Fora <pof@eslack.org>
 
 
 
 
  6 */
  7
  8#include <linux/errno.h>
  9#include <linux/kernel.h>
 10#include <linux/module.h>
 11#include <linux/input.h>
 12#include <linux/interrupt.h>
 13#include <linux/io.h>
 14#include <linux/init.h>
 15#include <linux/irq.h>
 16#include <linux/isa.h>
 17#include <linux/ioport.h>
 18#include <linux/dmi.h>
 19
 20MODULE_AUTHOR("Pau Oliva Fora <pau@eslack.org>");
 21MODULE_DESCRIPTION("HTC Shift touchscreen driver");
 22MODULE_LICENSE("GPL");
 23
 24#define HTCPEN_PORT_IRQ_CLEAR	0x068
 25#define HTCPEN_PORT_INIT	0x06c
 26#define HTCPEN_PORT_INDEX	0x0250
 27#define HTCPEN_PORT_DATA	0x0251
 28#define HTCPEN_IRQ		3
 29
 30#define DEVICE_ENABLE		0xa2
 31#define DEVICE_DISABLE		0xa3
 32
 33#define X_INDEX			3
 34#define Y_INDEX			5
 35#define TOUCH_INDEX		0xb
 36#define LSB_XY_INDEX		0xc
 37#define X_AXIS_MAX		2040
 38#define Y_AXIS_MAX		2040
 39
 40static bool invert_x;
 41module_param(invert_x, bool, 0644);
 42MODULE_PARM_DESC(invert_x, "If set, X axis is inverted");
 43static bool invert_y;
 44module_param(invert_y, bool, 0644);
 45MODULE_PARM_DESC(invert_y, "If set, Y axis is inverted");
 46
 
 
 
 
 
 
 47static irqreturn_t htcpen_interrupt(int irq, void *handle)
 48{
 49	struct input_dev *htcpen_dev = handle;
 50	unsigned short x, y, xy;
 51
 52	/* 0 = press; 1 = release */
 53	outb_p(TOUCH_INDEX, HTCPEN_PORT_INDEX);
 54
 55	if (inb_p(HTCPEN_PORT_DATA)) {
 56		input_report_key(htcpen_dev, BTN_TOUCH, 0);
 57	} else {
 58		outb_p(X_INDEX, HTCPEN_PORT_INDEX);
 59		x = inb_p(HTCPEN_PORT_DATA);
 60
 61		outb_p(Y_INDEX, HTCPEN_PORT_INDEX);
 62		y = inb_p(HTCPEN_PORT_DATA);
 63
 64		outb_p(LSB_XY_INDEX, HTCPEN_PORT_INDEX);
 65		xy = inb_p(HTCPEN_PORT_DATA);
 66
 67		/* get high resolution value of X and Y using LSB */
 68		x = X_AXIS_MAX - ((x * 8) + ((xy >> 4) & 0xf));
 69		y = (y * 8) + (xy & 0xf);
 70		if (invert_x)
 71			x = X_AXIS_MAX - x;
 72		if (invert_y)
 73			y = Y_AXIS_MAX - y;
 74
 75		if (x != X_AXIS_MAX && x != 0) {
 76			input_report_key(htcpen_dev, BTN_TOUCH, 1);
 77			input_report_abs(htcpen_dev, ABS_X, x);
 78			input_report_abs(htcpen_dev, ABS_Y, y);
 79		}
 80	}
 81
 82	input_sync(htcpen_dev);
 83
 84	inb_p(HTCPEN_PORT_IRQ_CLEAR);
 85
 86	return IRQ_HANDLED;
 87}
 88
 89static int htcpen_open(struct input_dev *dev)
 90{
 91	outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT);
 92
 93	return 0;
 94}
 95
 96static void htcpen_close(struct input_dev *dev)
 97{
 98	outb_p(DEVICE_DISABLE, HTCPEN_PORT_INIT);
 99	synchronize_irq(HTCPEN_IRQ);
100}
101
102static int htcpen_isa_probe(struct device *dev, unsigned int id)
103{
104	struct input_dev *htcpen_dev;
105	int err = -EBUSY;
106
107	if (!request_region(HTCPEN_PORT_IRQ_CLEAR, 1, "htcpen")) {
108		printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
109			HTCPEN_PORT_IRQ_CLEAR);
110		goto request_region1_failed;
111	}
112
113	if (!request_region(HTCPEN_PORT_INIT, 1, "htcpen")) {
114		printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
115			HTCPEN_PORT_INIT);
116		goto request_region2_failed;
117	}
118
119	if (!request_region(HTCPEN_PORT_INDEX, 2, "htcpen")) {
120		printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
121			HTCPEN_PORT_INDEX);
122		goto request_region3_failed;
123	}
124
125	htcpen_dev = input_allocate_device();
126	if (!htcpen_dev) {
127		printk(KERN_ERR "htcpen: can't allocate device\n");
128		err = -ENOMEM;
129		goto input_alloc_failed;
130	}
131
132	htcpen_dev->name = "HTC Shift EC TouchScreen";
133	htcpen_dev->id.bustype = BUS_ISA;
134
135	htcpen_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
136	htcpen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
137	input_set_abs_params(htcpen_dev, ABS_X, 0, X_AXIS_MAX, 0, 0);
138	input_set_abs_params(htcpen_dev, ABS_Y, 0, Y_AXIS_MAX, 0, 0);
139
140	htcpen_dev->open = htcpen_open;
141	htcpen_dev->close = htcpen_close;
142
143	err = request_irq(HTCPEN_IRQ, htcpen_interrupt, 0, "htcpen",
144			htcpen_dev);
145	if (err) {
146		printk(KERN_ERR "htcpen: irq busy\n");
147		goto request_irq_failed;
148	}
149
150	inb_p(HTCPEN_PORT_IRQ_CLEAR);
151
152	err = input_register_device(htcpen_dev);
153	if (err)
154		goto input_register_failed;
155
156	dev_set_drvdata(dev, htcpen_dev);
157
158	return 0;
159
160 input_register_failed:
161	free_irq(HTCPEN_IRQ, htcpen_dev);
162 request_irq_failed:
163	input_free_device(htcpen_dev);
164 input_alloc_failed:
165	release_region(HTCPEN_PORT_INDEX, 2);
166 request_region3_failed:
167	release_region(HTCPEN_PORT_INIT, 1);
168 request_region2_failed:
169	release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
170 request_region1_failed:
171	return err;
172}
173
174static void htcpen_isa_remove(struct device *dev, unsigned int id)
175{
176	struct input_dev *htcpen_dev = dev_get_drvdata(dev);
177
178	input_unregister_device(htcpen_dev);
179
180	free_irq(HTCPEN_IRQ, htcpen_dev);
181
182	release_region(HTCPEN_PORT_INDEX, 2);
183	release_region(HTCPEN_PORT_INIT, 1);
184	release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
 
 
 
 
185}
186
187#ifdef CONFIG_PM
188static int htcpen_isa_suspend(struct device *dev, unsigned int n,
189				pm_message_t state)
190{
191	outb_p(DEVICE_DISABLE, HTCPEN_PORT_INIT);
192
193	return 0;
194}
195
196static int htcpen_isa_resume(struct device *dev, unsigned int n)
197{
198	outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT);
199
200	return 0;
201}
202#endif
203
204static struct isa_driver htcpen_isa_driver = {
205	.probe		= htcpen_isa_probe,
206	.remove		= htcpen_isa_remove,
207#ifdef CONFIG_PM
208	.suspend	= htcpen_isa_suspend,
209	.resume		= htcpen_isa_resume,
210#endif
211	.driver = {
212		.owner	= THIS_MODULE,
213		.name	= "htcpen",
214	}
215};
216
217static const struct dmi_system_id htcshift_dmi_table[] __initconst = {
218	{
219		.ident = "Shift",
220		.matches = {
221			DMI_MATCH(DMI_SYS_VENDOR, "High Tech Computer Corp"),
222			DMI_MATCH(DMI_PRODUCT_NAME, "Shift"),
223		},
224	},
225	{ }
226};
227MODULE_DEVICE_TABLE(dmi, htcshift_dmi_table);
228
229static int __init htcpen_isa_init(void)
230{
231	if (!dmi_check_system(htcshift_dmi_table))
232		return -ENODEV;
233
234	return isa_register_driver(&htcpen_isa_driver, 1);
235}
236
237static void __exit htcpen_isa_exit(void)
238{
239	isa_unregister_driver(&htcpen_isa_driver);
240}
241
242module_init(htcpen_isa_init);
243module_exit(htcpen_isa_exit);
v3.1
 
  1/*
  2 * HTC Shift touchscreen driver
  3 *
  4 * Copyright (C) 2008 Pau Oliva Fora <pof@eslack.org>
  5 *
  6 * This program is free software; you can redistribute it and/or modify it
  7 * under the terms of the GNU General Public License version 2 as published
  8 * by the Free Software Foundation.
  9 */
 10
 11#include <linux/errno.h>
 12#include <linux/kernel.h>
 13#include <linux/module.h>
 14#include <linux/input.h>
 15#include <linux/interrupt.h>
 16#include <linux/io.h>
 17#include <linux/init.h>
 18#include <linux/irq.h>
 19#include <linux/isa.h>
 20#include <linux/ioport.h>
 21#include <linux/dmi.h>
 22
 23MODULE_AUTHOR("Pau Oliva Fora <pau@eslack.org>");
 24MODULE_DESCRIPTION("HTC Shift touchscreen driver");
 25MODULE_LICENSE("GPL");
 26
 27#define HTCPEN_PORT_IRQ_CLEAR	0x068
 28#define HTCPEN_PORT_INIT	0x06c
 29#define HTCPEN_PORT_INDEX	0x0250
 30#define HTCPEN_PORT_DATA	0x0251
 31#define HTCPEN_IRQ		3
 32
 33#define DEVICE_ENABLE		0xa2
 34#define DEVICE_DISABLE		0xa3
 35
 36#define X_INDEX			3
 37#define Y_INDEX			5
 38#define TOUCH_INDEX		0xb
 39#define LSB_XY_INDEX		0xc
 40#define X_AXIS_MAX		2040
 41#define Y_AXIS_MAX		2040
 42
 43static int invert_x;
 44module_param(invert_x, bool, 0644);
 45MODULE_PARM_DESC(invert_x, "If set, X axis is inverted");
 46static int invert_y;
 47module_param(invert_y, bool, 0644);
 48MODULE_PARM_DESC(invert_y, "If set, Y axis is inverted");
 49
 50static struct pnp_device_id pnp_ids[] = {
 51	{ .id = "PNP0cc0" },
 52	{ .id = "" }
 53};
 54MODULE_DEVICE_TABLE(pnp, pnp_ids);
 55
 56static irqreturn_t htcpen_interrupt(int irq, void *handle)
 57{
 58	struct input_dev *htcpen_dev = handle;
 59	unsigned short x, y, xy;
 60
 61	/* 0 = press; 1 = release */
 62	outb_p(TOUCH_INDEX, HTCPEN_PORT_INDEX);
 63
 64	if (inb_p(HTCPEN_PORT_DATA)) {
 65		input_report_key(htcpen_dev, BTN_TOUCH, 0);
 66	} else {
 67		outb_p(X_INDEX, HTCPEN_PORT_INDEX);
 68		x = inb_p(HTCPEN_PORT_DATA);
 69
 70		outb_p(Y_INDEX, HTCPEN_PORT_INDEX);
 71		y = inb_p(HTCPEN_PORT_DATA);
 72
 73		outb_p(LSB_XY_INDEX, HTCPEN_PORT_INDEX);
 74		xy = inb_p(HTCPEN_PORT_DATA);
 75
 76		/* get high resolution value of X and Y using LSB */
 77		x = X_AXIS_MAX - ((x * 8) + ((xy >> 4) & 0xf));
 78		y = (y * 8) + (xy & 0xf);
 79		if (invert_x)
 80			x = X_AXIS_MAX - x;
 81		if (invert_y)
 82			y = Y_AXIS_MAX - y;
 83
 84		if (x != X_AXIS_MAX && x != 0) {
 85			input_report_key(htcpen_dev, BTN_TOUCH, 1);
 86			input_report_abs(htcpen_dev, ABS_X, x);
 87			input_report_abs(htcpen_dev, ABS_Y, y);
 88		}
 89	}
 90
 91	input_sync(htcpen_dev);
 92
 93	inb_p(HTCPEN_PORT_IRQ_CLEAR);
 94
 95	return IRQ_HANDLED;
 96}
 97
 98static int htcpen_open(struct input_dev *dev)
 99{
100	outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT);
101
102	return 0;
103}
104
105static void htcpen_close(struct input_dev *dev)
106{
107	outb_p(DEVICE_DISABLE, HTCPEN_PORT_INIT);
108	synchronize_irq(HTCPEN_IRQ);
109}
110
111static int __devinit htcpen_isa_probe(struct device *dev, unsigned int id)
112{
113	struct input_dev *htcpen_dev;
114	int err = -EBUSY;
115
116	if (!request_region(HTCPEN_PORT_IRQ_CLEAR, 1, "htcpen")) {
117		printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
118			HTCPEN_PORT_IRQ_CLEAR);
119		goto request_region1_failed;
120	}
121
122	if (!request_region(HTCPEN_PORT_INIT, 1, "htcpen")) {
123		printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
124			HTCPEN_PORT_INIT);
125		goto request_region2_failed;
126	}
127
128	if (!request_region(HTCPEN_PORT_INDEX, 2, "htcpen")) {
129		printk(KERN_ERR "htcpen: unable to get IO region 0x%x\n",
130			HTCPEN_PORT_INDEX);
131		goto request_region3_failed;
132	}
133
134	htcpen_dev = input_allocate_device();
135	if (!htcpen_dev) {
136		printk(KERN_ERR "htcpen: can't allocate device\n");
137		err = -ENOMEM;
138		goto input_alloc_failed;
139	}
140
141	htcpen_dev->name = "HTC Shift EC TouchScreen";
142	htcpen_dev->id.bustype = BUS_ISA;
143
144	htcpen_dev->evbit[0] = BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY);
145	htcpen_dev->keybit[BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH);
146	input_set_abs_params(htcpen_dev, ABS_X, 0, X_AXIS_MAX, 0, 0);
147	input_set_abs_params(htcpen_dev, ABS_Y, 0, Y_AXIS_MAX, 0, 0);
148
149	htcpen_dev->open = htcpen_open;
150	htcpen_dev->close = htcpen_close;
151
152	err = request_irq(HTCPEN_IRQ, htcpen_interrupt, 0, "htcpen",
153			htcpen_dev);
154	if (err) {
155		printk(KERN_ERR "htcpen: irq busy\n");
156		goto request_irq_failed;
157	}
158
159	inb_p(HTCPEN_PORT_IRQ_CLEAR);
160
161	err = input_register_device(htcpen_dev);
162	if (err)
163		goto input_register_failed;
164
165	dev_set_drvdata(dev, htcpen_dev);
166
167	return 0;
168
169 input_register_failed:
170	free_irq(HTCPEN_IRQ, htcpen_dev);
171 request_irq_failed:
172	input_free_device(htcpen_dev);
173 input_alloc_failed:
174	release_region(HTCPEN_PORT_INDEX, 2);
175 request_region3_failed:
176	release_region(HTCPEN_PORT_INIT, 1);
177 request_region2_failed:
178	release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
179 request_region1_failed:
180	return err;
181}
182
183static int __devexit htcpen_isa_remove(struct device *dev, unsigned int id)
184{
185	struct input_dev *htcpen_dev = dev_get_drvdata(dev);
186
187	input_unregister_device(htcpen_dev);
188
189	free_irq(HTCPEN_IRQ, htcpen_dev);
190
191	release_region(HTCPEN_PORT_INDEX, 2);
192	release_region(HTCPEN_PORT_INIT, 1);
193	release_region(HTCPEN_PORT_IRQ_CLEAR, 1);
194
195	dev_set_drvdata(dev, NULL);
196
197	return 0;
198}
199
200#ifdef CONFIG_PM
201static int htcpen_isa_suspend(struct device *dev, unsigned int n,
202				pm_message_t state)
203{
204	outb_p(DEVICE_DISABLE, HTCPEN_PORT_INIT);
205
206	return 0;
207}
208
209static int htcpen_isa_resume(struct device *dev, unsigned int n)
210{
211	outb_p(DEVICE_ENABLE, HTCPEN_PORT_INIT);
212
213	return 0;
214}
215#endif
216
217static struct isa_driver htcpen_isa_driver = {
218	.probe		= htcpen_isa_probe,
219	.remove		= __devexit_p(htcpen_isa_remove),
220#ifdef CONFIG_PM
221	.suspend	= htcpen_isa_suspend,
222	.resume		= htcpen_isa_resume,
223#endif
224	.driver = {
225		.owner	= THIS_MODULE,
226		.name	= "htcpen",
227	}
228};
229
230static struct dmi_system_id __initdata htcshift_dmi_table[] = {
231	{
232		.ident = "Shift",
233		.matches = {
234			DMI_MATCH(DMI_SYS_VENDOR, "High Tech Computer Corp"),
235			DMI_MATCH(DMI_PRODUCT_NAME, "Shift"),
236		},
237	},
238	{ }
239};
 
240
241static int __init htcpen_isa_init(void)
242{
243	if (!dmi_check_system(htcshift_dmi_table))
244		return -ENODEV;
245
246	return isa_register_driver(&htcpen_isa_driver, 1);
247}
248
249static void __exit htcpen_isa_exit(void)
250{
251	isa_unregister_driver(&htcpen_isa_driver);
252}
253
254module_init(htcpen_isa_init);
255module_exit(htcpen_isa_exit);