ide-generic.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. #ifdef CONFIG_MIPS
  73. if (!ide_probe_legacy())
  74. return -ENODEV;
  75. #endif
  76. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
  77. "parameter for probing all legacy ISA IDE ports\n");
  78. for (i = 0; i < MAX_HWIFS; i++) {
  79. io_addr = ide_default_io_base(i);
  80. hws[i] = NULL;
  81. if ((probe_mask & (1 << i)) && io_addr) {
  82. if (!request_region(io_addr, 8, DRV_NAME)) {
  83. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  84. "not free.\n",
  85. DRV_NAME, io_addr, io_addr + 7);
  86. continue;
  87. }
  88. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  89. printk(KERN_ERR "%s: I/O resource 0x%lX "
  90. "not free.\n",
  91. DRV_NAME, io_addr + 0x206);
  92. release_region(io_addr, 8);
  93. continue;
  94. }
  95. memset(&hw[i], 0, sizeof(hw[i]));
  96. ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
  97. hw[i].irq = ide_default_irq(io_addr);
  98. hw[i].chipset = ide_generic;
  99. hws[i] = &hw[i];
  100. }
  101. }
  102. host = ide_host_alloc_all(NULL, hws);
  103. if (host == NULL) {
  104. rc = -ENOMEM;
  105. goto err;
  106. }
  107. rc = ide_host_register(host, NULL, hws);
  108. if (rc)
  109. goto err_free;
  110. if (ide_generic_sysfs_init())
  111. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  112. "class\n");
  113. return 0;
  114. err_free:
  115. ide_host_free(host);
  116. err:
  117. for (i = 0; i < MAX_HWIFS; i++) {
  118. if (hws[i] == NULL)
  119. continue;
  120. io_addr = hws[i]->io_ports.data_addr;
  121. release_region(io_addr + 0x206, 1);
  122. release_region(io_addr, 8);
  123. }
  124. return rc;
  125. }
  126. module_init(ide_generic_init);
  127. MODULE_LICENSE("GPL");