quirks.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 <linux/io.h>
  19. #include "base.h"
  20. static void quirk_awe32_resources(struct pnp_dev *dev)
  21. {
  22. struct pnp_port *port, *port2, *port3;
  23. struct pnp_option *res = dev->dependent;
  24. /*
  25. * Unfortunately the isapnp_add_port_resource is too tightly bound
  26. * into the PnP discovery sequence, and cannot be used. Link in the
  27. * two extra ports (at offset 0x400 and 0x800 from the one given) by
  28. * hand.
  29. */
  30. for ( ; res ; res = res->next ) {
  31. port2 = pnp_alloc(sizeof(struct pnp_port));
  32. if (!port2)
  33. return;
  34. port3 = pnp_alloc(sizeof(struct pnp_port));
  35. if (!port3) {
  36. kfree(port2);
  37. return;
  38. }
  39. port = res->port;
  40. memcpy(port2, port, sizeof(struct pnp_port));
  41. memcpy(port3, port, sizeof(struct pnp_port));
  42. port->next = port2;
  43. port2->next = port3;
  44. port2->min += 0x400;
  45. port2->max += 0x400;
  46. port3->min += 0x800;
  47. port3->max += 0x800;
  48. }
  49. printk(KERN_INFO "pnp: AWE32 quirk - adding two ports\n");
  50. }
  51. static void quirk_cmi8330_resources(struct pnp_dev *dev)
  52. {
  53. struct pnp_option *res = dev->dependent;
  54. unsigned long tmp;
  55. for ( ; res ; res = res->next ) {
  56. struct pnp_irq *irq;
  57. struct pnp_dma *dma;
  58. for( irq = res->irq; irq; irq = irq->next ) { // Valid irqs are 5, 7, 10
  59. tmp = 0x04A0;
  60. bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000
  61. }
  62. for( dma = res->dma; dma; dma = dma->next ) // Valid 8bit dma channels are 1,3
  63. if( ( dma->flags & IORESOURCE_DMA_TYPE_MASK ) == IORESOURCE_DMA_8BIT )
  64. dma->map = 0x000A;
  65. }
  66. printk(KERN_INFO "pnp: CMI8330 quirk - fixing interrupts and dma\n");
  67. }
  68. static void quirk_sb16audio_resources(struct pnp_dev *dev)
  69. {
  70. struct pnp_port *port;
  71. struct pnp_option *res = dev->dependent;
  72. int changed = 0;
  73. /*
  74. * The default range on the mpu port for these devices is 0x388-0x388.
  75. * Here we increase that range so that two such cards can be
  76. * auto-configured.
  77. */
  78. for( ; res ; res = res->next ) {
  79. port = res->port;
  80. if(!port)
  81. continue;
  82. port = port->next;
  83. if(!port)
  84. continue;
  85. port = port->next;
  86. if(!port)
  87. continue;
  88. if(port->min != port->max)
  89. continue;
  90. port->max += 0x70;
  91. changed = 1;
  92. }
  93. if(changed)
  94. printk(KERN_INFO "pnp: SB audio device quirk - increasing port range\n");
  95. return;
  96. }
  97. static int quirk_smc_fir_enabled(struct pnp_dev *dev)
  98. {
  99. unsigned long firbase;
  100. u8 bank, high, low, chip;
  101. if (!pnp_port_valid(dev, 1))
  102. return 0;
  103. firbase = pnp_port_start(dev, 1);
  104. /* Select register bank 3 */
  105. bank = inb(firbase + 7);
  106. bank &= 0xf0;
  107. bank |= 3;
  108. outb(bank, firbase + 7);
  109. high = inb(firbase + 0);
  110. low = inb(firbase + 1);
  111. chip = inb(firbase + 2);
  112. /* This corresponds to the check in smsc_ircc_present() */
  113. if (high == 0x10 && low == 0xb8 && (chip == 0xf1 || chip == 0xf2))
  114. return 1;
  115. return 0;
  116. }
  117. static void quirk_smc_enable(struct pnp_dev *dev)
  118. {
  119. struct resource fir, sir, irq;
  120. pnp_activate_dev(dev);
  121. if (quirk_smc_fir_enabled(dev))
  122. return;
  123. /*
  124. * Sometimes the BIOS claims the device is enabled, but it reports
  125. * the wrong FIR resources or doesn't properly configure ISA or LPC
  126. * bridges on the way to the device.
  127. *
  128. * HP nc6000 and nc8000/nw8000 laptops have known problems like
  129. * this. Fortunately, they do fix things up if we auto-configure
  130. * the device using its _PRS and _SRS methods.
  131. */
  132. dev_err(&dev->dev, "%s not responding at SIR 0x%lx, FIR 0x%lx; "
  133. "auto-configuring\n", dev->id->id,
  134. (unsigned long) pnp_port_start(dev, 0),
  135. (unsigned long) pnp_port_start(dev, 1));
  136. pnp_disable_dev(dev);
  137. pnp_init_resource_table(&dev->res);
  138. pnp_auto_config_dev(dev);
  139. pnp_activate_dev(dev);
  140. if (quirk_smc_fir_enabled(dev)) {
  141. dev_err(&dev->dev, "responds at SIR 0x%lx, FIR 0x%lx\n",
  142. (unsigned long) pnp_port_start(dev, 0),
  143. (unsigned long) pnp_port_start(dev, 1));
  144. return;
  145. }
  146. /*
  147. * The Toshiba Portege 4000 _CRS reports the FIR region first,
  148. * followed by the SIR region. The BIOS will configure the bridge,
  149. * but only if we call _SRS with SIR first, then FIR. It also
  150. * reports the IRQ as active high, when it is really active low.
  151. */
  152. dev_err(&dev->dev, "not responding at SIR 0x%lx, FIR 0x%lx; "
  153. "swapping SIR/FIR and reconfiguring\n",
  154. (unsigned long) pnp_port_start(dev, 0),
  155. (unsigned long) pnp_port_start(dev, 1));
  156. /*
  157. * Clear IORESOURCE_AUTO so pnp_activate_dev() doesn't reassign
  158. * these resources any more.
  159. */
  160. fir = dev->res.port_resource[0];
  161. sir = dev->res.port_resource[1];
  162. fir.flags &= ~IORESOURCE_AUTO;
  163. sir.flags &= ~IORESOURCE_AUTO;
  164. irq = dev->res.irq_resource[0];
  165. irq.flags &= ~IORESOURCE_AUTO;
  166. irq.flags &= ~IORESOURCE_BITS;
  167. irq.flags |= IORESOURCE_IRQ_LOWEDGE;
  168. pnp_disable_dev(dev);
  169. dev->res.port_resource[0] = sir;
  170. dev->res.port_resource[1] = fir;
  171. dev->res.irq_resource[0] = irq;
  172. pnp_activate_dev(dev);
  173. if (quirk_smc_fir_enabled(dev)) {
  174. dev_err(&dev->dev, "responds at SIR 0x%lx, FIR 0x%lx\n",
  175. (unsigned long) pnp_port_start(dev, 0),
  176. (unsigned long) pnp_port_start(dev, 1));
  177. return;
  178. }
  179. dev_err(&dev->dev, "giving up; try \"smsc-ircc2.nopnp\" and "
  180. "email bjorn.helgaas@hp.com\n");
  181. }
  182. /*
  183. * PnP Quirks
  184. * Cards or devices that need some tweaking due to incomplete resource info
  185. */
  186. static struct pnp_fixup pnp_fixups[] = {
  187. /* Soundblaster awe io port quirk */
  188. { "CTL0021", quirk_awe32_resources },
  189. { "CTL0022", quirk_awe32_resources },
  190. { "CTL0023", quirk_awe32_resources },
  191. /* CMI 8330 interrupt and dma fix */
  192. { "@X@0001", quirk_cmi8330_resources },
  193. /* Soundblaster audio device io port range quirk */
  194. { "CTL0001", quirk_sb16audio_resources },
  195. { "CTL0031", quirk_sb16audio_resources },
  196. { "CTL0041", quirk_sb16audio_resources },
  197. { "CTL0042", quirk_sb16audio_resources },
  198. { "CTL0043", quirk_sb16audio_resources },
  199. { "CTL0044", quirk_sb16audio_resources },
  200. { "CTL0045", quirk_sb16audio_resources },
  201. { "SMCf010", quirk_smc_enable },
  202. { "" }
  203. };
  204. void pnp_fixup_device(struct pnp_dev *dev)
  205. {
  206. int i = 0;
  207. while (*pnp_fixups[i].id) {
  208. if (compare_pnp_id(dev->id,pnp_fixups[i].id)) {
  209. pnp_dbg("Calling quirk for %s",
  210. dev->dev.bus_id);
  211. pnp_fixups[i].quirk_function(dev);
  212. }
  213. i++;
  214. }
  215. }