forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/drivers/net/wireless/rockchip_wlan/cywdhd/bcmdhd/bcmsdh_linux.c
....@@ -1,15 +1,16 @@
1
-/* SPDX-License-Identifier: GPL-2.0 */
21 /*
32 * SDIO access interface for drivers - linux specific (pci only)
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: bcmsdh_linux.c 579798 2015-08-17 07:00:05Z $
29
+ * $Id: bcmsdh_linux.c 689948 2017-03-14 05:21:03Z $
2930 */
3031
3132 /**
....@@ -48,9 +49,6 @@
4849 #include <bcmutils.h>
4950 #include <dngl_stats.h>
5051 #include <dhd.h>
51
-#if defined(CONFIG_ARCH_ODIN)
52
-#include <linux/platform_data/gpio-odin.h>
53
-#endif /* defined(CONFIG_ARCH_ODIN) */
5452 #include <dhd_linux.h>
5553
5654 /* driver info, initialized when bcmsdh_register is called */
....@@ -85,7 +83,7 @@
8583 } bcmsdh_os_info_t;
8684
8785 /* debugging macros */
88
-#define SDLX_MSG(x) do { printf x; } while (0)
86
+#define SDLX_MSG(x)
8987
9088 /**
9189 * Checks to see if vendor and device IDs match a supported SDIO Host Controller.
....@@ -98,6 +96,9 @@
9896 #ifdef BCMSDIOH_STD
9997 /* Check for Arasan host controller */
10098 if (vendor == VENDOR_SI_IMAGE) {
99
+ return (TRUE);
100
+ }
101
+ if (device == SDIOH_FPGA_ID && vendor == VENDOR_CYPRESS) {
101102 return (TRUE);
102103 }
103104 /* Check for BRCM 27XX Standard host controller */
....@@ -161,10 +162,13 @@
161162 bcmsdh_osinfo->dev = dev;
162163 osl_set_bus_handle(osh, bcmsdh);
163164
164
-#if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
165
+#if (!defined(CONFIG_PM_WAKELOCKS) || !defined(CONFIG_HAS_WAKELOCK)) && \
166
+ (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
165167 if (dev && device_init_wakeup(dev, true) == 0)
166168 bcmsdh_osinfo->dev_wake_enabled = TRUE;
167
-#endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
169
+#endif /* CONFIG_PM_WAKELOCKS ||CONFIG_HAS_WAKELOCK &&
170
+ * (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
171
+ */
168172
169173 #if defined(OOB_INTR_ONLY)
170174 spin_lock_init(&bcmsdh_osinfo->oob_irq_spinlock);
....@@ -179,9 +183,15 @@
179183
180184 /* Read the vendor/device ID from the CIS */
181185 vendevid = bcmsdh_query_device(bcmsdh);
186
+
182187 /* try to attach to the target device */
188
+#if defined(BCMSPI) && (defined(BCMPCISPIHOST) || defined(BCMSDIOH_SPI))
189
+ bcmsdh_osinfo->context = drvinfo.probe((vendevid >> 16), (vendevid & 0xFFFF), bus_num,
190
+ slot_num, 0, bus_type, (void *)regs, NULL, bcmsdh);
191
+#else
183192 bcmsdh_osinfo->context = drvinfo.probe((vendevid >> 16), (vendevid & 0xFFFF), bus_num,
184193 slot_num, 0, bus_type, (void *)regs, osh, bcmsdh);
194
+#endif /* BCMSPI && (BCMPCISPIHOST || BCMSDIOH_SPI) */
185195 if (bcmsdh_osinfo->context == NULL) {
186196 SDLX_MSG(("%s: device attach failed\n", __FUNCTION__));
187197 goto err;
....@@ -202,11 +212,14 @@
202212 {
203213 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
204214
205
-#if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
215
+#if (!defined(CONFIG_PM_WAKELOCKS) || !defined(CONFIG_HAS_WAKELOCK)) && \
216
+ (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
206217 if (bcmsdh_osinfo->dev)
207218 device_init_wakeup(bcmsdh_osinfo->dev, false);
208219 bcmsdh_osinfo->dev_wake_enabled = FALSE;
209
-#endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
220
+#endif /* CONFIG_PM_WAKELOCKS ||CONFIG_HAS_WAKELOCK &&
221
+ * (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
222
+ */
210223
211224 drvinfo.remove(bcmsdh_osinfo->context);
212225 MFREE(bcmsdh->osh, bcmsdh->os_cxt, sizeof(bcmsdh_os_info_t));
....@@ -214,6 +227,29 @@
214227
215228 return 0;
216229 }
230
+
231
+#ifdef DHD_WAKE_STATUS
232
+int bcmsdh_get_total_wake(bcmsdh_info_t *bcmsdh)
233
+{
234
+ return bcmsdh->total_wake_count;
235
+}
236
+
237
+int bcmsdh_set_get_wake(bcmsdh_info_t *bcmsdh, int flag)
238
+{
239
+ bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
240
+ unsigned long flags;
241
+ int ret;
242
+
243
+ spin_lock_irqsave(&bcmsdh_osinfo->oob_irq_spinlock, flags);
244
+
245
+ ret = bcmsdh->pkt_wake;
246
+ bcmsdh->total_wake_count += flag;
247
+ bcmsdh->pkt_wake = flag;
248
+
249
+ spin_unlock_irqrestore(&bcmsdh_osinfo->oob_irq_spinlock, flags);
250
+ return ret;
251
+}
252
+#endif /* DHD_WAKE_STATUS */
217253
218254 int bcmsdh_suspend(bcmsdh_info_t *bcmsdh)
219255 {
....@@ -270,25 +306,31 @@
270306 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0))
271307 if (bcmsdh_pci_driver.node.next == NULL)
272308 return;
273
-#endif
309
+#endif // endif
274310
275311 bcmsdh_unregister_client_driver();
276312 }
277313
278314 void bcmsdh_dev_pm_stay_awake(bcmsdh_info_t *bcmsdh)
279315 {
280
-#if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
316
+#if (!defined(CONFIG_PM_WAKELOCKS) || !defined(CONFIG_HAS_WAKELOCK)) && \
317
+ (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
281318 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
282319 pm_stay_awake(bcmsdh_osinfo->dev);
283
-#endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
320
+#endif /* CONFIG_PM_WAKELOCKS ||CONFIG_HAS_WAKELOCK &&
321
+ * (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
322
+ */
284323 }
285324
286325 void bcmsdh_dev_relax(bcmsdh_info_t *bcmsdh)
287326 {
288
-#if !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
327
+#if (!defined(CONFIG_PM_WAKELOCKS) || !defined(CONFIG_HAS_WAKELOCK)) && \
328
+ (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
289329 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
290330 pm_relax(bcmsdh_osinfo->dev);
291
-#endif /* !defined(CONFIG_HAS_WAKELOCK) && (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36)) */
331
+#endif /* CONFIG_PM_WAKELOCKS ||CONFIG_HAS_WAKELOCK &&
332
+ * (LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 36))
333
+ */
292334 }
293335
294336 bool bcmsdh_dev_pm_enabled(bcmsdh_info_t *bcmsdh)
....@@ -298,7 +340,7 @@
298340 return bcmsdh_osinfo->dev_wake_enabled;
299341 }
300342
301
-#if defined(OOB_INTR_ONLY)
343
+#if defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID)
302344 void bcmsdh_oob_intr_set(bcmsdh_info_t *bcmsdh, bool enable)
303345 {
304346 unsigned long flags;
....@@ -324,7 +366,9 @@
324366 bcmsdh_info_t *bcmsdh = (bcmsdh_info_t *)dev_id;
325367 bcmsdh_os_info_t *bcmsdh_osinfo = bcmsdh->os_cxt;
326368
369
+#ifndef BCMSPI_ANDROID
327370 bcmsdh_oob_intr_set(bcmsdh, FALSE);
371
+#endif /* !BCMSPI_ANDROID */
328372 bcmsdh_osinfo->oob_irq_handler(bcmsdh_osinfo->oob_irq_handler_context);
329373
330374 return IRQ_HANDLED;
....@@ -345,23 +389,26 @@
345389 (int)bcmsdh_osinfo->oob_irq_num, (int)bcmsdh_osinfo->oob_irq_flags));
346390 bcmsdh_osinfo->oob_irq_handler = oob_irq_handler;
347391 bcmsdh_osinfo->oob_irq_handler_context = oob_irq_handler_context;
348
-#if defined(CONFIG_ARCH_ODIN)
349
- err = odin_gpio_sms_request_irq(bcmsdh_osinfo->oob_irq_num, wlan_oob_irq,
350
- bcmsdh_osinfo->oob_irq_flags, "bcmsdh_sdmmc", bcmsdh);
351
-#else
392
+ bcmsdh_osinfo->oob_irq_enabled = TRUE;
393
+ bcmsdh_osinfo->oob_irq_registered = TRUE;
352394 err = request_irq(bcmsdh_osinfo->oob_irq_num, wlan_oob_irq,
353395 bcmsdh_osinfo->oob_irq_flags, "bcmsdh_sdmmc", bcmsdh);
354
-#endif /* defined(CONFIG_ARCH_ODIN) */
355396 if (err) {
356397 SDLX_MSG(("%s: request_irq failed with %d\n", __FUNCTION__, err));
398
+ bcmsdh_osinfo->oob_irq_enabled = FALSE;
399
+ bcmsdh_osinfo->oob_irq_registered = FALSE;
357400 return err;
358401 }
359402
403
+#if defined(CONFIG_ARCH_RHEA) || defined(CONFIG_ARCH_CAPRI)
404
+ if (device_may_wakeup(bcmsdh_osinfo->dev)) {
405
+#endif /* CONFIG_ARCH_RHEA || CONFIG_ARCH_CAPRI */
360406 err = enable_irq_wake(bcmsdh_osinfo->oob_irq_num);
361407 if (!err)
362408 bcmsdh_osinfo->oob_irq_wake_enabled = TRUE;
363
- bcmsdh_osinfo->oob_irq_enabled = TRUE;
364
- bcmsdh_osinfo->oob_irq_registered = TRUE;
409
+#if defined(CONFIG_ARCH_RHEA) || defined(CONFIG_ARCH_CAPRI)
410
+ }
411
+#endif /* CONFIG_ARCH_RHEA || CONFIG_ARCH_CAPRI */
365412 return err;
366413 }
367414
....@@ -376,9 +423,15 @@
376423 return;
377424 }
378425 if (bcmsdh_osinfo->oob_irq_wake_enabled) {
426
+#if defined(CONFIG_ARCH_RHEA) || defined(CONFIG_ARCH_CAPRI)
427
+ if (device_may_wakeup(bcmsdh_osinfo->dev)) {
428
+#endif /* CONFIG_ARCH_RHEA || CONFIG_ARCH_CAPRI */
379429 err = disable_irq_wake(bcmsdh_osinfo->oob_irq_num);
380430 if (!err)
381431 bcmsdh_osinfo->oob_irq_wake_enabled = FALSE;
432
+#if defined(CONFIG_ARCH_RHEA) || defined(CONFIG_ARCH_CAPRI)
433
+ }
434
+#endif /* CONFIG_ARCH_RHEA || CONFIG_ARCH_CAPRI */
382435 }
383436 if (bcmsdh_osinfo->oob_irq_enabled) {
384437 disable_irq(bcmsdh_osinfo->oob_irq_num);
....@@ -387,12 +440,12 @@
387440 free_irq(bcmsdh_osinfo->oob_irq_num, bcmsdh);
388441 bcmsdh_osinfo->oob_irq_registered = FALSE;
389442 }
390
-#endif
443
+#endif /* defined(OOB_INTR_ONLY) || defined(BCMSPI_ANDROID) */
391444
392445 /* Module parameters specific to each host-controller driver */
393446
394447 extern uint sd_msglevel; /* Debug message level */
395
-module_param(sd_msglevel, uint, 0664);
448
+module_param(sd_msglevel, uint, 0);
396449
397450 extern uint sd_power; /* 0 = SD Power OFF, 1 = SD Power ON. */
398451 module_param(sd_power, uint, 0);
....@@ -427,7 +480,10 @@
427480 extern char dhd_sdiod_uhsi_ds_override[2];
428481 module_param_string(dhd_sdiod_uhsi_ds_override, dhd_sdiod_uhsi_ds_override, 2, 0);
429482
430
-#endif
483
+#endif // endif
484
+
485
+
486
+
431487
432488 #ifdef BCMSDH_MODULE
433489 EXPORT_SYMBOL(bcmsdh_attach);
....@@ -440,7 +496,11 @@
440496
441497 #if defined(DHD_DEBUG)
442498 EXPORT_SYMBOL(bcmsdh_intr_pending);
443
-#endif
499
+#endif // endif
500
+
501
+#if defined(BT_OVER_SDIO)
502
+EXPORT_SYMBOL(bcmsdh_btsdio_interface_init);
503
+#endif /* defined (BT_OVER_SDIO) */
444504
445505 EXPORT_SYMBOL(bcmsdh_devremove_reg);
446506 EXPORT_SYMBOL(bcmsdh_cfg_read);