ide-generic.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. unsigned int base, ctl;
  27. int irq, rc;
  28. hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  29. if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
  30. return -EINVAL;
  31. memset(&hw, 0, sizeof(hw));
  32. ide_std_init_ports(&hw, base, ctl);
  33. hw.irq = irq;
  34. hw.chipset = ide_generic;
  35. rc = ide_host_add(NULL, hws, NULL);
  36. if (rc)
  37. return rc;
  38. return n;
  39. };
  40. static struct class_attribute ide_generic_class_attrs[] = {
  41. __ATTR(add, S_IWUSR, NULL, store_add),
  42. __ATTR_NULL
  43. };
  44. static void ide_generic_class_release(struct class *cls)
  45. {
  46. kfree(cls);
  47. }
  48. static int __init ide_generic_sysfs_init(void)
  49. {
  50. struct class *cls;
  51. int rc;
  52. cls = kzalloc(sizeof(*cls), GFP_KERNEL);
  53. if (!cls)
  54. return -ENOMEM;
  55. cls->name = DRV_NAME;
  56. cls->owner = THIS_MODULE;
  57. cls->class_release = ide_generic_class_release;
  58. cls->class_attrs = ide_generic_class_attrs;
  59. rc = class_register(cls);
  60. if (rc) {
  61. kfree(cls);
  62. return rc;
  63. }
  64. return 0;
  65. }
  66. static int __init ide_generic_init(void)
  67. {
  68. hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS];
  69. struct ide_host *host;
  70. unsigned long io_addr;
  71. int i, rc;
  72. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
  73. "parameter for probing all legacy ISA IDE ports\n");
  74. for (i = 0; i < MAX_HWIFS; i++) {
  75. io_addr = ide_default_io_base(i);
  76. hws[i] = NULL;
  77. if ((probe_mask & (1 << i)) && io_addr) {
  78. if (!request_region(io_addr, 8, DRV_NAME)) {
  79. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  80. "not free.\n",
  81. DRV_NAME, io_addr, io_addr + 7);
  82. continue;
  83. }
  84. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  85. printk(KERN_ERR "%s: I/O resource 0x%lX "
  86. "not free.\n",
  87. DRV_NAME, io_addr + 0x206);
  88. release_region(io_addr, 8);
  89. continue;
  90. }
  91. memset(&hw[i], 0, sizeof(hw[i]));
  92. ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
  93. hw[i].irq = ide_default_irq(io_addr);
  94. hw[i].chipset = ide_generic;
  95. hws[i] = &hw[i];
  96. }
  97. }
  98. host = ide_host_alloc_all(NULL, hws);
  99. if (host == NULL) {
  100. rc = -ENOMEM;
  101. goto err;
  102. }
  103. rc = ide_host_register(host, NULL, hws);
  104. if (rc)
  105. goto err_free;
  106. if (ide_generic_sysfs_init())
  107. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  108. "class\n");
  109. return 0;
  110. err_free:
  111. ide_host_free(host);
  112. err:
  113. for (i = 0; i < MAX_HWIFS; i++) {
  114. if (hws[i] == NULL)
  115. continue;
  116. io_addr = hws[i]->io_ports.data_addr;
  117. release_region(io_addr + 0x206, 1);
  118. release_region(io_addr, 8);
  119. }
  120. return rc;
  121. }
  122. module_init(ide_generic_init);
  123. MODULE_LICENSE("GPL");