pcmcia.c 3.1 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

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

M
Michael Buesch 已提交
34

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

MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl);

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

	return ssb_bus_suspend(ssb);
49 50 51 52
}

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

	return ssb_bus_resume(ssb);
56 57 58 59 60 61 62 63 64 65
}
#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;
	int err = -ENOMEM;
66
	int res = 0;
67 68 69

	ssb = kzalloc(sizeof(*ssb), GFP_KERNEL);
	if (!ssb)
70
		goto out_error;
71 72 73

	err = -ENODEV;

74
	dev->config_flags |= CONF_ENABLE_IRQ;
75

76
	dev->resource[2]->flags |=  WIN_ENABLE | WIN_DATA_WIDTH_16 |
77
			 WIN_USE_WAIT;
78 79 80
	dev->resource[2]->start = 0;
	dev->resource[2]->end = SSB_CORE_SIZE;
	res = pcmcia_request_window(dev, dev->resource[2], 250);
D
Dominik Brodowski 已提交
81
	if (res != 0)
82 83
		goto err_kfree_ssb;

84
	res = pcmcia_map_mem_page(dev, dev->resource[2], 0);
D
Dominik Brodowski 已提交
85
	if (res != 0)
86
		goto err_disable;
87

88
	if (!dev->irq)
M
Michael Buesch 已提交
89 90
		goto err_disable;

91
	res = pcmcia_enable_device(dev);
D
Dominik Brodowski 已提交
92
	if (res != 0)
93 94
		goto err_disable;

95
	err = ssb_bus_pcmciabus_register(ssb, dev, dev->resource[2]->start);
96 97
	if (err)
		goto err_disable;
98 99
	dev->priv = ssb;

100 101 102
	return 0;

err_disable:
103
	pcmcia_disable_device(dev);
104
err_kfree_ssb:
105
	kfree(ssb);
106 107 108
out_error:
	printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n",
	       res, err);
109 110 111 112 113 114 115 116 117 118 119 120 121 122
	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 = {
123
	.owner		= THIS_MODULE,
124
	.name		= "b43-pcmcia",
125 126 127 128 129
	.id_table	= b43_pcmcia_tbl,
	.probe		= b43_pcmcia_probe,
	.remove		= __devexit_p(b43_pcmcia_remove),
	.suspend	= b43_pcmcia_suspend,
	.resume		= b43_pcmcia_resume,
130 131 132 133 134 135 136 137 138 139 140
};

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

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