Home | History | Annotate | Line # | Download | only in jazz
      1  1.19   thorpej /* $NetBSD: pckbc_jazzio.c,v 1.19 2020/11/18 02:14:13 thorpej Exp $ */
      2   1.1      soda /* NetBSD: pckbc_isa.c,v 1.2 2000/03/23 07:01:35 thorpej Exp  */
      3   1.1      soda 
      4   1.1      soda /*
      5   1.1      soda  * Copyright (c) 1998
      6   1.1      soda  *	Matthias Drochner.  All rights reserved.
      7   1.1      soda  *
      8   1.1      soda  * Redistribution and use in source and binary forms, with or without
      9   1.1      soda  * modification, are permitted provided that the following conditions
     10   1.1      soda  * are met:
     11   1.1      soda  * 1. Redistributions of source code must retain the above copyright
     12   1.1      soda  *    notice, this list of conditions and the following disclaimer.
     13   1.1      soda  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1      soda  *    notice, this list of conditions and the following disclaimer in the
     15   1.1      soda  *    documentation and/or other materials provided with the distribution.
     16   1.1      soda  *
     17   1.1      soda  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18   1.1      soda  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19   1.1      soda  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20   1.1      soda  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21   1.1      soda  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22   1.1      soda  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23   1.1      soda  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24   1.1      soda  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25   1.1      soda  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26   1.1      soda  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27   1.1      soda  */
     28   1.9     lukem 
     29   1.9     lukem #include <sys/cdefs.h>
     30  1.19   thorpej __KERNEL_RCSID(0, "$NetBSD: pckbc_jazzio.c,v 1.19 2020/11/18 02:14:13 thorpej Exp $");
     31   1.1      soda 
     32   1.1      soda #include <sys/param.h>
     33   1.1      soda #include <sys/systm.h>
     34   1.1      soda #include <sys/kernel.h>
     35   1.1      soda #include <sys/proc.h>
     36   1.1      soda #include <sys/device.h>
     37  1.19   thorpej #include <sys/kmem.h>
     38   1.1      soda #include <sys/errno.h>
     39   1.1      soda #include <sys/queue.h>
     40  1.17        ad #include <sys/bus.h>
     41   1.1      soda 
     42   1.1      soda #include <machine/autoconf.h>
     43   1.2        ur #include <arc/jazz/pica.h>
     44   1.2        ur #include <arc/jazz/jazziovar.h>
     45   1.1      soda 
     46   1.1      soda #include <dev/ic/i8042reg.h>
     47   1.1      soda #include <dev/ic/pckbcvar.h>
     48   1.1      soda #include <arc/jazz/pckbc_jazzioreg.h>
     49   1.1      soda 
     50   1.3      soda #define PMS_INTR 7	/* XXX - should be obtained from firmware */
     51   1.1      soda #define PICA_KBCMDP	(PICA_SYS_KBD + JAZZIO_KBCMDP)
     52   1.1      soda 
     53  1.18      cube int	pckbc_jazzio_match(device_t, cfdata_t, void *);
     54  1.18      cube void	pckbc_jazzio_attach(device_t, device_t, void *);
     55  1.12   tsutsui void	pckbc_jazzio_intr_establish(struct pckbc_softc *, pckbc_slot_t);
     56   1.1      soda 
     57   1.1      soda struct pckbc_jazzio_softc {
     58   1.1      soda 	struct pckbc_softc sc_pckbc;
     59   1.1      soda 
     60   1.2        ur 	int sc_intr[PCKBC_NSLOTS];
     61   1.1      soda };
     62   1.1      soda 
     63  1.18      cube CFATTACH_DECL_NEW(pckbc_jazzio, sizeof(struct pckbc_jazzio_softc),
     64   1.6   thorpej     pckbc_jazzio_match, pckbc_jazzio_attach, NULL, NULL);
     65   1.1      soda 
     66   1.1      soda int
     67  1.18      cube pckbc_jazzio_match(device_t parent, cfdata_t match, void *aux)
     68   1.1      soda {
     69   1.2        ur 	struct jazzio_attach_args *ja = aux;
     70   1.2        ur 	bus_space_tag_t iot = ja->ja_bust;
     71   1.1      soda 	bus_space_handle_t ioh_d, ioh_c;
     72   1.2        ur 	bus_addr_t addr = ja->ja_addr;
     73   1.1      soda 	int res, ok = 1;
     74   1.1      soda 
     75   1.7   tsutsui 	if (strcmp(ja->ja_name, "I8742") != 0)
     76  1.12   tsutsui 		return 0;
     77   1.1      soda 
     78   1.1      soda 	if (pckbc_is_console(iot, addr) == 0) {
     79   1.4  jdolecek 		struct pckbc_internal t;
     80   1.4  jdolecek 
     81   1.1      soda 		if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d))
     82  1.12   tsutsui 			return 0;
     83   1.1      soda 		if (bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c)) {
     84   1.1      soda 			bus_space_unmap(iot, ioh_d, 1);
     85  1.12   tsutsui 			return 0;
     86   1.1      soda 		}
     87   1.1      soda 
     88   1.4  jdolecek 		memset(&t, 0, sizeof(t));
     89   1.4  jdolecek 		t.t_iot = iot;
     90   1.4  jdolecek 		t.t_ioh_d = ioh_d;
     91   1.4  jdolecek 		t.t_ioh_c = ioh_c;
     92   1.4  jdolecek 
     93   1.1      soda 		/* flush KBC */
     94  1.12   tsutsui 		(void)pckbc_poll_data1(&t, PCKBC_KBD_SLOT);
     95   1.1      soda 
     96   1.1      soda 		/* KBC selftest */
     97   1.1      soda 		if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0) {
     98   1.1      soda 			ok = 0;
     99   1.1      soda 			goto out;
    100   1.1      soda 		}
    101  1.10     bjh21 		res = pckbc_poll_data1(&t, PCKBC_KBD_SLOT);
    102   1.1      soda 		if (res != 0x55) {
    103   1.1      soda 			printf("kbc selftest: %x\n", res);
    104   1.1      soda 			ok = 0;
    105   1.1      soda 		}
    106   1.1      soda  out:
    107   1.1      soda 		bus_space_unmap(iot, ioh_d, 1);
    108   1.1      soda 		bus_space_unmap(iot, ioh_c, 1);
    109   1.1      soda 	}
    110   1.1      soda 
    111  1.12   tsutsui 	return ok;
    112   1.1      soda }
    113   1.1      soda 
    114   1.1      soda void
    115  1.18      cube pckbc_jazzio_attach(device_t parent, device_t self, void *aux)
    116   1.1      soda {
    117   1.2        ur 	struct jazzio_attach_args *ja = aux;
    118  1.18      cube 	struct pckbc_jazzio_softc *jsc = device_private(self);
    119   1.1      soda 	struct pckbc_softc *sc = &jsc->sc_pckbc;
    120   1.1      soda 	struct pckbc_internal *t;
    121   1.2        ur 	bus_space_tag_t iot = ja->ja_bust;
    122   1.1      soda 	bus_space_handle_t ioh_d, ioh_c;
    123   1.2        ur 	bus_addr_t addr = ja->ja_addr;
    124   1.1      soda 
    125  1.18      cube 	sc->sc_dv = self;
    126   1.1      soda 	sc->intr_establish = pckbc_jazzio_intr_establish;
    127   1.1      soda 
    128   1.1      soda 	/*
    129   1.1      soda 	 * To establish interrupt handler
    130   1.1      soda 	 *
    131   1.1      soda 	 * XXX handcrafting "aux" slot...
    132   1.1      soda 	 */
    133   1.2        ur 	jsc->sc_intr[PCKBC_KBD_SLOT] = ja->ja_intr;
    134   1.3      soda 	jsc->sc_intr[PCKBC_AUX_SLOT] = PMS_INTR;		/* XXX */
    135   1.1      soda 
    136   1.1      soda 	if (pckbc_is_console(iot, addr)) {
    137   1.1      soda 		t = &pckbc_consdata;
    138   1.1      soda 		ioh_d = t->t_ioh_d;
    139   1.1      soda 		ioh_c = t->t_ioh_c;
    140   1.1      soda 		pckbc_console_attached = 1;
    141   1.1      soda 		/* t->t_cmdbyte was initialized by cnattach */
    142   1.1      soda 	} else {
    143   1.1      soda 		if (bus_space_map(iot, addr + KBDATAP, 1, 0, &ioh_d) ||
    144   1.1      soda 		    bus_space_map(iot, PICA_KBCMDP, 1, 0, &ioh_c))
    145   1.1      soda 			panic("pckbc_attach: couldn't map");
    146   1.1      soda 
    147  1.19   thorpej 		t = kmem_zalloc(sizeof(struct pckbc_internal),
    148  1.19   thorpej 		    KM_SLEEP);
    149   1.1      soda 		t->t_iot = iot;
    150   1.1      soda 		t->t_ioh_d = ioh_d;
    151   1.1      soda 		t->t_ioh_c = ioh_c;
    152   1.1      soda 		t->t_addr = addr;
    153   1.1      soda 		t->t_cmdbyte = KC8_CPU; /* Enable ports */
    154  1.15        ad 		callout_init(&t->t_cleanup, 0);
    155   1.1      soda 	}
    156   1.1      soda 
    157   1.1      soda 	t->t_sc = sc;
    158   1.1      soda 	sc->id = t;
    159   1.1      soda 
    160  1.18      cube 	aprint_normal("\n");
    161   1.1      soda 
    162   1.1      soda 	/* Finish off the attach. */
    163   1.1      soda 	pckbc_attach(sc);
    164   1.1      soda }
    165   1.1      soda 
    166   1.1      soda void
    167  1.12   tsutsui pckbc_jazzio_intr_establish(struct pckbc_softc *sc, pckbc_slot_t slot)
    168   1.1      soda {
    169   1.1      soda 	struct pckbc_jazzio_softc *jsc = (void *) sc;
    170   1.1      soda 
    171   1.2        ur 	jazzio_intr_establish(jsc->sc_intr[slot], pckbcintr, sc);
    172   1.1      soda }
    173