hc
2024-05-10 23fa18eaa71266feff7ba8d83022d9e1cc83c65a
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/dhd_linux_platdev.c
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * Linux platform device for DHD WLAN adapter
43 *
5
- * Copyright (C) 1999-2019, Broadcom Corporation
6
- *
4
+ * Portions of this code are copyright (c) 2022 Cypress Semiconductor Corporation
5
+ *
6
+ * Copyright (C) 1999-2017, Broadcom Corporation
7
+ *
78 * Unless you and Broadcom execute a separate written software license
89 * agreement governing use of this software, this software is licensed to you
910 * under the terms of the GNU General Public License version 2 (the "GPL"),
1011 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
1112 * following added to such license:
12
- *
13
+ *
1314 * As a special exception, the copyright holders of this software give you
1415 * permission to link this software with independent modules, and to copy and
1516 * distribute the resulting executable under terms of your choice, provided that
....@@ -17,7 +18,7 @@
1718 * the license of that module. An independent module is a module which is not
1819 * derived from this software. The special exception does not apply to any
1920 * modifications of the software.
20
- *
21
+ *
2122 * Notwithstanding the above, under no circumstances may you combine this
2223 * software in any way with any other Broadcom software provided under a license
2324 * other than the GPL, without Broadcom's express prior written consent.
....@@ -25,7 +26,7 @@
2526 *
2627 * <<Broadcom-WL-IPTag/Open:>>
2728 *
28
- * $Id: dhd_linux_platdev.c 401742 2013-05-13 15:03:21Z $
29
+ * $Id: dhd_linux_platdev.c 697969 2017-05-05 16:36:11Z $
2930 */
3031 #include <typedefs.h>
3132 #include <linux/kernel.h>
....@@ -39,26 +40,37 @@
3940 #include <dhd.h>
4041 #include <dhd_bus.h>
4142 #include <dhd_linux.h>
43
+#if defined(OEM_ANDROID)
4244 #include <wl_android.h>
45
+#endif // endif
4346 #if defined(CONFIG_WIFI_CONTROL_FUNC)
4447 #include <linux/wlan_plat.h>
45
-#endif
46
-#ifdef BCMDBUS
47
-#include <dbus.h>
48
-#endif
48
+#endif // endif
4949 #ifdef CONFIG_DTS
5050 #include<linux/regulator/consumer.h>
5151 #include<linux/of_gpio.h>
5252 #endif /* CONFIG_DTS */
53
-
54
-
5553 #define WIFI_PLAT_NAME "bcmdhd_wlan"
5654 #define WIFI_PLAT_NAME2 "bcm4329_wlan"
5755 #define WIFI_PLAT_EXT "bcmdhd_wifi_platform"
5856
57
+#ifdef USE_CUSTOM_MSM_PCIE
58
+#include <linux/msm_pcie.h>
59
+#endif /* USE_CUSTOM_MSM_PCIE */
60
+
61
+#ifdef DHD_WIFI_SHUTDOWN
62
+extern void wifi_plat_dev_drv_shutdown(struct platform_device *pdev);
63
+#endif // endif
64
+
5965 #ifdef CONFIG_DTS
6066 struct regulator *wifi_regulator = NULL;
6167 #endif /* CONFIG_DTS */
68
+
69
+
70
+#ifdef DHD_CUSTOM_PLAT_DATA
71
+extern int dhd_wlan_init_plat_data(void);
72
+extern int dhd_wlan_deinit_plat_data(void);
73
+#endif /* DHD_CUSTOM_PLAT_DATA */
6274
6375 bool cfg_multichip = FALSE;
6476 bcmdhd_wifi_platdata_t *dhd_wifi_platdata = NULL;
....@@ -67,19 +79,31 @@
6779 #if !defined(CONFIG_DTS)
6880 #if defined(DHD_OF_SUPPORT)
6981 static bool dts_enabled = TRUE;
70
-extern int dhd_wlan_init_plat_data(void);
7182 extern struct resource dhd_wlan_resources;
7283 extern struct wifi_platform_data dhd_wlan_control;
7384 #else
7485 static bool dts_enabled = FALSE;
86
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
87
+#pragma GCC diagnostic push
88
+#pragma GCC diagnostic ignored "-Wmissing-field-initializers"
89
+#endif // endif
7590 struct resource dhd_wlan_resources = {0};
7691 struct wifi_platform_data dhd_wlan_control = {0};
92
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
93
+#pragma GCC diagnostic pop
94
+#endif // endif
7795 #endif /* CONFIG_OF && !defined(CONFIG_ARCH_MSM) */
7896 #endif /* !defind(CONFIG_DTS) */
7997
8098 static int dhd_wifi_platform_load(void);
8199
82
-extern void* wl_cfg80211_get_dhdp(void);
100
+extern void* wl_cfg80211_get_dhdp(struct net_device *dev);
101
+
102
+#if defined(BOARD_HIKEY) || defined(USE_CUSTOM_MSM_PCIE)
103
+extern int dhd_wlan_init(void);
104
+extern int dhd_wlan_deinit(void);
105
+extern void post_power_operation(int on);
106
+#endif /* defined(BOARD_HIKEY) || defined(USE_CUSTOM_MSM_PCIE) */
83107
84108 #ifdef ENABLE_4335BT_WAR
85109 extern int bcm_bt_lock(int cookie);
....@@ -166,9 +190,10 @@
166190
167191 if (!adapter || !adapter->wifi_plat_data)
168192 return -EINVAL;
193
+
169194 plat_data = adapter->wifi_plat_data;
170195
171
- DHD_ERROR(("%s = %d\n", __FUNCTION__, on));
196
+ DHD_ERROR(("%s = %d, delay: %lu msec\n", __FUNCTION__, on, msec));
172197 if (plat_data->set_power) {
173198 #ifdef ENABLE_4335BT_WAR
174199 if (on) {
....@@ -189,17 +214,21 @@
189214 if (msec && !err)
190215 OSL_SLEEP(msec);
191216
192
- if (on && !err)
217
+ if (on && !err) {
193218 is_power_on = TRUE;
194
- else
219
+#ifdef USE_CUSTOM_POST_PWR_OPER
220
+ post_power_operation(on);
221
+#endif /* USE_CUSTOM_MSM_PCIE */
222
+ } else {
195223 is_power_on = FALSE;
224
+ }
196225
197226 #endif /* CONFIG_DTS */
198227
199228 return err;
200229 }
201230
202
-#if defined(CUSTOMER_IMX)
231
+#if defined(PLATFORM_IMX)
203232 extern void wifi_card_detect(bool);
204233 int wifi_platform_bus_enumerate(wifi_adapter_info_t *adapter, bool device_present)
205234 {
....@@ -229,6 +258,11 @@
229258 int err = 0;
230259 struct wifi_platform_data *plat_data;
231260
261
+#ifdef CONFIG_DTS
262
+ if (wifi_regulator)
263
+ return err;
264
+#endif /* CONFIG_DTS */
265
+
232266 if (!adapter || !adapter->wifi_plat_data)
233267 return -EINVAL;
234268 plat_data = adapter->wifi_plat_data;
....@@ -240,7 +274,7 @@
240274 return err;
241275
242276 }
243
-#endif /* CUSTOMER_IMX */
277
+#endif /* PLATFORM_IMX */
244278
245279 int wifi_platform_get_mac_addr(wifi_adapter_info_t *adapter, unsigned char *buf)
246280 {
....@@ -255,7 +289,7 @@
255289 }
256290 return -EOPNOTSUPP;
257291 }
258
-#ifdef CUSTOM_COUNTRY_CODE
292
+#ifdef CUSTOM_COUNTRY_CODE
259293 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode, u32 flags)
260294 #else
261295 void *wifi_platform_get_country_code(wifi_adapter_info_t *adapter, char *ccode)
....@@ -274,7 +308,7 @@
274308 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 58))
275309 return plat_data->get_country_code(ccode, WLAN_PLAT_NODFS_FLAG);
276310 #else
277
-#ifdef CUSTOM_COUNTRY_CODE
311
+#ifdef CUSTOM_COUNTRY_CODE
278312 return plat_data->get_country_code(ccode, flags);
279313 #else
280314 return plat_data->get_country_code(ccode);
....@@ -308,6 +342,9 @@
308342 if (resource) {
309343 adapter->irq_num = resource->start;
310344 adapter->intr_flags = resource->flags & IRQF_TRIGGER_MASK;
345
+#ifdef DHD_ISR_NO_SUSPEND
346
+ adapter->intr_flags |= IRQF_NO_SUSPEND;
347
+#endif // endif
311348 }
312349
313350 #ifdef CONFIG_DTS
....@@ -317,12 +354,14 @@
317354 return -1;
318355 }
319356
357
+#if defined(OOB_INTR_ONLY) || defined(BCMPCIE_OOB_HOST_WAKE)
320358 /* This is to get the irq for the OOB */
321359 gpio = of_get_gpio(pdev->dev.of_node, 0);
322360
323361 if (gpio < 0) {
324
- DHD_ERROR(("%s gpio information is incorrect\n", __FUNCTION__));
325
- return -1;
362
+ DHD_ERROR(("%s OOB GPIO information is incorrect Or Not available\n",
363
+ __FUNCTION__));
364
+ goto end;
326365 }
327366 irq = gpio_to_irq(gpio);
328367 if (irq < 0) {
....@@ -334,6 +373,8 @@
334373 /* need to change the flags according to our requirement */
335374 adapter->intr_flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL |
336375 IORESOURCE_IRQ_SHAREABLE;
376
+end:
377
+#endif /* defined(OOB_INTR_ONLY) || defined(BCMPCIE_OOB_HOST_WAKE) */
337378 #endif /* CONFIG_DTS */
338379
339380 wifi_plat_dev_probe_ret = dhd_wifi_platform_load();
....@@ -398,6 +439,9 @@
398439 .remove = wifi_plat_dev_drv_remove,
399440 .suspend = wifi_plat_dev_drv_suspend,
400441 .resume = wifi_plat_dev_drv_resume,
442
+#ifdef DHD_WIFI_SHUTDOWN
443
+ .shutdown = wifi_plat_dev_drv_shutdown,
444
+#endif // endif
401445 .driver = {
402446 .name = WIFI_PLAT_NAME,
403447 #ifdef CONFIG_DTS
....@@ -411,19 +455,28 @@
411455 .remove = wifi_plat_dev_drv_remove,
412456 .suspend = wifi_plat_dev_drv_suspend,
413457 .resume = wifi_plat_dev_drv_resume,
458
+#ifdef DHD_WIFI_SHUTDOWN
459
+ .shutdown = wifi_plat_dev_drv_shutdown,
460
+#endif // endif
414461 .driver = {
415462 .name = WIFI_PLAT_NAME2,
416463 }
417464 };
418
-
419
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
465
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 3, 0))
420466 static int wifi_platdev_match(struct device *dev, const void *data)
421467 #else
422468 static int wifi_platdev_match(struct device *dev, void *data)
423
-#endif
469
+#endif /* LINUX_VERSION_CODE */
424470 {
425
- char *name = (char*)data;
426
- struct platform_device *pdev = to_platform_device(dev);
471
+ const char *name = (const char*)data;
472
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
473
+#pragma GCC diagnostic push
474
+#pragma GCC diagnostic ignored "-Wcast-qual"
475
+#endif // endif
476
+ const struct platform_device *pdev = to_platform_device(dev);
477
+#if defined(STRICT_GCC_WARNINGS) && defined(__GNUC__)
478
+#pragma GCC diagnostic pop
479
+#endif // endif
427480
428481 if (strcmp(pdev->name, name) == 0) {
429482 DHD_ERROR(("found wifi platform device %s\n", name));
....@@ -441,6 +494,10 @@
441494
442495 dev1 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME, wifi_platdev_match);
443496 dev2 = bus_find_device(&platform_bus_type, NULL, WIFI_PLAT_NAME2, wifi_platdev_match);
497
+
498
+#if defined(BOARD_HIKEY_MODULAR) || defined(USE_CUSTOM_MSM_PCIE)
499
+ dhd_wlan_init();
500
+#endif /* defined(BOARD_HIKEY_MODULAR) || defined(USE_CUSTOM_MSM_PCIE) */
444501
445502 #if !defined(CONFIG_DTS)
446503 if (!dts_enabled) {
....@@ -486,23 +543,25 @@
486543 return err;
487544 }
488545 }
489
-
490546 #if !defined(CONFIG_DTS)
491547 if (dts_enabled) {
492548 struct resource *resource;
493
-
494
- wifi_plat_dev_probe_ret = dhd_wlan_init_plat_data();
495
- if (wifi_plat_dev_probe_ret)
549
+#ifdef DHD_CUSTOM_PLAT_DATA
550
+ wifi_plat_dev_probe_ret = dhd_wlan_init_plat_data();
551
+ if (wifi_plat_dev_probe_ret) {
496552 return wifi_plat_dev_probe_ret;
497
-
553
+ }
554
+#endif /* DHD_CUSTOM_PLAT_DATA */
498555 adapter->wifi_plat_data = (void *)&dhd_wlan_control;
499556 resource = &dhd_wlan_resources;
500557 adapter->irq_num = resource->start;
501558 adapter->intr_flags = resource->flags & IRQF_TRIGGER_MASK;
559
+#ifdef DHD_ISR_NO_SUSPEND
560
+ adapter->intr_flags |= IRQF_NO_SUSPEND;
561
+#endif // endif
502562 wifi_plat_dev_probe_ret = dhd_wifi_platform_load();
503563 }
504564 #endif /* !defined(CONFIG_DTS) */
505
-
506565
507566 #ifdef CONFIG_DTS
508567 wifi_plat_dev_probe_ret = platform_driver_register(&wifi_platform_dev_driver);
....@@ -527,6 +586,7 @@
527586 return;
528587
529588 DHD_ERROR(("unregister wifi platform drivers\n"));
589
+
530590 if (dev1)
531591 platform_driver_unregister(&wifi_platform_dev_driver);
532592 if (dev2)
....@@ -539,6 +599,13 @@
539599 wifi_platform_bus_enumerate(adapter, FALSE);
540600 }
541601 }
602
+#ifdef BOARD_HIKEY_MODULAR
603
+ dhd_wlan_deinit();
604
+#endif /* BOARD_HIKEY_MODULAR */
605
+#ifdef DHD_CUSTOM_PLAT_DATA
606
+ dhd_wlan_deinit_plat_data();
607
+#endif /* DHD_CUSTOM_PLAT_DATA */
608
+
542609 #endif /* !defined(CONFIG_DTS) */
543610
544611 kfree(dhd_wifi_platdata->adapters);
....@@ -699,7 +766,6 @@
699766 }
700767 #endif /* BCMPCIE */
701768
702
-
703769 void dhd_wifi_platform_unregister_drv(void)
704770 {
705771 if (cfg_multichip)
....@@ -711,9 +777,9 @@
711777 extern int dhd_watchdog_prio;
712778 extern int dhd_dpc_prio;
713779 extern uint dhd_deferred_tx;
714
-#if defined(BCMLXSDMMC)
780
+#if defined(OEM_ANDROID) && defined(BCMLXSDMMC)
715781 extern struct semaphore dhd_registration_sem;
716
-#endif
782
+#endif /* defined(OEM_ANDROID) && defined(BCMLXSDMMC) */
717783
718784 #ifdef BCMSDIO
719785 static int dhd_wifi_platform_load_sdio(void)
....@@ -724,6 +790,7 @@
724790
725791 BCM_REFERENCE(i);
726792 BCM_REFERENCE(adapter);
793
+
727794 /* Sanity check on the module parameters
728795 * - Both watchdog and DPC as tasklets are ok
729796 * - If both watchdog and DPC are threads, TX must be deferred
....@@ -732,19 +799,19 @@
732799 !(dhd_watchdog_prio >= 0 && dhd_dpc_prio >= 0 && dhd_deferred_tx))
733800 return -EINVAL;
734801
735
-#if defined(BCMLXSDMMC)
802
+#if defined(OEM_ANDROID) && defined(BCMLXSDMMC)
736803 sema_init(&dhd_registration_sem, 0);
737
-#endif
804
+#endif // endif
738805
739806 if (dhd_wifi_platdata == NULL) {
740807 DHD_ERROR(("DHD wifi platform data is required for Android build\n"));
741
- DHD_ERROR(("DHD registeing bus directly\n"));
808
+ DHD_ERROR(("DHD registering bus directly\n"));
742809 /* x86 bring-up PC needs no power-up operations */
743810 err = dhd_bus_register();
744811 return err;
745812 }
746813
747
-#if defined(BCMLXSDMMC)
814
+#if defined(OEM_ANDROID) && defined(BCMLXSDMMC)
748815 /* power up all adapters */
749816 for (i = 0; i < dhd_wifi_platdata->num_adapters; i++) {
750817 bool chip_up = FALSE;
....@@ -769,12 +836,13 @@
769836 }
770837 err = wifi_platform_set_power(adapter, TRUE, WIFI_TURNON_DELAY);
771838 if (err) {
839
+ DHD_ERROR(("%s: wifi pwr on error ! \n", __FUNCTION__));
840
+ dhd_bus_unreg_sdio_notify();
772841 /* WL_REG_ON state unknown, Power off forcely */
773842 wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
774843 continue;
775844 } else {
776845 wifi_platform_bus_enumerate(adapter, TRUE);
777
- err = 0;
778846 }
779847
780848 if (down_timeout(&dhd_chipup_sem, msecs_to_jiffies(POWERUP_WAIT_MS)) == 0) {
....@@ -824,7 +892,7 @@
824892 wifi_platform_set_power(adapter, FALSE, WIFI_TURNOFF_DELAY);
825893 wifi_platform_bus_enumerate(adapter, FALSE);
826894 }
827
-#endif
895
+#endif /* defined(OEM_ANDROID) && defined(BCMLXSDMMC) */
828896
829897 return err;
830898 }
....@@ -835,49 +903,18 @@
835903 }
836904 #endif /* BCMSDIO */
837905
838
-#ifdef BCMDBUS
839
-/* User-specified vid/pid */
840
-int dhd_vid = 0xa5c;
841
-int dhd_pid = 0x48f;
842
-module_param(dhd_vid, int, 0);
843
-module_param(dhd_pid, int, 0);
844
-void *dhd_dbus_probe_cb(void *arg, const char *desc, uint32 bustype, uint32 hdrlen);
845
-void dhd_dbus_disconnect_cb(void *arg);
846
-
847
-static int dhd_wifi_platform_load_usb(void)
848
-{
849
- int err = 0;
850
-
851
- if (dhd_vid < 0 || dhd_vid > 0xffff) {
852
- DHD_ERROR(("%s: invalid dhd_vid 0x%x\n", __FUNCTION__, dhd_vid));
853
- return -EINVAL;
854
- }
855
- if (dhd_pid < 0 || dhd_pid > 0xffff) {
856
- DHD_ERROR(("%s: invalid dhd_pid 0x%x\n", __FUNCTION__, dhd_pid));
857
- return -EINVAL;
858
- }
859
-
860
- err = dbus_register(dhd_vid, dhd_pid, dhd_dbus_probe_cb, dhd_dbus_disconnect_cb,
861
- NULL, NULL, NULL);
862
-
863
- /* Device not detected */
864
- if (err == DBUS_ERR_NODEVICE)
865
- err = DBUS_OK;
866
-
867
- return err;
868
-}
869
-#else /* BCMDBUS */
870906 static int dhd_wifi_platform_load_usb(void)
871907 {
872908 return 0;
873909 }
874
-#endif /* BCMDBUS */
875910
876911 static int dhd_wifi_platform_load()
877912 {
878913 int err = 0;
879914
915
+#if defined(OEM_ANDROID)
880916 wl_android_init();
917
+#endif /* OEM_ANDROID */
881918
882919 if ((err = dhd_wifi_platform_load_usb()))
883920 goto end;
....@@ -887,10 +924,12 @@
887924 err = dhd_wifi_platform_load_pcie();
888925
889926 end:
927
+#if defined(OEM_ANDROID)
890928 if (err)
891929 wl_android_exit();
892930 else
893931 wl_android_post_init();
932
+#endif /* OEM_ANDROID */
894933
895934 return err;
896935 }