pcmcia.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. Broadcom B43 wireless driver
  3. Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; see the file COPYING. If not, write to
  14. the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  15. Boston, MA 02110-1301, USA.
  16. */
  17. #include "pcmcia.h"
  18. #include <linux/ssb/ssb.h>
  19. #include <pcmcia/cs_types.h>
  20. #include <pcmcia/cs.h>
  21. #include <pcmcia/cistpl.h>
  22. #include <pcmcia/ciscode.h>
  23. #include <pcmcia/ds.h>
  24. #include <pcmcia/cisreg.h>
  25. static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
  26. PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
  27. PCMCIA_DEVICE_NULL,
  28. };
  29. MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
  30. #ifdef CONFIG_PM
  31. static int b43_pcmcia_suspend(struct pcmcia_device *dev)
  32. {
  33. struct ssb_bus *ssb = dev->priv;
  34. return ssb_bus_suspend(ssb);
  35. }
  36. static int b43_pcmcia_resume(struct pcmcia_device *dev)
  37. {
  38. struct ssb_bus *ssb = dev->priv;
  39. return ssb_bus_resume(ssb);
  40. }
  41. #else /* CONFIG_PM */
  42. # define b43_pcmcia_suspend NULL
  43. # define b43_pcmcia_resume NULL
  44. #endif /* CONFIG_PM */
  45. static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
  46. {
  47. struct ssb_bus *ssb;
  48. win_req_t win;
  49. memreq_t mem;
  50. tuple_t tuple;
  51. cisparse_t parse;
  52. int err = -ENOMEM;
  53. int res = 0;
  54. unsigned char buf[64];
  55. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  56. if (!ssb)
  57. goto out_error;
  58. err = -ENODEV;
  59. tuple.DesiredTuple = CISTPL_CONFIG;
  60. tuple.Attributes = 0;
  61. tuple.TupleData = buf;
  62. tuple.TupleDataMax = sizeof(buf);
  63. tuple.TupleOffset = 0;
  64. res = pcmcia_get_first_tuple(dev, &tuple);
  65. if (res != 0)
  66. goto err_kfree_ssb;
  67. res = pcmcia_get_tuple_data(dev, &tuple);
  68. if (res != 0)
  69. goto err_kfree_ssb;
  70. res = pcmcia_parse_tuple(&tuple, &parse);
  71. if (res != 0)
  72. goto err_kfree_ssb;
  73. dev->conf.ConfigBase = parse.config.base;
  74. dev->conf.Present = parse.config.rmask[0];
  75. dev->conf.Attributes = CONF_ENABLE_IRQ;
  76. dev->conf.IntType = INT_MEMORY_AND_IO;
  77. dev->io.BasePort2 = 0;
  78. dev->io.NumPorts2 = 0;
  79. dev->io.Attributes2 = 0;
  80. win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
  81. WIN_ENABLE | WIN_DATA_WIDTH_16 |
  82. WIN_USE_WAIT;
  83. win.Base = 0;
  84. win.Size = SSB_CORE_SIZE;
  85. win.AccessSpeed = 250;
  86. res = pcmcia_request_window(&dev, &win, &dev->win);
  87. if (res != 0)
  88. goto err_kfree_ssb;
  89. mem.CardOffset = 0;
  90. mem.Page = 0;
  91. res = pcmcia_map_mem_page(dev->win, &mem);
  92. if (res != 0)
  93. goto err_disable;
  94. dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
  95. dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
  96. dev->irq.Handler = NULL; /* The handler is registered later. */
  97. dev->irq.Instance = NULL;
  98. res = pcmcia_request_irq(dev, &dev->irq);
  99. if (res != 0)
  100. goto err_disable;
  101. res = pcmcia_request_configuration(dev, &dev->conf);
  102. if (res != 0)
  103. goto err_disable;
  104. err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
  105. if (err)
  106. goto err_disable;
  107. dev->priv = ssb;
  108. return 0;
  109. err_disable:
  110. pcmcia_disable_device(dev);
  111. err_kfree_ssb:
  112. kfree(ssb);
  113. out_error:
  114. printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
  115. res, err);
  116. return err;
  117. }
  118. static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
  119. {
  120. struct ssb_bus *ssb = dev->priv;
  121. ssb_bus_unregister(ssb);
  122. pcmcia_disable_device(dev);
  123. kfree(ssb);
  124. dev->priv = NULL;
  125. }
  126. static struct pcmcia_driver b43_pcmcia_driver = {
  127. .owner = THIS_MODULE,
  128. .drv = {
  129. .name = "b43-pcmcia",
  130. },
  131. .id_table = b43_pcmcia_tbl,
  132. .probe = b43_pcmcia_probe,
  133. .remove = __devexit_p(b43_pcmcia_remove),
  134. .suspend = b43_pcmcia_suspend,
  135. .resume = b43_pcmcia_resume,
  136. };
  137. int b43_pcmcia_init(void)
  138. {
  139. return pcmcia_register_driver(&b43_pcmcia_driver);
  140. }
  141. void b43_pcmcia_exit(void)
  142. {
  143. pcmcia_unregister_driver(&b43_pcmcia_driver);
  144. }