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