static irqreturn_t titsc_irq(int irq, void *dev) { struct titsc *ts_dev = dev; struct input_dev *input_dev = ts_dev->input; unsigned int fsm, status, irqclr = 0; unsigned int x = 0, y = 0; unsigned int z1, z2, z; status = titsc_readl(ts_dev, REG_RAWIRQSTATUS); if (status & IRQENB_HW_PEN) { ts_dev->pen_down = true; irqclr |= IRQENB_HW_PEN; pm_stay_awake(ts_dev->mfd_tscadc->dev); } if (status & IRQENB_PENUP) { fsm = titsc_readl(ts_dev, REG_ADCFSM); if (fsm == ADCFSM_STEPID) { ts_dev->pen_down = false; input_report_key(input_dev, BTN_TOUCH, 0); input_report_abs(input_dev, ABS_PRESSURE, 0); input_sync(input_dev); pm_relax(ts_dev->mfd_tscadc->dev); } else { ts_dev->pen_down = true; } irqclr |= IRQENB_PENUP; } if (status & IRQENB_EOS) irqclr |= IRQENB_EOS; /* * ADC and touchscreen share the IRQ line. * FIFO1 interrupts are used by ADC. Handle FIFO0 IRQs here only */ if (status & IRQENB_FIFO0THRES) { titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2); if (ts_dev->pen_down && z1 != 0 && z2 != 0) { /* * Calculate pressure using formula * Resistance(touch) = x plate resistance * * x postion/4096 * ((z2 / z1) - 1) */ z = z1 - z2; z *= x; z *= ts_dev->x_plate_resistance; z /= z2; z = (z + 2047) >> 12; if (z <= MAX_12BIT) { input_report_abs(input_dev, ABS_X, x); input_report_abs(input_dev, ABS_Y, y); input_report_abs(input_dev, ABS_PRESSURE, z); input_report_key(input_dev, BTN_TOUCH, 1); input_sync(input_dev); } }
static void titsc_read_coordinates(struct titsc *ts_dev, u32 *x, u32 *y, u32 *z1, u32 *z2) { unsigned int yvals[7], xvals[7]; unsigned int i, xsum = 0, ysum = 0; unsigned int creads = ts_dev->coordinate_readouts; for (i = 0; i < creads; i++) { yvals[i] = titsc_readl(ts_dev, REG_FIFO0); yvals[i] &= 0xfff; } *z1 = titsc_readl(ts_dev, REG_FIFO0); *z1 &= 0xfff; *z2 = titsc_readl(ts_dev, REG_FIFO0); *z2 &= 0xfff; for (i = 0; i < creads; i++) { xvals[i] = titsc_readl(ts_dev, REG_FIFO0); xvals[i] &= 0xfff; } /* * If co-ordinates readouts is less than 4 then * report the average. In case of 4 or more * readouts, sort the co-ordinate samples, drop * min and max values and report the average of * remaining values. */ if (creads <= 3) { for (i = 0; i < creads; i++) { ysum += yvals[i]; xsum += xvals[i]; } ysum /= creads; xsum /= creads; } else { sort(yvals, creads, sizeof(unsigned int), titsc_cmp_coord, NULL); sort(xvals, creads, sizeof(unsigned int), titsc_cmp_coord, NULL); for (i = 1; i < creads - 1; i++) { ysum += yvals[i]; xsum += xvals[i]; } ysum /= creads - 2; xsum /= creads - 2; } *y = ysum; *x = xsum; }
static void titsc_read_coordinates(struct titsc *ts_dev, u32 *x, u32 *y, u32 *z1, u32 *z2) { unsigned int fifocount = titsc_readl(ts_dev, REG_FIFO0CNT); unsigned int prev_val_x = ~0, prev_val_y = ~0; unsigned int prev_diff_x = ~0, prev_diff_y = ~0; unsigned int read, diff; unsigned int i, channel; unsigned int creads = ts_dev->coordinate_readouts; *z1 = *z2 = 0; if (fifocount % (creads * 2 + 2)) fifocount -= fifocount % (creads * 2 + 2); /* * Delta filter is used to remove large variations in sampled * values from ADC. The filter tries to predict where the next * coordinate could be. This is done by taking a previous * coordinate and subtracting it form current one. Further the * algorithm compares the difference with that of a present value, * if true the value is reported to the sub system. */ for (i = 0; i < fifocount; i++) { read = titsc_readl(ts_dev, REG_FIFO0); channel = (read & 0xf0000) >> 16; read &= 0xfff; if (channel < creads) { diff = abs(read - prev_val_x); if (diff < prev_diff_x) { prev_diff_x = diff; *x = read; } prev_val_x = read; } else if (channel < creads * 2) { diff = abs(read - prev_val_y); if (diff < prev_diff_y) { prev_diff_y = diff; *y = read; } prev_val_y = read; } else if (channel < creads * 2 + 1) { *z1 = read; } else if (channel < creads * 2 + 2) { *z2 = read; } } }
static irqreturn_t titsc_irq(int irq, void *dev) { struct titsc *ts_dev = dev; struct input_dev *input_dev = ts_dev->input; unsigned int status, irqclr = 0; unsigned int x = 0, y = 0; unsigned int z1, z2, z; unsigned int fsm; status = titsc_readl(ts_dev, REG_IRQSTATUS); if (status & IRQENB_FIFO0THRES) { titsc_read_coordinates(ts_dev, &x, &y, &z1, &z2); if (ts_dev->pen_down && z1 != 0 && z2 != 0) { /* * Calculate pressure using formula * Resistance(touch) = x plate resistance * * x postion/4096 * ((z2 / z1) - 1) */ z = z1 - z2; z *= x; z *= ts_dev->x_plate_resistance; z /= z2; z = (z + 2047) >> 12; if (z <= MAX_12BIT) { input_report_abs(input_dev, ABS_X, x); input_report_abs(input_dev, ABS_Y, y); input_report_abs(input_dev, ABS_PRESSURE, z); input_report_key(input_dev, BTN_TOUCH, 1); input_sync(input_dev); } }
static void titsc_read_coordinates(struct titsc *ts_dev, unsigned int *x, unsigned int *y) { unsigned int fifocount = titsc_readl(ts_dev, REG_FIFO0CNT); unsigned int prev_val_x = ~0, prev_val_y = ~0; unsigned int prev_diff_x = ~0, prev_diff_y = ~0; unsigned int read, diff; unsigned int i, channel; /* * Delta filter is used to remove large variations in sampled * values from ADC. The filter tries to predict where the next * coordinate could be. This is done by taking a previous * coordinate and subtracting it form current one. Further the * algorithm compares the difference with that of a present value, * if true the value is reported to the sub system. */ for (i = 0; i < fifocount - 1; i++) { read = titsc_readl(ts_dev, REG_FIFO0); channel = read & 0xf0000; channel = channel >> 0x10; if ((channel >= 0) && (channel < ts_dev->steps_to_configure)) { read &= 0xfff; diff = abs(read - prev_val_x); if (diff < prev_diff_x) { prev_diff_x = diff; *x = read; } prev_val_x = read; } read = titsc_readl(ts_dev, REG_FIFO1); channel = read & 0xf0000; channel = channel >> 0x10; if ((channel >= ts_dev->steps_to_configure) && (channel < (2 * ts_dev->steps_to_configure - 1))) { read &= 0xfff; diff = abs(read - prev_val_y); if (diff < prev_diff_y) { prev_diff_y = diff; *y = read; } prev_val_y = read; } } }
static void titsc_step_config(struct titsc *ts_dev) { unsigned int config; int i; int end_step, first_step, tsc_steps; u32 stepenable; config = STEPCONFIG_MODE_HWSYNC | STEPCONFIG_AVG_16 | ts_dev->bit_xp; switch (ts_dev->wires) { case 4: config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn; break; case 5: config |= ts_dev->bit_yn | STEPCONFIG_INP_AN4 | ts_dev->bit_xn | ts_dev->bit_yp; break; case 8: config |= STEPCONFIG_INP(ts_dev->inp_yp) | ts_dev->bit_xn; break; } tsc_steps = ts_dev->coordinate_readouts * 2 + 2; first_step = TOTAL_STEPS - tsc_steps; /* Steps 16 to 16-coordinate_readouts is for X */ end_step = first_step + tsc_steps; for (i = end_step - ts_dev->coordinate_readouts; i < end_step; i++) { titsc_writel(ts_dev, REG_STEPCONFIG(i), config); titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY); } config = 0; config = STEPCONFIG_MODE_HWSYNC | STEPCONFIG_AVG_16 | ts_dev->bit_yn | STEPCONFIG_INM_ADCREFM; switch (ts_dev->wires) { case 4: config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp); break; case 5: config |= ts_dev->bit_xp | STEPCONFIG_INP_AN4 | ts_dev->bit_xn | ts_dev->bit_yp; break; case 8: config |= ts_dev->bit_yp | STEPCONFIG_INP(ts_dev->inp_xp); break; } /* 1 ... coordinate_readouts is for Y */ end_step = first_step + ts_dev->coordinate_readouts; for (i = first_step; i < end_step; i++) { titsc_writel(ts_dev, REG_STEPCONFIG(i), config); titsc_writel(ts_dev, REG_STEPDELAY(i), STEPCONFIG_OPENDLY); } /* Make CHARGECONFIG same as IDLECONFIG */ config = titsc_readl(ts_dev, REG_IDLECONFIG); titsc_writel(ts_dev, REG_CHARGECONFIG, config); titsc_writel(ts_dev, REG_CHARGEDELAY, ts_dev->charge_delay); /* coordinate_readouts + 1 ... coordinate_readouts + 2 is for Z */ config = STEPCONFIG_MODE_HWSYNC | STEPCONFIG_AVG_16 | ts_dev->bit_yp | ts_dev->bit_xn | STEPCONFIG_INM_ADCREFM | STEPCONFIG_INP(ts_dev->inp_xp); titsc_writel(ts_dev, REG_STEPCONFIG(end_step), config); titsc_writel(ts_dev, REG_STEPDELAY(end_step), STEPCONFIG_OPENDLY); end_step++; config |= STEPCONFIG_INP(ts_dev->inp_yn); titsc_writel(ts_dev, REG_STEPCONFIG(end_step), config); titsc_writel(ts_dev, REG_STEPDELAY(end_step), STEPCONFIG_OPENDLY); /* The steps end ... end - readouts * 2 + 2 and bit 0 for TS_Charge */ stepenable = 1; for (i = 0; i < tsc_steps; i++) stepenable |= 1 << (first_step + i + 1); ts_dev->step_mask = stepenable; am335x_tsc_se_set_cache(ts_dev->mfd_tscadc, ts_dev->step_mask); }