Rafał Miłecki | 482f053 | 2011-05-18 02:06:36 +0200 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | Broadcom B43 wireless driver |
| 4 | Bus abstraction layer |
| 5 | |
Rafał Miłecki | 108f4f3 | 2011-09-03 21:01:02 +0200 | [diff] [blame] | 6 | Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com> |
| 7 | |
Rafał Miłecki | 482f053 | 2011-05-18 02:06:36 +0200 | [diff] [blame] | 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 | #include "b43.h" |
| 26 | #include "bus.h" |
| 27 | |
Rafał Miłecki | 397915c | 2011-07-06 19:03:46 +0200 | [diff] [blame] | 28 | /* BCMA */ |
| 29 | #ifdef CONFIG_B43_BCMA |
| 30 | static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev) |
| 31 | { |
| 32 | return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */ |
| 33 | } |
| 34 | static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev, |
| 35 | bool dynamic_pctl) |
| 36 | { |
| 37 | return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */ |
| 38 | } |
| 39 | static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev) |
| 40 | { |
| 41 | return bcma_core_is_enabled(dev->bdev); |
| 42 | } |
| 43 | static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev, |
| 44 | u32 core_specific_flags) |
| 45 | { |
| 46 | bcma_core_enable(dev->bdev, core_specific_flags); |
| 47 | } |
| 48 | static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev, |
| 49 | u32 core_specific_flags) |
| 50 | { |
| 51 | bcma_core_disable(dev->bdev, core_specific_flags); |
| 52 | } |
| 53 | static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset) |
| 54 | { |
| 55 | return bcma_read16(dev->bdev, offset); |
| 56 | } |
| 57 | static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset) |
| 58 | { |
| 59 | return bcma_read32(dev->bdev, offset); |
| 60 | } |
| 61 | static |
| 62 | void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value) |
| 63 | { |
| 64 | bcma_write16(dev->bdev, offset, value); |
| 65 | } |
| 66 | static |
| 67 | void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value) |
| 68 | { |
| 69 | bcma_write32(dev->bdev, offset, value); |
| 70 | } |
| 71 | static |
| 72 | void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer, |
| 73 | size_t count, u16 offset, u8 reg_width) |
| 74 | { |
| 75 | bcma_block_read(dev->bdev, buffer, count, offset, reg_width); |
| 76 | } |
| 77 | static |
| 78 | void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer, |
| 79 | size_t count, u16 offset, u8 reg_width) |
| 80 | { |
| 81 | bcma_block_write(dev->bdev, buffer, count, offset, reg_width); |
| 82 | } |
| 83 | |
| 84 | struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core) |
| 85 | { |
| 86 | struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 87 | if (!dev) |
| 88 | return NULL; |
| 89 | |
| 90 | dev->bus_type = B43_BUS_BCMA; |
| 91 | dev->bdev = core; |
| 92 | |
| 93 | dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown; |
| 94 | dev->bus_powerup = b43_bus_bcma_bus_powerup; |
| 95 | dev->device_is_enabled = b43_bus_bcma_device_is_enabled; |
| 96 | dev->device_enable = b43_bus_bcma_device_enable; |
| 97 | dev->device_disable = b43_bus_bcma_device_disable; |
| 98 | |
| 99 | dev->read16 = b43_bus_bcma_read16; |
| 100 | dev->read32 = b43_bus_bcma_read32; |
| 101 | dev->write16 = b43_bus_bcma_write16; |
| 102 | dev->write32 = b43_bus_bcma_write32; |
| 103 | dev->block_read = b43_bus_bcma_block_read; |
| 104 | dev->block_write = b43_bus_bcma_block_write; |
| 105 | |
| 106 | dev->dev = &core->dev; |
| 107 | dev->dma_dev = core->dma_dev; |
| 108 | dev->irq = core->irq; |
| 109 | |
| 110 | /* |
| 111 | dev->board_vendor = core->bus->boardinfo.vendor; |
| 112 | dev->board_type = core->bus->boardinfo.type; |
| 113 | dev->board_rev = core->bus->boardinfo.rev; |
| 114 | */ |
| 115 | |
| 116 | dev->chip_id = core->bus->chipinfo.id; |
| 117 | dev->chip_rev = core->bus->chipinfo.rev; |
| 118 | dev->chip_pkg = core->bus->chipinfo.pkg; |
| 119 | |
| 120 | dev->bus_sprom = &core->bus->sprom; |
| 121 | |
| 122 | dev->core_id = core->id.id; |
| 123 | dev->core_rev = core->id.rev; |
| 124 | |
| 125 | return dev; |
| 126 | } |
| 127 | #endif /* CONFIG_B43_BCMA */ |
Rafał Miłecki | 482f053 | 2011-05-18 02:06:36 +0200 | [diff] [blame] | 128 | |
| 129 | /* SSB */ |
Rafał Miłecki | aec7ffd | 2011-06-14 08:18:59 +0200 | [diff] [blame] | 130 | #ifdef CONFIG_B43_SSB |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 131 | static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev) |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 132 | { |
| 133 | return ssb_bus_may_powerdown(dev->sdev->bus); |
| 134 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 135 | static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev, |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 136 | bool dynamic_pctl) |
| 137 | { |
| 138 | return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl); |
| 139 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 140 | static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev) |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 141 | { |
| 142 | return ssb_device_is_enabled(dev->sdev); |
| 143 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 144 | static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev, |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 145 | u32 core_specific_flags) |
| 146 | { |
| 147 | ssb_device_enable(dev->sdev, core_specific_flags); |
| 148 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 149 | static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev, |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 150 | u32 core_specific_flags) |
| 151 | { |
| 152 | ssb_device_disable(dev->sdev, core_specific_flags); |
| 153 | } |
| 154 | |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 155 | static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset) |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 156 | { |
| 157 | return ssb_read16(dev->sdev, offset); |
| 158 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 159 | static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset) |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 160 | { |
| 161 | return ssb_read32(dev->sdev, offset); |
| 162 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 163 | static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value) |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 164 | { |
| 165 | ssb_write16(dev->sdev, offset, value); |
| 166 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 167 | static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value) |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 168 | { |
| 169 | ssb_write32(dev->sdev, offset, value); |
| 170 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 171 | static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer, |
| 172 | size_t count, u16 offset, u8 reg_width) |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 173 | { |
| 174 | ssb_block_read(dev->sdev, buffer, count, offset, reg_width); |
| 175 | } |
Rafał Miłecki | 0901edb | 2011-07-17 01:15:18 +0200 | [diff] [blame] | 176 | static |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 177 | void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer, |
| 178 | size_t count, u16 offset, u8 reg_width) |
| 179 | { |
| 180 | ssb_block_write(dev->sdev, buffer, count, offset, reg_width); |
| 181 | } |
| 182 | |
Rafał Miłecki | 482f053 | 2011-05-18 02:06:36 +0200 | [diff] [blame] | 183 | struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev) |
| 184 | { |
Dan Carpenter | 5b49b35 | 2011-06-09 10:09:34 +0300 | [diff] [blame] | 185 | struct b43_bus_dev *dev; |
| 186 | |
| 187 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 188 | if (!dev) |
| 189 | return NULL; |
Rafał Miłecki | 482f053 | 2011-05-18 02:06:36 +0200 | [diff] [blame] | 190 | |
| 191 | dev->bus_type = B43_BUS_SSB; |
| 192 | dev->sdev = sdev; |
| 193 | |
Rafał Miłecki | 24ca39d | 2011-05-18 02:06:43 +0200 | [diff] [blame] | 194 | dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown; |
| 195 | dev->bus_powerup = b43_bus_ssb_bus_powerup; |
| 196 | dev->device_is_enabled = b43_bus_ssb_device_is_enabled; |
| 197 | dev->device_enable = b43_bus_ssb_device_enable; |
| 198 | dev->device_disable = b43_bus_ssb_device_disable; |
| 199 | |
Rafał Miłecki | c0b4c00 | 2011-05-18 02:06:37 +0200 | [diff] [blame] | 200 | dev->read16 = b43_bus_ssb_read16; |
| 201 | dev->read32 = b43_bus_ssb_read32; |
| 202 | dev->write16 = b43_bus_ssb_write16; |
| 203 | dev->write32 = b43_bus_ssb_write32; |
| 204 | dev->block_read = b43_bus_ssb_block_read; |
| 205 | dev->block_write = b43_bus_ssb_block_write; |
| 206 | |
Rafał Miłecki | a18c715 | 2011-05-18 02:06:40 +0200 | [diff] [blame] | 207 | dev->dev = sdev->dev; |
| 208 | dev->dma_dev = sdev->dma_dev; |
| 209 | dev->irq = sdev->irq; |
| 210 | |
Rafał Miłecki | 79d2232 | 2011-05-18 02:06:42 +0200 | [diff] [blame] | 211 | dev->board_vendor = sdev->bus->boardinfo.vendor; |
| 212 | dev->board_type = sdev->bus->boardinfo.type; |
| 213 | dev->board_rev = sdev->bus->boardinfo.rev; |
| 214 | |
Rafał Miłecki | c244e08 | 2011-05-18 02:06:41 +0200 | [diff] [blame] | 215 | dev->chip_id = sdev->bus->chip_id; |
| 216 | dev->chip_rev = sdev->bus->chip_rev; |
| 217 | dev->chip_pkg = sdev->bus->chip_package; |
| 218 | |
Rafał Miłecki | 0581483 | 2011-05-18 02:06:39 +0200 | [diff] [blame] | 219 | dev->bus_sprom = &sdev->bus->sprom; |
| 220 | |
Rafał Miłecki | 21d889d | 2011-05-18 02:06:38 +0200 | [diff] [blame] | 221 | dev->core_id = sdev->id.coreid; |
| 222 | dev->core_rev = sdev->id.revision; |
| 223 | |
Rafał Miłecki | 482f053 | 2011-05-18 02:06:36 +0200 | [diff] [blame] | 224 | return dev; |
| 225 | } |
Rafał Miłecki | aec7ffd | 2011-06-14 08:18:59 +0200 | [diff] [blame] | 226 | #endif /* CONFIG_B43_SSB */ |
Rafał Miłecki | 74abacb | 2011-07-06 15:45:28 +0200 | [diff] [blame] | 227 | |
| 228 | void *b43_bus_get_wldev(struct b43_bus_dev *dev) |
| 229 | { |
| 230 | switch (dev->bus_type) { |
| 231 | #ifdef CONFIG_B43_BCMA |
| 232 | case B43_BUS_BCMA: |
| 233 | return bcma_get_drvdata(dev->bdev); |
| 234 | #endif |
| 235 | #ifdef CONFIG_B43_SSB |
| 236 | case B43_BUS_SSB: |
| 237 | return ssb_get_drvdata(dev->sdev); |
| 238 | #endif |
| 239 | } |
| 240 | return NULL; |
| 241 | } |
| 242 | |
| 243 | void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev) |
| 244 | { |
| 245 | switch (dev->bus_type) { |
| 246 | #ifdef CONFIG_B43_BCMA |
| 247 | case B43_BUS_BCMA: |
| 248 | bcma_set_drvdata(dev->bdev, wldev); |
Rafał Miłecki | f76f424 | 2011-07-22 13:11:04 +0200 | [diff] [blame] | 249 | break; |
Rafał Miłecki | 74abacb | 2011-07-06 15:45:28 +0200 | [diff] [blame] | 250 | #endif |
| 251 | #ifdef CONFIG_B43_SSB |
| 252 | case B43_BUS_SSB: |
| 253 | ssb_set_drvdata(dev->sdev, wldev); |
Rafał Miłecki | f76f424 | 2011-07-22 13:11:04 +0200 | [diff] [blame] | 254 | break; |
Rafał Miłecki | 74abacb | 2011-07-06 15:45:28 +0200 | [diff] [blame] | 255 | #endif |
| 256 | } |
| 257 | } |