ide_platform.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/interrupt.h>
  22. #include <linux/io.h>
  23. static void __devinit plat_ide_setup_ports(struct ide_hw *hw,
  24. void __iomem *base,
  25. void __iomem *ctrl,
  26. struct pata_platform_info *pdata,
  27. int irq)
  28. {
  29. unsigned long port = (unsigned long)base;
  30. int i;
  31. hw->io_ports.data_addr = port;
  32. port += (1 << pdata->ioport_shift);
  33. for (i = 1; i <= 7;
  34. i++, port += (1 << pdata->ioport_shift))
  35. hw->io_ports_array[i] = port;
  36. hw->io_ports.ctl_addr = (unsigned long)ctrl;
  37. hw->irq = irq;
  38. }
  39. static const struct ide_port_info platform_ide_port_info = {
  40. .host_flags = IDE_HFLAG_NO_DMA,
  41. .chipset = ide_generic,
  42. };
  43. static int __devinit plat_ide_probe(struct platform_device *pdev)
  44. {
  45. struct resource *res_base, *res_alt, *res_irq;
  46. void __iomem *base, *alt_base;
  47. struct pata_platform_info *pdata;
  48. struct ide_host *host;
  49. int ret = 0, mmio = 0;
  50. struct ide_hw hw, *hws[] = { &hw };
  51. struct ide_port_info d = platform_ide_port_info;
  52. pdata = pdev->dev.platform_data;
  53. /* get a pointer to the register memory */
  54. res_base = platform_get_resource(pdev, IORESOURCE_IO, 0);
  55. res_alt = platform_get_resource(pdev, IORESOURCE_IO, 1);
  56. if (!res_base || !res_alt) {
  57. res_base = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  58. res_alt = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  59. if (!res_base || !res_alt) {
  60. ret = -ENOMEM;
  61. goto out;
  62. }
  63. mmio = 1;
  64. }
  65. res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
  66. if (!res_irq) {
  67. ret = -EINVAL;
  68. goto out;
  69. }
  70. if (mmio) {
  71. base = devm_ioremap(&pdev->dev,
  72. res_base->start, resource_size(res_base));
  73. alt_base = devm_ioremap(&pdev->dev,
  74. res_alt->start, resource_size(res_alt));
  75. } else {
  76. base = devm_ioport_map(&pdev->dev,
  77. res_base->start, resource_size(res_base));
  78. alt_base = devm_ioport_map(&pdev->dev,
  79. res_alt->start, resource_size(res_alt));
  80. }
  81. memset(&hw, 0, sizeof(hw));
  82. plat_ide_setup_ports(&hw, base, alt_base, pdata, res_irq->start);
  83. hw.dev = &pdev->dev;
  84. d.irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
  85. if (res_irq->flags & IORESOURCE_IRQ_SHAREABLE)
  86. d.irq_flags |= IRQF_SHARED;
  87. if (mmio)
  88. d.host_flags |= IDE_HFLAG_MMIO;
  89. ret = ide_host_add(&d, hws, 1, &host);
  90. if (ret)
  91. goto out;
  92. platform_set_drvdata(pdev, host);
  93. return 0;
  94. out:
  95. return ret;
  96. }
  97. static int __devexit plat_ide_remove(struct platform_device *pdev)
  98. {
  99. struct ide_host *host = dev_get_drvdata(&pdev->dev);
  100. ide_host_remove(host);
  101. return 0;
  102. }
  103. static struct platform_driver platform_ide_driver = {
  104. .driver = {
  105. .name = "pata_platform",
  106. .owner = THIS_MODULE,
  107. },
  108. .probe = plat_ide_probe,
  109. .remove = __devexit_p(plat_ide_remove),
  110. };
  111. static int __init platform_ide_init(void)
  112. {
  113. return platform_driver_register(&platform_ide_driver);
  114. }
  115. static void __exit platform_ide_exit(void)
  116. {
  117. platform_driver_unregister(&platform_ide_driver);
  118. }
  119. MODULE_DESCRIPTION("Platform IDE driver");
  120. MODULE_LICENSE("GPL");
  121. MODULE_ALIAS("platform:pata_platform");
  122. module_init(platform_ide_init);
  123. module_exit(platform_ide_exit);