Committer: Michael Beasley <mike@snafu.setup>
[mikesnafu-overlay.git] / drivers / net / wireless / b43 / pcmcia.c
blob371e4a11951190e17d2e18597cce5f9844ce23aa
1 /*
3 Broadcom B43 wireless driver
5 Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>
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.
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.
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.
24 #include "pcmcia.h"
26 #include <linux/ssb/ssb.h>
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>
36 static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
37 PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
38 PCMCIA_DEVICE_NULL,
41 MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);
43 #ifdef CONFIG_PM
44 static int b43_pcmcia_suspend(struct pcmcia_device *dev)
46 //TODO
47 return 0;
50 static int b43_pcmcia_resume(struct pcmcia_device *dev)
52 //TODO
53 return 0;
55 #else /* CONFIG_PM */
56 # define b43_pcmcia_suspend NULL
57 # define b43_pcmcia_resume NULL
58 #endif /* CONFIG_PM */
60 static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
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;
68 int res = 0;
69 unsigned char buf[64];
71 ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
72 if (!ssb)
73 goto out_error;
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;
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;
92 dev->conf.ConfigBase = parse.config.base;
93 dev->conf.Present = parse.config.rmask[0];
94 dev->conf.Attributes = CONF_ENABLE_IRQ;
95 dev->conf.IntType = INT_MEMORY_AND_IO;
97 dev->io.BasePort2 = 0;
98 dev->io.NumPorts2 = 0;
99 dev->io.Attributes2 = 0;
101 win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
102 WIN_ENABLE | WIN_DATA_WIDTH_16 |
103 WIN_USE_WAIT;
104 win.Base = 0;
105 win.Size = SSB_CORE_SIZE;
106 win.AccessSpeed = 250;
107 res = pcmcia_request_window(&dev, &win, &dev->win);
108 if (res != CS_SUCCESS)
109 goto err_kfree_ssb;
111 mem.CardOffset = 0;
112 mem.Page = 0;
113 res = pcmcia_map_mem_page(dev->win, &mem);
114 if (res != CS_SUCCESS)
115 goto err_disable;
117 dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
118 dev->irq.IRQInfo1 = IRQ_LEVEL_ID;
119 dev->irq.Handler = NULL; /* The handler is registered later. */
120 dev->irq.Instance = NULL;
121 res = pcmcia_request_irq(dev, &dev->irq);
122 if (res != CS_SUCCESS)
123 goto err_disable;
125 res = pcmcia_request_configuration(dev, &dev->conf);
126 if (res != CS_SUCCESS)
127 goto err_disable;
129 err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
130 if (err)
131 goto err_disable;
132 dev->priv = ssb;
134 return 0;
136 err_disable:
137 pcmcia_disable_device(dev);
138 err_kfree_ssb:
139 kfree(ssb);
140 out_error:
141 printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
142 res, err);
143 return err;
146 static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev)
148 struct ssb_bus *ssb = dev->priv;
150 ssb_bus_unregister(ssb);
151 pcmcia_disable_device(dev);
152 kfree(ssb);
153 dev->priv = NULL;
156 static struct pcmcia_driver b43_pcmcia_driver = {
157 .owner = THIS_MODULE,
158 .drv = {
159 .name = "b43-pcmcia",
161 .id_table = b43_pcmcia_tbl,
162 .probe = b43_pcmcia_probe,
163 .remove = __devexit_p(b43_pcmcia_remove),
164 .suspend = b43_pcmcia_suspend,
165 .resume = b43_pcmcia_resume,
168 int b43_pcmcia_init(void)
170 return pcmcia_register_driver(&b43_pcmcia_driver);
173 void b43_pcmcia_exit(void)
175 pcmcia_unregister_driver(&b43_pcmcia_driver);