pata_palmld.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <[email protected]>
  9. *
  10. * Rewrite for mainline:
  11. * Marek Vasut <[email protected]>
  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 <[email protected]>
  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. #define DRV_NAME "pata_palmld"
  27. struct palmld_pata {
  28. struct ata_host *host;
  29. struct gpio_desc *power;
  30. struct gpio_desc *reset;
  31. };
  32. static struct scsi_host_template palmld_sht = {
  33. ATA_PIO_SHT(DRV_NAME),
  34. };
  35. static struct ata_port_operations palmld_port_ops = {
  36. .inherits = &ata_sff_port_ops,
  37. .sff_data_xfer = ata_sff_data_xfer32,
  38. .cable_detect = ata_cable_40wire,
  39. };
  40. static int palmld_pata_probe(struct platform_device *pdev)
  41. {
  42. struct palmld_pata *lda;
  43. struct ata_port *ap;
  44. void __iomem *mem;
  45. struct device *dev = &pdev->dev;
  46. int ret;
  47. lda = devm_kzalloc(dev, sizeof(*lda), GFP_KERNEL);
  48. if (!lda)
  49. return -ENOMEM;
  50. /* allocate host */
  51. lda->host = ata_host_alloc(dev, 1);
  52. if (!lda->host)
  53. return -ENOMEM;
  54. /* remap drive's physical memory address */
  55. mem = devm_platform_ioremap_resource(pdev, 0);
  56. if (IS_ERR(mem))
  57. return PTR_ERR(mem);
  58. /* request and activate power and reset GPIOs */
  59. lda->power = devm_gpiod_get(dev, "power", GPIOD_OUT_HIGH);
  60. if (IS_ERR(lda->power))
  61. return PTR_ERR(lda->power);
  62. lda->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH);
  63. if (IS_ERR(lda->reset)) {
  64. gpiod_set_value(lda->power, 0);
  65. return PTR_ERR(lda->reset);
  66. }
  67. /* Assert reset to reset the drive */
  68. gpiod_set_value(lda->reset, 1);
  69. msleep(30);
  70. gpiod_set_value(lda->reset, 0);
  71. msleep(30);
  72. /* setup the ata port */
  73. ap = lda->host->ports[0];
  74. ap->ops = &palmld_port_ops;
  75. ap->pio_mask = ATA_PIO4;
  76. ap->flags |= ATA_FLAG_PIO_POLLING;
  77. /* memory mapping voodoo */
  78. ap->ioaddr.cmd_addr = mem + 0x10;
  79. ap->ioaddr.altstatus_addr = mem + 0xe;
  80. ap->ioaddr.ctl_addr = mem + 0xe;
  81. /* start the port */
  82. ata_sff_std_ports(&ap->ioaddr);
  83. /* activate host */
  84. ret = ata_host_activate(lda->host, 0, NULL, IRQF_TRIGGER_RISING,
  85. &palmld_sht);
  86. /* power down on failure */
  87. if (ret) {
  88. gpiod_set_value(lda->power, 0);
  89. return ret;
  90. }
  91. platform_set_drvdata(pdev, lda);
  92. return 0;
  93. }
  94. static int palmld_pata_remove(struct platform_device *pdev)
  95. {
  96. struct palmld_pata *lda = platform_get_drvdata(pdev);
  97. ata_platform_remove_one(pdev);
  98. /* power down the HDD */
  99. gpiod_set_value(lda->power, 0);
  100. return 0;
  101. }
  102. static struct platform_driver palmld_pata_platform_driver = {
  103. .driver = {
  104. .name = DRV_NAME,
  105. },
  106. .probe = palmld_pata_probe,
  107. .remove = palmld_pata_remove,
  108. };
  109. module_platform_driver(palmld_pata_platform_driver);
  110. MODULE_AUTHOR("Marek Vasut <[email protected]>");
  111. MODULE_DESCRIPTION("PalmLD PATA driver");
  112. MODULE_LICENSE("GPL");
  113. MODULE_ALIAS("platform:" DRV_NAME);