/*
* Copyright (c) 2003 Valeriy E. Ushakov
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
static int
j6x0tp_match(device_t parent, cfdata_t cf, void *aux)
{
/*
* XXX: platid_mask_MACH_HP_LX also matches 360LX. It's not
* confirmed whether touch panel in 360LX is connected this
* way. We may need to regroup platid masks.
*/
if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_6XX)
&& !platid_match(&platid, &platid_mask_MACH_HP_LX))
return (0);
if (strcmp(cf->cf_name, "j6x0tp") != 0)
return (0);
/* used when in polling mode */
callout_init(&sc->sc_touch_ch, 0);
/* establish interrupt handler, but disable until opened */
intc_intr_establish(SH7709_INTEVT2_IRQ3, IST_EDGE, IPL_TTY,
j6x0tp_intr, sc);
intc_intr_disable(SH7709_INTEVT2_IRQ3);
if (!pmf_device_register(self, NULL, NULL))
aprint_error_dev(self, "unable to establish power handler\n");
}
/*
* Enable touch panel: we start in interrupt mode.
* Must be called as spltty().
*/
static void
j6x0tp_enable(struct j6x0tp_softc *sc)
{
if (--tremor_timeout == 0) {
DPRINTF(("%s: tremor timeout!\n",
device_xname(sc->sc_dev)));
goto served;
}
} while (steady < TREMOR_THRESHOLD);
if (touched) {
intc_intr_disable(SH7709_INTEVT2_IRQ3);
/*
* ADC readings are not stable yet, so schedule
* callout instead of accessing ADC from the interrupt
* handler only to immediately delay().
*/
callout_reset(&sc->sc_touch_ch, hz/32,
j6x0tp_start_polling, sc);
} else
DPRINTFN(1, ("%s: tremor\n", device_xname(sc->sc_dev)));
served:
/* clear the interrupt (XXX: protect access?) */
_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
return (1);
}
/*
* Called from the interrupt handler at spltty() upon first touch.
* Decide if we are going to report this touch as a mouse click/drag
* or as a key press.
*/
static void
j6x0tp_start_polling(void *arg)
{
struct j6x0tp_softc *sc = arg;
uint8_t phdr;
int do_mouse, do_kbd;
int rawx, rawy;
int icon;
phdr = _reg_read_1(SH7709_PHDR);
if ((phdr & PHDR_TP_PEN_DOWN) == 0) {
DPRINTFN(2, ("%s: start: pen is not down\n",
device_xname(sc->sc_dev)));
j6x0tp_stop_polling(sc);
}
/* clear pending interrupt signal before re-enabling the interrupt */
irr0 = _reg_read_1(SH7709_IRR0);
if ((irr0 & IRR0_IRQ3) != 0)
_reg_write_1(SH7709_IRR0, irr0 & ~IRR0_IRQ3);
intc_intr_enable(SH7709_INTEVT2_IRQ3);
}
/*
* We are reporting this touch as a keyboard event.
* Poll touch screen waiting for pen-up.
*/
static void
j6x0tp_callout_wskbd(void *arg)
{
struct j6x0tp_softc *sc = arg;
uint8_t phdr;
int s;
phdr = _reg_read_1(SH7709_PHDR);
if ((phdr & PHDR_TP_PEN_DOWN) != 0) {
/*
* Pen is still down, continue polling. Wskbd's
* auto-repeat takes care of repeating the key.
*/
callout_schedule(&sc->sc_touch_ch, hz/32);
} else {
wskbd_input(sc->sc_wskbddev,
WSCONS_EVENT_KEY_UP, sc->sc_hard_icon);
j6x0tp_stop_polling(sc);
}
splx(s);
}
/*
* We are reporting this touch as a mouse click/drag.
*/
static void
j6x0tp_callout_wsmouse(void *arg)
{
struct j6x0tp_softc *sc = arg;
uint8_t phdr;
int rawx, rawy;
int s;
/*
* Read raw X/Y coordinates from the ADC.
* XXX: protect accesses to SCPDR?
*/
static void
j6x0tp_get_raw_xy(int *rawxp, int *rawyp)
{
uint8_t scpdr;
/*
* Check if the (rawx, rawy) is inside one of the 4 hard icons.
* Return the icon number 1..4, or 0 if not inside an icon.
*/
static int
j6x0tp_get_hard_icon(int rawx, int rawy)
{
if (rawx <= J6X0TP_FB_RIGHT)
return (0);
if (rawy < J6X0TP_HARD_ICON_MAX_Y(1))
return (1);
else if (rawy < J6X0TP_HARD_ICON_MAX_Y(2))
return (2);
else if (rawy < J6X0TP_HARD_ICON_MAX_Y(3))
return (3);
else
return (4);
}
static int
j6x0tp_wsmouse_ioctl(void *arg, u_long cmd, void *data, int flag, lwp_t *l)
{
struct j6x0tp_softc *sc = arg;