xref: /linux/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c (revision 323bbfcf1ef8836d0d2ad9e2c1f1c684f0e3b5b3)
1 // SPDX-License-Identifier: ISC
2 /*
3  * Copyright (c) 2010 Broadcom Corporation
4  */
5 
6 #include <linux/kernel.h>
7 #include <linux/string.h>
8 #include <linux/netdevice.h>
9 #include <linux/module.h>
10 #include <linux/firmware.h>
11 #include <brcmu_wifi.h>
12 #include <brcmu_utils.h>
13 #include "core.h"
14 #include "bus.h"
15 #include "debug.h"
16 #include "fwil.h"
17 #include "fwil_types.h"
18 #include "tracepoint.h"
19 #include "common.h"
20 #include "of.h"
21 #include "firmware.h"
22 #include "chip.h"
23 
24 MODULE_AUTHOR("Broadcom Corporation");
25 MODULE_DESCRIPTION("Broadcom 802.11 wireless LAN fullmac driver.");
26 MODULE_LICENSE("Dual BSD/GPL");
27 
28 #define BRCMF_DEFAULT_SCAN_CHANNEL_TIME	40
29 #define BRCMF_DEFAULT_SCAN_UNASSOC_TIME	40
30 
31 /* default boost value for RSSI_DELTA in preferred join selection */
32 #define BRCMF_JOIN_PREF_RSSI_BOOST	8
33 
34 #define BRCMF_DEFAULT_TXGLOM_SIZE	32  /* max tx frames in glom chain */
35 
36 static int brcmf_sdiod_txglomsz = BRCMF_DEFAULT_TXGLOM_SIZE;
37 module_param_named(txglomsz, brcmf_sdiod_txglomsz, int, 0);
38 MODULE_PARM_DESC(txglomsz, "Maximum tx packet chain size [SDIO]");
39 
40 /* Debug level configuration. See debug.h for bits, sysfs modifiable */
41 int brcmf_msg_level;
42 module_param_named(debug, brcmf_msg_level, int, 0600);
43 MODULE_PARM_DESC(debug, "Level of debug output");
44 
45 static int brcmf_p2p_enable;
46 module_param_named(p2pon, brcmf_p2p_enable, int, 0);
47 MODULE_PARM_DESC(p2pon, "Enable legacy p2p management functionality");
48 
49 static int brcmf_feature_disable;
50 module_param_named(feature_disable, brcmf_feature_disable, int, 0);
51 MODULE_PARM_DESC(feature_disable, "Disable features");
52 
53 static char brcmf_firmware_path[BRCMF_FW_ALTPATH_LEN];
54 module_param_string(alternative_fw_path, brcmf_firmware_path,
55 		    BRCMF_FW_ALTPATH_LEN, 0400);
56 MODULE_PARM_DESC(alternative_fw_path, "Alternative firmware path");
57 
58 static int brcmf_fcmode;
59 module_param_named(fcmode, brcmf_fcmode, int, 0);
60 MODULE_PARM_DESC(fcmode, "Mode of firmware signalled flow control");
61 
62 static int brcmf_roamoff;
63 module_param_named(roamoff, brcmf_roamoff, int, 0400);
64 MODULE_PARM_DESC(roamoff, "Do not use internal roaming engine");
65 
66 static int brcmf_iapp_enable;
67 module_param_named(iapp, brcmf_iapp_enable, int, 0);
68 MODULE_PARM_DESC(iapp, "Enable partial support for the obsoleted Inter-Access Point Protocol");
69 
70 #ifdef DEBUG
71 /* always succeed brcmf_bus_started() */
72 static int brcmf_ignore_probe_fail;
73 module_param_named(ignore_probe_fail, brcmf_ignore_probe_fail, int, 0);
74 MODULE_PARM_DESC(ignore_probe_fail, "always succeed probe for debugging");
75 #endif
76 
77 static struct brcmfmac_platform_data *brcmfmac_pdata;
78 struct brcmf_mp_global_t brcmf_mp_global;
79 
brcmf_c_set_joinpref_default(struct brcmf_if * ifp)80 void brcmf_c_set_joinpref_default(struct brcmf_if *ifp)
81 {
82 	struct brcmf_pub *drvr = ifp->drvr;
83 	struct brcmf_join_pref_params join_pref_params[2];
84 	int err;
85 
86 	/* Setup join_pref to select target by RSSI (boost on 5GHz) */
87 	join_pref_params[0].type = BRCMF_JOIN_PREF_RSSI_DELTA;
88 	join_pref_params[0].len = 2;
89 	join_pref_params[0].rssi_gain = BRCMF_JOIN_PREF_RSSI_BOOST;
90 	join_pref_params[0].band = WLC_BAND_5G;
91 
92 	join_pref_params[1].type = BRCMF_JOIN_PREF_RSSI;
93 	join_pref_params[1].len = 2;
94 	join_pref_params[1].rssi_gain = 0;
95 	join_pref_params[1].band = 0;
96 	err = brcmf_fil_iovar_data_set(ifp, "join_pref", join_pref_params,
97 				       sizeof(join_pref_params));
98 	if (err)
99 		bphy_err(drvr, "Set join_pref error (%d)\n", err);
100 }
101 
brcmf_c_download(struct brcmf_if * ifp,u16 flag,struct brcmf_dload_data_le * dload_buf,u32 len,const char * var)102 static int brcmf_c_download(struct brcmf_if *ifp, u16 flag,
103 			    struct brcmf_dload_data_le *dload_buf,
104 			    u32 len, const char *var)
105 {
106 	s32 err;
107 
108 	flag |= (DLOAD_HANDLER_VER << DLOAD_FLAG_VER_SHIFT);
109 	dload_buf->flag = cpu_to_le16(flag);
110 	dload_buf->dload_type = cpu_to_le16(DL_TYPE_CLM);
111 	dload_buf->len = cpu_to_le32(len);
112 	dload_buf->crc = cpu_to_le32(0);
113 
114 	err = brcmf_fil_iovar_data_set(ifp, var, dload_buf,
115 				       struct_size(dload_buf, data, len));
116 
117 	return err;
118 }
119 
brcmf_c_download_blob(struct brcmf_if * ifp,const void * data,size_t size,const char * loadvar,const char * statvar)120 static int brcmf_c_download_blob(struct brcmf_if *ifp,
121 				 const void *data, size_t size,
122 				 const char *loadvar, const char *statvar)
123 {
124 	struct brcmf_pub *drvr = ifp->drvr;
125 	struct brcmf_dload_data_le *chunk_buf;
126 	u32 chunk_len;
127 	u32 datalen;
128 	u32 cumulative_len;
129 	u16 dl_flag = DL_BEGIN;
130 	u32 status;
131 	s32 err;
132 
133 	brcmf_dbg(TRACE, "Enter\n");
134 
135 	chunk_buf = kzalloc_flex(*chunk_buf, data, MAX_CHUNK_LEN);
136 	if (!chunk_buf) {
137 		err = -ENOMEM;
138 		return -ENOMEM;
139 	}
140 
141 	datalen = size;
142 	cumulative_len = 0;
143 	do {
144 		if (datalen > MAX_CHUNK_LEN) {
145 			chunk_len = MAX_CHUNK_LEN;
146 		} else {
147 			chunk_len = datalen;
148 			dl_flag |= DL_END;
149 		}
150 		memcpy(chunk_buf->data, data + cumulative_len, chunk_len);
151 
152 		err = brcmf_c_download(ifp, dl_flag, chunk_buf, chunk_len,
153 				       loadvar);
154 
155 		dl_flag &= ~DL_BEGIN;
156 
157 		cumulative_len += chunk_len;
158 		datalen -= chunk_len;
159 	} while ((datalen > 0) && (err == 0));
160 
161 	if (err) {
162 		bphy_err(drvr, "%s (%zu byte file) failed (%d)\n",
163 			 loadvar, size, err);
164 		/* Retrieve status and print */
165 		err = brcmf_fil_iovar_int_get(ifp, statvar, &status);
166 		if (err)
167 			bphy_err(drvr, "get %s failed (%d)\n", statvar, err);
168 		else
169 			brcmf_dbg(INFO, "%s=%d\n", statvar, status);
170 		err = -EIO;
171 	}
172 
173 	kfree(chunk_buf);
174 	return err;
175 }
176 
brcmf_c_process_clm_blob(struct brcmf_if * ifp)177 static int brcmf_c_process_clm_blob(struct brcmf_if *ifp)
178 {
179 	struct brcmf_pub *drvr = ifp->drvr;
180 	struct brcmf_bus *bus = drvr->bus_if;
181 	const struct firmware *fw = NULL;
182 	s32 err;
183 
184 	brcmf_dbg(TRACE, "Enter\n");
185 
186 	err = brcmf_bus_get_blob(bus, &fw, BRCMF_BLOB_CLM);
187 	if (err || !fw) {
188 		brcmf_info("no clm_blob available (err=%d), device may have limited channels available\n",
189 			   err);
190 		return 0;
191 	}
192 
193 	err = brcmf_c_download_blob(ifp, fw->data, fw->size,
194 				    "clmload", "clmload_status");
195 
196 	release_firmware(fw);
197 	return err;
198 }
199 
brcmf_c_process_txcap_blob(struct brcmf_if * ifp)200 static int brcmf_c_process_txcap_blob(struct brcmf_if *ifp)
201 {
202 	struct brcmf_pub *drvr = ifp->drvr;
203 	struct brcmf_bus *bus = drvr->bus_if;
204 	const struct firmware *fw = NULL;
205 	s32 err;
206 
207 	brcmf_dbg(TRACE, "Enter\n");
208 
209 	err = brcmf_bus_get_blob(bus, &fw, BRCMF_BLOB_TXCAP);
210 	if (err || !fw) {
211 		brcmf_info("no txcap_blob available (err=%d)\n", err);
212 		return 0;
213 	}
214 
215 	brcmf_info("TxCap blob found, loading\n");
216 	err = brcmf_c_download_blob(ifp, fw->data, fw->size,
217 				    "txcapload", "txcapload_status");
218 
219 	release_firmware(fw);
220 	return err;
221 }
222 
brcmf_c_set_cur_etheraddr(struct brcmf_if * ifp,const u8 * addr)223 int brcmf_c_set_cur_etheraddr(struct brcmf_if *ifp, const u8 *addr)
224 {
225 	s32 err;
226 
227 	err = brcmf_fil_iovar_data_set(ifp, "cur_etheraddr", addr, ETH_ALEN);
228 	if (err < 0)
229 		bphy_err(ifp->drvr, "Setting cur_etheraddr failed, %d\n", err);
230 
231 	return err;
232 }
233 
234 /* On some boards there is no eeprom to hold the nvram, in this case instead
235  * a board specific nvram is loaded from /lib/firmware. On most boards the
236  * macaddr setting in the /lib/firmware nvram file is ignored because the
237  * wifibt chip has a unique MAC programmed into the chip itself.
238  * But in some cases the actual MAC from the /lib/firmware nvram file gets
239  * used, leading to MAC conflicts.
240  * The MAC addresses in the troublesome nvram files seem to all come from
241  * the same nvram file template, so we only need to check for 1 known
242  * address to detect this.
243  */
244 static const u8 brcmf_default_mac_address[ETH_ALEN] = {
245 	0x00, 0x90, 0x4c, 0xc5, 0x12, 0x38
246 };
247 
brcmf_c_process_cal_blob(struct brcmf_if * ifp)248 static int brcmf_c_process_cal_blob(struct brcmf_if *ifp)
249 {
250 	struct brcmf_pub *drvr = ifp->drvr;
251 	struct brcmf_mp_device *settings = drvr->settings;
252 	s32 err;
253 
254 	brcmf_dbg(TRACE, "Enter\n");
255 
256 	if (!settings->cal_blob || !settings->cal_size)
257 		return 0;
258 
259 	brcmf_info("Calibration blob provided by platform, loading\n");
260 	err = brcmf_c_download_blob(ifp, settings->cal_blob, settings->cal_size,
261 				    "calload", "calload_status");
262 	return err;
263 }
264 
brcmf_c_preinit_dcmds(struct brcmf_if * ifp)265 int brcmf_c_preinit_dcmds(struct brcmf_if *ifp)
266 {
267 	struct brcmf_pub *drvr = ifp->drvr;
268 	struct brcmf_fweh_info *fweh = drvr->fweh;
269 	u8 buf[BRCMF_DCMD_SMLEN];
270 	struct brcmf_bus *bus;
271 	struct brcmf_rev_info_le revinfo;
272 	struct brcmf_rev_info *ri;
273 	char *clmver;
274 	char *ptr;
275 	s32 err;
276 
277 	if (is_valid_ether_addr(ifp->mac_addr)) {
278 		/* set mac address */
279 		err = brcmf_c_set_cur_etheraddr(ifp, ifp->mac_addr);
280 		if (err < 0)
281 			goto done;
282 	} else {
283 		/* retrieve mac address */
284 		err = brcmf_fil_iovar_data_get(ifp, "cur_etheraddr", ifp->mac_addr,
285 					       sizeof(ifp->mac_addr));
286 		if (err < 0) {
287 			bphy_err(drvr, "Retrieving cur_etheraddr failed, %d\n", err);
288 			goto done;
289 		}
290 
291 		if (ether_addr_equal_unaligned(ifp->mac_addr, brcmf_default_mac_address)) {
292 			bphy_err(drvr, "Default MAC is used, replacing with random MAC to avoid conflicts\n");
293 			eth_random_addr(ifp->mac_addr);
294 			ifp->ndev->addr_assign_type = NET_ADDR_RANDOM;
295 			err = brcmf_c_set_cur_etheraddr(ifp, ifp->mac_addr);
296 			if (err < 0)
297 				goto done;
298 		}
299 	}
300 
301 	memcpy(ifp->drvr->mac, ifp->mac_addr, sizeof(ifp->drvr->mac));
302 	memcpy(ifp->drvr->wiphy->perm_addr, ifp->drvr->mac, ETH_ALEN);
303 
304 	bus = ifp->drvr->bus_if;
305 	ri = &ifp->drvr->revinfo;
306 
307 	err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_REVINFO,
308 				     &revinfo, sizeof(revinfo));
309 	if (err < 0) {
310 		bphy_err(drvr, "retrieving revision info failed, %d\n", err);
311 		strscpy(ri->chipname, "UNKNOWN", sizeof(ri->chipname));
312 	} else {
313 		ri->vendorid = le32_to_cpu(revinfo.vendorid);
314 		ri->deviceid = le32_to_cpu(revinfo.deviceid);
315 		ri->radiorev = le32_to_cpu(revinfo.radiorev);
316 		ri->corerev = le32_to_cpu(revinfo.corerev);
317 		ri->boardid = le32_to_cpu(revinfo.boardid);
318 		ri->boardvendor = le32_to_cpu(revinfo.boardvendor);
319 		ri->boardrev = le32_to_cpu(revinfo.boardrev);
320 		ri->driverrev = le32_to_cpu(revinfo.driverrev);
321 		ri->ucoderev = le32_to_cpu(revinfo.ucoderev);
322 		ri->bus = le32_to_cpu(revinfo.bus);
323 		ri->phytype = le32_to_cpu(revinfo.phytype);
324 		ri->phyrev = le32_to_cpu(revinfo.phyrev);
325 		ri->anarev = le32_to_cpu(revinfo.anarev);
326 		ri->chippkg = le32_to_cpu(revinfo.chippkg);
327 		ri->nvramrev = le32_to_cpu(revinfo.nvramrev);
328 
329 		/* use revinfo if not known yet */
330 		if (!bus->chip) {
331 			bus->chip = le32_to_cpu(revinfo.chipnum);
332 			bus->chiprev = le32_to_cpu(revinfo.chiprev);
333 		}
334 	}
335 	ri->result = err;
336 
337 	if (bus->chip)
338 		brcmf_chip_name(bus->chip, bus->chiprev,
339 				ri->chipname, sizeof(ri->chipname));
340 
341 	/* Do any CLM downloading */
342 	err = brcmf_c_process_clm_blob(ifp);
343 	if (err < 0) {
344 		bphy_err(drvr, "download CLM blob file failed, %d\n", err);
345 		goto done;
346 	}
347 
348 	/* Do TxCap downloading, if needed */
349 	err = brcmf_c_process_txcap_blob(ifp);
350 	if (err < 0) {
351 		bphy_err(drvr, "download TxCap blob file failed, %d\n", err);
352 		goto done;
353 	}
354 
355 	/* Download external calibration blob, if available */
356 	err = brcmf_c_process_cal_blob(ifp);
357 	if (err < 0) {
358 		bphy_err(drvr, "download calibration blob file failed, %d\n", err);
359 		goto done;
360 	}
361 
362 	/* query for 'ver' to get version info from firmware */
363 	memset(buf, 0, sizeof(buf));
364 	err = brcmf_fil_iovar_data_get(ifp, "ver", buf, sizeof(buf));
365 	if (err < 0) {
366 		bphy_err(drvr, "Retrieving version information failed, %d\n",
367 			 err);
368 		goto done;
369 	}
370 	buf[sizeof(buf) - 1] = '\0';
371 	ptr = (char *)buf;
372 	strsep(&ptr, "\n");
373 
374 	/* Print fw version info */
375 	brcmf_info("Firmware: %s %s\n", ri->chipname, buf);
376 
377 	/* locate firmware version number for ethtool */
378 	ptr = strrchr(buf, ' ');
379 	if (!ptr) {
380 		bphy_err(drvr, "Retrieving version number failed");
381 		goto done;
382 	}
383 	strscpy(ifp->drvr->fwver, ptr + 1, sizeof(ifp->drvr->fwver));
384 
385 	/* Query for 'clmver' to get CLM version info from firmware */
386 	memset(buf, 0, sizeof(buf));
387 	err = brcmf_fil_iovar_data_get(ifp, "clmver", buf, sizeof(buf));
388 	if (err) {
389 		brcmf_dbg(TRACE, "retrieving clmver failed, %d\n", err);
390 	} else {
391 		buf[sizeof(buf) - 1] = '\0';
392 		clmver = (char *)buf;
393 
394 		/* Replace all newline/linefeed characters with space
395 		 * character
396 		 */
397 		strreplace(clmver, '\n', ' ');
398 
399 		/* store CLM version for adding it to revinfo debugfs file */
400 		memcpy(ifp->drvr->clmver, clmver, sizeof(ifp->drvr->clmver));
401 
402 		brcmf_dbg(INFO, "CLM version = %s\n", clmver);
403 	}
404 
405 	/* set mpc */
406 	err = brcmf_fil_iovar_int_set(ifp, "mpc", 1);
407 	if (err) {
408 		bphy_err(drvr, "failed setting mpc\n");
409 		goto done;
410 	}
411 
412 	brcmf_c_set_joinpref_default(ifp);
413 
414 	/* Setup event_msgs, enable E_IF */
415 	err = brcmf_fil_iovar_data_get(ifp, "event_msgs", fweh->event_mask,
416 				       fweh->event_mask_len);
417 	if (err) {
418 		bphy_err(drvr, "Get event_msgs error (%d)\n", err);
419 		goto done;
420 	}
421 	/*
422 	 * BRCMF_E_IF can safely be used to set the appropriate bit
423 	 * in the event_mask as the firmware event code is guaranteed
424 	 * to match the value of BRCMF_E_IF because it is old cruft
425 	 * that all vendors have.
426 	 */
427 	setbit(fweh->event_mask, BRCMF_E_IF);
428 	err = brcmf_fil_iovar_data_set(ifp, "event_msgs", fweh->event_mask,
429 				       fweh->event_mask_len);
430 	if (err) {
431 		bphy_err(drvr, "Set event_msgs error (%d)\n", err);
432 		goto done;
433 	}
434 
435 	/* Setup default scan channel time */
436 	err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
437 				    BRCMF_DEFAULT_SCAN_CHANNEL_TIME);
438 	if (err) {
439 		bphy_err(drvr, "BRCMF_C_SET_SCAN_CHANNEL_TIME error (%d)\n",
440 			 err);
441 		goto done;
442 	}
443 
444 	/* Setup default scan unassoc time */
445 	err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
446 				    BRCMF_DEFAULT_SCAN_UNASSOC_TIME);
447 	if (err) {
448 		bphy_err(drvr, "BRCMF_C_SET_SCAN_UNASSOC_TIME error (%d)\n",
449 			 err);
450 		goto done;
451 	}
452 
453 	/* Enable tx beamforming, errors can be ignored (not supported) */
454 	(void)brcmf_fil_iovar_int_set(ifp, "txbf", 1);
455 done:
456 	return err;
457 }
458 
459 #ifndef CONFIG_BRCM_TRACING
__brcmf_err(struct brcmf_bus * bus,const char * func,const char * fmt,...)460 void __brcmf_err(struct brcmf_bus *bus, const char *func, const char *fmt, ...)
461 {
462 	struct va_format vaf;
463 	va_list args;
464 
465 	va_start(args, fmt);
466 
467 	vaf.fmt = fmt;
468 	vaf.va = &args;
469 	if (bus)
470 		dev_err(bus->dev, "%s: %pV", func, &vaf);
471 	else
472 		pr_err("%s: %pV", func, &vaf);
473 
474 	va_end(args);
475 }
476 #endif
477 
478 #if defined(CONFIG_BRCM_TRACING) || defined(CONFIG_BRCMDBG)
__brcmf_dbg(u32 level,const char * func,const char * fmt,...)479 void __brcmf_dbg(u32 level, const char *func, const char *fmt, ...)
480 {
481 	struct va_format vaf = {
482 		.fmt = fmt,
483 	};
484 	va_list args;
485 
486 	va_start(args, fmt);
487 	vaf.va = &args;
488 	if (brcmf_msg_level & level)
489 		pr_debug("%s %pV", func, &vaf);
490 	trace_brcmf_dbg(level, func, &vaf);
491 	va_end(args);
492 }
493 BRCMF_EXPORT_SYMBOL_GPL(__brcmf_dbg);
494 #endif
495 
brcmf_mp_attach(void)496 static void brcmf_mp_attach(void)
497 {
498 	/* If module param firmware path is set then this will always be used,
499 	 * if not set then if available use the platform data version. To make
500 	 * sure it gets initialized at all, always copy the module param version
501 	 */
502 	strscpy(brcmf_mp_global.firmware_path, brcmf_firmware_path,
503 		BRCMF_FW_ALTPATH_LEN);
504 	if ((brcmfmac_pdata) && (brcmfmac_pdata->fw_alternative_path) &&
505 	    (brcmf_mp_global.firmware_path[0] == '\0')) {
506 		strscpy(brcmf_mp_global.firmware_path,
507 			brcmfmac_pdata->fw_alternative_path,
508 			BRCMF_FW_ALTPATH_LEN);
509 	}
510 }
511 
brcmf_get_module_param(struct device * dev,enum brcmf_bus_type bus_type,u32 chip,u32 chiprev)512 struct brcmf_mp_device *brcmf_get_module_param(struct device *dev,
513 					       enum brcmf_bus_type bus_type,
514 					       u32 chip, u32 chiprev)
515 {
516 	struct brcmf_mp_device *settings;
517 	struct brcmfmac_pd_device *device_pd;
518 	bool found;
519 	int i;
520 
521 	brcmf_dbg(INFO, "Enter, bus=%d, chip=%d, rev=%d\n", bus_type, chip,
522 		  chiprev);
523 	settings = kzalloc_obj(*settings, GFP_ATOMIC);
524 	if (!settings)
525 		return NULL;
526 
527 	/* start by using the module parameters */
528 	settings->p2p_enable = !!brcmf_p2p_enable;
529 	settings->feature_disable = brcmf_feature_disable;
530 	settings->fcmode = brcmf_fcmode;
531 	settings->roamoff = !!brcmf_roamoff;
532 	settings->iapp = !!brcmf_iapp_enable;
533 #ifdef DEBUG
534 	settings->ignore_probe_fail = !!brcmf_ignore_probe_fail;
535 #endif
536 
537 	if (bus_type == BRCMF_BUSTYPE_SDIO)
538 		settings->bus.sdio.txglomsz = brcmf_sdiod_txglomsz;
539 
540 	/* See if there is any device specific platform data configured */
541 	found = false;
542 	if (brcmfmac_pdata) {
543 		for (i = 0; i < brcmfmac_pdata->device_count; i++) {
544 			device_pd = &brcmfmac_pdata->devices[i];
545 			if ((device_pd->bus_type == bus_type) &&
546 			    (device_pd->id == chip) &&
547 			    ((device_pd->rev == chiprev) ||
548 			     (device_pd->rev == -1))) {
549 				brcmf_dbg(INFO, "Platform data for device found\n");
550 				settings->country_codes =
551 						device_pd->country_codes;
552 				if (device_pd->bus_type == BRCMF_BUSTYPE_SDIO)
553 					memcpy(&settings->bus.sdio,
554 					       &device_pd->bus.sdio,
555 					       sizeof(settings->bus.sdio));
556 				found = true;
557 				break;
558 			}
559 		}
560 	}
561 	if (!found) {
562 		/* No platform data for this device, try OF and DMI data */
563 		brcmf_dmi_probe(settings, chip, chiprev);
564 		if (brcmf_of_probe(dev, bus_type, settings) == -EPROBE_DEFER) {
565 			kfree(settings);
566 			return ERR_PTR(-EPROBE_DEFER);
567 		}
568 		brcmf_acpi_probe(dev, bus_type, settings);
569 	}
570 	return settings;
571 }
572 
brcmf_release_module_param(struct brcmf_mp_device * module_param)573 void brcmf_release_module_param(struct brcmf_mp_device *module_param)
574 {
575 	kfree(module_param);
576 }
577 
brcmf_common_pd_probe(struct platform_device * pdev)578 static int __init brcmf_common_pd_probe(struct platform_device *pdev)
579 {
580 	brcmf_dbg(INFO, "Enter\n");
581 
582 	brcmfmac_pdata = dev_get_platdata(&pdev->dev);
583 
584 	if (brcmfmac_pdata->power_on)
585 		brcmfmac_pdata->power_on();
586 
587 	return 0;
588 }
589 
brcmf_common_pd_remove(struct platform_device * pdev)590 static void brcmf_common_pd_remove(struct platform_device *pdev)
591 {
592 	brcmf_dbg(INFO, "Enter\n");
593 
594 	if (brcmfmac_pdata->power_off)
595 		brcmfmac_pdata->power_off();
596 }
597 
598 static struct platform_driver brcmf_pd = {
599 	.remove		= brcmf_common_pd_remove,
600 	.driver		= {
601 		.name	= BRCMFMAC_PDATA_NAME,
602 	}
603 };
604 
brcmfmac_module_init(void)605 static int __init brcmfmac_module_init(void)
606 {
607 	int err;
608 
609 	/* Get the platform data (if available) for our devices */
610 	err = platform_driver_probe(&brcmf_pd, brcmf_common_pd_probe);
611 	if (err == -ENODEV)
612 		brcmf_dbg(INFO, "No platform data available.\n");
613 
614 	/* Initialize global module parameters */
615 	brcmf_mp_attach();
616 
617 	/* Continue the initialization by registering the different busses */
618 	err = brcmf_core_init();
619 	if (err) {
620 		if (brcmfmac_pdata)
621 			platform_driver_unregister(&brcmf_pd);
622 	}
623 
624 	return err;
625 }
626 
brcmfmac_module_exit(void)627 static void __exit brcmfmac_module_exit(void)
628 {
629 	brcmf_core_exit();
630 	if (brcmfmac_pdata)
631 		platform_driver_unregister(&brcmf_pd);
632 }
633 
634 module_init(brcmfmac_module_init);
635 module_exit(brcmfmac_module_exit);
636 
637