blob: 7c9af82fcf7e77dd757b4f67301976a25314e2d3 [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/cs.h>
30#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
Michael Buesche4d6b792007-09-18 15:39:42 -040036static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
37 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;
66 win_req_t win;
67 memreq_t mem;
Michael Buesche4d6b792007-09-18 15:39:42 -040068 int err = -ENOMEM;
Michael Bueschce2d9052007-11-06 16:36:41 +010069 int res = 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040070
71 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
72 if (!ssb)
Michael Bueschce2d9052007-11-06 16:36:41 +010073 goto out_error;
Michael Buesche4d6b792007-09-18 15:39:42 -040074
75 err = -ENODEV;
Michael Buesche4d6b792007-09-18 15:39:42 -040076
Michael Buesche6458902008-03-28 11:48:53 +010077 dev->conf.Attributes = CONF_ENABLE_IRQ;
78 dev->conf.IntType = INT_MEMORY_AND_IO;
Michael Buesche4d6b792007-09-18 15:39:42 -040079
Michael Bueschce2d9052007-11-06 16:36:41 +010080 win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
81 WIN_ENABLE | WIN_DATA_WIDTH_16 |
82 WIN_USE_WAIT;
Michael Buesche4d6b792007-09-18 15:39:42 -040083 win.Base = 0;
84 win.Size = SSB_CORE_SIZE;
Michael Bueschce2d9052007-11-06 16:36:41 +010085 win.AccessSpeed = 250;
Dominik Brodowski6838b032009-11-03 01:31:52 +010086 res = pcmcia_request_window(dev, &win, &dev->win);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020087 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -040088 goto err_kfree_ssb;
89
90 mem.CardOffset = 0;
91 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +090092 res = pcmcia_map_mem_page(dev, dev->win, &mem);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020093 if (res != 0)
Michael Bueschce2d9052007-11-06 16:36:41 +010094 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -040095
Dominik Brodowskieb141202010-03-07 12:21:16 +010096 if (!dev->irq)
Michael Buesch9dcb5f42007-11-07 19:08:26 +010097 goto err_disable;
98
Michael Buesche4d6b792007-09-18 15:39:42 -040099 res = pcmcia_request_configuration(dev, &dev->conf);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200100 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -0400101 goto err_disable;
102
103 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
Michael Bueschce2d9052007-11-06 16:36:41 +0100104 if (err)
105 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -0400106 dev->priv = ssb;
107
Michael Bueschce2d9052007-11-06 16:36:41 +0100108 return 0;
109
110err_disable:
Michael Buesche4d6b792007-09-18 15:39:42 -0400111 pcmcia_disable_device(dev);
Michael Bueschce2d9052007-11-06 16:36:41 +0100112err_kfree_ssb:
Michael Buesche4d6b792007-09-18 15:39:42 -0400113 kfree(ssb);
Michael Bueschce2d9052007-11-06 16:36:41 +0100114out_error:
115 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
116 res, err);
Michael Buesche4d6b792007-09-18 15:39:42 -0400117 return err;
118}
119
120static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
121{
122 struct ssb_bus *ssb = dev->priv;
123
124 ssb_bus_unregister(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400125 pcmcia_disable_device(dev);
126 kfree(ssb);
127 dev->priv = NULL;
128}
129
130static struct pcmcia_driver b43_pcmcia_driver = {
Michael Bueschce2d9052007-11-06 16:36:41 +0100131 .owner = THIS_MODULE,
132 .drv = {
133 .name = "b43-pcmcia",
134 },
135 .id_table = b43_pcmcia_tbl,
136 .probe = b43_pcmcia_probe,
137 .remove = __devexit_p(b43_pcmcia_remove),
138 .suspend = b43_pcmcia_suspend,
139 .resume = b43_pcmcia_resume,
Michael Buesche4d6b792007-09-18 15:39:42 -0400140};
141
142int b43_pcmcia_init(void)
143{
144 return pcmcia_register_driver(&b43_pcmcia_driver);
145}
146
147void b43_pcmcia_exit(void)
148{
149 pcmcia_unregister_driver(&b43_pcmcia_driver);
150}