2 * Touchscreen driver for Marvell 88PM860x
4 * Copyright (C) 2009 Marvell International Ltd.
5 * Haojian Zhuang <haojian.zhuang@marvell.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.h>
14 #include <linux/i2c.h>
15 #include <linux/input.h>
16 #include <linux/mfd/88pm860x.h>
17 #include <linux/slab.h>
20 #define ACCURATE_BIT (12)
23 #define MEAS_EN3 (0x52)
25 #define MEAS_TSIX_1 (0x8D)
26 #define MEAS_TSIX_2 (0x8E)
27 #define MEAS_TSIY_1 (0x8F)
28 #define MEAS_TSIY_2 (0x90)
29 #define MEAS_TSIZ1_1 (0x91)
30 #define MEAS_TSIZ1_2 (0x92)
31 #define MEAS_TSIZ2_1 (0x93)
32 #define MEAS_TSIZ2_2 (0x94)
34 /* bit definitions of touch */
35 #define MEAS_PD_EN (1 << 3)
36 #define MEAS_TSIX_EN (1 << 4)
37 #define MEAS_TSIY_EN (1 << 5)
38 #define MEAS_TSIZ1_EN (1 << 6)
39 #define MEAS_TSIZ2_EN (1 << 7)
42 struct input_dev
*idev
;
43 struct i2c_client
*i2c
;
44 struct pm860x_chip
*chip
;
46 int res_x
; /* resistor of Xplate */
49 static irqreturn_t
pm860x_touch_handler(int irq
, void *data
)
51 struct pm860x_touch
*touch
= data
;
52 struct pm860x_chip
*chip
= touch
->chip
;
53 unsigned char buf
[MEAS_LEN
];
58 ret
= pm860x_bulk_read(touch
->i2c
, MEAS_TSIX_1
, MEAS_LEN
, buf
);
62 pen_down
= buf
[1] & (1 << 6);
63 x
= ((buf
[0] & 0xFF) << 4) | (buf
[1] & 0x0F);
64 y
= ((buf
[2] & 0xFF) << 4) | (buf
[3] & 0x0F);
65 z1
= ((buf
[4] & 0xFF) << 4) | (buf
[5] & 0x0F);
66 z2
= ((buf
[6] & 0xFF) << 4) | (buf
[7] & 0x0F);
69 if ((x
!= 0) && (z1
!= 0) && (touch
->res_x
!= 0)) {
71 rt
= (rt
* touch
->res_x
* x
) >> ACCURATE_BIT
;
72 dev_dbg(chip
->dev
, "z1:%d, z2:%d, rt:%d\n",
75 input_report_abs(touch
->idev
, ABS_X
, x
);
76 input_report_abs(touch
->idev
, ABS_Y
, y
);
77 input_report_abs(touch
->idev
, ABS_PRESSURE
, rt
);
78 input_report_key(touch
->idev
, BTN_TOUCH
, 1);
79 dev_dbg(chip
->dev
, "pen down at [%d, %d].\n", x
, y
);
81 input_report_abs(touch
->idev
, ABS_PRESSURE
, 0);
82 input_report_key(touch
->idev
, BTN_TOUCH
, 0);
83 dev_dbg(chip
->dev
, "pen release\n");
85 input_sync(touch
->idev
);
91 static int pm860x_touch_open(struct input_dev
*dev
)
93 struct pm860x_touch
*touch
= input_get_drvdata(dev
);
96 data
= MEAS_PD_EN
| MEAS_TSIX_EN
| MEAS_TSIY_EN
97 | MEAS_TSIZ1_EN
| MEAS_TSIZ2_EN
;
98 ret
= pm860x_set_bits(touch
->i2c
, MEAS_EN3
, data
, data
);
106 static void pm860x_touch_close(struct input_dev
*dev
)
108 struct pm860x_touch
*touch
= input_get_drvdata(dev
);
111 data
= MEAS_PD_EN
| MEAS_TSIX_EN
| MEAS_TSIY_EN
112 | MEAS_TSIZ1_EN
| MEAS_TSIZ2_EN
;
113 pm860x_set_bits(touch
->i2c
, MEAS_EN3
, data
, 0);
116 static int __devinit
pm860x_touch_probe(struct platform_device
*pdev
)
118 struct pm860x_chip
*chip
= dev_get_drvdata(pdev
->dev
.parent
);
119 struct pm860x_platform_data
*pm860x_pdata
= \
120 pdev
->dev
.parent
->platform_data
;
121 struct pm860x_touch_pdata
*pdata
= NULL
;
122 struct pm860x_touch
*touch
;
125 irq
= platform_get_irq(pdev
, 0);
127 dev_err(&pdev
->dev
, "No IRQ resource!\n");
132 dev_err(&pdev
->dev
, "platform data is missing\n");
136 pdata
= pm860x_pdata
->touch
;
138 dev_err(&pdev
->dev
, "touchscreen data is missing\n");
142 touch
= kzalloc(sizeof(struct pm860x_touch
), GFP_KERNEL
);
145 dev_set_drvdata(&pdev
->dev
, touch
);
147 touch
->idev
= input_allocate_device();
148 if (touch
->idev
== NULL
) {
149 dev_err(&pdev
->dev
, "Failed to allocate input device!\n");
154 touch
->idev
->name
= "88pm860x-touch";
155 touch
->idev
->phys
= "88pm860x/input0";
156 touch
->idev
->id
.bustype
= BUS_I2C
;
157 touch
->idev
->dev
.parent
= &pdev
->dev
;
158 touch
->idev
->open
= pm860x_touch_open
;
159 touch
->idev
->close
= pm860x_touch_close
;
161 touch
->i2c
= (chip
->id
== CHIP_PM8607
) ? chip
->client
: chip
->companion
;
162 touch
->irq
= irq
+ chip
->irq_base
;
163 touch
->res_x
= pdata
->res_x
;
164 input_set_drvdata(touch
->idev
, touch
);
166 ret
= request_threaded_irq(touch
->irq
, NULL
, pm860x_touch_handler
,
167 IRQF_ONESHOT
, "touch", touch
);
171 __set_bit(EV_ABS
, touch
->idev
->evbit
);
172 __set_bit(ABS_X
, touch
->idev
->absbit
);
173 __set_bit(ABS_Y
, touch
->idev
->absbit
);
174 __set_bit(ABS_PRESSURE
, touch
->idev
->absbit
);
175 __set_bit(EV_SYN
, touch
->idev
->evbit
);
176 __set_bit(EV_KEY
, touch
->idev
->evbit
);
177 __set_bit(BTN_TOUCH
, touch
->idev
->keybit
);
179 input_set_abs_params(touch
->idev
, ABS_X
, 0, 1 << ACCURATE_BIT
, 0, 0);
180 input_set_abs_params(touch
->idev
, ABS_Y
, 0, 1 << ACCURATE_BIT
, 0, 0);
181 input_set_abs_params(touch
->idev
, ABS_PRESSURE
, 0, 1 << ACCURATE_BIT
,
184 ret
= input_register_device(touch
->idev
);
186 dev_err(chip
->dev
, "Failed to register touch!\n");
190 platform_set_drvdata(pdev
, touch
);
193 free_irq(touch
->irq
, touch
);
195 input_free_device(touch
->idev
);
201 static int __devexit
pm860x_touch_remove(struct platform_device
*pdev
)
203 struct pm860x_touch
*touch
= platform_get_drvdata(pdev
);
205 input_unregister_device(touch
->idev
);
206 free_irq(touch
->irq
, touch
);
207 platform_set_drvdata(pdev
, NULL
);
212 static struct platform_driver pm860x_touch_driver
= {
214 .name
= "88pm860x-touch",
215 .owner
= THIS_MODULE
,
217 .probe
= pm860x_touch_probe
,
218 .remove
= __devexit_p(pm860x_touch_remove
),
221 static int __init
pm860x_touch_init(void)
223 return platform_driver_register(&pm860x_touch_driver
);
225 module_init(pm860x_touch_init
);
227 static void __exit
pm860x_touch_exit(void)
229 platform_driver_unregister(&pm860x_touch_driver
);
231 module_exit(pm860x_touch_exit
);
233 MODULE_DESCRIPTION("Touchscreen driver for Marvell Semiconductor 88PM860x");
234 MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>");
235 MODULE_LICENSE("GPL");
236 MODULE_ALIAS("platform:88pm860x-touch");