quirks.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * This file contains quirk handling code for PnP devices
  3. * Some devices do not report all their resources, and need to have extra
  4. * resources added. This is most easily accomplished at initialisation time
  5. * when building up the resource structure for the first time.
  6. *
  7. * Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk>
  8. *
  9. * Heavily based on PCI quirks handling which is
  10. *
  11. * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
  12. */
  13. #include <linux/config.h>
  14. #include <linux/types.h>
  15. #include <linux/kernel.h>
  16. #include <linux/string.h>
  17. #include <linux/slab.h>
  18. #ifdef CONFIG_PNP_DEBUG
  19. #define DEBUG
  20. #else
  21. #undef DEBUG
  22. #endif
  23. #include <linux/pnp.h>
  24. #include "base.h"
  25. static void quirk_awe32_resources(struct pnp_dev *dev)
  26. {
  27. struct pnp_port *port, *port2, *port3;
  28. struct pnp_option *res = dev->dependent;
  29. /*
  30. * Unfortunately the isapnp_add_port_resource is too tightly bound
  31. * into the PnP discovery sequence, and cannot be used. Link in the
  32. * two extra ports (at offset 0x400 and 0x800 from the one given) by
  33. * hand.
  34. */
  35. for ( ; res ; res = res->next ) {
  36. port2 = pnp_alloc(sizeof(struct pnp_port));
  37. if (!port2)
  38. return;
  39. port3 = pnp_alloc(sizeof(struct pnp_port));
  40. if (!port3) {
  41. kfree(port2);
  42. return;
  43. }
  44. port = res->port;
  45. memcpy(port2, port, sizeof(struct pnp_port));
  46. memcpy(port3, port, sizeof(struct pnp_port));
  47. port->next = port2;
  48. port2->next = port3;
  49. port2->min += 0x400;
  50. port2->max += 0x400;
  51. port3->min += 0x800;
  52. port3->max += 0x800;
  53. }
  54. printk(KERN_INFO "pnp: AWE32 quirk - adding two ports\n");
  55. }
  56. static void quirk_cmi8330_resources(struct pnp_dev *dev)
  57. {
  58. struct pnp_option *res = dev->dependent;
  59. unsigned long tmp;
  60. for ( ; res ; res = res->next ) {
  61. struct pnp_irq *irq;
  62. struct pnp_dma *dma;
  63. for( irq = res->irq; irq; irq = irq->next ) { // Valid irqs are 5, 7, 10
  64. tmp = 0x04A0;
  65. bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000
  66. }
  67. for( dma = res->dma; dma; dma = dma->next ) // Valid 8bit dma channels are 1,3
  68. if( ( dma->flags & IORESOURCE_DMA_TYPE_MASK ) == IORESOURCE_DMA_8BIT )
  69. dma->map = 0x000A;
  70. }
  71. printk(KERN_INFO "pnp: CMI8330 quirk - fixing interrupts and dma\n");
  72. }
  73. static void quirk_sb16audio_resources(struct pnp_dev *dev)
  74. {
  75. struct pnp_port *port;
  76. struct pnp_option *res = dev->dependent;
  77. int changed = 0;
  78. /*
  79. * The default range on the mpu port for these devices is 0x388-0x388.
  80. * Here we increase that range so that two such cards can be
  81. * auto-configured.
  82. */
  83. for( ; res ; res = res->next ) {
  84. port = res->port;
  85. if(!port)
  86. continue;
  87. port = port->next;
  88. if(!port)
  89. continue;
  90. port = port->next;
  91. if(!port)
  92. continue;
  93. if(port->min != port->max)
  94. continue;
  95. port->max += 0x70;
  96. changed = 1;
  97. }
  98. if(changed)
  99. printk(KERN_INFO "pnp: SB audio device quirk - increasing port range\n");
  100. return;
  101. }
  102. /*
  103. * PnP Quirks
  104. * Cards or devices that need some tweaking due to incomplete resource info
  105. */
  106. static struct pnp_fixup pnp_fixups[] = {
  107. /* Soundblaster awe io port quirk */
  108. { "CTL0021", quirk_awe32_resources },
  109. { "CTL0022", quirk_awe32_resources },
  110. { "CTL0023", quirk_awe32_resources },
  111. /* CMI 8330 interrupt and dma fix */
  112. { "@X@0001", quirk_cmi8330_resources },
  113. /* Soundblaster audio device io port range quirk */
  114. { "CTL0001", quirk_sb16audio_resources },
  115. { "CTL0031", quirk_sb16audio_resources },
  116. { "CTL0041", quirk_sb16audio_resources },
  117. { "CTL0042", quirk_sb16audio_resources },
  118. { "CTL0043", quirk_sb16audio_resources },
  119. { "CTL0044", quirk_sb16audio_resources },
  120. { "CTL0045", quirk_sb16audio_resources },
  121. { "" }
  122. };
  123. void pnp_fixup_device(struct pnp_dev *dev)
  124. {
  125. int i = 0;
  126. while (*pnp_fixups[i].id) {
  127. if (compare_pnp_id(dev->id,pnp_fixups[i].id)) {
  128. pnp_dbg("Calling quirk for %s",
  129. dev->dev.bus_id);
  130. pnp_fixups[i].quirk_function(dev);
  131. }
  132. i++;
  133. }
  134. }