ide-legacy.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <linux/kernel.h>
  2. #include <linux/export.h>
  3. #include <linux/ide.h>
  4. static void ide_legacy_init_one(struct ide_hw **hws, struct ide_hw *hw,
  5. u8 port_no, const struct ide_port_info *d,
  6. unsigned long config)
  7. {
  8. unsigned long base, ctl;
  9. int irq;
  10. if (port_no == 0) {
  11. base = 0x1f0;
  12. ctl = 0x3f6;
  13. irq = 14;
  14. } else {
  15. base = 0x170;
  16. ctl = 0x376;
  17. irq = 15;
  18. }
  19. if (!request_region(base, 8, d->name)) {
  20. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
  21. d->name, base, base + 7);
  22. return;
  23. }
  24. if (!request_region(ctl, 1, d->name)) {
  25. printk(KERN_ERR "%s: I/O resource 0x%lX not free.\n",
  26. d->name, ctl);
  27. release_region(base, 8);
  28. return;
  29. }
  30. ide_std_init_ports(hw, base, ctl);
  31. hw->irq = irq;
  32. hw->config = config;
  33. hws[port_no] = hw;
  34. }
  35. int ide_legacy_device_add(const struct ide_port_info *d, unsigned long config)
  36. {
  37. struct ide_hw hw[2], *hws[] = { NULL, NULL };
  38. memset(&hw, 0, sizeof(hw));
  39. if ((d->host_flags & IDE_HFLAG_QD_2ND_PORT) == 0)
  40. ide_legacy_init_one(hws, &hw[0], 0, d, config);
  41. ide_legacy_init_one(hws, &hw[1], 1, d, config);
  42. if (hws[0] == NULL && hws[1] == NULL &&
  43. (d->host_flags & IDE_HFLAG_SINGLE))
  44. return -ENOENT;
  45. return ide_host_add(d, hws, 2, NULL);
  46. }
  47. EXPORT_SYMBOL_GPL(ide_legacy_device_add);