target/linux/generic/files/drivers/net/phy/swconfig_leds.c
/*
 * link off -> led off (can't be any other reason to turn it on)
 * link on:
 *	mode link: led on by default only if speed matches, else off
 *	mode txrx: blink only if speed matches, else off
 */
link off -> led off (can't be any other reason to turn it on)
link on:
mode link: led on by default only if speed matches, else off
mode txrx: blink only if speed matches, else off
link off - > led off ( can ' t be any other reason to turn it on ) link on : mode link : led on by default only if speed matches else off mode txrx : blink only if speed matches else off
static void
swconfig_trig_led_event(struct switch_led_trigger *sw_trig,
			struct led_classdev *led_cdev)
{
	struct swconfig_trig_data *trig_data;
	u32 port_mask;
	bool link;
	u8 speed_mask, mode;
	enum led_brightness led_base, led_blink;
	trig_data = led_cdev->trigger_data;
	if (!trig_data)
		return;
	read_lock(&trig_data->lock);
	port_mask = trig_data->port_mask;
	speed_mask = trig_data->speed_mask;
	mode = trig_data->mode;
	read_unlock(&trig_data->lock);
	link = !!(sw_trig->port_link & port_mask);
	if (!link) {
		if (trig_data->prev_brightness != LED_OFF)
			swconfig_trig_set_brightness(trig_data, LED_OFF); 
	}
	else {
		unsigned long traffic;
		int speedok;	
		int i;
		led_base = LED_FULL;
		led_blink = LED_OFF;
		traffic = 0;
		speedok = 0;
		for (i = 0; i < SWCONFIG_LED_NUM_PORTS; i++) {
			if (port_mask & (1 << i)) {
				if (sw_trig->link_speed[i] & speed_mask) {
					traffic += ((mode & SWCONFIG_LED_MODE_TX) ?
						    sw_trig->port_tx_traffic[i] : 0) +
						((mode & SWCONFIG_LED_MODE_RX) ?
						 sw_trig->port_rx_traffic[i] : 0);
					speedok = 1;
				}
			}
		}
		if (speedok) {
			if (!(mode & SWCONFIG_LED_MODE_LINK)) {
				led_base = LED_OFF;
				led_blink = LED_FULL;
			}
			if (trig_data->prev_brightness != led_base)
				swconfig_trig_set_brightness(trig_data,
							     led_base);
			else if (traffic != trig_data->prev_traffic)
				swconfig_trig_set_brightness(trig_data,
							     led_blink);
		} else if (trig_data->prev_brightness != LED_OFF)
			swconfig_trig_set_brightness(trig_data, LED_OFF);
		trig_data->prev_traffic = traffic;
	}
	trig_data->prev_link = link;
}
static void swconfig_trig_led_event ( struct switch_led_trigger * sw_trig , struct led_classdev * led_cdev ) { struct swconfig_trig_data * trig_data ; u32 port_mask ; bool link ; u8 speed_mask , mode ; enum led_brightness led_base , led_blink ; trig_data = led_cdev -> trigger_data ; if ( ! trig_data ) return ; read_lock ( & trig_data -> lock ) ; port_mask = trig_data -> port_mask ; speed_mask = trig_data -> speed_mask ; mode = trig_data -> mode ; read_unlock ( & trig_data -> lock ) ; link = ! ! ( sw_trig -> port_link & port_mask ) ; if ( ! link ) { if ( trig_data -> prev_brightness != LED_OFF ) swconfig_trig_set_brightness ( trig_data , LED_OFF ) ; } else { unsigned long traffic ; int speedok ; int i ; led_base = LED_FULL ; led_blink = LED_OFF ; traffic = 0 ; speedok = 0 ; for ( i = 0 ; i < SWCONFIG_LED_NUM_PORTS ; i ++ ) { if ( port_mask & ( 1 << i ) ) { if ( sw_trig -> link_speed [ i ] & speed_mask ) { traffic += ( ( mode & SWCONFIG_LED_MODE_TX ) ? sw_trig -> port_tx_traffic [ i ] : 0 ) + ( ( mode & SWCONFIG_LED_MODE_RX ) ? sw_trig -> port_rx_traffic [ i ] : 0 ) ; speedok = 1 ; } } } if ( speedok ) { if ( ! ( mode & SWCONFIG_LED_MODE_LINK ) ) { led_base = LED_OFF ; led_blink = LED_FULL ; } if ( trig_data -> prev_brightness != led_base ) swconfig_trig_set_brightness ( trig_data , led_base ) ; else if ( traffic != trig_data -> prev_traffic ) swconfig_trig_set_brightness ( trig_data , led_blink ) ; } else if ( trig_data -> prev_brightness != LED_OFF ) swconfig_trig_set_brightness ( trig_data , LED_OFF ) ; trig_data -> prev_traffic = traffic ; } trig_data -> prev_link = link ; }
link off -> led off (can't be any other reason to turn it on)
 link on:
      mode link: led on by default only if speed matches, else off
      mode txrx: blink only if speed matches, else off
link off - > led off ( can ' t be any other reason to turn it on ) link on : mode link : led on by default only if speed matches else off mode txrx : blink only if speed matches else off
/* and stop */ /* link speed flag */ /* At least one port speed matches speed_mask */