if_ne_mainbus.c revision 1.1 1 1.1 kiyohara /* $NetBSD: if_ne_mainbus.c,v 1.1 2011/02/19 10:46:28 kiyohara Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2010 KIYOHARA Takashi
4 1.1 kiyohara * All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara *
15 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 kiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 kiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1 kiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1 kiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 kiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1 kiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1 kiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
26 1.1 kiyohara *
27 1.1 kiyohara */
28 1.1 kiyohara #include <sys/cdefs.h>
29 1.1 kiyohara __KERNEL_RCSID(0, "$NetBSD: if_ne_mainbus.c,v 1.1 2011/02/19 10:46:28 kiyohara Exp $");
30 1.1 kiyohara
31 1.1 kiyohara #include <sys/param.h>
32 1.1 kiyohara #include <sys/bus.h>
33 1.1 kiyohara #include <sys/device.h>
34 1.1 kiyohara #include <sys/errno.h>
35 1.1 kiyohara
36 1.1 kiyohara #include <machine/autoconf.h>
37 1.1 kiyohara #include <machine/intr.h>
38 1.1 kiyohara #include <machine/mmeye.h>
39 1.1 kiyohara
40 1.1 kiyohara #include <net/if.h>
41 1.1 kiyohara #include <net/if_dl.h>
42 1.1 kiyohara #include <net/if_ether.h>
43 1.1 kiyohara #include <net/if_media.h>
44 1.1 kiyohara
45 1.1 kiyohara #include <dev/ic/dp8390reg.h>
46 1.1 kiyohara #include <dev/ic/dp8390var.h>
47 1.1 kiyohara
48 1.1 kiyohara #include <dev/ic/ne2000reg.h>
49 1.1 kiyohara #include <dev/ic/ne2000var.h>
50 1.1 kiyohara
51 1.1 kiyohara #include "locators.h"
52 1.1 kiyohara
53 1.1 kiyohara static int ne_mainbus_match(device_t, cfdata_t , void *);
54 1.1 kiyohara static void ne_mainbus_attach(device_t, device_t, void *);
55 1.1 kiyohara
56 1.1 kiyohara CFATTACH_DECL_NEW(ne_mainbus, sizeof(struct ne2000_softc),
57 1.1 kiyohara ne_mainbus_match, ne_mainbus_attach, NULL, NULL);
58 1.1 kiyohara
59 1.1 kiyohara static int
60 1.1 kiyohara ne_mainbus_match(device_t parent, cfdata_t match, void *aux)
61 1.1 kiyohara {
62 1.1 kiyohara struct mainbus_attach_args *ma = aux;
63 1.1 kiyohara bus_space_tag_t nict, asict;
64 1.1 kiyohara bus_space_handle_t nich, asich;
65 1.1 kiyohara int rv = 0;
66 1.1 kiyohara
67 1.1 kiyohara if (strcmp(ma->ma_name, match->cf_name) != 0)
68 1.1 kiyohara return 0;
69 1.1 kiyohara
70 1.1 kiyohara /* Disallow wildcarded values. */
71 1.1 kiyohara if (ma->ma_addr1 == MAINBUSCF_ADDR1_DEFAULT ||
72 1.1 kiyohara ma->ma_irq1 == MAINBUSCF_IRQ1_DEFAULT)
73 1.1 kiyohara return 0;
74 1.1 kiyohara
75 1.1 kiyohara /* Make sure this is a valid NE[12]000 i/o address. */
76 1.1 kiyohara if ((ma->ma_addr1 & 0x1f) != 0)
77 1.1 kiyohara return 0;
78 1.1 kiyohara
79 1.1 kiyohara /* Map i/o space. */
80 1.1 kiyohara nict = SH3_BUS_SPACE_PCMCIA_IO;
81 1.1 kiyohara if (bus_space_map(nict, ma->ma_addr1, NE2000_NPORTS, 0, &nich))
82 1.1 kiyohara return 0;
83 1.1 kiyohara
84 1.1 kiyohara if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
85 1.1 kiyohara NE2000_ASIC_NPORTS, &asich))
86 1.1 kiyohara goto out;
87 1.1 kiyohara asict = nict;
88 1.1 kiyohara
89 1.1 kiyohara /* Look for an NE2000-compatible card. */
90 1.1 kiyohara rv = ne2000_detect(nict, nich, asict, asich);
91 1.1 kiyohara
92 1.1 kiyohara out:
93 1.1 kiyohara bus_space_unmap(nict, nich, NE2000_NPORTS);
94 1.1 kiyohara return rv;
95 1.1 kiyohara }
96 1.1 kiyohara
97 1.1 kiyohara void
98 1.1 kiyohara ne_mainbus_attach(device_t parent, device_t self, void *aux)
99 1.1 kiyohara {
100 1.1 kiyohara struct ne2000_softc *sc = device_private(self);
101 1.1 kiyohara struct dp8390_softc *dsc = &sc->sc_dp8390;
102 1.1 kiyohara struct mainbus_attach_args *ma = aux;
103 1.1 kiyohara bus_space_tag_t nict, asict;
104 1.1 kiyohara bus_space_handle_t nich, asich;
105 1.1 kiyohara int netype;
106 1.1 kiyohara const char *typestr;
107 1.1 kiyohara void *ih;
108 1.1 kiyohara
109 1.1 kiyohara dsc->sc_dev = self;
110 1.1 kiyohara aprint_normal("\n");
111 1.1 kiyohara
112 1.1 kiyohara /* Map i/o space. */
113 1.1 kiyohara nict = SH3_BUS_SPACE_PCMCIA_IO;
114 1.1 kiyohara if (bus_space_map(nict, ma->ma_addr1, NE2000_NPORTS, 0, &nich)) {
115 1.1 kiyohara aprint_error_dev(self, "can't map i/o space\n");
116 1.1 kiyohara return;
117 1.1 kiyohara }
118 1.1 kiyohara
119 1.1 kiyohara if (bus_space_subregion(nict, nich, NE2000_ASIC_OFFSET,
120 1.1 kiyohara NE2000_ASIC_NPORTS, &asich)) {
121 1.1 kiyohara aprint_error_dev(self, "can't subregion i/o space\n");
122 1.1 kiyohara return;
123 1.1 kiyohara }
124 1.1 kiyohara asict = nict;
125 1.1 kiyohara
126 1.1 kiyohara dsc->sc_regt = nict;
127 1.1 kiyohara dsc->sc_regh = nich;
128 1.1 kiyohara
129 1.1 kiyohara sc->sc_asict = asict;
130 1.1 kiyohara sc->sc_asich = asich;
131 1.1 kiyohara
132 1.1 kiyohara /*
133 1.1 kiyohara * Detect it again, so we can print some information about the
134 1.1 kiyohara * interface.
135 1.1 kiyohara */
136 1.1 kiyohara netype = ne2000_detect(nict, nich, asict, asich);
137 1.1 kiyohara switch (netype) {
138 1.1 kiyohara case NE2000_TYPE_RTL8019:
139 1.1 kiyohara typestr = "NE2000 (RTL8019)";
140 1.1 kiyohara break;
141 1.1 kiyohara
142 1.1 kiyohara case NE2000_TYPE_NE1000:
143 1.1 kiyohara case NE2000_TYPE_NE2000:
144 1.1 kiyohara default:
145 1.1 kiyohara aprint_error_dev(self, "where did the card go?!\n");
146 1.1 kiyohara return;
147 1.1 kiyohara }
148 1.1 kiyohara
149 1.1 kiyohara aprint_normal_dev(self, "%s Ethernet\n", typestr);
150 1.1 kiyohara
151 1.1 kiyohara /* This interface is always enabled. */
152 1.1 kiyohara dsc->sc_enabled = 1;
153 1.1 kiyohara
154 1.1 kiyohara /*
155 1.1 kiyohara * Do generic NE2000 attach. This will read the station address
156 1.1 kiyohara * from the EEPROM.
157 1.1 kiyohara */
158 1.1 kiyohara ne2000_attach(sc, NULL);
159 1.1 kiyohara
160 1.1 kiyohara /* Establish the interrupt handler. */
161 1.1 kiyohara ih = mmeye_intr_establish(ma->ma_irq1, IST_LEVEL, IPL_NET,
162 1.1 kiyohara dp8390_intr, dsc);
163 1.1 kiyohara if (ih == NULL)
164 1.1 kiyohara aprint_error_dev(self,
165 1.1 kiyohara "couldn't establish interrupt handler\n");
166 1.1 kiyohara }
167