quirks.c 3.7 KB

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