/*-
* Copyright (c) 1998 maximum entropy. All rights reserved.
* Copyright (c) 1997 Leo Weppelman. All rights reserved.
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Ralph Campbell and Rick Macklem.
*
* 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.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#)if_le.c 8.2 (Berkeley) 11/16/93
*/
/*-
* Copyright (c) 1995 Charles M. Hannum. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Ralph Campbell and Rick Macklem.
*
* 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.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
*
* @(#)if_le.c 8.2 (Berkeley) 11/16/93
*/
/*
* All cards except BVME410 have 64KB RAM. However,
* - On the Riebl cards the area between the offsets 0xee70-0xeec0 is used
* to store config data.
* - On PAM and ROTHRON, mem_addr cannot be mapped if reg_addr is already
* mapped because they are overwrapped. Just use 32KB as Linux does.
*/
static struct le_addresses {
u_long reg_addr;
u_long mem_addr;
int irq;
int reg_size;
int mem_size;
int type_hint;
} lestd[] = {
{ 0xfe00fff0, 0xfe010000, IRQUNK, 16, 64*1024,
LE_OLD_RIEBL|LE_NEW_RIEBL }, /* Riebl */
{ 0xfecffff0, 0xfecf0000, 5, 16, 32*1024,
LE_PAM }, /* PAM */
{ 0xfecffff0, 0xfecf0000, 5, 16, 32*1024,
LE_ROTHRON }, /* Rhotron */
{ 0xfeff4100, 0xfe000000, 4, 8, VMECF_MEMSIZ_DEFAULT,
LE_BVME410 } /* BVME410 */
};
#define NLESTD __arraycount(lestd)
/*
* Default mac for RIEBL cards without a (working) battery. The first 4 bytes
* are the manufacturer id.
*/
static const uint8_t riebl_def_mac[] = {
0x00, 0x00, 0x36, 0x04, 0x00, 0x00
};
/*
* Test accesibility of register and memory area
*/
if (!bus_space_peek_2(*iot, *ioh, LER_RDP))
return 0;
if (!bus_space_peek_1(*memt, *memh, 0))
return 0;
/*
* Test for writable memory
*/
bus_space_write_2(*memt, *memh, 0, 0xa5a5);
if (bus_space_read_2(*memt, *memh, 0) != 0xa5a5)
return 0;
/*
* Test writability of selector port.
*/
bus_space_write_2(*iot, *ioh, LER_RAP, LE_CSR1);
if (bus_space_read_2(*iot, *ioh, LER_RAP) != LE_CSR1)
return 0;
/*
* Do a small register test
*/
bus_space_write_2(*iot, *ioh, LER_RAP, LE_CSR0);
bus_space_write_2(*iot, *ioh, LER_RDP, LE_C0_INIT | LE_C0_STOP);
if (bus_space_read_2(*iot, *ioh, LER_RDP) != LE_C0_STOP)
return 0;
/*
* Interrupt mess. Because the card's interrupt is hardwired to either
* ipl5 or ipl3 (mostly on ipl5) and raising splnet to spl5() just won't do
* (it kills the serial at the least), we use a 2-level interrupt scheme. The
* card interrupt is routed to 'le_intr'. If the previous ipl was below
* splnet, just call the mi-function. If not, save the interrupt status,
* turn off card interrupts (the card is *very* persistent) and arrange
* for a softint 'callback' through 'lepseudointr'.
*/
static int
le_intr(struct le_softc *lesc, int sr)
{
struct lance_softc *sc = &lesc->sc_am7990.lsc;
uint16_t csr0;
/*
* Get MAC address
*/
switch (lesc->sc_type) {
case LE_OLD_RIEBL:
memcpy(sc->sc_enaddr, riebl_def_mac, sizeof(sc->sc_enaddr));
break;
case LE_NEW_RIEBL:
for (i = 0; i < sizeof(sc->sc_enaddr); i++)
sc->sc_enaddr[i] =
bus_space_read_1(memt, memh, i + RIEBL_MAC_ADDR);
break;
case LE_PAM:
i = bus_space_read_1(iot, ioh, LER_EEPROM);
for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
sc->sc_enaddr[i] =
(bus_space_read_2(memt, memh, 2 * i) << 4) |
(bus_space_read_2(memt, memh, 2 * i + 1) & 0xf);
}
i = bus_space_read_1(iot, ioh, LER_MEME);
break;
case LE_BVME410:
for (i = 0; i < (sizeof(sc->sc_enaddr) >> 1); i++) {
uint16_t tmp;
if ((lesc->sc_type == LE_OLD_RIEBL) || (lesc->sc_type == LE_NEW_RIEBL))
riebl_skip_reserved_area(sc);
/*
* XXX: We always use uservector 64....
*/
if ((lesc->sc_intr = intr_establish(64, USER_VEC, 0,
(hw_ifun_t)le_intr, lesc)) == NULL) {
aprint_error("le_vme_attach: Can't establish interrupt\n");
return;
}
/*
* Notify the card of the vector
*/
switch (lesc->sc_type) {
case LE_OLD_RIEBL:
case LE_NEW_RIEBL:
bus_space_write_2(memt, memh, RIEBL_IVEC_ADDR, 64 + 64);
break;
case LE_PAM:
bus_space_write_1(iot, ioh, LER_IVEC, 64 + 64);
break;
case LE_BVME410:
bus_space_write_2(iot, ioh, BVME410_IVEC, 64 + 64);
break;
}
/*
* Unmask the VME-interrupt we're on
*/
if ((machineid & ATARI_TT) != 0)
SCU->vme_mask |= 1 << va->va_irq;
}
/*
* True if 'addr' containe within [start,len]
*/
#define WITHIN(start, len, addr) \
((addr >= start) && ((addr) <= ((start) + (len))))
static void
riebl_skip_reserved_area(struct lance_softc *sc)
{
int offset = 0;
int i;
for (i = 0; i < sc->sc_nrbuf; i++) {
if (WITHIN(sc->sc_rbufaddr[i], LEBLEN, RIEBL_RES_START) ||
WITHIN(sc->sc_rbufaddr[i], LEBLEN, RIEBL_RES_END)) {
offset = RIEBL_RES_END - sc->sc_rbufaddr[i];
}
sc->sc_rbufaddr[i] += offset;
}
for (i = 0; i < sc->sc_ntbuf; i++) {
if (WITHIN(sc->sc_tbufaddr[i], LEBLEN, RIEBL_RES_START) ||
WITHIN(sc->sc_tbufaddr[i], LEBLEN, RIEBL_RES_END)) {
offset = RIEBL_RES_END - sc->sc_tbufaddr[i];
}
sc->sc_tbufaddr[i] += offset;
}
}
static int
nm93c06_read(bus_space_tag_t iot, bus_space_handle_t ioh, int nm93c06reg)
{
int bar;
int shift;
int bits = 0x180 | (nm93c06reg & 0xf);
int data = 0;
bar = 1 << BVME410_CS_SHIFT;
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(1); /* tCSS = 1 us */
for (shift = 9; shift >= 0; shift--) {
if (((bits >> shift) & 1) == 1)
bar |= 1 << BVME410_DIN_SHIFT;
else
bar &= ~(1 << BVME410_DIN_SHIFT);
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(1); /* tDIS = 0.4 us */
bar |= 1 << BVME410_CLK_SHIFT;
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(2); /* tSKH = 1 us, tSKH + tSKL >= 4 us */
bar &= ~(1 << BVME410_CLK_SHIFT);
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(2); /* tSKL = 1 us, tSKH + tSKL >= 4 us */
}
bar &= ~(1 << BVME410_DIN_SHIFT);
for (shift = 15; shift >= 0; shift--) {
delay(1); /* tDIS = 100 ns, BVM manual says 0.4 us */
bar |= 1 << BVME410_CLK_SHIFT;
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(2); /* tSKH = 1 us, tSKH + tSKL >= 4 us */
data |= (bus_space_read_2(iot, ioh, BVME410_BAR) & 1) << shift;
bar &= ~(1 << BVME410_CLK_SHIFT);
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(2); /* tSKL = 1 us, tSKH + tSKL >= 4 us */
}
bar &= ~(1 << BVME410_CS_SHIFT);
bus_space_write_2(iot, ioh, BVME410_BAR, bar);
delay(1); /* tCS = 1 us */
return data;
}
static int
bvme410_probe(bus_space_tag_t iot, bus_space_handle_t ioh)
{
if (!bus_space_peek_2(iot, ioh, BVME410_IVEC))
return 0;