11.2Sskrll/*	$NetBSD: sm_ifpga.c,v 1.2 2013/02/23 08:23:03 skrll Exp $	*/
21.1Sskrll
31.1Sskrll/*-
41.1Sskrll * Copyright (c) 2013 Sergio Lopez <slp@sinrega.org>
51.1Sskrll * All rights reserved.
61.1Sskrll *
71.1Sskrll * Redistribution and use in source and binary forms, with or without
81.1Sskrll * modification, are permitted provided that the following conditions
91.1Sskrll * are met:
101.1Sskrll * 1. Redistributions of source code must retain the above copyright
111.1Sskrll *    notice, this list of conditions and the following disclaimer.
121.1Sskrll * 2. Redistributions in binary form must reproduce the above copyright
131.1Sskrll *    notice, this list of conditions and the following disclaimer in the
141.1Sskrll *    documentation and/or other materials provided with the distribution.
151.1Sskrll *
161.1Sskrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
171.1Sskrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
181.1Sskrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
191.1Sskrll * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
201.1Sskrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211.1Sskrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221.1Sskrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231.1Sskrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241.1Sskrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
251.1Sskrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
261.1Sskrll * POSSIBILITY OF SUCH DAMAGE.
271.1Sskrll */
281.1Sskrll
291.1Sskrll#include <sys/cdefs.h>
301.2Sskrll__KERNEL_RCSID(0, "$NetBSD: sm_ifpga.c,v 1.2 2013/02/23 08:23:03 skrll Exp $");
311.1Sskrll
321.1Sskrll#include <sys/param.h>
331.1Sskrll#include <sys/systm.h>
341.1Sskrll#include <sys/device.h>
351.1Sskrll
361.1Sskrll#include <net/if.h>
371.1Sskrll#include <net/if_ether.h>
381.1Sskrll#include <net/if_media.h>
391.1Sskrll
401.1Sskrll#include <machine/intr.h>
411.1Sskrll#include <sys/bus.h>
421.1Sskrll
431.1Sskrll#include <dev/mii/mii.h>
441.1Sskrll#include <dev/mii/miivar.h>
451.1Sskrll
461.1Sskrll#include <dev/ic/smc91cxxreg.h>
471.1Sskrll#include <dev/ic/smc91cxxvar.h>
481.1Sskrll
491.1Sskrll#include <evbarm/ifpga/ifpgareg.h>
501.1Sskrll#include <evbarm/ifpga/ifpgavar.h>
511.1Sskrll
521.1Sskrllstatic int	sm_ifpga_match(device_t, cfdata_t, void *);
531.1Sskrllstatic void	sm_ifpga_attach(device_t, device_t, void *);
541.1Sskrll
551.1Sskrllstruct sm_ifpga_softc {
561.1Sskrll	struct smc91cxx_softc sc_sm;
571.1Sskrll	void *ih;
581.1Sskrll};
591.1Sskrll
601.1SskrllCFATTACH_DECL_NEW(sm_ifpga, sizeof(struct sm_ifpga_softc), sm_ifpga_match,
611.1Sskrll    sm_ifpga_attach, NULL, NULL);
621.1Sskrll
631.1Sskrllstatic int
641.1Sskrllsm_ifpga_match(device_t parent, cfdata_t match, void *aux)
651.1Sskrll{
661.1Sskrll	struct ifpga_attach_args *ifa = aux;
671.1Sskrll
681.1Sskrll	if (ifa->ifa_addr == IFPGA_SMC911_BASE)
691.1Sskrll		return 1;
701.1Sskrll	return 0;
711.1Sskrll}
721.1Sskrll
731.1Sskrllstatic void
741.1Sskrllsm_ifpga_attach(device_t parent, device_t self, void *aux)
751.1Sskrll{
761.1Sskrll	struct sm_ifpga_softc *isc = device_private(self);
771.1Sskrll	struct smc91cxx_softc *sc = &isc->sc_sm;
781.1Sskrll	struct ifpga_attach_args *ifa = aux;
791.1Sskrll	bus_space_tag_t bst = ifa->ifa_iot;
801.1Sskrll	bus_space_handle_t bsh;
811.1Sskrll
821.1Sskrll	/* map i/o space */
831.1Sskrll	if (bus_space_map(bst, ifa->ifa_addr, SMC_IOSIZE, 0, &bsh) != 0) {
841.1Sskrll		aprint_error(": sm_ifpga_attach: can't map i/o space");
851.1Sskrll		return;
861.1Sskrll	}
871.1Sskrll
881.1Sskrll 	isc->ih = ifpga_intr_establish(ifa->ifa_irq, IPL_NET, smc91cxx_intr, sc);
891.1Sskrll	if (isc->ih == NULL) {
901.1Sskrll		aprint_error(": couldn't establish interrupt\n");
911.1Sskrll		bus_space_unmap(bst, bsh, SMC_IOSIZE);
921.1Sskrll		return;
931.1Sskrll	}
941.1Sskrll
951.2Sskrll	aprint_normal("\n");
961.1Sskrll
971.1Sskrll	/* fill in master sc */
981.1Sskrll	sc->sc_dev = self;
991.1Sskrll	sc->sc_bst = bst;
1001.1Sskrll	sc->sc_bsh = bsh;
1011.1Sskrll
1021.1Sskrll	sc->sc_flags = SMC_FLAGS_ENABLED;
1031.1Sskrll	smc91cxx_attach(sc, NULL);
1041.1Sskrll}
1051.1Sskrll
106