sim710.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * sim710.c - Copyright (C) 1999 Richard Hirst <richard@sleepie.demon.co.uk>
  3. *
  4. *----------------------------------------------------------------------------
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. *----------------------------------------------------------------------------
  19. *
  20. * MCA card detection code by Trent McNair. (now deleted)
  21. * Fixes to not explicitly nul bss data from Xavier Bestel.
  22. * Some multiboard fixes from Rolf Eike Beer.
  23. * Auto probing of EISA config space from Trevor Hemsley.
  24. *
  25. * Rewritten to use 53c700.c by James.Bottomley@SteelEye.com
  26. *
  27. */
  28. #include <linux/module.h>
  29. #include <linux/slab.h>
  30. #include <linux/blkdev.h>
  31. #include <linux/device.h>
  32. #include <linux/init.h>
  33. #include <linux/eisa.h>
  34. #include <linux/interrupt.h>
  35. #include <scsi/scsi_host.h>
  36. #include <scsi/scsi_device.h>
  37. #include <scsi/scsi_transport.h>
  38. #include <scsi/scsi_transport_spi.h>
  39. #include "53c700.h"
  40. /* Must be enough for EISA */
  41. #define MAX_SLOTS 8
  42. static __u8 __initdata id_array[MAX_SLOTS] = { [0 ... MAX_SLOTS-1] = 7 };
  43. static char *sim710; /* command line passed by insmod */
  44. MODULE_AUTHOR("Richard Hirst");
  45. MODULE_DESCRIPTION("Simple NCR53C710 driver");
  46. MODULE_LICENSE("GPL");
  47. module_param(sim710, charp, 0);
  48. #ifdef MODULE
  49. #define ARG_SEP ' '
  50. #else
  51. #define ARG_SEP ','
  52. #endif
  53. static __init int
  54. param_setup(char *str)
  55. {
  56. char *pos = str, *next;
  57. int slot = -1;
  58. while(pos != NULL && (next = strchr(pos, ':')) != NULL) {
  59. int val = (int)simple_strtoul(++next, NULL, 0);
  60. if(!strncmp(pos, "slot:", 5))
  61. slot = val;
  62. else if(!strncmp(pos, "id:", 3)) {
  63. if(slot == -1) {
  64. printk(KERN_WARNING "sim710: Must specify slot for id parameter\n");
  65. } else if(slot >= MAX_SLOTS) {
  66. printk(KERN_WARNING "sim710: Illegal slot %d for id %d\n", slot, val);
  67. } else {
  68. id_array[slot] = val;
  69. }
  70. }
  71. if((pos = strchr(pos, ARG_SEP)) != NULL)
  72. pos++;
  73. }
  74. return 1;
  75. }
  76. __setup("sim710=", param_setup);
  77. static struct scsi_host_template sim710_driver_template = {
  78. .name = "LSI (Symbios) 710 EISA",
  79. .proc_name = "sim710",
  80. .this_id = 7,
  81. .module = THIS_MODULE,
  82. };
  83. static int sim710_probe_common(struct device *dev, unsigned long base_addr,
  84. int irq, int clock, int differential,
  85. int scsi_id)
  86. {
  87. struct Scsi_Host * host = NULL;
  88. struct NCR_700_Host_Parameters *hostdata =
  89. kzalloc(sizeof(struct NCR_700_Host_Parameters), GFP_KERNEL);
  90. printk(KERN_NOTICE "sim710: %s\n", dev_name(dev));
  91. printk(KERN_NOTICE "sim710: irq = %d, clock = %d, base = 0x%lx, scsi_id = %d\n",
  92. irq, clock, base_addr, scsi_id);
  93. if(hostdata == NULL) {
  94. printk(KERN_ERR "sim710: Failed to allocate host data\n");
  95. goto out;
  96. }
  97. if(request_region(base_addr, 64, "sim710") == NULL) {
  98. printk(KERN_ERR "sim710: Failed to reserve IO region 0x%lx\n",
  99. base_addr);
  100. goto out_free;
  101. }
  102. /* Fill in the three required pieces of hostdata */
  103. hostdata->base = ioport_map(base_addr, 64);
  104. hostdata->differential = differential;
  105. hostdata->clock = clock;
  106. hostdata->chip710 = 1;
  107. hostdata->burst_length = 8;
  108. /* and register the chip */
  109. if((host = NCR_700_detect(&sim710_driver_template, hostdata, dev))
  110. == NULL) {
  111. printk(KERN_ERR "sim710: No host detected; card configuration problem?\n");
  112. goto out_release;
  113. }
  114. host->this_id = scsi_id;
  115. host->base = base_addr;
  116. host->irq = irq;
  117. if (request_irq(irq, NCR_700_intr, IRQF_SHARED, "sim710", host)) {
  118. printk(KERN_ERR "sim710: request_irq failed\n");
  119. goto out_put_host;
  120. }
  121. dev_set_drvdata(dev, host);
  122. scsi_scan_host(host);
  123. return 0;
  124. out_put_host:
  125. scsi_host_put(host);
  126. out_release:
  127. release_region(base_addr, 64);
  128. out_free:
  129. kfree(hostdata);
  130. out:
  131. return -ENODEV;
  132. }
  133. static int sim710_device_remove(struct device *dev)
  134. {
  135. struct Scsi_Host *host = dev_get_drvdata(dev);
  136. struct NCR_700_Host_Parameters *hostdata =
  137. (struct NCR_700_Host_Parameters *)host->hostdata[0];
  138. scsi_remove_host(host);
  139. NCR_700_release(host);
  140. kfree(hostdata);
  141. free_irq(host->irq, host);
  142. release_region(host->base, 64);
  143. return 0;
  144. }
  145. #ifdef CONFIG_EISA
  146. static struct eisa_device_id sim710_eisa_ids[] = {
  147. { "CPQ4410" },
  148. { "CPQ4411" },
  149. { "HWP0C80" },
  150. { "" }
  151. };
  152. MODULE_DEVICE_TABLE(eisa, sim710_eisa_ids);
  153. static int sim710_eisa_probe(struct device *dev)
  154. {
  155. struct eisa_device *edev = to_eisa_device(dev);
  156. unsigned long io_addr = edev->base_addr;
  157. char eisa_cpq_irqs[] = { 11, 14, 15, 10, 9, 0 };
  158. char eisa_hwp_irqs[] = { 3, 4, 5, 7, 12, 10, 11, 0};
  159. char *eisa_irqs;
  160. unsigned char irq_index;
  161. unsigned char irq, differential = 0, scsi_id = 7;
  162. if(strcmp(edev->id.sig, "HWP0C80") == 0) {
  163. __u8 val;
  164. eisa_irqs = eisa_hwp_irqs;
  165. irq_index = (inb(io_addr + 0xc85) & 0x7) - 1;
  166. val = inb(io_addr + 0x4);
  167. scsi_id = ffs(val) - 1;
  168. if(scsi_id > 7 || (val & ~(1<<scsi_id)) != 0) {
  169. printk(KERN_ERR "sim710.c, EISA card %s has incorrect scsi_id, setting to 7\n", dev_name(dev));
  170. scsi_id = 7;
  171. }
  172. } else {
  173. eisa_irqs = eisa_cpq_irqs;
  174. irq_index = inb(io_addr + 0xc88) & 0x07;
  175. }
  176. if(irq_index >= strlen(eisa_irqs)) {
  177. printk("sim710.c: irq nasty\n");
  178. return -ENODEV;
  179. }
  180. irq = eisa_irqs[irq_index];
  181. return sim710_probe_common(dev, io_addr, irq, 50,
  182. differential, scsi_id);
  183. }
  184. static struct eisa_driver sim710_eisa_driver = {
  185. .id_table = sim710_eisa_ids,
  186. .driver = {
  187. .name = "sim710",
  188. .probe = sim710_eisa_probe,
  189. .remove = sim710_device_remove,
  190. },
  191. };
  192. #endif /* CONFIG_EISA */
  193. static int __init sim710_init(void)
  194. {
  195. int err = -ENODEV;
  196. #ifdef MODULE
  197. if (sim710)
  198. param_setup(sim710);
  199. #endif
  200. #ifdef CONFIG_EISA
  201. err = eisa_driver_register(&sim710_eisa_driver);
  202. #endif
  203. /* FIXME: what we'd really like to return here is -ENODEV if
  204. * no devices have actually been found. Instead, the err
  205. * above actually only reports problems with kobject_register,
  206. * so for the moment return success */
  207. return 0;
  208. }
  209. static void __exit sim710_exit(void)
  210. {
  211. #ifdef CONFIG_EISA
  212. eisa_driver_unregister(&sim710_eisa_driver);
  213. #endif
  214. }
  215. module_init(sim710_init);
  216. module_exit(sim710_exit);