3 #define STATUS_IMAGE_CHECKSUM_MISMATCH -199
4 #define EVENT_SIGNALED 1
6 static B_UINT16 CFG_CalculateChecksum(B_UINT8 *pu8Buffer, B_UINT32 u32Size)
8 B_UINT16 u16CheckSum=0;
10 u16CheckSum += (B_UINT8)~(*pu8Buffer);
15 BOOLEAN IsReqGpioIsLedInNVM(PMINI_ADAPTER Adapter, UINT gpios)
18 Status = (Adapter->gpioBitMap & gpios) ^ gpios ;
25 static INT LED_Blink(PMINI_ADAPTER Adapter, UINT GPIO_Num, UCHAR uiLedIndex, ULONG timeout, INT num_of_time, LedEventInfo_t currdriverstate)
27 int Status = STATUS_SUCCESS;
28 BOOLEAN bInfinite = FALSE;
30 /*Check if num_of_time is -ve. If yes, blink led in infinite loop*/
39 if(currdriverstate == Adapter->DriverState)
40 TURN_ON_LED(GPIO_Num, uiLedIndex);
42 /*Wait for timeout after setting on the LED*/
43 Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
44 currdriverstate != Adapter->DriverState || kthread_should_stop(),
45 msecs_to_jiffies(timeout));
47 if(kthread_should_stop())
49 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
50 Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
51 TURN_OFF_LED(GPIO_Num, uiLedIndex);
52 Status=EVENT_SIGNALED;
57 TURN_OFF_LED(GPIO_Num, uiLedIndex);
58 Status=EVENT_SIGNALED;
62 TURN_OFF_LED(GPIO_Num, uiLedIndex);
63 Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
64 currdriverstate!= Adapter->DriverState || kthread_should_stop(),
65 msecs_to_jiffies(timeout));
66 if(bInfinite == FALSE)
72 static INT ScaleRateofTransfer(ULONG rate)
76 else if((rate > 3) && (rate <= 100))
78 else if((rate > 100) && (rate <= 200))
80 else if((rate > 200) && (rate <= 300))
82 else if((rate > 300) && (rate <= 400))
84 else if((rate > 400) && (rate <= 500))
86 else if((rate > 500) && (rate <= 600))
89 return MAX_NUM_OF_BLINKS;
94 static INT LED_Proportional_Blink(PMINI_ADAPTER Adapter, UCHAR GPIO_Num_tx,
95 UCHAR uiTxLedIndex, UCHAR GPIO_Num_rx, UCHAR uiRxLedIndex, LedEventInfo_t currdriverstate)
97 /* Initial values of TX and RX packets*/
98 ULONG64 Initial_num_of_packts_tx = 0, Initial_num_of_packts_rx = 0;
99 /*values of TX and RX packets after 1 sec*/
100 ULONG64 Final_num_of_packts_tx = 0, Final_num_of_packts_rx = 0;
101 /*Rate of transfer of Tx and Rx in 1 sec*/
102 ULONG64 rate_of_transfer_tx = 0, rate_of_transfer_rx = 0;
103 int Status = STATUS_SUCCESS;
104 INT num_of_time = 0, num_of_time_tx = 0, num_of_time_rx = 0;
106 BOOLEAN bBlinkBothLED = TRUE;
107 //UINT GPIO_num = DISABLE_GPIO_NUM;
110 /*Read initial value of packets sent/received */
111 Initial_num_of_packts_tx = atomic_read(&Adapter->TxTotalPacketCount);
112 Initial_num_of_packts_rx = atomic_read(&Adapter->GoodRxPktCount);
113 /*Scale the rate of transfer to no of blinks.*/
114 num_of_time_tx= ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
115 num_of_time_rx= ScaleRateofTransfer((ULONG)rate_of_transfer_rx);
117 while((Adapter->device_removed == FALSE))
120 if(0 == num_of_time_tx && 0 == num_of_time_rx)
123 Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
124 currdriverstate!= Adapter->DriverState || kthread_should_stop(),
125 msecs_to_jiffies (timeout));
126 if(kthread_should_stop())
128 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
129 Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
130 return EVENT_SIGNALED;
133 return EVENT_SIGNALED;
140 /*Turn on LED if Tx is high bandwidth*/
141 if(num_of_time_tx > MAX_NUM_OF_BLINKS)
143 TURN_ON_LED(1<<GPIO_Num_tx, uiTxLedIndex);
145 bBlinkBothLED = FALSE;
146 num_of_time = num_of_time_rx;
148 /*Turn on LED if Rx is high bandwidth*/
149 if(num_of_time_rx > MAX_NUM_OF_BLINKS)
151 TURN_ON_LED(1<<GPIO_Num_rx, uiRxLedIndex);
153 bBlinkBothLED = FALSE;
154 num_of_time = num_of_time_tx;
157 /*Blink Tx and Rx LED when both Tx and Rx is in normal bandwidth*/
160 /*Assign minimum number of blinks of either Tx or Rx.*/
161 if(num_of_time_tx > num_of_time_rx)
162 num_of_time = num_of_time_rx;
164 num_of_time = num_of_time_tx;
167 /*Blink both Tx and Rx LEDs*/
168 if(LED_Blink(Adapter, 1<<GPIO_Num_tx, uiTxLedIndex, timeout, num_of_time,currdriverstate)
171 return EVENT_SIGNALED;
173 if(LED_Blink(Adapter, 1<<GPIO_Num_rx, uiRxLedIndex, timeout, num_of_time,currdriverstate)
176 return EVENT_SIGNALED;
181 if(num_of_time == num_of_time_tx)
183 /*Blink pending rate of Rx*/
184 if(LED_Blink(Adapter, (1 << GPIO_Num_rx), uiRxLedIndex, timeout,
185 num_of_time_rx-num_of_time,currdriverstate) == EVENT_SIGNALED)
187 return EVENT_SIGNALED;
189 num_of_time = num_of_time_rx;
193 /*Blink pending rate of Tx*/
194 if(LED_Blink(Adapter, 1<<GPIO_Num_tx, uiTxLedIndex, timeout,
195 num_of_time_tx-num_of_time,currdriverstate) == EVENT_SIGNALED)
197 return EVENT_SIGNALED;
199 num_of_time = num_of_time_tx;
204 if(num_of_time == num_of_time_tx)
206 /*Blink pending rate of Rx*/
207 if(LED_Blink(Adapter, 1<<GPIO_Num_tx, uiTxLedIndex, timeout, num_of_time,currdriverstate)
210 return EVENT_SIGNALED;
215 /*Blink pending rate of Tx*/
216 if(LED_Blink(Adapter, 1<<GPIO_Num_rx, uiRxLedIndex, timeout,
217 num_of_time,currdriverstate) == EVENT_SIGNALED)
219 return EVENT_SIGNALED;
223 /* If Tx/Rx rate is less than maximum blinks per second,
224 * wait till delay completes to 1 second
226 remDelay = MAX_NUM_OF_BLINKS - num_of_time;
229 timeout= 100 * remDelay;
230 Status = wait_event_interruptible_timeout(Adapter->LEDInfo.notify_led_event,
231 currdriverstate!= Adapter->DriverState ||kthread_should_stop() ,
232 msecs_to_jiffies (timeout));
234 if(kthread_should_stop())
236 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
237 Adapter->LEDInfo.led_thread_running= BCM_LED_THREAD_DISABLED;
238 return EVENT_SIGNALED;
241 return EVENT_SIGNALED;
244 /*Turn off both Tx and Rx LEDs before next second*/
245 TURN_OFF_LED(1<<GPIO_Num_tx, uiTxLedIndex);
246 TURN_OFF_LED(1<<GPIO_Num_rx, uiTxLedIndex);
249 * Read the Tx & Rx packets transmission after 1 second and
250 * calculate rate of transfer
252 Final_num_of_packts_tx = atomic_read(&Adapter->TxTotalPacketCount);
253 rate_of_transfer_tx = Final_num_of_packts_tx - Initial_num_of_packts_tx;
254 Final_num_of_packts_rx = atomic_read(&Adapter->GoodRxPktCount);
255 rate_of_transfer_rx = Final_num_of_packts_rx - Initial_num_of_packts_rx;
257 /*Read initial value of packets sent/received */
258 Initial_num_of_packts_tx = Final_num_of_packts_tx;
259 Initial_num_of_packts_rx = Final_num_of_packts_rx ;
261 /*Scale the rate of transfer to no of blinks.*/
262 num_of_time_tx= ScaleRateofTransfer((ULONG)rate_of_transfer_tx);
263 num_of_time_rx= ScaleRateofTransfer((ULONG)rate_of_transfer_rx);
270 //-----------------------------------------------------------------------------
271 // Procedure: ValidateDSDParamsChecksum
273 // Description: Reads DSD Params and validates checkusm.
276 // Adapter - Pointer to Adapter structure.
277 // ulParamOffset - Start offset of the DSD parameter to be read and validated.
278 // usParamLen - Length of the DSD Parameter.
281 // <OSAL_STATUS_CODE>
282 //-----------------------------------------------------------------------------
284 static INT ValidateDSDParamsChecksum(
285 PMINI_ADAPTER Adapter,
289 INT Status = STATUS_SUCCESS;
290 PUCHAR puBuffer = NULL;
291 USHORT usChksmOrg = 0;
292 USHORT usChecksumCalculated = 0;
294 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread:ValidateDSDParamsChecksum: 0x%lx 0x%X",ulParamOffset, usParamLen);
296 puBuffer = OsalMemAlloc(usParamLen,"!MEM");
299 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum Allocation failed");
305 // Read the DSD data from the parameter offset.
307 if(STATUS_SUCCESS != BeceemNVMRead(Adapter,(PUINT)puBuffer,ulParamOffset,usParamLen))
309 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum BeceemNVMRead failed");
310 Status=STATUS_IMAGE_CHECKSUM_MISMATCH;
315 // Calculate the checksum of the data read from the DSD parameter.
317 usChecksumCalculated = CFG_CalculateChecksum(puBuffer,usParamLen);
318 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: usCheckSumCalculated = 0x%x\n", usChecksumCalculated);
321 // End of the DSD parameter will have a TWO bytes checksum stored in it. Read it and compare with the calculated
324 if(STATUS_SUCCESS != BeceemNVMRead(Adapter,(PUINT)&usChksmOrg,ulParamOffset+usParamLen,2))
326 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum BeceemNVMRead failed");
327 Status=STATUS_IMAGE_CHECKSUM_MISMATCH;
330 usChksmOrg = ntohs(usChksmOrg);
331 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: usChksmOrg = 0x%x", usChksmOrg);
334 // Compare the checksum calculated with the checksum read from DSD section
336 if(usChecksumCalculated ^ usChksmOrg)
338 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: ValidateDSDParamsChecksum: Checksums don't match");
339 Status = STATUS_IMAGE_CHECKSUM_MISMATCH;
346 OsalMemFree(puBuffer, usParamLen);
352 //-----------------------------------------------------------------------------
353 // Procedure: ValidateHWParmStructure
355 // Description: Validates HW Parameters.
358 // Adapter - Pointer to Adapter structure.
359 // ulHwParamOffset - Start offset of the HW parameter Section to be read and validated.
362 // <OSAL_STATUS_CODE>
363 //-----------------------------------------------------------------------------
365 static INT ValidateHWParmStructure(PMINI_ADAPTER Adapter, ULONG ulHwParamOffset)
368 INT Status = STATUS_SUCCESS ;
369 USHORT HwParamLen = 0;
370 // Add DSD start offset to the hwParamOffset to get the actual address.
371 ulHwParamOffset += DSD_START_OFFSET;
373 /*Read the Length of HW_PARAM structure*/
374 BeceemNVMRead(Adapter,(PUINT)&HwParamLen,ulHwParamOffset,2);
375 HwParamLen = ntohs(HwParamLen);
376 if(0==HwParamLen || HwParamLen > Adapter->uiNVMDSDSize)
378 return STATUS_IMAGE_CHECKSUM_MISMATCH;
381 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "LED Thread:HwParamLen = 0x%x", HwParamLen);
382 Status =ValidateDSDParamsChecksum(Adapter,ulHwParamOffset,HwParamLen);
384 } /* ValidateHWParmStructure() */
386 static int ReadLEDInformationFromEEPROM(PMINI_ADAPTER Adapter, UCHAR GPIO_Array[])
388 int Status = STATUS_SUCCESS;
390 ULONG dwReadValue = 0;
391 USHORT usHwParamData = 0;
392 USHORT usEEPROMVersion = 0;
394 UCHAR ucGPIOInfo[32] = {0};
396 BeceemNVMRead(Adapter,(PUINT)&usEEPROMVersion,EEPROM_VERSION_OFFSET,2);
398 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"usEEPROMVersion: Minor:0x%X Major:0x%x",usEEPROMVersion&0xFF, ((usEEPROMVersion>>8)&0xFF));
401 if(((usEEPROMVersion>>8)&0xFF) < EEPROM_MAP5_MAJORVERSION)
403 BeceemNVMRead(Adapter,(PUINT)&usHwParamData,EEPROM_HW_PARAM_POINTER_ADDRESS,2);
404 usHwParamData = ntohs(usHwParamData);
405 dwReadValue = usHwParamData;
410 // Validate Compatibility section and then read HW param if compatibility section is valid.
412 Status = ValidateDSDParamsChecksum(Adapter,
414 COMPATIBILITY_SECTION_LENGTH_MAP5);
416 if(Status != STATUS_SUCCESS)
420 BeceemNVMRead(Adapter,(PUINT)&dwReadValue,EEPROM_HW_PARAM_POINTER_ADDRRES_MAP5,4);
421 dwReadValue = ntohl(dwReadValue);
425 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: Start address of HW_PARAM structure = 0x%lx",dwReadValue);
428 // Validate if the address read out is within the DSD.
429 // Adapter->uiNVMDSDSize gives whole DSD size inclusive of Autoinit.
430 // lower limit should be above DSD_START_OFFSET and
431 // upper limit should be below (Adapter->uiNVMDSDSize-DSD_START_OFFSET)
433 if(dwReadValue < DSD_START_OFFSET ||
434 dwReadValue > (Adapter->uiNVMDSDSize-DSD_START_OFFSET))
436 return STATUS_IMAGE_CHECKSUM_MISMATCH;
439 Status = ValidateHWParmStructure(Adapter, dwReadValue);
445 Add DSD_START_OFFSET to the offset read from the EEPROM.
446 This will give the actual start HW Parameters start address.
447 To read GPIO section, add GPIO offset further.
450 dwReadValue += DSD_START_OFFSET; // = start address of hw param section.
451 dwReadValue += GPIO_SECTION_START_OFFSET; // = GPIO start offset within HW Param section.
453 /* Read the GPIO values for 32 GPIOs from EEPROM and map the function
454 * number to GPIO pin number to GPIO_Array
456 BeceemNVMRead(Adapter, (UINT *)ucGPIOInfo,dwReadValue,32);
457 for(ucIndex = 0; ucIndex < 32; ucIndex++)
460 switch(ucGPIOInfo[ucIndex])
464 GPIO_Array[RED_LED] = ucIndex;
465 Adapter->gpioBitMap |= (1<<ucIndex);
470 GPIO_Array[BLUE_LED] = ucIndex;
471 Adapter->gpioBitMap |= (1<<ucIndex);
476 GPIO_Array[YELLOW_LED] = ucIndex;
477 Adapter->gpioBitMap |= (1<<ucIndex);
482 GPIO_Array[GREEN_LED] = ucIndex;
483 Adapter->gpioBitMap |= (1<<ucIndex);
491 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"GPIO's bit map correspond to LED :0x%X",Adapter->gpioBitMap);
496 static int ReadConfigFileStructure(PMINI_ADAPTER Adapter, BOOLEAN *bEnableThread)
498 int Status = STATUS_SUCCESS;
499 UCHAR GPIO_Array[NUM_OF_LEDS+1]; /*Array to store GPIO numbers from EEPROM*/
501 UINT uiNum_of_LED_Type = 0;
502 PUCHAR puCFGData = NULL;
504 memset(GPIO_Array, DISABLE_GPIO_NUM, NUM_OF_LEDS+1);
506 if(!Adapter->pstargetparams || IS_ERR(Adapter->pstargetparams))
508 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Target Params not Avail.\n");
512 /*Populate GPIO_Array with GPIO numbers for LED functions*/
513 /*Read the GPIO numbers from EEPROM*/
514 Status = ReadLEDInformationFromEEPROM(Adapter, GPIO_Array);
515 if(Status == STATUS_IMAGE_CHECKSUM_MISMATCH)
517 *bEnableThread = FALSE;
518 return STATUS_SUCCESS;
522 *bEnableThread = FALSE;
526 * CONFIG file read successfully. Deallocate the memory of
527 * uiFileNameBufferSize
529 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: Config file read successfully\n");
530 puCFGData = (PUCHAR) &Adapter->pstargetparams->HostDrvrConfig1;
533 * Offset for HostDrvConfig1, HostDrvConfig2, HostDrvConfig3 which
534 * will have the information of LED type, LED on state for different
535 * driver state and LED blink state.
538 for(uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++)
542 /*Check Bit 8 for polarity. If it is set, polarity is reverse polarity*/
545 Adapter->LEDInfo.LEDState[uiIndex].BitPolarity = 0;
547 bData = bData & 0x7f;
550 Adapter->LEDInfo.LEDState[uiIndex].LED_Type = bData;
551 if(bData <= NUM_OF_LEDS)
552 Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num = GPIO_Array[bData];
554 Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num = DISABLE_GPIO_NUM;
558 Adapter->LEDInfo.LEDState[uiIndex].LED_On_State = bData;
561 Adapter->LEDInfo.LEDState[uiIndex].LED_Blink_State= bData;
565 /*Check if all the LED settings are disabled. If it is disabled, dont launch the LED control thread.*/
566 for(uiIndex = 0; uiIndex<NUM_OF_LEDS; uiIndex++)
568 if((Adapter->LEDInfo.LEDState[uiIndex].LED_Type == DISABLE_GPIO_NUM) ||
569 (Adapter->LEDInfo.LEDState[uiIndex].LED_Type == 0x7f) ||
570 (Adapter->LEDInfo.LEDState[uiIndex].LED_Type == 0))
573 if(uiNum_of_LED_Type >= NUM_OF_LEDS)
574 *bEnableThread = FALSE;
577 for(uiIndex=0; uiIndex<NUM_OF_LEDS; uiIndex++)
579 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].LED_Type = %x\n", uiIndex,
580 Adapter->LEDInfo.LEDState[uiIndex].LED_Type);
581 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].LED_On_State = %x\n", uiIndex,
582 Adapter->LEDInfo.LEDState[uiIndex].LED_On_State);
583 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].LED_Blink_State = %x\n", uiIndex,
584 Adapter->LEDInfo.LEDState[uiIndex].LED_Blink_State);
585 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LEDState[%d].GPIO_Num = %x\n", uiIndex,
586 Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num);
588 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: Polarity = %d\n",
589 Adapter->LEDInfo.BitPolarty);
593 //--------------------------------------------------------------------------
594 // Procedure: LedGpioInit
596 // Description: Initializes LED GPIOs. Makes the LED GPIOs to OUTPUT mode and make the
597 // initial state to be OFF.
600 // Adapter - Pointer to MINI_ADAPTER structure.
604 //-----------------------------------------------------------------------------
606 static VOID LedGpioInit(PMINI_ADAPTER Adapter)
608 UINT uiResetValue = 0;
611 /* Set all LED GPIO Mode to output mode */
612 if(rdmalt(Adapter, GPIO_MODE_REGISTER, &uiResetValue, sizeof(uiResetValue)) <0)
613 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: RDM Failed\n");
614 for(uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++)
616 if(Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
617 uiResetValue |= (1 << Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num);
618 TURN_OFF_LED(1<<Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num,uiIndex);
620 if(wrmalt(Adapter, GPIO_MODE_REGISTER, &uiResetValue, sizeof(uiResetValue)) < 0)
621 BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: WRM Failed\n");
623 Adapter->LEDInfo.bIdle_led_off = FALSE;
625 //-----------------------------------------------------------------------------
627 static INT BcmGetGPIOPinInfo(PMINI_ADAPTER Adapter, UCHAR *GPIO_num_tx, UCHAR *GPIO_num_rx ,UCHAR *uiLedTxIndex, UCHAR *uiLedRxIndex,LedEventInfo_t currdriverstate)
631 *GPIO_num_tx = DISABLE_GPIO_NUM;
632 *GPIO_num_rx = DISABLE_GPIO_NUM;
634 for(uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++)
637 if((currdriverstate == NORMAL_OPERATION)||
638 (currdriverstate == IDLEMODE_EXIT)||
639 (currdriverstate == FW_DOWNLOAD))
641 if(Adapter->LEDInfo.LEDState[uiIndex].LED_Blink_State & currdriverstate)
643 if(Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
645 if(*GPIO_num_tx == DISABLE_GPIO_NUM)
647 *GPIO_num_tx = Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num;
648 *uiLedTxIndex = uiIndex;
652 *GPIO_num_rx = Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num;
653 *uiLedRxIndex = uiIndex;
660 if(Adapter->LEDInfo.LEDState[uiIndex].LED_On_State & currdriverstate)
662 if(Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
664 *GPIO_num_tx = Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num;
665 *uiLedTxIndex = uiIndex;
670 return STATUS_SUCCESS ;
672 static VOID LEDControlThread(PMINI_ADAPTER Adapter)
676 UCHAR uiLedIndex = 0 ;
677 UINT uiResetValue = 0;
678 LedEventInfo_t currdriverstate = 0;
683 UCHAR dummyGPIONum = 0;
684 UCHAR dummyIndex = 0;
686 //currdriverstate = Adapter->DriverState;
687 Adapter->LEDInfo.bIdleMode_tx_from_host = FALSE;
689 /*Wait till event is triggered*/
690 //wait_event(Adapter->LEDInfo.notify_led_event,
691 // currdriverstate!= Adapter->DriverState);
693 GPIO_num = DISABLE_GPIO_NUM ;
697 /*Wait till event is triggered*/
698 if( (GPIO_num == DISABLE_GPIO_NUM)
700 ((currdriverstate != FW_DOWNLOAD) &&
701 (currdriverstate != NORMAL_OPERATION) &&
702 (currdriverstate != LOWPOWER_MODE_ENTER))
704 (currdriverstate == LED_THREAD_INACTIVE) )
706 Status = wait_event_interruptible(Adapter->LEDInfo.notify_led_event,
707 currdriverstate != Adapter->DriverState || kthread_should_stop());
710 if(kthread_should_stop() || Adapter->device_removed )
712 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Led thread got signal to exit..hence exiting");
713 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_DISABLED;
714 TURN_OFF_LED(1<<GPIO_num, uiLedIndex);
715 return ;//STATUS_FAILURE;
718 if(Adapter->device_removed)
720 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"Device removed hence exiting from Led Thread..");
725 if((GPIO_num != DISABLE_GPIO_NUM) &&
726 ((currdriverstate != FW_DOWNLOAD) &&
727 (currdriverstate != NORMAL_OPERATION) &&
728 (currdriverstate != IDLEMODE_EXIT)))
729 TURN_OFF_LED(1<<GPIO_num, uiLedIndex);
732 if(GPIO_num != DISABLE_GPIO_NUM)
734 TURN_OFF_LED(1<<GPIO_num, uiLedIndex);
737 if(Adapter->LEDInfo.bLedInitDone == FALSE)
739 LedGpioInit(Adapter);
740 Adapter->LEDInfo.bLedInitDone = TRUE;
743 switch(Adapter->DriverState)
747 currdriverstate = DRIVER_INIT;//Adapter->DriverState;
749 LedGpioInit(Adapter);
750 Adapter->LEDInfo.bLedInitDone = TRUE;
752 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex, currdriverstate);
754 if(GPIO_num != DISABLE_GPIO_NUM)
756 TURN_ON_LED(1<<GPIO_num, uiLedIndex);
762 //BCM_DEBUG_PRINT (Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: FW_DN_DONE called\n");
763 currdriverstate = FW_DOWNLOAD;
765 if(Adapter->LEDInfo.bLedInitDone == FALSE)
767 LedGpioInit(Adapter);
768 Adapter->LEDInfo.bLedInitDone = TRUE;
771 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex, currdriverstate);
773 if(GPIO_num != DISABLE_GPIO_NUM)
776 LED_Blink(Adapter, 1<<GPIO_num, uiLedIndex, timeout, -1,currdriverstate);
780 case FW_DOWNLOAD_DONE:
782 currdriverstate = FW_DOWNLOAD_DONE;
783 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex, &dummyIndex,currdriverstate);
784 if(GPIO_num != DISABLE_GPIO_NUM)
786 TURN_ON_LED(1<<GPIO_num, uiLedIndex);
793 if(Adapter->ulPowerSaveMode == DEVICE_POWERSAVE_MODE_AS_PMU_SHUTDOWN)
795 LedGpioInit(Adapter);
798 //no break, continue to NO_NETWORK_ENTRY state as well.
800 case NO_NETWORK_ENTRY:
802 currdriverstate = NO_NETWORK_ENTRY;
803 BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum, &uiLedIndex,&dummyGPIONum,currdriverstate);
804 if(GPIO_num != DISABLE_GPIO_NUM)
806 TURN_ON_LED(1<<GPIO_num, uiLedIndex);
810 case NORMAL_OPERATION:
812 UCHAR GPIO_num_tx = DISABLE_GPIO_NUM;
813 UCHAR GPIO_num_rx = DISABLE_GPIO_NUM;
816 currdriverstate = NORMAL_OPERATION;
817 Adapter->LEDInfo.bIdle_led_off = FALSE;
819 BcmGetGPIOPinInfo(Adapter, &GPIO_num_tx, &GPIO_num_rx, &uiLEDTx,&uiLEDRx,currdriverstate);
820 if((GPIO_num_tx == DISABLE_GPIO_NUM) && (GPIO_num_rx == DISABLE_GPIO_NUM))
822 GPIO_num = DISABLE_GPIO_NUM ;
826 /*If single LED is selected, use same for both Tx and Rx*/
827 if(GPIO_num_tx == DISABLE_GPIO_NUM)
829 GPIO_num_tx = GPIO_num_rx;
832 else if(GPIO_num_rx == DISABLE_GPIO_NUM)
834 GPIO_num_rx = GPIO_num_tx;
837 /*Blink the LED in proportionate to Tx and Rx transmissions.*/
838 LED_Proportional_Blink(Adapter, GPIO_num_tx, uiLEDTx, GPIO_num_rx, uiLEDRx,currdriverstate);
842 case LOWPOWER_MODE_ENTER:
844 currdriverstate = LOWPOWER_MODE_ENTER;
845 if( DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING == Adapter->ulPowerSaveMode)
847 /* Turn OFF all the LED */
849 for(uiIndex =0; uiIndex < NUM_OF_LEDS; uiIndex++)
851 if(Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
852 TURN_OFF_LED((1<<Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num),uiIndex);
856 /* Turn off LED And WAKE-UP for Sendinf IDLE mode ACK */
857 Adapter->LEDInfo.bLedInitDone = FALSE;
858 Adapter->LEDInfo.bIdle_led_off = TRUE;
859 wake_up(&Adapter->LEDInfo.idleModeSyncEvent);
860 GPIO_num = DISABLE_GPIO_NUM;
863 case IDLEMODE_CONTINUE:
865 currdriverstate = IDLEMODE_CONTINUE;
866 GPIO_num = DISABLE_GPIO_NUM;
872 UCHAR GPIO_num_tx = DISABLE_GPIO_NUM;
873 UCHAR GPIO_num_rx = DISABLE_GPIO_NUM;
874 UCHAR uiTxLedIndex = 0;
875 UCHAR uiRxLedIndex = 0;
877 currdriverstate = IDLEMODE_EXIT;
878 if(DEVICE_POWERSAVE_MODE_AS_PMU_SHUTDOWN == Adapter->ulPowerSaveMode)
880 LedGpioInit(Adapter);
882 BcmGetGPIOPinInfo(Adapter, &GPIO_num_tx, &GPIO_num_rx, &uiTxLedIndex,&uiRxLedIndex,currdriverstate);
884 Adapter->LEDInfo.bIdle_led_off = FALSE;
886 if((GPIO_num_tx == DISABLE_GPIO_NUM) && (GPIO_num_rx == DISABLE_GPIO_NUM))
888 GPIO_num = DISABLE_GPIO_NUM ;
893 if(Adapter->LEDInfo.bIdleMode_tx_from_host)
894 LED_Blink(Adapter, 1<<GPIO_num_tx, uiTxLedIndex, timeout, -1,currdriverstate);
896 LED_Blink(Adapter, 1<<GPIO_num_rx, uiRxLedIndex, timeout, -1,currdriverstate);
903 currdriverstate = DRIVER_HALT;
904 GPIO_num = DISABLE_GPIO_NUM;
905 for(uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++)
907 if(Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num !=
909 TURN_OFF_LED((1<<Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num),uiIndex);
911 //Adapter->DriverState = DRIVER_INIT;
914 case LED_THREAD_INACTIVE :
916 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"InActivating LED thread...");
917 currdriverstate = LED_THREAD_INACTIVE;
918 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_RUNNING_INACTIVELY ;
919 Adapter->LEDInfo.bLedInitDone = FALSE ;
921 for(uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++)
923 if(Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num !=
925 TURN_OFF_LED((1<<Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num),uiIndex);
929 case LED_THREAD_ACTIVE :
931 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"Activating LED thread again...");
932 if(Adapter->LinkUpStatus == FALSE)
933 Adapter->DriverState = NO_NETWORK_ENTRY;
935 Adapter->DriverState = NORMAL_OPERATION;
937 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_RUNNING_ACTIVELY ;
945 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_DISABLED;
948 int InitLedSettings(PMINI_ADAPTER Adapter)
950 int Status = STATUS_SUCCESS;
951 BOOLEAN bEnableThread = TRUE;
954 /*Initially set BitPolarity to normal polarity. The bit 8 of LED type
955 * is used to change the polarity of the LED.*/
957 for(uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
958 Adapter->LEDInfo.LEDState[uiIndex].BitPolarity = 1;
961 /*Read the LED settings of CONFIG file and map it to GPIO numbers in EEPROM*/
962 Status = ReadConfigFileStructure(Adapter, &bEnableThread);
963 if(STATUS_SUCCESS != Status)
965 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL,"LED Thread: FAILED in ReadConfigFileStructure\n");
969 if(Adapter->LEDInfo.led_thread_running)
975 Adapter->DriverState = DRIVER_HALT;
976 wake_up(&Adapter->LEDInfo.notify_led_event);
977 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_DISABLED;
982 else if(bEnableThread)
984 /*Create secondary thread to handle the LEDs*/
985 init_waitqueue_head(&Adapter->LEDInfo.notify_led_event);
986 init_waitqueue_head(&Adapter->LEDInfo.idleModeSyncEvent);
987 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_RUNNING_ACTIVELY;
988 Adapter->LEDInfo.bIdle_led_off = FALSE;
989 Adapter->LEDInfo.led_cntrl_threadid = kthread_run((int (*)(void *))
990 LEDControlThread, Adapter, "led_control_thread");
991 if(IS_ERR(Adapter->LEDInfo.led_cntrl_threadid))
993 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, LED_DUMP_INFO, DBG_LVL_ALL, "Not able to spawn Kernel Thread\n");
994 Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_DISABLED;
995 return PTR_ERR(Adapter->LEDInfo.led_cntrl_threadid);