pcmcia: deprecate CS_SUCCESS
[linux-2.6-block.git] / drivers / net / wireless / b43 / pcmcia.c
CommitLineData
e4d6b795
MB
1/*
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
1a09404a
MB
24#include "pcmcia.h"
25
e4d6b795
MB
26#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
1a09404a 35
e4d6b795
MB
36static /*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{
8fe2b65a
MB
46 struct ssb_bus *ssb = dev->priv;
47
48 return ssb_bus_suspend(ssb);
e4d6b795
MB
49}
50
51static int b43_pcmcia_resume(struct pcmcia_device *dev)
52{
8fe2b65a
MB
53 struct ssb_bus *ssb = dev->priv;
54
55 return ssb_bus_resume(ssb);
e4d6b795
MB
56}
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;
65 win_req_t win;
66 memreq_t mem;
67 tuple_t tuple;
68 cisparse_t parse;
69 int err = -ENOMEM;
ce2d9059 70 int res = 0;
e4d6b795
MB
71 unsigned char buf[64];
72
73 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
74 if (!ssb)
ce2d9059 75 goto out_error;
e4d6b795
MB
76
77 err = -ENODEV;
78 tuple.DesiredTuple = CISTPL_CONFIG;
79 tuple.Attributes = 0;
80 tuple.TupleData = buf;
81 tuple.TupleDataMax = sizeof(buf);
82 tuple.TupleOffset = 0;
83
84 res = pcmcia_get_first_tuple(dev, &tuple);
4c89e88b 85 if (res != 0)
e4d6b795
MB
86 goto err_kfree_ssb;
87 res = pcmcia_get_tuple_data(dev, &tuple);
4c89e88b 88 if (res != 0)
e4d6b795
MB
89 goto err_kfree_ssb;
90 res = pcmcia_parse_tuple(dev, &tuple, &parse);
4c89e88b 91 if (res != 0)
e4d6b795
MB
92 goto err_kfree_ssb;
93
94 dev->conf.ConfigBase = parse.config.base;
95 dev->conf.Present = parse.config.rmask[0];
e6458901
MB
96 dev->conf.Attributes = CONF_ENABLE_IRQ;
97 dev->conf.IntType = INT_MEMORY_AND_IO;
e4d6b795
MB
98
99 dev->io.BasePort2 = 0;
100 dev->io.NumPorts2 = 0;
101 dev->io.Attributes2 = 0;
102
ce2d9059
MB
103 win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
104 WIN_ENABLE | WIN_DATA_WIDTH_16 |
105 WIN_USE_WAIT;
e4d6b795
MB
106 win.Base = 0;
107 win.Size = SSB_CORE_SIZE;
ce2d9059 108 win.AccessSpeed = 250;
e4d6b795 109 res = pcmcia_request_window(&dev, &win, &dev->win);
4c89e88b 110 if (res != 0)
e4d6b795
MB
111 goto err_kfree_ssb;
112
113 mem.CardOffset = 0;
114 mem.Page = 0;
115 res = pcmcia_map_mem_page(dev->win, &mem);
4c89e88b 116 if (res != 0)
ce2d9059 117 goto err_disable;
e4d6b795 118
e6458901
MB
119 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
120 dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
9dcb5f47
MB
121 dev->irq.Handler = NULL; /* The handler is registered later. */
122 dev->irq.Instance = NULL;
123 res = pcmcia_request_irq(dev, &dev->irq);
4c89e88b 124 if (res != 0)
9dcb5f47
MB
125 goto err_disable;
126
e4d6b795 127 res = pcmcia_request_configuration(dev, &dev->conf);
4c89e88b 128 if (res != 0)
e4d6b795
MB
129 goto err_disable;
130
131 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
ce2d9059
MB
132 if (err)
133 goto err_disable;
e4d6b795
MB
134 dev->priv = ssb;
135
ce2d9059
MB
136 return 0;
137
138err_disable:
e4d6b795 139 pcmcia_disable_device(dev);
ce2d9059 140err_kfree_ssb:
e4d6b795 141 kfree(ssb);
ce2d9059
MB
142out_error:
143 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
144 res, err);
e4d6b795
MB
145 return err;
146}
147
148static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
149{
150 struct ssb_bus *ssb = dev->priv;
151
152 ssb_bus_unregister(ssb);
e4d6b795
MB
153 pcmcia_disable_device(dev);
154 kfree(ssb);
155 dev->priv = NULL;
156}
157
158static struct pcmcia_driver b43_pcmcia_driver = {
ce2d9059
MB
159 .owner = THIS_MODULE,
160 .drv = {
161 .name = "b43-pcmcia",
162 },
163 .id_table = b43_pcmcia_tbl,
164 .probe = b43_pcmcia_probe,
165 .remove = __devexit_p(b43_pcmcia_remove),
166 .suspend = b43_pcmcia_suspend,
167 .resume = b43_pcmcia_resume,
e4d6b795
MB
168};
169
170int b43_pcmcia_init(void)
171{
172 return pcmcia_register_driver(&b43_pcmcia_driver);
173}
174
175void b43_pcmcia_exit(void)
176{
177 pcmcia_unregister_driver(&b43_pcmcia_driver);
178}