You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

eisa.c 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #include "string.h"
  2. #include "io.h"
  3. #include "timer.h"
  4. #include "eisa.h"
  5. /*
  6. * Ensure that there is sufficient space in the shared dev_bus
  7. * structure for a struct pci_device.
  8. *
  9. */
  10. DEV_BUS( struct eisa_device, eisa_dev );
  11. static char eisa_magic[0]; /* guaranteed unique symbol */
  12. /*
  13. * Fill in parameters for an EISA device based on slot number
  14. *
  15. * Return 1 if device present, 0 otherwise
  16. *
  17. */
  18. static int fill_eisa_device ( struct eisa_device *eisa ) {
  19. uint8_t present;
  20. /* Set ioaddr */
  21. eisa->ioaddr = EISA_SLOT_BASE ( eisa->slot );
  22. /* Test for board present */
  23. outb ( 0xff, eisa->ioaddr + EISA_MFG_ID_HI );
  24. present = inb ( eisa->ioaddr + EISA_MFG_ID_HI );
  25. if ( present & 0x80 ) {
  26. /* No board present */
  27. return 0;
  28. }
  29. /* Read mfg and product IDs. Yes, the resulting uint16_ts
  30. * will be upside-down. This appears to be by design.
  31. */
  32. eisa->mfg_id = ( inb ( eisa->ioaddr + EISA_MFG_ID_LO ) << 8 )
  33. + present;
  34. eisa->prod_id = ( inb ( eisa->ioaddr + EISA_PROD_ID_LO ) << 8 )
  35. + inb ( eisa->ioaddr + EISA_PROD_ID_HI );
  36. DBG ( "EISA found slot %d (base %#hx) ID %hx:%hx (\"%s\")\n",
  37. eisa->slot, eisa->ioaddr, eisa->mfg_id, eisa->prod_id,
  38. isa_id_string ( eisa->mfg_id, eisa->prod_id ) );
  39. return 1;
  40. }
  41. /*
  42. * Find an EISA device matching the specified driver
  43. *
  44. */
  45. int find_eisa_device ( struct eisa_device *eisa, struct eisa_driver *driver ) {
  46. unsigned int i;
  47. /* Initialise struct eisa if it's the first time it's been used. */
  48. if ( eisa->magic != eisa_magic ) {
  49. memset ( eisa, 0, sizeof ( *eisa ) );
  50. eisa->magic = eisa_magic;
  51. eisa->slot = EISA_MIN_SLOT;
  52. }
  53. /* Iterate through all possible EISA slots, starting where we
  54. * left off.
  55. */
  56. DBG ( "EISA searching for device matching driver %s\n", driver->name );
  57. for ( ; eisa->slot <= EISA_MAX_SLOT ; eisa->slot++ ) {
  58. /* If we've already used this device, skip it */
  59. if ( eisa->already_tried ) {
  60. eisa->already_tried = 0;
  61. continue;
  62. }
  63. /* Fill in device parameters */
  64. if ( ! fill_eisa_device ( eisa ) ) {
  65. continue;
  66. }
  67. /* Compare against driver's ID list */
  68. for ( i = 0 ; i < driver->id_count ; i++ ) {
  69. struct eisa_id *id = &driver->ids[i];
  70. if ( ( eisa->mfg_id == id->mfg_id ) &&
  71. ( ISA_PROD_ID ( eisa->prod_id ) ==
  72. ISA_PROD_ID ( id->prod_id ) ) ) {
  73. DBG ( "EISA found ID %hx:%hx (\"%s\") "
  74. "(device %s) matching driver %s\n",
  75. eisa->mfg_id, eisa->prod_id,
  76. isa_id_string ( eisa->mfg_id,
  77. eisa->prod_id ),
  78. id->name, driver->name );
  79. eisa->name = id->name;
  80. eisa->already_tried = 1;
  81. return 1;
  82. }
  83. }
  84. }
  85. /* No device found */
  86. DBG ( "EISA found no device matching driver %s\n", driver->name );
  87. eisa->slot = EISA_MIN_SLOT;
  88. return 0;
  89. }
  90. /*
  91. * Find the next EISA device that can be used to boot using the
  92. * specified driver.
  93. *
  94. */
  95. int find_eisa_boot_device ( struct dev *dev, struct eisa_driver *driver ) {
  96. struct eisa_device *eisa = ( struct eisa_device * )dev->bus;
  97. if ( ! find_eisa_device ( eisa, driver ) )
  98. return 0;
  99. dev->name = eisa->name;
  100. dev->devid.bus_type = ISA_BUS_TYPE;
  101. dev->devid.vendor_id = eisa->mfg_id;
  102. dev->devid.device_id = eisa->prod_id;
  103. return 1;
  104. }
  105. /*
  106. * Reset and enable an EISA device
  107. *
  108. */
  109. void enable_eisa_device ( struct eisa_device *eisa ) {
  110. /* Set reset line high for 1000 µs. Spec says 500 µs, but
  111. * this doesn't work for all cards, so we are conservative.
  112. */
  113. outb ( EISA_CMD_RESET, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  114. udelay ( 1000 ); /* Must wait 800 */
  115. /* Set reset low and write a 1 to ENABLE. Delay again, in
  116. * case the card takes a while to wake up.
  117. */
  118. outb ( EISA_CMD_ENABLE, eisa->ioaddr + EISA_GLOBAL_CONFIG );
  119. udelay ( 1000 ); /* Must wait 800 */
  120. }