19 #include <linux/input.h>
21 #include <linux/module.h>
24 #include <linux/slab.h>
30 #define LPC32XX_TSC_STAT 0x00
31 #define LPC32XX_TSC_SEL 0x04
32 #define LPC32XX_TSC_CON 0x08
33 #define LPC32XX_TSC_FIFO 0x0C
34 #define LPC32XX_TSC_DTR 0x10
35 #define LPC32XX_TSC_RTR 0x14
36 #define LPC32XX_TSC_UTR 0x18
37 #define LPC32XX_TSC_TTR 0x1C
38 #define LPC32XX_TSC_DXP 0x20
39 #define LPC32XX_TSC_MIN_X 0x24
40 #define LPC32XX_TSC_MAX_X 0x28
41 #define LPC32XX_TSC_MIN_Y 0x2C
42 #define LPC32XX_TSC_MAX_Y 0x30
43 #define LPC32XX_TSC_AUX_UTR 0x34
44 #define LPC32XX_TSC_AUX_MIN 0x38
45 #define LPC32XX_TSC_AUX_MAX 0x3C
47 #define LPC32XX_TSC_STAT_FIFO_OVRRN (1 << 8)
48 #define LPC32XX_TSC_STAT_FIFO_EMPTY (1 << 7)
50 #define LPC32XX_TSC_SEL_DEFVAL 0x0284
52 #define LPC32XX_TSC_ADCCON_IRQ_TO_FIFO_4 (0x1 << 11)
53 #define LPC32XX_TSC_ADCCON_X_SAMPLE_SIZE(s) ((10 - (s)) << 7)
54 #define LPC32XX_TSC_ADCCON_Y_SAMPLE_SIZE(s) ((10 - (s)) << 4)
55 #define LPC32XX_TSC_ADCCON_POWER_UP (1 << 2)
56 #define LPC32XX_TSC_ADCCON_AUTO_EN (1 << 0)
58 #define LPC32XX_TSC_FIFO_TS_P_LEVEL (1 << 31)
59 #define LPC32XX_TSC_FIFO_NORMALIZE_X_VAL(x) (((x) & 0x03FF0000) >> 16)
60 #define LPC32XX_TSC_FIFO_NORMALIZE_Y_VAL(y) ((y) & 0x000003FF)
62 #define LPC32XX_TSC_ADCDAT_VALUE_MASK 0x000003FF
64 #define LPC32XX_TSC_MIN_XY_VAL 0x0
65 #define LPC32XX_TSC_MAX_XY_VAL 0x3FF
67 #define MOD_NAME "ts-lpc32xx"
69 #define tsc_readl(dev, reg) \
70 __raw_readl((dev)->tsc_base + (reg))
71 #define tsc_writel(dev, reg, val) \
72 __raw_writel((val), (dev)->tsc_base + (reg))
75 struct input_dev *
dev;
99 lpc32xx_fifo_clear(tsc);
124 input_report_abs(input,
ABS_X, (xs[1] + xs[2]) / 2);
125 input_report_abs(input,
ABS_Y, (ys[1] + ys[2]) / 2);
136 static void lpc32xx_stop_tsc(
struct lpc32xx_tsc *tsc)
146 static void lpc32xx_setup_tsc(
struct lpc32xx_tsc *tsc)
184 lpc32xx_fifo_clear(tsc);
190 static int lpc32xx_ts_open(
struct input_dev *
dev)
194 lpc32xx_setup_tsc(tsc);
199 static void lpc32xx_ts_close(
struct input_dev *
dev)
203 lpc32xx_stop_tsc(tsc);
209 struct input_dev *
input;
217 dev_err(&pdev->
dev,
"Can't get memory resource\n");
223 dev_err(&pdev->
dev,
"Can't get interrupt resource\n");
228 input = input_allocate_device();
229 if (!tsc || !input) {
230 dev_err(&pdev->
dev,
"failed allocating memory\n");
238 size = resource_size(res);
241 dev_err(&pdev->
dev,
"TSC registers are not free\n");
250 goto err_release_mem;
254 if (IS_ERR(tsc->
clk)) {
255 dev_err(&pdev->
dev,
"failed getting clock\n");
256 error = PTR_ERR(tsc->
clk);
261 input->phys =
"lpc32xx/input0";
263 input->id.vendor = 0x0001;
264 input->id.product = 0x0002;
265 input->id.version = 0x0100;
266 input->dev.parent = &pdev->
dev;
267 input->open = lpc32xx_ts_open;
268 input->close = lpc32xx_ts_close;
277 input_set_drvdata(input, tsc);
282 dev_err(&pdev->
dev,
"failed requesting interrupt\n");
286 error = input_register_device(input);
288 dev_err(&pdev->
dev,
"failed registering input device\n");
292 platform_set_drvdata(pdev, tsc);
306 input_free_device(input);
314 struct lpc32xx_tsc *tsc = platform_get_drvdata(pdev);
320 input_unregister_device(tsc->
dev);
334 static int lpc32xx_ts_suspend(
struct device *
dev)
337 struct input_dev *input = tsc->
dev;
348 if (device_may_wakeup(dev))
349 enable_irq_wake(tsc->
irq);
351 lpc32xx_stop_tsc(tsc);
359 static int lpc32xx_ts_resume(
struct device *dev)
362 struct input_dev *input = tsc->
dev;
367 if (device_may_wakeup(dev))
368 disable_irq_wake(tsc->
irq);
370 lpc32xx_setup_tsc(tsc);
378 static const struct dev_pm_ops lpc32xx_ts_pm_ops = {
380 .resume = lpc32xx_ts_resume,
382 #define LPC32XX_TS_PM_OPS (&lpc32xx_ts_pm_ops)
384 #define LPC32XX_TS_PM_OPS NULL
396 .probe = lpc32xx_ts_probe,