• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "b43.h"
26 #include "bus.h"
27 
28 /* BCMA */
29 #ifdef CONFIG_B43_BCMA
b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev * dev)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 }
b43_bus_bcma_bus_powerup(struct b43_bus_dev * dev,bool dynamic_pctl)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 }
b43_bus_bcma_device_is_enabled(struct b43_bus_dev * dev)39 static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
40 {
41 	return bcma_core_is_enabled(dev->bdev);
42 }
b43_bus_bcma_device_enable(struct b43_bus_dev * dev,u32 core_specific_flags)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 }
b43_bus_bcma_device_disable(struct b43_bus_dev * dev,u32 core_specific_flags)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 }
b43_bus_bcma_read16(struct b43_bus_dev * dev,u16 offset)53 static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
54 {
55 	return bcma_read16(dev->bdev, offset);
56 }
b43_bus_bcma_read32(struct b43_bus_dev * dev,u16 offset)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
b43_bus_bcma_write16(struct b43_bus_dev * dev,u16 offset,u16 value)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
b43_bus_bcma_write32(struct b43_bus_dev * dev,u16 offset,u32 value)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
b43_bus_bcma_block_read(struct b43_bus_dev * dev,void * buffer,size_t count,u16 offset,u8 reg_width)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
b43_bus_bcma_block_write(struct b43_bus_dev * dev,const void * buffer,size_t count,u16 offset,u8 reg_width)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 
b43_bus_dev_bcma_init(struct bcma_device * core)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 	dev->board_vendor = core->bus->boardinfo.vendor;
111 	dev->board_type = core->bus->boardinfo.type;
112 	dev->board_rev = core->bus->sprom.board_rev;
113 
114 	dev->chip_id = core->bus->chipinfo.id;
115 	dev->chip_rev = core->bus->chipinfo.rev;
116 	dev->chip_pkg = core->bus->chipinfo.pkg;
117 
118 	dev->bus_sprom = &core->bus->sprom;
119 
120 	dev->core_id = core->id.id;
121 	dev->core_rev = core->id.rev;
122 
123 	return dev;
124 }
125 #endif /* CONFIG_B43_BCMA */
126 
127 /* SSB */
128 #ifdef CONFIG_B43_SSB
b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev * dev)129 static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
130 {
131 	return ssb_bus_may_powerdown(dev->sdev->bus);
132 }
b43_bus_ssb_bus_powerup(struct b43_bus_dev * dev,bool dynamic_pctl)133 static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
134 					  bool dynamic_pctl)
135 {
136 	return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
137 }
b43_bus_ssb_device_is_enabled(struct b43_bus_dev * dev)138 static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
139 {
140 	return ssb_device_is_enabled(dev->sdev);
141 }
b43_bus_ssb_device_enable(struct b43_bus_dev * dev,u32 core_specific_flags)142 static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
143 					     u32 core_specific_flags)
144 {
145 	ssb_device_enable(dev->sdev, core_specific_flags);
146 }
b43_bus_ssb_device_disable(struct b43_bus_dev * dev,u32 core_specific_flags)147 static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
148 					      u32 core_specific_flags)
149 {
150 	ssb_device_disable(dev->sdev, core_specific_flags);
151 }
152 
b43_bus_ssb_read16(struct b43_bus_dev * dev,u16 offset)153 static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
154 {
155 	return ssb_read16(dev->sdev, offset);
156 }
b43_bus_ssb_read32(struct b43_bus_dev * dev,u16 offset)157 static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
158 {
159 	return ssb_read32(dev->sdev, offset);
160 }
b43_bus_ssb_write16(struct b43_bus_dev * dev,u16 offset,u16 value)161 static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
162 {
163 	ssb_write16(dev->sdev, offset, value);
164 }
b43_bus_ssb_write32(struct b43_bus_dev * dev,u16 offset,u32 value)165 static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
166 {
167 	ssb_write32(dev->sdev, offset, value);
168 }
b43_bus_ssb_block_read(struct b43_bus_dev * dev,void * buffer,size_t count,u16 offset,u8 reg_width)169 static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
170 				   size_t count, u16 offset, u8 reg_width)
171 {
172 	ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
173 }
174 static
b43_bus_ssb_block_write(struct b43_bus_dev * dev,const void * buffer,size_t count,u16 offset,u8 reg_width)175 void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
176 			     size_t count, u16 offset, u8 reg_width)
177 {
178 	ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
179 }
180 
b43_bus_dev_ssb_init(struct ssb_device * sdev)181 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
182 {
183 	struct b43_bus_dev *dev;
184 
185 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
186 	if (!dev)
187 		return NULL;
188 
189 	dev->bus_type = B43_BUS_SSB;
190 	dev->sdev = sdev;
191 
192 	dev->bus_may_powerdown = b43_bus_ssb_bus_may_powerdown;
193 	dev->bus_powerup = b43_bus_ssb_bus_powerup;
194 	dev->device_is_enabled = b43_bus_ssb_device_is_enabled;
195 	dev->device_enable = b43_bus_ssb_device_enable;
196 	dev->device_disable = b43_bus_ssb_device_disable;
197 
198 	dev->read16 = b43_bus_ssb_read16;
199 	dev->read32 = b43_bus_ssb_read32;
200 	dev->write16 = b43_bus_ssb_write16;
201 	dev->write32 = b43_bus_ssb_write32;
202 	dev->block_read = b43_bus_ssb_block_read;
203 	dev->block_write = b43_bus_ssb_block_write;
204 
205 	dev->dev = sdev->dev;
206 	dev->dma_dev = sdev->dma_dev;
207 	dev->irq = sdev->irq;
208 
209 	dev->board_vendor = sdev->bus->boardinfo.vendor;
210 	dev->board_type = sdev->bus->boardinfo.type;
211 	dev->board_rev = sdev->bus->sprom.board_rev;
212 
213 	dev->chip_id = sdev->bus->chip_id;
214 	dev->chip_rev = sdev->bus->chip_rev;
215 	dev->chip_pkg = sdev->bus->chip_package;
216 
217 	dev->bus_sprom = &sdev->bus->sprom;
218 
219 	dev->core_id = sdev->id.coreid;
220 	dev->core_rev = sdev->id.revision;
221 
222 	return dev;
223 }
224 #endif /* CONFIG_B43_SSB */
225 
b43_bus_get_wldev(struct b43_bus_dev * dev)226 void *b43_bus_get_wldev(struct b43_bus_dev *dev)
227 {
228 	switch (dev->bus_type) {
229 #ifdef CONFIG_B43_BCMA
230 	case B43_BUS_BCMA:
231 		return bcma_get_drvdata(dev->bdev);
232 #endif
233 #ifdef CONFIG_B43_SSB
234 	case B43_BUS_SSB:
235 		return ssb_get_drvdata(dev->sdev);
236 #endif
237 	}
238 	return NULL;
239 }
240 
b43_bus_set_wldev(struct b43_bus_dev * dev,void * wldev)241 void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
242 {
243 	switch (dev->bus_type) {
244 #ifdef CONFIG_B43_BCMA
245 	case B43_BUS_BCMA:
246 		bcma_set_drvdata(dev->bdev, wldev);
247 		break;
248 #endif
249 #ifdef CONFIG_B43_SSB
250 	case B43_BUS_SSB:
251 		ssb_set_drvdata(dev->sdev, wldev);
252 		break;
253 #endif
254 	}
255 }
256