blob: 4b6648f0efcd6f7a4b90b8bb41b863d8ef6989f4 [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>
27
28#include <pcmcia/cs_types.h>
29#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),
38 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{
46 //TODO
47 return 0;
48}
49
50static int b43_pcmcia_resume(struct pcmcia_device *dev)
51{
52 //TODO
53 return 0;
54}
55#else /* CONFIG_PM */
56# define b43_pcmcia_suspend NULL
57# define b43_pcmcia_resume NULL
58#endif /* CONFIG_PM */
59
60static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
61{
62 struct ssb_bus *ssb;
63 win_req_t win;
64 memreq_t mem;
65 tuple_t tuple;
66 cisparse_t parse;
67 int err = -ENOMEM;
Michael Bueschce2d90592007-11-06 16:36:41 +010068 int res = 0;
Michael Buesche4d6b792007-09-18 15:39:42 -040069 unsigned char buf[64];
70
71 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
72 if (!ssb)
Michael Bueschce2d90592007-11-06 16:36:41 +010073 goto out_error;
Michael Buesche4d6b792007-09-18 15:39:42 -040074
75 err = -ENODEV;
76 tuple.DesiredTuple = CISTPL_CONFIG;
77 tuple.Attributes = 0;
78 tuple.TupleData = buf;
79 tuple.TupleDataMax = sizeof(buf);
80 tuple.TupleOffset = 0;
81
82 res = pcmcia_get_first_tuple(dev, &tuple);
83 if (res != CS_SUCCESS)
84 goto err_kfree_ssb;
85 res = pcmcia_get_tuple_data(dev, &tuple);
86 if (res != CS_SUCCESS)
87 goto err_kfree_ssb;
88 res = pcmcia_parse_tuple(dev, &tuple, &parse);
89 if (res != CS_SUCCESS)
90 goto err_kfree_ssb;
91
92 dev->conf.ConfigBase = parse.config.base;
93 dev->conf.Present = parse.config.rmask[0];
94
95 dev->io.BasePort2 = 0;
96 dev->io.NumPorts2 = 0;
97 dev->io.Attributes2 = 0;
98
Michael Bueschce2d90592007-11-06 16:36:41 +010099 win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
100 WIN_ENABLE | WIN_DATA_WIDTH_16 |
101 WIN_USE_WAIT;
Michael Buesche4d6b792007-09-18 15:39:42 -0400102 win.Base = 0;
103 win.Size = SSB_CORE_SIZE;
Michael Bueschce2d90592007-11-06 16:36:41 +0100104 win.AccessSpeed = 250;
Michael Buesche4d6b792007-09-18 15:39:42 -0400105 res = pcmcia_request_window(&dev, &win, &dev->win);
106 if (res != CS_SUCCESS)
107 goto err_kfree_ssb;
108
109 mem.CardOffset = 0;
110 mem.Page = 0;
111 res = pcmcia_map_mem_page(dev->win, &mem);
112 if (res != CS_SUCCESS)
Michael Bueschce2d90592007-11-06 16:36:41 +0100113 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -0400114
115 res = pcmcia_request_configuration(dev, &dev->conf);
116 if (res != CS_SUCCESS)
117 goto err_disable;
118
119 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
Michael Bueschce2d90592007-11-06 16:36:41 +0100120 if (err)
121 goto err_disable;
Michael Buesche4d6b792007-09-18 15:39:42 -0400122 dev->priv = ssb;
123
Michael Bueschce2d90592007-11-06 16:36:41 +0100124 return 0;
125
126err_disable:
Michael Buesche4d6b792007-09-18 15:39:42 -0400127 pcmcia_disable_device(dev);
Michael Bueschce2d90592007-11-06 16:36:41 +0100128err_kfree_ssb:
Michael Buesche4d6b792007-09-18 15:39:42 -0400129 kfree(ssb);
Michael Bueschce2d90592007-11-06 16:36:41 +0100130out_error:
131 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
132 res, err);
Michael Buesche4d6b792007-09-18 15:39:42 -0400133 return err;
134}
135
136static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
137{
138 struct ssb_bus *ssb = dev->priv;
139
140 ssb_bus_unregister(ssb);
Michael Buesche4d6b792007-09-18 15:39:42 -0400141 pcmcia_disable_device(dev);
142 kfree(ssb);
143 dev->priv = NULL;
144}
145
146static struct pcmcia_driver b43_pcmcia_driver = {
Michael Bueschce2d90592007-11-06 16:36:41 +0100147 .owner = THIS_MODULE,
148 .drv = {
149 .name = "b43-pcmcia",
150 },
151 .id_table = b43_pcmcia_tbl,
152 .probe = b43_pcmcia_probe,
153 .remove = __devexit_p(b43_pcmcia_remove),
154 .suspend = b43_pcmcia_suspend,
155 .resume = b43_pcmcia_resume,
Michael Buesche4d6b792007-09-18 15:39:42 -0400156};
157
158int b43_pcmcia_init(void)
159{
160 return pcmcia_register_driver(&b43_pcmcia_driver);
161}
162
163void b43_pcmcia_exit(void)
164{
165 pcmcia_unregister_driver(&b43_pcmcia_driver);
166}