ide-generic.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 ssize_t store_add(struct class *cls, const char *buf, size_t n)
  22. {
  23. ide_hwif_t *hwif;
  24. unsigned int base, ctl;
  25. int irq;
  26. hw_regs_t hw;
  27. u8 idx[] = { 0xff, 0xff, 0xff, 0xff };
  28. if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
  29. return -EINVAL;
  30. hwif = ide_find_port();
  31. if (hwif == NULL)
  32. return -ENOENT;
  33. memset(&hw, 0, sizeof(hw));
  34. ide_std_init_ports(&hw, base, ctl);
  35. hw.irq = irq;
  36. hw.chipset = ide_generic;
  37. ide_init_port_hw(hwif, &hw);
  38. idx[0] = hwif->index;
  39. ide_device_add(idx, NULL);
  40. return n;
  41. };
  42. static struct class_attribute ide_generic_class_attrs[] = {
  43. __ATTR(add, S_IWUSR, NULL, store_add),
  44. __ATTR_NULL
  45. };
  46. static void ide_generic_class_release(struct class *cls)
  47. {
  48. kfree(cls);
  49. }
  50. static int __init ide_generic_sysfs_init(void)
  51. {
  52. struct class *cls;
  53. int rc;
  54. cls = kzalloc(sizeof(*cls), GFP_KERNEL);
  55. if (!cls)
  56. return -ENOMEM;
  57. cls->name = DRV_NAME;
  58. cls->owner = THIS_MODULE;
  59. cls->class_release = ide_generic_class_release;
  60. cls->class_attrs = ide_generic_class_attrs;
  61. rc = class_register(cls);
  62. if (rc) {
  63. kfree(cls);
  64. return rc;
  65. }
  66. return 0;
  67. }
  68. static int __init ide_generic_init(void)
  69. {
  70. u8 idx[MAX_HWIFS];
  71. int i;
  72. for (i = 0; i < MAX_HWIFS; i++) {
  73. ide_hwif_t *hwif;
  74. unsigned long io_addr = ide_default_io_base(i);
  75. hw_regs_t hw;
  76. if (io_addr) {
  77. /*
  78. * Skip probing if the corresponding
  79. * slot is already occupied.
  80. */
  81. hwif = ide_find_port();
  82. if (hwif == NULL || hwif->index != i) {
  83. idx[i] = 0xff;
  84. continue;
  85. }
  86. memset(&hw, 0, sizeof(hw));
  87. ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
  88. hw.irq = ide_default_irq(io_addr);
  89. ide_init_port_hw(hwif, &hw);
  90. idx[i] = i;
  91. } else
  92. idx[i] = 0xff;
  93. }
  94. ide_device_add_all(idx, NULL);
  95. if (ide_generic_sysfs_init())
  96. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  97. "class\n");
  98. return 0;
  99. }
  100. module_init(ide_generic_init);
  101. MODULE_LICENSE("GPL");