1 /* $NetBSD: if_ate_mca.c,v 1.20 2008/04/12 06:27:01 tsutsui Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * Driver for ATI AT1720X MCA cards based on Fujitsu MB8696xA controller.
36 #include <sys/cdefs.h>
37 __KERNEL_RCSID(0, "$NetBSD: if_ate_mca.c,v 1.20 2008/04/12 06:27:01 tsutsui Exp $");
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/socket.h>
43 #include <sys/syslog.h>
46 #include <net/if_ether.h>
47 #include <net/if_media.h>
52 #include <dev/ic/mb86960reg.h>
53 #include <dev/ic/mb86960var.h>
55 #include <dev/mca/mcavar.h>
56 #include <dev/mca/mcadevs.h>
58 int ate_mca_match(device_t
, cfdata_t
, void *);
59 void ate_mca_attach(device_t
, device_t
, void *);
60 static void ate_mca_detect(bus_space_tag_t
, bus_space_handle_t
,
61 uint8_t enaddr
[ETHER_ADDR_LEN
]);
63 #define ATE_NPORTS 0x20
66 struct mb86960_softc sc_mb86960
; /* real "mb86960" softc */
68 /* MCA-specific goo. */
69 void *sc_ih
; /* interrupt cookie */
72 CFATTACH_DECL_NEW(ate_mca
, sizeof(struct ate_softc
),
73 ate_mca_match
, ate_mca_attach
, NULL
, NULL
);
75 static const struct ate_mca_product
{
76 uint32_t at_prodid
; /* MCA product ID */
77 const char *at_name
; /* device name */
78 int at_type
; /* device type */
79 } ate_mca_products
[] = {
80 { MCA_PRODUCT_AT1720T
, "ATI AT1720T", FE_TYPE_AT1700T
},
81 { MCA_PRODUCT_AT1720BT
, "ATI AT1720BT", FE_TYPE_AT1700BT
},
82 { MCA_PRODUCT_AT1720AT
, "ATI AT1720AT", FE_TYPE_AT1700AT
},
83 { MCA_PRODUCT_AT1720FT
, "ATI AT1720FT", FE_TYPE_AT1700FT
},
87 static const struct ate_mca_product
*ate_mca_lookup(uint32_t);
89 static const struct ate_mca_product
*
90 ate_mca_lookup(uint32_t id
)
92 const struct ate_mca_product
*atp
;
94 for (atp
= ate_mca_products
; atp
->at_name
!= NULL
; atp
++)
95 if (id
== atp
->at_prodid
)
102 ate_mca_match(device_t parent
, cfdata_t cf
, void *aux
)
104 struct mca_attach_args
*ma
= aux
;
106 if (ate_mca_lookup(ma
->ma_id
) != NULL
)
112 /* see POS diagrams below for explanation of these arrays' contents */
113 static const int ats_iobase
[] = {
114 0x400, 0x2400, 0x4400, 0x6400, 0x1400, 0x3400, 0x5400, 0x7400
116 static const int ats_irq
[] = {
117 3, 4, 5, 9, 10, 11, 12, 15
121 ate_mca_attach(device_t parent
, device_t self
, void *aux
)
123 struct ate_softc
*isc
= device_private(self
);
124 struct mb86960_softc
*sc
= &isc
->sc_mb86960
;
125 struct mca_attach_args
*ma
= aux
;
126 bus_space_tag_t iot
= ma
->ma_iot
;
127 bus_space_handle_t ioh
;
128 uint8_t myea
[ETHER_ADDR_LEN
];
131 const struct ate_mca_product
*atp
;
135 pos3
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 3);
136 pos4
= mca_conf_read(ma
->ma_mc
, ma
->ma_slot
, 4);
139 * POS register 2: (adf pos0)
141 * \__ enable: 0=adapter disabled, 1=adapter enabled
143 * POS register 3: (adf pos1)
147 * \ \ \__ I/O Port Addresses: 000=0x400-0x4FF 100=0x1400-
148 * \ \ 001=0x2400 101=0x3400 010=0x4400 110=0x5400
149 * \ \ 011=0x6400 111=0x7400
150 * \ \_____ Boot ROM Memory Address
152 * \_________ Lower 2 bit of Interrupt Request Number
154 * POS register 4: (adf pos2)
157 * \ \_______ Twisted Pair Type: 0=100 ohm, Unshielded
158 * \ 1=150 ohm, Shielded
159 * \____________ Higher 1 bit of Interrupt Request Number:
160 * 000=3 001=4 010=5 011=9 100=10 101=11 110=12 111=15
163 atp
= ate_mca_lookup(ma
->ma_id
);
167 aprint_error_dev(sc
->sc_dev
, "where did the card go?\n");
172 iobase
= ats_iobase
[pos3
& 0x7];
173 irq
= ats_irq
[((pos4
& 0x40) >> 4) | ((pos3
& 0xc0) >> 6)];
175 aprint_normal(" slot %d irq %d: %s\n",
176 ma
->ma_slot
+ 1, irq
, atp
->at_name
);
179 if (bus_space_map(iot
, iobase
, ATE_NPORTS
, 0, &ioh
)) {
180 aprint_error_dev(sc
->sc_dev
, "can't map i/o space\n");
187 /* Get ethernet address. */
188 ate_mca_detect(iot
, ioh
, myea
);
190 /* This interface is always enabled. */
191 sc
->sc_stat
|= FE_STAT_ENABLED
;
194 * Do generic MB86960 attach.
196 mb86960_attach(sc
, myea
);
198 mb86960_config(sc
, NULL
, 0, 0);
200 /* Establish the interrupt handler. */
201 isc
->sc_ih
= mca_intr_establish(ma
->ma_mc
, irq
, IPL_NET
,
203 if (isc
->sc_ih
== NULL
) {
204 aprint_error_dev(sc
->sc_dev
,
205 "couldn't establish interrupt handler\n");
211 * Very simplified ate_detect() from dev/isa/if_ate.c, only
212 * to determine ethernet address.
215 ate_mca_detect(bus_space_tag_t iot
, bus_space_handle_t ioh
,
216 uint8_t enaddr
[ETHER_ADDR_LEN
])
218 uint8_t eeprom
[FE_EEPROM_SIZE
];
220 /* Get our station address from EEPROM. */
221 mb86965_read_eeprom(iot
, ioh
, eeprom
);
222 memcpy(enaddr
, eeprom
+ FE_ATI_EEP_ADDR
, ETHER_ADDR_LEN
);