1/* 2 3 Broadcom B43 wireless driver 4 Bus abstraction layer 5 6 Copyright (c) 2011 Rafa�� Mi��ecki <zajec5@gmail.com> 7 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. 12 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. 17 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. 22 23*/ 24 25#ifdef CONFIG_BCM47XX_BCMA 26#include <asm/mach-bcm47xx/bcm47xx.h> 27#endif 28 29#include "b43.h" 30#include "bus.h" 31 32/* BCMA */ 33#ifdef CONFIG_B43_BCMA 34static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev) 35{ 36 return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */ 37} 38static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev, 39 bool dynamic_pctl) 40{ 41 return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */ 42} 43static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev) 44{ 45 return bcma_core_is_enabled(dev->bdev); 46} 47static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev, 48 u32 core_specific_flags) 49{ 50 bcma_core_enable(dev->bdev, core_specific_flags); 51} 52static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev, 53 u32 core_specific_flags) 54{ 55 bcma_core_disable(dev->bdev, core_specific_flags); 56} 57static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset) 58{ 59 return bcma_read16(dev->bdev, offset); 60} 61static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset) 62{ 63 return bcma_read32(dev->bdev, offset); 64} 65static 66void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value) 67{ 68 bcma_write16(dev->bdev, offset, value); 69} 70static 71void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value) 72{ 73 bcma_write32(dev->bdev, offset, value); 74} 75static 76void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer, 77 size_t count, u16 offset, u8 reg_width) 78{ 79 bcma_block_read(dev->bdev, buffer, count, offset, reg_width); 80} 81static 82void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer, 83 size_t count, u16 offset, u8 reg_width) 84{ 85 bcma_block_write(dev->bdev, buffer, count, offset, reg_width); 86} 87 88struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core) 89{ 90 struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL); 91 if (!dev) 92 return NULL; 93 94 dev->bus_type = B43_BUS_BCMA; 95 dev->bdev = core; 96 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; 102 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 115 116 dev->dev = &core->dev; 117 dev->dma_dev = core->dma_dev; 118 dev->irq = core->irq; 119 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; 123 124 dev->chip_id = core->bus->chipinfo.id; 125 dev->chip_rev = core->bus->chipinfo.rev; 126 dev->chip_pkg = core->bus->chipinfo.pkg; 127 128 dev->bus_sprom = &core->bus->sprom; 129 130 dev->core_id = core->id.id; 131 dev->core_rev = core->id.rev; 132 133 return dev; 134} 135#endif /* CONFIG_B43_BCMA */ 136 137/* SSB */ 138#ifdef CONFIG_B43_SSB 139static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev) 140{ 141 return ssb_bus_may_powerdown(dev->sdev->bus); 142} 143static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev, 144 bool dynamic_pctl) 145{ 146 return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl); 147} 148static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev) 149{ 150 return ssb_device_is_enabled(dev->sdev); 151} 152static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev, 153 u32 core_specific_flags) 154{ 155 ssb_device_enable(dev->sdev, core_specific_flags); 156} 157static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev, 158 u32 core_specific_flags) 159{ 160 ssb_device_disable(dev->sdev, core_specific_flags); 161} 162 163static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset) 164{ 165 return ssb_read16(dev->sdev, offset); 166} 167static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset) 168{ 169 return ssb_read32(dev->sdev, offset); 170} 171static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value) 172{ 173 ssb_write16(dev->sdev, offset, value); 174} 175static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value) 176{ 177 ssb_write32(dev->sdev, offset, value); 178} 179static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer, 180 size_t count, u16 offset, u8 reg_width) 181{ 182 ssb_block_read(dev->sdev, buffer, count, offset, reg_width); 183} 184static 185void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer, 186 size_t count, u16 offset, u8 reg_width) 187{ 188 ssb_block_write(dev->sdev, buffer, count, offset, reg_width); 189} 190 191struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev) 192{ 193 struct b43_bus_dev *dev; 194 195 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 196 if (!dev) 197 return NULL; 198 199 dev->bus_type = B43_BUS_SSB; 200 dev->sdev = sdev; 201 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; 207 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; 214 215 dev->dev = sdev->dev; 216 dev->dma_dev = sdev->dma_dev; 217 dev->irq = sdev->irq; 218 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; 222 223 dev->chip_id = sdev->bus->chip_id; 224 dev->chip_rev = sdev->bus->chip_rev; 225 dev->chip_pkg = sdev->bus->chip_package; 226 227 dev->bus_sprom = &sdev->bus->sprom; 228 229 dev->core_id = sdev->id.coreid; 230 dev->core_rev = sdev->id.revision; 231 232 return dev; 233} 234#endif /* CONFIG_B43_SSB */ 235 236void *b43_bus_get_wldev(struct b43_bus_dev *dev) 237{ 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 247 } 248 return NULL; 249} 250 251void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev) 252{ 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 264 } 265} 266