pcmcia.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 <linux/slab.h>
  20. #include <pcmcia/cs_types.h>
  21. #include <pcmcia/cs.h>
  22. #include <pcmcia/cistpl.h>
  23. #include <pcmcia/ciscode.h>
  24. #include <pcmcia/ds.h>
  25. #include <pcmcia/cisreg.h>
  26. static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
  27. PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
  28. PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
  29. PCMCIA_DEVICE_NULL,
  30. };
  31. MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
  32. #ifdef CONFIG_PM
  33. static int b43_pcmcia_suspend(struct pcmcia_device *dev)
  34. {
  35. struct ssb_bus *ssb = dev->priv;
  36. return ssb_bus_suspend(ssb);
  37. }
  38. static int b43_pcmcia_resume(struct pcmcia_device *dev)
  39. {
  40. struct ssb_bus *ssb = dev->priv;
  41. return ssb_bus_resume(ssb);
  42. }
  43. #else /* CONFIG_PM */
  44. # define b43_pcmcia_suspend NULL
  45. # define b43_pcmcia_resume NULL
  46. #endif /* CONFIG_PM */
  47. static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
  48. {
  49. struct ssb_bus *ssb;
  50. win_req_t win;
  51. memreq_t mem;
  52. int err = -ENOMEM;
  53. int res = 0;
  54. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  55. if (!ssb)
  56. goto out_error;
  57. err = -ENODEV;
  58. dev->conf.Attributes = CONF_ENABLE_IRQ;
  59. dev->conf.IntType = INT_MEMORY_AND_IO;
  60. dev->io.BasePort2 = 0;
  61. dev->io.NumPorts2 = 0;
  62. dev->io.Attributes2 = 0;
  63. win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
  64. WIN_ENABLE | WIN_DATA_WIDTH_16 |
  65. WIN_USE_WAIT;
  66. win.Base = 0;
  67. win.Size = SSB_CORE_SIZE;
  68. win.AccessSpeed = 250;
  69. res = pcmcia_request_window(dev, &win, &dev->win);
  70. if (res != 0)
  71. goto err_kfree_ssb;
  72. mem.CardOffset = 0;
  73. mem.Page = 0;
  74. res = pcmcia_map_mem_page(dev, dev->win, &mem);
  75. if (res != 0)
  76. goto err_disable;
  77. if (!dev->irq)
  78. goto err_disable;
  79. res = pcmcia_request_configuration(dev, &dev->conf);
  80. if (res != 0)
  81. goto err_disable;
  82. err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
  83. if (err)
  84. goto err_disable;
  85. dev->priv = ssb;
  86. return 0;
  87. err_disable:
  88. pcmcia_disable_device(dev);
  89. err_kfree_ssb:
  90. kfree(ssb);
  91. out_error:
  92. printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
  93. res, err);
  94. return err;
  95. }
  96. static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
  97. {
  98. struct ssb_bus *ssb = dev->priv;
  99. ssb_bus_unregister(ssb);
  100. pcmcia_disable_device(dev);
  101. kfree(ssb);
  102. dev->priv = NULL;
  103. }
  104. static struct pcmcia_driver b43_pcmcia_driver = {
  105. .owner = THIS_MODULE,
  106. .drv = {
  107. .name = "b43-pcmcia",
  108. },
  109. .id_table = b43_pcmcia_tbl,
  110. .probe = b43_pcmcia_probe,
  111. .remove = __devexit_p(b43_pcmcia_remove),
  112. .suspend = b43_pcmcia_suspend,
  113. .resume = b43_pcmcia_resume,
  114. };
  115. int b43_pcmcia_init(void)
  116. {
  117. return pcmcia_register_driver(&b43_pcmcia_driver);
  118. }
  119. void b43_pcmcia_exit(void)
  120. {
  121. pcmcia_unregister_driver(&b43_pcmcia_driver);
  122. }