Home | History | Annotate | Line # | Download | only in dev
j720tp.c revision 1.1.14.5
      1  1.1.14.5  yamt /*	$NetBSD: j720tp.c,v 1.1.14.5 2007/10/27 11:26:13 yamt Exp $	*/
      2  1.1.14.2  yamt 
      3  1.1.14.2  yamt /*-
      4  1.1.14.2  yamt  * Copyright (c) 2006 The NetBSD Foundation, Inc.
      5  1.1.14.2  yamt  * All rights reserved.
      6  1.1.14.2  yamt  *
      7  1.1.14.2  yamt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.14.2  yamt  * by IWAMOTO Toshihiro and Peter Postma.
      9  1.1.14.2  yamt  *
     10  1.1.14.2  yamt  * Redistribution and use in source and binary forms, with or without
     11  1.1.14.2  yamt  * modification, are permitted provided that the following conditions
     12  1.1.14.2  yamt  * are met:
     13  1.1.14.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.1.14.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.1.14.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.14.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.14.2  yamt  *    documentation and/or other materials provided with the distribution.
     18  1.1.14.2  yamt  * 3. All advertising materials mentioning features or use of this software
     19  1.1.14.2  yamt  *    must display the following acknowledgement:
     20  1.1.14.2  yamt  *        This product includes software developed by the NetBSD
     21  1.1.14.2  yamt  *        Foundation, Inc. and its contributors.
     22  1.1.14.2  yamt  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.14.2  yamt  *    contributors may be used to endorse or promote products derived
     24  1.1.14.2  yamt  *    from this software without specific prior written permission.
     25  1.1.14.2  yamt  *
     26  1.1.14.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.14.2  yamt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.14.2  yamt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.14.2  yamt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.14.2  yamt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.14.2  yamt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.14.2  yamt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.14.2  yamt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.14.2  yamt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.14.2  yamt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.14.2  yamt  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.14.2  yamt  */
     38  1.1.14.2  yamt 
     39  1.1.14.2  yamt /* Jornada 720 touch-panel driver. */
     40  1.1.14.2  yamt 
     41  1.1.14.2  yamt #include <sys/cdefs.h>
     42  1.1.14.5  yamt __KERNEL_RCSID(0, "$NetBSD: j720tp.c,v 1.1.14.5 2007/10/27 11:26:13 yamt Exp $");
     43  1.1.14.3  yamt 
     44  1.1.14.3  yamt #ifdef _KERNEL_OPT
     45  1.1.14.3  yamt #include "opt_j720tp.h"
     46  1.1.14.3  yamt #include "opt_wsdisplay_compat.h"
     47  1.1.14.3  yamt #endif
     48  1.1.14.2  yamt 
     49  1.1.14.2  yamt #include <sys/param.h>
     50  1.1.14.2  yamt #include <sys/systm.h>
     51  1.1.14.2  yamt #include <sys/device.h>
     52  1.1.14.2  yamt #include <sys/kernel.h>
     53  1.1.14.2  yamt #include <sys/malloc.h>
     54  1.1.14.2  yamt #include <sys/ioctl.h>
     55  1.1.14.2  yamt #include <sys/callout.h>
     56  1.1.14.3  yamt #include <sys/sysctl.h>
     57  1.1.14.2  yamt 
     58  1.1.14.2  yamt #include <machine/platid.h>
     59  1.1.14.2  yamt #include <machine/platid_mask.h>
     60  1.1.14.2  yamt 
     61  1.1.14.2  yamt #include <arm/sa11x0/sa11x0_var.h>
     62  1.1.14.2  yamt #include <arm/sa11x0/sa11x0_gpioreg.h>
     63  1.1.14.2  yamt #include <arm/sa11x0/sa11x0_ppcreg.h>
     64  1.1.14.2  yamt #include <arm/sa11x0/sa11x0_sspreg.h>
     65  1.1.14.2  yamt 
     66  1.1.14.2  yamt #include <dev/wscons/wsconsio.h>
     67  1.1.14.2  yamt #include <dev/wscons/wsmousevar.h>
     68  1.1.14.3  yamt #include <dev/wscons/wskbdvar.h>
     69  1.1.14.3  yamt #include <dev/wscons/wsksymvar.h>
     70  1.1.14.3  yamt #include <dev/wscons/wsksymdef.h>
     71  1.1.14.2  yamt #include <dev/hpc/hpctpanelvar.h>
     72  1.1.14.2  yamt 
     73  1.1.14.2  yamt #include <hpcarm/dev/j720sspvar.h>
     74  1.1.14.2  yamt 
     75  1.1.14.3  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
     76  1.1.14.3  yamt #include <dev/hpc/pckbd_encode.h>
     77  1.1.14.3  yamt #endif
     78  1.1.14.3  yamt 
     79  1.1.14.3  yamt #define arraysize(ary)	(sizeof(ary) / sizeof(ary[0]))
     80  1.1.14.2  yamt 
     81  1.1.14.2  yamt #ifdef J720TP_DEBUG
     82  1.1.14.3  yamt int j720tp_debug = 0;
     83  1.1.14.3  yamt #define DPRINTF(arg)		if (j720tp_debug) printf arg
     84  1.1.14.3  yamt #define DPRINTFN(n, arg)	if (j720tp_debug >= (n)) printf arg
     85  1.1.14.2  yamt #else
     86  1.1.14.3  yamt #define DPRINTF(arg)		/* nothing */
     87  1.1.14.3  yamt #define DPRINTFN(n, arg)	/* nothing */
     88  1.1.14.2  yamt #endif
     89  1.1.14.2  yamt 
     90  1.1.14.2  yamt struct j720tp_softc {
     91  1.1.14.2  yamt 	struct device		sc_dev;
     92  1.1.14.2  yamt 
     93  1.1.14.3  yamt #define J720TP_WSMOUSE_ENABLED	0x01
     94  1.1.14.3  yamt #define J720TP_WSKBD_ENABLED	0x02
     95  1.1.14.2  yamt 	int			sc_enabled;
     96  1.1.14.3  yamt 	int			sc_hard_icon;
     97  1.1.14.3  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
     98  1.1.14.3  yamt 	int			sc_rawkbd;
     99  1.1.14.3  yamt #endif
    100  1.1.14.2  yamt 
    101  1.1.14.2  yamt 	struct callout		sc_tpcallout;
    102  1.1.14.2  yamt 	struct j720ssp_softc	*sc_ssp;
    103  1.1.14.2  yamt 
    104  1.1.14.2  yamt 	struct device		*sc_wsmousedev;
    105  1.1.14.3  yamt 	struct device		*sc_wskbddev;
    106  1.1.14.2  yamt 
    107  1.1.14.2  yamt 	struct tpcalib_softc	sc_tpcalib;
    108  1.1.14.2  yamt };
    109  1.1.14.2  yamt 
    110  1.1.14.2  yamt static int	j720tp_match(struct device *, struct cfdata *, void *);
    111  1.1.14.2  yamt static void	j720tp_attach(struct device *, struct device *, void *);
    112  1.1.14.2  yamt 
    113  1.1.14.2  yamt static int	j720tp_wsmouse_enable(void *);
    114  1.1.14.4  yamt static int	j720tp_wsmouse_ioctl(void *, u_long, void *, int,
    115  1.1.14.2  yamt 			struct lwp *);
    116  1.1.14.2  yamt static void	j720tp_wsmouse_disable(void *);
    117  1.1.14.2  yamt 
    118  1.1.14.3  yamt static int	j720tp_wskbd_enable(void *, int);
    119  1.1.14.3  yamt static void	j720tp_wskbd_set_leds(void *, int);
    120  1.1.14.4  yamt static int	j720tp_wskbd_ioctl(void *, u_long, void *, int, struct lwp *);
    121  1.1.14.3  yamt 
    122  1.1.14.2  yamt static void	j720tp_enable_intr(struct j720tp_softc *);
    123  1.1.14.2  yamt static void	j720tp_disable_intr(struct j720tp_softc *);
    124  1.1.14.2  yamt static int	j720tp_intr(void *);
    125  1.1.14.2  yamt static int	j720tp_get_rawxy(struct j720tp_softc *, int *, int *);
    126  1.1.14.3  yamt static int	j720tp_get_hard_icon(struct j720tp_softc *, int, int);
    127  1.1.14.2  yamt static void	j720tp_wsmouse_input(struct j720tp_softc *, int, int);
    128  1.1.14.2  yamt static void	j720tp_wsmouse_callout(void *);
    129  1.1.14.3  yamt static void	j720tp_wskbd_input(struct j720tp_softc *, u_int);
    130  1.1.14.3  yamt static void	j720tp_wskbd_callout(void *);
    131  1.1.14.2  yamt 
    132  1.1.14.2  yamt const struct wsmouse_accessops j720tp_wsmouse_accessops = {
    133  1.1.14.2  yamt 	j720tp_wsmouse_enable,
    134  1.1.14.2  yamt 	j720tp_wsmouse_ioctl,
    135  1.1.14.2  yamt 	j720tp_wsmouse_disable
    136  1.1.14.2  yamt };
    137  1.1.14.2  yamt 
    138  1.1.14.2  yamt static const struct wsmouse_calibcoords j720tp_default_calib = {
    139  1.1.14.2  yamt 	0, 0, 639, 239,
    140  1.1.14.2  yamt 	4,
    141  1.1.14.2  yamt 	{{ 988,  80,   0,   0 },
    142  1.1.14.2  yamt 	 {  88,  84, 639,   0 },
    143  1.1.14.2  yamt 	 { 988, 927,   0, 239 },
    144  1.1.14.2  yamt 	 {  88, 940, 639, 239 }}
    145  1.1.14.2  yamt };
    146  1.1.14.2  yamt 
    147  1.1.14.3  yamt const struct wskbd_accessops j720tp_wskbd_accessops = {
    148  1.1.14.3  yamt 	j720tp_wskbd_enable,
    149  1.1.14.3  yamt 	j720tp_wskbd_set_leds,
    150  1.1.14.3  yamt 	j720tp_wskbd_ioctl
    151  1.1.14.3  yamt };
    152  1.1.14.3  yamt 
    153  1.1.14.3  yamt #ifndef J720TP_SETTINGS_ICON_KEYSYM
    154  1.1.14.3  yamt #define J720TP_SETTINGS_ICON_KEYSYM	KS_Home
    155  1.1.14.3  yamt #endif
    156  1.1.14.3  yamt #ifndef J720TP_BACKUP_ICON_KEYSYM
    157  1.1.14.3  yamt #define J720TP_BACKUP_ICON_KEYSYM	KS_Prior
    158  1.1.14.3  yamt #endif
    159  1.1.14.3  yamt #ifndef J720TP_DIALUP_ICON_KEYSYM
    160  1.1.14.3  yamt #define J720TP_DIALUP_ICON_KEYSYM	KS_Next
    161  1.1.14.3  yamt #endif
    162  1.1.14.3  yamt #ifndef J720TP_MEDIA_ICON_KEYSYM
    163  1.1.14.3  yamt #define J720TP_MEDIA_ICON_KEYSYM	KS_End
    164  1.1.14.3  yamt #endif
    165  1.1.14.3  yamt 
    166  1.1.14.3  yamt /* Max Y value of the n'th hard icon. */
    167  1.1.14.3  yamt #define J720TP_HARD_ICON_MAX_Y(n) \
    168  1.1.14.3  yamt 	(((j720tp_hard_icon_bottom - j720tp_hard_icon_top) / 4) * (n)) + \
    169  1.1.14.3  yamt 	j720tp_hard_icon_top
    170  1.1.14.3  yamt 
    171  1.1.14.3  yamt /* Default raw X/Y values of the hard icon area. */
    172  1.1.14.3  yamt static int j720tp_hard_icon_left = 70;
    173  1.1.14.3  yamt static int j720tp_hard_icon_right = 20;
    174  1.1.14.3  yamt static int j720tp_hard_icon_top = 70;
    175  1.1.14.3  yamt static int j720tp_hard_icon_bottom = 940;
    176  1.1.14.3  yamt 
    177  1.1.14.3  yamt /* Maps the icon number to a raw keycode. */
    178  1.1.14.3  yamt static const int j720tp_wskbd_keys[] = {
    179  1.1.14.3  yamt 	/* Icon 1 */ 199,
    180  1.1.14.3  yamt 	/* Icon 2 */ 201,
    181  1.1.14.3  yamt 	/* Icon 3 */ 209,
    182  1.1.14.3  yamt 	/* Icon 4 */ 207
    183  1.1.14.3  yamt };
    184  1.1.14.3  yamt 
    185  1.1.14.3  yamt static const keysym_t j720tp_wskbd_keydesc[] = {
    186  1.1.14.3  yamt 	KS_KEYCODE(199), J720TP_SETTINGS_ICON_KEYSYM,
    187  1.1.14.3  yamt 	KS_KEYCODE(201), J720TP_BACKUP_ICON_KEYSYM,
    188  1.1.14.3  yamt 	KS_KEYCODE(209), J720TP_DIALUP_ICON_KEYSYM,
    189  1.1.14.3  yamt 	KS_KEYCODE(207), J720TP_MEDIA_ICON_KEYSYM
    190  1.1.14.3  yamt };
    191  1.1.14.3  yamt 
    192  1.1.14.3  yamt const struct wscons_keydesc j720tp_wskbd_keydesctab[] = {
    193  1.1.14.3  yamt 	{ KB_US, 0,
    194  1.1.14.3  yamt 	  sizeof(j720tp_wskbd_keydesc) / sizeof(keysym_t),
    195  1.1.14.3  yamt 	  j720tp_wskbd_keydesc
    196  1.1.14.3  yamt 	},
    197  1.1.14.3  yamt 	{ 0, 0, 0, 0 }
    198  1.1.14.3  yamt };
    199  1.1.14.3  yamt 
    200  1.1.14.3  yamt const struct wskbd_mapdata j720tp_wskbd_keymapdata = {
    201  1.1.14.3  yamt 	j720tp_wskbd_keydesctab, KB_US
    202  1.1.14.3  yamt };
    203  1.1.14.3  yamt 
    204  1.1.14.2  yamt CFATTACH_DECL(j720tp, sizeof(struct j720tp_softc),
    205  1.1.14.2  yamt     j720tp_match, j720tp_attach, NULL, NULL);
    206  1.1.14.2  yamt 
    207  1.1.14.2  yamt 
    208  1.1.14.2  yamt static int
    209  1.1.14.2  yamt j720tp_match(struct device *parent, struct cfdata *cf, void *aux)
    210  1.1.14.2  yamt {
    211  1.1.14.2  yamt 
    212  1.1.14.2  yamt 	if (!platid_match(&platid, &platid_mask_MACH_HP_JORNADA_7XX))
    213  1.1.14.2  yamt 		return 0;
    214  1.1.14.2  yamt 	if (strcmp(cf->cf_name, "j720tp") != 0)
    215  1.1.14.2  yamt 		return 0;
    216  1.1.14.2  yamt 
    217  1.1.14.2  yamt 	return 1;
    218  1.1.14.2  yamt }
    219  1.1.14.2  yamt 
    220  1.1.14.2  yamt static void
    221  1.1.14.2  yamt j720tp_attach(struct device *parent, struct device *self, void *aux)
    222  1.1.14.2  yamt {
    223  1.1.14.3  yamt 	struct j720tp_softc *sc = (struct j720tp_softc *)self;
    224  1.1.14.2  yamt 	struct wsmousedev_attach_args wsma;
    225  1.1.14.3  yamt 	struct wskbddev_attach_args wska;
    226  1.1.14.2  yamt 
    227  1.1.14.2  yamt 	printf("\n");
    228  1.1.14.2  yamt 
    229  1.1.14.2  yamt 	sc->sc_ssp = (struct j720ssp_softc *)parent;
    230  1.1.14.2  yamt 	sc->sc_enabled = 0;
    231  1.1.14.3  yamt 	sc->sc_hard_icon = 0;
    232  1.1.14.3  yamt 	sc->sc_rawkbd = 0;
    233  1.1.14.2  yamt 
    234  1.1.14.2  yamt 	/* Touch-panel as a pointing device. */
    235  1.1.14.2  yamt 	wsma.accessops = &j720tp_wsmouse_accessops;
    236  1.1.14.2  yamt 	wsma.accesscookie = sc;
    237  1.1.14.2  yamt 
    238  1.1.14.2  yamt 	sc->sc_wsmousedev = config_found_ia(self, "wsmousedev", &wsma,
    239  1.1.14.2  yamt 	    wsmousedevprint);
    240  1.1.14.3  yamt 	if (sc->sc_wsmousedev == NULL)
    241  1.1.14.3  yamt 		return;
    242  1.1.14.2  yamt 
    243  1.1.14.2  yamt 	/* Initialize calibration, set default parameters. */
    244  1.1.14.2  yamt 	tpcalib_init(&sc->sc_tpcalib);
    245  1.1.14.2  yamt 	tpcalib_ioctl(&sc->sc_tpcalib, WSMOUSEIO_SCALIBCOORDS,
    246  1.1.14.2  yamt 	    __UNCONST(&j720tp_default_calib), 0, 0);
    247  1.1.14.2  yamt 
    248  1.1.14.4  yamt 	callout_init(&sc->sc_tpcallout, 0);
    249  1.1.14.2  yamt 
    250  1.1.14.5  yamt 	j720tp_wsmouse_disable(sc);
    251  1.1.14.5  yamt 
    252  1.1.14.3  yamt 	/* On-screen "hard icons" as a keyboard device. */
    253  1.1.14.3  yamt 	wska.console = 0;
    254  1.1.14.3  yamt 	wska.keymap = &j720tp_wskbd_keymapdata;
    255  1.1.14.3  yamt 	wska.accessops = &j720tp_wskbd_accessops;
    256  1.1.14.3  yamt 	wska.accesscookie = sc;
    257  1.1.14.3  yamt 
    258  1.1.14.3  yamt 	sc->sc_wskbddev = config_found_ia(self, "wskbddev", &wska,
    259  1.1.14.3  yamt 	    wskbddevprint);
    260  1.1.14.3  yamt 
    261  1.1.14.2  yamt 	/* Setup touch-panel interrupt. */
    262  1.1.14.2  yamt 	sa11x0_intr_establish(0, 9, 1, IPL_TTY, j720tp_intr, sc);
    263  1.1.14.2  yamt }
    264  1.1.14.2  yamt 
    265  1.1.14.2  yamt static int
    266  1.1.14.2  yamt j720tp_wsmouse_enable(void *self)
    267  1.1.14.2  yamt {
    268  1.1.14.2  yamt 	struct j720tp_softc *sc = self;
    269  1.1.14.2  yamt 	int s;
    270  1.1.14.2  yamt 
    271  1.1.14.2  yamt 	s = spltty();
    272  1.1.14.2  yamt 
    273  1.1.14.2  yamt 	j720tp_enable_intr(sc);
    274  1.1.14.2  yamt 
    275  1.1.14.3  yamt 	sc->sc_enabled |= J720TP_WSMOUSE_ENABLED;
    276  1.1.14.2  yamt 
    277  1.1.14.2  yamt 	splx(s);
    278  1.1.14.2  yamt 	return 0;
    279  1.1.14.2  yamt }
    280  1.1.14.2  yamt 
    281  1.1.14.2  yamt static int
    282  1.1.14.4  yamt j720tp_wsmouse_ioctl(void *self, u_long cmd, void *data, int flag,
    283  1.1.14.2  yamt     struct lwp *l)
    284  1.1.14.2  yamt {
    285  1.1.14.2  yamt 	struct j720tp_softc *sc = self;
    286  1.1.14.2  yamt 
    287  1.1.14.2  yamt 	return hpc_tpanel_ioctl(&sc->sc_tpcalib, cmd, data, flag, l);
    288  1.1.14.2  yamt }
    289  1.1.14.2  yamt 
    290  1.1.14.2  yamt static void
    291  1.1.14.2  yamt j720tp_wsmouse_disable(void *self)
    292  1.1.14.2  yamt {
    293  1.1.14.2  yamt 	struct j720tp_softc *sc = self;
    294  1.1.14.2  yamt 	int s;
    295  1.1.14.2  yamt 
    296  1.1.14.2  yamt 	s = spltty();
    297  1.1.14.2  yamt 
    298  1.1.14.2  yamt 	j720tp_disable_intr(sc);
    299  1.1.14.2  yamt 	callout_stop(&sc->sc_tpcallout);
    300  1.1.14.2  yamt 
    301  1.1.14.3  yamt 	sc->sc_enabled &= ~J720TP_WSMOUSE_ENABLED;
    302  1.1.14.2  yamt 
    303  1.1.14.2  yamt 	splx(s);
    304  1.1.14.2  yamt }
    305  1.1.14.2  yamt 
    306  1.1.14.3  yamt static int
    307  1.1.14.3  yamt j720tp_wskbd_enable(void *self, int on)
    308  1.1.14.3  yamt {
    309  1.1.14.3  yamt 	struct j720tp_softc *sc = self;
    310  1.1.14.3  yamt 	int s;
    311  1.1.14.3  yamt 
    312  1.1.14.3  yamt 	s = spltty();
    313  1.1.14.3  yamt 	sc->sc_enabled |= J720TP_WSKBD_ENABLED;
    314  1.1.14.3  yamt 	splx(s);
    315  1.1.14.3  yamt 
    316  1.1.14.3  yamt 	return 0;
    317  1.1.14.3  yamt }
    318  1.1.14.3  yamt 
    319  1.1.14.3  yamt static void
    320  1.1.14.3  yamt j720tp_wskbd_set_leds(void *self, int leds)
    321  1.1.14.3  yamt {
    322  1.1.14.3  yamt 	/* nothing to do */
    323  1.1.14.3  yamt }
    324  1.1.14.3  yamt 
    325  1.1.14.3  yamt static int
    326  1.1.14.4  yamt j720tp_wskbd_ioctl(void *self, u_long cmd, void *data, int flag,
    327  1.1.14.3  yamt     struct lwp *l)
    328  1.1.14.3  yamt {
    329  1.1.14.3  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    330  1.1.14.3  yamt 	struct j720tp_softc *sc = self;
    331  1.1.14.3  yamt #endif
    332  1.1.14.3  yamt 
    333  1.1.14.3  yamt 	switch (cmd) {
    334  1.1.14.3  yamt 	case WSKBDIO_GTYPE:
    335  1.1.14.3  yamt 		*(int *)data = WSKBD_TYPE_HPC_BTN;
    336  1.1.14.3  yamt 		return 0;
    337  1.1.14.3  yamt 	case WSKBDIO_GETLEDS:
    338  1.1.14.3  yamt 		*(int *)data = 0;
    339  1.1.14.3  yamt 		return 0;
    340  1.1.14.3  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    341  1.1.14.3  yamt 	case WSKBDIO_SETMODE:
    342  1.1.14.3  yamt 		sc->sc_rawkbd = (*(int *)data == WSKBD_RAW);
    343  1.1.14.3  yamt 		return 0;
    344  1.1.14.3  yamt #endif
    345  1.1.14.3  yamt 	}
    346  1.1.14.3  yamt 
    347  1.1.14.3  yamt 	return EPASSTHROUGH;
    348  1.1.14.3  yamt }
    349  1.1.14.3  yamt 
    350  1.1.14.2  yamt /*
    351  1.1.14.2  yamt  * Enable touch-panel interrupt.  Must be called at spltty().
    352  1.1.14.2  yamt  */
    353  1.1.14.2  yamt static void
    354  1.1.14.2  yamt j720tp_enable_intr(struct j720tp_softc *sc)
    355  1.1.14.2  yamt {
    356  1.1.14.2  yamt 	struct j720ssp_softc *ssp = sc->sc_ssp;
    357  1.1.14.2  yamt 	uint32_t er;
    358  1.1.14.2  yamt 
    359  1.1.14.2  yamt 	er = bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER);
    360  1.1.14.2  yamt 	er |= 1 << 9;
    361  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER, er);
    362  1.1.14.2  yamt }
    363  1.1.14.2  yamt 
    364  1.1.14.2  yamt /*
    365  1.1.14.2  yamt  * Disable touch-panel interrupt.  Must be called at spltty().
    366  1.1.14.2  yamt  */
    367  1.1.14.2  yamt static void
    368  1.1.14.2  yamt j720tp_disable_intr(struct j720tp_softc *sc)
    369  1.1.14.2  yamt {
    370  1.1.14.2  yamt 	struct j720ssp_softc *ssp = sc->sc_ssp;
    371  1.1.14.2  yamt 	uint32_t er;
    372  1.1.14.2  yamt 
    373  1.1.14.2  yamt 	er = bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER);
    374  1.1.14.2  yamt 	er &= ~(1 << 9);
    375  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_FER, er);
    376  1.1.14.2  yamt }
    377  1.1.14.2  yamt 
    378  1.1.14.2  yamt static int
    379  1.1.14.2  yamt j720tp_intr(void *arg)
    380  1.1.14.2  yamt {
    381  1.1.14.2  yamt 	struct j720tp_softc *sc = arg;
    382  1.1.14.2  yamt 	struct j720ssp_softc *ssp = sc->sc_ssp;
    383  1.1.14.2  yamt 	int rawx, rawy;
    384  1.1.14.2  yamt 
    385  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_EDR, 1 << 9);
    386  1.1.14.2  yamt 
    387  1.1.14.3  yamt 	if (!(sc->sc_enabled & J720TP_WSMOUSE_ENABLED)) {
    388  1.1.14.2  yamt 		DPRINTF(("j720tp_intr: !sc_enabled\n"));
    389  1.1.14.2  yamt 		return 0;
    390  1.1.14.2  yamt 	}
    391  1.1.14.2  yamt 
    392  1.1.14.2  yamt 	j720tp_disable_intr(sc);
    393  1.1.14.2  yamt 
    394  1.1.14.3  yamt 	if (j720tp_get_rawxy(sc, &rawx, &rawy)) {
    395  1.1.14.3  yamt 		sc->sc_hard_icon = j720tp_get_hard_icon(sc, rawx, rawy);
    396  1.1.14.2  yamt 
    397  1.1.14.3  yamt 		if (sc->sc_hard_icon > 0) {
    398  1.1.14.3  yamt 			j720tp_wskbd_input(sc, WSCONS_EVENT_KEY_DOWN);
    399  1.1.14.3  yamt 			callout_reset(&sc->sc_tpcallout, hz / 32,
    400  1.1.14.3  yamt 			    j720tp_wskbd_callout, sc);
    401  1.1.14.3  yamt 		} else {
    402  1.1.14.3  yamt 			j720tp_wsmouse_input(sc, rawx, rawy);
    403  1.1.14.3  yamt 			callout_reset(&sc->sc_tpcallout, hz / 32,
    404  1.1.14.3  yamt 			    j720tp_wsmouse_callout, sc);
    405  1.1.14.3  yamt 		}
    406  1.1.14.3  yamt 	}
    407  1.1.14.2  yamt 
    408  1.1.14.2  yamt 	return 1;
    409  1.1.14.2  yamt }
    410  1.1.14.2  yamt 
    411  1.1.14.2  yamt static int
    412  1.1.14.2  yamt j720tp_get_rawxy(struct j720tp_softc *sc, int *rawx, int *rawy)
    413  1.1.14.2  yamt {
    414  1.1.14.2  yamt 	struct j720ssp_softc *ssp = sc->sc_ssp;
    415  1.1.14.2  yamt 	int buf[8], data, i;
    416  1.1.14.2  yamt 
    417  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PCR, 0x2000000);
    418  1.1.14.2  yamt 
    419  1.1.14.2  yamt 	/* Send read touch-panel command. */
    420  1.1.14.3  yamt 	if (j720ssp_readwrite(ssp, 1, 0xa0, &data, 100) < 0 || data != 0x11) {
    421  1.1.14.2  yamt 		DPRINTF(("j720tp_get_rawxy: no dummy received\n"));
    422  1.1.14.2  yamt 		goto out;
    423  1.1.14.2  yamt 	}
    424  1.1.14.2  yamt 
    425  1.1.14.2  yamt 	for (i = 0; i < 8; i++) {
    426  1.1.14.3  yamt 		if (j720ssp_readwrite(ssp, 0, 0x11, &data, 100) < 0)
    427  1.1.14.2  yamt 			goto out;
    428  1.1.14.2  yamt 		buf[i] = data;
    429  1.1.14.2  yamt 	}
    430  1.1.14.2  yamt 
    431  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
    432  1.1.14.2  yamt 
    433  1.1.14.2  yamt 	buf[6] <<= 8;
    434  1.1.14.2  yamt 	buf[7] <<= 8;
    435  1.1.14.2  yamt 	for (i = 0; i < 3; i++) {
    436  1.1.14.2  yamt 		buf[i] |= buf[6] & 0x300;
    437  1.1.14.2  yamt 		buf[6] >>= 2;
    438  1.1.14.2  yamt 		buf[i + 3] |= buf[7] & 0x300;
    439  1.1.14.2  yamt 		buf[7] >>= 2;
    440  1.1.14.2  yamt 	}
    441  1.1.14.2  yamt 
    442  1.1.14.3  yamt 	DPRINTFN(2, ("j720tp_get_rawxy: %d:%d:%d:%d:%d:%d:%d:%d\n",
    443  1.1.14.3  yamt 	    buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7]));
    444  1.1.14.2  yamt 
    445  1.1.14.2  yamt 	*rawx = buf[1];
    446  1.1.14.2  yamt 	*rawy = buf[4];
    447  1.1.14.2  yamt 
    448  1.1.14.2  yamt 	return 1;
    449  1.1.14.2  yamt out:
    450  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PSR, 0x2000000);
    451  1.1.14.2  yamt 
    452  1.1.14.2  yamt 	/* reset SSP */
    453  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x307);
    454  1.1.14.2  yamt 	delay(100);
    455  1.1.14.2  yamt 	bus_space_write_4(ssp->sc_iot, ssp->sc_ssph, SASSP_CR0, 0x387);
    456  1.1.14.2  yamt 
    457  1.1.14.2  yamt 	DPRINTF(("j720tp_get_rawxy: error %x\n", data));
    458  1.1.14.2  yamt 	return 0;
    459  1.1.14.2  yamt }
    460  1.1.14.2  yamt 
    461  1.1.14.3  yamt static int
    462  1.1.14.3  yamt j720tp_get_hard_icon(struct j720tp_softc *sc, int rawx, int rawy)
    463  1.1.14.3  yamt {
    464  1.1.14.3  yamt 	int icon = 0;
    465  1.1.14.3  yamt 
    466  1.1.14.3  yamt 	if (!(sc->sc_enabled & J720TP_WSKBD_ENABLED))
    467  1.1.14.3  yamt 		return 0;
    468  1.1.14.3  yamt 	/* Check if the touch was in the hard icons area. */
    469  1.1.14.3  yamt 	if (rawx > j720tp_hard_icon_left)
    470  1.1.14.3  yamt 		return 0;
    471  1.1.14.3  yamt 
    472  1.1.14.3  yamt 	if (rawy < J720TP_HARD_ICON_MAX_Y(1))
    473  1.1.14.3  yamt 		icon = 1;
    474  1.1.14.3  yamt 	else if (rawy < J720TP_HARD_ICON_MAX_Y(2))
    475  1.1.14.3  yamt 		icon = 2;
    476  1.1.14.3  yamt 	else if (rawy < J720TP_HARD_ICON_MAX_Y(3))
    477  1.1.14.3  yamt 		icon = 3;
    478  1.1.14.3  yamt 	else if (rawy < J720TP_HARD_ICON_MAX_Y(4))
    479  1.1.14.3  yamt 		icon = 4;
    480  1.1.14.3  yamt 
    481  1.1.14.3  yamt 	return icon;
    482  1.1.14.3  yamt }
    483  1.1.14.3  yamt 
    484  1.1.14.2  yamt static void
    485  1.1.14.2  yamt j720tp_wsmouse_input(struct j720tp_softc *sc, int rawx, int rawy)
    486  1.1.14.2  yamt {
    487  1.1.14.2  yamt 	int x, y;
    488  1.1.14.2  yamt 
    489  1.1.14.2  yamt 	tpcalib_trans(&sc->sc_tpcalib, rawx, rawy, &x, &y);
    490  1.1.14.3  yamt 	wsmouse_input(sc->sc_wsmousedev, 1, x, y, 0, 0,
    491  1.1.14.2  yamt 	    WSMOUSE_INPUT_ABSOLUTE_X | WSMOUSE_INPUT_ABSOLUTE_Y);
    492  1.1.14.2  yamt }
    493  1.1.14.2  yamt 
    494  1.1.14.2  yamt static void
    495  1.1.14.2  yamt j720tp_wsmouse_callout(void *arg)
    496  1.1.14.2  yamt {
    497  1.1.14.2  yamt 	struct j720tp_softc *sc = arg;
    498  1.1.14.2  yamt 	struct j720ssp_softc *ssp = sc->sc_ssp;
    499  1.1.14.2  yamt 	int rawx, rawy, s;
    500  1.1.14.2  yamt 
    501  1.1.14.2  yamt 	s = spltty();
    502  1.1.14.2  yamt 
    503  1.1.14.3  yamt 	if (!(sc->sc_enabled & J720TP_WSMOUSE_ENABLED)) {
    504  1.1.14.2  yamt 		DPRINTF(("j720tp_wsmouse_callout: !sc_enabled\n"));
    505  1.1.14.2  yamt 		splx(s);
    506  1.1.14.2  yamt 		return;
    507  1.1.14.2  yamt 	}
    508  1.1.14.2  yamt 
    509  1.1.14.2  yamt 	if (bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PLR) & (1<<9)) {
    510  1.1.14.3  yamt 		wsmouse_input(sc->sc_wsmousedev, 0, 0, 0, 0, 0, 0);
    511  1.1.14.2  yamt 		j720tp_enable_intr(sc);
    512  1.1.14.2  yamt 	} else {
    513  1.1.14.2  yamt 		if (j720tp_get_rawxy(sc, &rawx, &rawy))
    514  1.1.14.2  yamt 			j720tp_wsmouse_input(sc, rawx, rawy);
    515  1.1.14.3  yamt 		callout_schedule(&sc->sc_tpcallout, hz / 32);
    516  1.1.14.3  yamt 	}
    517  1.1.14.3  yamt 
    518  1.1.14.3  yamt 	splx(s);
    519  1.1.14.3  yamt }
    520  1.1.14.3  yamt 
    521  1.1.14.3  yamt static void
    522  1.1.14.3  yamt j720tp_wskbd_input(struct j720tp_softc *sc, u_int evtype)
    523  1.1.14.3  yamt {
    524  1.1.14.3  yamt 	int key = j720tp_wskbd_keys[sc->sc_hard_icon - 1];
    525  1.1.14.3  yamt 
    526  1.1.14.3  yamt #ifdef WSDISPLAY_COMPAT_RAWKBD
    527  1.1.14.3  yamt 	if (sc->sc_rawkbd) {
    528  1.1.14.3  yamt 		int n;
    529  1.1.14.3  yamt 		u_char data[16];
    530  1.1.14.3  yamt 
    531  1.1.14.3  yamt 		n = pckbd_encode(evtype, key, data);
    532  1.1.14.3  yamt 		wskbd_rawinput(sc->sc_wskbddev, data, n);
    533  1.1.14.3  yamt 	} else
    534  1.1.14.3  yamt #endif
    535  1.1.14.3  yamt 		wskbd_input(sc->sc_wskbddev, evtype, key);
    536  1.1.14.3  yamt }
    537  1.1.14.3  yamt 
    538  1.1.14.3  yamt static void
    539  1.1.14.3  yamt j720tp_wskbd_callout(void *arg)
    540  1.1.14.3  yamt {
    541  1.1.14.3  yamt 	struct j720tp_softc *sc = arg;
    542  1.1.14.3  yamt 	struct j720ssp_softc *ssp = sc->sc_ssp;
    543  1.1.14.3  yamt 	int s;
    544  1.1.14.3  yamt 
    545  1.1.14.3  yamt 	s = spltty();
    546  1.1.14.3  yamt 
    547  1.1.14.3  yamt 	if (!sc->sc_enabled) {
    548  1.1.14.3  yamt 		DPRINTF(("j720tp_wskbd_callout: !sc_enabled\n"));
    549  1.1.14.3  yamt 		splx(s);
    550  1.1.14.3  yamt 		return;
    551  1.1.14.3  yamt 	}
    552  1.1.14.2  yamt 
    553  1.1.14.3  yamt 	if (bus_space_read_4(ssp->sc_iot, ssp->sc_gpioh, SAGPIO_PLR) & (1<<9)) {
    554  1.1.14.3  yamt 		j720tp_wskbd_input(sc, WSCONS_EVENT_KEY_UP);
    555  1.1.14.3  yamt 		j720tp_enable_intr(sc);
    556  1.1.14.3  yamt 	} else {
    557  1.1.14.2  yamt 		callout_schedule(&sc->sc_tpcallout, hz / 32);
    558  1.1.14.2  yamt 	}
    559  1.1.14.2  yamt 
    560  1.1.14.2  yamt 	splx(s);
    561  1.1.14.2  yamt }
    562  1.1.14.3  yamt 
    563  1.1.14.3  yamt SYSCTL_SETUP(sysctl_j720tp, "sysctl j720tp subtree setup")
    564  1.1.14.3  yamt {
    565  1.1.14.3  yamt 	const struct sysctlnode *rnode;
    566  1.1.14.3  yamt 	int rc;
    567  1.1.14.3  yamt 
    568  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, NULL, &rnode,
    569  1.1.14.3  yamt 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "hw", NULL,
    570  1.1.14.3  yamt 	    NULL, 0, NULL, 0, CTL_HW, CTL_EOL)) != 0)
    571  1.1.14.3  yamt 		goto err;
    572  1.1.14.3  yamt 
    573  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, &rnode,
    574  1.1.14.3  yamt 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "j720tp",
    575  1.1.14.3  yamt 	    SYSCTL_DESCR("Jornada 720 touch panel controls"),
    576  1.1.14.3  yamt 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
    577  1.1.14.3  yamt 		goto err;
    578  1.1.14.3  yamt 
    579  1.1.14.3  yamt #ifdef J720TP_DEBUG
    580  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
    581  1.1.14.3  yamt 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "debug",
    582  1.1.14.3  yamt 	    SYSCTL_DESCR("Verbosity of debugging messages"),
    583  1.1.14.3  yamt 	    NULL, 0, &j720tp_debug, 0, CTL_CREATE, CTL_EOL)) != 0)
    584  1.1.14.3  yamt 		goto err;
    585  1.1.14.3  yamt #endif /* J720TP_DEBUG */
    586  1.1.14.3  yamt 
    587  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, &rnode,
    588  1.1.14.3  yamt 	    CTLFLAG_PERMANENT, CTLTYPE_NODE, "hard_icons",
    589  1.1.14.3  yamt 	    SYSCTL_DESCR("Touch panel hard icons controls"),
    590  1.1.14.3  yamt 	    NULL, 0, NULL, 0, CTL_CREATE, CTL_EOL)) != 0)
    591  1.1.14.3  yamt 		goto err;
    592  1.1.14.3  yamt 
    593  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
    594  1.1.14.3  yamt 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "left",
    595  1.1.14.3  yamt 	    SYSCTL_DESCR("Raw left X value of the hard icon area"),
    596  1.1.14.3  yamt 	    NULL, 0, &j720tp_hard_icon_left, 0, CTL_CREATE, CTL_EOL)) != 0)
    597  1.1.14.3  yamt 		goto err;
    598  1.1.14.3  yamt 
    599  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
    600  1.1.14.3  yamt 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "right",
    601  1.1.14.3  yamt 	    SYSCTL_DESCR("Raw right X value of the hard icon area"),
    602  1.1.14.3  yamt 	    NULL, 0, &j720tp_hard_icon_right, 0, CTL_CREATE, CTL_EOL)) != 0)
    603  1.1.14.3  yamt 		goto err;
    604  1.1.14.3  yamt 
    605  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
    606  1.1.14.3  yamt 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "top",
    607  1.1.14.3  yamt 	    SYSCTL_DESCR("Raw top Y value of the hard icon area"),
    608  1.1.14.3  yamt 	    NULL, 0, &j720tp_hard_icon_top, 0, CTL_CREATE, CTL_EOL)) != 0)
    609  1.1.14.3  yamt 		goto err;
    610  1.1.14.3  yamt 
    611  1.1.14.3  yamt 	if ((rc = sysctl_createv(clog, 0, &rnode, NULL,
    612  1.1.14.3  yamt 	    CTLFLAG_PERMANENT | CTLFLAG_READWRITE, CTLTYPE_INT, "bottom",
    613  1.1.14.3  yamt 	    SYSCTL_DESCR("Raw bottom Y value of the hard icon area"),
    614  1.1.14.3  yamt 	    NULL, 0, &j720tp_hard_icon_bottom, 0, CTL_CREATE, CTL_EOL)) != 0)
    615  1.1.14.3  yamt 		goto err;
    616  1.1.14.3  yamt 
    617  1.1.14.3  yamt 	return;
    618  1.1.14.3  yamt err:
    619  1.1.14.3  yamt 	printf("%s: sysctl_createv failed (rc = %d)\n", __func__, rc);
    620  1.1.14.3  yamt }
    621