Exemplo n.º 1
0
int do_led_control(int which, int mode)
#endif
{
	int use_gpio, gpio_nr;
	int v = (mode == LED_OFF)? 0:1;

	// Did the user disable the leds?
	if ((mode == LED_ON) && (nvram_get_int("led_disable") == 1) && (which != LED_TURBO)
#ifdef RTCONFIG_QTN
		&& (which != BTN_QTN_RESET)
#endif
	)
	{
		return 0;
	}

	if (which < 0 || which >= LED_ID_MAX || mode < 0 || mode >= LED_FAN_MODE_MAX)
		return -1;

	get_gpio_values_once(0);
	use_gpio = led_gpio_table[which];
	gpio_nr = use_gpio & 0xFF;

#if defined(RTCONFIG_ETRON_XHCI_USB3_LED)
	if (which == LED_USB3 && nvram_match("led_usb3_gpio", "etron")) {
		char *onoff = "2";	/* LED OFF */

		if (mode == LED_ON || mode == FAN_ON || mode == HAVE_FAN_ON)
			onoff = "3";	/* LED ON */

		f_write_string("/sys/bus/pci/drivers/xhci_hcd/port_led", onoff, 0, 0);
		return 0;
	}
#endif

#if defined(RTAC56U) || defined(RTAC56S)
	if (which == LED_5G && nvram_match("5g_fail", "1"))
		return -1;
#endif

	if (use_gpio < 0 || gpio_nr == 0xFF)
		return -1;

	if (use_gpio & GPIO_ACTIVE_LOW)
		v ^= 1;

	if (mode == LED_OFF) {
		stop_bled(use_gpio);
	}

	set_gpio(gpio_nr, v);

	if (mode == LED_ON) {
		start_bled(use_gpio);
	}

	return 0;
}
Exemplo n.º 2
0
int init_gpio(void)
{
	char *btn_list[] = { "btn_rst_gpio", "btn_wps_gpio", "fan_gpio", "have_fan_gpio"
#ifdef RTCONFIG_WIRELESS_SWITCH
		, "btn_wifi_gpio"
#endif
#ifdef RTCONFIG_WIFI_TOG_BTN
		, "btn_wltog_gpio"
#endif
#ifdef RTCONFIG_SWMODE_SWITCH
#if defined(PLAC66U)
		, "btn_swmode1_gpio"
#else
		, "btn_swmode1_gpio", "btn_swmode2_gpio", "btn_swmode3_gpio"
#endif	/* Mode */
#endif	/* RTCONFIG_SWMODE_SWITCH */
#ifdef RTCONFIG_TURBO
		, "btn_turbo_gpio"
#endif
#ifdef RTCONFIG_LED_BTN
		, "btn_led_gpio"
#endif
#ifdef RTCONFIG_INTERNAL_GOBI
		, "btn_lte_gpio"
#endif
	};
	char *led_list[] = { "led_turbo_gpio", "led_pwr_gpio", "led_usb_gpio", "led_wps_gpio", "fan_gpio", "have_fan_gpio", "led_lan_gpio", "led_wan_gpio", "led_usb3_gpio", "led_2g_gpio", "led_5g_gpio" 
#ifdef RTCONFIG_LAN4WAN_LED
		, "led_lan1_gpio", "led_lan2_gpio", "led_lan3_gpio", "led_lan4_gpio"
#endif  /* LAN4WAN_LED */
#ifdef RTCONFIG_LED_ALL
		, "led_all_gpio"
#endif
		, "led_wan_red_gpio"
#ifdef RTCONFIG_QTN
		, "reset_qtn_gpio"
#endif
#ifdef RTCONFIG_USBRESET
		, "pwr_usb_gpio"
		, "pwr_usb_gpio2"
#endif
#ifdef RTCONFIG_WIFIPWR
		, "pwr_2g_gpio"
		, "pwr_5g_gpio"
#endif
#ifdef RTCONFIG_INTERNAL_GOBI
		, "led_3g_gpio", "led_lte_gpio", "led_sig1_gpio", "led_sig2_gpio", "led_sig3_gpio", "led_sig4_gpio"
#endif
#if (defined(PLN12) || defined(PLAC56))
		, "plc_wake_gpio"
		, "led_pwr_red_gpio"
		, "led_2g_green_gpio", "led_2g_orange_gpio", "led_2g_red_gpio"
		, "led_5g_green_gpio", "led_5g_orange_gpio", "led_5g_red_gpio"
#endif
#ifdef RTCONFIG_MMC_LED
		, "led_mmc_gpio"
#endif
#if defined(RTCONFIG_RTAC5300) || defined(RTCONFIG_RTAC5300R)
		, "rpm_fan_gpio"
#endif
#ifdef RTCONFIG_RESET_SWITCH
		, "reset_switch_gpio"
#endif
			   };
	int use_gpio, gpio_pin;
	int enable, disable;
	int i;

#ifdef RTCONFIG_INTERNAL_GOBI
	void get_gpio_values_once(int);
	get_gpio_values_once(0);		// for filling data to led_gpio_table[]
#endif	/* RTCONFIG_INTERNAL_GOBI */

	/* btn input */
	for(i = 0; i < ASIZE(btn_list); i++)
	{
		if (!nvram_get(btn_list[i]))
			continue;
		use_gpio = nvram_get_int(btn_list[i]);
		if((gpio_pin = use_gpio & 0xff) == 0xff)
			continue;
		gpio_dir(gpio_pin, GPIO_DIR_IN);
	}

	/* led output */
	for(i = 0; i < ASIZE(led_list); i++)
	{
		if (!nvram_get(led_list[i]))
			continue;
#if defined(RTCONFIG_ETRON_XHCI_USB3_LED)
		if (!strcmp(led_list[i], "led_usb3_gpio") && nvram_match("led_usb3_gpio", "etron")) {
			led_control(LED_USB3, LED_OFF);
			continue;
		}
#endif
		use_gpio = nvram_get_int(led_list[i]);

		if((gpio_pin = use_gpio & 0xff) == 0xff)
			continue;

#if defined(RTCONFIG_RALINK_MT7620)
		if(gpio_pin == 72)	//skip 2g wifi led NOT to be gpio LED
			continue;
#endif

		disable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 0: 1;
		gpio_dir(gpio_pin, GPIO_DIR_OUT);

		/* If WAN RED LED is defined, keep it on until Internet connection ready in router mode. */
		if (!strcmp(led_list[i], "led_wan_red_gpio") && nvram_get_int("sw_mode") == SW_MODE_ROUTER)
			disable = !disable;

		set_gpio(gpio_pin, disable);
#ifdef RTCONFIG_INTERNAL_GOBI	// save setting value
		{ int i; char led[16]; for(i=0; i<LED_ID_MAX; i++) if(gpio_pin == (led_gpio_table[i]&0xff)){snprintf(led, sizeof(led), "led%02d", i); nvram_set_int(led, LED_OFF); break;}}
#endif	/* RTCONFIG_INTERNAL_GOBI */
	}

#if (defined(PLN12) || defined(PLAC56))
	if((gpio_pin = (use_gpio = nvram_get_int("led_pwr_red_gpio")) & 0xff) != 0xff)
#else
	if((gpio_pin = (use_gpio = nvram_get_int("led_pwr_gpio")) & 0xff) != 0xff)
#endif
	{
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
#ifdef RTCONFIG_INTERNAL_GOBI	// save setting value
		{ int i; char led[16]; for(i=0; i<LED_ID_MAX; i++) if(gpio_pin == (led_gpio_table[i]&0xff)){snprintf(led, sizeof(led), "led%02d", i); nvram_set_int(led, LED_ON); break;}}
#endif	/* RTCONFIG_INTERNAL_GOBI */
	}

	// Power of USB.
	if((gpio_pin = (use_gpio = nvram_get_int("pwr_usb_gpio")) & 0xff) != 0xff){
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
	}
	if((gpio_pin = (use_gpio = nvram_get_int("pwr_usb_gpio2")) & 0xff) != 0xff){
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
	}

#if defined(RTCONFIG_RTAC5300) || defined(RTCONFIG_RTAC5300R)
	// RPM of FAN
	if((gpio_pin = (use_gpio = nvram_get_int("rpm_fan_gpio")) & 0xff) != 0xff){
	enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
	set_gpio(gpio_pin, enable);
	}
#endif

#ifdef PLAC56
	if((gpio_pin = (use_gpio = nvram_get_int("plc_wake_gpio")) & 0xff) != 0xff){
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		set_gpio(gpio_pin, enable);
	}
#endif

	// TODO: system dependent initialization
	return 0;
}
Exemplo n.º 3
0
int button_pressed(int which)
{
	int use_gpio;
	int gpio_value;

	get_gpio_values_once(0);
	switch(which) {
		case BTN_RESET:
			use_gpio = btn_rst_gpio;
			break;
		case BTN_WPS:
			use_gpio = btn_wps_gpio;
			break;
		case BTN_FAN:
			use_gpio = fan_gpio;
			break;
		case BTN_HAVE_FAN:
			use_gpio = have_fan_gpio;
			break;
#ifdef RTCONFIG_SWMODE_SWITCH
#if defined(PLAC66U)
		case BTN_SWMODE_SW_ROUTER:
			use_gpio = btn_swmode_sw_router;
			break;
#else
		case BTN_SWMODE_SW_ROUTER:
			use_gpio = btn_swmode_sw_router;
			break;
		case BTN_SWMODE_SW_REPEATER:
			use_gpio = btn_swmode_sw_repeater;
			break;
		case BTN_SWMODE_SW_AP:
			use_gpio = btn_swmode_sw_ap;
			break;
#endif	/* Model */
#endif	/* RTCONFIG_SWMODE_SWITCH */
#ifdef RTCONFIG_WIRELESS_SWITCH
		case BTN_WIFI_SW:
			use_gpio = btn_wifi_sw;
			break;
#endif
#ifdef RTCONFIG_WIFI_TOG_BTN
		case BTN_WIFI_TOG:
			use_gpio = btn_wltog_gpio;
			break;
#endif
#ifdef RTCONFIG_TURBO
		case BTN_TURBO:
			use_gpio = btn_turbo_gpio;
			break;
#endif
#ifdef RTCONFIG_LED_BTN
		case BTN_LED:
			use_gpio = btn_led_gpio;
			break;
#endif
#ifdef RTCONFIG_INTERNAL_GOBI
		case BTN_LTE:
			use_gpio = btn_lte_gpio;
			break;
#endif
		default:
			use_gpio = 0xff;
			break;
	}

	if((use_gpio&0xff)!=0x0ff) 
	{
		gpio_value = get_gpio(use_gpio&0xff);

//		_dprintf("use_gpio: %x gpio_value: %x\n", use_gpio, gpio_value);

		if((use_gpio&GPIO_ACTIVE_LOW)==0) // active high case
			return gpio_value==0 ? 0 : 1;
		else 
			return gpio_value==0 ? 1 : 0;
	}
	else return 0;
}
Exemplo n.º 4
0
int led_control(int which, int mode)
{
	int use_gpio;
//	int gpio_value;
	int enable, disable;
	int model;

	model = get_model();

	// Did the user disable the leds?
	if ((mode == LED_ON) && (nvram_get_int("led_disable") == 1) && (which != LED_TURBO)
#ifdef RTCONFIG_QTN
		&& (which != BTN_QTN_RESET)
#endif
	)
		return 0;

	get_gpio_values_once();
	switch(which) {
		case LED_POWER:
			use_gpio = led_pwr_gpio;
			break;
		case LED_USB:
			use_gpio = led_usb_gpio;
			break;
		case LED_USB3:
			use_gpio = led_usb3_gpio;
			break;
		case LED_WPS:	
			use_gpio = led_wps_gpio;
			break;
		case LED_2G:
			if ((model == MODEL_RTN66U) || (model == MODEL_RTAC66U) || (model == MODEL_RTN16)) {
				if (mode == LED_ON)
					eval("wl", "-i", "eth1", "leddc", "0");
				else if (mode == LED_OFF)
					eval("wl", "-i", "eth1", "leddc", "1");
				use_gpio = 0xff;
			} else if (model == MODEL_RTAC56U) {
				if (mode == LED_ON)
					eval("wl", "-i", "eth1", "ledbh", "3", "7");
				else if (mode == LED_OFF)
					eval("wl", "-i", "eth1", "ledbh", "3", "0");
			} else if ((model == MODEL_RTAC68U) || (model == MODEL_RTAC87U)) {
				if (mode == LED_ON)
					eval("wl", "ledbh", "10", "7");
				else if (mode == LED_OFF)
					eval("wl", "ledbh", "10", "0");
			} else {
				use_gpio = led_2g_gpio;
			}
			break;
		case LED_5G_FORCED:
			if (model == MODEL_RTAC68U) {
				if (mode == LED_ON) {
					nvram_set("led_5g", "1");
		                        eval("wl", "-i", "eth2", "ledbh", "10", "7");
				} else if (mode == LED_OFF) {
					nvram_set("led_5g", "0");
					eval("wl", "-i", "eth2", "ledbh", "10", "0");
				}
				use_gpio = led_5g_gpio;
			}
			// Fall through regular LED_5G to handle other models
		case LED_5G:
			if ((model == MODEL_RTN66U) || (model == MODEL_RTN16)) {
                                if (mode == LED_ON)
                                        eval("wl", "-i", "eth2", "leddc", "0");
                                else if (mode == LED_OFF)
                                        eval("wl", "-i", "eth2", "leddc", "1");
				use_gpio = 0xff;
			} else if ((model == MODEL_RTAC66U) || (model == MODEL_RTAC56U)) {
				if (mode == LED_ON)
					nvram_set("led_5g", "1");
				else if (mode == LED_OFF)
					nvram_set("led_5g", "0");
				use_gpio = led_5g_gpio;
                        } else {
                                use_gpio = led_5g_gpio;
			}
#if defined(RTAC56U) || defined(RTAC56S)
			if(nvram_match("5g_fail", "1"))
				return -1;
#endif
			break;
#ifdef RTCONFIG_LAN4WAN_LED
		case LED_LAN1:
			use_gpio = led_lan1_gpio;
			break;
		case LED_LAN2:
			use_gpio = led_lan2_gpio;
			break;
		case LED_LAN3:
			use_gpio = led_lan3_gpio;
			break;
		case LED_LAN4:
			use_gpio = led_lan4_gpio;
			break;
#else
		case LED_LAN:
			use_gpio = led_lan_gpio;
			break;
#endif
		case LED_WAN:
			use_gpio = led_wan_gpio;
			break;
		case FAN:
			use_gpio = fan_gpio;
			break;
		case HAVE_FAN:
			use_gpio = have_fan_gpio;
			break;
		case LED_SWITCH:
			if (mode == LED_ON) {
				eval("et", "robowr", "0x00", "0x18", "0x01ff");
				eval("et", "robowr", "0x00", "0x1a", "0x01ff");
			} else if (mode == LED_OFF) {
				eval("et", "robowr", "0x00", "0x18", "0x01e0");
				eval("et", "robowr", "0x00", "0x1a", "0x01e0");
			}
			use_gpio = 0xff;
			break;
#ifdef RTCONFIG_LED_ALL
		case LED_ALL:
			use_gpio = led_all_gpio;
			break;
#endif
		case LED_TURBO:
			use_gpio = led_turbo_gpio;
			break;
#ifdef RTCONFIG_QTN
		case BTN_QTN_RESET:
			use_gpio = reset_qtn_gpio;
			break;
#endif
		default:
			use_gpio = 0xff;
			break;
	}

	if((use_gpio&0xff) != 0xff)
	{
		enable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 1 : 0;
		disable = (use_gpio&GPIO_ACTIVE_LOW)==0 ? 0: 1;

		switch(mode) {
			case LED_ON:
			case FAN_ON:
			case HAVE_FAN_ON:
				set_gpio((use_gpio&0xff), enable);
				break;
			case LED_OFF:	
			case FAN_OFF:
			case HAVE_FAN_OFF:
				set_gpio((use_gpio&0xff), disable);
				break;
		}
	}
	return 0;
}