Use tpcalib_trans() instead of own function.
This commit is contained in:
parent
74c51d31a7
commit
bc90321cbe
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: ztp.c,v 1.2 2007/03/04 06:01:11 christos Exp $ */
|
||||
/* $NetBSD: ztp.c,v 1.3 2007/06/28 15:44:01 nonaka Exp $ */
|
||||
/* $OpenBSD: zts.c,v 1.9 2005/04/24 18:55:49 uwe Exp $ */
|
||||
|
||||
/*
|
||||
@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ztp.c,v 1.2 2007/03/04 06:01:11 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ztp.c,v 1.3 2007/06/28 15:44:01 nonaka Exp $");
|
||||
|
||||
#include "lcd.h"
|
||||
|
||||
@ -37,13 +37,21 @@ __KERNEL_RCSID(0, "$NetBSD: ztp.c,v 1.2 2007/03/04 06:01:11 christos Exp $");
|
||||
#include <dev/hpc/hpcfbio.h> /* XXX: for tpctl */
|
||||
#include <dev/hpc/hpctpanelvar.h>
|
||||
|
||||
#include <arm/xscale/pxa2x0cpu.h>
|
||||
#include <arm/xscale/pxa2x0reg.h>
|
||||
#include <arm/xscale/pxa2x0var.h>
|
||||
#include <arm/xscale/xscalereg.h>
|
||||
#include <arm/xscale/pxa2x0_lcd.h>
|
||||
#include <arm/xscale/pxa2x0_gpio.h>
|
||||
|
||||
#include <zaurus/dev/zsspvar.h>
|
||||
|
||||
#ifdef ZTP_DEBUG
|
||||
#define DPRINTF(s) printf s
|
||||
#else
|
||||
#define DPRINTF(s)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* ADS784x touch screen controller
|
||||
*/
|
||||
@ -67,16 +75,24 @@ __KERNEL_RCSID(0, "$NetBSD: ztp.c,v 1.2 2007/03/04 06:01:11 christos Exp $");
|
||||
extern const struct lcd_panel_geometry sharp_zaurus_C3000;
|
||||
|
||||
/* Settable via sysctl. */
|
||||
int ztp_rawmode;
|
||||
int ztp_rawmode;
|
||||
|
||||
static const struct wsmouse_calibcoords ztp_default_calib = {
|
||||
/*0, 0, 639, 479,*/
|
||||
0, 0, 479, 639,
|
||||
4,
|
||||
{{ 988, 80, 0, 0 },
|
||||
{ 88, 84, 479, 0 },
|
||||
{ 988, 927, 0, 639 },
|
||||
{ 88, 940, 479, 639 }}
|
||||
0, 0, 479, 639, /* minx, miny, maxx, maxy */
|
||||
5, /* samplelen */
|
||||
{
|
||||
{ 1929, 2021, 240, 320 }, /* rawx, rawy, x, y */
|
||||
{ 545, 3464, 48, 64 },
|
||||
{ 3308, 3452, 48, 576 },
|
||||
{ 2854, 768, 432, 576 },
|
||||
{ 542, 593, 432, 64 }
|
||||
}
|
||||
};
|
||||
|
||||
struct ztp_pos {
|
||||
int x;
|
||||
int y;
|
||||
int z; /* touch pressure */
|
||||
};
|
||||
|
||||
struct ztp_softc {
|
||||
@ -87,9 +103,7 @@ struct ztp_softc {
|
||||
int sc_enabled;
|
||||
int sc_buttons; /* button emulation ? */
|
||||
struct device *sc_wsmousedev;
|
||||
int sc_oldx;
|
||||
int sc_oldy;
|
||||
int sc_oldz;
|
||||
struct ztp_pos sc_oldpos;
|
||||
int sc_resx;
|
||||
int sc_resy;
|
||||
struct tpcalib_softc sc_tpcalib;
|
||||
@ -108,7 +122,7 @@ static void ztp_poll(void *);
|
||||
static int ztp_irq(void *);
|
||||
static int ztp_ioctl(void *, u_long, void *, int, struct lwp *);
|
||||
|
||||
const struct wsmouse_accessops ztp_accessops = {
|
||||
static const struct wsmouse_accessops ztp_accessops = {
|
||||
ztp_enable,
|
||||
ztp_ioctl,
|
||||
ztp_disable
|
||||
@ -127,6 +141,8 @@ ztp_attach(struct device *parent, struct device *self, void *aux)
|
||||
struct ztp_softc *sc = (struct ztp_softc *)self;
|
||||
struct wsmousedev_attach_args a;
|
||||
|
||||
printf("\n");
|
||||
|
||||
callout_init(&sc->sc_tp_poll);
|
||||
callout_setfunc(&sc->sc_tp_poll, ztp_poll, sc);
|
||||
|
||||
@ -146,7 +162,6 @@ ztp_attach(struct device *parent, struct device *self, void *aux)
|
||||
|
||||
a.accessops = &ztp_accessops;
|
||||
a.accesscookie = sc;
|
||||
printf("\n");
|
||||
|
||||
#if NLCD > 0
|
||||
sc->sc_resx = CURRENT_DISPLAY->panel_height;
|
||||
@ -169,8 +184,12 @@ ztp_enable(void *v)
|
||||
{
|
||||
struct ztp_softc *sc = (struct ztp_softc *)v;
|
||||
|
||||
if (sc->sc_enabled)
|
||||
DPRINTF(("%s: ztp_enable()\n", sc->sc_dev.dv_xname));
|
||||
|
||||
if (sc->sc_enabled) {
|
||||
DPRINTF(("%s: already enabled\n", sc->sc_dev.dv_xname));
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
callout_stop(&sc->sc_tp_poll);
|
||||
|
||||
@ -203,6 +222,8 @@ ztp_disable(void *v)
|
||||
{
|
||||
struct ztp_softc *sc = (struct ztp_softc *)v;
|
||||
|
||||
DPRINTF(("%s: ztp_disable()\n", sc->sc_dev.dv_xname));
|
||||
|
||||
callout_stop(&sc->sc_tp_poll);
|
||||
|
||||
if (sc->sc_powerhook != NULL) {
|
||||
@ -210,10 +231,12 @@ ztp_disable(void *v)
|
||||
sc->sc_powerhook = NULL;
|
||||
}
|
||||
|
||||
if (sc->sc_gh != NULL) {
|
||||
if (sc->sc_gh) {
|
||||
#if 0
|
||||
pxa2x0_gpio_intr_disestablish(sc->sc_gh);
|
||||
sc->sc_gh = NULL;
|
||||
#else
|
||||
pxa2x0_gpio_intr_mask(sc->sc_gh);
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -226,6 +249,8 @@ ztp_power(int why, void *v)
|
||||
{
|
||||
struct ztp_softc *sc = (struct ztp_softc *)v;
|
||||
|
||||
DPRINTF(("%s: ztp_power()\n", sc->sc_dev.dv_xname));
|
||||
|
||||
switch (why) {
|
||||
case PWR_STANDBY:
|
||||
case PWR_SUSPEND:
|
||||
@ -241,8 +266,7 @@ ztp_power(int why, void *v)
|
||||
(void)zssp_ic_send(ZSSP_IC_ADS7846, (1 << ADSCTRL_PD1_SH) |
|
||||
(1 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH));
|
||||
|
||||
pxa2x0_gpio_set_function(GPIO_TP_INT_C3K,
|
||||
GPIO_OUT | GPIO_SET);
|
||||
pxa2x0_gpio_set_function(GPIO_TP_INT_C3K, GPIO_OUT | GPIO_SET);
|
||||
break;
|
||||
|
||||
case PWR_RESUME:
|
||||
@ -255,8 +279,7 @@ ztp_power(int why, void *v)
|
||||
|
||||
#if 0
|
||||
sc->sc_gh = pxa2x0_gpio_intr_establish(GPIO_TP_INT_C3K,
|
||||
IST_EDGE_FALLING, IPL_TTY, ztp_irq, sc,
|
||||
sc->sc_dev.dv_xname);
|
||||
IST_EDGE_FALLING, IPL_TTY, ztp_irq, sc);
|
||||
#else
|
||||
pxa2x0_gpio_intr_unmask(sc->sc_gh);
|
||||
#endif
|
||||
@ -265,49 +288,38 @@ ztp_power(int why, void *v)
|
||||
}
|
||||
}
|
||||
|
||||
struct ztp_pos {
|
||||
int x;
|
||||
int y;
|
||||
int z; /* touch pressure */
|
||||
};
|
||||
|
||||
#define NSAMPLES 3
|
||||
static struct ztp_pos ztp_samples[NSAMPLES];
|
||||
static int ztpavgloaded = 0;
|
||||
|
||||
static int ztp_readpos(struct ztp_pos *);
|
||||
static void ztp_avgpos(struct ztp_pos *);
|
||||
|
||||
#define HSYNC() \
|
||||
do { \
|
||||
while (pxa2x0_gpio_get_bit(GPIO_HSYNC_C3K) == 0) \
|
||||
continue; \
|
||||
while (pxa2x0_gpio_get_bit(GPIO_HSYNC_C3K) != 0) \
|
||||
continue; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
do { \
|
||||
while (pxa2x0_gpio_get_bit(GPIO_HSYNC_C3K) == 0) \
|
||||
continue; \
|
||||
while (pxa2x0_gpio_get_bit(GPIO_HSYNC_C3K) != 0) \
|
||||
continue; \
|
||||
} while (/*CONSTCOND*/0)
|
||||
|
||||
static int pxa2x0_ccnt_enable(int);
|
||||
static uint32_t pxa2x0_read_ccnt(void);
|
||||
static uint32_t ztp_sync_ads784x(int, int, uint32_t);
|
||||
static void ztp_sync_send(uint32_t);
|
||||
static inline uint32_t pxa2x0_ccnt_enable(uint32_t);
|
||||
static inline uint32_t pxa2x0_read_ccnt(void);
|
||||
static uint32_t ztp_sync_ads784x(int, int, uint32_t);
|
||||
static void ztp_sync_send(uint32_t);
|
||||
static int ztp_readpos(struct ztp_pos *);
|
||||
|
||||
static int
|
||||
pxa2x0_ccnt_enable(int on)
|
||||
static inline uint32_t
|
||||
pxa2x0_ccnt_enable(uint32_t reg)
|
||||
{
|
||||
uint32_t rv;
|
||||
|
||||
on = on ? 0x1 : 0x0;
|
||||
__asm volatile("mrc p14, 0, %0, c0, c1, 0" : "=r" (rv));
|
||||
__asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (on));
|
||||
return ((int)(rv & 0x1));
|
||||
__asm volatile("mcr p14, 0, %0, c0, c1, 0" : : "r" (reg));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
static uint32_t
|
||||
static inline uint32_t
|
||||
pxa2x0_read_ccnt(void)
|
||||
{
|
||||
uint32_t rv;
|
||||
|
||||
__asm volatile("mrc p14, 0, %0, c1, c1, 0" : "=r" (rv));
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -317,25 +329,24 @@ pxa2x0_read_ccnt(void)
|
||||
static uint32_t
|
||||
ztp_sync_ads784x(int dorecv/* XXX */, int dosend/* XXX */, uint32_t cmd)
|
||||
{
|
||||
int ccen;
|
||||
uint32_t rv;
|
||||
uint32_t ccen;
|
||||
uint32_t rv = 0;
|
||||
|
||||
/* XXX poll hsync only if LCD is enabled */
|
||||
|
||||
/* start clock counter */
|
||||
ccen = pxa2x0_ccnt_enable(1);
|
||||
ccen = pxa2x0_ccnt_enable(PMNC_E);
|
||||
|
||||
HSYNC();
|
||||
|
||||
if (dorecv) {
|
||||
/* read SSDR and disable ADS784x */
|
||||
rv = zssp_ic_stop(ZSSP_IC_ADS7846);
|
||||
} else {
|
||||
rv = 0;
|
||||
}
|
||||
|
||||
if (dosend)
|
||||
if (dosend) {
|
||||
ztp_sync_send(cmd);
|
||||
}
|
||||
|
||||
/* stop clock counter */
|
||||
pxa2x0_ccnt_enable(ccen);
|
||||
@ -346,8 +357,8 @@ ztp_sync_ads784x(int dorecv/* XXX */, int dosend/* XXX */, uint32_t cmd)
|
||||
void
|
||||
ztp_sync_send(uint32_t cmd)
|
||||
{
|
||||
volatile uint32_t base, now;
|
||||
uint32_t tck;
|
||||
uint32_t a, b;
|
||||
|
||||
/* XXX */
|
||||
tck = CCNT_HS_400_VGA_C3K - 151;
|
||||
@ -359,10 +370,10 @@ ztp_sync_send(uint32_t cmd)
|
||||
HSYNC();
|
||||
|
||||
/* wait after refresh */
|
||||
a = pxa2x0_read_ccnt();
|
||||
b = pxa2x0_read_ccnt();
|
||||
while ((b - a) < tck)
|
||||
b = pxa2x0_read_ccnt();
|
||||
base = pxa2x0_read_ccnt();
|
||||
now = pxa2x0_read_ccnt();
|
||||
while ((now - base) < tck)
|
||||
now = pxa2x0_read_ccnt();
|
||||
|
||||
/* send the actual command; keep ADS784x enabled */
|
||||
zssp_ic_start(ZSSP_IC_ADS7846, cmd);
|
||||
@ -381,42 +392,41 @@ ztp_readpos(struct ztp_pos *pos)
|
||||
/* check that pen is down */
|
||||
cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
|
||||
(3 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
|
||||
|
||||
t0 = zssp_ic_send(ZSSP_IC_ADS7846, cmd);
|
||||
down = !(t0 < 10);
|
||||
DPRINTF(("ztp_readpos(): t0 = %d\n", t0));
|
||||
|
||||
down = (t0 >= 10);
|
||||
if (down == 0)
|
||||
goto out;
|
||||
|
||||
/* Y */
|
||||
cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
|
||||
(1 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
|
||||
|
||||
(void)ztp_sync_ads784x(0, 1, cmd);
|
||||
|
||||
/* Y */
|
||||
cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
|
||||
(1 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
|
||||
|
||||
(void)ztp_sync_ads784x(1, 1, cmd);
|
||||
|
||||
/* X */
|
||||
cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
|
||||
(5 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
|
||||
|
||||
pos->y = ztp_sync_ads784x(1, 1, cmd);
|
||||
DPRINTF(("ztp_readpos(): y = %d\n", pos->y));
|
||||
|
||||
/* T0 */
|
||||
cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
|
||||
(3 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
|
||||
|
||||
pos->x = ztp_sync_ads784x(1, 1, cmd);
|
||||
DPRINTF(("ztp_readpos(): x = %d\n", pos->x));
|
||||
|
||||
/* T1 */
|
||||
cmd = (1 << ADSCTRL_PD0_SH) | (1 << ADSCTRL_PD1_SH) |
|
||||
(4 << ADSCTRL_ADR_SH) | (1 << ADSCTRL_STS_SH);
|
||||
|
||||
t0 = ztp_sync_ads784x(1, 1, cmd);
|
||||
t1 = ztp_sync_ads784x(1, 0, cmd);
|
||||
DPRINTF(("ztp_readpos(): t0 = %d, t1 = %d\n", t0, t1));
|
||||
|
||||
/* check that pen is still down */
|
||||
/* XXX pressure sensitivity varies with X or what? */
|
||||
@ -432,70 +442,6 @@ out:
|
||||
return down;
|
||||
}
|
||||
|
||||
#define NAVGSAMPLES (NSAMPLES < 3 ? NSAMPLES : 3)
|
||||
|
||||
static void
|
||||
ztp_avgpos(struct ztp_pos *pos)
|
||||
{
|
||||
struct ztp_pos *tpp = ztp_samples;
|
||||
int diff[NAVGSAMPLES];
|
||||
int mindiff, mindiffv;
|
||||
int n;
|
||||
int i;
|
||||
static int tail;
|
||||
|
||||
if (ztpavgloaded < NAVGSAMPLES) {
|
||||
tpp[(tail + ztpavgloaded) % NSAMPLES] = *pos;
|
||||
ztpavgloaded++;
|
||||
return;
|
||||
}
|
||||
|
||||
tpp[tail] = *pos;
|
||||
tail = (tail+1) % NSAMPLES;
|
||||
|
||||
/* X */
|
||||
i = tail;
|
||||
for (n = 0 ; n < NAVGSAMPLES; n++) {
|
||||
int alt;
|
||||
alt = (i+1) % NSAMPLES;
|
||||
diff[n] = tpp[i].x - tpp[alt].x;
|
||||
if (diff[n] < 0)
|
||||
diff[n] = -diff[n]; /* ABS */
|
||||
i = alt;
|
||||
}
|
||||
mindiffv = diff[0];
|
||||
mindiff = 0;
|
||||
for (n = 1; n < NAVGSAMPLES; n++) {
|
||||
if (diff[n] < mindiffv) {
|
||||
mindiffv = diff[n];
|
||||
mindiff = n;
|
||||
}
|
||||
}
|
||||
pos->x = (tpp[(tail + mindiff) % NSAMPLES].x +
|
||||
tpp[(tail + mindiff + 1) % NSAMPLES].x) / 2;
|
||||
|
||||
/* Y */
|
||||
i = tail;
|
||||
for (n = 0 ; n < NAVGSAMPLES; n++) {
|
||||
int alt;
|
||||
alt = (i+1) % NSAMPLES;
|
||||
diff[n] = tpp[i].y - tpp[alt].y;
|
||||
if (diff[n] < 0)
|
||||
diff[n] = -diff[n]; /* ABS */
|
||||
i = alt;
|
||||
}
|
||||
mindiffv = diff[0];
|
||||
mindiff = 0;
|
||||
for (n = 1; n < NAVGSAMPLES; n++) {
|
||||
if (diff[n] < mindiffv) {
|
||||
mindiffv = diff[n];
|
||||
mindiff = n;
|
||||
}
|
||||
}
|
||||
pos->y = (tpp[(tail + mindiff) % NSAMPLES].y +
|
||||
tpp[(tail + mindiff + 1) % NSAMPLES].y) / 2;
|
||||
}
|
||||
|
||||
static void
|
||||
ztp_poll(void *v)
|
||||
{
|
||||
@ -506,7 +452,6 @@ ztp_poll(void *v)
|
||||
splx(s);
|
||||
}
|
||||
|
||||
#define TS_STABLE 8
|
||||
static int
|
||||
ztp_irq(void *v)
|
||||
{
|
||||
@ -524,56 +469,53 @@ ztp_irq(void *v)
|
||||
s = splhigh();
|
||||
|
||||
pindown = pxa2x0_gpio_get_bit(GPIO_TP_INT_C3K) ? 0 : 1;
|
||||
DPRINTF(("%s: pindown = %d\n", sc->sc_dev.dv_xname, pindown));
|
||||
if (pindown) {
|
||||
pxa2x0_gpio_intr_mask(sc->sc_gh);
|
||||
callout_schedule(&sc->sc_tp_poll, POLL_TIMEOUT_RATE1);
|
||||
}
|
||||
|
||||
down = ztp_readpos(&tp);
|
||||
DPRINTF(("%s: x = %d, y = %d, z = %d, down = %d\n", sc->sc_dev.dv_xname,
|
||||
tp.x, tp.y, tp.z, down));
|
||||
|
||||
if (!pindown) {
|
||||
pxa2x0_gpio_intr_unmask(sc->sc_gh);
|
||||
callout_schedule(&sc->sc_tp_poll, POLL_TIMEOUT_RATE0);
|
||||
ztpavgloaded = 0;
|
||||
}
|
||||
pxa2x0_gpio_clear_intr(GPIO_TP_INT_C3K);
|
||||
|
||||
splx(s);
|
||||
|
||||
if (down) {
|
||||
ztp_avgpos(&tp);
|
||||
if (!ztp_rawmode) {
|
||||
tpcalib_trans(&sc->sc_tpcalib, tp.x, tp.y, &x, &y);
|
||||
DPRINTF(("%s: x = %d, y = %d\n", sc->sc_dev.dv_xname,
|
||||
x, y));
|
||||
tp.x = x;
|
||||
tp.y = y;
|
||||
}
|
||||
}
|
||||
|
||||
if (zkbd_modstate != 0 && down) {
|
||||
if(zkbd_modstate & (1 << 1)) {
|
||||
if (zkbd_modstate & (1 << 1)) {
|
||||
/* Fn */
|
||||
down = 2;
|
||||
}
|
||||
if(zkbd_modstate & (1 << 2)) {
|
||||
} else if (zkbd_modstate & (1 << 2)) {
|
||||
/* 'Alt' */
|
||||
down = 4;
|
||||
}
|
||||
}
|
||||
if (!down) {
|
||||
/* x/y values are not reliable when pen is up */
|
||||
tp.x = sc->sc_oldx;
|
||||
tp.y = sc->sc_oldy;
|
||||
tp.z = sc->sc_oldz;
|
||||
tp = sc->sc_oldpos;
|
||||
}
|
||||
|
||||
if (down || sc->sc_buttons != down) {
|
||||
wsmouse_input(sc->sc_wsmousedev, down, tp.x, tp.y, tp.z, 0,
|
||||
WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y |
|
||||
WSMOUSE_INPUT_ABSOLUTE_Z);
|
||||
wsmouse_input(sc->sc_wsmousedev, down, tp.x, tp.y, 0, 0,
|
||||
WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
|
||||
sc->sc_buttons = down;
|
||||
sc->sc_oldx = tp.x;
|
||||
sc->sc_oldy = tp.y;
|
||||
sc->sc_oldz = tp.z;
|
||||
sc->sc_oldpos = tp;
|
||||
}
|
||||
|
||||
return 1;
|
||||
|
Loading…
Reference in New Issue
Block a user