MT6620: add the new driver JB2 V1.0
[firefly-linux-kernel-4.4.55.git] / drivers / mtk_wcn_combo / drv_wlan / mt6620 / wlan / os / linux / hif / sdio / sdio.c
1 /******************************************************************************
2 *[File]             sdio.c
3 *[Version]          v1.0
4 *[Revision Date]    2010-03-01
5 *[Author]
6 *[Description]
7 *    The program provides SDIO HIF driver
8 *[Copyright]
9 *    Copyright (C) 2010 MediaTek Incorporation. All Rights Reserved.
10 ******************************************************************************/
11
12
13
14 /*
15 ** $Log: sdio.c $
16  *
17  * 04 12 2012 terry.wu
18  * NULL
19  * Add AEE message support
20  * 1) Show AEE warning(red screen) if SDIO access error occurs
21
22  *
23  * 02 14 2012 cp.wu
24  * [WCXRP00000851] [MT6628 Wi-Fi][Driver] Add HIFSYS related definition to driver source tree
25  * include correct header file upon setting.
26  *
27  * 11 10 2011 cp.wu
28  * [WCXRP00001098] [MT6620 Wi-Fi][Driver] Replace printk by DBG LOG macros in linux porting layer
29  * 1. eliminaite direct calls to printk in porting layer.
30  * 2. replaced by DBGLOG, which would be XLOG on ALPS platforms.
31  *
32  * 09 20 2011 cp.wu
33  * [WCXRP00000994] [MT6620 Wi-Fi][Driver] dump message for bus error and reset bus error flag while re-initialized
34  * 1. always show error message for SDIO bus errors.
35  * 2. reset bus error flag when re-initialization
36  *
37  * 08 17 2011 cp.wu
38  * [WCXRP00000851] [MT6628 Wi-Fi][Driver] Add HIFSYS related definition to driver source tree
39  * add MT6628 related definitions for Linux/Android driver.
40  *
41  * 05 18 2011 cp.wu
42  * [WCXRP00000702] [MT5931][Driver] Modify initialization sequence for E1 ASIC
43  * add device ID for MT5931.
44  *
45  * 04 08 2011 pat.lu
46  * [WCXRP00000623] [MT6620 Wi-Fi][Driver] use ARCH define to distinguish PC Linux driver
47  * Use CONFIG_X86 instead of PC_LINUX_DRIVER_USE option to have proper compile settting for PC Linux driver
48  *
49  * 03 22 2011 pat.lu
50  * [WCXRP00000592] [MT6620 Wi-Fi][Driver] Support PC Linux Environment Driver Build
51  * Add a compiler option "PC_LINUX_DRIVER_USE" for building driver in PC Linux environment.
52  *
53  * 03 18 2011 cp.wu
54  * [WCXRP00000559] [MT6620 Wi-Fi][Driver] Combine TX/RX DMA buffers into a single one to reduce physically continuous memory consumption
55  * deprecate CFG_HANDLE_IST_IN_SDIO_CALLBACK.
56  *
57  * 03 15 2011 cp.wu
58  * [WCXRP00000559] [MT6620 Wi-Fi][Driver] Combine TX/RX DMA buffers into a single one to reduce physically continuous memory consumption
59  * 1. deprecate CFG_HANDLE_IST_IN_SDIO_CALLBACK
60  * 2. Use common coalescing buffer for both TX/RX directions
61  *
62  *
63  * 03 07 2011 terry.wu
64  * [WCXRP00000521] [MT6620 Wi-Fi][Driver] Remove non-standard debug message
65  * Toggle non-standard debug messages to comments.
66  *
67  * 11 15 2010 jeffrey.chang
68  * [WCXRP00000181] [MT6620 Wi-Fi][Driver] fix the driver message "GLUE_FLAG_HALT skip INT" during unloading
69  * Fix GLUE_FALG_HALT message which cause driver to hang
70  *
71  * 11 08 2010 cp.wu
72  * [WCXRP00000166] [MT6620 Wi-Fi][Driver] use SDIO CMD52 for enabling/disabling interrupt to reduce transaction period
73  * correct typo
74  *
75  * 11 08 2010 cp.wu
76  * [WCXRP00000166] [MT6620 Wi-Fi][Driver] use SDIO CMD52 for enabling/disabling interrupt to reduce transaction period
77  * change to use CMD52 for enabling/disabling interrupt to reduce SDIO transaction time
78  *
79  * 11 01 2010 yarco.yang
80  * [WCXRP00000149] [MT6620 WI-Fi][Driver]Fine tune performance on MT6516 platform
81  * Add code to run WlanIST in SDIO callback.
82  *
83  * 10 19 2010 cp.wu
84  * [WCXRP00000122] [MT6620 Wi-Fi][Driver] Preparation for YuSu source tree integration
85  * remove HIF_SDIO_ONE flags because the settings could be merged for runtime detection instead of compile-time.
86  *
87  * 10 19 2010 jeffrey.chang
88  * [WCXRP00000120] [MT6620 Wi-Fi][Driver] Refine linux kernel module to the license of MTK propietary and enable MTK HIF by default
89  * Refine linux kernel module to the license of MTK and enable MTK HIF
90  *
91  * 08 21 2010 jeffrey.chang
92  * NULL
93  * 1) add sdio two setting
94  * 2) bug fix of sdio glue
95  *
96  * 08 18 2010 jeffrey.chang
97  * NULL
98  * support multi-function sdio
99  *
100  * 08 18 2010 cp.wu
101  * NULL
102  * #if defined(__X86__) is not working, change to use #ifdef CONFIG_X86.
103  *
104  * 08 17 2010 cp.wu
105  * NULL
106  * add ENE SDIO host workaround for x86 linux platform.
107  *
108  * 07 08 2010 cp.wu
109  *
110  * [WPD00003833] [MT6620 and MT5931] Driver migration - move to new repository.
111  *
112  * 06 06 2010 kevin.huang
113  * [WPD00003832][MT6620 5931] Create driver base
114  * [MT6620 5931] Create driver base
115  *
116  * 05 07 2010 jeffrey.chang
117  * [WPD00003826]Initial import for Linux port
118  * Fix hotplug bug
119  *
120  * 03 28 2010 jeffrey.chang
121  * [WPD00003826]Initial import for Linux port
122  * clear sdio interrupt
123  *
124  * 03 24 2010 jeffrey.chang
125  * [WPD00003826]Initial import for Linux port
126  * initial import for Linux port
127 **
128 */
129
130 /*******************************************************************************
131 *                         C O M P I L E R   F L A G S
132 ********************************************************************************
133 */
134
135 /*******************************************************************************
136 *                    E X T E R N A L   R E F E R E N C E S
137 ********************************************************************************
138 */
139
140 #include "gl_os.h"
141
142 #if MTK_WCN_HIF_SDIO
143 #include "hif_sdio.h"
144 #else
145 #include <linux/mmc/card.h>
146 #include <linux/mmc/host.h>
147 #include <linux/mmc/sdio.h>
148 #include <linux/mmc/sdio_func.h> /* sdio_readl(), etc */
149 #include <linux/mmc/sdio_ids.h>
150 #endif
151
152 #include <linux/mm.h>
153 //#ifndef CONFIG_X86  modify by Nicolas Luo
154 #ifdef CONFIG_ARM
155 #include <asm/memory.h>
156 #endif
157
158
159 #if defined(MT6620)
160     #include "mt6620_reg.h"
161 #elif defined(MT5931)
162     #include "mt5931_reg.h"
163 #elif defined(MT6628)
164     #include "mt6628_reg.h"
165 #endif
166
167 #if CFG_DBG_GPIO_PINS/* FIXME: move to platform or custom header */
168 #include <mach/mt6516_gpio.h>
169 #endif
170
171 /*******************************************************************************
172 *                              C O N S T A N T S
173 ********************************************************************************
174 */
175
176 #define HIF_SDIO_ERR_TITLE_STR              "["CHIP_NAME"] SDIO Access Error!"
177 #define HIF_SDIO_ERR_DESC_STR               "**SDIO Access Error**\n"
178
179 #if MTK_WCN_HIF_SDIO
180
181
182 /*
183  * function prototypes
184  *
185  */
186
187 static INT32
188 mtk_sdio_probe(MTK_WCN_HIF_SDIO_CLTCTX, const MTK_WCN_HIF_SDIO_FUNCINFO *);
189
190 static INT32
191 mtk_sdio_remove(MTK_WCN_HIF_SDIO_CLTCTX);
192 static INT32 mtk_sdio_interrupt(MTK_WCN_HIF_SDIO_CLTCTX);
193
194 /*
195  * sdio function info table
196  */
197
198 static MTK_WCN_HIF_SDIO_FUNCINFO funcInfo[] = {
199 #if defined(MT6620)
200     { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x020a, 0x1, 512) },
201     { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x020c, 0x2, 512) },
202     { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x018a, 0x1, 512) },
203     { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x018c, 0x2, 512) },
204 #elif defined(MT5931)
205     { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x5931, 0x1, 512) },
206 #elif defined(MT6628)
207     { MTK_WCN_HIF_SDIO_FUNC(0x037a, 0x6628, 0x1, 512) },
208 #endif
209 };
210
211
212 static MTK_WCN_HIF_SDIO_CLTINFO cltInfo = {
213     .func_tbl = funcInfo,
214     .func_tbl_size = sizeof(funcInfo)/sizeof(MTK_WCN_HIF_SDIO_FUNCINFO),
215     .hif_clt_probe = mtk_sdio_probe,
216     .hif_clt_remove = mtk_sdio_remove,
217     .hif_clt_irq = mtk_sdio_interrupt,
218 };
219
220 #else
221
222 static const struct sdio_device_id mtk_sdio_ids[] = {
223 #if defined(MT6620)
224         { SDIO_DEVICE(0x037a, 0x020a) }, /* Not an SDIO standard class device */
225         { SDIO_DEVICE(0x037a, 0x020b) }, /* Not an SDIO standard class device */
226         { SDIO_DEVICE(0x037a, 0x020c) }, /* Not an SDIO standard class device */
227 #elif defined(MT5931)
228         { SDIO_DEVICE(0x037a, 0x5931) }, /* Not an SDIO standard class device */
229 #elif defined(MT6628)
230         { SDIO_DEVICE(0x037a, 0x6628) }, /* Not an SDIO standard class device */
231 #endif
232         { /* end: all zeroes */ },
233 };
234
235 MODULE_DEVICE_TABLE(sdio, mtk_sdio_ids);
236
237 #endif
238
239 /*******************************************************************************
240 *                             D A T A   T Y P E S
241 ********************************************************************************
242 */
243
244
245 /*******************************************************************************
246 *                            P U B L I C   D A T A
247 ********************************************************************************
248 */
249 extern KAL_WAKE_LOCK_T isr_wakelock;
250
251 /*******************************************************************************
252 *                           P R I V A T E   D A T A
253 ********************************************************************************
254 */
255 static probe_card pfWlanProbe = NULL;
256 static remove_card pfWlanRemove = NULL;
257
258
259 #if (MTK_WCN_HIF_SDIO == 0)
260 static struct sdio_driver mtk_sdio_driver = {
261         .name           = "wlan", /* "MTK SDIO WLAN Driver" */
262         .id_table       = mtk_sdio_ids,
263         .probe          = NULL,
264         .remove         = NULL,
265 };
266 #endif
267
268
269 #if CFG_DBG_GPIO_PINS
270
271 /* debug pins */
272 UINT_32 dbgPinSTP[] = {
273     GPIO_PLATFORM(33)/* CMFLASH, IDX_ERR J613 */
274     , GPIO_PLATFORM(62)/* EINT3, IDX_TX_THREAD */
275     , GPIO_PLATFORM(80)/* SPI_CS_N, IDX_TX_REQ J613 */
276     , GPIO_PLATFORM(81)/* SPI_SCK, IDX_TX_PORT_WRITE J613 */
277     , GPIO_PLATFORM(17) /* CMRST, IDX_STP_MTX_BT J618 */
278     , GPIO_PLATFORM(18) /* CMPDN, IDX_STP_MTX_FM J613 */
279     , GPIO_PLATFORM(19) /* CMVREF,IDX_STP_MTX_GPS J613 */
280     , GPIO_INVALID /* REMOVED, IDX_STP_MTX_WIFI */
281     , GPIO_INVALID /* REMOVED, IDX_STP_MTX_WMT */
282     , GPIO_PLATFORM(135) /* SCL2, IDX_LOOP_CNT  J616 */
283     , GPIO_PLATFORM(136) /* SDA2, IDX_NO_BUF J616 */
284     , GPIO_PLATFORM(30) /* CAM_MECHSH0, IDX_BT_TX, J613 low-active */
285     , GPIO_PLATFORM(31) /* CAM_MECHSH1, IDX_BT_RX, J613 low-active */
286     , GPIO_PLATFORM(124) /* GPS_PWR_EN, ThreadDSPIn [GPS] */
287     , GPIO_PLATFORM(125) /* GPS_SYNC, mtk_sys_msg_recv [GPS] */
288     , GPIO_PLATFORM(21) /* GPS_EINT8, dump_nmea_data [GPS] */
289     , GPIO_PLATFORM(29) /* CAM_STROBE, IDX_GPS_TX, J613 low-active */
290     , GPIO_PLATFORM(20) /*CMHREF, J613 UNUSED */
291 //    , GPIO_6516(64) /* EINT5, REMOVED!!! for MT6620-Wi-Fi Int */
292 //    , GPIO_6516(122) /* BT_PWR_EN, REMOVED!!! for MT6620-PMU_EN */
293 //    , GPIO_6516(123) /* BT_RESET, REMOVED!!! for MT6620-RST */
294 };
295 #endif
296 /*******************************************************************************
297 *                                 M A C R O S
298 ********************************************************************************
299 */
300
301 /*******************************************************************************
302 *                   F U N C T I O N   D E C L A R A T I O N S
303 ********************************************************************************
304 */
305
306 /*******************************************************************************
307 *                              F U N C T I O N S
308 ********************************************************************************
309 */
310 #if CFG_DBG_GPIO_PINS
311 void debug_gpio_init(void)
312 {
313     int i;
314
315     for (i = 0; i < sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]); ++i) {
316         if (GPIO_INVALID == dbgPinSTP[i]) {
317             continue;
318         }
319         //printk(KERN_INFO "[%s] %ld \n", __FUNCTION__, dbgPinSTP[i]);
320         mt_set_gpio_pull_enable(dbgPinSTP[i], 0); /* disable pull */
321         mt_set_gpio_dir(dbgPinSTP[i], GPIO_DIR_OUT); /* set output */
322         mt_set_gpio_mode(dbgPinSTP[i], GPIO_MODE_00); /* set gpio mode */
323
324         /* toggle twice to check if ok: */
325         mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ZERO); /* tie low */
326         mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ONE); /* tie high*/
327         mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ZERO); /* tie low */
328         mt_set_gpio_out(dbgPinSTP[i], GPIO_OUT_ONE); /* tie high*/
329     }
330     //printk(KERN_INFO "[%s] initialization ok \n", __FUNCTION__);
331 }
332
333 void debug_gpio_deinit(void)
334 {
335     int i;
336     for (i = 0; i < sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]); ++i) {
337         if (GPIO_INVALID == dbgPinSTP[i]) {
338             continue;
339         }
340         //printk(KERN_INFO "[%s] %ld \n", __FUNCTION__, dbgPinSTP[i]);
341         mt_set_gpio_dir(dbgPinSTP[i], GPIO_DIR_IN);
342     }
343
344     //printk(KERN_INFO "[%s] k\n", __FUNCTION__);
345 }
346
347 void mtk_wcn_stp_debug_gpio_assert(UINT_32 dwIndex, UINT_32 dwMethod)
348 {
349     unsigned int i;
350
351     if (dwIndex >= (sizeof(dbgPinSTP)/sizeof(dbgPinSTP[0]))) {
352         //printk(KERN_INFO "[%s] invalid dwIndex(%ld) \n", __FUNCTION__, dwIndex);
353         return;
354     }
355
356     if (dwIndex > IDX_STP_MAX) {
357         //printk(KERN_INFO "[%s] dwIndex(%ld) > IDX_STP_MAX(%d) \n", __FUNCTION__, dwIndex, IDX_STP_MAX);
358     }
359
360     if (GPIO_INVALID == dbgPinSTP[dwIndex]) {
361         return;
362     }
363
364     if (dwMethod & DBG_TIE_DIR) {
365         if (dwMethod & DBG_HIGH) {
366             mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ONE);
367         }
368         else {
369             mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ZERO);
370         }
371         return;
372     }
373
374     if (dwMethod & DBG_TOGGLE(0)) {
375         for (i = 0; i < DBG_TOGGLE_NUM(dwMethod); ++i) {
376             mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ZERO);
377             mt_set_gpio_out(dbgPinSTP[dwIndex], GPIO_OUT_ONE);
378         }
379         return;
380     }
381
382     return;
383 }
384 #endif
385
386 /*----------------------------------------------------------------------------*/
387 /*!
388 * \brief This function is a SDIO interrupt callback function
389 *
390 * \param[in] func  pointer to SDIO handle
391 *
392 * \return void
393 */
394 /*----------------------------------------------------------------------------*/
395
396 #if MTK_WCN_HIF_SDIO
397
398 static INT32 mtk_sdio_interrupt(MTK_WCN_HIF_SDIO_CLTCTX cltCtx)
399 {
400     P_GLUE_INFO_T prGlueInfo = NULL;
401     INT32 ret = 0;
402
403     prGlueInfo = mtk_wcn_hif_sdio_get_drvdata(cltCtx);
404
405     ASSERT(prGlueInfo);
406
407     if (!prGlueInfo) {
408         //printk(KERN_INFO DRV_NAME"No glue info in mtk_sdio_interrupt()\n");
409         return (-HIF_SDIO_ERR_FAIL);
410     }
411
412     if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
413         //printk(KERN_INFO DRV_NAME"GLUE_FLAG_HALT skip INT\n");
414         ret = mtk_wcn_hif_sdio_writel(cltCtx, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
415         return ret;
416     }
417      /*WCNCR 00002676*/
418     KAL_WAKE_UNLOCK(NULL, &isr_wakelock);
419     KAL_WAKE_LOCK_TIMEOUT(NULL, &isr_wakelock, KAL_HZ/10);
420     ret = mtk_wcn_hif_sdio_writel(cltCtx, MCR_WHLPCR, WHLPCR_INT_EN_CLR);
421
422     set_bit (GLUE_FLAG_INT_BIT, &prGlueInfo->u4Flag);
423
424     /* when we got sdio interrupt, we wake up the tx servie thread*/
425     wake_up_interruptible(&prGlueInfo->waitq);
426
427     return ret;
428 }
429
430 #else
431
432 static unsigned int in_interrupt = 0;
433
434 static void mtk_sdio_interrupt(struct sdio_func *func)
435 {
436     P_GLUE_INFO_T prGlueInfo = NULL;
437
438     int ret = 0;
439
440     prGlueInfo = sdio_get_drvdata(func);
441     ASSERT(prGlueInfo);
442
443     if (!prGlueInfo) {
444         //printk(KERN_INFO DRV_NAME"No glue info in mtk_sdio_interrupt()\n");
445         return;
446     }
447
448     if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
449         sdio_writel(prGlueInfo->rHifInfo.func, WHLPCR_INT_EN_CLR, MCR_WHLPCR, &ret);
450         //printk(KERN_INFO DRV_NAME"GLUE_FLAG_HALT skip INT\n");
451         return;
452     }
453
454     sdio_writel(prGlueInfo->rHifInfo.func, WHLPCR_INT_EN_CLR, MCR_WHLPCR, &ret);
455
456     #if 0
457     wlanISR(prGlueInfo->prAdapter, TRUE);
458
459     if (prGlueInfo->u4Flag & GLUE_FLAG_HALT) {
460         /* Should stop now... skip pending interrupt */
461         //printk(KERN_INFO DRV_NAME"ignore pending interrupt\n");
462     }
463     else {
464         wlanIST(prGlueInfo->prAdapter);
465     }
466     #endif
467
468     set_bit (GLUE_FLAG_INT_BIT, &prGlueInfo->u4Flag);
469
470     /* when we got sdio interrupt, we wake up the tx servie thread*/
471     wake_up_interruptible(&prGlueInfo->waitq);
472 }
473 #endif
474
475 /*----------------------------------------------------------------------------*/
476 /*!
477 * \brief This function is a SDIO probe function
478 *
479 * \param[in] func   pointer to SDIO handle
480 * \param[in] id     pointer to SDIO device id table
481 *
482 * \return void
483 */
484 /*----------------------------------------------------------------------------*/
485
486 #if MTK_WCN_HIF_SDIO
487
488 // FIXME: global variable
489 static const MTK_WCN_HIF_SDIO_FUNCINFO *prFunc;
490
491
492 static INT32
493 mtk_sdio_probe(MTK_WCN_HIF_SDIO_CLTCTX cltCtx, const MTK_WCN_HIF_SDIO_FUNCINFO *prFuncInfo)
494 {
495     INT32 ret = HIF_SDIO_ERR_SUCCESS;
496
497     prFunc = prFuncInfo;
498
499     if (pfWlanProbe((PVOID) &cltCtx) != WLAN_STATUS_SUCCESS) {
500         //printk(KERN_WARNING DRV_NAME"pfWlanProbe fail!call pfWlanRemove()\n");
501         pfWlanRemove();
502         ret = -(HIF_SDIO_ERR_FAIL);
503     } else {
504         //printk(KERN_INFO DRV_NAME"mtk_wifi_sdio_probe() done(%d)\n", ret);
505     }
506     return ret;
507 }
508 #else
509 static int mtk_sdio_probe (
510     struct sdio_func *func,
511     const struct sdio_device_id *id
512     )
513 {
514     int ret = 0;
515     int i = 0;
516
517     //printk(KERN_INFO DRV_NAME "mtk_sdio_probe()\n");
518
519     ASSERT(func);
520     ASSERT(id);
521
522     //printk(KERN_INFO DRV_NAME "Basic struct size checking...\n");
523     //printk(KERN_INFO DRV_NAME "sizeof(struct device) = %d\n", sizeof(struct device));
524     //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_host) = %d\n", sizeof(struct mmc_host));
525     //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_card) = %d\n", sizeof(struct mmc_card));
526     //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_driver) = %d\n", sizeof(struct mmc_driver));
527     //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_data) = %d\n", sizeof(struct mmc_data));
528     //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_command) = %d\n", sizeof(struct mmc_command));
529     //printk(KERN_INFO DRV_NAME "sizeof(struct mmc_request) = %d\n", sizeof(struct mmc_request));
530     //printk(KERN_INFO DRV_NAME "sizeof(struct sdio_func) = %d\n", sizeof(struct sdio_func));
531
532     //printk(KERN_INFO DRV_NAME "Card information checking...\n");
533     //printk(KERN_INFO DRV_NAME "func = 0x%p\n", func);
534     //printk(KERN_INFO DRV_NAME "Number of info = %d:\n", func->card->num_info);
535
536     for (i = 0; i < func->card->num_info; i++) {
537         //printk(KERN_INFO DRV_NAME "info[%d]: %s\n", i, func->card->info[i]);
538     }
539
540     sdio_claim_host(func);
541     ret = sdio_enable_func(func);
542     sdio_release_host(func);
543
544     if (ret) {
545         //printk(KERN_INFO DRV_NAME"sdio_enable_func failed!\n");
546         goto out;
547     }
548     //printk(KERN_INFO DRV_NAME"sdio_enable_func done!\n");
549
550     if (pfWlanProbe((PVOID)func) != WLAN_STATUS_SUCCESS) {
551         //printk(KERN_WARNING DRV_NAME"pfWlanProbe fail!call pfWlanRemove()\n");
552         pfWlanRemove();
553         ret = -1;
554     }
555     else {
556 #if CFG_DBG_GPIO_PINS
557     //printk(KERN_INFO "[%s] init debug gpio, 20100815 \n", __FUNCTION__);
558     /* Debug pins initialization */
559     debug_gpio_init();
560 #endif
561     }
562
563 out:
564     //printk(KERN_INFO DRV_NAME"mtk_sdio_probe() done(%d)\n", ret);
565     return ret;
566 }
567 #endif
568
569
570 #if MTK_WCN_HIF_SDIO
571 static INT32
572 mtk_sdio_remove(MTK_WCN_HIF_SDIO_CLTCTX cltCtx)
573 {
574     INT32 ret = HIF_SDIO_ERR_SUCCESS;
575     //printk(KERN_INFO DRV_NAME"pfWlanRemove done\n");
576     pfWlanRemove();
577
578     return ret;
579 }
580 #else
581 static void
582 mtk_sdio_remove (
583     struct sdio_func *func
584     )
585 {
586     //printk(KERN_INFO DRV_NAME"mtk_sdio_remove()\n");
587
588 #if CFG_DBG_GPIO_PINS
589     //printk(KERN_INFO "[%s] deinit debug gpio \n", __FUNCTION__);
590     debug_gpio_deinit();
591 #endif
592
593     ASSERT(func);
594     //printk(KERN_INFO DRV_NAME"pfWlanRemove done\n");
595     pfWlanRemove();
596
597     sdio_claim_host(func);
598     sdio_disable_func(func);
599     //printk(KERN_INFO DRV_NAME"sdio_disable_func() done\n");
600     sdio_release_host(func);
601
602     //printk(KERN_INFO DRV_NAME"mtk_sdio_remove() done\n");
603 }
604 #endif
605
606 #if (MTK_WCN_HIF_SDIO == 0)
607 static int
608 mtk_sdio_suspend (
609     struct device * pDev,
610     pm_message_t state
611     )
612 {
613     //printk(KERN_INFO "mtk_sdio: mtk_sdio_suspend dev(0x%p)\n", pDev);
614     //printk(KERN_INFO "mtk_sdio: MediaTek SDIO WLAN driver\n");
615
616     return 0;
617 }
618
619 int mtk_sdio_resume (
620     struct device * pDev
621     )
622 {
623     //printk(KERN_INFO "mtk_sdio: mtk_sdio_resume dev(0x%p)\n", pDev);
624
625     return 0;
626 }
627 #endif
628
629
630 /*----------------------------------------------------------------------------*/
631 /*!
632 * \brief This function will register sdio bus to the os
633 *
634 * \param[in] pfProbe    Function pointer to detect card
635 * \param[in] pfRemove   Function pointer to remove card
636 *
637 * \return The result of registering sdio bus
638 */
639 /*----------------------------------------------------------------------------*/
640 WLAN_STATUS
641 glRegisterBus (
642     probe_card pfProbe,
643     remove_card pfRemove
644     )
645 {
646     int ret = 0;
647
648     ASSERT(pfProbe);
649     ASSERT(pfRemove);
650
651     //printk(KERN_INFO "mtk_sdio: MediaTek SDIO WLAN driver\n");
652     //printk(KERN_INFO "mtk_sdio: Copyright MediaTek Inc.\n");
653
654     pfWlanProbe = pfProbe;
655     pfWlanRemove = pfRemove;
656
657 #if MTK_WCN_HIF_SDIO
658     /* register MTK sdio client */
659     ret = ((mtk_wcn_hif_sdio_client_reg(&cltInfo) == HIF_SDIO_ERR_SUCCESS) ? WLAN_STATUS_SUCCESS : WLAN_STATUS_FAILURE);
660 #else
661     mtk_sdio_driver.probe = mtk_sdio_probe;
662     mtk_sdio_driver.remove = mtk_sdio_remove;
663
664     mtk_sdio_driver.drv.suspend = mtk_sdio_suspend;
665     mtk_sdio_driver.drv.resume = mtk_sdio_resume;
666
667     ret = (sdio_register_driver(&mtk_sdio_driver) == 0) ? WLAN_STATUS_SUCCESS : WLAN_STATUS_FAILURE;
668 #endif
669
670     return ret;
671 } /* end of glRegisterBus() */
672
673
674 /*----------------------------------------------------------------------------*/
675 /*!
676 * \brief This function will unregister sdio bus to the os
677 *
678 * \param[in] pfRemove   Function pointer to remove card
679 *
680 * \return (none)
681 */
682 /*----------------------------------------------------------------------------*/
683 VOID
684 glUnregisterBus(
685     remove_card pfRemove
686     )
687 {
688     ASSERT(pfRemove);
689     pfRemove();
690
691 #if MTK_WCN_HIF_SDIO
692     /* unregister MTK sdio client */
693     mtk_wcn_hif_sdio_client_unreg(&cltInfo);
694 #else
695     sdio_unregister_driver(&mtk_sdio_driver);
696 #endif
697
698     return;
699 } /* end of glUnregisterBus() */
700
701
702 /*----------------------------------------------------------------------------*/
703 /*!
704 * \brief This function stores hif related info, which is initialized before.
705 *
706 * \param[in] prGlueInfo Pointer to glue info structure
707 * \param[in] u4Cookie   Pointer to UINT_32 memory base variable for _HIF_HPI
708 *
709 * \return (none)
710 */
711 /*----------------------------------------------------------------------------*/
712 VOID
713 glSetHifInfo (
714     P_GLUE_INFO_T prGlueInfo,
715     UINT_32 u4Cookie
716     )
717 {
718     P_GL_HIF_INFO_T prHif = NULL;
719
720     prHif = &prGlueInfo->rHifInfo;
721
722 #if MTK_WCN_HIF_SDIO
723     //prHif->prFuncInfo = ((MTK_WCN_HIF_SDIO_FUNCINFO *) u4Cookie);
724     prHif->prFuncInfo = prFunc;
725     prHif->cltCtx = *((MTK_WCN_HIF_SDIO_CLTCTX *) u4Cookie);
726     mtk_wcn_hif_sdio_set_drvdata(prHif->cltCtx, prGlueInfo);
727
728 #else
729     prHif->func = (struct sdio_func *) u4Cookie;
730
731     //printk(KERN_INFO DRV_NAME"prHif->func->dev = 0x%p\n", &prHif->func->dev);
732     //printk(KERN_INFO DRV_NAME"prHif->func->vendor = 0x%04X\n", prHif->func->vendor);
733     //printk(KERN_INFO DRV_NAME"prHif->func->device = 0x%04X\n", prHif->func->device);
734     //printk(KERN_INFO DRV_NAME"prHif->func->func = 0x%04X\n", prHif->func->num);
735
736     sdio_set_drvdata(prHif->func, prGlueInfo);
737
738     SET_NETDEV_DEV(prGlueInfo->prDevHandler, &prHif->func->dev);
739 #endif
740
741     return;
742 } /* end of glSetHifInfo() */
743
744 /*----------------------------------------------------------------------------*/
745 /*!
746 * \brief This function clears hif related info.
747 *
748 * \param[in] prGlueInfo Pointer to glue info structure
749 *
750 * \return (none)
751 */
752 /*----------------------------------------------------------------------------*/
753 VOID
754 glClearHifInfo (
755     P_GLUE_INFO_T prGlueInfo
756     )
757 {
758     //P_GL_HIF_INFO_T prHif = NULL;
759     //ASSERT(prGlueInfo);
760     //prHif = &prGlueInfo->rHifInfo;
761
762     return;
763 } /* end of glClearHifInfo() */
764
765
766 /*----------------------------------------------------------------------------*/
767 /*!
768 * \brief Initialize bus operation and hif related information, request resources.
769 *
770 * \param[out] pvData    A pointer to HIF-specific data type buffer.
771 *                       For eHPI, pvData is a pointer to UINT_32 type and stores a
772 *                       mapped base address.
773 *
774 * \return (none)
775 */
776 /*----------------------------------------------------------------------------*/
777 BOOL
778 glBusInit (
779     PVOID pvData
780     )
781 {
782 #if (MTK_WCN_HIF_SDIO == 0)
783     int ret = 0;
784     struct sdio_func *func = NULL;
785
786     ASSERT(pvData);
787
788     func = (struct sdio_func *) pvData;
789
790     sdio_claim_host(func);
791     ret = sdio_set_block_size(func, 512);
792     sdio_release_host(func);
793
794     if (ret) {
795         //printk(KERN_INFO DRV_NAME"sdio_set_block_size 512 failed!\n");
796     }
797     else {
798         //printk(KERN_INFO DRV_NAME"sdio_set_block_size 512 done!\n");
799     }
800
801     //printk(KERN_INFO DRV_NAME"param: func->cur_blksize(%d)\n", func->cur_blksize);
802     //printk(KERN_INFO DRV_NAME"param: func->max_blksize(%d)\n", func->max_blksize);
803     //printk(KERN_INFO DRV_NAME"param: func->card->host->max_blk_size(%d)\n", func->card->host->max_blk_size);
804     //printk(KERN_INFO DRV_NAME"param: func->card->host->max_blk_count(%d)\n", func->card->host->max_blk_count);
805 #endif
806     return TRUE;
807 } /* end of glBusInit() */
808
809
810 /*----------------------------------------------------------------------------*/
811 /*!
812 * \brief Stop bus operation and release resources.
813 *
814 * \param[in] pvData A pointer to struct net_device.
815 *
816 * \return (none)
817 */
818 /*----------------------------------------------------------------------------*/
819 VOID
820 glBusRelease (
821     PVOID pvData
822     )
823 {
824
825     return;
826 } /* end of glBusRelease() */
827
828
829 /*----------------------------------------------------------------------------*/
830 /*!
831 * \brief Setup bus interrupt operation and interrupt handler for os.
832 *
833 * \param[in] pvData     A pointer to struct net_device.
834 * \param[in] pfnIsr     A pointer to interrupt handler function.
835 * \param[in] pvCookie   Private data for pfnIsr function.
836 *
837 * \retval WLAN_STATUS_SUCCESS   if success
838 *         NEGATIVE_VALUE   if fail
839 */
840 /*----------------------------------------------------------------------------*/
841 INT_32
842 glBusSetIrq (
843     PVOID pvData,
844     PVOID pfnIsr,
845     PVOID pvCookie
846     )
847 {
848     int ret = 0;
849
850 #if (MTK_WCN_HIF_SDIO == 0)
851     struct net_device *prNetDevice = NULL;
852     P_GLUE_INFO_T prGlueInfo = NULL;
853     P_GL_HIF_INFO_T prHifInfo = NULL;
854
855     ASSERT(pvData);
856     if (!pvData) {
857         return -1;
858     }
859     prNetDevice = (struct net_device *) pvData;
860     prGlueInfo = (P_GLUE_INFO_T) pvCookie;
861     ASSERT(prGlueInfo);
862     if (!prGlueInfo) {
863         return -1;
864     }
865
866     prHifInfo = &prGlueInfo->rHifInfo;
867
868     sdio_claim_host(prHifInfo->func);
869     ret = sdio_claim_irq(prHifInfo->func, mtk_sdio_interrupt);
870     sdio_release_host(prHifInfo->func);
871 #else
872                 /* hif_sdio case */
873                 struct net_device *prNetDevice = NULL;
874                 P_GLUE_INFO_T prGlueInfo = NULL;
875         
876                 ASSERT(pvData);
877                 if (!pvData) {
878                         return -1;
879                 }
880                 prNetDevice = (struct net_device *) pvData;
881         
882                 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
883                 ASSERT(prGlueInfo);
884                 if (!prGlueInfo) {
885                         return -1;
886                 }
887         
888                 mtk_wcn_hif_sdio_enable_irq(prGlueInfo->rHifInfo.cltCtx, MTK_WCN_BOOL_TRUE);
889
890 #endif
891     return ret;
892 } /* end of glBusSetIrq() */
893
894
895 /*----------------------------------------------------------------------------*/
896 /*!
897 * \brief Stop bus interrupt operation and disable interrupt handling for os.
898 *
899 * \param[in] pvData     A pointer to struct net_device.
900 * \param[in] pvCookie   Private data for pfnIsr function.
901 *
902 * \return (none)
903 */
904 /*----------------------------------------------------------------------------*/
905 VOID
906 glBusFreeIrq (
907     PVOID pvData,
908     PVOID pvCookie
909     )
910 {
911 #if (MTK_WCN_HIF_SDIO == 0)
912     struct net_device *prNetDevice = NULL;
913     P_GLUE_INFO_T prGlueInfo = NULL;
914     P_GL_HIF_INFO_T prHifInfo = NULL;
915     int ret = 0;
916
917     ASSERT(pvData);
918     if (!pvData) {
919         //printk(KERN_INFO DRV_NAME"%s null pvData\n", __FUNCTION__);
920         return;
921     }
922     prNetDevice = (struct net_device *) pvData;
923     prGlueInfo = (P_GLUE_INFO_T) pvCookie;
924     ASSERT(prGlueInfo);
925     if (!prGlueInfo) {
926         //printk(KERN_INFO DRV_NAME"%s no glue info\n", __FUNCTION__);
927         return;
928     }
929
930     prHifInfo = &prGlueInfo->rHifInfo;
931
932     sdio_claim_host(prHifInfo->func);
933     ret = sdio_release_irq(prHifInfo->func);
934     sdio_release_host(prHifInfo->func);
935 #else
936                 /* hif_sdio case */
937                 struct net_device *prNetDevice = NULL;
938                 P_GLUE_INFO_T prGlueInfo = NULL;
939         
940                 ASSERT(pvData);
941                 if (!pvData) {
942                         //printk(KERN_INFO DRV_NAME"%s null pvData\n", __FUNCTION__);
943                         return;
944                 }
945                 prNetDevice = (struct net_device *) pvData;
946         
947                 prGlueInfo = (P_GLUE_INFO_T) pvCookie;
948                 ASSERT(prGlueInfo);
949                 if (!prGlueInfo) {
950                         //printk(KERN_INFO DRV_NAME"%s no glue info\n", __FUNCTION__);
951                         return;
952                 }
953         
954                 mtk_wcn_hif_sdio_enable_irq(prGlueInfo->rHifInfo.cltCtx, MTK_WCN_BOOL_FALSE);
955
956 #endif
957
958     return;
959 } /* end of glBusreeIrq() */
960
961
962 /*----------------------------------------------------------------------------*/
963 /*!
964 * \brief Read a 32-bit device register
965 *
966 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
967 * \param[in] u4Register Register offset
968 * \param[in] pu4Value   Pointer to variable used to store read value
969 *
970 * \retval TRUE          operation success
971 * \retval FALSE         operation fail
972 */
973 /*----------------------------------------------------------------------------*/
974 BOOL
975 kalDevRegRead (
976     IN  P_GLUE_INFO_T   prGlueInfo,
977     IN  UINT_32         u4Register,
978     OUT PUINT_32        pu4Value
979     )
980 {
981     int ret = 0;
982
983     ASSERT(prGlueInfo);
984     ASSERT(pu4Value);
985
986 #if MTK_WCN_HIF_SDIO
987     ret = mtk_wcn_hif_sdio_readl(prGlueInfo->rHifInfo.cltCtx, u4Register, (PUINT32) pu4Value);
988 #else
989     if (!in_interrupt) {
990         sdio_claim_host(prGlueInfo->rHifInfo.func);
991     }
992
993     *pu4Value = sdio_readl(prGlueInfo->rHifInfo.func, u4Register, &ret);
994
995     if (!in_interrupt) {
996         sdio_release_host(prGlueInfo->rHifInfo.func);
997     }
998 #endif
999
1000     if (ret) {
1001         kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_readl() reports error: %x", ret);
1002         DBGLOG(HAL, ERROR, ("sdio_readl() reports error: %x", ret));
1003     }
1004
1005     return (ret) ? FALSE : TRUE;
1006 } /* end of kalDevRegRead() */
1007
1008
1009 /*----------------------------------------------------------------------------*/
1010 /*!
1011 * \brief Write a 32-bit device register
1012 *
1013 * \param[in] prGlueInfo Pointer to the GLUE_INFO_T structure.
1014 * \param[in] u4Register Register offset
1015 * \param[in] u4Value    Value to be written
1016 *
1017 * \retval TRUE          operation success
1018 * \retval FALSE         operation fail
1019 */
1020 /*----------------------------------------------------------------------------*/
1021 BOOL
1022 kalDevRegWrite (
1023     IN P_GLUE_INFO_T  prGlueInfo,
1024     IN UINT_32        u4Register,
1025     IN UINT_32        u4Value
1026     )
1027 {
1028     int ret = 0;
1029
1030     ASSERT(prGlueInfo);
1031
1032 #if MTK_WCN_HIF_SDIO
1033     ret = mtk_wcn_hif_sdio_writel(prGlueInfo->rHifInfo.cltCtx, u4Register, u4Value);
1034 #else
1035     if (!in_interrupt) {
1036         sdio_claim_host(prGlueInfo->rHifInfo.func);
1037     }
1038
1039     sdio_writel(prGlueInfo->rHifInfo.func, u4Value, u4Register, &ret);
1040
1041     if (!in_interrupt) {
1042         sdio_release_host(prGlueInfo->rHifInfo.func);
1043     }
1044 #endif
1045
1046     if (ret) {
1047         kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writel() reports error: %x", ret);
1048         DBGLOG(HAL, ERROR, ("sdio_writel() reports error: %x", ret));
1049     }
1050
1051     return (ret) ? FALSE : TRUE;
1052 } /* end of kalDevRegWrite() */
1053
1054
1055 /*----------------------------------------------------------------------------*/
1056 /*!
1057 * \brief Read device I/O port
1058 *
1059 * \param[in] prGlueInfo         Pointer to the GLUE_INFO_T structure.
1060 * \param[in] u2Port             I/O port offset
1061 * \param[in] u2Len              Length to be read
1062 * \param[out] pucBuf            Pointer to read buffer
1063 * \param[in] u2ValidOutBufSize  Length of the buffer valid to be accessed
1064 *
1065 * \retval TRUE          operation success
1066 * \retval FALSE         operation fail
1067 */
1068 /*----------------------------------------------------------------------------*/
1069 BOOL
1070 kalDevPortRead (
1071     IN  P_GLUE_INFO_T   prGlueInfo,
1072     IN  UINT_16         u2Port,
1073     IN  UINT_16         u2Len,
1074     OUT PUINT_8         pucBuf,
1075     IN  UINT_16         u2ValidOutBufSize
1076     )
1077 {
1078     P_GL_HIF_INFO_T prHifInfo = NULL;
1079     PUINT_8 pucDst = NULL;
1080     int count = u2Len;
1081     int ret = 0;
1082     int bNum = 0;
1083
1084 #if (MTK_WCN_HIF_SDIO == 0)
1085     struct sdio_func *prSdioFunc = NULL;
1086 #endif
1087
1088     #if DBG
1089     //printk(KERN_INFO DRV_NAME"++kalDevPortRead++ buf:0x%p, port:0x%x, length:%d\n", pucBuf, u2Port, u2Len);
1090     #endif
1091
1092     ASSERT(prGlueInfo);
1093     prHifInfo = &prGlueInfo->rHifInfo;
1094
1095     ASSERT(pucBuf);
1096     pucDst = pucBuf;
1097
1098     ASSERT(u2Len <= u2ValidOutBufSize);
1099
1100 #if (MTK_WCN_HIF_SDIO == 0)
1101     prSdioFunc = prHifInfo->func;
1102
1103     ASSERT(prSdioFunc->cur_blksize > 0);
1104
1105     if (!in_interrupt) {
1106         sdio_claim_host(prSdioFunc);
1107     }
1108
1109     /* Split buffer into multiple single block to workaround hifsys */
1110     while (count >= prSdioFunc->cur_blksize) {
1111         count -= prSdioFunc->cur_blksize;
1112         bNum++;
1113     }
1114     if (count > 0 && bNum > 0) {
1115         bNum++;
1116     }
1117
1118     if (bNum > 0) {
1119         ret = sdio_readsb(prSdioFunc, pucDst, u2Port, prSdioFunc->cur_blksize * bNum);
1120
1121 #ifdef CONFIG_X86
1122         /* ENE workaround */
1123         {
1124             int tmp;
1125             sdio_writel(prSdioFunc, 0x0, SDIO_X86_WORKAROUND_WRITE_MCR, &tmp);
1126         }
1127 #endif
1128
1129     }
1130     else {
1131         ret = sdio_readsb(prSdioFunc, pucDst, u2Port, count);
1132     }
1133
1134     if (!in_interrupt) {
1135         sdio_release_host(prSdioFunc);
1136     }
1137 #else
1138
1139     /* Split buffer into multiple single block to workaround hifsys */
1140     while (count >= (prGlueInfo->rHifInfo).prFuncInfo->blk_sz) {
1141         count -= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz);
1142         bNum++;
1143     }
1144     if (count > 0 && bNum > 0) {
1145         bNum++;
1146     }
1147
1148     if (bNum > 0) {
1149         ret = mtk_wcn_hif_sdio_read_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucDst,
1150                  ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz) * bNum);
1151     }
1152     else {
1153         ret = mtk_wcn_hif_sdio_read_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucDst, count);
1154     }
1155 #endif
1156
1157     if (ret) {
1158         kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_readsb() reports error: %x", ret);
1159         DBGLOG(HAL, ERROR, ("sdio_readsb() reports error: %x", ret));
1160     }
1161
1162     return (ret) ? FALSE : TRUE;
1163 } /* end of kalDevPortRead() */
1164
1165
1166 /*----------------------------------------------------------------------------*/
1167 /*!
1168 * \brief Write device I/O port
1169 *
1170 * \param[in] prGlueInfo         Pointer to the GLUE_INFO_T structure.
1171 * \param[in] u2Port             I/O port offset
1172 * \param[in] u2Len              Length to be write
1173 * \param[in] pucBuf             Pointer to write buffer
1174 * \param[in] u2ValidInBufSize   Length of the buffer valid to be accessed
1175 *
1176 * \retval TRUE          operation success
1177 * \retval FALSE         operation fail
1178 */
1179 /*----------------------------------------------------------------------------*/
1180 BOOL
1181 kalDevPortWrite (
1182     IN P_GLUE_INFO_T  prGlueInfo,
1183     IN UINT_16        u2Port,
1184     IN UINT_16        u2Len,
1185     IN PUINT_8        pucBuf,
1186     IN UINT_16        u2ValidInBufSize
1187     )
1188 {
1189     P_GL_HIF_INFO_T prHifInfo = NULL;
1190     PUINT_8 pucSrc = NULL;
1191     int count = u2Len;
1192     int ret = 0;
1193     int bNum = 0;
1194
1195 #if (MTK_WCN_HIF_SDIO == 0)
1196     struct sdio_func *prSdioFunc = NULL;
1197 #endif
1198
1199     #if DBG
1200     //printk(KERN_INFO DRV_NAME"++kalDevPortWrite++ buf:0x%p, port:0x%x, length:%d\n", pucBuf, u2Port, u2Len);
1201     #endif
1202
1203     ASSERT(prGlueInfo);
1204     prHifInfo = &prGlueInfo->rHifInfo;
1205
1206     ASSERT(pucBuf);
1207     pucSrc = pucBuf;
1208
1209     ASSERT(u2Len <= u2ValidInBufSize);
1210
1211 #if (MTK_WCN_HIF_SDIO == 0)
1212     prSdioFunc = prHifInfo->func;
1213     ASSERT(prSdioFunc->cur_blksize > 0);
1214
1215     if (!in_interrupt) {
1216         sdio_claim_host(prSdioFunc);
1217     }
1218
1219     /* Split buffer into multiple single block to workaround hifsys */
1220     while (count >= prSdioFunc->cur_blksize) {
1221         count -= prSdioFunc->cur_blksize;
1222         bNum++;
1223     }
1224     if (count > 0 && bNum > 0) {
1225         bNum++;
1226     }
1227
1228     if (bNum > 0) { // block mode
1229         ret = sdio_writesb(prSdioFunc, u2Port, pucSrc, prSdioFunc->cur_blksize * bNum);
1230
1231 #ifdef CONFIG_X86
1232         /* ENE workaround */
1233         {
1234             int tmp;
1235             sdio_writel(prSdioFunc, 0x0, SDIO_X86_WORKAROUND_WRITE_MCR, &tmp);
1236         }
1237 #endif
1238
1239     }
1240     else {  // byte mode
1241
1242         ret = sdio_writesb(prSdioFunc, u2Port, pucSrc, count);
1243     }
1244
1245     if (!in_interrupt) {
1246         sdio_release_host(prSdioFunc);
1247     }
1248 #else
1249     /* Split buffer into multiple single block to workaround hifsys */
1250     while (count >= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz)) {
1251         count -= ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz);
1252         bNum++;
1253     }
1254     if (count > 0 && bNum > 0) {
1255         bNum++;
1256     }
1257
1258     if (bNum > 0) { // block mode
1259         ret = mtk_wcn_hif_sdio_write_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucSrc,
1260                              ((prGlueInfo->rHifInfo).prFuncInfo->blk_sz) * bNum);
1261     }
1262     else {  // byte mode
1263         ret = mtk_wcn_hif_sdio_write_buf(prGlueInfo->rHifInfo.cltCtx, u2Port, (PUINT32) pucSrc, count);
1264     }
1265 #endif
1266
1267     if (ret) {
1268         kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writesb() reports error: %x", ret);
1269         DBGLOG(HAL, ERROR, ("sdio_writesb() reports error: %x", ret));
1270     }
1271
1272     return (ret) ? FALSE : TRUE;
1273 } /* end of kalDevPortWrite() */
1274
1275
1276 /*----------------------------------------------------------------------------*/
1277 /*!
1278 * \brief Write device I/O port in byte with CMD52
1279 *
1280 * \param[in] prGlueInfo         Pointer to the GLUE_INFO_T structure.
1281 * \param[in] u4Addr             I/O port offset
1282 * \param[in] ucData             Single byte of data to be written
1283 *
1284 * \retval TRUE          operation success
1285 * \retval FALSE         operation fail
1286 */
1287 /*----------------------------------------------------------------------------*/
1288 BOOL
1289 kalDevWriteWithSdioCmd52 (
1290     IN P_GLUE_INFO_T    prGlueInfo,
1291     IN UINT_32          u4Addr,
1292     IN UINT_8           ucData
1293     )
1294 {
1295     int ret = 0;
1296
1297 #if (MTK_WCN_HIF_SDIO == 0)
1298     if (!in_interrupt) {
1299         sdio_claim_host(prGlueInfo->rHifInfo.func);
1300     }
1301
1302     sdio_writeb(prGlueInfo->rHifInfo.func, ucData, u4Addr, &ret);
1303
1304     if (!in_interrupt) {
1305         sdio_release_host(prGlueInfo->rHifInfo.func);
1306     }
1307 #else
1308     ret = mtk_wcn_hif_sdio_writeb(prGlueInfo->rHifInfo.cltCtx, u4Addr, ucData);
1309 #endif
1310
1311     if (ret) {
1312         kalSendAeeWarning(HIF_SDIO_ERR_TITLE_STR, HIF_SDIO_ERR_DESC_STR "sdio_writeb() reports error: %x", ret);
1313         DBGLOG(HAL, ERROR, ("sdio_writeb() reports error: %x", ret));
1314     }
1315
1316     return (ret) ? FALSE : TRUE;
1317
1318 } /* end of kalDevWriteWithSdioCmd52() */
1319
1320
1321 VOID
1322 glSetPowerState (
1323     IN P_GLUE_INFO_T  prGlueInfo,
1324     IN UINT_32 ePowerMode
1325     )
1326 {
1327     return;
1328 }
1329