LCOV - code coverage report
Current view: top level - dev/isa - mpu_isa.c (source / functions) Hit Total Coverage
Test: 6.4 Lines: 0 39 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: mpu_isa.c,v 1.6 2015/03/14 03:38:47 jsg Exp $ */
       2             : 
       3             : /*
       4             :  * Copyright (c) 2002 Sergey Smitienko. All rights reserved.
       5             :  *
       6             :  * Redistribution and use in source and binary forms, with or without
       7             :  * modification, are permitted provided that the following conditions
       8             :  * are met:
       9             :  * 1. Redistributions of source code must retain the above copyright
      10             :  *    notice, this list of conditions and the following disclaimer.
      11             :  * 2. Redistributions in binary form must reproduce the above copyright
      12             :  *    notice, this list of conditions and the following disclaimer in the
      13             :  *    documentation and/or other materials provided with the distribution.
      14             :  * 3. The name of the author may not be used to endorse or promote products
      15             :  *    derived from this software without specific prior written permission.
      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 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
      21             :  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
      22             :  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
      23             :  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      24             :  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
      25             :  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
      26             :  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
      27             :  * OF THE POSSIBILITY OF SUCH DAMAGE.
      28             :  */
      29             : 
      30             : #include <sys/param.h>
      31             : #include <sys/systm.h>
      32             : #include <sys/errno.h>
      33             : #include <sys/ioctl.h>
      34             : #include <sys/syslog.h>
      35             : #include <sys/device.h>
      36             : 
      37             : #include <machine/bus.h>
      38             : 
      39             : #include <sys/audioio.h>
      40             : #include <dev/midi_if.h>
      41             : 
      42             : #include <dev/isa/isavar.h>
      43             : #include <dev/isa/isadmavar.h>
      44             : 
      45             : #include <dev/ic/mpuvar.h>
      46             : 
      47             : int     mpu_isa_match(struct device *, void *, void *);
      48             : void    mpu_isa_attach(struct device *, struct device *, void *);
      49             : int     mpu_test(bus_space_tag_t, int);
      50             : 
      51             : #ifdef  AUDIO_DEBUG
      52             : #define DPRINTF(x)      if (mpu_debug) printf x
      53             : int     mpu_debug = 0;
      54             : #else
      55             : #define DPRINTF(x)
      56             : #endif
      57             : 
      58             : #define MPU_GETSTATUS(iot, ioh) (bus_space_read_1(iot, ioh, MPU_STATUS))
      59             : 
      60             : struct mpu_isa_softc {
      61             :         struct device sc_dev;
      62             : 
      63             :         struct mpu_softc sc_mpu;
      64             : };
      65             : 
      66             : struct cfattach mpu_isa_ca = {
      67             :         sizeof(struct mpu_isa_softc), mpu_isa_match, mpu_isa_attach
      68             : };
      69             : 
      70             : int
      71           0 : mpu_test (iot, iobase)
      72             :         bus_space_tag_t iot;
      73             :         int iobase;     /* base port number to try */
      74             : {
      75           0 :         bus_space_handle_t ioh;
      76             :         int     i, rc;
      77             : 
      78             :         rc = 0;
      79           0 :         if (bus_space_map(iot, iobase, MPU401_NPORT, 0, &ioh)) {
      80             :                 DPRINTF(("mpu_test: can't map: %x/2\n", iobase));
      81           0 :                 return (0);
      82             :         }
      83             : 
      84             :         DPRINTF(("mpu_test: trying: %x\n", iobase));
      85             : 
      86             :         /*
      87             :          * The following code is a shameless copy of mpu401.c
      88             :          * it is here until a redesign of mpu_find() interface
      89             :          */
      90             : 
      91           0 :         if (MPU_GETSTATUS(iot, ioh) == 0xff)
      92             :                 goto done;
      93             : 
      94           0 :         for (i = 0; i < MPU_MAXWAIT; i++) {
      95           0 :                 if (!(MPU_GETSTATUS(iot, ioh) & MPU_OUTPUT_BUSY)) {
      96             :                         rc = 1;
      97           0 :                         break;
      98             :                 }
      99           0 :                 delay (10);
     100             :         }
     101             :         
     102           0 :         if (rc == 1) {  
     103           0 :                 bus_space_write_1(iot, ioh, MPU_COMMAND, MPU_RESET);
     104             :                 rc = 0;
     105           0 :                 for (i = 0; i < 2 * MPU_MAXWAIT; i++)
     106           0 :                         if (!(MPU_GETSTATUS(iot, ioh) & MPU_INPUT_EMPTY) &&
     107           0 :                             bus_space_read_1(iot, ioh, MPU_DATA) == MPU_ACK) {
     108             :                                 rc = 1;
     109           0 :                                 break;
     110             :                         }
     111             :         }
     112             : done:
     113           0 :         bus_space_unmap(iot, ioh, MPU401_NPORT);
     114             : 
     115           0 :         return (rc);
     116           0 : }
     117             : 
     118             : int
     119           0 : mpu_isa_match(parent, match, aux)
     120             :         struct device *parent;
     121             :         void *match, *aux;
     122             : {
     123           0 :         struct isa_attach_args *ia = aux;
     124             : 
     125           0 :         if (mpu_test(ia->ia_iot, ia->ia_iobase)) {
     126           0 :                 ia->ia_iosize = MPU401_NPORT;
     127           0 :                 return (1);
     128             :         }
     129             : 
     130           0 :         return (0);
     131           0 : }
     132             : 
     133             : void
     134           0 : mpu_isa_attach(parent, self, aux)
     135             :         struct device *parent, *self;
     136             :         void *aux;
     137             : {
     138           0 :         struct mpu_isa_softc *sc = (struct mpu_isa_softc *)self;
     139           0 :         struct isa_attach_args *ia = aux;
     140             : 
     141           0 :         sc->sc_mpu.iot = ia->ia_iot;
     142             : 
     143           0 :         if (bus_space_map (ia->ia_iot, ia->ia_iobase, MPU401_NPORT,
     144           0 :             0, &sc->sc_mpu.ioh)) {
     145           0 :                 printf(": can't map i/o space\n");
     146           0 :                 return;
     147             :         }
     148             : 
     149           0 :         if (!mpu_find(&sc->sc_mpu)) {
     150           0 :                 printf(": find failed\n");
     151           0 :                 return;
     152             :         }
     153             : 
     154           0 :         printf(": generic MPU-401 compatible\n");
     155             : 
     156           0 :         midi_attach_mi(&mpu_midi_hw_if, &sc->sc_mpu, &sc->sc_dev);
     157           0 : }

Generated by: LCOV version 1.13