jazz_esp.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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 ([email protected])
  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 = err = platform_get_irq(dev, 0);
  116. if (err < 0)
  117. goto fail_unmap_command_block;
  118. err = request_irq(host->irq, scsi_esp_intr, IRQF_SHARED, "ESP", esp);
  119. if (err < 0)
  120. goto fail_unmap_command_block;
  121. esp->scsi_id = 7;
  122. esp->host->this_id = esp->scsi_id;
  123. esp->scsi_id_mask = (1 << esp->scsi_id);
  124. esp->cfreq = 40000000;
  125. dev_set_drvdata(&dev->dev, esp);
  126. err = scsi_esp_register(esp);
  127. if (err)
  128. goto fail_free_irq;
  129. return 0;
  130. fail_free_irq:
  131. free_irq(host->irq, esp);
  132. fail_unmap_command_block:
  133. dma_free_coherent(esp->dev, 16,
  134. esp->command_block,
  135. esp->command_block_dma);
  136. fail_unmap_regs:
  137. fail_unlink:
  138. scsi_host_put(host);
  139. fail:
  140. return err;
  141. }
  142. static int esp_jazz_remove(struct platform_device *dev)
  143. {
  144. struct esp *esp = dev_get_drvdata(&dev->dev);
  145. unsigned int irq = esp->host->irq;
  146. scsi_esp_unregister(esp);
  147. free_irq(irq, esp);
  148. dma_free_coherent(esp->dev, 16,
  149. esp->command_block,
  150. esp->command_block_dma);
  151. scsi_host_put(esp->host);
  152. return 0;
  153. }
  154. /* work with hotplug and coldplug */
  155. MODULE_ALIAS("platform:jazz_esp");
  156. static struct platform_driver esp_jazz_driver = {
  157. .probe = esp_jazz_probe,
  158. .remove = esp_jazz_remove,
  159. .driver = {
  160. .name = "jazz_esp",
  161. },
  162. };
  163. module_platform_driver(esp_jazz_driver);
  164. MODULE_DESCRIPTION("JAZZ ESP SCSI driver");
  165. MODULE_AUTHOR("Thomas Bogendoerfer ([email protected])");
  166. MODULE_LICENSE("GPL");
  167. MODULE_VERSION(DRV_VERSION);