blob: 609e7051e01806a015660e029a8eb545e98bb85a [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
29#include <pcmcia/cs_types.h>
30#include <pcmcia/cs.h>
31#include <pcmcia/cistpl.h>
32#include <pcmcia/ciscode.h>
33#include <pcmcia/ds.h>
34#include <pcmcia/cisreg.h>
35
Michael Buesch1a094042007-09-20 11:13:40 -070036
Michael Buesche4d6b792007-09-18 15:39:42 -040037static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
38 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
Clyde McPhersoncff782c2009-06-30 22:39:28 -050039 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
Michael Buesche4d6b792007-09-18 15:39:42 -040040 PCMCIA_DEVICE_NULL,
41};
42
43MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
44
45#ifdef CONFIG_PM
46static int b43_pcmcia_suspend(struct pcmcia_device *dev)
47{
Michael Buesch8fe2b652008-03-30 00:10:50 +010048 struct ssb_bus *ssb = dev->priv;
49
50 return ssb_bus_suspend(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -040051}
52
53static int b43_pcmcia_resume(struct pcmcia_device *dev)
54{
Michael Buesch8fe2b652008-03-30 00:10:50 +010055 struct ssb_bus *ssb = dev->priv;
56
57 return ssb_bus_resume(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -040058}
59#else /* CONFIG_PM */
60# define b43_pcmcia_suspend NULL
61# define b43_pcmcia_resume NULL
62#endif /* CONFIG_PM */
63
64static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
65{
66 struct ssb_bus *ssb;
67 win_req_t win;
68 memreq_t mem;
Michael Buesche4d6b792007-09-18 15:39:42 -040069 int err = -ENOMEM;
Michael Bueschce2d9052007-11-06 16:36:41 +010070 int res = 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040071
72 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
73 if (!ssb)
Michael Bueschce2d9052007-11-06 16:36:41 +010074 goto out_error;
Michael Buesche4d6b792007-09-18 15:39:42 -040075
76 err = -ENODEV;
Michael Buesche4d6b792007-09-18 15:39:42 -040077
Michael Buesche6458902008-03-28 11:48:53 +010078 dev->conf.Attributes = CONF_ENABLE_IRQ;
79 dev->conf.IntType = INT_MEMORY_AND_IO;
Michael Buesche4d6b792007-09-18 15:39:42 -040080
81 dev->io.BasePort2 = 0;
82 dev->io.NumPorts2 = 0;
83 dev->io.Attributes2 = 0;
84
Michael Bueschce2d9052007-11-06 16:36:41 +010085 win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
86 WIN_ENABLE | WIN_DATA_WIDTH_16 |
87 WIN_USE_WAIT;
Michael Buesche4d6b792007-09-18 15:39:42 -040088 win.Base = 0;
89 win.Size = SSB_CORE_SIZE;
Michael Bueschce2d9052007-11-06 16:36:41 +010090 win.AccessSpeed = 250;
Dominik Brodowski6838b032009-11-03 01:31:52 +010091 res = pcmcia_request_window(dev, &win, &dev->win);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020092 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -040093 goto err_kfree_ssb;
94
95 mem.CardOffset = 0;
96 mem.Page = 0;
Magnus Damm868575d2006-12-13 19:46:43 +090097 res = pcmcia_map_mem_page(dev, dev->win, &mem);
Dominik Brodowski4c89e882008-08-03 10:07:45 +020098 if (res != 0)
Michael Bueschce2d9052007-11-06 16:36:41 +010099 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -0400100
Michael Buesche6458902008-03-28 11:48:53 +0100101 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
Michael Buesch9dcb5f42007-11-07 19:08:26 +0100102 dev->irq.Handler = NULL; /* The handler is registered later. */
Michael Buesch9dcb5f42007-11-07 19:08:26 +0100103 res = pcmcia_request_irq(dev, &dev->irq);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200104 if (res != 0)
Michael Buesch9dcb5f42007-11-07 19:08:26 +0100105 goto err_disable;
106
Michael Buesche4d6b792007-09-18 15:39:42 -0400107 res = pcmcia_request_configuration(dev, &dev->conf);
Dominik Brodowski4c89e882008-08-03 10:07:45 +0200108 if (res != 0)
Michael Buesche4d6b792007-09-18 15:39:42 -0400109 goto err_disable;
110
111 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
Michael Bueschce2d9052007-11-06 16:36:41 +0100112 if (err)
113 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -0400114 dev->priv = ssb;
115
Michael Bueschce2d9052007-11-06 16:36:41 +0100116 return 0;
117
118err_disable:
Michael Buesche4d6b792007-09-18 15:39:42 -0400119 pcmcia_disable_device(dev);
Michael Bueschce2d9052007-11-06 16:36:41 +0100120err_kfree_ssb:
Michael Buesche4d6b792007-09-18 15:39:42 -0400121 kfree(ssb);
Michael Bueschce2d9052007-11-06 16:36:41 +0100122out_error:
123 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
124 res, err);
Michael Buesche4d6b792007-09-18 15:39:42 -0400125 return err;
126}
127
128static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
129{
130 struct ssb_bus *ssb = dev->priv;
131
132 ssb_bus_unregister(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400133 pcmcia_disable_device(dev);
134 kfree(ssb);
135 dev->priv = NULL;
136}
137
138static struct pcmcia_driver b43_pcmcia_driver = {
Michael Bueschce2d9052007-11-06 16:36:41 +0100139 .owner = THIS_MODULE,
140 .drv = {
141 .name = "b43-pcmcia",
142 },
143 .id_table = b43_pcmcia_tbl,
144 .probe = b43_pcmcia_probe,
145 .remove = __devexit_p(b43_pcmcia_remove),
146 .suspend = b43_pcmcia_suspend,
147 .resume = b43_pcmcia_resume,
Michael Buesche4d6b792007-09-18 15:39:42 -0400148};
149
150int b43_pcmcia_init(void)
151{
152 return pcmcia_register_driver(&b43_pcmcia_driver);
153}
154
155void b43_pcmcia_exit(void)
156{
157 pcmcia_unregister_driver(&b43_pcmcia_driver);
158}