No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / evbarm / gumstix / if_smsh_gxio.c
blobfd720802769a54f3f44b9e96a7831df72b2e15dc
1 /* $NetBSD: if_smsh_gxio.c,v 1.1 2009/08/09 07:10:13 kiyohara Exp $ */
2 /*
3 * Copyright (c) 2008 KIYOHARA Takashi
4 * All rights reserved.
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.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
28 #include <sys/cdefs.h>
29 __KERNEL_RCSID(0, "$NetBSD: if_smsh_gxio.c,v 1.1 2009/08/09 07:10:13 kiyohara Exp $");
31 #include <sys/param.h>
32 #include <sys/device.h>
33 #include <sys/errno.h>
34 #include <sys/bus.h>
35 #include <sys/systm.h>
37 #include <evbarm/gumstix/gumstixvar.h>
39 #include <net/if.h>
40 #include <net/if_ether.h>
41 #include <net/if_media.h>
43 #include <dev/mii/miivar.h>
45 #include <dev/ic/lan9118var.h>
46 #include <dev/ic/lan9118reg.h>
48 #include "locators.h"
51 static int smsh_gxio_match(device_t, struct cfdata *, void *);
52 static void smsh_gxio_attach(device_t, device_t, void *);
54 static int ether_serial_digit = 1;
56 struct smsh_gxio_softc {
57 struct lan9118_softc sc_smsh;
58 void *sc_ih;
61 * Board independent DMA stuffs, if uses master DMA.
62 * We use PXA2x0's DMA.
64 struct dmac_xfer *sc_txfer;
65 struct dmac_xfer *sc_rxfer;
68 CFATTACH_DECL_NEW(smsh_gxio, sizeof(struct smsh_gxio_softc),
69 smsh_gxio_match, smsh_gxio_attach, NULL, NULL);
72 /* ARGSUSED */
73 static int
74 smsh_gxio_match(device_t parent, struct cfdata *match, void *aux)
76 struct gxio_attach_args *gxa = aux;
77 bus_space_tag_t iot = gxa->gxa_iot;
78 bus_space_handle_t ioh;
79 uint32_t val;
80 int rv = 0;
82 /* Disallow wildcarded values. */
83 if (gxa->gxa_addr == GXIOCF_ADDR_DEFAULT)
84 return 0;
85 if (gxa->gxa_gpirq == GXIOCF_GPIRQ_DEFAULT)
86 return 0;
88 if (bus_space_map(iot, gxa->gxa_addr, LAN9118_IOSIZE, 0, &ioh) != 0)
89 return 0;
91 bus_space_write_4(iot, ioh, LAN9118_BYTE_TEST, 0);
92 val = bus_space_read_4(iot, ioh, LAN9118_BYTE_TEST);
93 if (val == LAN9118_BYTE_TEST_VALUE)
94 /* Assume we have an SMSC LAN9117 */
95 rv = 1;
96 if (ether_serial_digit > 15)
97 rv = 0;
99 bus_space_unmap(iot, ioh, LAN9118_IOSIZE);
100 return rv;
103 /* ARGSUSED */
104 static void
105 smsh_gxio_attach(device_t parent, device_t self, void *aux)
107 struct smsh_gxio_softc *gsc = device_private(self);
108 struct lan9118_softc *sc = &gsc->sc_smsh;
109 struct gxio_attach_args *gxa = aux;
111 KASSERT(system_serial_high != 0 || system_serial_low != 0);
113 sc->sc_dev = self;
115 /* Map i/o space. */
116 if (bus_space_map(gxa->gxa_iot, gxa->gxa_addr, LAN9118_IOSIZE, 0,
117 &sc->sc_ioh))
118 panic("sms_gxio_attach: can't map i/o space");
119 sc->sc_iot = gxa->gxa_iot;
121 sc->sc_enaddr[0] = ((system_serial_high >> 8) & 0xfe) | 0x02;
122 sc->sc_enaddr[1] = system_serial_high;
123 sc->sc_enaddr[2] = system_serial_low >> 24;
124 sc->sc_enaddr[3] = system_serial_low >> 16;
125 sc->sc_enaddr[4] = system_serial_low >> 8;
126 sc->sc_enaddr[5] = (system_serial_low & 0xc0) |
127 (1 << 4) | ((ether_serial_digit++) & 0x0f);
128 sc->sc_flags = LAN9118_FLAGS_NO_EEPROM;
129 if (lan9118_attach(sc) != 0) {
130 bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE);
131 return;
134 /* Establish the interrupt handler. */
135 gsc->sc_ih = gxio_intr_establish(gxa->gxa_sc,
136 gxa->gxa_gpirq, IST_EDGE_FALLING, IPL_NET, lan9118_intr, sc);
137 if (gsc->sc_ih == NULL) {
138 aprint_error_dev(self,
139 "couldn't establish interrupt handler\n");
140 bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE);
141 return;