pata_falcon.c 4.6 KB

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