aboutsummaryrefslogtreecommitdiffstats
path: root/package/bcm43xx-mac80211/src/bcm43xx/bcm43xx_pcmcia.c
blob: f48cba648216713cc7005c87642dcdc3340cf76d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*

  Broadcom BCM43xx wireless driver

  Copyright (c) 2007 Michael Buesch <mb@bu3sch.de>

  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  Boston, MA 02110-1301, USA.

*/

#include <linux/ssb/ssb.h>

#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/ciscode.h>
#include <pcmcia/ds.h>
#include <pcmcia/cisreg.h>


static /*const*/ struct pcmcia_device_id bcm43xx_pcmcia_tbl[] = {
	PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
	PCMCIA_DEVICE_NULL,
};
MODULE_DEVICE_TABLE(pcmcia, bcm43xx_pcmcia_tbl);


#ifdef CONFIG_PM
static int bcm43xx_pcmcia_suspend(struct pcmcia_device *dev)
{
	//TODO
	return 0;
}

static int bcm43xx_pcmcia_resume(struct pcmcia_device *dev)
{
	//TODO
	return 0;
}
#else /* CONFIG_PM */
# define bcm43xx_pcmcia_suspend		NULL
# define bcm43xx_pcmcia_resume		NULL
#endif /* CONFIG_PM */

static int __devinit bcm43xx_pcmcia_probe(struct pcmcia_device *dev)
{
	struct ssb_bus *ssb;
	win_req_t win;
	memreq_t mem;
	tuple_t tuple;
	cisparse_t parse;
	int err = -ENOMEM;
	int res;
	unsigned char buf[64];

	ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
	if (!ssb)
		goto out;

	err = -ENODEV;
	tuple.DesiredTuple = CISTPL_CONFIG;
	tuple.Attributes = 0;
	tuple.TupleData = buf;
	tuple.TupleDataMax = sizeof(buf);
	tuple.TupleOffset = 0;

	res = pcmcia_get_first_tuple(dev, &tuple);
	if (res != CS_SUCCESS)
		goto err_kfree_ssb;
	res = pcmcia_get_tuple_data(dev, &tuple);
	if (res != CS_SUCCESS)
		goto err_kfree_ssb;
	res = pcmcia_parse_tuple(dev, &tuple, &parse);
	if (res != CS_SUCCESS)
		goto err_kfree_ssb;

	dev->conf.ConfigBase = parse.config.base;
	dev->conf.Present = parse.config.rmask[0];

	dev->io.BasePort2 = 0;
	dev->io.NumPorts2 = 0;
	dev->io.Attributes2 = 0;

	win.Attributes = WIN_MEMORY_TYPE_CM | WIN_ENABLE | WIN_USE_WAIT;
	win.Base = 0;
	win.Size = SSB_CORE_SIZE;
	win.AccessSpeed = 1000;
	res = pcmcia_request_window(&dev, &win, &dev->win);
	if (res != CS_SUCCESS)
		goto err_kfree_ssb;

	mem.CardOffset = 0;
	mem.Page = 0;
	res = pcmcia_map_mem_page(dev->win, &mem);
	if (res != CS_SUCCESS)
		goto err_kfree_ssb;

	res = pcmcia_request_configuration(dev, &dev->conf);
	if (res != CS_SUCCESS)
		goto err_disable;

	err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
	dev->priv = ssb;

out:
	return err;
err_disable:
	pcmcia_disable_device(dev);
err_kfree_ssb:
	kfree(ssb);
	return err;
}

static void __devexit bcm43xx_pcmcia_remove(struct pcmcia_device *dev)
{
	struct ssb_bus *ssb = dev->priv;

	ssb_bus_unregister(ssb);
	pcmcia_release_window(dev->win);
	pcmcia_disable_device(dev);
	kfree(ssb);
	dev->priv = NULL;
}

static struct pcmcia_driver bcm43xx_pcmcia_driver = {
	.owner		= THIS_MODULE,
	.drv		= {
		.name	= "bcm43xx-pcmcia",
	},
	.id_table	= bcm43xx_pcmcia_tbl,
	.probe		= bcm43xx_pcmcia_probe,
	.remove		= bcm43xx_pcmcia_remove,
	.suspend	= bcm43xx_pcmcia_suspend,
	.resume		= bcm43xx_pcmcia_resume,
};

int bcm43xx_pcmcia_init(void)
{
	return pcmcia_register_driver(&bcm43xx_pcmcia_driver);
}

void bcm43xx_pcmcia_exit(void)
{
	pcmcia_unregister_driver(&bcm43xx_pcmcia_driver);
}