ide_platform.c 3.2 KB

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