ide-generic.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. /* FIXME: convert m32r to use ide_platform host driver */
  21. #ifdef CONFIG_M32R
  22. #include <asm/m32r.h>
  23. #endif
  24. #define DRV_NAME "ide_generic"
  25. static int probe_mask = 0x03;
  26. module_param(probe_mask, int, 0);
  27. MODULE_PARM_DESC(probe_mask, "probe mask for legacy ISA IDE ports");
  28. static ssize_t store_add(struct class *cls, const char *buf, size_t n)
  29. {
  30. unsigned int base, ctl;
  31. int irq, rc;
  32. hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
  33. if (sscanf(buf, "%x:%x:%d", &base, &ctl, &irq) != 3)
  34. return -EINVAL;
  35. memset(&hw, 0, sizeof(hw));
  36. ide_std_init_ports(&hw, base, ctl);
  37. hw.irq = irq;
  38. hw.chipset = ide_generic;
  39. rc = ide_host_add(NULL, hws, NULL);
  40. if (rc)
  41. return rc;
  42. return n;
  43. };
  44. static struct class_attribute ide_generic_class_attrs[] = {
  45. __ATTR(add, S_IWUSR, NULL, store_add),
  46. __ATTR_NULL
  47. };
  48. static void ide_generic_class_release(struct class *cls)
  49. {
  50. kfree(cls);
  51. }
  52. static int __init ide_generic_sysfs_init(void)
  53. {
  54. struct class *cls;
  55. int rc;
  56. cls = kzalloc(sizeof(*cls), GFP_KERNEL);
  57. if (!cls)
  58. return -ENOMEM;
  59. cls->name = DRV_NAME;
  60. cls->owner = THIS_MODULE;
  61. cls->class_release = ide_generic_class_release;
  62. cls->class_attrs = ide_generic_class_attrs;
  63. rc = class_register(cls);
  64. if (rc) {
  65. kfree(cls);
  66. return rc;
  67. }
  68. return 0;
  69. }
  70. #if defined(CONFIG_PLAT_M32700UT) || defined(CONFIG_PLAT_MAPPI2) \
  71. || defined(CONFIG_PLAT_OPSPUT)
  72. static const u16 legacy_bases[] = { 0x1f0 };
  73. static const int legacy_irqs[] = { PLD_IRQ_CFIREQ };
  74. #elif defined(CONFIG_PLAT_MAPPI3)
  75. static const u16 legacy_bases[] = { 0x1f0, 0x170 };
  76. static const int legacy_irqs[] = { PLD_IRQ_CFIREQ, PLD_IRQ_IDEIREQ };
  77. #elif defined(CONFIG_ALPHA)
  78. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168 };
  79. static const int legacy_irqs[] = { 14, 15, 11, 10 };
  80. #else
  81. static const u16 legacy_bases[] = { 0x1f0, 0x170, 0x1e8, 0x168, 0x1e0, 0x160 };
  82. static const int legacy_irqs[] = { 14, 15, 11, 10, 8, 12 };
  83. #endif
  84. static int __init ide_generic_init(void)
  85. {
  86. hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS];
  87. struct ide_host *host;
  88. unsigned long io_addr;
  89. int i, rc;
  90. #ifdef CONFIG_MIPS
  91. if (!ide_probe_legacy())
  92. return -ENODEV;
  93. #endif
  94. printk(KERN_INFO DRV_NAME ": please use \"probe_mask=0x3f\" module "
  95. "parameter for probing all legacy ISA IDE ports\n");
  96. memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
  97. for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
  98. io_addr = legacy_bases[i];
  99. hws[i] = NULL;
  100. if ((probe_mask & (1 << i)) && io_addr) {
  101. if (!request_region(io_addr, 8, DRV_NAME)) {
  102. printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
  103. "not free.\n",
  104. DRV_NAME, io_addr, io_addr + 7);
  105. continue;
  106. }
  107. if (!request_region(io_addr + 0x206, 1, DRV_NAME)) {
  108. printk(KERN_ERR "%s: I/O resource 0x%lX "
  109. "not free.\n",
  110. DRV_NAME, io_addr + 0x206);
  111. release_region(io_addr, 8);
  112. continue;
  113. }
  114. memset(&hw[i], 0, sizeof(hw[i]));
  115. ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
  116. #ifdef CONFIG_IA64
  117. hw[i].irq = isa_irq_to_vector(legacy_irqs[i]);
  118. #else
  119. hw[i].irq = legacy_irqs[i];
  120. #endif
  121. hw[i].chipset = ide_generic;
  122. hws[i] = &hw[i];
  123. }
  124. }
  125. host = ide_host_alloc_all(NULL, hws);
  126. if (host == NULL) {
  127. rc = -ENOMEM;
  128. goto err;
  129. }
  130. rc = ide_host_register(host, NULL, hws);
  131. if (rc)
  132. goto err_free;
  133. if (ide_generic_sysfs_init())
  134. printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
  135. "class\n");
  136. return 0;
  137. err_free:
  138. ide_host_free(host);
  139. err:
  140. for (i = 0; i < MAX_HWIFS; i++) {
  141. if (hws[i] == NULL)
  142. continue;
  143. io_addr = hws[i]->io_ports.data_addr;
  144. release_region(io_addr + 0x206, 1);
  145. release_region(io_addr, 8);
  146. }
  147. return rc;
  148. }
  149. module_init(ide_generic_init);
  150. MODULE_LICENSE("GPL");