1*f6d93529Sskrll /* $NetBSD: sm_ifpga.c,v 1.2 2013/02/23 08:23:03 skrll Exp $ */
25c979652Sskrll
35c979652Sskrll /*-
45c979652Sskrll * Copyright (c) 2013 Sergio Lopez <slp@sinrega.org>
55c979652Sskrll * All rights reserved.
65c979652Sskrll *
75c979652Sskrll * Redistribution and use in source and binary forms, with or without
85c979652Sskrll * modification, are permitted provided that the following conditions
95c979652Sskrll * are met:
105c979652Sskrll * 1. Redistributions of source code must retain the above copyright
115c979652Sskrll * notice, this list of conditions and the following disclaimer.
125c979652Sskrll * 2. Redistributions in binary form must reproduce the above copyright
135c979652Sskrll * notice, this list of conditions and the following disclaimer in the
145c979652Sskrll * documentation and/or other materials provided with the distribution.
155c979652Sskrll *
165c979652Sskrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
175c979652Sskrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
185c979652Sskrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
195c979652Sskrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
205c979652Sskrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
215c979652Sskrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
225c979652Sskrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
235c979652Sskrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
245c979652Sskrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
255c979652Sskrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
265c979652Sskrll * POSSIBILITY OF SUCH DAMAGE.
275c979652Sskrll */
285c979652Sskrll
295c979652Sskrll #include <sys/cdefs.h>
30*f6d93529Sskrll __KERNEL_RCSID(0, "$NetBSD: sm_ifpga.c,v 1.2 2013/02/23 08:23:03 skrll Exp $");
315c979652Sskrll
325c979652Sskrll #include <sys/param.h>
335c979652Sskrll #include <sys/systm.h>
345c979652Sskrll #include <sys/device.h>
355c979652Sskrll
365c979652Sskrll #include <net/if.h>
375c979652Sskrll #include <net/if_ether.h>
385c979652Sskrll #include <net/if_media.h>
395c979652Sskrll
405c979652Sskrll #include <machine/intr.h>
415c979652Sskrll #include <sys/bus.h>
425c979652Sskrll
435c979652Sskrll #include <dev/mii/mii.h>
445c979652Sskrll #include <dev/mii/miivar.h>
455c979652Sskrll
465c979652Sskrll #include <dev/ic/smc91cxxreg.h>
475c979652Sskrll #include <dev/ic/smc91cxxvar.h>
485c979652Sskrll
495c979652Sskrll #include <evbarm/ifpga/ifpgareg.h>
505c979652Sskrll #include <evbarm/ifpga/ifpgavar.h>
515c979652Sskrll
525c979652Sskrll static int sm_ifpga_match(device_t, cfdata_t, void *);
535c979652Sskrll static void sm_ifpga_attach(device_t, device_t, void *);
545c979652Sskrll
555c979652Sskrll struct sm_ifpga_softc {
565c979652Sskrll struct smc91cxx_softc sc_sm;
575c979652Sskrll void *ih;
585c979652Sskrll };
595c979652Sskrll
605c979652Sskrll CFATTACH_DECL_NEW(sm_ifpga, sizeof(struct sm_ifpga_softc), sm_ifpga_match,
615c979652Sskrll sm_ifpga_attach, NULL, NULL);
625c979652Sskrll
635c979652Sskrll static int
sm_ifpga_match(device_t parent,cfdata_t match,void * aux)645c979652Sskrll sm_ifpga_match(device_t parent, cfdata_t match, void *aux)
655c979652Sskrll {
665c979652Sskrll struct ifpga_attach_args *ifa = aux;
675c979652Sskrll
685c979652Sskrll if (ifa->ifa_addr == IFPGA_SMC911_BASE)
695c979652Sskrll return 1;
705c979652Sskrll return 0;
715c979652Sskrll }
725c979652Sskrll
735c979652Sskrll static void
sm_ifpga_attach(device_t parent,device_t self,void * aux)745c979652Sskrll sm_ifpga_attach(device_t parent, device_t self, void *aux)
755c979652Sskrll {
765c979652Sskrll struct sm_ifpga_softc *isc = device_private(self);
775c979652Sskrll struct smc91cxx_softc *sc = &isc->sc_sm;
785c979652Sskrll struct ifpga_attach_args *ifa = aux;
795c979652Sskrll bus_space_tag_t bst = ifa->ifa_iot;
805c979652Sskrll bus_space_handle_t bsh;
815c979652Sskrll
825c979652Sskrll /* map i/o space */
835c979652Sskrll if (bus_space_map(bst, ifa->ifa_addr, SMC_IOSIZE, 0, &bsh) != 0) {
845c979652Sskrll aprint_error(": sm_ifpga_attach: can't map i/o space");
855c979652Sskrll return;
865c979652Sskrll }
875c979652Sskrll
885c979652Sskrll isc->ih = ifpga_intr_establish(ifa->ifa_irq, IPL_NET, smc91cxx_intr, sc);
895c979652Sskrll if (isc->ih == NULL) {
905c979652Sskrll aprint_error(": couldn't establish interrupt\n");
915c979652Sskrll bus_space_unmap(bst, bsh, SMC_IOSIZE);
925c979652Sskrll return;
935c979652Sskrll }
945c979652Sskrll
95*f6d93529Sskrll aprint_normal("\n");
965c979652Sskrll
975c979652Sskrll /* fill in master sc */
985c979652Sskrll sc->sc_dev = self;
995c979652Sskrll sc->sc_bst = bst;
1005c979652Sskrll sc->sc_bsh = bsh;
1015c979652Sskrll
1025c979652Sskrll sc->sc_flags = SMC_FLAGS_ENABLED;
1035c979652Sskrll smc91cxx_attach(sc, NULL);
1045c979652Sskrll }
1055c979652Sskrll
106