fdomain_stub.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*======================================================================
  2. A driver for Future Domain-compatible PCMCIA SCSI cards
  3. fdomain_cs.c 1.47 2001/10/13 00:08:52
  4. The contents of this file are subject to the Mozilla Public
  5. License Version 1.1 (the "License"); you may not use this file
  6. except in compliance with the License. You may obtain a copy of
  7. the License at http://www.mozilla.org/MPL/
  8. Software distributed under the License is distributed on an "AS
  9. IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  10. implied. See the License for the specific language governing
  11. rights and limitations under the License.
  12. The initial developer of the original code is David A. Hinds
  13. <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
  14. are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
  15. Alternatively, the contents of this file may be used under the
  16. terms of the GNU General Public License version 2 (the "GPL"), in
  17. which case the provisions of the GPL are applicable instead of the
  18. above. If you wish to allow the use of your version of this file
  19. only under the terms of the GPL and not to allow others to use
  20. your version of this file under the MPL, indicate your decision
  21. by deleting the provisions above and replace them with the notice
  22. and other provisions required by the GPL. If you do not delete
  23. the provisions above, a recipient may use your version of this
  24. file under either the MPL or the GPL.
  25. ======================================================================*/
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/kernel.h>
  29. #include <linux/sched.h>
  30. #include <linux/slab.h>
  31. #include <linux/string.h>
  32. #include <linux/ioport.h>
  33. #include <scsi/scsi.h>
  34. #include <linux/major.h>
  35. #include <linux/blkdev.h>
  36. #include <scsi/scsi_ioctl.h>
  37. #include "scsi.h"
  38. #include <scsi/scsi_host.h>
  39. #include "fdomain.h"
  40. #include <pcmcia/cs_types.h>
  41. #include <pcmcia/cs.h>
  42. #include <pcmcia/cistpl.h>
  43. #include <pcmcia/ds.h>
  44. /*====================================================================*/
  45. /* Module parameters */
  46. MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
  47. MODULE_DESCRIPTION("Future Domain PCMCIA SCSI driver");
  48. MODULE_LICENSE("Dual MPL/GPL");
  49. #ifdef PCMCIA_DEBUG
  50. static int pc_debug = PCMCIA_DEBUG;
  51. module_param(pc_debug, int, 0);
  52. #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
  53. static char *version =
  54. "fdomain_cs.c 1.47 2001/10/13 00:08:52 (David Hinds)";
  55. #else
  56. #define DEBUG(n, args...)
  57. #endif
  58. /*====================================================================*/
  59. typedef struct scsi_info_t {
  60. struct pcmcia_device *p_dev;
  61. dev_node_t node;
  62. struct Scsi_Host *host;
  63. } scsi_info_t;
  64. static void fdomain_release(struct pcmcia_device *link);
  65. static void fdomain_detach(struct pcmcia_device *p_dev);
  66. static int fdomain_config(struct pcmcia_device *link);
  67. static int fdomain_probe(struct pcmcia_device *link)
  68. {
  69. scsi_info_t *info;
  70. DEBUG(0, "fdomain_attach()\n");
  71. /* Create new SCSI device */
  72. info = kzalloc(sizeof(*info), GFP_KERNEL);
  73. if (!info)
  74. return -ENOMEM;
  75. info->p_dev = link;
  76. link->priv = info;
  77. link->io.NumPorts1 = 0x10;
  78. link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
  79. link->io.IOAddrLines = 10;
  80. link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
  81. link->irq.IRQInfo1 = IRQ_LEVEL_ID;
  82. link->conf.Attributes = CONF_ENABLE_IRQ;
  83. link->conf.IntType = INT_MEMORY_AND_IO;
  84. link->conf.Present = PRESENT_OPTION;
  85. return fdomain_config(link);
  86. } /* fdomain_attach */
  87. /*====================================================================*/
  88. static void fdomain_detach(struct pcmcia_device *link)
  89. {
  90. DEBUG(0, "fdomain_detach(0x%p)\n", link);
  91. fdomain_release(link);
  92. kfree(link->priv);
  93. } /* fdomain_detach */
  94. /*====================================================================*/
  95. #define CS_CHECK(fn, ret) \
  96. do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
  97. static int fdomain_config(struct pcmcia_device *link)
  98. {
  99. scsi_info_t *info = link->priv;
  100. tuple_t tuple;
  101. cisparse_t parse;
  102. int i, last_ret, last_fn;
  103. u_char tuple_data[64];
  104. char str[16];
  105. struct Scsi_Host *host;
  106. DEBUG(0, "fdomain_config(0x%p)\n", link);
  107. tuple.DesiredTuple = CISTPL_CONFIG;
  108. tuple.TupleData = tuple_data;
  109. tuple.TupleDataMax = 64;
  110. tuple.TupleOffset = 0;
  111. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  112. CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
  113. CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
  114. link->conf.ConfigBase = parse.config.base;
  115. tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
  116. CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
  117. while (1) {
  118. if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
  119. pcmcia_parse_tuple(link, &tuple, &parse) != 0)
  120. goto next_entry;
  121. link->conf.ConfigIndex = parse.cftable_entry.index;
  122. link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
  123. i = pcmcia_request_io(link, &link->io);
  124. if (i == CS_SUCCESS) break;
  125. next_entry:
  126. CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
  127. }
  128. CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
  129. CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
  130. /* A bad hack... */
  131. release_region(link->io.BasePort1, link->io.NumPorts1);
  132. /* Set configuration options for the fdomain driver */
  133. sprintf(str, "%d,%d", link->io.BasePort1, link->irq.AssignedIRQ);
  134. fdomain_setup(str);
  135. host = __fdomain_16x0_detect(&fdomain_driver_template);
  136. if (!host) {
  137. printk(KERN_INFO "fdomain_cs: no SCSI devices found\n");
  138. goto cs_failed;
  139. }
  140. if (scsi_add_host(host, NULL))
  141. goto cs_failed;
  142. scsi_scan_host(host);
  143. sprintf(info->node.dev_name, "scsi%d", host->host_no);
  144. link->dev_node = &info->node;
  145. info->host = host;
  146. return 0;
  147. cs_failed:
  148. cs_error(link, last_fn, last_ret);
  149. fdomain_release(link);
  150. return -ENODEV;
  151. } /* fdomain_config */
  152. /*====================================================================*/
  153. static void fdomain_release(struct pcmcia_device *link)
  154. {
  155. scsi_info_t *info = link->priv;
  156. DEBUG(0, "fdomain_release(0x%p)\n", link);
  157. scsi_remove_host(info->host);
  158. pcmcia_disable_device(link);
  159. scsi_unregister(info->host);
  160. }
  161. /*====================================================================*/
  162. static int fdomain_resume(struct pcmcia_device *link)
  163. {
  164. fdomain_16x0_bus_reset(NULL);
  165. return 0;
  166. }
  167. static struct pcmcia_device_id fdomain_ids[] = {
  168. PCMCIA_DEVICE_PROD_ID12("IBM Corp.", "SCSI PCMCIA Card", 0xe3736c88, 0x859cad20),
  169. PCMCIA_DEVICE_PROD_ID1("SCSI PCMCIA Adapter Card", 0x8dacb57e),
  170. PCMCIA_DEVICE_PROD_ID12(" SIMPLE TECHNOLOGY Corporation", "SCSI PCMCIA Credit Card Controller", 0x182bdafe, 0xc80d106f),
  171. PCMCIA_DEVICE_NULL,
  172. };
  173. MODULE_DEVICE_TABLE(pcmcia, fdomain_ids);
  174. static struct pcmcia_driver fdomain_cs_driver = {
  175. .owner = THIS_MODULE,
  176. .drv = {
  177. .name = "fdomain_cs",
  178. },
  179. .probe = fdomain_probe,
  180. .remove = fdomain_detach,
  181. .id_table = fdomain_ids,
  182. .resume = fdomain_resume,
  183. };
  184. static int __init init_fdomain_cs(void)
  185. {
  186. return pcmcia_register_driver(&fdomain_cs_driver);
  187. }
  188. static void __exit exit_fdomain_cs(void)
  189. {
  190. pcmcia_unregister_driver(&fdomain_cs_driver);
  191. }
  192. module_init(init_fdomain_cs);
  193. module_exit(exit_fdomain_cs);