bus.c 6.9 KB
Newer Older
1 2 3 4 5
/*

  Broadcom B43 wireless driver
  Bus abstraction layer

6 7
  Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
  This program is free software; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; see the file COPYING.  If not, write to
  the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor,
  Boston, MA 02110-1301, USA.

*/

#include "b43.h"
#include "bus.h"

R
Rafał Miłecki 已提交
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
/* BCMA */
#ifdef CONFIG_B43_BCMA
static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
{
	return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
}
static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
					  bool dynamic_pctl)
{
	return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
}
static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
{
	return bcma_core_is_enabled(dev->bdev);
}
static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
					     u32 core_specific_flags)
{
	bcma_core_enable(dev->bdev, core_specific_flags);
}
static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
					      u32 core_specific_flags)
{
	bcma_core_disable(dev->bdev, core_specific_flags);
}
static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
{
	return bcma_read16(dev->bdev, offset);
}
static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
{
	return bcma_read32(dev->bdev, offset);
}
static
void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
{
	bcma_write16(dev->bdev, offset, value);
}
static
void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
{
	bcma_write32(dev->bdev, offset, value);
}
static
void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
			     size_t count, u16 offset, u8 reg_width)
{
	bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
}
static
void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
			      size_t count, u16 offset, u8 reg_width)
{
	bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
}

struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
{
	struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (!dev)
		return NULL;

	dev->bus_type = B43_BUS_BCMA;
	dev->bdev = core;

	dev->bus_may_powerdown = b43_bus_bcma_bus_may_powerdown;
	dev->bus_powerup = b43_bus_bcma_bus_powerup;
	dev->device_is_enabled = b43_bus_bcma_device_is_enabled;
	dev->device_enable = b43_bus_bcma_device_enable;
	dev->device_disable = b43_bus_bcma_device_disable;

	dev->read16 = b43_bus_bcma_read16;
	dev->read32 = b43_bus_bcma_read32;
	dev->write16 = b43_bus_bcma_write16;
	dev->write32 = b43_bus_bcma_write32;
	dev->block_read = b43_bus_bcma_block_read;
	dev->block_write = b43_bus_bcma_block_write;

	dev->dev = &core->dev;
	dev->dma_dev = core->dma_dev;
	dev->irq = core->irq;

	/*
	dev->board_vendor = core->bus->boardinfo.vendor;
	dev->board_type = core->bus->boardinfo.type;
	dev->board_rev = core->bus->boardinfo.rev;
	*/

	dev->chip_id = core->bus->chipinfo.id;
	dev->chip_rev = core->bus->chipinfo.rev;
	dev->chip_pkg = core->bus->chipinfo.pkg;

	dev->bus_sprom = &core->bus->sprom;

	dev->core_id = core->id.id;
	dev->core_rev = core->id.rev;

	return dev;
}
#endif /* CONFIG_B43_BCMA */
128 129

/* SSB */
130
#ifdef CONFIG_B43_SSB
131
static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
132 133 134
{
	return ssb_bus_may_powerdown(dev->sdev->bus);
}
135
static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
136 137 138 139
					  bool dynamic_pctl)
{
	return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
}
140
static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
141 142 143
{
	return ssb_device_is_enabled(dev->sdev);
}
144
static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
145 146 147 148
					     u32 core_specific_flags)
{
	ssb_device_enable(dev->sdev, core_specific_flags);
}
149
static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
150 151 152 153 154
					      u32 core_specific_flags)
{
	ssb_device_disable(dev->sdev, core_specific_flags);
}

155
static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
156 157 158
{
	return ssb_read16(dev->sdev, offset);
}
159
static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
160 161 162
{
	return ssb_read32(dev->sdev, offset);
}
163
static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
164 165 166
{
	ssb_write16(dev->sdev, offset, value);
}
167
static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
168 169 170
{
	ssb_write32(dev->sdev, offset, value);
}
171 172
static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
				   size_t count, u16 offset, u8 reg_width)
173 174 175
{
	ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
}
176
static
177 178 179 180 181 182
void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
			     size_t count, u16 offset, u8 reg_width)
{
	ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
}

183 184
struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
{
185 186 187 188 189
	struct b43_bus_dev *dev;

	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
	if (!dev)
		return NULL;
190 191 192 193

	dev->bus_type = B43_BUS_SSB;
	dev->sdev = sdev;

194 195 196 197 198 199
	dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
	dev->bus_powerup = b43_bus_ssb_bus_powerup;
	dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
	dev->device_enable = b43_bus_ssb_device_enable;
	dev->device_disable = b43_bus_ssb_device_disable;

200 201 202 203 204 205 206
	dev->read16 = b43_bus_ssb_read16;
	dev->read32 = b43_bus_ssb_read32;
	dev->write16 = b43_bus_ssb_write16;
	dev->write32 = b43_bus_ssb_write32;
	dev->block_read = b43_bus_ssb_block_read;
	dev->block_write = b43_bus_ssb_block_write;

207 208 209 210
	dev->dev = sdev->dev;
	dev->dma_dev = sdev->dma_dev;
	dev->irq = sdev->irq;

R
Rafał Miłecki 已提交
211 212 213 214
	dev->board_vendor = sdev->bus->boardinfo.vendor;
	dev->board_type = sdev->bus->boardinfo.type;
	dev->board_rev = sdev->bus->boardinfo.rev;

R
Rafał Miłecki 已提交
215 216 217 218
	dev->chip_id = sdev->bus->chip_id;
	dev->chip_rev = sdev->bus->chip_rev;
	dev->chip_pkg = sdev->bus->chip_package;

R
Rafał Miłecki 已提交
219 220
	dev->bus_sprom = &sdev->bus->sprom;

221 222 223
	dev->core_id = sdev->id.coreid;
	dev->core_rev = sdev->id.revision;

224 225
	return dev;
}
226
#endif /* CONFIG_B43_SSB */
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248

void *b43_bus_get_wldev(struct b43_bus_dev *dev)
{
	switch (dev->bus_type) {
#ifdef CONFIG_B43_BCMA
	case B43_BUS_BCMA:
		return bcma_get_drvdata(dev->bdev);
#endif
#ifdef CONFIG_B43_SSB
	case B43_BUS_SSB:
		return ssb_get_drvdata(dev->sdev);
#endif
	}
	return NULL;
}

void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
{
	switch (dev->bus_type) {
#ifdef CONFIG_B43_BCMA
	case B43_BUS_BCMA:
		bcma_set_drvdata(dev->bdev, wldev);
249
		break;
250 251 252 253
#endif
#ifdef CONFIG_B43_SSB
	case B43_BUS_SSB:
		ssb_set_drvdata(dev->sdev, wldev);
254
		break;
255 256 257
#endif
	}
}