blob: 714cad649c45b68281ae7c2c1e7f66e7c317c52c [file] [log] [blame]
Michael Buesche4d6b792007-09-18 15:39:42 -04001/*
2
3 Broadcom B43 wireless driver
4
Michael Büscheb032b92011-07-04 20:50:05 +02005 Copyright (c) 2007 Michael Buesch <m@bues.ch>
Michael Buesche4d6b792007-09-18 15:39:42 -04006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21
22*/
23
Michael Buesch1a094042007-09-20 11:13:40 -070024#include "pcmcia.h"
25
Michael Buesche4d6b792007-09-18 15:39:42 -040026#include <linux/ssb/ssb.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090027#include <linux/slab.h>
Paul Gortmaker9d9779e2011-07-03 15:21:01 -040028#include <linux/module.h>
Michael Buesche4d6b792007-09-18 15:39:42 -040029
Michael Buesche4d6b792007-09-18 15:39:42 -040030#include <pcmcia/cistpl.h>
31#include <pcmcia/ciscode.h>
32#include <pcmcia/ds.h>
33#include <pcmcia/cisreg.h>
34
Michael Buesch1a094042007-09-20 11:13:40 -070035
Joe Perches25f8f542011-05-03 19:29:01 -070036static const struct pcmcia_device_id b43_pcmcia_tbl[] = {
Michael Buesche4d6b792007-09-18 15:39:42 -040037 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
Clyde McPhersoncff782c2009-06-30 22:39:28 -050038 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
Michael Buesche4d6b792007-09-18 15:39:42 -040039 PCMCIA_DEVICE_NULL,
40};
41
42MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
43
44#ifdef CONFIG_PM
45static int b43_pcmcia_suspend(struct pcmcia_device *dev)
46{
Michael Buesch8fe2b652008-03-30 00:10:50 +010047 struct ssb_bus *ssb = dev->priv;
48
49 return ssb_bus_suspend(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -040050}
51
52static int b43_pcmcia_resume(struct pcmcia_device *dev)
53{
Michael Buesch8fe2b652008-03-30 00:10:50 +010054 struct ssb_bus *ssb = dev->priv;
55
56 return ssb_bus_resume(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -040057}
58#else /* CONFIG_PM */
59# define b43_pcmcia_suspend NULL
60# define b43_pcmcia_resume NULL
61#endif /* CONFIG_PM */
62
63static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
64{
65 struct ssb_bus *ssb;
Michael Buesche4d6b792007-09-18 15:39:42 -040066 int err = -ENOMEM;
Michael Bueschce2d90592007-11-06 16:36:41 +010067 int res = 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040068
69 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
70 if (!ssb)
Michael Bueschce2d90592007-11-06 16:36:41 +010071 goto out_error;
Michael Buesche4d6b792007-09-18 15:39:42 -040072
73 err = -ENODEV;
Michael Buesche4d6b792007-09-18 15:39:42 -040074
Dominik Brodowski1ac71e52010-07-29 19:27:09 +020075 dev->config_flags |= CONF_ENABLE_IRQ;
Michael Buesche4d6b792007-09-18 15:39:42 -040076
Dominik Brodowskicdb13802010-07-28 10:59:06 +020077 dev->resource[2]->flags |= WIN_ENABLE | WIN_DATA_WIDTH_16 |
Michael Bueschce2d90592007-11-06 16:36:41 +010078 WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +020079 dev->resource[2]->start = 0;
80 dev->resource[2]->end = SSB_CORE_SIZE;
81 res = pcmcia_request_window(dev, dev->resource[2], 250);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020082 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -040083 goto err_kfree_ssb;
84
Dominik Brodowskicdb13802010-07-28 10:59:06 +020085 res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020086 if (res != 0)
Michael Bueschce2d90592007-11-06 16:36:41 +010087 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -040088
Dominik Brodowskieb141202010-03-07 12:21:16 +010089 if (!dev->irq)
Michael Buesch9dcb5f42007-11-07 19:08:26 +010090 goto err_disable;
91
Dominik Brodowski1ac71e52010-07-29 19:27:09 +020092 res = pcmcia_enable_device(dev);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020093 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -040094 goto err_disable;
95
Dominik Brodowskicdb13802010-07-28 10:59:06 +020096 err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
Michael Bueschce2d90592007-11-06 16:36:41 +010097 if (err)
98 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -040099 dev->priv = ssb;
100
Michael Bueschce2d90592007-11-06 16:36:41 +0100101 return 0;
102
103err_disable:
Michael Buesche4d6b792007-09-18 15:39:42 -0400104 pcmcia_disable_device(dev);
Michael Bueschce2d90592007-11-06 16:36:41 +0100105err_kfree_ssb:
Michael Buesche4d6b792007-09-18 15:39:42 -0400106 kfree(ssb);
Michael Bueschce2d90592007-11-06 16:36:41 +0100107out_error:
108 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
109 res, err);
Michael Buesche4d6b792007-09-18 15:39:42 -0400110 return err;
111}
112
113static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
114{
115 struct ssb_bus *ssb = dev->priv;
116
117 ssb_bus_unregister(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400118 pcmcia_disable_device(dev);
119 kfree(ssb);
120 dev->priv = NULL;
121}
122
123static struct pcmcia_driver b43_pcmcia_driver = {
Michael Bueschce2d90592007-11-06 16:36:41 +0100124 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200125 .name = "b43-pcmcia",
Michael Bueschce2d90592007-11-06 16:36:41 +0100126 .id_table = b43_pcmcia_tbl,
127 .probe = b43_pcmcia_probe,
128 .remove = __devexit_p(b43_pcmcia_remove),
129 .suspend = b43_pcmcia_suspend,
130 .resume = b43_pcmcia_resume,
Michael Buesche4d6b792007-09-18 15:39:42 -0400131};
132
133int b43_pcmcia_init(void)
134{
135 return pcmcia_register_driver(&b43_pcmcia_driver);
136}
137
138void b43_pcmcia_exit(void)
139{
140 pcmcia_unregister_driver(&b43_pcmcia_driver);
141}