if_sm_pxaip.c revision 1.1 1 /* $NetBSD: if_sm_pxaip.c,v 1.1 2005/06/06 20:24:11 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2005 Antti Kantee. 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. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by The NetBSD
17 * Foundation, Inc. and its contributors.
18 * 4. The name of the company nor the name of the author may be used to
19 * endorse or promote products derived from this software without specific
20 * prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: if_sm_pxaip.c,v 1.1 2005/06/06 20:24:11 pooka Exp $");
37
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41
42 #include <net/if.h>
43 #include <net/if_ether.h>
44 #include <net/if_media.h>
45
46 #include <machine/intr.h>
47 #include <machine/bus.h>
48
49 #include <dev/mii/mii.h>
50 #include <dev/mii/miivar.h>
51
52 #include <dev/ic/smc91cxxreg.h>
53 #include <dev/ic/smc91cxxvar.h>
54
55 #include <arch/arm/xscale/pxa2x0var.h>
56 #include <arch/arm/xscale/pxa2x0_gpio.h>
57
58 #include <arch/evbarm/viper/viper_reg.h>
59
60 static int sm_pxaip_match(struct device *, struct cfdata *, void *);
61 static void sm_pxaip_attach(struct device *, struct device *, void *);
62
63 struct sm_pxaip_softc {
64 struct smc91cxx_softc sc_sm;
65 void *ih;
66 };
67
68 CFATTACH_DECL(sm_pxaip, sizeof(struct sm_pxaip_softc), sm_pxaip_match,
69 sm_pxaip_attach, NULL, NULL);
70
71 static int
72 sm_pxaip_match(struct device *parent, struct cfdata *match, void *aux)
73 {
74 struct pxaip_attach_args *paa = aux;
75
76 if (paa->pxa_addr == VIPER_SMSC_PBASE)
77 return 1;
78 return 0;
79 }
80
81 static void
82 sm_pxaip_attach(struct device *parent, struct device *self, void *aux)
83 {
84 struct sm_pxaip_softc *pxasc = (struct sm_pxaip_softc *)self;
85 struct smc91cxx_softc *sc = &pxasc->sc_sm;
86 struct pxaip_attach_args *paa = aux;
87 bus_space_tag_t bst = &pxa2x0_bs_tag;
88 bus_space_handle_t bsh;
89
90 /* map i/o space */
91 if (bus_space_map(bst, paa->pxa_addr, SMC_IOSIZE, 0, &bsh) != 0) {
92 aprint_error(": sm_pxaip_attach: can't map i/o space");
93 return;
94 }
95
96 /* register the interrupt handler */
97 pxasc->ih = pxa2x0_gpio_intr_establish(paa->pxa_intr, IST_EDGE_RISING,
98 IPL_NET, smc91cxx_intr, sc);
99 if (pxasc->ih == NULL) {
100 aprint_error(": couldn't establish interrupt\n");
101 bus_space_unmap(bst, bsh, SMC_IOSIZE);
102 return;
103 }
104
105 printf("\n");
106
107 /* fill in master sc */
108 sc->sc_bst = bst;
109 sc->sc_bsh = bsh;
110
111 sc->sc_flags = SMC_FLAGS_ENABLED;
112 smc91cxx_attach(sc, NULL);
113 }
114