ide-legacy.c 1.3 KB

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