rapide.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * linux/drivers/ide/arm/rapide.c
  3. *
  4. * Copyright (c) 1996-2002 Russell King.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/slab.h>
  8. #include <linux/blkdev.h>
  9. #include <linux/errno.h>
  10. #include <linux/ide.h>
  11. #include <linux/init.h>
  12. #include <asm/ecard.h>
  13. /*
  14. * Something like this really should be in generic code, but isn't.
  15. */
  16. static ide_hwif_t *
  17. rapide_locate_hwif(void __iomem *base, void __iomem *ctrl, unsigned int sz, int irq)
  18. {
  19. unsigned long port = (unsigned long)base;
  20. ide_hwif_t *hwif;
  21. int index, i;
  22. for (index = 0; index < MAX_HWIFS; ++index) {
  23. hwif = ide_hwifs + index;
  24. if (hwif->io_ports[IDE_DATA_OFFSET] == port)
  25. goto found;
  26. }
  27. for (index = 0; index < MAX_HWIFS; ++index) {
  28. hwif = ide_hwifs + index;
  29. if (hwif->io_ports[IDE_DATA_OFFSET] == 0)
  30. goto found;
  31. }
  32. return NULL;
  33. found:
  34. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
  35. hwif->hw.io_ports[i] = port;
  36. hwif->io_ports[i] = port;
  37. port += sz;
  38. }
  39. hwif->hw.io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
  40. hwif->io_ports[IDE_CONTROL_OFFSET] = (unsigned long)ctrl;
  41. hwif->hw.irq = hwif->irq = irq;
  42. hwif->mmio = 2;
  43. default_hwif_mmiops(hwif);
  44. return hwif;
  45. }
  46. static int __devinit
  47. rapide_probe(struct expansion_card *ec, const struct ecard_id *id)
  48. {
  49. ide_hwif_t *hwif;
  50. void __iomem *base;
  51. int ret;
  52. ret = ecard_request_resources(ec);
  53. if (ret)
  54. goto out;
  55. base = ioremap(ecard_resource_start(ec, ECARD_RES_MEMC),
  56. ecard_resource_len(ec, ECARD_RES_MEMC));
  57. if (!base) {
  58. ret = -ENOMEM;
  59. goto release;
  60. }
  61. hwif = rapide_locate_hwif(base, base + 0x818, 1 << 6, ec->irq);
  62. if (hwif) {
  63. hwif->hwif_data = base;
  64. hwif->gendev.parent = &ec->dev;
  65. hwif->noprobe = 0;
  66. probe_hwif_init(hwif);
  67. create_proc_ide_interfaces();
  68. ecard_set_drvdata(ec, hwif);
  69. goto out;
  70. }
  71. iounmap(base);
  72. release:
  73. ecard_release_resources(ec);
  74. out:
  75. return ret;
  76. }
  77. static void __devexit rapide_remove(struct expansion_card *ec)
  78. {
  79. ide_hwif_t *hwif = ecard_get_drvdata(ec);
  80. ecard_set_drvdata(ec, NULL);
  81. /* there must be a better way */
  82. ide_unregister(hwif - ide_hwifs);
  83. iounmap(hwif->hwif_data);
  84. ecard_release_resources(ec);
  85. }
  86. static struct ecard_id rapide_ids[] = {
  87. { MANU_YELLOWSTONE, PROD_YELLOWSTONE_RAPIDE32 },
  88. { 0xffff, 0xffff }
  89. };
  90. static struct ecard_driver rapide_driver = {
  91. .probe = rapide_probe,
  92. .remove = __devexit_p(rapide_remove),
  93. .id_table = rapide_ids,
  94. .drv = {
  95. .name = "rapide",
  96. },
  97. };
  98. static int __init rapide_init(void)
  99. {
  100. return ecard_register_driver(&rapide_driver);
  101. }
  102. MODULE_LICENSE("GPL");
  103. MODULE_DESCRIPTION("Yellowstone RAPIDE driver");
  104. module_init(rapide_init);