Home | History | Annotate | Line # | Download | only in ieee1394
fwohci.c revision 1.1
      1 /*-
      2  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      3  * All rights reserved.
      4  *
      5  * This code is derived from software contributed to The NetBSD Foundation
      6  * by Matt Thomas of 3am Software Foundry.
      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  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *        This product includes software developed by the NetBSD
     19  *        Foundation, Inc. and its contributors.
     20  * 4. Neither the name of The NetBSD Foundation nor the names of its
     21  *    contributors may be used to endorse or promote products derived
     22  *    from this software without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     25  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     26  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     27  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     28  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     31  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     32  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     33  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     34  * POSSIBILITY OF SUCH DAMAGE.
     35  */
     36 
     37 #include <sys/param.h>
     38 #include <sys/types.h>
     39 #include <sys/socket.h>
     40 #include <sys/device.h>
     41 
     42 #include <machine/bus.h>
     43 
     44 #include <dev/ieee1394/ieee1394reg.h>
     45 #include <dev/ieee1394/fwohcireg.h>
     46 
     47 #include <dev/ieee1394/ieee1394var.h>
     48 #include <dev/ieee1394/fwohcivar.h>
     49 
     50 static const char * const ieee1394_speeds[] = { IEEE1394_SPD_STRINGS };
     51 
     52 int
     53 fwohci_init(struct fwohci_softc *sc)
     54 {
     55 	u_int32_t val;
     56 
     57 	/* What dialect of OHCI is this device?
     58 	 */
     59 	val = OHCI_CSR_READ(sc, OHCI_REG_Version);
     60 	printf("%s: OHCI %u.%u", sc->sc_sc1394.sc1394_dev.dv_xname,
     61 	    OHCI_Version_GET_Version(val), OHCI_Version_GET_Revision(val));
     62 
     63 	/* Is the Global UID ROM present?
     64 	 */
     65 	if ((val & OHCI_Version_GUID_ROM) == 0) {
     66 		printf("\n%x: fatal: no global UID ROM\n", sc->sc_sc1394.sc1394_dev.dv_xname);
     67 		return -1;
     68 	}
     69 
     70 	/* Extract the Global UID
     71 	 */
     72 	val = OHCI_CSR_READ(sc, OHCI_REG_GUIDHi);
     73 	sc->sc_sc1394.sc1394_guid[0] = (val >> 24) & 0xff;
     74 	sc->sc_sc1394.sc1394_guid[1] = (val >> 16) & 0xff;
     75 	sc->sc_sc1394.sc1394_guid[2] = (val >>  8) & 0xff;
     76 	sc->sc_sc1394.sc1394_guid[3] = (val >>  0) & 0xff;
     77 
     78 	val = OHCI_CSR_READ(sc, OHCI_REG_GUIDLo);
     79 	sc->sc_sc1394.sc1394_guid[4] = (val >> 24) & 0xff;
     80 	sc->sc_sc1394.sc1394_guid[5] = (val >> 16) & 0xff;
     81 	sc->sc_sc1394.sc1394_guid[6] = (val >>  8) & 0xff;
     82 	sc->sc_sc1394.sc1394_guid[7] = (val >>  0) & 0xff;
     83 
     84 	printf(", %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x",
     85 	    sc->sc_sc1394.sc1394_guid[0], sc->sc_sc1394.sc1394_guid[1],
     86 	    sc->sc_sc1394.sc1394_guid[2], sc->sc_sc1394.sc1394_guid[3],
     87 	    sc->sc_sc1394.sc1394_guid[4], sc->sc_sc1394.sc1394_guid[5],
     88 	    sc->sc_sc1394.sc1394_guid[6], sc->sc_sc1394.sc1394_guid[7]);
     89 
     90 	/* Get the maximum link speed and receive size
     91 	 */
     92 	val = OHCI_CSR_READ(sc, OHCI_REG_BusOptions);
     93 	sc->sc_sc1394.sc1394_link_speed =
     94 	    (val & OHCI_BusOptions_LinkSpd_MASK)
     95 		>> OHCI_BusOptions_LinkSpd_BITPOS;
     96 	if (sc->sc_sc1394.sc1394_link_speed < IEEE1394_SPD_MAX) {
     97 		printf(", %s", ieee1394_speeds[sc->sc_sc1394.sc1394_link_speed]);
     98 	} else {
     99 		printf(", unknown speed %u", sc->sc_sc1394.sc1394_link_speed);
    100 	}
    101 
    102 	/* MaxRec is encoded as log2(max_rec_octets)-1
    103 	 */
    104 	sc->sc_sc1394.sc1394_max_receive =
    105 	    1 << (((val & OHCI_BusOptions_MaxRec_MASK)
    106 		       >> OHCI_BusOptions_MaxRec_BITPOS) + 1);
    107 	printf(", %u byte packets max", sc->sc_sc1394.sc1394_max_receive);
    108 
    109 	printf("\n");
    110 	return 0;
    111 }
    112 
    113 int
    114 fwohci_intr(void *arg)
    115 {
    116 	struct fwohci_softc * const sc = arg;
    117 	int progress = 0;
    118 
    119 	for (;;) {
    120 		u_int32_t intmask = OHCI_CSR_READ(sc, OHCI_REG_IntEventClear);
    121 		if (intmask == 0)
    122 			return progress;
    123 		OHCI_CSR_WRITE(sc, OHCI_REG_IntEventClear, intmask);
    124 		progress = 1;
    125 	}
    126 }
    127