pata_palmld.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * drivers/ata/pata_palmld.c
  4. *
  5. * Driver for IDE channel in Palm LifeDrive
  6. *
  7. * Based on research of:
  8. * Alex Osborne <ato@meshy.org>
  9. *
  10. * Rewrite for mainline:
  11. * Marek Vasut <marek.vasut@gmail.com>
  12. *
  13. * Rewritten version based on pata_ixp4xx_cf.c:
  14. * ixp4xx PATA/Compact Flash driver
  15. * Copyright (C) 2006-07 Tower Technologies
  16. * Author: Alessandro Zummo <a.zummo@towertech.it>
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/module.h>
  20. #include <linux/libata.h>
  21. #include <linux/irq.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/delay.h>
  24. #include <linux/gpio/consumer.h>
  25. #include <scsi/scsi_host.h>
  26. #include <mach/palmld.h>
  27. #define DRV_NAME "pata_palmld"
  28. struct palmld_pata {
  29. struct ata_host *host;
  30. struct gpio_desc *power;
  31. struct gpio_desc *reset;
  32. };
  33. static struct scsi_host_template palmld_sht = {
  34. ATA_PIO_SHT(DRV_NAME),
  35. };
  36. static struct ata_port_operations palmld_port_ops = {
  37. .inherits = &ata_sff_port_ops,
  38. .sff_data_xfer = ata_sff_data_xfer32,
  39. .cable_detect = ata_cable_40wire,
  40. };
  41. static int palmld_pata_probe(struct platform_device *pdev)
  42. {
  43. struct palmld_pata *lda;
  44. struct ata_port *ap;
  45. void __iomem *mem;
  46. struct device *dev = &pdev->dev;
  47. int ret;
  48. lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL);
  49. if (!lda)
  50. return -ENOMEM;
  51. /* allocate host */
  52. lda->host = ata_host_alloc(dev, 1);
  53. if (!lda->host)
  54. return -ENOMEM;
  55. /* remap drive's physical memory address */
  56. mem = devm_ioremap(dev, PALMLD_IDE_PHYS, 0x1000);
  57. if (!mem)
  58. return -ENOMEM;
  59. /* request and activate power and reset GPIOs */
  60. lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
  61. if (IS_ERR(lda->power))
  62. return PTR_ERR(lda->power);
  63. lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
  64. if (IS_ERR(lda->reset)) {
  65. gpiod_set_value(lda->power, 0);
  66. return PTR_ERR(lda->reset);
  67. }
  68. /* Assert reset to reset the drive */
  69. gpiod_set_value(lda->reset, 1);
  70. msleep(30);
  71. gpiod_set_value(lda->reset, 0);
  72. msleep(30);
  73. /* setup the ata port */
  74. ap = lda->host->ports[0];
  75. ap->ops = &palmld_port_ops;
  76. ap->pio_mask = ATA_PIO4;
  77. ap->flags |= ATA_FLAG_PIO_POLLING;
  78. /* memory mapping voodoo */
  79. ap->ioaddr.cmd_addr = mem + 0x10;
  80. ap->ioaddr.altstatus_addr = mem + 0xe;
  81. ap->ioaddr.ctl_addr = mem + 0xe;
  82. /* start the port */
  83. ata_sff_std_ports(&ap->ioaddr);
  84. /* activate host */
  85. ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING,
  86. &palmld_sht);
  87. /* power down on failure */
  88. if (ret) {
  89. gpiod_set_value(lda->power, 0);
  90. return ret;
  91. }
  92. platform_set_drvdata(pdev, lda);
  93. return 0;
  94. }
  95. static int palmld_pata_remove(struct platform_device *pdev)
  96. {
  97. struct palmld_pata *lda = platform_get_drvdata(pdev);
  98. ata_platform_remove_one(pdev);
  99. /* power down the HDD */
  100. gpiod_set_value(lda->power, 0);
  101. return 0;
  102. }
  103. static struct platform_driver palmld_pata_platform_driver = {
  104. .driver = {
  105. .name = DRV_NAME,
  106. },
  107. .probe = palmld_pata_probe,
  108. .remove = palmld_pata_remove,
  109. };
  110. module_platform_driver(palmld_pata_platform_driver);
  111. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  112. MODULE_DESCRIPTION("PalmLD PATA driver");
  113. MODULE_LICENSE("GPL");
  114. MODULE_ALIAS("platform:" DRV_NAME);