LCOV - code coverage report
Current view: top level - dev/isa - pckbc_isa.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 75 0.0 %
Date: 2018-10-19 03:25:38 Functions: 0 3 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*      $OpenBSD: pckbc_isa.c,v 1.19 2015/08/18 06:54:00 stsp Exp $     */
       2             : /*      $NetBSD: pckbc_isa.c,v 1.2 2000/03/23 07:01:35 thorpej Exp $    */
       3             : 
       4             : /*
       5             :  * Copyright (c) 1998
       6             :  *      Matthias Drochner.  All rights reserved.
       7             :  *
       8             :  * Redistribution and use in source and binary forms, with or without
       9             :  * modification, are permitted provided that the following conditions
      10             :  * are met:
      11             :  * 1. Redistributions of source code must retain the above copyright
      12             :  *    notice, this list of conditions and the following disclaimer.
      13             :  * 2. Redistributions in binary form must reproduce the above copyright
      14             :  *    notice, this list of conditions and the following disclaimer in the
      15             :  *    documentation and/or other materials provided with the distribution.
      16             :  *
      17             :  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
      18             :  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
      19             :  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
      20             :  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
      21             :  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
      22             :  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
      23             :  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
      24             :  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
      25             :  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
      26             :  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
      27             :  */
      28             : 
      29             : #include <sys/param.h>
      30             : #include <sys/systm.h>
      31             : #include <sys/device.h>
      32             : #include <sys/malloc.h>
      33             : 
      34             : #include <machine/bus.h>
      35             : 
      36             : #include <dev/isa/isareg.h>
      37             : #include <dev/isa/isavar.h>
      38             : 
      39             : #include <dev/ic/i8042reg.h>
      40             : #include <dev/ic/pckbcvar.h>
      41             : 
      42             : int     pckbc_isa_match(struct device *, void *, void *);
      43             : void    pckbc_isa_attach(struct device *, struct device *, void *);
      44             : int     pckbc_isa_activate(struct device *, int);
      45             : 
      46             : const struct cfattach pckbc_isa_ca = {
      47             :         sizeof(struct pckbc_softc), pckbc_isa_match, pckbc_isa_attach,
      48             :         NULL, pckbc_isa_activate
      49             : };
      50             : 
      51             : int
      52           0 : pckbc_isa_match(struct device *parent, void *match, void *aux)
      53             : {
      54           0 :         struct isa_attach_args *ia = aux;
      55           0 :         bus_space_tag_t iot = ia->ia_iot;
      56           0 :         bus_space_handle_t ioh_d, ioh_c;
      57             :         int res;
      58             : 
      59             :         /* If values are hardwired to something that they can't be, punt. */
      60           0 :         if ((ia->ia_iobase != IOBASEUNK && ia->ia_iobase != IO_KBD) ||
      61           0 :             ia->ia_maddr != MADDRUNK ||
      62           0 :             (ia->ia_irq != IRQUNK && ia->ia_irq != 1 /* XXX */) ||
      63           0 :             ia->ia_drq != DRQUNK)
      64           0 :                 return (0);
      65             : 
      66           0 :         if (pckbc_is_console(iot, IO_KBD) == 0) {
      67           0 :                 if (bus_space_map(iot, IO_KBD + KBDATAP, 1, 0, &ioh_d))
      68           0 :                         return (0);
      69           0 :                 if (bus_space_map(iot, IO_KBD + KBCMDP, 1, 0, &ioh_c))
      70             :                         goto fail;
      71             : 
      72             :                 /* flush KBC */
      73           0 :                 (void) pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);
      74             : 
      75             :                 /* KBC selftest */
      76           0 :                 if (pckbc_send_cmd(iot, ioh_c, KBC_SELFTEST) == 0)
      77             :                         goto fail2;
      78           0 :                 res = pckbc_poll_data1(iot, ioh_d, ioh_c, PCKBC_KBD_SLOT, 0);
      79           0 :                 if (res != 0x55) {
      80           0 :                         printf("kbc selftest: %x\n", res);
      81           0 :                         goto fail2;
      82             :                 }
      83           0 :                 bus_space_unmap(iot, ioh_c, 1);
      84           0 :                 bus_space_unmap(iot, ioh_d, 1);
      85           0 :         }
      86             : 
      87           0 :         ia->ia_iobase = IO_KBD;
      88           0 :         ia->ia_iosize = 5;
      89           0 :         ia->ia_msize = 0x0;
      90           0 :         ia->ipa_nirq = PCKBC_NSLOTS;
      91           0 :         ia->ipa_irq[PCKBC_KBD_SLOT].num = 1;
      92           0 :         ia->ipa_irq[PCKBC_AUX_SLOT].num = 12;
      93             : 
      94           0 :         return (1);
      95             : 
      96             : fail2:
      97           0 :         bus_space_unmap(iot, ioh_c, 1);
      98             : fail:
      99           0 :         bus_space_unmap(iot, ioh_d, 1);
     100           0 :         return (0);
     101           0 : }
     102             : 
     103             : int
     104           0 : pckbc_isa_activate(struct device *self, int act)
     105             : {
     106           0 :         struct pckbc_softc *sc = (struct pckbc_softc *)self;
     107             :         int rv = 0;
     108             : 
     109           0 :         switch (act) {
     110             :         case DVACT_SUSPEND:
     111           0 :                 rv = config_activate_children(self, act);
     112           0 :                 pckbc_stop(sc);
     113           0 :                 break;
     114             :         case DVACT_RESUME:
     115           0 :                 pckbc_reset(sc);
     116           0 :                 rv = config_activate_children(self, act);
     117           0 :                 break;
     118             :         default:
     119           0 :                 rv = config_activate_children(self, act);
     120           0 :                 break;
     121             :         }
     122           0 :         return (rv);
     123             : }
     124             : 
     125             : void
     126           0 : pckbc_isa_attach(struct device *parent, struct device *self, void *aux)
     127             : {
     128           0 :         struct pckbc_softc *sc = (struct pckbc_softc *)self;
     129           0 :         struct cfdata *cf = self->dv_cfdata;
     130           0 :         struct isa_attach_args *ia = aux;
     131             :         struct pckbc_internal *t;
     132             :         bus_space_tag_t iot;
     133           0 :         bus_space_handle_t ioh_d, ioh_c;
     134             :         void *rv;
     135             :         int slot;
     136             : 
     137           0 :         iot = ia->ia_iot;
     138             : 
     139           0 :         printf("\n");
     140             : 
     141           0 :         for (slot = 0; slot < PCKBC_NSLOTS; slot++) {
     142           0 :                 rv = isa_intr_establish(ia->ia_ic, ia->ipa_irq[slot].num,
     143           0 :                     IST_EDGE, IPL_TTY, pckbcintr, sc, sc->sc_dv.dv_xname);
     144           0 :                 if (rv == NULL) {
     145           0 :                         printf("%s: unable to establish interrupt for irq %d\n",
     146           0 :                             sc->sc_dv.dv_xname, ia->ipa_irq[slot].num);
     147             :                         /* XXX fail attach? */
     148           0 :                 }
     149             :         }
     150             : 
     151           0 :         if (pckbc_is_console(iot, IO_KBD)) {
     152             :                 t = &pckbc_consdata;
     153           0 :                 pckbc_console_attached = 1;
     154             :                 /* t->t_cmdbyte was initialized by cnattach */
     155           0 :         } else {
     156           0 :                 if (bus_space_map(iot, IO_KBD + KBDATAP, 1, 0, &ioh_d) ||
     157           0 :                     bus_space_map(iot, IO_KBD + KBCMDP, 1, 0, &ioh_c))
     158           0 :                         panic("pckbc_attach: couldn't map");
     159             : 
     160           0 :                 t = malloc(sizeof(*t), M_DEVBUF, M_WAITOK | M_ZERO);
     161           0 :                 t->t_iot = iot;
     162           0 :                 t->t_ioh_d = ioh_d;
     163           0 :                 t->t_ioh_c = ioh_c;
     164           0 :                 t->t_addr = IO_KBD;
     165           0 :                 t->t_cmdbyte = KC8_CPU; /* Enable ports */
     166             :         }
     167             : 
     168           0 :         t->t_sc = sc;
     169           0 :         sc->id = t;
     170             : 
     171             :         /* Finish off the attach. */
     172           0 :         pckbc_attach(sc, cf->cf_flags);
     173           0 : }

Generated by: LCOV version 1.13