zalon.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Zalon 53c7xx device driver.
  4. * By Richard Hirst ([email protected])
  5. */
  6. #include <linux/init.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/module.h>
  9. #include <linux/types.h>
  10. #include <asm/hardware.h>
  11. #include <asm/io.h>
  12. #include "../parisc/gsc.h"
  13. #include "ncr53c8xx.h"
  14. MODULE_AUTHOR("Richard Hirst");
  15. MODULE_DESCRIPTION("Bluefish/Zalon 720 SCSI Driver");
  16. MODULE_LICENSE("GPL");
  17. #define GSC_SCSI_ZALON_OFFSET 0x800
  18. #define IO_MODULE_EIM (1*4)
  19. #define IO_MODULE_DC_ADATA (2*4)
  20. #define IO_MODULE_II_CDATA (3*4)
  21. #define IO_MODULE_IO_COMMAND (12*4)
  22. #define IO_MODULE_IO_STATUS (13*4)
  23. #define IOSTATUS_RY 0x40
  24. #define IOSTATUS_FE 0x80
  25. #define IOIIDATA_SMINT5L 0x40000000
  26. #define IOIIDATA_MINT5EN 0x20000000
  27. #define IOIIDATA_PACKEN 0x10000000
  28. #define IOIIDATA_PREFETCHEN 0x08000000
  29. #define IOIIDATA_IOII 0x00000020
  30. #define CMD_RESET 5
  31. static struct ncr_chip zalon720_chip __initdata = {
  32. .revision_id = 0x0f,
  33. .burst_max = 3,
  34. .offset_max = 8,
  35. .nr_divisor = 4,
  36. .features = FE_WIDE | FE_DIFF | FE_EHP| FE_MUX | FE_EA,
  37. };
  38. #if 0
  39. /* FIXME:
  40. * Is this function dead code? or is someone planning on using it in the
  41. * future. The clock = (int) pdc_result[16] does not look correct to
  42. * me ... I think it should be iodc_data[16]. Since this cause a compile
  43. * error with the new encapsulated PDC, I'm not compiling in this function.
  44. * - RB
  45. */
  46. /* poke SCSI clock out of iodc data */
  47. static u8 iodc_data[32] __attribute__ ((aligned (64)));
  48. static unsigned long pdc_result[32] __attribute__ ((aligned (16))) ={0,0,0,0};
  49. static int
  50. lasi_scsi_clock(void * hpa, int defaultclock)
  51. {
  52. int clock, status;
  53. status = pdc_iodc_read(&pdc_result, hpa, 0, &iodc_data, 32 );
  54. if (status == PDC_RET_OK) {
  55. clock = (int) pdc_result[16];
  56. } else {
  57. printk(KERN_WARNING "%s: pdc_iodc_read returned %d\n", __func__, status);
  58. clock = defaultclock;
  59. }
  60. printk(KERN_DEBUG "%s: SCSI clock %d\n", __func__, clock);
  61. return clock;
  62. }
  63. #endif
  64. static struct scsi_host_template zalon7xx_template = {
  65. .module = THIS_MODULE,
  66. .proc_name = "zalon7xx",
  67. .cmd_size = sizeof(struct ncr_cmd_priv),
  68. };
  69. static int __init
  70. zalon_probe(struct parisc_device *dev)
  71. {
  72. struct gsc_irq gsc_irq;
  73. u32 zalon_vers;
  74. int error = -ENODEV;
  75. void __iomem *zalon = ioremap(dev->hpa.start, 4096);
  76. void __iomem *io_port = zalon + GSC_SCSI_ZALON_OFFSET;
  77. static int unit = 0;
  78. struct Scsi_Host *host;
  79. struct ncr_device device;
  80. __raw_writel(CMD_RESET, zalon + IO_MODULE_IO_COMMAND);
  81. while (!(__raw_readl(zalon + IO_MODULE_IO_STATUS) & IOSTATUS_RY))
  82. cpu_relax();
  83. __raw_writel(IOIIDATA_MINT5EN | IOIIDATA_PACKEN | IOIIDATA_PREFETCHEN,
  84. zalon + IO_MODULE_II_CDATA);
  85. /* XXX: Save the Zalon version for bug workarounds? */
  86. zalon_vers = (__raw_readl(zalon + IO_MODULE_II_CDATA) >> 24) & 0x07;
  87. /* Setup the interrupts first.
  88. ** Later on request_irq() will register the handler.
  89. */
  90. dev->irq = gsc_alloc_irq(&gsc_irq);
  91. printk(KERN_INFO "%s: Zalon version %d, IRQ %d\n", __func__,
  92. zalon_vers, dev->irq);
  93. __raw_writel(gsc_irq.txn_addr | gsc_irq.txn_data, zalon + IO_MODULE_EIM);
  94. if (zalon_vers == 0)
  95. printk(KERN_WARNING "%s: Zalon 1.1 or earlier\n", __func__);
  96. memset(&device, 0, sizeof(struct ncr_device));
  97. /* The following three are needed before any other access. */
  98. __raw_writeb(0x20, io_port + 0x38); /* DCNTL_REG, EA */
  99. __raw_writeb(0x04, io_port + 0x1b); /* CTEST0_REG, EHP */
  100. __raw_writeb(0x80, io_port + 0x22); /* CTEST4_REG, MUX */
  101. /* Initialise ncr_device structure with items required by ncr_attach. */
  102. device.chip = zalon720_chip;
  103. device.host_id = 7;
  104. device.dev = &dev->dev;
  105. device.slot.base = dev->hpa.start + GSC_SCSI_ZALON_OFFSET;
  106. device.slot.base_v = io_port;
  107. device.slot.irq = dev->irq;
  108. device.differential = 2;
  109. host = ncr_attach(&zalon7xx_template, unit, &device);
  110. if (!host)
  111. return -ENODEV;
  112. if (request_irq(dev->irq, ncr53c8xx_intr, IRQF_SHARED, "zalon", host)) {
  113. dev_printk(KERN_ERR, &dev->dev, "irq problem with %d, detaching\n ",
  114. dev->irq);
  115. goto fail;
  116. }
  117. unit++;
  118. dev_set_drvdata(&dev->dev, host);
  119. error = scsi_add_host(host, &dev->dev);
  120. if (error)
  121. goto fail_free_irq;
  122. scsi_scan_host(host);
  123. return 0;
  124. fail_free_irq:
  125. free_irq(dev->irq, host);
  126. fail:
  127. ncr53c8xx_release(host);
  128. return error;
  129. }
  130. static const struct parisc_device_id zalon_tbl[] __initconst = {
  131. { HPHW_A_DMA, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x00089 },
  132. { 0, }
  133. };
  134. MODULE_DEVICE_TABLE(parisc, zalon_tbl);
  135. static void __exit zalon_remove(struct parisc_device *dev)
  136. {
  137. struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
  138. scsi_remove_host(host);
  139. ncr53c8xx_release(host);
  140. free_irq(dev->irq, host);
  141. }
  142. static struct parisc_driver zalon_driver __refdata = {
  143. .name = "zalon",
  144. .id_table = zalon_tbl,
  145. .probe = zalon_probe,
  146. .remove = __exit_p(zalon_remove),
  147. };
  148. static int __init zalon7xx_init(void)
  149. {
  150. int ret = ncr53c8xx_init();
  151. if (!ret)
  152. ret = register_parisc_driver(&zalon_driver);
  153. if (ret)
  154. ncr53c8xx_exit();
  155. return ret;
  156. }
  157. static void __exit zalon7xx_exit(void)
  158. {
  159. unregister_parisc_driver(&zalon_driver);
  160. ncr53c8xx_exit();
  161. }
  162. module_init(zalon7xx_init);
  163. module_exit(zalon7xx_exit);