1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * zylonite-wm97xx.c -- Zylonite Continuous Touch screen driver
5 * Copyright 2004, 2007, 2008 Wolfson Microelectronics PLC.
6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
7 * Parts Copyright : Ian Molton <spyro@f2s.com>
8 * Andrew Zabolotny <zap@homelink.ru>
11 * This is a wm97xx extended touch driver supporting interrupt driven
12 * and continuous operation on Marvell Zylonite development systems
13 * (which have a WM9713 on board).
16 #include <linux/module.h>
17 #include <linux/moduleparam.h>
18 #include <linux/kernel.h>
19 #include <linux/delay.h>
20 #include <linux/gpio/consumer.h>
21 #include <linux/irq.h>
22 #include <linux/interrupt.h>
24 #include <linux/soc/pxa/cpu.h>
25 #include <linux/wm97xx.h>
27 #include <sound/pxa2xx-lib.h>
30 u16 id; /* codec id */
31 u8 code; /* continuous code */
32 u8 reads; /* number of coord reads per read cycle */
33 u32 speed; /* number of coords per second */
36 #define WM_READS(sp) ((sp / HZ) + 1)
38 static const struct continuous cinfo[] = {
39 { WM9713_ID2, 0, WM_READS(94), 94 },
40 { WM9713_ID2, 1, WM_READS(120), 120 },
41 { WM9713_ID2, 2, WM_READS(154), 154 },
42 { WM9713_ID2, 3, WM_READS(188), 188 },
45 /* continuous speed index */
49 * Pen sampling frequency (Hz) in continuous mode.
51 static int cont_rate = 200;
52 module_param(cont_rate, int, 0);
53 MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");
58 * Set to 1 to read back pen down pressure
61 module_param(pressure, int, 0);
62 MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");
65 * AC97 touch data slot.
67 * Touch screen readback data ac97 slot
69 static int ac97_touch_slot = 5;
70 module_param(ac97_touch_slot, int, 0);
71 MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");
74 /* flush AC97 slot 5 FIFO machines */
75 static void wm97xx_acc_pen_up(struct wm97xx *wm)
81 for (i = 0; i < 16; i++)
82 pxa2xx_ac97_read_modr();
85 static int wm97xx_acc_pen_down(struct wm97xx *wm)
87 u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;
89 static u16 last, tries;
91 /* When the AC97 queue has been drained we need to allow time
92 * to buffer up samples otherwise we end up spinning polling
93 * for samples. The controller can't have a suitably low
94 * threshold set to use the notifications it gives.
103 x = pxa2xx_ac97_read_modr();
111 x = pxa2xx_ac97_read_modr();
112 y = pxa2xx_ac97_read_modr();
114 p = pxa2xx_ac97_read_modr();
116 dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n",
119 /* are samples valid */
120 if ((x & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_X ||
121 (y & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_Y ||
122 (p & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_PRES)
125 /* coordinate is good */
127 input_report_abs(wm->input_dev, ABS_X, x & 0xfff);
128 input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);
129 input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);
130 input_report_key(wm->input_dev, BTN_TOUCH, (p != 0));
131 input_sync(wm->input_dev);
133 } while (reads < cinfo[sp_idx].reads);
135 return RC_PENDOWN | RC_AGAIN;
138 static int wm97xx_acc_startup(struct wm97xx *wm)
142 /* check we have a codec */
143 if (wm->ac97 == NULL)
146 /* Go you big red fire engine */
147 for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {
148 if (wm->id != cinfo[idx].id)
151 if (cont_rate <= cinfo[idx].speed)
154 wm->acc_rate = cinfo[sp_idx].code;
155 wm->acc_slot = ac97_touch_slot;
157 "zylonite accelerated touchscreen driver, %d samples/sec\n",
158 cinfo[sp_idx].speed);
163 static struct wm97xx_mach_ops zylonite_mach_ops = {
165 .acc_pen_up = wm97xx_acc_pen_up,
166 .acc_pen_down = wm97xx_acc_pen_down,
167 .acc_startup = wm97xx_acc_startup,
168 .irq_gpio = WM97XX_GPIO_2,
171 static int zylonite_wm97xx_probe(struct platform_device *pdev)
173 struct wm97xx *wm = platform_get_drvdata(pdev);
174 struct gpio_desc *gpio_touch_irq;
177 gpio_touch_irq = devm_gpiod_get(&pdev->dev, "touch", GPIOD_IN);
178 err = PTR_ERR_OR_ZERO(gpio_touch_irq);
180 dev_err(&pdev->dev, "Cannot get irq gpio: %d\n", err);
184 wm->pen_irq = gpiod_to_irq(gpio_touch_irq);
185 irq_set_irq_type(wm->pen_irq, IRQ_TYPE_EDGE_BOTH);
187 wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,
188 WM97XX_GPIO_POL_HIGH,
191 wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,
192 WM97XX_GPIO_POL_HIGH,
193 WM97XX_GPIO_NOTSTICKY,
196 return wm97xx_register_mach_ops(wm, &zylonite_mach_ops);
199 static int zylonite_wm97xx_remove(struct platform_device *pdev)
201 struct wm97xx *wm = platform_get_drvdata(pdev);
203 wm97xx_unregister_mach_ops(wm);
208 static struct platform_driver zylonite_wm97xx_driver = {
209 .probe = zylonite_wm97xx_probe,
210 .remove = zylonite_wm97xx_remove,
212 .name = "wm97xx-touch",
215 module_platform_driver(zylonite_wm97xx_driver);
217 /* Module information */
218 MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
219 MODULE_DESCRIPTION("wm97xx continuous touch driver for Zylonite");
220 MODULE_LICENSE("GPL");