pcmcia.c 3.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*

  Broadcom B43 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.

*/

M
Michael Buesch 已提交
24 25
#include "pcmcia.h"

26
#include <linux/ssb/ssb.h>
27
#include <linux/slab.h>
28 29 30 31 32 33 34 35

#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>

M
Michael Buesch 已提交
36

37 38
static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = {
	PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448),
C
Clyde McPherson 已提交
39
	PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476),
40 41 42 43 44 45 46 47
	PCMCIA_DEVICE_NULL,
};

MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);

#ifdef CONFIG_PM
static int b43_pcmcia_suspend(struct pcmcia_device *dev)
{
48 49 50
	struct ssb_bus *ssb = dev->priv;

	return ssb_bus_suspend(ssb);
51 52 53 54
}

static int b43_pcmcia_resume(struct pcmcia_device *dev)
{
55 56 57
	struct ssb_bus *ssb = dev->priv;

	return ssb_bus_resume(ssb);
58 59 60 61 62 63 64 65 66 67 68 69
}
#else /* CONFIG_PM */
# define b43_pcmcia_suspend		NULL
# define b43_pcmcia_resume		NULL
#endif /* CONFIG_PM */

static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
{
	struct ssb_bus *ssb;
	win_req_t win;
	memreq_t mem;
	int err = -ENOMEM;
70
	int res = 0;
71 72 73

	ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
	if (!ssb)
74
		goto out_error;
75 76 77

	err = -ENODEV;

M
Michael Buesch 已提交
78 79
	dev->conf.Attributes = CONF_ENABLE_IRQ;
	dev->conf.IntType = INT_MEMORY_AND_IO;
80 81 82 83 84

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

85 86 87
	win.Attributes = WIN_ADDR_SPACE_MEM | WIN_MEMORY_TYPE_CM |
			 WIN_ENABLE | WIN_DATA_WIDTH_16 |
			 WIN_USE_WAIT;
88 89
	win.Base = 0;
	win.Size = SSB_CORE_SIZE;
90
	win.AccessSpeed = 250;
91
	res = pcmcia_request_window(dev, &win, &dev->win);
D
Dominik Brodowski 已提交
92
	if (res != 0)
93 94 95 96
		goto err_kfree_ssb;

	mem.CardOffset = 0;
	mem.Page = 0;
97
	res = pcmcia_map_mem_page(dev, dev->win, &mem);
D
Dominik Brodowski 已提交
98
	if (res != 0)
99
		goto err_disable;
100

M
Michael Buesch 已提交
101
	dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
M
Michael Buesch 已提交
102 103
	dev->irq.Handler = NULL; /* The handler is registered later. */
	res = pcmcia_request_irq(dev, &dev->irq);
D
Dominik Brodowski 已提交
104
	if (res != 0)
M
Michael Buesch 已提交
105 106
		goto err_disable;

107
	res = pcmcia_request_configuration(dev, &dev->conf);
D
Dominik Brodowski 已提交
108
	if (res != 0)
109 110 111
		goto err_disable;

	err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
112 113
	if (err)
		goto err_disable;
114 115
	dev->priv = ssb;

116 117 118
	return 0;

err_disable:
119
	pcmcia_disable_device(dev);
120
err_kfree_ssb:
121
	kfree(ssb);
122 123 124
out_error:
	printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
	       res, err);
125 126 127 128 129 130 131 132 133 134 135 136 137 138
	return err;
}

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

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

static struct pcmcia_driver b43_pcmcia_driver = {
139 140 141 142 143 144 145 146 147
	.owner		= THIS_MODULE,
	.drv		= {
				.name = "b43-pcmcia",
			},
	.id_table	= b43_pcmcia_tbl,
	.probe		= b43_pcmcia_probe,
	.remove		= __devexit_p(b43_pcmcia_remove),
	.suspend	= b43_pcmcia_suspend,
	.resume		= b43_pcmcia_resume,
148 149 150 151 152 153 154 155 156 157 158
};

int b43_pcmcia_init(void)
{
	return pcmcia_register_driver(&b43_pcmcia_driver);
}

void b43_pcmcia_exit(void)
{
	pcmcia_unregister_driver(&b43_pcmcia_driver);
}