pata_gayle.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Amiga Gayle PATA controller driver
  4. *
  5. * Copyright (c) 2018 Samsung Electronics Co., Ltd.
  6. * http://www.samsung.com
  7. *
  8. * Based on gayle.c:
  9. *
  10. * Created 12 Jul 1997 by Geert Uytterhoeven
  11. */
  12. #include <linux/ata.h>
  13. #include <linux/blkdev.h>
  14. #include <linux/delay.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel.h>
  17. #include <linux/libata.h>
  18. #include <linux/mm.h>
  19. #include <linux/module.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/zorro.h>
  22. #include <scsi/scsi_cmnd.h>
  23. #include <scsi/scsi_host.h>
  24. #include <asm/amigahw.h>
  25. #include <asm/amigaints.h>
  26. #include <asm/amigayle.h>
  27. #include <asm/ide.h>
  28. #include <asm/setup.h>
  29. #define DRV_NAME "pata_gayle"
  30. #define DRV_VERSION "0.1.0"
  31. #define GAYLE_CONTROL 0x101a
  32. static struct scsi_host_template pata_gayle_sht = {
  33. ATA_PIO_SHT(DRV_NAME),
  34. };
  35. /* FIXME: is this needed? */
  36. static unsigned int pata_gayle_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. /* Transfer multiple of 2 bytes */
  45. if (rw == READ)
  46. raw_insw((u16 *)data_addr, (u16 *)buf, words);
  47. else
  48. raw_outsw((u16 *)data_addr, (u16 *)buf, words);
  49. /* Transfer trailing byte, if any. */
  50. if (unlikely(buflen & 0x01)) {
  51. unsigned char pad[2] = { };
  52. /* Point buf to the tail of buffer */
  53. buf += buflen - 1;
  54. if (rw == READ) {
  55. raw_insw((u16 *)data_addr, (u16 *)pad, 1);
  56. *buf = pad[0];
  57. } else {
  58. pad[0] = *buf;
  59. raw_outsw((u16 *)data_addr, (u16 *)pad, 1);
  60. }
  61. words++;
  62. }
  63. return words << 1;
  64. }
  65. /*
  66. * Provide our own set_mode() as we don't want to change anything that has
  67. * already been configured..
  68. */
  69. static int pata_gayle_set_mode(struct ata_link *link,
  70. struct ata_device **unused)
  71. {
  72. struct ata_device *dev;
  73. ata_for_each_dev(dev, link, ENABLED) {
  74. /* We don't really care */
  75. dev->pio_mode = dev->xfer_mode = XFER_PIO_0;
  76. dev->xfer_shift = ATA_SHIFT_PIO;
  77. dev->flags |= ATA_DFLAG_PIO;
  78. ata_dev_info(dev, "configured for PIO\n");
  79. }
  80. return 0;
  81. }
  82. static bool pata_gayle_irq_check(struct ata_port *ap)
  83. {
  84. u8 ch;
  85. ch = z_readb((unsigned long)ap->private_data);
  86. return !!(ch & GAYLE_IRQ_IDE);
  87. }
  88. static void pata_gayle_irq_clear(struct ata_port *ap)
  89. {
  90. (void)z_readb((unsigned long)ap->ioaddr.status_addr);
  91. z_writeb(0x7c, (unsigned long)ap->private_data);
  92. }
  93. static struct ata_port_operations pata_gayle_a1200_ops = {
  94. .inherits = &ata_sff_port_ops,
  95. .sff_data_xfer = pata_gayle_data_xfer,
  96. .sff_irq_check = pata_gayle_irq_check,
  97. .sff_irq_clear = pata_gayle_irq_clear,
  98. .cable_detect = ata_cable_unknown,
  99. .set_mode = pata_gayle_set_mode,
  100. };
  101. static struct ata_port_operations pata_gayle_a4000_ops = {
  102. .inherits = &ata_sff_port_ops,
  103. .sff_data_xfer = pata_gayle_data_xfer,
  104. .cable_detect = ata_cable_unknown,
  105. .set_mode = pata_gayle_set_mode,
  106. };
  107. static int __init pata_gayle_init_one(struct platform_device *pdev)
  108. {
  109. struct resource *res;
  110. struct gayle_ide_platform_data *pdata;
  111. struct ata_host *host;
  112. struct ata_port *ap;
  113. void __iomem *base;
  114. int ret;
  115. pdata = dev_get_platdata(&pdev->dev);
  116. dev_info(&pdev->dev, "Amiga Gayle IDE controller (A%u style)\n",
  117. pdata->explicit_ack ? 1200 : 4000);
  118. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  119. if (!res)
  120. return -ENODEV;
  121. if (!devm_request_mem_region(&pdev->dev, res->start,
  122. resource_size(res), DRV_NAME)) {
  123. pr_err(DRV_NAME ": resources busy\n");
  124. return -EBUSY;
  125. }
  126. /* allocate host */
  127. host = ata_host_alloc(&pdev->dev, 1);
  128. if (!host)
  129. return -ENOMEM;
  130. ap = host->ports[0];
  131. if (pdata->explicit_ack)
  132. ap->ops = &pata_gayle_a1200_ops;
  133. else
  134. ap->ops = &pata_gayle_a4000_ops;
  135. ap->pio_mask = ATA_PIO4;
  136. ap->flags |= ATA_FLAG_SLAVE_POSS | ATA_FLAG_NO_IORDY;
  137. base = ZTWO_VADDR(pdata->base);
  138. ap->ioaddr.data_addr = base;
  139. ap->ioaddr.error_addr = base + 2 + 1 * 4;
  140. ap->ioaddr.feature_addr = base + 2 + 1 * 4;
  141. ap->ioaddr.nsect_addr = base + 2 + 2 * 4;
  142. ap->ioaddr.lbal_addr = base + 2 + 3 * 4;
  143. ap->ioaddr.lbam_addr = base + 2 + 4 * 4;
  144. ap->ioaddr.lbah_addr = base + 2 + 5 * 4;
  145. ap->ioaddr.device_addr = base + 2 + 6 * 4;
  146. ap->ioaddr.status_addr = base + 2 + 7 * 4;
  147. ap->ioaddr.command_addr = base + 2 + 7 * 4;
  148. ap->ioaddr.altstatus_addr = base + GAYLE_CONTROL;
  149. ap->ioaddr.ctl_addr = base + GAYLE_CONTROL;
  150. ap->private_data = (void *)ZTWO_VADDR(pdata->irqport);
  151. ata_port_desc(ap, "cmd 0x%lx ctl 0x%lx", pdata->base,
  152. pdata->base + GAYLE_CONTROL);
  153. ret = ata_host_activate(host, IRQ_AMIGA_PORTS, ata_sff_interrupt,
  154. IRQF_SHARED, &pata_gayle_sht);
  155. if (ret)
  156. return ret;
  157. platform_set_drvdata(pdev, host);
  158. return 0;
  159. }
  160. static int __exit pata_gayle_remove_one(struct platform_device *pdev)
  161. {
  162. struct ata_host *host = platform_get_drvdata(pdev);
  163. ata_host_detach(host);
  164. return 0;
  165. }
  166. static struct platform_driver pata_gayle_driver = {
  167. .remove = __exit_p(pata_gayle_remove_one),
  168. .driver = {
  169. .name = "amiga-gayle-ide",
  170. },
  171. };
  172. module_platform_driver_probe(pata_gayle_driver, pata_gayle_init_one);
  173. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz");
  174. MODULE_DESCRIPTION("low-level driver for Amiga Gayle PATA");
  175. MODULE_LICENSE("GPL v2");
  176. MODULE_ALIAS("platform:amiga-gayle-ide");
  177. MODULE_VERSION(DRV_VERSION);