pata_falcon.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Atari Falcon PATA controller driver
  4. *
  5. * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  6. * http://www.samsung.com
  7. *
  8. * Based on falconide.c:
  9. *
  10. * Created 12 Jul 1997 by Geert Uytterhoeven
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/blkdev.h>
  16. #include <linux/delay.h>
  17. #include <scsi/scsi_host.h>
  18. #include <scsi/scsi_cmnd.h>
  19. #include <linux/ata.h>
  20. #include <linux/libata.h>
  21. #include <linux/mm.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/platform_device.h>
  24. #include <asm/setup.h>
  25. #include <asm/atarihw.h>
  26. #include <asm/atariints.h>
  27. #include <asm/atari_stdma.h>
  28. #include <asm/ide.h>
  29. #define DRV_NAME "pata_falcon"
  30. #define DRV_VERSION "0.1.0"
  31. #define ATA_HD_CONTROL 0x39
  32. static struct scsi_host_template pata_falcon_sht = {
  33. ATA_PIO_SHT(DRV_NAME),
  34. };
  35. static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
  36. unsigned char *buf,
  37. unsigned int buflen, int rw)
  38. {
  39. struct ata_device *dev = qc->dev;
  40. struct ata_port *ap = dev->link->ap;
  41. void __iomem *data_addr = ap->ioaddr.data_addr;
  42. unsigned int words = buflen >> 1;
  43. struct scsi_cmnd *cmd = qc->scsicmd;
  44. bool swap = 1;
  45. if (dev->class == ATA_DEV_ATA && cmd && cmd->request &&
  46. !blk_rq_is_passthrough(cmd->request))
  47. swap = 0;
  48. /* Transfer multiple of 2 bytes */
  49. if (rw == READ) {
  50. if (swap)
  51. raw_insw_swapw((u16 *)data_addr, (u16 *)buf, words);
  52. else
  53. raw_insw((u16 *)data_addr, (u16 *)buf, words);
  54. } else {
  55. if (swap)
  56. raw_outsw_swapw((u16 *)data_addr, (u16 *)buf, words);
  57. else
  58. raw_outsw((u16 *)data_addr, (u16 *)buf, words);
  59. }
  60. /* Transfer trailing byte, if any. */
  61. if (unlikely(buflen & 0x01)) {
  62. unsigned char pad[2] = { };
  63. /* Point buf to the tail of buffer */
  64. buf += buflen - 1;
  65. if (rw == READ) {
  66. if (swap)
  67. raw_insw_swapw((u16 *)data_addr, (u16 *)pad, 1);
  68. else
  69. raw_insw((u16 *)data_addr, (u16 *)pad, 1);
  70. *buf = pad[0];
  71. } else {
  72. pad[0] = *buf;
  73. if (swap)
  74. raw_outsw_swapw((u16 *)data_addr, (u16 *)pad, 1);
  75. else
  76. raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
  77. }
  78. words++;
  79. }
  80. return words << 1;
  81. }
  82. /*
  83. * Provide our own set_mode() as we don't want to change anything that has
  84. * already been configured..
  85. */
  86. static int pata_falcon_set_mode(struct ata_link *link,
  87. struct ata_device **unused)
  88. {
  89. struct ata_device *dev;
  90. ata_for_each_dev(dev, link, ENABLED) {
  91. /* We don't really care */
  92. dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
  93. dev->xfer_shift = ATA_SHIFT_PIO;
  94. dev->flags |= ATA_DFLAG_PIO;
  95. ata_dev_info(dev, "configured for PIO\n");
  96. }
  97. return 0;
  98. }
  99. static struct ata_port_operations pata_falcon_ops = {
  100. .inherits = &ata_sff_port_ops,
  101. .sff_data_xfer = pata_falcon_data_xfer,
  102. .cable_detect = ata_cable_unknown,
  103. .set_mode = pata_falcon_set_mode,
  104. };
  105. static int __init pata_falcon_init_one(struct platform_device *pdev)
  106. {
  107. struct resource *res;
  108. struct ata_host *host;
  109. struct ata_port *ap;
  110. void __iomem *base;
  111. dev_info(&pdev->dev, "Atari Falcon PATA controller\n");
  112. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  113. if (!res)
  114. return -ENODEV;
  115. if (!devm_request_mem_region(&pdev->dev, res->start,
  116. resource_size(res), DRV_NAME)) {
  117. dev_err(&pdev->dev, "resources busy\n");
  118. return -EBUSY;
  119. }
  120. /* allocate host */
  121. host = ata_host_alloc(&pdev->dev, 1);
  122. if (!host)
  123. return -ENOMEM;
  124. ap = host->ports[0];
  125. ap->ops = &pata_falcon_ops;
  126. ap->pio_mask = ATA_PIO4;
  127. ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
  128. ap->flags |= ATA_FLAG_PIO_POLLING;
  129. base = (void __iomem *)res->start;
  130. ap->ioaddr.data_addr = base;
  131. ap->ioaddr.error_addr = base + 1 + 1 * 4;
  132. ap->ioaddr.feature_addr = base + 1 + 1 * 4;
  133. ap->ioaddr.nsect_addr = base + 1 + 2 * 4;
  134. ap->ioaddr.lbal_addr = base + 1 + 3 * 4;
  135. ap->ioaddr.lbam_addr = base + 1 + 4 * 4;
  136. ap->ioaddr.lbah_addr = base + 1 + 5 * 4;
  137. ap->ioaddr.device_addr = base + 1 + 6 * 4;
  138. ap->ioaddr.status_addr = base + 1 + 7 * 4;
  139. ap->ioaddr.command_addr = base + 1 + 7 * 4;
  140. ap->ioaddr.altstatus_addr = base + ATA_HD_CONTROL;
  141. ap->ioaddr.ctl_addr = base + ATA_HD_CONTROL;
  142. ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", (unsigned long)base,
  143. (unsigned long)base + ATA_HD_CONTROL);
  144. /* activate */
  145. return ata_host_activate(host, 0, NULL, 0, &pata_falcon_sht);
  146. }
  147. static int __exit pata_falcon_remove_one(struct platform_device *pdev)
  148. {
  149. struct ata_host *host = platform_get_drvdata(pdev);
  150. ata_host_detach(host);
  151. return 0;
  152. }
  153. static struct platform_driver pata_falcon_driver = {
  154. .remove = __exit_p(pata_falcon_remove_one),
  155. .driver = {
  156. .name = "atari-falcon-ide",
  157. },
  158. };
  159. module_platform_driver_probe(pata_falcon_driver, pata_falcon_init_one);
  160. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
  161. MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
  162. MODULE_LICENSE("GPL v2");
  163. MODULE_ALIAS("platform:atari-falcon-ide");
  164. MODULE_VERSION(DRV_VERSION);