zalon.c 5.0 KB

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