Ejemplo n.º 1
0
/*
 * [ 0,     0     ] --> no charge in uboot, show charging logo and boot
 * [ lo_uv, 0     ] --> charge only until lo_uv
 * [ 0,     hi_uv ] --> show logo and charge until hi_uv
 * [ lo_uv, hi_uv ] --> charge until lo_uv, show logo, and then charge until hi_uv
 */
static void loop_charge(struct pmic *p_bat, int lo_uv, u32 hi_uv,
		void (*charging_indication)(bool))
{
	if (!p_bat || !p_bat->pbat) {
		printf("%s: battery information is NULL!\n", __func__);
		return;
	}

	/* for sequence test */
	if ((lo_uv == 0) && (hi_uv == 0)) {
		/* TODO: show logo here */
		return;
	}

	printf("\n%s begins...\n\n", __func__);

	/* update battery voltage and compare it with the threshold */
	p_bat->fg->fg_battery_update(p_bat->pbat->fg, p_bat);

	if (p_bat->pbat->bat->voltage_uV <= lo_uv) {
		printf("charging phase #1\n");
		do_charging(p_bat, lo_uv);
	}

	if (p_bat->pbat->bat->voltage_uV <= hi_uv) {
		if (charging_indication)
			(*charging_indication)(true);
		printf("charging phase #2\n");
		do_charging(p_bat, hi_uv);
		if (charging_indication)
			(*charging_indication)(false);
	}

	printf("\n%s finishes...\n\n", __func__);
}
Ejemplo n.º 2
0
int otg_main_thread(void *data)
{
	struct dwc_otg2 *otg = (struct dwc_otg2 *)data;

	/* Allow the thread to be killed by a signal, but set the signal mask
	 * to block everything but INT, TERM, KILL, and USR1. */
	allow_signal(SIGINT);
	allow_signal(SIGTERM);
	allow_signal(SIGKILL);
	allow_signal(SIGUSR1);

	pm_runtime_get_sync(otg->dev);

	/* Allow the thread to be frozen */
	set_freezable();

	otg_dbg(otg, "Thread running\n");
	while (otg->state != DWC_STATE_TERMINATED) {
		int next = DWC_STATE_B_IDLE;
		otg_dbg(otg, "\n\n\nMain thread entering state\n");

		switch (otg->state) {
		case DWC_STATE_B_IDLE:
			otg_dbg(otg, "DWC_STATE_B_IDLE\n");
			next = do_connector_id_status(otg);
			break;
		case DWC_STATE_CHARGER_DETECTION:
			otg_dbg(otg, "DWC_STATE_CHARGER_DETECTION\n");
			next = do_charger_detection(otg);
			break;
		case DWC_STATE_WAIT_VBUS_FALL:
			otg_dbg(otg, "DWC_STATE_WAIT_VBUS_FALL\n");
			next = do_wait_vbus_fall(otg);
			break;
		case DWC_STATE_CHARGING:
			otg_dbg(otg, "DWC_STATE_CHARGING\n");
			next = do_charging(otg);
			break;
		case DWC_STATE_A_HOST:
			otg_dbg(otg, "DWC_STATE_A_HOST\n");
			next = do_a_host(otg);
			break;
		case DWC_STATE_B_PERIPHERAL:
			otg_dbg(otg, "DWC_STATE_B_PERIPHERAL\n");
			start_peripheral(otg);
			next = do_b_peripheral(otg);

			stop_peripheral(otg);
			break;
		case DWC_STATE_EXIT:
			otg_dbg(otg, "DWC_STATE_EXIT\n");
			next = DWC_STATE_TERMINATED;
			break;
		case DWC_STATE_INVALID:
			otg_dbg(otg, "DWC_STATE_INVALID!!!\n");
		default:
			otg_dbg(otg, "Unknown State %d, sleeping...\n",
					otg->state);
			sleep_main_thread(otg);
			break;
		}

		otg->prev = otg->state;
		otg->state = next;
	}

	pm_runtime_mark_last_busy(otg->dev);
	pm_runtime_put_autosuspend(otg->dev);
	otg->main_thread = NULL;
	otg_dbg(otg, "OTG main thread exiting....\n");

	return 0;
}