Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ce2705c3 authored by Matthias Beyer's avatar Matthias Beyer Committed by Greg Kroah-Hartman
Browse files

Staging: bcm: led_control.c: Outsourced adapter driver state handling

parent 9bcfab20
Loading
Loading
Loading
Loading
+171 −154
Original line number Diff line number Diff line
@@ -661,69 +661,21 @@ static INT BcmGetGPIOPinInfo(struct bcm_mini_adapter *Adapter,
	return STATUS_SUCCESS;
}

static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
static void handle_adapter_driver_state(struct bcm_mini_adapter *ad,
					enum bcm_led_events currdriverstate,
					UCHAR GPIO_num,
					UCHAR dummyGPIONum,
					UCHAR uiLedIndex,
					UCHAR dummyIndex,
					ulong timeout,
					UINT uiResetValue,
					UINT uiIndex)
{
	UINT uiIndex = 0;
	UCHAR GPIO_num = 0;
	UCHAR uiLedIndex = 0;
	UINT uiResetValue = 0;
	enum bcm_led_events currdriverstate = 0;
	ulong timeout = 0;

	INT Status = 0;

	UCHAR dummyGPIONum = 0;
	UCHAR dummyIndex = 0;

	/* currdriverstate = Adapter->DriverState; */
	Adapter->LEDInfo.bIdleMode_tx_from_host = false;

	/*
	 * Wait till event is triggered
	 *
	 * wait_event(Adapter->LEDInfo.notify_led_event,
	 *	currdriverstate!= Adapter->DriverState);
	 */

	GPIO_num = DISABLE_GPIO_NUM;

	while (TRUE) {
		/* Wait till event is triggered */
		if ((GPIO_num == DISABLE_GPIO_NUM)
						||
				((currdriverstate != FW_DOWNLOAD) &&
				 (currdriverstate != NORMAL_OPERATION) &&
				 (currdriverstate != LOWPOWER_MODE_ENTER))
						||
				(currdriverstate == LED_THREAD_INACTIVE))
			Status = wait_event_interruptible(
					Adapter->LEDInfo.notify_led_event,
					currdriverstate != Adapter->DriverState
						|| kthread_should_stop());

		if (kthread_should_stop() || Adapter->device_removed) {
			BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
				DBG_LVL_ALL,
				"Led thread got signal to exit..hence exiting");
			Adapter->LEDInfo.led_thread_running =
						BCM_LED_THREAD_DISABLED;
			TURN_OFF_LED(1 << GPIO_num, uiLedIndex);
			return; /* STATUS_FAILURE; */
		}

		if (GPIO_num != DISABLE_GPIO_NUM)
			TURN_OFF_LED(1 << GPIO_num, uiLedIndex);

		if (Adapter->LEDInfo.bLedInitDone == false) {
			LedGpioInit(Adapter);
			Adapter->LEDInfo.bLedInitDone = TRUE;
		}

		switch (Adapter->DriverState) {
	switch (ad->DriverState) {
	case DRIVER_INIT:
		currdriverstate = DRIVER_INIT;
					/* Adapter->DriverState; */
			BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum,
				/* ad->DriverState; */
		BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
				  &uiLedIndex, &dummyIndex,
				  currdriverstate);

@@ -733,26 +685,25 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
		break;
	case FW_DOWNLOAD:
		/*
			 * BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS,
		 * BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS,
		 *	LED_DUMP_INFO, DBG_LVL_ALL,
		 *	"LED Thread: FW_DN_DONE called\n");
		 */
		currdriverstate = FW_DOWNLOAD;
			BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum,
		BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
				  &uiLedIndex, &dummyIndex,
				  currdriverstate);

		if (GPIO_num != DISABLE_GPIO_NUM) {
			timeout = 50;
				LED_Blink(Adapter, 1 << GPIO_num, uiLedIndex,
					  timeout, -1, currdriverstate);
			LED_Blink(ad, 1 << GPIO_num, uiLedIndex, timeout,
				  -1, currdriverstate);
		}
		break;
	case FW_DOWNLOAD_DONE:
		currdriverstate = FW_DOWNLOAD_DONE;
			BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum,
					  &uiLedIndex, &dummyIndex,
					  currdriverstate);
		BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
				  &uiLedIndex, &dummyIndex, currdriverstate);
		if (GPIO_num != DISABLE_GPIO_NUM)
			TURN_ON_LED(1 << GPIO_num, uiLedIndex);
		break;
@@ -764,9 +715,8 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
		 */
	case NO_NETWORK_ENTRY:
		currdriverstate = NO_NETWORK_ENTRY;
			BcmGetGPIOPinInfo(Adapter, &GPIO_num, &dummyGPIONum,
					  &uiLedIndex, &dummyGPIONum,
					  currdriverstate);
		BcmGetGPIOPinInfo(ad, &GPIO_num, &dummyGPIONum,
				  &uiLedIndex, &dummyGPIONum, currdriverstate);
		if (GPIO_num != DISABLE_GPIO_NUM)
			TURN_ON_LED(1 << GPIO_num, uiLedIndex);
		break;
@@ -777,14 +727,12 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
			UCHAR uiLEDTx = 0;
			UCHAR uiLEDRx = 0;
			currdriverstate = NORMAL_OPERATION;
				Adapter->LEDInfo.bIdle_led_off = false;
			ad->LEDInfo.bIdle_led_off = false;

				BcmGetGPIOPinInfo(Adapter, &GPIO_num_tx,
					&GPIO_num_rx, &uiLEDTx, &uiLEDRx,
					currdriverstate);
			BcmGetGPIOPinInfo(ad, &GPIO_num_tx, &GPIO_num_rx,
					  &uiLEDTx, &uiLEDRx, currdriverstate);
			if ((GPIO_num_tx == DISABLE_GPIO_NUM) &&
						(GPIO_num_rx ==
						 DISABLE_GPIO_NUM)) {
					(GPIO_num_rx == DISABLE_GPIO_NUM)) {
				GPIO_num = DISABLE_GPIO_NUM;
			} else {
				/*
@@ -794,8 +742,7 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
				if (GPIO_num_tx == DISABLE_GPIO_NUM) {
					GPIO_num_tx = GPIO_num_rx;
					uiLEDTx = uiLEDRx;
					} else if (GPIO_num_rx ==
							DISABLE_GPIO_NUM) {
				} else if (GPIO_num_rx == DISABLE_GPIO_NUM) {
					GPIO_num_rx = GPIO_num_tx;
					uiLEDRx = uiLEDTx;
				}
@@ -803,7 +750,7 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
				 * Blink the LED in proportionate
				 * to Tx and Rx transmissions.
				 */
					LED_Proportional_Blink(Adapter,
				LED_Proportional_Blink(ad,
						       GPIO_num_tx, uiLEDTx,
						       GPIO_num_rx, uiLEDRx,
						       currdriverstate);
@@ -813,19 +760,19 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
	case LOWPOWER_MODE_ENTER:
		currdriverstate = LOWPOWER_MODE_ENTER;
		if (DEVICE_POWERSAVE_MODE_AS_MANUAL_CLOCK_GATING ==
					Adapter->ulPowerSaveMode) {
				ad->ulPowerSaveMode) {
			/* Turn OFF all the LED */
			uiResetValue = 0;
			for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
					if (Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
						TURN_OFF_LED((1 << Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num), uiIndex);
				if (ad->LEDInfo.LEDState[uiIndex].GPIO_Num != DISABLE_GPIO_NUM)
					TURN_OFF_LED((1 << ad->LEDInfo.LEDState[uiIndex].GPIO_Num), uiIndex);
			}

		}
		/* Turn off LED And WAKE-UP for Sendinf IDLE mode ACK */
			Adapter->LEDInfo.bLedInitDone = false;
			Adapter->LEDInfo.bIdle_led_off = TRUE;
			wake_up(&Adapter->LEDInfo.idleModeSyncEvent);
		ad->LEDInfo.bLedInitDone = false;
		ad->LEDInfo.bIdle_led_off = TRUE;
		wake_up(&ad->LEDInfo.idleModeSyncEvent);
		GPIO_num = DISABLE_GPIO_NUM;
		break;
	case IDLEMODE_CONTINUE:
@@ -838,35 +785,35 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
		currdriverstate = DRIVER_HALT;
		GPIO_num = DISABLE_GPIO_NUM;
		for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
				if (Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num
						!= DISABLE_GPIO_NUM)
					TURN_OFF_LED((1 << Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num), uiIndex);
			if (ad->LEDInfo.LEDState[uiIndex].GPIO_Num !=
					DISABLE_GPIO_NUM)
				TURN_OFF_LED((1 << ad->LEDInfo.LEDState[uiIndex].GPIO_Num), uiIndex);
		}
			/* Adapter->DriverState = DRIVER_INIT; */
		/* ad->DriverState = DRIVER_INIT; */
		break;
	case LED_THREAD_INACTIVE:
			BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
		BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, LED_DUMP_INFO,
				DBG_LVL_ALL, "InActivating LED thread...");
		currdriverstate = LED_THREAD_INACTIVE;
			Adapter->LEDInfo.led_thread_running =
		ad->LEDInfo.led_thread_running =
				BCM_LED_THREAD_RUNNING_INACTIVELY;
			Adapter->LEDInfo.bLedInitDone = false;
		ad->LEDInfo.bLedInitDone = false;
		/* disable ALL LED */
		for (uiIndex = 0; uiIndex < NUM_OF_LEDS; uiIndex++) {
				if (Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num
						!= DISABLE_GPIO_NUM)
					TURN_OFF_LED((1 << Adapter->LEDInfo.LEDState[uiIndex].GPIO_Num), uiIndex);
			if (ad->LEDInfo.LEDState[uiIndex].GPIO_Num !=
					DISABLE_GPIO_NUM)
				TURN_OFF_LED((1 << ad->LEDInfo.LEDState[uiIndex].GPIO_Num), uiIndex);
		}
		break;
	case LED_THREAD_ACTIVE:
			BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
		BCM_DEBUG_PRINT(ad, DBG_TYPE_OTHERS, LED_DUMP_INFO,
				DBG_LVL_ALL, "Activating LED thread again...");
			if (Adapter->LinkUpStatus == false)
				Adapter->DriverState = NO_NETWORK_ENTRY;
		if (ad->LinkUpStatus == false)
			ad->DriverState = NO_NETWORK_ENTRY;
		else
				Adapter->DriverState = NORMAL_OPERATION;
			ad->DriverState = NORMAL_OPERATION;

			Adapter->LEDInfo.led_thread_running =
		ad->LEDInfo.led_thread_running =
				BCM_LED_THREAD_RUNNING_ACTIVELY;
		break;
		/* return; */
@@ -874,6 +821,76 @@ static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
		break;
	}
}

static VOID LEDControlThread(struct bcm_mini_adapter *Adapter)
{
	UINT uiIndex = 0;
	UCHAR GPIO_num = 0;
	UCHAR uiLedIndex = 0;
	UINT uiResetValue = 0;
	enum bcm_led_events currdriverstate = 0;
	ulong timeout = 0;

	INT Status = 0;

	UCHAR dummyGPIONum = 0;
	UCHAR dummyIndex = 0;

	/* currdriverstate = Adapter->DriverState; */
	Adapter->LEDInfo.bIdleMode_tx_from_host = false;

	/*
	 * Wait till event is triggered
	 *
	 * wait_event(Adapter->LEDInfo.notify_led_event,
	 *	currdriverstate!= Adapter->DriverState);
	 */

	GPIO_num = DISABLE_GPIO_NUM;

	while (TRUE) {
		/* Wait till event is triggered */
		if ((GPIO_num == DISABLE_GPIO_NUM)
						||
				((currdriverstate != FW_DOWNLOAD) &&
				 (currdriverstate != NORMAL_OPERATION) &&
				 (currdriverstate != LOWPOWER_MODE_ENTER))
						||
				(currdriverstate == LED_THREAD_INACTIVE))
			Status = wait_event_interruptible(
					Adapter->LEDInfo.notify_led_event,
					currdriverstate != Adapter->DriverState
						|| kthread_should_stop());

		if (kthread_should_stop() || Adapter->device_removed) {
			BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, LED_DUMP_INFO,
				DBG_LVL_ALL,
				"Led thread got signal to exit..hence exiting");
			Adapter->LEDInfo.led_thread_running =
						BCM_LED_THREAD_DISABLED;
			TURN_OFF_LED(1 << GPIO_num, uiLedIndex);
			return; /* STATUS_FAILURE; */
		}

		if (GPIO_num != DISABLE_GPIO_NUM)
			TURN_OFF_LED(1 << GPIO_num, uiLedIndex);

		if (Adapter->LEDInfo.bLedInitDone == false) {
			LedGpioInit(Adapter);
			Adapter->LEDInfo.bLedInitDone = TRUE;
		}

		handle_adapter_driver_state(Adapter,
					    currdriverstate,
					    GPIO_num,
					    dummyGPIONum,
					    uiLedIndex,
					    dummyIndex,
					    timeout,
					    uiResetValue,
					    uiIndex
					    );
	}
	Adapter->LEDInfo.led_thread_running = BCM_LED_THREAD_DISABLED;
}