Path: blob/master/drivers/input/touchscreen/mainstone-wm97xx.c
15109 views
/*1* mainstone-wm97xx.c -- Mainstone Continuous Touch screen driver for2* Wolfson WM97xx AC97 Codecs.3*4* Copyright 2004, 2007 Wolfson Microelectronics PLC.5* Author: Liam Girdwood <[email protected]>6* Parts Copyright : Ian Molton <[email protected]>7* Andrew Zabolotny <[email protected]>8*9* This program is free software; you can redistribute it and/or modify it10* under the terms of the GNU General Public License as published by the11* Free Software Foundation; either version 2 of the License, or (at your12* option) any later version.13*14* Notes:15* This is a wm97xx extended touch driver to capture touch16* data in a continuous manner on the Intel XScale architecture17*18* Features:19* - codecs supported:- WM9705, WM9712, WM971320* - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x21*22*/2324#include <linux/module.h>25#include <linux/moduleparam.h>26#include <linux/kernel.h>27#include <linux/init.h>28#include <linux/delay.h>29#include <linux/irq.h>30#include <linux/interrupt.h>31#include <linux/wm97xx.h>32#include <linux/io.h>33#include <linux/gpio.h>3435#include <mach/regs-ac97.h>3637#include <asm/mach-types.h>3839struct continuous {40u16 id; /* codec id */41u8 code; /* continuous code */42u8 reads; /* number of coord reads per read cycle */43u32 speed; /* number of coords per second */44};4546#define WM_READS(sp) ((sp / HZ) + 1)4748static const struct continuous cinfo[] = {49{WM9705_ID2, 0, WM_READS(94), 94},50{WM9705_ID2, 1, WM_READS(188), 188},51{WM9705_ID2, 2, WM_READS(375), 375},52{WM9705_ID2, 3, WM_READS(750), 750},53{WM9712_ID2, 0, WM_READS(94), 94},54{WM9712_ID2, 1, WM_READS(188), 188},55{WM9712_ID2, 2, WM_READS(375), 375},56{WM9712_ID2, 3, WM_READS(750), 750},57{WM9713_ID2, 0, WM_READS(94), 94},58{WM9713_ID2, 1, WM_READS(120), 120},59{WM9713_ID2, 2, WM_READS(154), 154},60{WM9713_ID2, 3, WM_READS(188), 188},61};6263/* continuous speed index */64static int sp_idx;65static u16 last, tries;66static int irq;6768/*69* Pen sampling frequency (Hz) in continuous mode.70*/71static int cont_rate = 200;72module_param(cont_rate, int, 0);73MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)");7475/*76* Pen down detection.77*78* This driver can either poll or use an interrupt to indicate a pen down79* event. If the irq request fails then it will fall back to polling mode.80*/81static int pen_int;82module_param(pen_int, int, 0);83MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)");8485/*86* Pressure readback.87*88* Set to 1 to read back pen down pressure89*/90static int pressure;91module_param(pressure, int, 0);92MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)");9394/*95* AC97 touch data slot.96*97* Touch screen readback data ac97 slot98*/99static int ac97_touch_slot = 5;100module_param(ac97_touch_slot, int, 0);101MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number");102103104/* flush AC97 slot 5 FIFO on pxa machines */105#ifdef CONFIG_PXA27x106static void wm97xx_acc_pen_up(struct wm97xx *wm)107{108schedule_timeout_uninterruptible(1);109110while (MISR & (1 << 2))111MODR;112}113#else114static void wm97xx_acc_pen_up(struct wm97xx *wm)115{116unsigned int count;117118schedule_timeout_uninterruptible(1);119120for (count = 0; count < 16; count++)121MODR;122}123#endif124125static int wm97xx_acc_pen_down(struct wm97xx *wm)126{127u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES;128int reads = 0;129130/* When the AC97 queue has been drained we need to allow time131* to buffer up samples otherwise we end up spinning polling132* for samples. The controller can't have a suitably low133* threshold set to use the notifications it gives.134*/135schedule_timeout_uninterruptible(1);136137if (tries > 5) {138tries = 0;139return RC_PENUP;140}141142x = MODR;143if (x == last) {144tries++;145return RC_AGAIN;146}147last = x;148do {149if (reads)150x = MODR;151y = MODR;152if (pressure)153p = MODR;154155dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n",156x, y, p);157158/* are samples valid */159if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||160(y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||161(p & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_PRES)162goto up;163164/* coordinate is good */165tries = 0;166input_report_abs(wm->input_dev, ABS_X, x & 0xfff);167input_report_abs(wm->input_dev, ABS_Y, y & 0xfff);168input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff);169input_report_key(wm->input_dev, BTN_TOUCH, (p != 0));170input_sync(wm->input_dev);171reads++;172} while (reads < cinfo[sp_idx].reads);173up:174return RC_PENDOWN | RC_AGAIN;175}176177static int wm97xx_acc_startup(struct wm97xx *wm)178{179int idx = 0, ret = 0;180181/* check we have a codec */182if (wm->ac97 == NULL)183return -ENODEV;184185/* Go you big red fire engine */186for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) {187if (wm->id != cinfo[idx].id)188continue;189sp_idx = idx;190if (cont_rate <= cinfo[idx].speed)191break;192}193wm->acc_rate = cinfo[sp_idx].code;194wm->acc_slot = ac97_touch_slot;195dev_info(wm->dev,196"mainstone accelerated touchscreen driver, %d samples/sec\n",197cinfo[sp_idx].speed);198199/* IRQ driven touchscreen is used on Palm hardware */200if (machine_is_palmt5() || machine_is_palmtx() || machine_is_palmld()) {201pen_int = 1;202irq = 27;203/* There is some obscure mutant of WM9712 interbred with WM9713204* used on Palm HW */205wm->variant = WM97xx_WM1613;206} else if (machine_is_mainstone() && pen_int)207irq = 4;208209if (irq) {210ret = gpio_request(irq, "Touchscreen IRQ");211if (ret)212goto out;213214ret = gpio_direction_input(irq);215if (ret) {216gpio_free(irq);217goto out;218}219220wm->pen_irq = gpio_to_irq(irq);221irq_set_irq_type(wm->pen_irq, IRQ_TYPE_EDGE_BOTH);222} else /* pen irq not supported */223pen_int = 0;224225/* codec specific irq config */226if (pen_int) {227switch (wm->id) {228case WM9705_ID2:229break;230case WM9712_ID2:231case WM9713_ID2:232/* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */233wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN,234WM97XX_GPIO_POL_HIGH,235WM97XX_GPIO_STICKY,236WM97XX_GPIO_WAKE);237wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT,238WM97XX_GPIO_POL_HIGH,239WM97XX_GPIO_NOTSTICKY,240WM97XX_GPIO_NOWAKE);241break;242default:243dev_err(wm->dev,244"pen down irq not supported on this device\n");245pen_int = 0;246break;247}248}249250out:251return ret;252}253254static void wm97xx_acc_shutdown(struct wm97xx *wm)255{256/* codec specific deconfig */257if (pen_int) {258if (irq)259gpio_free(irq);260wm->pen_irq = 0;261}262}263264static void wm97xx_irq_enable(struct wm97xx *wm, int enable)265{266if (enable)267enable_irq(wm->pen_irq);268else269disable_irq_nosync(wm->pen_irq);270}271272static struct wm97xx_mach_ops mainstone_mach_ops = {273.acc_enabled = 1,274.acc_pen_up = wm97xx_acc_pen_up,275.acc_pen_down = wm97xx_acc_pen_down,276.acc_startup = wm97xx_acc_startup,277.acc_shutdown = wm97xx_acc_shutdown,278.irq_enable = wm97xx_irq_enable,279.irq_gpio = WM97XX_GPIO_2,280};281282static int mainstone_wm97xx_probe(struct platform_device *pdev)283{284struct wm97xx *wm = platform_get_drvdata(pdev);285286return wm97xx_register_mach_ops(wm, &mainstone_mach_ops);287}288289static int mainstone_wm97xx_remove(struct platform_device *pdev)290{291struct wm97xx *wm = platform_get_drvdata(pdev);292293wm97xx_unregister_mach_ops(wm);294return 0;295}296297static struct platform_driver mainstone_wm97xx_driver = {298.probe = mainstone_wm97xx_probe,299.remove = mainstone_wm97xx_remove,300.driver = {301.name = "wm97xx-touch",302},303};304305static int __init mainstone_wm97xx_init(void)306{307return platform_driver_register(&mainstone_wm97xx_driver);308}309310static void __exit mainstone_wm97xx_exit(void)311{312platform_driver_unregister(&mainstone_wm97xx_driver);313}314315module_init(mainstone_wm97xx_init);316module_exit(mainstone_wm97xx_exit);317318/* Module information */319MODULE_AUTHOR("Liam Girdwood <[email protected]>");320MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone");321MODULE_LICENSE("GPL");322323324