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