treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / net / wireless / broadcom / b43 / bus.c
blobfdb1c82892d6798e4f081f0e9c0d43468aafb4c3
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
4 Broadcom B43 wireless driver
5 Bus abstraction layer
7 Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>
12 #ifdef CONFIG_BCM47XX_BCMA
13 #include <asm/mach-bcm47xx/bcm47xx.h>
14 #endif
16 #include "b43.h"
17 #include "bus.h"
19 /* BCMA */
20 #ifdef CONFIG_B43_BCMA
21 static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
23 return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
25 static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
26 bool dynamic_pctl)
28 return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
30 static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
32 return bcma_core_is_enabled(dev->bdev);
34 static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
35 u32 core_specific_flags)
37 bcma_core_enable(dev->bdev, core_specific_flags);
39 static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
40 u32 core_specific_flags)
42 bcma_core_disable(dev->bdev, core_specific_flags);
44 static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
46 return bcma_read16(dev->bdev, offset);
48 static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
50 return bcma_read32(dev->bdev, offset);
52 static
53 void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
55 bcma_write16(dev->bdev, offset, value);
57 static
58 void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
60 bcma_write32(dev->bdev, offset, value);
62 static
63 void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
64 size_t count, u16 offset, u8 reg_width)
66 bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
68 static
69 void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
70 size_t count, u16 offset, u8 reg_width)
72 bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
75 struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
77 struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
78 if (!dev)
79 return NULL;
81 dev->bus_type = B43_BUS_BCMA;
82 dev->bdev = core;
84 dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown;
85 dev->bus_powerup = b43_bus_bcma_bus_powerup;
86 dev->device_is_enabled = b43_bus_bcma_device_is_enabled;
87 dev->device_enable = b43_bus_bcma_device_enable;
88 dev->device_disable = b43_bus_bcma_device_disable;
90 dev->read16 = b43_bus_bcma_read16;
91 dev->read32 = b43_bus_bcma_read32;
92 dev->write16 = b43_bus_bcma_write16;
93 dev->write32 = b43_bus_bcma_write32;
94 dev->block_read = b43_bus_bcma_block_read;
95 dev->block_write = b43_bus_bcma_block_write;
96 #ifdef CONFIG_BCM47XX_BCMA
97 if (b43_bus_host_is_pci(dev) &&
98 bcm47xx_bus_type == BCM47XX_BUS_TYPE_BCMA &&
99 bcm47xx_bus.bcma.bus.chipinfo.id == BCMA_CHIP_ID_BCM4716)
100 dev->flush_writes = true;
101 #endif
103 dev->dev = &core->dev;
104 dev->dma_dev = core->dma_dev;
105 dev->irq = core->irq;
107 dev->board_vendor = core->bus->boardinfo.vendor;
108 dev->board_type = core->bus->boardinfo.type;
109 dev->board_rev = core->bus->sprom.board_rev;
111 dev->chip_id = core->bus->chipinfo.id;
112 dev->chip_rev = core->bus->chipinfo.rev;
113 dev->chip_pkg = core->bus->chipinfo.pkg;
115 dev->bus_sprom = &core->bus->sprom;
117 dev->core_id = core->id.id;
118 dev->core_rev = core->id.rev;
120 return dev;
122 #endif /* CONFIG_B43_BCMA */
124 /* SSB */
125 #ifdef CONFIG_B43_SSB
126 static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
128 return ssb_bus_may_powerdown(dev->sdev->bus);
130 static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
131 bool dynamic_pctl)
133 return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
135 static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
137 return ssb_device_is_enabled(dev->sdev);
139 static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
140 u32 core_specific_flags)
142 ssb_device_enable(dev->sdev, core_specific_flags);
144 static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
145 u32 core_specific_flags)
147 ssb_device_disable(dev->sdev, core_specific_flags);
150 static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
152 return ssb_read16(dev->sdev, offset);
154 static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
156 return ssb_read32(dev->sdev, offset);
158 static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
160 ssb_write16(dev->sdev, offset, value);
162 static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
164 ssb_write32(dev->sdev, offset, value);
166 static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
167 size_t count, u16 offset, u8 reg_width)
169 ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
171 static
172 void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
173 size_t count, u16 offset, u8 reg_width)
175 ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
178 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
180 struct b43_bus_dev *dev;
182 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
183 if (!dev)
184 return NULL;
186 dev->bus_type = B43_BUS_SSB;
187 dev->sdev = sdev;
189 dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
190 dev->bus_powerup = b43_bus_ssb_bus_powerup;
191 dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
192 dev->device_enable = b43_bus_ssb_device_enable;
193 dev->device_disable = b43_bus_ssb_device_disable;
195 dev->read16 = b43_bus_ssb_read16;
196 dev->read32 = b43_bus_ssb_read32;
197 dev->write16 = b43_bus_ssb_write16;
198 dev->write32 = b43_bus_ssb_write32;
199 dev->block_read = b43_bus_ssb_block_read;
200 dev->block_write = b43_bus_ssb_block_write;
202 dev->dev = sdev->dev;
203 dev->dma_dev = sdev->dma_dev;
204 dev->irq = sdev->irq;
206 dev->board_vendor = sdev->bus->boardinfo.vendor;
207 dev->board_type = sdev->bus->boardinfo.type;
208 dev->board_rev = sdev->bus->sprom.board_rev;
210 dev->chip_id = sdev->bus->chip_id;
211 dev->chip_rev = sdev->bus->chip_rev;
212 dev->chip_pkg = sdev->bus->chip_package;
214 dev->bus_sprom = &sdev->bus->sprom;
216 dev->core_id = sdev->id.coreid;
217 dev->core_rev = sdev->id.revision;
219 return dev;
221 #endif /* CONFIG_B43_SSB */
223 void *b43_bus_get_wldev(struct b43_bus_dev *dev)
225 switch (dev->bus_type) {
226 #ifdef CONFIG_B43_BCMA
227 case B43_BUS_BCMA:
228 return bcma_get_drvdata(dev->bdev);
229 #endif
230 #ifdef CONFIG_B43_SSB
231 case B43_BUS_SSB:
232 return ssb_get_drvdata(dev->sdev);
233 #endif
235 return NULL;
238 void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
240 switch (dev->bus_type) {
241 #ifdef CONFIG_B43_BCMA
242 case B43_BUS_BCMA:
243 bcma_set_drvdata(dev->bdev, wldev);
244 break;
245 #endif
246 #ifdef CONFIG_B43_SSB
247 case B43_BUS_SSB:
248 ssb_set_drvdata(dev->sdev, wldev);
249 break;
250 #endif