1 From d231cea1dca0c1b04d11cbf996077cf59612e3c4 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sun, 5 Sep 2010 20:45:08 +0200
4 Subject: [PATCH 14/23] input: Add touchscreen driver for the JZ4740 SoC
6 This patch adds a touchscreen driver for the Ingenic JZ4740 SoC.
7 The touchscreen controller is part of the ADC unit and thus this driver is a mfd
8 cell from the jz4740-adc driver.
10 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
12 drivers/input/touchscreen/Kconfig | 12 ++
13 drivers/input/touchscreen/Makefile | 1 +
14 drivers/input/touchscreen/jz4740-ts.c | 330 +++++++++++++++++++++++++++++++++
15 3 files changed, 343 insertions(+), 0 deletions(-)
16 create mode 100644 drivers/input/touchscreen/jz4740-ts.c
18 --- a/drivers/input/touchscreen/Kconfig
19 +++ b/drivers/input/touchscreen/Kconfig
20 @@ -681,4 +681,16 @@ config TOUCHSCREEN_STMPE
21 To compile this driver as a module, choose M here: the
22 module will be called stmpe-ts.
24 +config TOUCHSCREEN_JZ4740
25 + tristate "JZ4740 touchscreen support"
26 + depends on MFD_JZ4740_ADC
28 + Say Y here if you want support for the touchscreen controller found on
29 + Ingenic JZ4740 SoCs.
33 + To compile this driver as a module, choose M here: the
34 + module will be called jz4740-ts.
37 --- a/drivers/input/touchscreen/Makefile
38 +++ b/drivers/input/touchscreen/Makefile
39 @@ -26,6 +26,7 @@ obj-$(CONFIG_TOUCHSCREEN_FUJITSU) += fuj
40 obj-$(CONFIG_TOUCHSCREEN_INEXIO) += inexio.o
41 obj-$(CONFIG_TOUCHSCREEN_INTEL_MID) += intel-mid-touch.o
42 obj-$(CONFIG_TOUCHSCREEN_LPC32XX) += lpc32xx_ts.o
43 +obj-$(CONFIG_TOUCHSCREEN_JZ4740) += jz4740-ts.o
44 obj-$(CONFIG_TOUCHSCREEN_MC13783) += mc13783_ts.o
45 obj-$(CONFIG_TOUCHSCREEN_MCS5000) += mcs5000_ts.o
46 obj-$(CONFIG_TOUCHSCREEN_MIGOR) += migor_ts.o
48 +++ b/drivers/input/touchscreen/jz4740-ts.c
51 + * Touchscreen driver for Ingenic JZ SoCs.
53 + * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
55 + * This program is free software; you can redistribute it and/or modify
56 + * it under the terms of the GNU General Public License version 2 as
57 + * published by the Free Software Foundation.
61 +#include <linux/interrupt.h>
62 +#include <linux/kernel.h>
63 +#include <linux/module.h>
64 +#include <linux/platform_device.h>
65 +#include <linux/slab.h>
67 +#include <linux/delay.h>
68 +#include <linux/mfd/core.h>
69 +#include <linux/input.h>
70 +#include <linux/bitops.h>
71 +#include <linux/jz4740-adc.h>
74 + struct platform_device *pdev;
76 + struct resource *mem;
83 + struct mfd_cell *cell;
84 + struct input_dev *input;
89 +static irqreturn_t jz4740_ts_data_ready_irq_handler(int irq, void *devid)
91 + struct jz4740_ts *jz4740_ts = devid;
93 + unsigned long x, y, z1, z2, pressure;
95 + data = readl(jz4740_ts->base + 0x08);
97 + y = (data >> 16) & 0xfff;
99 + data = readl(jz4740_ts->base + 0x08);
101 + z2 = (data >> 16) & 0xfff;
104 + } else if (z1 > z2) {
108 + pressure = (((480UL * x * z2) / z1) - 480UL * x) / 4096UL;
110 + pressure = (((272UL * y * z2) / z1) - 272UL * y) / 4096UL;
111 + if (pressure >= 4096UL)
113 + pressure = 4095UL - pressure;
116 + input_report_abs(jz4740_ts->input, ABS_X, y);
117 + input_report_abs(jz4740_ts->input, ABS_Y, 4095 - x);
118 + input_report_abs(jz4740_ts->input, ABS_PRESSURE, pressure);
119 + input_report_key(jz4740_ts->input, BTN_TOUCH, 1);
120 + input_sync(jz4740_ts->input);
122 + return IRQ_HANDLED;
125 +static irqreturn_t jz4740_ts_pen_irq_handler(int irq, void *devid)
127 + struct jz4740_ts *jz4740_ts = devid;
130 + if (irq == jz4740_ts->irq_penup) {
131 + enable_irq(jz4740_ts->irq_pendown);
134 + enable_irq(jz4740_ts->irq_penup);
137 + disable_irq_nosync(irq);
139 + printk("pen irq: %d\n", irq);
140 + input_report_key(jz4740_ts->input, BTN_TOUCH, is_pressed);
141 + if (is_pressed == 0)
142 + input_report_abs(jz4740_ts->input, ABS_PRESSURE, 0);
143 + input_sync(jz4740_ts->input);
145 + return IRQ_HANDLED;
148 +static int jz4740_ts_open(struct input_dev *input)
150 + struct jz4740_ts *jz4740_ts = input_get_drvdata(input);
152 + jz4740_ts->is_open = true;
153 + jz4740_ts->cell->enable(jz4740_ts->pdev);
158 +static void jz4740_ts_close(struct input_dev *input)
160 + struct jz4740_ts *jz4740_ts = input_get_drvdata(input);
162 + jz4740_ts->cell->disable(jz4740_ts->pdev);
163 + jz4740_ts->is_open = false;
166 +static int __devinit jz4740_ts_probe(struct platform_device *pdev)
169 + struct jz4740_ts *jz4740_ts;
170 + struct input_dev *input;
172 + jz4740_ts = kzalloc(sizeof(*jz4740_ts), GFP_KERNEL);
174 + dev_err(&pdev->dev, "Failed to allocate driver structure\n");
178 + jz4740_ts->pdev = pdev;
179 + jz4740_ts->cell = pdev->dev.platform_data;
181 + jz4740_ts->irq_data_ready = platform_get_irq(pdev, 0);
182 + if (jz4740_ts->irq_data_ready < 0) {
183 + ret = jz4740_ts->irq_data_ready;
184 + dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
188 + jz4740_ts->irq_penup = platform_get_irq(pdev, 1);
189 + if (jz4740_ts->irq_penup < 0) {
190 + ret = jz4740_ts->irq_penup;
191 + dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
195 + jz4740_ts->irq_pendown = platform_get_irq(pdev, 2);
196 + if (jz4740_ts->irq_pendown < 0) {
197 + ret = jz4740_ts->irq_pendown;
198 + dev_err(&pdev->dev, "Failed to get platform irq: %d\n", ret);
202 + jz4740_ts->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
203 + if (!jz4740_ts->mem) {
205 + dev_err(&pdev->dev, "Failed to get platform mmio resource\n");
209 + jz4740_ts->mem = request_mem_region(jz4740_ts->mem->start,
210 + resource_size(jz4740_ts->mem), pdev->name);
211 + if (!jz4740_ts->mem) {
213 + dev_err(&pdev->dev, "Failed to request mmio memory region\n");
217 + jz4740_ts->base = ioremap_nocache(jz4740_ts->mem->start,
218 + resource_size(jz4740_ts->mem));
219 + if (!jz4740_ts->base) {
221 + dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
222 + goto err_release_mem_region;
225 + input = input_allocate_device();
227 + dev_err(&pdev->dev, "Failed to allocate input device\n");
232 + input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
233 + __set_bit(BTN_TOUCH, input->keybit);
235 + input_set_abs_params(input, ABS_X, 150, 3920, 0, 0);
236 + input_set_abs_params(input, ABS_Y, 270, 3700, 0, 0);
237 + input_set_abs_params(input, ABS_PRESSURE, 0, 4096, 0, 0);
239 + input->name = pdev->name;
240 + input->phys = "jz4740";
241 + input->id.bustype = BUS_HOST;
242 + input->dev.parent = &pdev->dev;
244 + input->open = jz4740_ts_open;
245 + input->close = jz4740_ts_close;
247 + input_set_drvdata(input, jz4740_ts);
249 + ret = input_register_device(input);
251 + dev_err(&pdev->dev, "Failed to register input device: %d\n", ret);
252 + input_free_device(input);
255 + jz4740_ts->input = input;
257 + ret = request_irq(jz4740_ts->irq_data_ready, jz4740_ts_data_ready_irq_handler, 0, pdev->name,
260 + dev_err(&pdev->dev, "Failed to request irq %d\n", ret);
261 + goto err_input_unregister_device;
263 + ret = request_irq(jz4740_ts->irq_penup, jz4740_ts_pen_irq_handler, 0, pdev->name,
266 + dev_err(&pdev->dev, "Failed to request irq %d\n", ret);
267 + goto err_free_irq_data_ready;
269 + disable_irq(jz4740_ts->irq_penup);
270 + ret = request_irq(jz4740_ts->irq_pendown, jz4740_ts_pen_irq_handler, 0, pdev->name,
273 + dev_err(&pdev->dev, "Failed to request irq %d\n", ret);
274 + goto err_free_irq_penup;
276 + platform_set_drvdata(pdev, jz4740_ts);
278 + jz4740_adc_set_config(pdev->dev.parent,
279 + JZ_ADC_CONFIG_EX_IN | JZ_ADC_CONFIG_XYZ_OFFSET(2) | JZ_ADC_CONFIG_DNUM(7),
280 + JZ_ADC_CONFIG_EX_IN | JZ_ADC_CONFIG_XYZ_MASK | JZ_ADC_CONFIG_DNUM_MASK);
283 + writel(0x15e, jz4740_ts->base);
284 + writel(0x32, jz4740_ts->base + 0x04);
289 + free_irq(jz4740_ts->irq_penup, jz4740_ts);
290 +err_free_irq_data_ready:
291 + free_irq(jz4740_ts->irq_data_ready, jz4740_ts);
292 +err_input_unregister_device:
293 + input_unregister_device(jz4740_ts->input);
295 + platform_set_drvdata(pdev, NULL);
296 + iounmap(jz4740_ts->base);
297 +err_release_mem_region:
298 + release_mem_region(jz4740_ts->mem->start, resource_size(jz4740_ts->mem));
304 +static int __devexit jz4740_ts_remove(struct platform_device *pdev)
306 + struct jz4740_ts *jz4740_ts = platform_get_drvdata(pdev);
309 + free_irq(jz4740_ts->irq_pendown, jz4740_ts);
310 + free_irq(jz4740_ts->irq_penup, jz4740_ts);
311 + free_irq(jz4740_ts->irq_data_ready, jz4740_ts);
313 + input_unregister_device(jz4740_ts->input);
315 + iounmap(jz4740_ts->base);
316 + release_mem_region(jz4740_ts->mem->start, resource_size(jz4740_ts->mem));
324 +static int jz4740_ts_suspend(struct device *dev)
326 + struct jz4740_ts *jz4740_ts = dev_get_drvdata(dev);
328 + if (jz4740_ts->is_open);
329 + jz4740_ts->cell->disable(jz4740_ts->pdev);
334 +static int jz4740_ts_resume(struct device *dev)
336 + struct jz4740_ts *jz4740_ts = dev_get_drvdata(dev);
338 + if (jz4740_ts->is_open);
339 + jz4740_ts->cell->enable(jz4740_ts->pdev);
344 +static const struct dev_pm_ops jz4740_ts_pm_ops = {
345 + .suspend = jz4740_ts_suspend,
346 + .resume = jz4740_ts_resume,
349 +#define JZ4740_TS_PM_OPS (&jz4740_ts_pm_ops)
351 +#define JZ4740_TS_PM_OPS NULL
354 +static struct platform_driver jz4740_ts_driver = {
355 + .probe = jz4740_ts_probe,
356 + .remove = __devexit_p(jz4740_ts_remove),
358 + .name = "jz4740-ts",
359 + .owner = THIS_MODULE,
360 + .pm = JZ4740_TS_PM_OPS,
364 +static int __init jz4740_ts_init(void)
366 + return platform_driver_register(&jz4740_ts_driver);
368 +module_init(jz4740_ts_init);
370 +static void __exit jz4740_ts_exit(void)
372 + platform_driver_unregister(&jz4740_ts_driver);
374 +module_exit(jz4740_ts_exit);
376 +MODULE_ALIAS("platform:jz4740-ts");
377 +MODULE_LICENSE("GPL");
378 +MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>");
379 +MODULE_DESCRIPTION("JZ4740 SoC battery driver");