if_smsh_gxio.c revision 1.1 1 1.1 kiyohara /* $NetBSD: if_smsh_gxio.c,v 1.1 2009/08/09 07:10:13 kiyohara Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2008 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_smsh_gxio.c,v 1.1 2009/08/09 07:10:13 kiyohara Exp $");
30 1.1 kiyohara
31 1.1 kiyohara #include <sys/param.h>
32 1.1 kiyohara #include <sys/device.h>
33 1.1 kiyohara #include <sys/errno.h>
34 1.1 kiyohara #include <sys/bus.h>
35 1.1 kiyohara #include <sys/systm.h>
36 1.1 kiyohara
37 1.1 kiyohara #include <evbarm/gumstix/gumstixvar.h>
38 1.1 kiyohara
39 1.1 kiyohara #include <net/if.h>
40 1.1 kiyohara #include <net/if_ether.h>
41 1.1 kiyohara #include <net/if_media.h>
42 1.1 kiyohara
43 1.1 kiyohara #include <dev/mii/miivar.h>
44 1.1 kiyohara
45 1.1 kiyohara #include <dev/ic/lan9118var.h>
46 1.1 kiyohara #include <dev/ic/lan9118reg.h>
47 1.1 kiyohara
48 1.1 kiyohara #include "locators.h"
49 1.1 kiyohara
50 1.1 kiyohara
51 1.1 kiyohara static int smsh_gxio_match(device_t, struct cfdata *, void *);
52 1.1 kiyohara static void smsh_gxio_attach(device_t, device_t, void *);
53 1.1 kiyohara
54 1.1 kiyohara static int ether_serial_digit = 1;
55 1.1 kiyohara
56 1.1 kiyohara struct smsh_gxio_softc {
57 1.1 kiyohara struct lan9118_softc sc_smsh;
58 1.1 kiyohara void *sc_ih;
59 1.1 kiyohara
60 1.1 kiyohara /*
61 1.1 kiyohara * Board independent DMA stuffs, if uses master DMA.
62 1.1 kiyohara * We use PXA2x0's DMA.
63 1.1 kiyohara */
64 1.1 kiyohara struct dmac_xfer *sc_txfer;
65 1.1 kiyohara struct dmac_xfer *sc_rxfer;
66 1.1 kiyohara };
67 1.1 kiyohara
68 1.1 kiyohara CFATTACH_DECL_NEW(smsh_gxio, sizeof(struct smsh_gxio_softc),
69 1.1 kiyohara smsh_gxio_match, smsh_gxio_attach, NULL, NULL);
70 1.1 kiyohara
71 1.1 kiyohara
72 1.1 kiyohara /* ARGSUSED */
73 1.1 kiyohara static int
74 1.1 kiyohara smsh_gxio_match(device_t parent, struct cfdata *match, void *aux)
75 1.1 kiyohara {
76 1.1 kiyohara struct gxio_attach_args *gxa = aux;
77 1.1 kiyohara bus_space_tag_t iot = gxa->gxa_iot;
78 1.1 kiyohara bus_space_handle_t ioh;
79 1.1 kiyohara uint32_t val;
80 1.1 kiyohara int rv = 0;
81 1.1 kiyohara
82 1.1 kiyohara /* Disallow wildcarded values. */
83 1.1 kiyohara if (gxa->gxa_addr == GXIOCF_ADDR_DEFAULT)
84 1.1 kiyohara return 0;
85 1.1 kiyohara if (gxa->gxa_gpirq == GXIOCF_GPIRQ_DEFAULT)
86 1.1 kiyohara return 0;
87 1.1 kiyohara
88 1.1 kiyohara if (bus_space_map(iot, gxa->gxa_addr, LAN9118_IOSIZE, 0, &ioh) != 0)
89 1.1 kiyohara return 0;
90 1.1 kiyohara
91 1.1 kiyohara bus_space_write_4(iot, ioh, LAN9118_BYTE_TEST, 0);
92 1.1 kiyohara val = bus_space_read_4(iot, ioh, LAN9118_BYTE_TEST);
93 1.1 kiyohara if (val == LAN9118_BYTE_TEST_VALUE)
94 1.1 kiyohara /* Assume we have an SMSC LAN9117 */
95 1.1 kiyohara rv = 1;
96 1.1 kiyohara if (ether_serial_digit > 15)
97 1.1 kiyohara rv = 0;
98 1.1 kiyohara
99 1.1 kiyohara bus_space_unmap(iot, ioh, LAN9118_IOSIZE);
100 1.1 kiyohara return rv;
101 1.1 kiyohara }
102 1.1 kiyohara
103 1.1 kiyohara /* ARGSUSED */
104 1.1 kiyohara static void
105 1.1 kiyohara smsh_gxio_attach(device_t parent, device_t self, void *aux)
106 1.1 kiyohara {
107 1.1 kiyohara struct smsh_gxio_softc *gsc = device_private(self);
108 1.1 kiyohara struct lan9118_softc *sc = &gsc->sc_smsh;
109 1.1 kiyohara struct gxio_attach_args *gxa = aux;
110 1.1 kiyohara
111 1.1 kiyohara aprint_normal("\n");
112 1.1 kiyohara aprint_naive("\n");
113 1.1 kiyohara
114 1.1 kiyohara KASSERT(system_serial_high != 0 || system_serial_low != 0);
115 1.1 kiyohara
116 1.1 kiyohara sc->sc_dev = self;
117 1.1 kiyohara
118 1.1 kiyohara /* Map i/o space. */
119 1.1 kiyohara if (bus_space_map(gxa->gxa_iot, gxa->gxa_addr, LAN9118_IOSIZE, 0,
120 1.1 kiyohara &sc->sc_ioh))
121 1.1 kiyohara panic("sms_gxio_attach: can't map i/o space");
122 1.1 kiyohara sc->sc_iot = gxa->gxa_iot;
123 1.1 kiyohara
124 1.1 kiyohara sc->sc_enaddr[0] = ((system_serial_high >> 8) & 0xfe) | 0x02;
125 1.1 kiyohara sc->sc_enaddr[1] = system_serial_high;
126 1.1 kiyohara sc->sc_enaddr[2] = system_serial_low >> 24;
127 1.1 kiyohara sc->sc_enaddr[3] = system_serial_low >> 16;
128 1.1 kiyohara sc->sc_enaddr[4] = system_serial_low >> 8;
129 1.1 kiyohara sc->sc_enaddr[5] = (system_serial_low & 0xc0) |
130 1.1 kiyohara (1 << 4) | ((ether_serial_digit++) & 0x0f);
131 1.1 kiyohara sc->sc_flags = LAN9118_FLAGS_NO_EEPROM;
132 1.1 kiyohara if (lan9118_attach(sc) != 0) {
133 1.1 kiyohara bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE);
134 1.1 kiyohara return;
135 1.1 kiyohara }
136 1.1 kiyohara
137 1.1 kiyohara /* Establish the interrupt handler. */
138 1.1 kiyohara gsc->sc_ih = gxio_intr_establish(gxa->gxa_sc,
139 1.1 kiyohara gxa->gxa_gpirq, IST_EDGE_FALLING, IPL_NET, lan9118_intr, sc);
140 1.1 kiyohara if (gsc->sc_ih == NULL) {
141 1.1 kiyohara aprint_error_dev(self,
142 1.1 kiyohara "couldn't establish interrupt handler\n");
143 1.1 kiyohara bus_space_unmap(sc->sc_iot, sc->sc_ioh, LAN9118_IOSIZE);
144 1.1 kiyohara return;
145 1.1 kiyohara }
146 1.1 kiyohara }
147