ide-generic.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. int i;
  71. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
  72. "parameter for probing all legacy ISA IDE ports\n");
  73. for (i = 0; i < MAX_HWIFS; i++) {
  74. unsigned long io_addr = ide_default_io_base(i);
  75. hws[i] = NULL;
  76. if ((probe_mask & (1 << i)) && io_addr) {
  77. if (!request_region(io_addr, 8, DRV_NAME)) {
  78. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  79. "not free.\n",
  80. DRV_NAME, io_addr, io_addr + 7);
  81. continue;
  82. }
  83. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  84. printk(KERN_ERR "%s: I/O resource 0x%lX "
  85. "not free.\n",
  86. DRV_NAME, io_addr + 0x206);
  87. release_region(io_addr, 8);
  88. continue;
  89. }
  90. memset(&hw[i], 0, sizeof(hw[i]));
  91. ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
  92. hw[i].irq = ide_default_irq(io_addr);
  93. hw[i].chipset = ide_generic;
  94. hws[i] = &hw[i];
  95. }
  96. }
  97. host = ide_host_alloc_all(NULL, hws);
  98. if (host)
  99. ide_host_register(host, NULL, hws);
  100. if (ide_generic_sysfs_init())
  101. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  102. "class\n");
  103. return 0;
  104. }
  105. module_init(ide_generic_init);
  106. MODULE_LICENSE("GPL");