xref: /netbsd-src/sys/arch/evbsh3/ap_ms104_sh4/if_sm_mainbus.c (revision c2f76ff004a2cb67efe5b12d97bd3ef7fe89e18d)
1 /*	$NetBSD: if_sm_mainbus.c,v 1.1 2010/04/06 15:54:29 nonaka Exp $	*/
2 
3 /*-
4  * Copyright (c) 2009 NONAKA Kimihiro <nonaka@netbsd.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  */
28 
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: if_sm_mainbus.c,v 1.1 2010/04/06 15:54:29 nonaka Exp $");
31 
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 
36 #include <net/if.h>
37 #include <net/if_ether.h>
38 #include <net/if_media.h>
39 
40 #include <machine/autoconf.h>
41 #include <machine/intr.h>
42 #include <machine/bus.h>
43 
44 #include <dev/mii/mii.h>
45 #include <dev/mii/miivar.h>
46 
47 #include <dev/ic/smc91cxxreg.h>
48 #include <dev/ic/smc91cxxvar.h>
49 
50 #include <evbsh3/ap_ms104_sh4/ap_ms104_sh4reg.h>
51 #include <evbsh3/ap_ms104_sh4/ap_ms104_sh4var.h>
52 
53 static int	sm_mainbus_match(device_t, cfdata_t, void *);
54 static void	sm_mainbus_attach(device_t, device_t, void *);
55 
56 struct sm_mainbus_softc {
57 	struct smc91cxx_softc sc_sm;
58 
59 	void *sc_ih;
60 };
61 
62 CFATTACH_DECL(sm_mainbus, sizeof(struct sm_mainbus_softc),
63     sm_mainbus_match, sm_mainbus_attach, NULL, NULL);
64 
65 static int
66 sm_mainbus_match(device_t parent, cfdata_t cf, void *aux)
67 {
68 	struct mainbus_attach_args *maa = (struct mainbus_attach_args *)aux;
69 
70 	if (strcmp(maa->ma_name, "sm") != 0)
71 		return 0;
72 	return 1;
73 }
74 
75 static void
76 sm_mainbus_attach(device_t parent, device_t self, void *aux)
77 {
78 	struct sm_mainbus_softc *smsc = device_private(self);
79 	struct smc91cxx_softc *sc = &smsc->sc_sm;
80 	bus_space_tag_t bst = &ap_ms104_sh4_bus_io;
81 	bus_space_handle_t bsh;
82 
83 	aprint_naive("\n");
84 	aprint_normal("\n");
85 
86 	/* map i/o space */
87 	if (bus_space_map(bst, 0x08000000, SMC_IOSIZE, 0, &bsh) != 0) {
88 		aprint_error_dev(self, "can't map i/o space");
89 		return;
90 	}
91 
92 	/* register the interrupt handler */
93 	smsc->sc_ih = extintr_establish(EXTINTR_INTR_SMC91C111, IST_LEVEL,
94 	    IPL_NET, smc91cxx_intr, sc);
95 	if (smsc->sc_ih == NULL) {
96 		aprint_error_dev(self, "couldn't establish interrupt\n");
97 		bus_space_unmap(bst, bsh, SMC_IOSIZE);
98 		return;
99 	}
100 
101 	/* fill in master sc */
102 	sc->sc_bst = bst;
103 	sc->sc_bsh = bsh;
104 
105 	sc->sc_flags = SMC_FLAGS_ENABLED;
106 	smc91cxx_attach(sc, NULL);
107 }
108