Merge branch 'akpm'
[linux-2.6/next.git] / drivers / net / wireless / b43 / bus.c
blob05f6c7bff6ab683836c9614bbe4797e5fdd2d2ad
1 /*
3 Broadcom B43 wireless driver
4 Bus abstraction layer
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
19 Boston, MA 02110-1301, USA.
23 #include "b43.h"
24 #include "bus.h"
26 /* BCMA */
27 #ifdef CONFIG_B43_BCMA
28 static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
30 return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
32 static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
33 bool dynamic_pctl)
35 return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
37 static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
39 return bcma_core_is_enabled(dev->bdev);
41 static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
42 u32 core_specific_flags)
44 bcma_core_enable(dev->bdev, core_specific_flags);
46 static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
47 u32 core_specific_flags)
49 bcma_core_disable(dev->bdev, core_specific_flags);
51 static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
53 return bcma_read16(dev->bdev, offset);
55 static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
57 return bcma_read32(dev->bdev, offset);
59 static
60 void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
62 bcma_write16(dev->bdev, offset, value);
64 static
65 void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
67 bcma_write32(dev->bdev, offset, value);
69 static
70 void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
71 size_t count, u16 offset, u8 reg_width)
73 bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
75 static
76 void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
77 size_t count, u16 offset, u8 reg_width)
79 bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
82 struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
84 struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
85 if (!dev)
86 return NULL;
88 dev->bus_type = B43_BUS_BCMA;
89 dev->bdev = core;
91 dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown;
92 dev->bus_powerup = b43_bus_bcma_bus_powerup;
93 dev->device_is_enabled = b43_bus_bcma_device_is_enabled;
94 dev->device_enable = b43_bus_bcma_device_enable;
95 dev->device_disable = b43_bus_bcma_device_disable;
97 dev->read16 = b43_bus_bcma_read16;
98 dev->read32 = b43_bus_bcma_read32;
99 dev->write16 = b43_bus_bcma_write16;
100 dev->write32 = b43_bus_bcma_write32;
101 dev->block_read = b43_bus_bcma_block_read;
102 dev->block_write = b43_bus_bcma_block_write;
104 dev->dev = &core->dev;
105 dev->dma_dev = core->dma_dev;
106 dev->irq = core->irq;
109 dev->board_vendor = core->bus->boardinfo.vendor;
110 dev->board_type = core->bus->boardinfo.type;
111 dev->board_rev = core->bus->boardinfo.rev;
114 dev->chip_id = core->bus->chipinfo.id;
115 dev->chip_rev = core->bus->chipinfo.rev;
116 dev->chip_pkg = core->bus->chipinfo.pkg;
118 dev->bus_sprom = &core->bus->sprom;
120 dev->core_id = core->id.id;
121 dev->core_rev = core->id.rev;
123 return dev;
125 #endif /* CONFIG_B43_BCMA */
127 /* SSB */
128 #ifdef CONFIG_B43_SSB
129 static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
131 return ssb_bus_may_powerdown(dev->sdev->bus);
133 static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
134 bool dynamic_pctl)
136 return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
138 static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
140 return ssb_device_is_enabled(dev->sdev);
142 static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
143 u32 core_specific_flags)
145 ssb_device_enable(dev->sdev, core_specific_flags);
147 static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
148 u32 core_specific_flags)
150 ssb_device_disable(dev->sdev, core_specific_flags);
153 static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
155 return ssb_read16(dev->sdev, offset);
157 static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
159 return ssb_read32(dev->sdev, offset);
161 static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
163 ssb_write16(dev->sdev, offset, value);
165 static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
167 ssb_write32(dev->sdev, offset, value);
169 static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
170 size_t count, u16 offset, u8 reg_width)
172 ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
174 static
175 void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
176 size_t count, u16 offset, u8 reg_width)
178 ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
181 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
183 struct b43_bus_dev *dev;
185 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
186 if (!dev)
187 return NULL;
189 dev->bus_type = B43_BUS_SSB;
190 dev->sdev = sdev;
192 dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
193 dev->bus_powerup = b43_bus_ssb_bus_powerup;
194 dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
195 dev->device_enable = b43_bus_ssb_device_enable;
196 dev->device_disable = b43_bus_ssb_device_disable;
198 dev->read16 = b43_bus_ssb_read16;
199 dev->read32 = b43_bus_ssb_read32;
200 dev->write16 = b43_bus_ssb_write16;
201 dev->write32 = b43_bus_ssb_write32;
202 dev->block_read = b43_bus_ssb_block_read;
203 dev->block_write = b43_bus_ssb_block_write;
205 dev->dev = sdev->dev;
206 dev->dma_dev = sdev->dma_dev;
207 dev->irq = sdev->irq;
209 dev->board_vendor = sdev->bus->boardinfo.vendor;
210 dev->board_type = sdev->bus->boardinfo.type;
211 dev->board_rev = sdev->bus->boardinfo.rev;
213 dev->chip_id = sdev->bus->chip_id;
214 dev->chip_rev = sdev->bus->chip_rev;
215 dev->chip_pkg = sdev->bus->chip_package;
217 dev->bus_sprom = &sdev->bus->sprom;
219 dev->core_id = sdev->id.coreid;
220 dev->core_rev = sdev->id.revision;
222 return dev;
224 #endif /* CONFIG_B43_SSB */
226 void *b43_bus_get_wldev(struct b43_bus_dev *dev)
228 switch (dev->bus_type) {
229 #ifdef CONFIG_B43_BCMA
230 case B43_BUS_BCMA:
231 return bcma_get_drvdata(dev->bdev);
232 #endif
233 #ifdef CONFIG_B43_SSB
234 case B43_BUS_SSB:
235 return ssb_get_drvdata(dev->sdev);
236 #endif
238 return NULL;
241 void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
243 switch (dev->bus_type) {
244 #ifdef CONFIG_B43_BCMA
245 case B43_BUS_BCMA:
246 bcma_set_drvdata(dev->bdev, wldev);
247 break;
248 #endif
249 #ifdef CONFIG_B43_SSB
250 case B43_BUS_SSB:
251 ssb_set_drvdata(dev->sdev, wldev);
252 break;
253 #endif