pata_falcon.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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_BASE 0xfff00000
  32. #define ATA_HD_CONTROL 0x39
  33. static struct scsi_host_template pata_falcon_sht = {
  34. ATA_PIO_SHT(DRV_NAME),
  35. };
  36. static unsigned int pata_falcon_data_xfer(struct ata_queued_cmd *qc,
  37. unsigned char *buf,
  38. unsigned int buflen, int rw)
  39. {
  40. struct ata_device *dev = qc->dev;
  41. struct ata_port *ap = dev->link->ap;
  42. void __iomem *data_addr = ap->ioaddr.data_addr;
  43. unsigned int words = buflen >> 1;
  44. struct scsi_cmnd *cmd = qc->scsicmd;
  45. bool swap = 1;
  46. if (dev->class == ATA_DEV_ATA && cmd && cmd->request &&
  47. !blk_rq_is_passthrough(cmd->request))
  48. swap = 0;
  49. /* Transfer multiple of 2 bytes */
  50. if (rw == READ) {
  51. if (swap)
  52. raw_insw_swapw((u16 *)data_addr, (u16 *)buf, words);
  53. else
  54. raw_insw((u16 *)data_addr, (u16 *)buf, words);
  55. } else {
  56. if (swap)
  57. raw_outsw_swapw((u16 *)data_addr, (u16 *)buf, words);
  58. else
  59. raw_outsw((u16 *)data_addr, (u16 *)buf, words);
  60. }
  61. /* Transfer trailing byte, if any. */
  62. if (unlikely(buflen & 0x01)) {
  63. unsigned char pad[2] = { };
  64. /* Point buf to the tail of buffer */
  65. buf += buflen - 1;
  66. if (rw == READ) {
  67. if (swap)
  68. raw_insw_swapw((u16 *)data_addr, (u16 *)pad, 1);
  69. else
  70. raw_insw((u16 *)data_addr, (u16 *)pad, 1);
  71. *buf = pad[0];
  72. } else {
  73. pad[0] = *buf;
  74. if (swap)
  75. raw_outsw_swapw((u16 *)data_addr, (u16 *)pad, 1);
  76. else
  77. raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
  78. }
  79. words++;
  80. }
  81. return words << 1;
  82. }
  83. /*
  84. * Provide our own set_mode() as we don't want to change anything that has
  85. * already been configured..
  86. */
  87. static int pata_falcon_set_mode(struct ata_link *link,
  88. struct ata_device **unused)
  89. {
  90. struct ata_device *dev;
  91. ata_for_each_dev(dev, link, ENABLED) {
  92. /* We don't really care */
  93. dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
  94. dev->xfer_shift = ATA_SHIFT_PIO;
  95. dev->flags |= ATA_DFLAG_PIO;
  96. ata_dev_info(dev, "configured for PIO\n");
  97. }
  98. return 0;
  99. }
  100. static struct ata_port_operations pata_falcon_ops = {
  101. .inherits = &ata_sff_port_ops,
  102. .sff_data_xfer = pata_falcon_data_xfer,
  103. .cable_detect = ata_cable_unknown,
  104. .set_mode = pata_falcon_set_mode,
  105. };
  106. static int pata_falcon_init_one(void)
  107. {
  108. struct ata_host *host;
  109. struct ata_port *ap;
  110. struct platform_device *pdev;
  111. void __iomem *base;
  112. if (!MACH_IS_ATARI || !ATARIHW_PRESENT(IDE))
  113. return -ENODEV;
  114. pr_info(DRV_NAME ": Atari Falcon PATA controller\n");
  115. pdev = platform_device_register_simple(DRV_NAME, 0, NULL, 0);
  116. if (IS_ERR(pdev))
  117. return PTR_ERR(pdev);
  118. if (!devm_request_mem_region(&pdev->dev, ATA_HD_BASE, 0x40, DRV_NAME)) {
  119. pr_err(DRV_NAME ": resources busy\n");
  120. return -EBUSY;
  121. }
  122. /* allocate host */
  123. host = ata_host_alloc(&pdev->dev, 1);
  124. if (!host)
  125. return -ENOMEM;
  126. ap = host->ports[0];
  127. ap->ops = &pata_falcon_ops;
  128. ap->pio_mask = ATA_PIO4;
  129. ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
  130. ap->flags |= ATA_FLAG_PIO_POLLING;
  131. base = (void __iomem *)ATA_HD_BASE;
  132. ap->ioaddr.data_addr = base;
  133. ap->ioaddr.error_addr = base + 1 + 1 * 4;
  134. ap->ioaddr.feature_addr = base + 1 + 1 * 4;
  135. ap->ioaddr.nsect_addr = base + 1 + 2 * 4;
  136. ap->ioaddr.lbal_addr = base + 1 + 3 * 4;
  137. ap->ioaddr.lbam_addr = base + 1 + 4 * 4;
  138. ap->ioaddr.lbah_addr = base + 1 + 5 * 4;
  139. ap->ioaddr.device_addr = base + 1 + 6 * 4;
  140. ap->ioaddr.status_addr = base + 1 + 7 * 4;
  141. ap->ioaddr.command_addr = base + 1 + 7 * 4;
  142. ap->ioaddr.altstatus_addr = base + ATA_HD_CONTROL;
  143. ap->ioaddr.ctl_addr = base + ATA_HD_CONTROL;
  144. ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", (unsigned long)base,
  145. (unsigned long)base + ATA_HD_CONTROL);
  146. /* activate */
  147. return ata_host_activate(host, 0, NULL, 0, &pata_falcon_sht);
  148. }
  149. module_init(pata_falcon_init_one);
  150. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
  151. MODULE_DESCRIPTION("low-level driver for Atari Falcon PATA");
  152. MODULE_LICENSE("GPL v2");
  153. MODULE_VERSION(DRV_VERSION);