blob: 2c8461dcf1b0b8f39df2c179a38f4200f4d4b46d [file] [log] [blame]
Michael Buesche4d6b792007-09-18 15:39:42 -04001/*
2
3 Broadcom B43 wireless driver
4
5 Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
6
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>
Michael Buesche4d6b792007-09-18 15:39:42 -040028
Michael Buesche4d6b792007-09-18 15:39:42 -040029#include <pcmcia/cistpl.h>
30#include <pcmcia/ciscode.h>
31#include <pcmcia/ds.h>
32#include <pcmcia/cisreg.h>
33
Michael Buesch1a094042007-09-20 11:13:40 -070034
Joe Perches25f8f542011-05-03 19:29:01 -070035static const struct pcmcia_device_id b43_pcmcia_tbl[] = {
Michael Buesche4d6b792007-09-18 15:39:42 -040036 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
Clyde McPhersoncff782c2009-06-30 22:39:28 -050037 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
Michael Buesche4d6b792007-09-18 15:39:42 -040038 PCMCIA_DEVICE_NULL,
39};
40
41MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
42
43#ifdef CONFIG_PM
44static int b43_pcmcia_suspend(struct pcmcia_device *dev)
45{
Michael Buesch8fe2b652008-03-30 00:10:50 +010046 struct ssb_bus *ssb = dev->priv;
47
48 return ssb_bus_suspend(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -040049}
50
51static int b43_pcmcia_resume(struct pcmcia_device *dev)
52{
Michael Buesch8fe2b652008-03-30 00:10:50 +010053 struct ssb_bus *ssb = dev->priv;
54
55 return ssb_bus_resume(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -040056}
57#else /* CONFIG_PM */
58# define b43_pcmcia_suspend NULL
59# define b43_pcmcia_resume NULL
60#endif /* CONFIG_PM */
61
62static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
63{
64 struct ssb_bus *ssb;
Michael Buesche4d6b792007-09-18 15:39:42 -040065 int err = -ENOMEM;
Michael Bueschce2d9052007-11-06 16:36:41 +010066 int res = 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040067
68 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
69 if (!ssb)
Michael Bueschce2d9052007-11-06 16:36:41 +010070 goto out_error;
Michael Buesche4d6b792007-09-18 15:39:42 -040071
72 err = -ENODEV;
Michael Buesche4d6b792007-09-18 15:39:42 -040073
Dominik Brodowski1ac71e52010-07-29 19:27:09 +020074 dev->config_flags |= CONF_ENABLE_IRQ;
Michael Buesche4d6b792007-09-18 15:39:42 -040075
Dominik Brodowskicdb13802010-07-28 10:59:06 +020076 dev->resource[2]->flags |= WIN_ENABLE | WIN_DATA_WIDTH_16 |
Michael Bueschce2d9052007-11-06 16:36:41 +010077 WIN_USE_WAIT;
Dominik Brodowskicdb13802010-07-28 10:59:06 +020078 dev->resource[2]->start = 0;
79 dev->resource[2]->end = SSB_CORE_SIZE;
80 res = pcmcia_request_window(dev, dev->resource[2], 250);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020081 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -040082 goto err_kfree_ssb;
83
Dominik Brodowskicdb13802010-07-28 10:59:06 +020084 res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020085 if (res != 0)
Michael Bueschce2d9052007-11-06 16:36:41 +010086 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -040087
Dominik Brodowskieb141202010-03-07 12:21:16 +010088 if (!dev->irq)
Michael Buesch9dcb5f42007-11-07 19:08:26 +010089 goto err_disable;
90
Dominik Brodowski1ac71e52010-07-29 19:27:09 +020091 res = pcmcia_enable_device(dev);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020092 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -040093 goto err_disable;
94
Dominik Brodowskicdb13802010-07-28 10:59:06 +020095 err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
Michael Bueschce2d9052007-11-06 16:36:41 +010096 if (err)
97 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -040098 dev->priv = ssb;
99
Michael Bueschce2d9052007-11-06 16:36:41 +0100100 return 0;
101
102err_disable:
Michael Buesche4d6b792007-09-18 15:39:42 -0400103 pcmcia_disable_device(dev);
Michael Bueschce2d9052007-11-06 16:36:41 +0100104err_kfree_ssb:
Michael Buesche4d6b792007-09-18 15:39:42 -0400105 kfree(ssb);
Michael Bueschce2d9052007-11-06 16:36:41 +0100106out_error:
107 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
108 res, err);
Michael Buesche4d6b792007-09-18 15:39:42 -0400109 return err;
110}
111
112static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
113{
114 struct ssb_bus *ssb = dev->priv;
115
116 ssb_bus_unregister(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400117 pcmcia_disable_device(dev);
118 kfree(ssb);
119 dev->priv = NULL;
120}
121
122static struct pcmcia_driver b43_pcmcia_driver = {
Michael Bueschce2d9052007-11-06 16:36:41 +0100123 .owner = THIS_MODULE,
Dominik Brodowski2e9b9812010-08-08 11:36:26 +0200124 .name = "b43-pcmcia",
Michael Bueschce2d9052007-11-06 16:36:41 +0100125 .id_table = b43_pcmcia_tbl,
126 .probe = b43_pcmcia_probe,
127 .remove = __devexit_p(b43_pcmcia_remove),
128 .suspend = b43_pcmcia_suspend,
129 .resume = b43_pcmcia_resume,
Michael Buesche4d6b792007-09-18 15:39:42 -0400130};
131
132int b43_pcmcia_init(void)
133{
134 return pcmcia_register_driver(&b43_pcmcia_driver);
135}
136
137void b43_pcmcia_exit(void)
138{
139 pcmcia_unregister_driver(&b43_pcmcia_driver);
140}