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/sched.h>
  39. #include <linux/ioport.h>
  40. #include <linux/dma-mapping.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 = kmalloc(sizeof(*hostdata), GFP_KERNEL);
  91. if (!hostdata) {
  92. printk(KERN_ERR "%s: Failed to allocate host data\n",
  93. dev->dev.bus_id);
  94. return -ENOMEM;
  95. }
  96. memset(hostdata, 0, sizeof(struct NCR_700_Host_Parameters));
  97. hostdata->dev = &dev->dev;
  98. dma_set_mask(&dev->dev, DMA_32BIT_MASK);
  99. hostdata->base = ioremap_nocache(base, 0x100);
  100. hostdata->differential = 0;
  101. if (dev->id.sversion == LASI_700_SVERSION) {
  102. hostdata->clock = LASI700_CLOCK;
  103. hostdata->force_le_on_be = 1;
  104. } else {
  105. hostdata->clock = LASI710_CLOCK;
  106. hostdata->force_le_on_be = 0;
  107. hostdata->chip710 = 1;
  108. hostdata->dmode_extra = DMODE_FC2;
  109. }
  110. host = NCR_700_detect(&lasi700_template, hostdata, &dev->dev);
  111. if (!host)
  112. goto out_kfree;
  113. host->this_id = 7;
  114. host->base = base;
  115. host->irq = dev->irq;
  116. if(request_irq(dev->irq, NCR_700_intr, SA_SHIRQ, "lasi700", host)) {
  117. printk(KERN_ERR "lasi700: request_irq failed!\n");
  118. goto out_put_host;
  119. }
  120. dev_set_drvdata(&dev->dev, host);
  121. scsi_scan_host(host);
  122. return 0;
  123. out_put_host:
  124. scsi_host_put(host);
  125. out_kfree:
  126. iounmap(hostdata->base);
  127. kfree(hostdata);
  128. return -ENODEV;
  129. }
  130. static int __exit
  131. lasi700_driver_remove(struct parisc_device *dev)
  132. {
  133. struct Scsi_Host *host = dev_get_drvdata(&dev->dev);
  134. struct NCR_700_Host_Parameters *hostdata =
  135. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  136. scsi_remove_host(host);
  137. NCR_700_release(host);
  138. free_irq(host->irq, host);
  139. iounmap(hostdata->base);
  140. kfree(hostdata);
  141. return 0;
  142. }
  143. static struct parisc_driver lasi700_driver = {
  144. .name = "lasi_scsi",
  145. .id_table = lasi700_ids,
  146. .probe = lasi700_probe,
  147. .remove = __devexit_p(lasi700_driver_remove),
  148. };
  149. static int __init
  150. lasi700_init(void)
  151. {
  152. return register_parisc_driver(&lasi700_driver);
  153. }
  154. static void __exit
  155. lasi700_exit(void)
  156. {
  157. unregister_parisc_driver(&lasi700_driver);
  158. }
  159. module_init(lasi700_init);
  160. module_exit(lasi700_exit);