dmaengine: imx-sdma: Let the core do the device node validation
[linux/fpc-iii.git] / drivers / net / wireless / broadcom / b43 / bus.c
blob17d16a391fe6556dc66ab9a6bd5e4d0bd0c954a3
1 /*
3 Broadcom B43 wireless driver
4 Bus abstraction layer
6 Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
21 Boston, MA 02110-1301, USA.
25 #ifdef CONFIG_BCM47XX_BCMA
26 #include <asm/mach-bcm47xx/bcm47xx.h>
27 #endif
29 #include "b43.h"
30 #include "bus.h"
32 /* BCMA */
33 #ifdef CONFIG_B43_BCMA
34 static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
36 return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
38 static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
39 bool dynamic_pctl)
41 return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
43 static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
45 return bcma_core_is_enabled(dev->bdev);
47 static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
48 u32 core_specific_flags)
50 bcma_core_enable(dev->bdev, core_specific_flags);
52 static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
53 u32 core_specific_flags)
55 bcma_core_disable(dev->bdev, core_specific_flags);
57 static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
59 return bcma_read16(dev->bdev, offset);
61 static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
63 return bcma_read32(dev->bdev, offset);
65 static
66 void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
68 bcma_write16(dev->bdev, offset, value);
70 static
71 void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
73 bcma_write32(dev->bdev, offset, value);
75 static
76 void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
77 size_t count, u16 offset, u8 reg_width)
79 bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
81 static
82 void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
83 size_t count, u16 offset, u8 reg_width)
85 bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
88 struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
90 struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
91 if (!dev)
92 return NULL;
94 dev->bus_type = B43_BUS_BCMA;
95 dev->bdev = core;
97 dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown;
98 dev->bus_powerup = b43_bus_bcma_bus_powerup;
99 dev->device_is_enabled = b43_bus_bcma_device_is_enabled;
100 dev->device_enable = b43_bus_bcma_device_enable;
101 dev->device_disable = b43_bus_bcma_device_disable;
103 dev->read16 = b43_bus_bcma_read16;
104 dev->read32 = b43_bus_bcma_read32;
105 dev->write16 = b43_bus_bcma_write16;
106 dev->write32 = b43_bus_bcma_write32;
107 dev->block_read = b43_bus_bcma_block_read;
108 dev->block_write = b43_bus_bcma_block_write;
109 #ifdef CONFIG_BCM47XX_BCMA
110 if (b43_bus_host_is_pci(dev) &&
111 bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA &&
112 bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4716)
113 dev->flush_writes = true;
114 #endif
116 dev->dev = &core->dev;
117 dev->dma_dev = core->dma_dev;
118 dev->irq = core->irq;
120 dev->board_vendor = core->bus->boardinfo.vendor;
121 dev->board_type = core->bus->boardinfo.type;
122 dev->board_rev = core->bus->sprom.board_rev;
124 dev->chip_id = core->bus->chipinfo.id;
125 dev->chip_rev = core->bus->chipinfo.rev;
126 dev->chip_pkg = core->bus->chipinfo.pkg;
128 dev->bus_sprom = &core->bus->sprom;
130 dev->core_id = core->id.id;
131 dev->core_rev = core->id.rev;
133 return dev;
135 #endif /* CONFIG_B43_BCMA */
137 /* SSB */
138 #ifdef CONFIG_B43_SSB
139 static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
141 return ssb_bus_may_powerdown(dev->sdev->bus);
143 static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
144 bool dynamic_pctl)
146 return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
148 static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
150 return ssb_device_is_enabled(dev->sdev);
152 static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
153 u32 core_specific_flags)
155 ssb_device_enable(dev->sdev, core_specific_flags);
157 static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
158 u32 core_specific_flags)
160 ssb_device_disable(dev->sdev, core_specific_flags);
163 static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
165 return ssb_read16(dev->sdev, offset);
167 static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
169 return ssb_read32(dev->sdev, offset);
171 static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
173 ssb_write16(dev->sdev, offset, value);
175 static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
177 ssb_write32(dev->sdev, offset, value);
179 static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
180 size_t count, u16 offset, u8 reg_width)
182 ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
184 static
185 void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
186 size_t count, u16 offset, u8 reg_width)
188 ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
191 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
193 struct b43_bus_dev *dev;
195 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
196 if (!dev)
197 return NULL;
199 dev->bus_type = B43_BUS_SSB;
200 dev->sdev = sdev;
202 dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
203 dev->bus_powerup = b43_bus_ssb_bus_powerup;
204 dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
205 dev->device_enable = b43_bus_ssb_device_enable;
206 dev->device_disable = b43_bus_ssb_device_disable;
208 dev->read16 = b43_bus_ssb_read16;
209 dev->read32 = b43_bus_ssb_read32;
210 dev->write16 = b43_bus_ssb_write16;
211 dev->write32 = b43_bus_ssb_write32;
212 dev->block_read = b43_bus_ssb_block_read;
213 dev->block_write = b43_bus_ssb_block_write;
215 dev->dev = sdev->dev;
216 dev->dma_dev = sdev->dma_dev;
217 dev->irq = sdev->irq;
219 dev->board_vendor = sdev->bus->boardinfo.vendor;
220 dev->board_type = sdev->bus->boardinfo.type;
221 dev->board_rev = sdev->bus->sprom.board_rev;
223 dev->chip_id = sdev->bus->chip_id;
224 dev->chip_rev = sdev->bus->chip_rev;
225 dev->chip_pkg = sdev->bus->chip_package;
227 dev->bus_sprom = &sdev->bus->sprom;
229 dev->core_id = sdev->id.coreid;
230 dev->core_rev = sdev->id.revision;
232 return dev;
234 #endif /* CONFIG_B43_SSB */
236 void *b43_bus_get_wldev(struct b43_bus_dev *dev)
238 switch (dev->bus_type) {
239 #ifdef CONFIG_B43_BCMA
240 case B43_BUS_BCMA:
241 return bcma_get_drvdata(dev->bdev);
242 #endif
243 #ifdef CONFIG_B43_SSB
244 case B43_BUS_SSB:
245 return ssb_get_drvdata(dev->sdev);
246 #endif
248 return NULL;
251 void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
253 switch (dev->bus_type) {
254 #ifdef CONFIG_B43_BCMA
255 case B43_BUS_BCMA:
256 bcma_set_drvdata(dev->bdev, wldev);
257 break;
258 #endif
259 #ifdef CONFIG_B43_SSB
260 case B43_BUS_SSB:
261 ssb_set_drvdata(dev->sdev, wldev);
262 break;
263 #endif