Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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 | |
Michael Buesch | 1a09404 | 2007-09-20 11:13:40 -0700 | [diff] [blame] | 24 | #include "pcmcia.h" |
| 25 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 26 | #include <linux/ssb/ssb.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 27 | #include <linux/slab.h> |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 28 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 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 | |
Michael Buesch | 1a09404 | 2007-09-20 11:13:40 -0700 | [diff] [blame] | 35 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 36 | static /*const */ struct pcmcia_device_id b43_pcmcia_tbl[] = { |
| 37 | PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x448), |
Clyde McPherson | cff782c | 2009-06-30 22:39:28 -0500 | [diff] [blame] | 38 | PCMCIA_DEVICE_MANF_CARD(0x2D0, 0x476), |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 39 | PCMCIA_DEVICE_NULL, |
| 40 | }; |
| 41 | |
| 42 | MODULE_DEVICE_TABLE(pcmcia, b43_pcmcia_tbl); |
| 43 | |
| 44 | #ifdef CONFIG_PM |
| 45 | static int b43_pcmcia_suspend(struct pcmcia_device *dev) |
| 46 | { |
Michael Buesch | 8fe2b65 | 2008-03-30 00:10:50 +0100 | [diff] [blame] | 47 | struct ssb_bus *ssb = dev->priv; |
| 48 | |
| 49 | return ssb_bus_suspend(ssb); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | static int b43_pcmcia_resume(struct pcmcia_device *dev) |
| 53 | { |
Michael Buesch | 8fe2b65 | 2008-03-30 00:10:50 +0100 | [diff] [blame] | 54 | struct ssb_bus *ssb = dev->priv; |
| 55 | |
| 56 | return ssb_bus_resume(ssb); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 57 | } |
| 58 | #else /* CONFIG_PM */ |
| 59 | # define b43_pcmcia_suspend NULL |
| 60 | # define b43_pcmcia_resume NULL |
| 61 | #endif /* CONFIG_PM */ |
| 62 | |
| 63 | static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev) |
| 64 | { |
| 65 | struct ssb_bus *ssb; |
| 66 | win_req_t win; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 67 | int err = -ENOMEM; |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 68 | int res = 0; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 69 | |
| 70 | ssb = kzalloc(sizeof(*ssb), GFP_KERNEL); |
| 71 | if (!ssb) |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 72 | goto out_error; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 73 | |
| 74 | err = -ENODEV; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 75 | |
Michael Buesch | e645890 | 2008-03-28 11:48:53 +0100 | [diff] [blame] | 76 | dev->conf.Attributes = CONF_ENABLE_IRQ; |
| 77 | dev->conf.IntType = INT_MEMORY_AND_IO; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 78 | |
Dominik Brodowski | 0ca724d3 | 2010-07-24 19:03:02 +0200 | [diff] [blame] | 79 | win.Attributes = WIN_ENABLE | WIN_DATA_WIDTH_16 | |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 80 | WIN_USE_WAIT; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 81 | win.Base = 0; |
| 82 | win.Size = SSB_CORE_SIZE; |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 83 | win.AccessSpeed = 250; |
Dominik Brodowski | 6838b03 | 2009-11-03 01:31:52 +0100 | [diff] [blame] | 84 | res = pcmcia_request_window(dev, &win, &dev->win); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 85 | if (res != 0) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 86 | goto err_kfree_ssb; |
| 87 | |
Dominik Brodowski | b5cb259 | 2010-07-24 18:46:42 +0200 | [diff] [blame] | 88 | res = pcmcia_map_mem_page(dev, dev->win, 0); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 89 | if (res != 0) |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 90 | goto err_disable; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 91 | |
Dominik Brodowski | eb14120 | 2010-03-07 12:21:16 +0100 | [diff] [blame] | 92 | if (!dev->irq) |
Michael Buesch | 9dcb5f4 | 2007-11-07 19:08:26 +0100 | [diff] [blame] | 93 | goto err_disable; |
| 94 | |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 95 | res = pcmcia_request_configuration(dev, &dev->conf); |
Dominik Brodowski | 4c89e88 | 2008-08-03 10:07:45 +0200 | [diff] [blame] | 96 | if (res != 0) |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 97 | goto err_disable; |
| 98 | |
| 99 | err = ssb_bus_pcmciabus_register(ssb, dev, win.Base); |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 100 | if (err) |
| 101 | goto err_disable; |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 102 | dev->priv = ssb; |
| 103 | |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 104 | return 0; |
| 105 | |
| 106 | err_disable: |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 107 | pcmcia_disable_device(dev); |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 108 | err_kfree_ssb: |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 109 | kfree(ssb); |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 110 | out_error: |
| 111 | printk(KERN_ERR "b43-pcmcia: Initialization failed (%d, %d)\n", |
| 112 | res, err); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 113 | return err; |
| 114 | } |
| 115 | |
| 116 | static void __devexit b43_pcmcia_remove(struct pcmcia_device *dev) |
| 117 | { |
| 118 | struct ssb_bus *ssb = dev->priv; |
| 119 | |
| 120 | ssb_bus_unregister(ssb); |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 121 | pcmcia_disable_device(dev); |
| 122 | kfree(ssb); |
| 123 | dev->priv = NULL; |
| 124 | } |
| 125 | |
| 126 | static struct pcmcia_driver b43_pcmcia_driver = { |
Michael Buesch | ce2d9059 | 2007-11-06 16:36:41 +0100 | [diff] [blame] | 127 | .owner = THIS_MODULE, |
| 128 | .drv = { |
| 129 | .name = "b43-pcmcia", |
| 130 | }, |
| 131 | .id_table = b43_pcmcia_tbl, |
| 132 | .probe = b43_pcmcia_probe, |
| 133 | .remove = __devexit_p(b43_pcmcia_remove), |
| 134 | .suspend = b43_pcmcia_suspend, |
| 135 | .resume = b43_pcmcia_resume, |
Michael Buesch | e4d6b79 | 2007-09-18 15:39:42 -0400 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | int b43_pcmcia_init(void) |
| 139 | { |
| 140 | return pcmcia_register_driver(&b43_pcmcia_driver); |
| 141 | } |
| 142 | |
| 143 | void b43_pcmcia_exit(void) |
| 144 | { |
| 145 | pcmcia_unregister_driver(&b43_pcmcia_driver); |
| 146 | } |