/drivers/scsi/jazz_esp.c

http://github.com/mirrors/linux · C · 221 lines · 167 code · 47 blank · 7 comment · 10 complexity · b3176dd56f251c5cf2bab2525f26bce3 MD5 · raw file

  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /* jazz_esp.c: ESP front-end for MIPS JAZZ systems.
  3. *
  4. * Copyright (C) 2007 Thomas Bogendörfer (tsbogend@alpha.frankende)
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/gfp.h>
  8. #include <linux/types.h>
  9. #include <linux/module.h>
  10. #include <linux/init.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <asm/irq.h>
  15. #include <asm/io.h>
  16. #include <asm/dma.h>
  17. #include <asm/jazz.h>
  18. #include <asm/jazzdma.h>
  19. #include <scsi/scsi_host.h>
  20. #include "esp_scsi.h"
  21. #define DRV_MODULE_NAME "jazz_esp"
  22. #define PFX DRV_MODULE_NAME ": "
  23. #define DRV_VERSION "1.000"
  24. #define DRV_MODULE_RELDATE "May 19, 2007"
  25. static void jazz_esp_write8(struct esp *esp, u8 val, unsigned long reg)
  26. {
  27. *(volatile u8 *)(esp->regs + reg) = val;
  28. }
  29. static u8 jazz_esp_read8(struct esp *esp, unsigned long reg)
  30. {
  31. return *(volatile u8 *)(esp->regs + reg);
  32. }
  33. static int jazz_esp_irq_pending(struct esp *esp)
  34. {
  35. if (jazz_esp_read8(esp, ESP_STATUS) & ESP_STAT_INTR)
  36. return 1;
  37. return 0;
  38. }
  39. static void jazz_esp_reset_dma(struct esp *esp)
  40. {
  41. vdma_disable ((int)esp->dma_regs);
  42. }
  43. static void jazz_esp_dma_drain(struct esp *esp)
  44. {
  45. /* nothing to do */
  46. }
  47. static void jazz_esp_dma_invalidate(struct esp *esp)
  48. {
  49. vdma_disable ((int)esp->dma_regs);
  50. }
  51. static void jazz_esp_send_dma_cmd(struct esp *esp, u32 addr, u32 esp_count,
  52. u32 dma_count, int write, u8 cmd)
  53. {
  54. BUG_ON(!(cmd & ESP_CMD_DMA));
  55. jazz_esp_write8(esp, (esp_count >> 0) & 0xff, ESP_TCLOW);
  56. jazz_esp_write8(esp, (esp_count >> 8) & 0xff, ESP_TCMED);
  57. vdma_disable ((int)esp->dma_regs);
  58. if (write)
  59. vdma_set_mode ((int)esp->dma_regs, DMA_MODE_READ);
  60. else
  61. vdma_set_mode ((int)esp->dma_regs, DMA_MODE_WRITE);
  62. vdma_set_addr ((int)esp->dma_regs, addr);
  63. vdma_set_count ((int)esp->dma_regs, dma_count);
  64. vdma_enable ((int)esp->dma_regs);
  65. scsi_esp_cmd(esp, cmd);
  66. }
  67. static int jazz_esp_dma_error(struct esp *esp)
  68. {
  69. u32 enable = vdma_get_enable((int)esp->dma_regs);
  70. if (enable & (R4030_MEM_INTR|R4030_ADDR_INTR))
  71. return 1;
  72. return 0;
  73. }
  74. static const struct esp_driver_ops jazz_esp_ops = {
  75. .esp_write8 = jazz_esp_write8,
  76. .esp_read8 = jazz_esp_read8,
  77. .irq_pending = jazz_esp_irq_pending,
  78. .reset_dma = jazz_esp_reset_dma,
  79. .dma_drain = jazz_esp_dma_drain,
  80. .dma_invalidate = jazz_esp_dma_invalidate,
  81. .send_dma_cmd = jazz_esp_send_dma_cmd,
  82. .dma_error = jazz_esp_dma_error,
  83. };
  84. static int esp_jazz_probe(struct platform_device *dev)
  85. {
  86. struct scsi_host_template *tpnt = &scsi_esp_template;
  87. struct Scsi_Host *host;
  88. struct esp *esp;
  89. struct resource *res;
  90. int err;
  91. host = scsi_host_alloc(tpnt, sizeof(struct esp));
  92. err = -ENOMEM;
  93. if (!host)
  94. goto fail;
  95. host->max_id = 8;
  96. esp = shost_priv(host);
  97. esp->host = host;
  98. esp->dev = &dev->dev;
  99. esp->ops = &jazz_esp_ops;
  100. res = platform_get_resource(dev, IORESOURCE_MEM, 0);
  101. if (!res)
  102. goto fail_unlink;
  103. esp->regs = (void __iomem *)res->start;
  104. if (!esp->regs)
  105. goto fail_unlink;
  106. res = platform_get_resource(dev, IORESOURCE_MEM, 1);
  107. if (!res)
  108. goto fail_unlink;
  109. esp->dma_regs = (void __iomem *)res->start;
  110. esp->command_block = dma_alloc_coherent(esp->dev, 16,
  111. &esp->command_block_dma,
  112. GFP_KERNEL);
  113. if (!esp->command_block)
  114. goto fail_unmap_regs;
  115. host->irq = platform_get_irq(dev, 0);
  116. err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
  117. if (err < 0)
  118. goto fail_unmap_command_block;
  119. esp->scsi_id = 7;
  120. esp->host->this_id = esp->scsi_id;
  121. esp->scsi_id_mask = (1 << esp->scsi_id);
  122. esp->cfreq = 40000000;
  123. dev_set_drvdata(&dev->dev, esp);
  124. err = scsi_esp_register(esp);
  125. if (err)
  126. goto fail_free_irq;
  127. return 0;
  128. fail_free_irq:
  129. free_irq(host->irq, esp);
  130. fail_unmap_command_block:
  131. dma_free_coherent(esp->dev, 16,
  132. esp->command_block,
  133. esp->command_block_dma);
  134. fail_unmap_regs:
  135. fail_unlink:
  136. scsi_host_put(host);
  137. fail:
  138. return err;
  139. }
  140. static int esp_jazz_remove(struct platform_device *dev)
  141. {
  142. struct esp *esp = dev_get_drvdata(&dev->dev);
  143. unsigned int irq = esp->host->irq;
  144. scsi_esp_unregister(esp);
  145. free_irq(irq, esp);
  146. dma_free_coherent(esp->dev, 16,
  147. esp->command_block,
  148. esp->command_block_dma);
  149. scsi_host_put(esp->host);
  150. return 0;
  151. }
  152. /* work with hotplug and coldplug */
  153. MODULE_ALIAS("platform:jazz_esp");
  154. static struct platform_driver esp_jazz_driver = {
  155. .probe = esp_jazz_probe,
  156. .remove = esp_jazz_remove,
  157. .driver = {
  158. .name = "jazz_esp",
  159. },
  160. };
  161. static int __init jazz_esp_init(void)
  162. {
  163. return platform_driver_register(&esp_jazz_driver);
  164. }
  165. static void __exit jazz_esp_exit(void)
  166. {
  167. platform_driver_unregister(&esp_jazz_driver);
  168. }
  169. MODULE_DESCRIPTION("JAZZ ESP SCSI driver");
  170. MODULE_AUTHOR("Thomas Bogendoerfer (tsbogend@alpha.franken.de)");
  171. MODULE_LICENSE("GPL");
  172. MODULE_VERSION(DRV_VERSION);
  173. module_init(jazz_esp_init);
  174. module_exit(jazz_esp_exit);