From: <cri...@us...> - 2006-08-26 15:51:20
|
Revision: 558 Author: cristianop Date: 2006-08-26 08:51:13 -0700 (Sat, 26 Aug 2006) ViewCVS: http://svn.sourceforge.net/hackndev/?rev=558&view=rev Log Message: ----------- palmtx: handling jitter with input's absfuzz Modified Paths: -------------- linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c Modified: linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c =================================================================== --- linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c 2006-08-26 13:58:50 UTC (rev 557) +++ linux4palm/linux/trunk/arch/arm/mach-pxa/palmtx/palmld_ac97.c 2006-08-26 15:51:13 UTC (rev 558) @@ -36,23 +36,22 @@ #include <sound/initval.h> #include <sound/ac97_codec.h> - -#define X_AXIS_MAX 3630 //3900 //3630 -#define X_AXIS_MIN 200 //350 //200 -#define Y_AXIS_MAX 3880 //3750 //3880 -#define Y_AXIS_MIN 160 //320 //160 +#define X_AXIS_MAX 3900 //3630 +#define X_AXIS_MIN 350 //200 +#define Y_AXIS_MAX 3750 //3880 +#define Y_AXIS_MIN 320 //160 #define PRESSURE_MIN 0 #define PRESSURE_MAX 150 //300 #define DIG2_INIT 0x0001 /* initial value for digitiser2 register */ -#define WM9712_PIL 0x00100 -#define WM97XX_POLL 0x8000 /* initiate a polling measurement */ -#define AC97_LINK_FRAME 21 /* time in uS for AC97 link frame */ -#define DEFAULT_PRESSURE_TRESHOLD 45160 /* default pressure treshold for pen up/down */ -#define DEFAULT_X_JITTER_TRESHOLD 5; -#define DEFAULT_Y_JITTER_TRESHOLD 35; +#define AC97_LINK_FRAME 21 /* time in uS for AC97 link frame */ +#define DEFAULT_PRESSURE_TRESHOLD 45160 /* default pressure treshold for pen up/down */ +#define DEFAULT_X_AXIS_FUZZ 5 /* default x axis noise treshold */ +#define DEFAULT_Y_AXIS_FUZZ 35 /* default y axis noise treshold */ +#define PRESSURE_FUZZ 5 /* default pressure noise treshold */ + #define palmld_ac97_WORK_QUEUE_NAME "palmld_ac97.c" @@ -64,19 +63,18 @@ module_param(dbglvl, int, 0); MODULE_PARM_DESC(dbglvl, "debug level (0 is disabled)"); -static int xdjtrsh = DEFAULT_X_JITTER_TRESHOLD; +static int xdjtrsh = DEFAULT_X_AXIS_FUZZ; module_param(xdjtrsh, int, 0); -MODULE_PARM_DESC(xdjtrsh, "treshold for x coordinates jitter"); +MODULE_PARM_DESC(xdjtrsh, "treshold for x axis jitter"); -static int ydjtrsh = DEFAULT_Y_JITTER_TRESHOLD; +static int ydjtrsh = DEFAULT_Y_AXIS_FUZZ; module_param(ydjtrsh, int, 0); -MODULE_PARM_DESC(ydjtrsh, "treshold for y coordinates jitter"); +MODULE_PARM_DESC(ydjtrsh, "treshold for y axis jitter"); static DECLARE_MUTEX_LOCKED(queue_sem); static DECLARE_MUTEX(digitiser_sem); static DECLARE_MUTEX(battery_update_mutex); - static struct workqueue_struct *palmld_ac97_workqueue; static struct work_struct palmld_ac97_irq_task; @@ -88,8 +86,6 @@ static int previous_voltage; static u16 d2base; -static int lastx = 0; -static int lasty = 0; #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE) /* original APM hook */ @@ -111,7 +107,8 @@ GEn &= ~gpio; ac97->bus->ops->write(ac97, 0x56, GEn); } - + + void wm97xx_gpio_mode(ac97_t *ac97, int gpio, int config, int polarity, int sticky, int wakeup) { @@ -147,15 +144,15 @@ ac97->bus->ops->write(ac97, 0x52, GWn); } + static void wm97xx_set_digitiser_power(struct device *dev, int value) { ac97_t *ac97 = dev->platform_data; - u16 d2 = d2base; - - d2 |= value; - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2); + + ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base | value); } + /* * note: for the TX there's some code that gets enabled in linux/sound/pxa2xx-ac97.c * (ifdef CONFIG_MACH_PALMTX) that tries to implement some recommended procedure for @@ -163,7 +160,6 @@ * (PXA27x Specification Update: 28007109.pdf sec.: E54) */ - static int palmld_ac97_take_reading(struct device *dev, int adcsel) { ac97_t *ac97 = dev->platform_data; @@ -171,33 +167,34 @@ u16 r76 = 0; u16 r7a; - r76 |= adcsel; /* set ADCSEL */ - r76 |= WM97XX_DELAY(3); /* set DELAY */ - r76 &= ~(1<<11); /* COO = 0 (single measurement) */ - r76 &= ~(1<<10); /* CTC = 0 (polling mode) */ - r76 |= (1<<15); /* start reading */ + r76 |= adcsel; /* set ADCSEL (ADC source) */ + r76 |= WM97XX_DELAY(3); /* set settling time delay DELAY */ + r76 &= ~(1<<11); /* COO = 0 (single measurement) */ + r76 &= ~(1<<10); /* CTC = 0 (polling mode) */ + r76 |= (1<<15); /* initiate measurement (POLL) */ ac97->bus->ops->write(ac97, 0x76, r76); - // some code from the the wolfson' driver + // wait settling time udelay ((3 * AC97_LINK_FRAME) + 167); /* wait for POLL to go low */ - while((ac97->bus->ops->read(ac97, 0x76) & 0x8000) && timeout){ udelay(AC97_LINK_FRAME); timeout--; } if (timeout == 0){ - printk("wm9712: discarding reading due to poll wait timout on 0x76\n"); + printk("wm9712: discarding reading due to POLL wait timout on 0x76\n"); return 0; } r7a = ac97->bus->ops->read(ac97, 0x7a); - // todo: print an error here - if ((r7a & WM97XX_ADCSEL_MASK) != adcsel) + + if ((r7a & WM97XX_ADCSEL_MASK) != adcsel){ + printk("wm9712: discarding reading -> wrong ADC source\n"); return 0; - + } + return (int) r7a; } @@ -255,14 +252,17 @@ { return PALMTX_BAT_MIN_VOLTAGE; } + int get_min_charge(struct battery *b) { return PALMTX_BAT_MIN_CHARGE; } + int get_max_voltage(struct battery *b) { return PALMTX_BAT_MAX_VOLTAGE; /* mV */ } + int get_max_charge(struct battery *b) { return PALMTX_BAT_MAX_CHARGE; @@ -280,6 +280,7 @@ { return 0; } + int get_status(struct battery *b) { int ac_connected = 0; @@ -342,7 +343,6 @@ static void palmld_ac97_pendown(struct device *dev) { int xread, yread, pressure; - int xval, yval; int valid_coords=0, btn_pressed = 0; /* take readings until the pen goes up */ @@ -352,22 +352,15 @@ yread = palmld_ac97_take_reading(dev, WM97XX_ADCSEL_Y); pressure = palmld_ac97_take_reading(dev, WM97XX_ADCSEL_PRES); - //valid_coords = (xread & 0xfff) && (yread & 0xfff) && (pressure & 0xfff); - xval = xread & 0xfff; - yval = yread & 0xfff; - valid_coords = (xval) && (yval) && (pressure & 0xfff); + valid_coords = (xread & 0xfff) && (yread & 0xfff) && (pressure & 0xfff); if(valid_coords && (pressure < ptrsh)) { - if(abs(xval - lastx) <= xdjtrsh){ xval = lastx; } - if(abs(yval - lasty) <= ydjtrsh){ yval = lasty; } btn_pressed = 1; input_report_key(palmld_ac97_input, BTN_TOUCH, 1); - input_report_abs(palmld_ac97_input, ABS_X, xval); - input_report_abs(palmld_ac97_input, ABS_Y, yval); + input_report_abs(palmld_ac97_input, ABS_X, xread & 0xfff); + input_report_abs(palmld_ac97_input, ABS_Y, yread & 0xfff); input_report_abs(palmld_ac97_input, ABS_PRESSURE, pressure & 0xfff); input_sync(palmld_ac97_input); - lastx = xval; - lasty = yval; set_current_state(TASK_INTERRUPTIBLE); schedule_timeout(HZ/100); @@ -382,12 +375,11 @@ input_report_abs(palmld_ac97_input, ABS_Y, 0); input_report_abs(palmld_ac97_input, ABS_PRESSURE, 0); input_sync(palmld_ac97_input); - lastx = 0; - lasty = 0; } } + static void palmld_ac97_irq_work(void *data) { struct device *dev = data; @@ -421,12 +413,9 @@ enable_irq(IRQ_GPIO_PALMTX_WM9712_IRQ); } + static irqreturn_t palmld_ac97_irq_handler(int irq, void *dev_id, struct pt_regs *regs) { - /* - * we can't use ac97 from within the interrupt handler, so schedule a task - * to do the actual handling. - */ if (down_trylock(&queue_sem) == 0){ disable_irq(IRQ_GPIO_PALMTX_WM9712_IRQ); queue_work(palmld_ac97_workqueue, &palmld_ac97_irq_task); @@ -440,7 +429,7 @@ { int err; ac97_t *ac97 = dev->platform_data; - u16 d2; // init d1 too? + u16 d2 = DIG2_INIT; // init d1 too? if(!machine_is_xscale_palmtx()) return -ENODEV; @@ -461,12 +450,10 @@ ac97->bus->ops->write(ac97, 0x54, 0); /* disable digitiser to save power, enable pen-down detect */ - d2 = DIG2_INIT; d2 |= WM97XX_PRP_DET; d2base = d2; - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2); + ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base); - /* enable interrupts on codec's gpio 2 (connected to cpu gpio 27) */ wm97xx_gpio_mode(ac97, WM97XX_GPIO_2, WM97XX_GPIO_IN, WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE); @@ -475,23 +462,22 @@ /* enable pen detect interrupt */ wm97xx_gpio_mode(ac97, WM97XX_GPIO_13, WM97XX_GPIO_IN, WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE); + /* turn off irq gpio inverting */ ac97->bus->ops->write(ac97, 0x58, ac97->bus->ops->read(ac97, 0x58)&~1); /* turn on the digitiser and pen down detector */ - d2 = ac97->bus->ops->read(ac97, AC97_WM97XX_DIGITISER2); - d2 |= WM97XX_PRP_DETW; - ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2); + ac97->bus->ops->write(ac97, AC97_WM97XX_DIGITISER2, d2base | WM97XX_PRP_DETW); /* setup the input device */ palmld_ac97_input = input_allocate_device(); palmld_ac97_input->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); palmld_ac97_input->keybit[LONG(BTN_TOUCH)] = BIT(BTN_TOUCH); - input_set_abs_params(palmld_ac97_input, ABS_X, X_AXIS_MIN, X_AXIS_MAX, 0, 0); - input_set_abs_params(palmld_ac97_input, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, 0, 0); - input_set_abs_params(palmld_ac97_input, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, 0, 0); + input_set_abs_params(palmld_ac97_input, ABS_X, X_AXIS_MIN, X_AXIS_MAX, xdjtrsh, 0); + input_set_abs_params(palmld_ac97_input, ABS_Y, Y_AXIS_MIN, Y_AXIS_MAX, ydjtrsh, 0); + input_set_abs_params(palmld_ac97_input, ABS_PRESSURE, PRESSURE_MIN, PRESSURE_MAX, PRESSURE_FUZZ, 0); palmld_ac97_input->name = "Palm TX touchscreen (Wolfson WM9712)"; palmld_ac97_input->dev = dev; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |