2 * Split out into 3c509.c and 3c5x9.c, to make it possible to build a
3 * 3c529 module without including ISA, ISAPnP and EISA code.
15 * 3c509 cards have their own method of contention resolution; this
16 * effectively defines another bus type similar to ISAPnP. Even the
17 * original ISA cards can be programatically mapped to any I/O address
18 * in the range 0x200-0x3e0.
20 * However, there is a small problem: once you've activated a card,
21 * the only ways to deactivate it will also wipe its tag, meaning that
22 * you won't be able to subsequently reactivate it without going
23 * through the whole ID sequence again. The solution we adopt is to
24 * isolate and tag all cards at the start, and to immediately
25 * re-isolate and re-tag a card after disabling it.
29 static uint16_t t509_id_port = 0;
30 static uint8_t t509_max_tag = 0;
33 * A location on a t509 bus
41 * A physical t509 device
50 * t509 utility functions
54 static inline void t509_set_id_port ( void ) {
55 outb ( 0x00, t509_id_port );
58 static inline void t509_wait_for_id_sequence ( void ) {
59 outb ( 0x00, t509_id_port );
62 static inline void t509_global_reset ( void ) {
63 outb ( 0xc0, t509_id_port );
66 static inline void t509_reset_tag ( void ) {
67 outb ( 0xd0, t509_id_port );
70 static inline void t509_set_tag ( uint8_t tag ) {
71 outb ( 0xd0 | tag, t509_id_port );
74 static inline void t509_select_tag ( uint8_t tag ) {
75 outb ( 0xd8 | tag, t509_id_port );
78 static inline void t509_activate ( uint16_t ioaddr ) {
79 outb ( 0xe0 | ( ioaddr >> 4 ), t509_id_port );
82 static inline void t509_deactivate_and_reset_tag ( uint16_t ioaddr ) {
83 outb ( GLOBAL_RESET, ioaddr + EP_COMMAND );
86 static inline void t509_load_eeprom_word ( uint8_t offset ) {
87 outb ( 0x80 | offset, t509_id_port );
91 * Find a suitable ID port
94 static inline int t509_find_id_port ( void ) {
96 for ( t509_id_port = EP_ID_PORT_START ;
97 t509_id_port < EP_ID_PORT_END ;
98 t509_id_port += EP_ID_PORT_INC ) {
100 /* See if anything's listening */
101 outb ( 0xff, t509_id_port );
102 if ( inb ( t509_id_port ) & 0x01 ) {
103 /* Found a suitable port */
104 DBG ( "T509 using ID port at %hx\n", t509_id_port );
108 /* No id port available */
109 DBG ( "T509 found no available ID port\n" );
114 * Send ID sequence to the ID port
117 static void t509_send_id_sequence ( void ) {
118 unsigned short lrs_state, i;
121 /* Reset IDS on cards */
122 t509_wait_for_id_sequence ();
124 for ( i = 0; i < 255; i++ ) {
125 outb ( lrs_state, t509_id_port );
127 lrs_state = lrs_state & 0x100 ? lrs_state ^ 0xcf : lrs_state;
132 * We get eeprom data from the id_port given an offset into the eeprom.
133 * Basically; after the ID_sequence is sent to all of the cards; they enter
134 * the ID_CMD state where they will accept command requests. 0x80-0xbf loads
135 * the eeprom data. We then read the port 16 times and with every read; the
136 * cards check for contention (ie: if one card writes a 0 bit and another
137 * writes a 1 bit then the host sees a 0. At the end of the cycle; each card
138 * compares the data on the bus; if there is a difference then that card goes
139 * into ID_WAIT state again). In the meantime; one bit of data is returned in
140 * the AX register which is conveniently returned to us by inb(). Hence; we
141 * read 16 times getting one bit of data with each read.
143 static uint16_t t509_id_read_eeprom ( int offset ) {
146 t509_load_eeprom_word ( offset );
147 /* Do we really need this wait? Won't be noticeable anyway */
150 for ( i = 0; i < 16; i++ ) {
151 data = ( data << 1 ) | ( inw ( t509_id_port ) & 1 );
157 * Isolate and tag all t509 cards
160 static void t509_isolate ( void ) {
164 /* Find a suitable ID port */
165 if ( ! t509_find_id_port () )
170 /* All cards are in ID_WAIT state each time we go
174 /* Send the ID sequence */
175 t509_send_id_sequence ();
177 /* First time through, reset all tags. On subsequent
178 * iterations, kill off any already-tagged cards
180 if ( t509_max_tag == 0 ) {
186 /* Read the manufacturer ID, to see if there are any
189 if ( t509_id_read_eeprom ( EEPROM_MFG_ID ) != MFG_ID ) {
190 DBG ( "T509 saw %s signs of life\n",
191 t509_max_tag ? "no further" : "no" );
195 /* Perform contention selection on the MAC address */
196 for ( i = 0 ; i < 3 ; i++ ) {
197 contend[i] = t509_id_read_eeprom ( i );
200 /* Only one device will still be left alive. Tag it. */
202 DBG ( "T509 found card %hx%hx%hx, assigning tag %hhx\n",
203 contend[0], contend[1], contend[2], t509_max_tag );
204 t509_set_tag ( t509_max_tag );
206 /* Return all cards back to ID_WAIT state */
207 t509_wait_for_id_sequence();
210 DBG ( "T509 found %d cards using ID port %hx\n",
211 t509_max_tag, t509_id_port );
216 * Increment a bus_loc structure to the next possible T509 location.
217 * Leave the structure zeroed and return 0 if there are no more valid
221 static int t509_next_location ( struct bus_loc *bus_loc ) {
222 struct t509_loc *t509_loc = ( struct t509_loc * ) bus_loc;
225 * Ensure that there is sufficient space in the shared bus
226 * structures for a struct t509_loc and a struct t509_dev,
227 * as mandated by bus.h.
230 BUS_LOC_CHECK ( struct t509_loc );
231 BUS_DEV_CHECK ( struct t509_device );
233 return ( t509_loc->tag = ( ++t509_loc->tag & EP_TAG_MAX ) );
237 * Fill in parameters for a T509 device based on tag
239 * Return 1 if device present, 0 otherwise
242 static int t509_fill_device ( struct bus_dev *bus_dev,
243 struct bus_loc *bus_loc ) {
244 struct t509_device *t509 = ( struct t509_device * ) bus_dev;
245 struct t509_loc *t509_loc = ( struct t509_loc * ) bus_loc;
248 /* Copy tag to struct t509 */
249 t509->tag = t509_loc->tag;
251 /* Tag 0 is never valid, but may be passed in */
255 /* Perform isolation if it hasn't yet been done */
256 if ( ! t509_id_port )
259 /* Check tag is in range */
260 if ( t509->tag > t509_max_tag )
263 /* Send the ID sequence */
264 t509_send_id_sequence ();
266 /* Select the specified tag */
267 t509_select_tag ( t509->tag );
269 /* Read the default I/O address */
270 iobase = t509_id_read_eeprom ( EEPROM_ADDR_CFG );
271 t509->ioaddr = 0x200 + ( ( iobase & 0x1f ) << 4 );
273 /* Send card back to ID_WAIT */
274 t509_wait_for_id_sequence();
276 DBG ( "T509 found device %hhx, base %hx\n", t509->tag, t509->ioaddr );
281 * Test whether or not a driver is capable of driving the device.
282 * This is a no-op for T509.
285 static int t509_check_driver ( struct bus_dev *bus_dev __unused,
286 struct device_driver *device_driver __unused ) {
291 * Describe a T509 device
294 static char * t509_describe ( struct bus_dev *bus_dev ) {
295 struct t509_device *t509 = ( struct t509_device * ) bus_dev;
296 static char t509_description[] = "T509 00";
298 sprintf ( t509_description + 4, "%hhx", t509->tag );
299 return t509_description;
306 static const char * t509_name ( struct bus_dev *bus_dev __unused ) {
311 * T509 bus operations table
314 struct bus_driver t509_driver __bus_driver = {
315 .next_location = t509_next_location,
316 .fill_device = t509_fill_device,
317 .check_driver = t509_check_driver,
318 .describe = t509_describe,
323 * Activate a T509 device
325 * The device will be enabled at whatever ioaddr is specified in the
326 * struct t509_device; there is no need to stick with the default
327 * ioaddr read from the EEPROM.
330 static inline void activate_t509_device ( struct t509_device *t509 ) {
331 t509_send_id_sequence ();
332 t509_select_tag ( t509->tag );
333 t509_activate ( t509->ioaddr );
334 DBG ( "T509 activated device %hhx at ioaddr %hx\n",
335 t509->tag, t509->ioaddr );
339 * Deactivate a T509 device
341 * Disabling also clears the tag, so we immediately isolate and re-tag
345 static inline void deactivate_t509_device ( struct t509_device *t509 ) {
346 t509_deactivate_and_reset_tag ( t509->ioaddr );
348 t509_send_id_sequence ();
349 t509_select_tag ( 0 );
350 t509_set_tag ( t509->tag );
351 t509_wait_for_id_sequence ();
352 DBG ( "T509 deactivated device at %hx and re-tagged as %hhx\n",
353 t509->ioaddr, t509->tag );
357 * Fill in a nic structure
359 * Called only once, so inlined for efficiency
362 static inline void t509_fill_nic ( struct nic *nic,
363 struct t509_device *t509 ) {
365 /* Fill in ioaddr and irqno */
366 nic->ioaddr = t509->ioaddr;
369 /* Fill in DHCP device ID structure */
370 nic->dhcp_dev_id.bus_type = ISA_BUS_TYPE;
371 nic->dhcp_dev_id.vendor_id = htons ( MFG_ID );
372 nic->dhcp_dev_id.device_id = htons ( PROD_ID );
376 * The ISA probe function
379 static int el3_t509_probe ( struct nic *nic, struct t509_device *t509 ) {
381 /* We could change t509->ioaddr if we wanted to */
382 activate_t509_device ( t509 );
383 t509_fill_nic ( nic, t509 );
385 /* Hand off to generic t5x9 probe routine */
386 return t5x9_probe ( nic, ISA_PROD_ID ( PROD_ID ), ISA_PROD_ID_MASK );
389 static void el3_t509_disable ( struct nic *nic, struct t509_device *t509 ) {
390 t5x9_disable ( nic );
391 deactivate_t509_device ( t509 );
394 static struct {} el3_t509_driver;
396 DRIVER ( "3c509", nic_driver, t509_driver, el3_t509_driver,
397 el3_t509_probe, el3_t509_disable );
399 ISA_ROM ( "3c509", "3c509" );