summaryrefslogtreecommitdiff
path: root/sys/arch/evbarm/mini2440/if_dm_mini2440.c
blob: 6217452ac152a6c3b9767be40bf60e15ef1bee59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*-
 * Copyright (c) 2012 The NetBSD Foundation, Inc.
 * All rights reserved.
 *
 * This code is derived from software contributed to The NetBSD Foundation
 * by Paul Fleischer <paul@xpg.dk>
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
#include <sys/cdefs.h>

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/socket.h>
#include <sys/device.h>
#include <sys/time.h>

#include <net/if.h>
#include <net/if_ether.h>
#include <net/if_media.h>

#include <sys/bus.h>
#include <machine/intr.h>

#include <arch/arm/s3c2xx0/s3c2440reg.h>
#include <arch/arm/s3c2xx0/s3c2440var.h>

#include <arch/arm/s3c2xx0/s3c2440_dma.h>

#include <dev/ic/dm9000var.h>
#include <dev/ic/dm9000reg.h>

#include "opt_mini2440.h"

int	dme_ssextio_match(device_t, cfdata_t, void *);
void	dme_ssextio_attach(device_t, device_t, void *);

CFATTACH_DECL_NEW(dme_ssextio, sizeof(struct dme_softc),
    dme_ssextio_match, dme_ssextio_attach, NULL, NULL);

int
dme_ssextio_match(device_t parent, cfdata_t cf, void *aux)
{
	struct s3c2xx0_attach_args *sa = aux;
	bus_space_tag_t iot = sa->sa_iot;
	bus_space_handle_t ioh;
	vaddr_t ioaddr;
	struct dme_softc sc; /* Used to temporarily access the device for
			       probing */
	int have_io = 0;
	int result = 0;
	uint8_t vendorId[2];
	uint8_t productId[2];

	/* Map memory to access the device during probing */
	ioaddr = sa->sa_addr;
	if (bus_space_map(iot, ioaddr, DM9000_IOSIZE, 0, &ioh))
		goto out;
	have_io = 1;

	/* Zero the device description */
	memset(&sc, 0, sizeof sc);
	sc.sc_iot = iot;
	sc.sc_ioh = ioh;
	sc.dme_io = 0x0;
	sc.dme_data = 0x4;

	vendorId[0] = dme_read(&sc, DM9000_VID0);
	vendorId[1] = dme_read(&sc, DM9000_VID1);

	productId[0] = dme_read(&sc, DM9000_PID0);
	productId[1] = dme_read(&sc, DM9000_PID1);

	if (vendorId[0] == 0x46 && vendorId[1] == 0x0a &&
	    productId[0] == 0x00 && productId[1] == 0x90 ) {
		result = 1;
	}

out:
	if (have_io)
		bus_space_unmap(iot, ioh, DM9000_IOSIZE);

	return result;
}


void
dme_ssextio_attach(device_t parent, device_t self, void *aux)
{
	struct dme_softc	   *sc = device_private(self);
	struct s3c2xx0_attach_args *sa = aux;
	vaddr_t			    ioaddr;
	const uint8_t		*enaddr;
	prop_data_t		ea;

#ifdef MINI2440_ETHER_ADDR_FIXED
	static uint8_t enaddr_default[ETHER_ADDR_LEN] = {MINI2440_ETHER_ADDR_FIXED};
#endif

	sc->sc_iot = sa->sa_iot;
	sc->sc_dev = self;

	ioaddr = sa->sa_addr;
	if (bus_space_map(sc->sc_iot, ioaddr, DM9000_IOSIZE, 0, &sc->sc_ioh)) {
		aprint_error(": unable to map i/o space\n");
		return;
	}


	sc->sc_ih = s3c2440_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING, dme_intr, sc);
	if (sc->sc_ih == NULL) {
		aprint_error(": unable to establish interrupt\n");
		return;
	}

	sc->dme_io = 0x0;
	sc->dme_data = 0x4;

	aprint_normal("\n");

	ea = prop_dictionary_get(device_properties(self), "mac-address");
	if( ea != NULL ) {
		KASSERT(prop_object_type(ea) == PROP_TYPE_DATA);
		KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN);
		enaddr = prop_data_data_nocopy(ea);
	} else {
#ifdef MINI2440_ETHER_ADDR_FIXED
		enaddr = &enaddr_default;
#else
		aprint_error_dev(self, "Unable to get mac-address property\n");
		return;
#endif
	}

	dme_attach(sc, enaddr);
}