1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 
4   Broadcom B43 wireless driver
5   Bus abstraction layer
6 
7   Copyright (c) 2011 Rafał Miłecki <zajec5@gmail.com>
8 
9 
10 */
11 
12 #ifdef CONFIG_BCM47XX_BCMA
13 #include <asm/mach-bcm47xx/bcm47xx.h>
14 #endif
15 
16 #include "b43.h"
17 #include "bus.h"
18 
19 /* BCMA */
20 #ifdef CONFIG_B43_BCMA
b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev * dev)21 static int b43_bus_bcma_bus_may_powerdown(struct b43_bus_dev *dev)
22 {
23 	return 0; /* bcma_bus_may_powerdown(dev->bdev->bus); */
24 }
b43_bus_bcma_bus_powerup(struct b43_bus_dev * dev,bool dynamic_pctl)25 static int b43_bus_bcma_bus_powerup(struct b43_bus_dev *dev,
26 					  bool dynamic_pctl)
27 {
28 	return 0; /* bcma_bus_powerup(dev->sdev->bus, dynamic_pctl); */
29 }
b43_bus_bcma_device_is_enabled(struct b43_bus_dev * dev)30 static int b43_bus_bcma_device_is_enabled(struct b43_bus_dev *dev)
31 {
32 	return bcma_core_is_enabled(dev->bdev);
33 }
b43_bus_bcma_device_enable(struct b43_bus_dev * dev,u32 core_specific_flags)34 static void b43_bus_bcma_device_enable(struct b43_bus_dev *dev,
35 					     u32 core_specific_flags)
36 {
37 	bcma_core_enable(dev->bdev, core_specific_flags);
38 }
b43_bus_bcma_device_disable(struct b43_bus_dev * dev,u32 core_specific_flags)39 static void b43_bus_bcma_device_disable(struct b43_bus_dev *dev,
40 					      u32 core_specific_flags)
41 {
42 	bcma_core_disable(dev->bdev, core_specific_flags);
43 }
b43_bus_bcma_read16(struct b43_bus_dev * dev,u16 offset)44 static u16 b43_bus_bcma_read16(struct b43_bus_dev *dev, u16 offset)
45 {
46 	return bcma_read16(dev->bdev, offset);
47 }
b43_bus_bcma_read32(struct b43_bus_dev * dev,u16 offset)48 static u32 b43_bus_bcma_read32(struct b43_bus_dev *dev, u16 offset)
49 {
50 	return bcma_read32(dev->bdev, offset);
51 }
52 static
b43_bus_bcma_write16(struct b43_bus_dev * dev,u16 offset,u16 value)53 void b43_bus_bcma_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
54 {
55 	bcma_write16(dev->bdev, offset, value);
56 }
57 static
b43_bus_bcma_write32(struct b43_bus_dev * dev,u16 offset,u32 value)58 void b43_bus_bcma_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
59 {
60 	bcma_write32(dev->bdev, offset, value);
61 }
62 static
b43_bus_bcma_block_read(struct b43_bus_dev * dev,void * buffer,size_t count,u16 offset,u8 reg_width)63 void b43_bus_bcma_block_read(struct b43_bus_dev *dev, void *buffer,
64 			     size_t count, u16 offset, u8 reg_width)
65 {
66 	bcma_block_read(dev->bdev, buffer, count, offset, reg_width);
67 }
68 static
b43_bus_bcma_block_write(struct b43_bus_dev * dev,const void * buffer,size_t count,u16 offset,u8 reg_width)69 void b43_bus_bcma_block_write(struct b43_bus_dev *dev, const void *buffer,
70 			      size_t count, u16 offset, u8 reg_width)
71 {
72 	bcma_block_write(dev->bdev, buffer, count, offset, reg_width);
73 }
74 
b43_bus_dev_bcma_init(struct bcma_device * core)75 struct b43_bus_dev *b43_bus_dev_bcma_init(struct bcma_device *core)
76 {
77 	struct b43_bus_dev *dev = kzalloc(sizeof(*dev), GFP_KERNEL);
78 	if (!dev)
79 		return NULL;
80 
81 	dev->bus_type = B43_BUS_BCMA;
82 	dev->bdev = core;
83 
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;
89 
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
102 
103 	dev->dev = &core->dev;
104 	dev->dma_dev = core->dma_dev;
105 	dev->irq = core->irq;
106 
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;
110 
111 	dev->chip_id = core->bus->chipinfo.id;
112 	dev->chip_rev = core->bus->chipinfo.rev;
113 	dev->chip_pkg = core->bus->chipinfo.pkg;
114 
115 	dev->bus_sprom = &core->bus->sprom;
116 
117 	dev->core_id = core->id.id;
118 	dev->core_rev = core->id.rev;
119 
120 	return dev;
121 }
122 #endif /* CONFIG_B43_BCMA */
123 
124 /* SSB */
125 #ifdef CONFIG_B43_SSB
b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev * dev)126 static int b43_bus_ssb_bus_may_powerdown(struct b43_bus_dev *dev)
127 {
128 	return ssb_bus_may_powerdown(dev->sdev->bus);
129 }
b43_bus_ssb_bus_powerup(struct b43_bus_dev * dev,bool dynamic_pctl)130 static int b43_bus_ssb_bus_powerup(struct b43_bus_dev *dev,
131 					  bool dynamic_pctl)
132 {
133 	return ssb_bus_powerup(dev->sdev->bus, dynamic_pctl);
134 }
b43_bus_ssb_device_is_enabled(struct b43_bus_dev * dev)135 static int b43_bus_ssb_device_is_enabled(struct b43_bus_dev *dev)
136 {
137 	return ssb_device_is_enabled(dev->sdev);
138 }
b43_bus_ssb_device_enable(struct b43_bus_dev * dev,u32 core_specific_flags)139 static void b43_bus_ssb_device_enable(struct b43_bus_dev *dev,
140 					     u32 core_specific_flags)
141 {
142 	ssb_device_enable(dev->sdev, core_specific_flags);
143 }
b43_bus_ssb_device_disable(struct b43_bus_dev * dev,u32 core_specific_flags)144 static void b43_bus_ssb_device_disable(struct b43_bus_dev *dev,
145 					      u32 core_specific_flags)
146 {
147 	ssb_device_disable(dev->sdev, core_specific_flags);
148 }
149 
b43_bus_ssb_read16(struct b43_bus_dev * dev,u16 offset)150 static u16 b43_bus_ssb_read16(struct b43_bus_dev *dev, u16 offset)
151 {
152 	return ssb_read16(dev->sdev, offset);
153 }
b43_bus_ssb_read32(struct b43_bus_dev * dev,u16 offset)154 static u32 b43_bus_ssb_read32(struct b43_bus_dev *dev, u16 offset)
155 {
156 	return ssb_read32(dev->sdev, offset);
157 }
b43_bus_ssb_write16(struct b43_bus_dev * dev,u16 offset,u16 value)158 static void b43_bus_ssb_write16(struct b43_bus_dev *dev, u16 offset, u16 value)
159 {
160 	ssb_write16(dev->sdev, offset, value);
161 }
b43_bus_ssb_write32(struct b43_bus_dev * dev,u16 offset,u32 value)162 static void b43_bus_ssb_write32(struct b43_bus_dev *dev, u16 offset, u32 value)
163 {
164 	ssb_write32(dev->sdev, offset, value);
165 }
b43_bus_ssb_block_read(struct b43_bus_dev * dev,void * buffer,size_t count,u16 offset,u8 reg_width)166 static void b43_bus_ssb_block_read(struct b43_bus_dev *dev, void *buffer,
167 				   size_t count, u16 offset, u8 reg_width)
168 {
169 	ssb_block_read(dev->sdev, buffer, count, offset, reg_width);
170 }
171 static
b43_bus_ssb_block_write(struct b43_bus_dev * dev,const void * buffer,size_t count,u16 offset,u8 reg_width)172 void b43_bus_ssb_block_write(struct b43_bus_dev *dev, const void *buffer,
173 			     size_t count, u16 offset, u8 reg_width)
174 {
175 	ssb_block_write(dev->sdev, buffer, count, offset, reg_width);
176 }
177 
b43_bus_dev_ssb_init(struct ssb_device * sdev)178 struct b43_bus_dev *b43_bus_dev_ssb_init(struct ssb_device *sdev)
179 {
180 	struct b43_bus_dev *dev;
181 
182 	dev = kzalloc(sizeof(*dev), GFP_KERNEL);
183 	if (!dev)
184 		return NULL;
185 
186 	dev->bus_type = B43_BUS_SSB;
187 	dev->sdev = sdev;
188 
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;
194 
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;
201 
202 	dev->dev = sdev->dev;
203 	dev->dma_dev = sdev->dma_dev;
204 	dev->irq = sdev->irq;
205 
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;
209 
210 	dev->chip_id = sdev->bus->chip_id;
211 	dev->chip_rev = sdev->bus->chip_rev;
212 	dev->chip_pkg = sdev->bus->chip_package;
213 
214 	dev->bus_sprom = &sdev->bus->sprom;
215 
216 	dev->core_id = sdev->id.coreid;
217 	dev->core_rev = sdev->id.revision;
218 
219 	return dev;
220 }
221 #endif /* CONFIG_B43_SSB */
222 
b43_bus_get_wldev(struct b43_bus_dev * dev)223 void *b43_bus_get_wldev(struct b43_bus_dev *dev)
224 {
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
234 	}
235 	return NULL;
236 }
237 
b43_bus_set_wldev(struct b43_bus_dev * dev,void * wldev)238 void b43_bus_set_wldev(struct b43_bus_dev *dev, void *wldev)
239 {
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
251 	}
252 }
253