diff options
Diffstat (limited to 'drivers/input/touchscreen')
-rw-r--r-- | drivers/input/touchscreen/Kconfig | 15 | ||||
-rw-r--r-- | drivers/input/touchscreen/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/touchscreen/ads7846.c | 95 | ||||
-rw-r--r-- | drivers/input/touchscreen/corgi_ts.c | 30 | ||||
-rw-r--r-- | drivers/input/touchscreen/elo.c | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/gunze.c | 17 | ||||
-rw-r--r-- | drivers/input/touchscreen/h3600_ts_input.c | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/hp680_ts_input.c | 29 | ||||
-rw-r--r-- | drivers/input/touchscreen/mk712.c | 26 | ||||
-rw-r--r-- | drivers/input/touchscreen/mtouch.c | 16 | ||||
-rw-r--r-- | drivers/input/touchscreen/penmount.c | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/touchright.c | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/touchwin.c | 3 | ||||
-rw-r--r-- | drivers/input/touchscreen/ucb1400_ts.c | 579 |
14 files changed, 731 insertions, 92 deletions
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig index 9418bbe47072..29ca0ab0acb8 100644 --- a/drivers/input/touchscreen/Kconfig +++ b/drivers/input/touchscreen/Kconfig @@ -144,4 +144,19 @@ config TOUCHSCREEN_TOUCHWIN To compile this driver as a module, choose M here: the module will be called touchwin. +config TOUCHSCREEN_UCB1400 + tristate "Philips UCB1400 touchscreen" + select SND_AC97_BUS + help + This enables support for the Philips UCB1400 touchscreen interface. + The UCB1400 is an AC97 audio codec. The touchscreen interface + will be initialized only after the ALSA subsystem has been + brought up and the UCB1400 detected. You therefore have to + configure ALSA support as well (either built-in or modular, + independently of whether this driver is itself built-in or + modular) for this driver to work. + + To compile this driver as a module, choose M here: the + module will be called ucb1400_ts. + endif diff --git a/drivers/input/touchscreen/Makefile b/drivers/input/touchscreen/Makefile index 1abb8f10d608..30e6e2217a15 100644 --- a/drivers/input/touchscreen/Makefile +++ b/drivers/input/touchscreen/Makefile @@ -15,3 +15,4 @@ obj-$(CONFIG_TOUCHSCREEN_HP600) += hp680_ts_input.o obj-$(CONFIG_TOUCHSCREEN_PENMOUNT) += penmount.o obj-$(CONFIG_TOUCHSCREEN_TOUCHRIGHT) += touchright.o obj-$(CONFIG_TOUCHSCREEN_TOUCHWIN) += touchwin.o +obj-$(CONFIG_TOUCHSCREEN_UCB1400) += ucb1400_ts.o diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c index 0517c7387d67..c6164b6f476a 100644 --- a/drivers/input/touchscreen/ads7846.c +++ b/drivers/input/touchscreen/ads7846.c @@ -76,6 +76,7 @@ struct ads7846 { char phys[32]; struct spi_device *spi; + struct attribute_group *attr_group; u16 model; u16 vref_delay_usecs; u16 x_plate_ohms; @@ -317,6 +318,48 @@ static ssize_t ads7846_disable_store(struct device *dev, static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); +static struct attribute *ads7846_attributes[] = { + &dev_attr_temp0.attr, + &dev_attr_temp1.attr, + &dev_attr_vbatt.attr, + &dev_attr_vaux.attr, + &dev_attr_pen_down.attr, + &dev_attr_disable.attr, + NULL, +}; + +static struct attribute_group ads7846_attr_group = { + .attrs = ads7846_attributes, +}; + +/* + * ads7843/7845 don't have temperature sensors, and + * use the other sensors a bit differently too + */ + +static struct attribute *ads7843_attributes[] = { + &dev_attr_vbatt.attr, + &dev_attr_vaux.attr, + &dev_attr_pen_down.attr, + &dev_attr_disable.attr, + NULL, +}; + +static struct attribute_group ads7843_attr_group = { + .attrs = ads7843_attributes, +}; + +static struct attribute *ads7845_attributes[] = { + &dev_attr_vaux.attr, + &dev_attr_pen_down.attr, + &dev_attr_disable.attr, + NULL, +}; + +static struct attribute_group ads7845_attr_group = { + .attrs = ads7845_attributes, +}; + /*--------------------------------------------------------------------------*/ /* @@ -788,38 +831,30 @@ static int __devinit ads7846_probe(struct spi_device *spi) (void) ads7846_read12_ser(&spi->dev, READ_12BIT_SER(vaux) | ADS_PD10_ALL_ON); - /* ads7843/7845 don't have temperature sensors, and - * use the other sensors a bit differently too - */ - if (ts->model == 7846) { - device_create_file(&spi->dev, &dev_attr_temp0); - device_create_file(&spi->dev, &dev_attr_temp1); + switch (ts->model) { + case 7846: + ts->attr_group = &ads7846_attr_group; + break; + case 7845: + ts->attr_group = &ads7845_attr_group; + break; + default: + ts->attr_group = &ads7843_attr_group; + break; } - if (ts->model != 7845) - device_create_file(&spi->dev, &dev_attr_vbatt); - device_create_file(&spi->dev, &dev_attr_vaux); - - device_create_file(&spi->dev, &dev_attr_pen_down); - - device_create_file(&spi->dev, &dev_attr_disable); + err = sysfs_create_group(&spi->dev.kobj, ts->attr_group); + if (err) + goto err_free_irq; err = input_register_device(input_dev); if (err) - goto err_remove_attr; + goto err_remove_attr_group; return 0; - err_remove_attr: - device_remove_file(&spi->dev, &dev_attr_disable); - device_remove_file(&spi->dev, &dev_attr_pen_down); - if (ts->model == 7846) { - device_remove_file(&spi->dev, &dev_attr_temp1); - device_remove_file(&spi->dev, &dev_attr_temp0); - } - if (ts->model != 7845) - device_remove_file(&spi->dev, &dev_attr_vbatt); - device_remove_file(&spi->dev, &dev_attr_vaux); - + err_remove_attr_group: + sysfs_remove_group(&spi->dev.kobj, ts->attr_group); + err_free_irq: free_irq(spi->irq, ts); err_free_mem: input_free_device(input_dev); @@ -835,15 +870,7 @@ static int __devexit ads7846_remove(struct spi_device *spi) ads7846_suspend(spi, PMSG_SUSPEND); - device_remove_file(&spi->dev, &dev_attr_disable); - device_remove_file(&spi->dev, &dev_attr_pen_down); - if (ts->model == 7846) { - device_remove_file(&spi->dev, &dev_attr_temp1); - device_remove_file(&spi->dev, &dev_attr_temp0); - } - if (ts->model != 7845) - device_remove_file(&spi->dev, &dev_attr_vbatt); - device_remove_file(&spi->dev, &dev_attr_vaux); + sysfs_remove_group(&spi->dev.kobj, ts->attr_group); free_irq(ts->spi->irq, ts); /* suspend left the IRQ disabled */ diff --git a/drivers/input/touchscreen/corgi_ts.c b/drivers/input/touchscreen/corgi_ts.c index 66121f6a89ad..e2945582828e 100644 --- a/drivers/input/touchscreen/corgi_ts.c +++ b/drivers/input/touchscreen/corgi_ts.c @@ -175,17 +175,19 @@ static int read_xydata(struct corgi_ts *corgi_ts) static void new_data(struct corgi_ts *corgi_ts) { + struct input_dev *dev = corgi_ts->input; + if (corgi_ts->power_mode != PWR_MODE_ACTIVE) return; if (!corgi_ts->tc.pressure && corgi_ts->pendown == 0) return; - input_report_abs(corgi_ts->input, ABS_X, corgi_ts->tc.x); - input_report_abs(corgi_ts->input, ABS_Y, corgi_ts->tc.y); - input_report_abs(corgi_ts->input, ABS_PRESSURE, corgi_ts->tc.pressure); - input_report_key(corgi_ts->input, BTN_TOUCH, (corgi_ts->pendown != 0)); - input_sync(corgi_ts->input); + input_report_abs(dev, ABS_X, corgi_ts->tc.x); + input_report_abs(dev, ABS_Y, corgi_ts->tc.y); + input_report_abs(dev, ABS_PRESSURE, corgi_ts->tc.pressure); + input_report_key(dev, BTN_TOUCH, corgi_ts->pendown); + input_sync(dev); } static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer) @@ -219,12 +221,14 @@ static void ts_interrupt_main(struct corgi_ts *corgi_ts, int isTimer) static void corgi_ts_timer(unsigned long data) { struct corgi_ts *corgits_data = (struct corgi_ts *) data; + ts_interrupt_main(corgits_data, 1); } static irqreturn_t ts_interrupt(int irq, void *dev_id) { struct corgi_ts *corgits_data = dev_id; + ts_interrupt_main(corgits_data, 0); return IRQ_HANDLED; } @@ -272,7 +276,7 @@ static int __init corgits_probe(struct platform_device *pdev) corgi_ts = kzalloc(sizeof(struct corgi_ts), GFP_KERNEL); input_dev = input_allocate_device(); if (!corgi_ts || !input_dev) - goto fail; + goto fail1; platform_set_drvdata(pdev, corgi_ts); @@ -281,7 +285,7 @@ static int __init corgits_probe(struct platform_device *pdev) if (corgi_ts->irq_gpio < 0) { err = -ENODEV; - goto fail; + goto fail1; } corgi_ts->input = input_dev; @@ -319,10 +323,12 @@ static int __init corgits_probe(struct platform_device *pdev) if (request_irq(corgi_ts->irq_gpio, ts_interrupt, IRQF_DISABLED, "ts", corgi_ts)) { err = -EBUSY; - goto fail; + goto fail1; } - input_register_device(corgi_ts->input); + err = input_register_device(corgi_ts->input); + if (err) + goto fail2; corgi_ts->power_mode = PWR_MODE_ACTIVE; @@ -331,17 +337,17 @@ static int __init corgits_probe(struct platform_device *pdev) return 0; - fail: input_free_device(input_dev); + fail2: free_irq(corgi_ts->irq_gpio, corgi_ts); + fail1: input_free_device(input_dev); kfree(corgi_ts); return err; - } static int corgits_remove(struct platform_device *pdev) { struct corgi_ts *corgi_ts = platform_get_drvdata(pdev); - free_irq(corgi_ts->irq_gpio, NULL); + free_irq(corgi_ts->irq_gpio, corgi_ts); del_timer_sync(&corgi_ts->timer); corgi_ts->machinfo->put_hsync(); input_unregister_device(corgi_ts->input); diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c index 913e1b73bb0e..9d61cd133d01 100644 --- a/drivers/input/touchscreen/elo.c +++ b/drivers/input/touchscreen/elo.c @@ -397,8 +397,7 @@ static struct serio_driver elo_drv = { static int __init elo_init(void) { - serio_register_driver(&elo_drv); - return 0; + return serio_register_driver(&elo_drv); } static void __exit elo_exit(void) diff --git a/drivers/input/touchscreen/gunze.c b/drivers/input/touchscreen/gunze.c index 817c2198933d..9157eb148e84 100644 --- a/drivers/input/touchscreen/gunze.c +++ b/drivers/input/touchscreen/gunze.c @@ -123,7 +123,7 @@ static int gunze_connect(struct serio *serio, struct serio_driver *drv) input_dev = input_allocate_device(); if (!gunze || !input_dev) { err = -ENOMEM; - goto fail; + goto fail1; } gunze->serio = serio; @@ -146,13 +146,17 @@ static int gunze_connect(struct serio *serio, struct serio_driver *drv) err = serio_open(serio, drv); if (err) - goto fail; + goto fail2; + + err = input_register_device(gunze->dev); + if (err) + goto fail3; - input_register_device(gunze->dev); return 0; - fail: serio_set_drvdata(serio, NULL); - input_free_device(input_dev); + fail3: serio_close(serio); + fail2: serio_set_drvdata(serio, NULL); + fail1: input_free_device(input_dev); kfree(gunze); return err; } @@ -190,8 +194,7 @@ static struct serio_driver gunze_drv = { static int __init gunze_init(void) { - serio_register_driver(&gunze_drv); - return 0; + return serio_register_driver(&gunze_drv); } static void __exit gunze_exit(void) diff --git a/drivers/input/touchscreen/h3600_ts_input.c b/drivers/input/touchscreen/h3600_ts_input.c index d9e61ee05ea9..c4116d4f64e7 100644 --- a/drivers/input/touchscreen/h3600_ts_input.c +++ b/drivers/input/touchscreen/h3600_ts_input.c @@ -478,8 +478,7 @@ static struct serio_driver h3600ts_drv = { static int __init h3600ts_init(void) { - serio_register_driver(&h3600ts_drv); - return 0; + return serio_register_driver(&h3600ts_drv); } static void __exit h3600ts_exit(void) diff --git a/drivers/input/touchscreen/hp680_ts_input.c b/drivers/input/touchscreen/hp680_ts_input.c index 58fca316786c..249087472740 100644 --- a/drivers/input/touchscreen/hp680_ts_input.c +++ b/drivers/input/touchscreen/hp680_ts_input.c @@ -76,38 +76,47 @@ static irqreturn_t hp680_ts_interrupt(int irq, void *dev) static int __init hp680_ts_init(void) { + int err; + hp680_ts_dev = input_allocate_device(); if (!hp680_ts_dev) return -ENOMEM; hp680_ts_dev->evbit[0] = BIT(EV_ABS) | BIT(EV_KEY); - hp680_ts_dev->absbit[0] = BIT(ABS_X) | BIT(ABS_Y); hp680_ts_dev->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); - hp680_ts_dev->absmin[ABS_X] = HP680_TS_ABS_X_MIN; - hp680_ts_dev->absmin[ABS_Y] = HP680_TS_ABS_Y_MIN; - hp680_ts_dev->absmax[ABS_X] = HP680_TS_ABS_X_MAX; - hp680_ts_dev->absmax[ABS_Y] = HP680_TS_ABS_Y_MAX; + input_set_abs_params(hp680_ts_dev, ABS_X, + HP680_TS_ABS_X_MIN, HP680_TS_ABS_X_MAX, 0, 0); + input_set_abs_params(hp680_ts_dev, ABS_Y, + HP680_TS_ABS_Y_MIN, HP680_TS_ABS_Y_MAX, 0, 0); hp680_ts_dev->name = "HP Jornada touchscreen"; hp680_ts_dev->phys = "hp680_ts/input0"; - input_register_device(hp680_ts_dev); - if (request_irq(HP680_TS_IRQ, hp680_ts_interrupt, IRQF_DISABLED, MODNAME, 0) < 0) { printk(KERN_ERR "hp680_touchscreen.c: Can't allocate irq %d\n", HP680_TS_IRQ); - input_unregister_device(hp680_ts_dev); - return -EBUSY; + err = -EBUSY; + goto fail1; } + err = input_register_device(hp680_ts_dev); + if (err) + goto fail2; + return 0; + + fail2: free_irq(HP680_TS_IRQ, NULL); + cancel_delayed_work(&work); + flush_scheduled_work(); + fail1: input_free_device(hp680_ts_dev); + return err; } static void __exit hp680_ts_exit(void) { - free_irq(HP680_TS_IRQ, 0); + free_irq(HP680_TS_IRQ, NULL); cancel_delayed_work(&work); flush_scheduled_work(); input_unregister_device(hp680_ts_dev); diff --git a/drivers/input/touchscreen/mk712.c b/drivers/input/touchscreen/mk712.c index 4cbcaa6a71e5..44140feeffc5 100644 --- a/drivers/input/touchscreen/mk712.c +++ b/drivers/input/touchscreen/mk712.c @@ -96,15 +96,13 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id) goto end; } - if (~status & MK712_STATUS_TOUCH) - { + if (~status & MK712_STATUS_TOUCH) { debounce = 1; input_report_key(mk712_dev, BTN_TOUCH, 0); goto end; } - if (debounce) - { + if (debounce) { debounce = 0; goto end; } @@ -113,8 +111,7 @@ static irqreturn_t mk712_interrupt(int irq, void *dev_id) input_report_abs(mk712_dev, ABS_X, last_x); input_report_abs(mk712_dev, ABS_Y, last_y); -end: - + end: last_x = inw(mk712_io + MK712_X) & 0x0fff; last_y = inw(mk712_io + MK712_Y) & 0x0fff; input_sync(mk712_dev); @@ -169,13 +166,14 @@ static int __init mk712_init(void) (inw(mk712_io + MK712_STATUS) & 0xf333)) { printk(KERN_WARNING "mk712: device not present\n"); err = -ENODEV; - goto fail; + goto fail1; } - if (!(mk712_dev = input_allocate_device())) { + mk712_dev = input_allocate_device(); + if (!mk712_dev) { printk(KERN_ERR "mk712: not enough memory\n"); err = -ENOMEM; - goto fail; + goto fail1; } mk712_dev->name = "ICS MicroClock MK712 TouchScreen"; @@ -196,13 +194,17 @@ static int __init mk712_init(void) if (request_irq(mk712_irq, mk712_interrupt, 0, "mk712", mk712_dev)) { printk(KERN_WARNING "mk712: unable to get IRQ\n"); err = -EBUSY; - goto fail; + goto fail1; } - input_register_device(mk712_dev); + err = input_register_device(mk712_dev); + if (err) + goto fail2; + return 0; - fail: input_free_device(mk712_dev); + fail2: free_irq(mk712_irq, mk712_dev); + fail1: input_free_device(mk712_dev); release_region(mk712_io, 8); return err; } diff --git a/drivers/input/touchscreen/mtouch.c b/drivers/input/touchscreen/mtouch.c index 3b4c61664b63..c3c2d735d0ec 100644 --- a/drivers/input/touchscreen/mtouch.c +++ b/drivers/input/touchscreen/mtouch.c @@ -137,7 +137,7 @@ static int mtouch_connect(struct serio *serio, struct serio_driver *drv) input_dev = input_allocate_device(); if (!mtouch || !input_dev) { err = -ENOMEM; - goto fail; + goto fail1; } mtouch->serio = serio; @@ -160,14 +160,17 @@ static int mtouch_connect(struct serio *serio, struct serio_driver *drv) err = serio_open(serio, drv); if (err) - goto fail; + goto fail2; - input_register_device(mtouch->dev); + err = input_register_device(mtouch->dev); + if (err) + goto fail3; return 0; - fail: serio_set_drvdata(serio, NULL); - input_free_device(input_dev); + fail3: serio_close(serio); + fail2: serio_set_drvdata(serio, NULL); + fail1: input_free_device(input_dev); kfree(mtouch); return err; } @@ -205,8 +208,7 @@ static struct serio_driver mtouch_drv = { static int __init mtouch_init(void) { - serio_register_driver(&mtouch_drv); - return 0; + return serio_register_driver(&mtouch_drv); } static void __exit mtouch_exit(void) diff --git a/drivers/input/touchscreen/penmount.c b/drivers/input/touchscreen/penmount.c index 6c7d0c2c76cc..bd2767991ae9 100644 --- a/drivers/input/touchscreen/penmount.c +++ b/drivers/input/touchscreen/penmount.c @@ -171,8 +171,7 @@ static struct serio_driver pm_drv = { static int __init pm_init(void) { - serio_register_driver(&pm_drv); - return 0; + return serio_register_driver(&pm_drv); } static void __exit pm_exit(void) diff --git a/drivers/input/touchscreen/touchright.c b/drivers/input/touchscreen/touchright.c index c74f74e57af0..35ba46c6ad2d 100644 --- a/drivers/input/touchscreen/touchright.c +++ b/drivers/input/touchscreen/touchright.c @@ -182,8 +182,7 @@ static struct serio_driver tr_drv = { static int __init tr_init(void) { - serio_register_driver(&tr_drv); - return 0; + return serio_register_driver(&tr_drv); } static void __exit tr_exit(void) diff --git a/drivers/input/touchscreen/touchwin.c b/drivers/input/touchscreen/touchwin.c index 9911820fa2fe..4dc073dacabb 100644 --- a/drivers/input/touchscreen/touchwin.c +++ b/drivers/input/touchscreen/touchwin.c @@ -189,8 +189,7 @@ static struct serio_driver tw_drv = { static int __init tw_init(void) { - serio_register_driver(&tw_drv); - return 0; + return serio_register_driver(&tw_drv); } static void __exit tw_exit(void) diff --git a/drivers/input/touchscreen/ucb1400_ts.c b/drivers/input/touchscreen/ucb1400_ts.c new file mode 100644 index 000000000000..6ef08369f65b --- /dev/null +++ b/drivers/input/touchscreen/ucb1400_ts.c @@ -0,0 +1,579 @@ +/* + * Philips UCB1400 touchscreen driver + * + * Author: Nicolas Pitre + * Created: September 25, 2006 + * Copyright: MontaVista Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This code is heavily based on ucb1x00-*.c copyrighted by Russell King + * covering the UCB1100, UCB1200 and UCB1300.. Support for the UCB1400 has + * been made separate from ucb1x00-core/ucb1x00-ts on Russell's request. + */ + +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/init.h> +#include <linux/sched.h> +#include <linux/completion.h> +#include <linux/delay.h> +#include <linux/input.h> +#include <linux/device.h> +#include <linux/interrupt.h> +#include <linux/suspend.h> +#include <linux/slab.h> +#include <linux/kthread.h> + +#include <sound/driver.h> +#include <sound/core.h> +#include <sound/ac97_codec.h> + + +/* + * Interesting UCB1400 AC-link registers + */ + +#define UCB_IE_RIS 0x5e +#define UCB_IE_FAL 0x60 +#define UCB_IE_STATUS 0x62 +#define UCB_IE_CLEAR 0x62 +#define UCB_IE_ADC (1 << 11) +#define UCB_IE_TSPX (1 << 12) + +#define UCB_TS_CR 0x64 +#define UCB_TS_CR_TSMX_POW (1 << 0) +#define UCB_TS_CR_TSPX_POW (1 << 1) +#define UCB_TS_CR_TSMY_POW (1 << 2) +#define UCB_TS_CR_TSPY_POW (1 << 3) +#define UCB_TS_CR_TSMX_GND (1 << 4) +#define UCB_TS_CR_TSPX_GND (1 << 5) +#define UCB_TS_CR_TSMY_GND (1 << 6) +#define UCB_TS_CR_TSPY_GND (1 << 7) +#define UCB_TS_CR_MODE_INT (0 << 8) +#define UCB_TS_CR_MODE_PRES (1 << 8) +#define UCB_TS_CR_MODE_POS (2 << 8) +#define UCB_TS_CR_BIAS_ENA (1 << 11) +#define UCB_TS_CR_TSPX_LOW (1 << 12) +#define UCB_TS_CR_TSMX_LOW (1 << 13) + +#define UCB_ADC_CR 0x66 +#define UCB_ADC_SYNC_ENA (1 << 0) +#define UCB_ADC_VREFBYP_CON (1 << 1) +#define UCB_ADC_INP_TSPX (0 << 2) +#define UCB_ADC_INP_TSMX (1 << 2) +#define UCB_ADC_INP_TSPY (2 << 2) +#define UCB_ADC_INP_TSMY (3 << 2) +#define UCB_ADC_INP_AD0 (4 << 2) +#define UCB_ADC_INP_AD1 (5 << 2) +#define UCB_ADC_INP_AD2 (6 << 2) +#define UCB_ADC_INP_AD3 (7 << 2) +#define UCB_ADC_EXT_REF (1 << 5) +#define UCB_ADC_START (1 << 7) +#define UCB_ADC_ENA (1 << 15) + +#define UCB_ADC_DATA 0x68 +#define UCB_ADC_DAT_VALID (1 << 15) +#define UCB_ADC_DAT_VALUE(x) ((x) & 0x3ff) + +#define UCB_ID 0x7e +#define UCB_ID_1400 0x4304 + + +struct ucb1400 { + ac97_t *ac97; + struct input_dev *ts_idev; + + int irq; + + wait_queue_head_t ts_wait; + struct task_struct *ts_task; + + unsigned int irq_pending; /* not bit field shared */ + unsigned int ts_restart:1; + unsigned int adcsync:1; +}; + +static int adcsync; + +static inline u16 ucb1400_reg_read(struct ucb1400 *ucb, u16 reg) +{ + return ucb->ac97->bus->ops->read(ucb->ac97, reg); +} + +static inline void ucb1400_reg_write(struct ucb1400 *ucb, u16 reg, u16 val) +{ + ucb->ac97->bus->ops->write(ucb->ac97, reg, val); +} + +static inline void ucb1400_adc_enable(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); +} + +static unsigned int ucb1400_adc_read(struct ucb1400 *ucb, u16 adc_channel) +{ + unsigned int val; + + if (ucb->adcsync) + adc_channel |= UCB_ADC_SYNC_ENA; + + ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | adc_channel); + ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | adc_channel | UCB_ADC_START); + + for (;;) { + val = ucb1400_reg_read(ucb, UCB_ADC_DATA); + if (val & UCB_ADC_DAT_VALID) + break; + /* yield to other processes */ + set_current_state(TASK_INTERRUPTIBLE); + schedule_timeout(1); + } + + return UCB_ADC_DAT_VALUE(val); +} + +static inline void ucb1400_adc_disable(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_ADC_CR, 0); +} + +/* Switch to interrupt mode. */ +static inline void ucb1400_ts_mode_int(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW | + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND | + UCB_TS_CR_MODE_INT); +} + +/* + * Switch to pressure mode, and read pressure. We don't need to wait + * here, since both plates are being driven. + */ +static inline unsigned int ucb1400_ts_read_pressure(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMX_POW | UCB_TS_CR_TSPX_POW | + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_GND | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPY); +} + +/* + * Switch to X position mode and measure Y plate. We switch the plate + * configuration in pressure mode, then switch to position mode. This + * gives a faster response time. Even so, we need to wait about 55us + * for things to stabilise. + */ +static inline unsigned int ucb1400_ts_read_xpos(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | + UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); + + udelay(55); + + return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPY); +} + +/* + * Switch to Y position mode and measure X plate. We switch the plate + * configuration in pressure mode, then switch to position mode. This + * gives a faster response time. Even so, we need to wait about 55us + * for things to stabilise. + */ +static inline unsigned int ucb1400_ts_read_ypos(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | + UCB_TS_CR_MODE_POS | UCB_TS_CR_BIAS_ENA); + + udelay(55); + + return ucb1400_adc_read(ucb, UCB_ADC_INP_TSPX); +} + +/* + * Switch to X plate resistance mode. Set MX to ground, PX to + * supply. Measure current. + */ +static inline unsigned int ucb1400_ts_read_xres(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMX_GND | UCB_TS_CR_TSPX_POW | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + return ucb1400_adc_read(ucb, 0); +} + +/* + * Switch to Y plate resistance mode. Set MY to ground, PY to + * supply. Measure current. + */ +static inline unsigned int ucb1400_ts_read_yres(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_TS_CR, + UCB_TS_CR_TSMY_GND | UCB_TS_CR_TSPY_POW | + UCB_TS_CR_MODE_PRES | UCB_TS_CR_BIAS_ENA); + return ucb1400_adc_read(ucb, 0); +} + +static inline int ucb1400_ts_pen_down(struct ucb1400 *ucb) +{ + unsigned short val = ucb1400_reg_read(ucb, UCB_TS_CR); + return (val & (UCB_TS_CR_TSPX_LOW | UCB_TS_CR_TSMX_LOW)); +} + +static inline void ucb1400_ts_irq_enable(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_IE_CLEAR, UCB_IE_TSPX); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); + ucb1400_reg_write(ucb, UCB_IE_FAL, UCB_IE_TSPX); +} + +static inline void ucb1400_ts_irq_disable(struct ucb1400 *ucb) +{ + ucb1400_reg_write(ucb, UCB_IE_FAL, 0); +} + +static void ucb1400_ts_evt_add(struct input_dev *idev, u16 pressure, u16 x, u16 y) +{ + input_report_abs(idev, ABS_X, x); + input_report_abs(idev, ABS_Y, y); + input_report_abs(idev, ABS_PRESSURE, pressure); + input_sync(idev); +} + +static void ucb1400_ts_event_release(struct input_dev *idev) +{ + input_report_abs(idev, ABS_PRESSURE, 0); + input_sync(idev); +} + +static void ucb1400_handle_pending_irq(struct ucb1400 *ucb) +{ + unsigned int isr; + + isr = ucb1400_reg_read(ucb, UCB_IE_STATUS); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, isr); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); + + if (isr & UCB_IE_TSPX) + ucb1400_ts_irq_disable(ucb); + else + printk(KERN_ERR "ucb1400: unexpected IE_STATUS = %#x\n", isr); + + enable_irq(ucb->irq); +} + +static int ucb1400_ts_thread(void *_ucb) +{ + struct ucb1400 *ucb = _ucb; + struct task_struct *tsk = current; + int valid = 0; + + tsk->policy = SCHED_FIFO; + tsk->rt_priority = 1; + + while (!kthread_should_stop()) { + unsigned int x, y, p; + long timeout; + + ucb->ts_restart = 0; + + if (ucb->irq_pending) { + ucb->irq_pending = 0; + ucb1400_handle_pending_irq(ucb); + } + + ucb1400_adc_enable(ucb); + x = ucb1400_ts_read_xpos(ucb); + y = ucb1400_ts_read_ypos(ucb); + p = ucb1400_ts_read_pressure(ucb); + ucb1400_adc_disable(ucb); + + /* Switch back to interrupt mode. */ + ucb1400_ts_mode_int(ucb); + + msleep(10); + + if (ucb1400_ts_pen_down(ucb)) { + ucb1400_ts_irq_enable(ucb); + + /* + * If we spat out a valid sample set last time, + * spit out a "pen off" sample here. + */ + if (valid) { + ucb1400_ts_event_release(ucb->ts_idev); + valid = 0; + } + + timeout = MAX_SCHEDULE_TIMEOUT; + } else { + valid = 1; + ucb1400_ts_evt_add(ucb->ts_idev, p, x, y); + timeout = msecs_to_jiffies(10); + } + + wait_event_interruptible_timeout(ucb->ts_wait, + ucb->irq_pending || ucb->ts_restart || kthread_should_stop(), + timeout); + try_to_freeze(); + } + + /* Send the "pen off" if we are stopping with the pen still active */ + if (valid) + ucb1400_ts_event_release(ucb->ts_idev); + + ucb->ts_task = NULL; + return 0; +} + +/* + * A restriction with interrupts exists when using the ucb1400, as + * the codec read/write routines may sleep while waiting for codec + * access completion and uses semaphores for access control to the + * AC97 bus. A complete codec read cycle could take anywhere from + * 60 to 100uSec so we *definitely* don't want to spin inside the + * interrupt handler waiting for codec access. So, we handle the + * interrupt by scheduling a RT kernel thread to run in process + * context instead of interrupt context. + */ +static irqreturn_t ucb1400_hard_irq(int irqnr, void *devid) +{ + struct ucb1400 *ucb = devid; + + if (irqnr == ucb->irq) { + disable_irq(ucb->irq); + ucb->irq_pending = 1; + wake_up(&ucb->ts_wait); + return IRQ_HANDLED; + } + return IRQ_NONE; +} + +static int ucb1400_ts_open(struct input_dev *idev) +{ + struct ucb1400 *ucb = idev->private; + int ret = 0; + + BUG_ON(ucb->ts_task); + + ucb->ts_task = kthread_run(ucb1400_ts_thread, ucb, "UCB1400_ts"); + if (IS_ERR(ucb->ts_task)) { + ret = PTR_ERR(ucb->ts_task); + ucb->ts_task = NULL; + } + + return ret; +} + +static void ucb1400_ts_close(struct input_dev *idev) +{ + struct ucb1400 *ucb = idev->private; + + if (ucb->ts_task) + kthread_stop(ucb->ts_task); + + ucb1400_ts_irq_disable(ucb); + ucb1400_reg_write(ucb, UCB_TS_CR, 0); +} + +#ifdef CONFIG_PM +static int ucb1400_ts_resume(struct device *dev) +{ + struct ucb1400 *ucb = dev_get_drvdata(dev); + + if (ucb->ts_task) { + /* + * Restart the TS thread to ensure the + * TS interrupt mode is set up again + * after sleep. + */ + ucb->ts_restart = 1; + wake_up(&ucb->ts_wait); + } + return 0; +} +#else +#define ucb1400_ts_resume NULL +#endif + +#ifndef NO_IRQ +#define NO_IRQ 0 +#endif + +/* + * Try to probe our interrupt, rather than relying on lots of + * hard-coded machine dependencies. + */ +static int ucb1400_detect_irq(struct ucb1400 *ucb) +{ + unsigned long mask, timeout; + + mask = probe_irq_on(); + if (!mask) { + probe_irq_off(mask); + return -EBUSY; + } + + /* Enable the ADC interrupt. */ + ucb1400_reg_write(ucb, UCB_IE_RIS, UCB_IE_ADC); + ucb1400_reg_write(ucb, UCB_IE_FAL, UCB_IE_ADC); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0xffff); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); + + /* Cause an ADC interrupt. */ + ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA); + ucb1400_reg_write(ucb, UCB_ADC_CR, UCB_ADC_ENA | UCB_ADC_START); + + /* Wait for the conversion to complete. */ + timeout = jiffies + HZ/2; + while (!(ucb1400_reg_read(ucb, UCB_ADC_DATA) & UCB_ADC_DAT_VALID)) { + cpu_relax(); + if (time_after(jiffies, timeout)) { + printk(KERN_ERR "ucb1400: timed out in IRQ probe\n"); + probe_irq_off(mask); + return -ENODEV; + } + } + ucb1400_reg_write(ucb, UCB_ADC_CR, 0); + + /* Disable and clear interrupt. */ + ucb1400_reg_write(ucb, UCB_IE_RIS, 0); + ucb1400_reg_write(ucb, UCB_IE_FAL, 0); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0xffff); + ucb1400_reg_write(ucb, UCB_IE_CLEAR, 0); + + /* Read triggered interrupt. */ + ucb->irq = probe_irq_off(mask); + if (ucb->irq < 0 || ucb->irq == NO_IRQ) + return -ENODEV; + + return 0; +} + +static int ucb1400_ts_probe(struct device *dev) +{ + struct ucb1400 *ucb; + struct input_dev *idev; + int error, id, x_res, y_res; + + ucb = kzalloc(sizeof(struct ucb1400), GFP_KERNEL); + idev = input_allocate_device(); + if (!ucb || !idev) { + error = -ENOMEM; + goto err_free_devs; + } + + ucb->ts_idev = idev; + ucb->adcsync = adcsync; + ucb->ac97 = to_ac97_t(dev); + init_waitqueue_head(&ucb->ts_wait); + + id = ucb1400_reg_read(ucb, UCB_ID); + if (id != UCB_ID_1400) { + error = -ENODEV; + goto err_free_devs; + } + + error = ucb1400_detect_irq(ucb); + if (error) { + printk(KERN_ERR "UCB1400: IRQ probe failed\n"); + goto err_free_devs; + } + + error = request_irq(ucb->irq, ucb1400_hard_irq, IRQF_TRIGGER_RISING, + "UCB1400", ucb); + if (error) { + printk(KERN_ERR "ucb1400: unable to grab irq%d: %d\n", + ucb->irq, error); + goto err_free_devs; + } + printk(KERN_DEBUG "UCB1400: found IRQ %d\n", ucb->irq); + + idev->private = ucb; + idev->cdev.dev = dev; + idev->name = "UCB1400 touchscreen interface"; + idev->id.vendor = ucb1400_reg_read(ucb, AC97_VENDOR_ID1); + idev->id.product = id; + idev->open = ucb1400_ts_open; + idev->close = ucb1400_ts_close; + idev->evbit[0] = BIT(EV_ABS); + + ucb1400_adc_enable(ucb); + x_res = ucb1400_ts_read_xres(ucb); + y_res = ucb1400_ts_read_yres(ucb); + ucb1400_adc_disable(ucb); + printk(KERN_DEBUG "UCB1400: x/y = %d/%d\n", x_res, y_res); + + input_set_abs_params(idev, ABS_X, 0, x_res, 0, 0); + input_set_abs_params(idev, ABS_Y, 0, y_res, 0, 0); + input_set_abs_params(idev, ABS_PRESSURE, 0, 0, 0, 0); + + error = input_register_device(idev); + if (error) + goto err_free_irq; + + dev_set_drvdata(dev, ucb); + return 0; + + err_free_irq: + free_irq(ucb->irq, ucb); + err_free_devs: + input_free_device(idev); + kfree(ucb); + return error; +} + +static int ucb1400_ts_remove(struct device *dev) +{ + struct ucb1400 *ucb = dev_get_drvdata(dev); + + free_irq(ucb->irq, ucb); + input_unregister_device(ucb->ts_idev); + dev_set_drvdata(dev, NULL); + kfree(ucb); + return 0; +} + +static struct device_driver ucb1400_ts_driver = { + .owner = THIS_MODULE, + .bus = &ac97_bus_type, + .probe = ucb1400_ts_probe, + .remove = ucb1400_ts_remove, + .resume = ucb1400_ts_resume, +}; + +static int __init ucb1400_ts_init(void) +{ + return driver_register(&ucb1400_ts_driver); +} + +static void __exit ucb1400_ts_exit(void) +{ + driver_unregister(&ucb1400_ts_driver); +} + +module_param(adcsync, int, 0444); + +module_init(ucb1400_ts_init); +module_exit(ucb1400_ts_exit); + +MODULE_DESCRIPTION("Philips UCB1400 touchscreen driver"); +MODULE_LICENSE("GPL"); |