pata_palmld.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * drivers/ata/pata_palmld.c
  3. *
  4. * Driver for IDE channel in Palm LifeDrive
  5. *
  6. * Based on research of:
  7. * Alex Osborne <ato@meshy.org>
  8. *
  9. * Rewrite for mainline:
  10. * Marek Vasut <marek.vasut@gmail.com>
  11. *
  12. * Rewritten version based on pata_ixp4xx_cf.c:
  13. * ixp4xx PATA/Compact Flash driver
  14. * Copyright (C) 2006-07 Tower Technologies
  15. * Author: Alessandro Zummo <a.zummo@towertech.it>
  16. *
  17. * This program is free software; you can redistribute it and/or modify
  18. * it under the terms of the GNU General Public License version 2 as
  19. * published by the Free Software Foundation.
  20. *
  21. */
  22. #include <linux/kernel.h>
  23. #include <linux/module.h>
  24. #include <linux/libata.h>
  25. #include <linux/irq.h>
  26. #include <linux/platform_device.h>
  27. #include <linux/delay.h>
  28. #include <linux/gpio.h>
  29. #include <scsi/scsi_host.h>
  30. #include <mach/palmld.h>
  31. #define DRV_NAME "pata_palmld"
  32. static struct gpio palmld_hdd_gpios[] = {
  33. { GPIO_NR_PALMLD_IDE_PWEN, GPIOF_INIT_HIGH, "HDD Power" },
  34. { GPIO_NR_PALMLD_IDE_RESET, GPIOF_INIT_LOW, "HDD Reset" },
  35. };
  36. static struct scsi_host_template palmld_sht = {
  37. ATA_PIO_SHT(DRV_NAME),
  38. };
  39. static struct ata_port_operations palmld_port_ops = {
  40. .inherits = &ata_sff_port_ops,
  41. .sff_data_xfer = ata_sff_data_xfer_noirq,
  42. .cable_detect = ata_cable_40wire,
  43. };
  44. static int palmld_pata_probe(struct platform_device *pdev)
  45. {
  46. struct ata_host *host;
  47. struct ata_port *ap;
  48. void __iomem *mem;
  49. int ret;
  50. /* allocate host */
  51. host = ata_host_alloc(&pdev->dev, 1);
  52. if (!host) {
  53. ret = -ENOMEM;
  54. goto err1;
  55. }
  56. /* remap drive's physical memory address */
  57. mem = devm_ioremap(&pdev->dev, PALMLD_IDE_PHYS, 0x1000);
  58. if (!mem) {
  59. ret = -ENOMEM;
  60. goto err1;
  61. }
  62. /* request and activate power GPIO, IRQ GPIO */
  63. ret = gpio_request_array(palmld_hdd_gpios,
  64. ARRAY_SIZE(palmld_hdd_gpios));
  65. if (ret)
  66. goto err1;
  67. /* reset the drive */
  68. gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 0);
  69. msleep(30);
  70. gpio_set_value(GPIO_NR_PALMLD_IDE_RESET, 1);
  71. msleep(30);
  72. /* setup the ata port */
  73. ap = 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(host, 0, NULL, IRQF_TRIGGER_RISING,
  85. &palmld_sht);
  86. if (ret)
  87. goto err2;
  88. return ret;
  89. err2:
  90. gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
  91. err1:
  92. return ret;
  93. }
  94. static int palmld_pata_remove(struct platform_device *dev)
  95. {
  96. ata_platform_remove_one(dev);
  97. /* power down the HDD */
  98. gpio_set_value(GPIO_NR_PALMLD_IDE_PWEN, 0);
  99. gpio_free_array(palmld_hdd_gpios, ARRAY_SIZE(palmld_hdd_gpios));
  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 <marek.vasut@gmail.com>");
  111. MODULE_DESCRIPTION("PalmLD PATA driver");
  112. MODULE_LICENSE("GPL");
  113. MODULE_ALIAS("platform:" DRV_NAME);