ide-generic.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * generic/default IDE host driver
  3. *
  4. * Copyright (C) 2004, 2008 Bartlomiej Zolnierkiewicz
  5. * This code was split off from ide.c. See it for original copyrights.
  6. *
  7. * May be copied or modified under the terms of the GNU General Public License.
  8. */
  9. /*
  10. * For special cases new interfaces may be added using sysfs, i.e.
  11. *
  12. * echo -n "0x168:0x36e:10" > /sys/class/ide_generic/add
  13. *
  14. * will add an interface using I/O ports 0x168-0x16f/0x36e and IRQ 10.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/module.h>
  19. #include <linux/ide.h>
  20. #define DRV_NAME "ide_generic"
  21. static int probe_mask = 0x03;
  22. module_param(probe_mask, int, 0);
  23. MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
  24. static ssize_t store_add(struct class *cls, const char *buf, size_t n)
  25. {
  26. ide_hwif_t *hwif;
  27. unsigned int base, ctl;
  28. int irq;
  29. hw_regs_t hw;
  30. u8 idx[] = { 0xff, 0xff, 0xff, 0xff };
  31. if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
  32. return -EINVAL;
  33. hwif = ide_find_port();
  34. if (hwif == NULL)
  35. return -ENOENT;
  36. memset(&hw, 0, sizeof(hw));
  37. ide_std_init_ports(&hw, base, ctl);
  38. hw.irq = irq;
  39. hw.chipset = ide_generic;
  40. ide_init_port_hw(hwif, &hw);
  41. idx[0] = hwif->index;
  42. ide_device_add(idx, NULL);
  43. return n;
  44. };
  45. static struct class_attribute ide_generic_class_attrs[] = {
  46. __ATTR(add, S_IWUSR, NULL, store_add),
  47. __ATTR_NULL
  48. };
  49. static void ide_generic_class_release(struct class *cls)
  50. {
  51. kfree(cls);
  52. }
  53. static int __init ide_generic_sysfs_init(void)
  54. {
  55. struct class *cls;
  56. int rc;
  57. cls = kzalloc(sizeof(*cls), GFP_KERNEL);
  58. if (!cls)
  59. return -ENOMEM;
  60. cls->name = DRV_NAME;
  61. cls->owner = THIS_MODULE;
  62. cls->class_release = ide_generic_class_release;
  63. cls->class_attrs = ide_generic_class_attrs;
  64. rc = class_register(cls);
  65. if (rc) {
  66. kfree(cls);
  67. return rc;
  68. }
  69. return 0;
  70. }
  71. static int __init ide_generic_init(void)
  72. {
  73. u8 idx[MAX_HWIFS];
  74. int i;
  75. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
  76. "parameter for probing all legacy ISA IDE ports\n");
  77. for (i = 0; i < MAX_HWIFS; i++) {
  78. ide_hwif_t *hwif;
  79. unsigned long io_addr = ide_default_io_base(i);
  80. hw_regs_t hw;
  81. idx[i] = 0xff;
  82. if ((probe_mask & (1 << i)) && io_addr) {
  83. if (!request_region(io_addr, 8, DRV_NAME)) {
  84. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  85. "not free.\n",
  86. DRV_NAME, io_addr, io_addr + 7);
  87. continue;
  88. }
  89. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  90. printk(KERN_ERR "%s: I/O resource 0x%lX "
  91. "not free.\n",
  92. DRV_NAME, io_addr + 0x206);
  93. release_region(io_addr, 8);
  94. continue;
  95. }
  96. /*
  97. * Skip probing if the corresponding
  98. * slot is already occupied.
  99. */
  100. hwif = ide_find_port();
  101. if (hwif == NULL || hwif->index != i) {
  102. idx[i] = 0xff;
  103. continue;
  104. }
  105. memset(&hw, 0, sizeof(hw));
  106. ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
  107. hw.irq = ide_default_irq(io_addr);
  108. hw.chipset = ide_generic;
  109. ide_init_port_hw(hwif, &hw);
  110. idx[i] = i;
  111. }
  112. }
  113. ide_device_add_all(idx, NULL);
  114. if (ide_generic_sysfs_init())
  115. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  116. "class\n");
  117. return 0;
  118. }
  119. module_init(ide_generic_init);
  120. MODULE_LICENSE("GPL");