ide_platform.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Platform IDE driver
  3. *
  4. * Copyright (C) 2007 MontaVista Software
  5. *
  6. * Maintainer: Kumar Gala <galak@kernel.crashing.org>
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the
  10. * Free Software Foundation; either version 2 of the License, or (at your
  11. * option) any later version.
  12. */
  13. #include <linux/types.h>
  14. #include <linux/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/ide.h>
  17. #include <linux/ioport.h>
  18. #include <linux/module.h>
  19. #include <linux/ata_platform.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/io.h>
  22. static void __devinit plat_ide_setup_ports(hw_regs_t *hw,
  23. void __iomem *base,
  24. void __iomem *ctrl,
  25. struct pata_platform_info *pdata,
  26. int irq)
  27. {
  28. unsigned long port = (unsigned long)base;
  29. int i;
  30. hw->io_ports.data_addr = port;
  31. port += (1 << pdata->ioport_shift);
  32. for (i = 1; i <= 7;
  33. i++, port += (1 << pdata->ioport_shift))
  34. hw->io_ports_array[i] = port;
  35. hw->io_ports.ctl_addr = (unsigned long)ctrl;
  36. hw->irq = irq;
  37. hw->chipset = ide_generic;
  38. }
  39. static const struct ide_port_info platform_ide_port_info = {
  40. .host_flags = IDE_HFLAG_NO_DMA,
  41. };
  42. static int __devinit plat_ide_probe(struct platform_device *pdev)
  43. {
  44. struct resource *res_base, *res_alt, *res_irq;
  45. void __iomem *base, *alt_base;
  46. ide_hwif_t *hwif;
  47. struct pata_platform_info *pdata;
  48. u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
  49. int ret = 0;
  50. int mmio = 0;
  51. hw_regs_t hw;
  52. struct ide_port_info d = platform_ide_port_info;
  53. pdata = pdev->dev.platform_data;
  54. /* get a pointer to the register memory */
  55. res_base = platform_get_resource(pdev, IORESOURCE_IO, 0);
  56. res_alt = platform_get_resource(pdev, IORESOURCE_IO, 1);
  57. if (!res_base || !res_alt) {
  58. res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  59. res_alt = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  60. if (!res_base || !res_alt) {
  61. ret = -ENOMEM;
  62. goto out;
  63. }
  64. mmio = 1;
  65. }
  66. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  67. if (!res_irq) {
  68. ret = -EINVAL;
  69. goto out;
  70. }
  71. if (mmio) {
  72. base = devm_ioremap(&pdev->dev,
  73. res_base->start, res_base->end - res_base->start + 1);
  74. alt_base = devm_ioremap(&pdev->dev,
  75. res_alt->start, res_alt->end - res_alt->start + 1);
  76. } else {
  77. base = devm_ioport_map(&pdev->dev,
  78. res_base->start, res_base->end - res_base->start + 1);
  79. alt_base = devm_ioport_map(&pdev->dev,
  80. res_alt->start, res_alt->end - res_alt->start + 1);
  81. }
  82. hwif = ide_find_port();
  83. if (!hwif) {
  84. ret = -ENODEV;
  85. goto out;
  86. }
  87. memset(&hw, 0, sizeof(hw));
  88. plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
  89. hw.dev = &pdev->dev;
  90. ide_init_port_hw(hwif, &hw);
  91. if (mmio) {
  92. d.host_flags |= IDE_HFLAG_MMIO;
  93. default_hwif_mmiops(hwif);
  94. }
  95. idx[0] = hwif->index;
  96. ide_device_add(idx, &d);
  97. platform_set_drvdata(pdev, hwif);
  98. return 0;
  99. out:
  100. return ret;
  101. }
  102. static int __devexit plat_ide_remove(struct platform_device *pdev)
  103. {
  104. ide_hwif_t *hwif = pdev->dev.driver_data;
  105. ide_unregister(hwif);
  106. return 0;
  107. }
  108. static struct platform_driver platform_ide_driver = {
  109. .driver = {
  110. .name = "pata_platform",
  111. .owner = THIS_MODULE,
  112. },
  113. .probe = plat_ide_probe,
  114. .remove = __devexit_p(plat_ide_remove),
  115. };
  116. static int __init platform_ide_init(void)
  117. {
  118. return platform_driver_register(&platform_ide_driver);
  119. }
  120. static void __exit platform_ide_exit(void)
  121. {
  122. platform_driver_unregister(&platform_ide_driver);
  123. }
  124. MODULE_DESCRIPTION("Platform IDE driver");
  125. MODULE_LICENSE("GPL");
  126. MODULE_ALIAS("platform:pata_platform");
  127. module_init(platform_ide_init);
  128. module_exit(platform_ide_exit);