pcmcia.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. Broadcom B43 wireless driver
  3. Copyright (c) 2007 Michael Buesch <m@bues.ch>
  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 <linux/module.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_MANF_CARD(0x2D0, 0x476),
  28. PCMCIA_DEVICE_NULL,
  29. };
  30. MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
  31. #ifdef CONFIG_PM
  32. static int b43_pcmcia_suspend(struct pcmcia_device *dev)
  33. {
  34. struct ssb_bus *ssb = dev->priv;
  35. return ssb_bus_suspend(ssb);
  36. }
  37. static int b43_pcmcia_resume(struct pcmcia_device *dev)
  38. {
  39. struct ssb_bus *ssb = dev->priv;
  40. return ssb_bus_resume(ssb);
  41. }
  42. #else /* CONFIG_PM */
  43. # define b43_pcmcia_suspend NULL
  44. # define b43_pcmcia_resume NULL
  45. #endif /* CONFIG_PM */
  46. static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
  47. {
  48. struct ssb_bus *ssb;
  49. int err = -ENOMEM;
  50. int res = 0;
  51. ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
  52. if (!ssb)
  53. goto out_error;
  54. err = -ENODEV;
  55. dev->config_flags |= CONF_ENABLE_IRQ;
  56. dev->resource[2]->flags |= WIN_ENABLE | WIN_DATA_WIDTH_16 |
  57. WIN_USE_WAIT;
  58. dev->resource[2]->start = 0;
  59. dev->resource[2]->end = SSB_CORE_SIZE;
  60. res = pcmcia_request_window(dev, dev->resource[2], 250);
  61. if (res != 0)
  62. goto err_kfree_ssb;
  63. res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
  64. if (res != 0)
  65. goto err_disable;
  66. if (!dev->irq)
  67. goto err_disable;
  68. res = pcmcia_enable_device(dev);
  69. if (res != 0)
  70. goto err_disable;
  71. err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
  72. if (err)
  73. goto err_disable;
  74. dev->priv = ssb;
  75. return 0;
  76. err_disable:
  77. pcmcia_disable_device(dev);
  78. err_kfree_ssb:
  79. kfree(ssb);
  80. out_error:
  81. printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
  82. res, err);
  83. return err;
  84. }
  85. static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
  86. {
  87. struct ssb_bus *ssb = dev->priv;
  88. ssb_bus_unregister(ssb);
  89. pcmcia_disable_device(dev);
  90. kfree(ssb);
  91. dev->priv = NULL;
  92. }
  93. static struct pcmcia_driver b43_pcmcia_driver = {
  94. .owner = THIS_MODULE,
  95. .name = "b43-pcmcia",
  96. .id_table = b43_pcmcia_tbl,
  97. .probe = b43_pcmcia_probe,
  98. .remove = __devexit_p(b43_pcmcia_remove),
  99. .suspend = b43_pcmcia_suspend,
  100. .resume = b43_pcmcia_resume,
  101. };
  102. int b43_pcmcia_init(void)
  103. {
  104. return pcmcia_register_driver(&b43_pcmcia_driver);
  105. }
  106. void b43_pcmcia_exit(void)
  107. {
  108. pcmcia_unregister_driver(&b43_pcmcia_driver);
  109. }