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