lasi700.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* -*- mode: c; c-basic-offset: 8 -*- */
  2. /* PARISC LASI driver for the 53c700 chip
  3. *
  4. * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
  5. **-----------------------------------------------------------------------------
  6. **
  7. ** This program is free software; you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation; either version 2 of the License, or
  10. ** (at your option) any later version.
  11. **
  12. ** This program is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with this program; if not, write to the Free Software
  19. ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. **
  21. **-----------------------------------------------------------------------------
  22. */
  23. /*
  24. * Many thanks to Richard Hirst <rhirst@linuxcare.com> for patiently
  25. * debugging this driver on the parisc architecture and suggesting
  26. * many improvements and bug fixes.
  27. *
  28. * Thanks also go to Linuxcare Inc. for providing several PARISC
  29. * machines for me to debug the driver on.
  30. */
  31. #include <linux/kernel.h>
  32. #include <linux/module.h>
  33. #include <linux/init.h>
  34. #include <linux/types.h>
  35. #include <linux/stat.h>
  36. #include <linux/mm.h>
  37. #include <linux/blkdev.h>
  38. #include <linux/ioport.h>
  39. #include <linux/dma-mapping.h>
  40. #include <linux/slab.h>
  41. #include <asm/page.h>
  42. #include <asm/pgtable.h>
  43. #include <asm/irq.h>
  44. #include <asm/hardware.h>
  45. #include <asm/parisc-device.h>
  46. #include <asm/delay.h>
  47. #include <scsi/scsi_host.h>
  48. #include <scsi/scsi_device.h>
  49. #include <scsi/scsi_transport.h>
  50. #include <scsi/scsi_transport_spi.h>
  51. #include "53c700.h"
  52. MODULE_AUTHOR("James Bottomley");
  53. MODULE_DESCRIPTION("lasi700 SCSI Driver");
  54. MODULE_LICENSE("GPL");
  55. #define LASI_700_SVERSION 0x00071
  56. #define LASI_710_SVERSION 0x00082
  57. #define LASI700_ID_TABLE { \
  58. .hw_type = HPHW_FIO, \
  59. .sversion = LASI_700_SVERSION, \
  60. .hversion = HVERSION_ANY_ID, \
  61. .hversion_rev = HVERSION_REV_ANY_ID, \
  62. }
  63. #define LASI710_ID_TABLE { \
  64. .hw_type = HPHW_FIO, \
  65. .sversion = LASI_710_SVERSION, \
  66. .hversion = HVERSION_ANY_ID, \
  67. .hversion_rev = HVERSION_REV_ANY_ID, \
  68. }
  69. #define LASI700_CLOCK 25
  70. #define LASI710_CLOCK 40
  71. #define LASI_SCSI_CORE_OFFSET 0x100
  72. static struct parisc_device_id lasi700_ids[] = {
  73. LASI700_ID_TABLE,
  74. LASI710_ID_TABLE,
  75. { 0 }
  76. };
  77. static struct scsi_host_template lasi700_template = {
  78. .name = "LASI SCSI 53c700",
  79. .proc_name = "lasi700",
  80. .this_id = 7,
  81. .module = THIS_MODULE,
  82. };
  83. MODULE_DEVICE_TABLE(parisc, lasi700_ids);
  84. static int __init
  85. lasi700_probe(struct parisc_device *dev)
  86. {
  87. unsigned long base = dev->hpa.start + LASI_SCSI_CORE_OFFSET;
  88. struct NCR_700_Host_Parameters *hostdata;
  89. struct Scsi_Host *host;
  90. hostdata = kzalloc(sizeof(*hostdata), GFP_KERNEL);
  91. if (!hostdata) {
  92. dev_printk(KERN_ERR, &dev->dev, "Failed to allocate host data\n");
  93. return -ENOMEM;
  94. }
  95. hostdata->dev = &dev->dev;
  96. dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
  97. hostdata->base = ioremap_nocache(base, 0x100);
  98. hostdata->differential = 0;
  99. if (dev->id.sversion == LASI_700_SVERSION) {
  100. hostdata->clock = LASI700_CLOCK;
  101. hostdata->force_le_on_be = 1;
  102. } else {
  103. hostdata->clock = LASI710_CLOCK;
  104. hostdata->force_le_on_be = 0;
  105. hostdata->chip710 = 1;
  106. hostdata->dmode_extra = DMODE_FC2;
  107. hostdata->burst_length = 8;
  108. }
  109. host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev);
  110. if (!host)
  111. goto out_kfree;
  112. host->this_id = 7;
  113. host->base = base;
  114. host->irq = dev->irq;
  115. if(request_irq(dev->irq, NCR_700_intr, IRQF_SHARED, "lasi700", host)) {
  116. printk(KERN_ERR "lasi700: request_irq failed!\n");
  117. goto out_put_host;
  118. }
  119. dev_set_drvdata(&dev->dev, host);
  120. scsi_scan_host(host);
  121. return 0;
  122. out_put_host:
  123. scsi_host_put(host);
  124. out_kfree:
  125. iounmap(hostdata->base);
  126. kfree(hostdata);
  127. return -ENODEV;
  128. }
  129. static int __exit
  130. lasi700_driver_remove(struct parisc_device *dev)
  131. {
  132. struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
  133. struct NCR_700_Host_Parameters *hostdata =
  134. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  135. scsi_remove_host(host);
  136. NCR_700_release(host);
  137. free_irq(host->irq, host);
  138. iounmap(hostdata->base);
  139. kfree(hostdata);
  140. return 0;
  141. }
  142. static struct parisc_driver lasi700_driver = {
  143. .name = "lasi_scsi",
  144. .id_table = lasi700_ids,
  145. .probe = lasi700_probe,
  146. .remove = lasi700_driver_remove,
  147. };
  148. static int __init
  149. lasi700_init(void)
  150. {
  151. return register_parisc_driver(&lasi700_driver);
  152. }
  153. static void __exit
  154. lasi700_exit(void)
  155. {
  156. unregister_parisc_driver(&lasi700_driver);
  157. }
  158. module_init(lasi700_init);
  159. module_exit(lasi700_exit);