Lines Matching +full:led +full:- +full:4
1 // SPDX-License-Identifier: GPL-2.0
14 * Internal PHY 3 has port at index 4. in qca8k_phy_to_port()
15 * Internal PHY 4 has port at index 5. in qca8k_phy_to_port()
26 reg_info->reg = QCA8K_LED_CTRL_REG(led_num); in qca8k_get_enable_led_reg()
27 reg_info->shift = QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT; in qca8k_get_enable_led_reg()
33 reg_info->reg = QCA8K_LED_CTRL3_REG; in qca8k_get_enable_led_reg()
34 reg_info->shift = QCA8K_LED_PHY123_PATTERN_EN_SHIFT(port_num, led_num); in qca8k_get_enable_led_reg()
36 case 4: in qca8k_get_enable_led_reg()
37 reg_info->reg = QCA8K_LED_CTRL_REG(led_num); in qca8k_get_enable_led_reg()
38 reg_info->shift = QCA8K_LED_PHY4_CONTROL_RULE_SHIFT; in qca8k_get_enable_led_reg()
41 return -EINVAL; in qca8k_get_enable_led_reg()
50 reg_info->reg = QCA8K_LED_CTRL_REG(led_num); in qca8k_get_control_led_reg()
53 * 3 control rules for phy0-3 that applies to all their leds in qca8k_get_control_led_reg()
56 if (port_num == 4) in qca8k_get_control_led_reg()
57 reg_info->shift = QCA8K_LED_PHY4_CONTROL_RULE_SHIFT; in qca8k_get_control_led_reg()
59 reg_info->shift = QCA8K_LED_PHY0123_CONTROL_RULE_SHIFT; in qca8k_get_control_led_reg()
84 return -EOPNOTSUPP; in qca8k_parse_netdev()
87 * - Blink at 4Hz by default in qca8k_parse_netdev()
95 qca8k_led_brightness_set(struct qca8k_led *led, in qca8k_led_brightness_set() argument
99 struct qca8k_priv *priv = led->priv; in qca8k_led_brightness_set()
102 qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); in qca8k_led_brightness_set()
108 /* HW regs to control brightness is special and port 1-2-3 in qca8k_led_brightness_set()
112 * - the 2 bit (15, 14) of: in qca8k_led_brightness_set()
113 * - QCA8K_LED_CTRL0_REG for led1 in qca8k_led_brightness_set()
114 * - QCA8K_LED_CTRL1_REG for led2 in qca8k_led_brightness_set()
115 * - QCA8K_LED_CTRL2_REG for led3 in qca8k_led_brightness_set()
117 * To control port 4: in qca8k_led_brightness_set()
118 * - the 2 bit (31, 30) of: in qca8k_led_brightness_set()
119 * - QCA8K_LED_CTRL0_REG for led1 in qca8k_led_brightness_set()
120 * - QCA8K_LED_CTRL1_REG for led2 in qca8k_led_brightness_set()
121 * - QCA8K_LED_CTRL2_REG for led3 in qca8k_led_brightness_set()
124 * - the 2 bit at (9, 8) of QCA8K_LED_CTRL3_REG are used for led1 in qca8k_led_brightness_set()
125 * - the 2 bit at (11, 10) of QCA8K_LED_CTRL3_REG are used for led2 in qca8k_led_brightness_set()
126 * - the 2 bit at (13, 12) of QCA8K_LED_CTRL3_REG are used for led3 in qca8k_led_brightness_set()
129 * - the 2 bit at (15, 14) of QCA8K_LED_CTRL3_REG are used for led1 in qca8k_led_brightness_set()
130 * - the 2 bit at (17, 16) of QCA8K_LED_CTRL3_REG are used for led2 in qca8k_led_brightness_set()
131 * - the 2 bit at (19, 18) of QCA8K_LED_CTRL3_REG are used for led3 in qca8k_led_brightness_set()
134 * - the 2 bit at (21, 20) of QCA8K_LED_CTRL3_REG are used for led1 in qca8k_led_brightness_set()
135 * - the 2 bit at (23, 22) of QCA8K_LED_CTRL3_REG are used for led2 in qca8k_led_brightness_set()
136 * - the 2 bit at (25, 24) of QCA8K_LED_CTRL3_REG are used for led3 in qca8k_led_brightness_set()
138 * To abstract this and have less code, we use the port and led numm in qca8k_led_brightness_set()
140 * not having a 1:1 map of LED with the regs. in qca8k_led_brightness_set()
142 if (led->port_num == 0 || led->port_num == 4) { in qca8k_led_brightness_set()
149 return regmap_update_bits(priv->regmap, reg_info.reg, in qca8k_led_brightness_set()
158 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_brightness_set_blocking() local
160 return qca8k_led_brightness_set(led, brightness); in qca8k_cled_brightness_set_blocking()
164 qca8k_led_brightness_get(struct qca8k_led *led) in qca8k_led_brightness_get() argument
167 struct qca8k_priv *priv = led->priv; in qca8k_led_brightness_get()
171 qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); in qca8k_led_brightness_get()
173 ret = regmap_read(priv->regmap, reg_info.reg, &val); in qca8k_led_brightness_get()
179 if (led->port_num == 0 || led->port_num == 4) { in qca8k_led_brightness_get()
186 /* Assume brightness ON only when the LED is set to always ON */ in qca8k_led_brightness_get()
195 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_blink_set() local
198 struct qca8k_priv *priv = led->priv; in qca8k_cled_blink_set()
206 /* The hardware only supports blinking at 4Hz. Fall back in qca8k_cled_blink_set()
209 return -EINVAL; in qca8k_cled_blink_set()
212 qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); in qca8k_cled_blink_set()
214 if (led->port_num == 0 || led->port_num == 4) { in qca8k_cled_blink_set()
221 regmap_update_bits(priv->regmap, reg_info.reg, mask << reg_info.shift, in qca8k_cled_blink_set()
230 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_trigger_offload() local
233 struct qca8k_priv *priv = led->priv; in qca8k_cled_trigger_offload()
236 qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); in qca8k_cled_trigger_offload()
241 if (led->port_num == 0 || led->port_num == 4) { in qca8k_cled_trigger_offload()
248 return regmap_update_bits(priv->regmap, reg_info.reg, mask << reg_info.shift, in qca8k_cled_trigger_offload()
255 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_hw_control_status() local
258 struct qca8k_priv *priv = led->priv; in qca8k_cled_hw_control_status()
261 qca8k_get_enable_led_reg(led->port_num, led->led_num, ®_info); in qca8k_cled_hw_control_status()
263 regmap_read(priv->regmap, reg_info.reg, &val); in qca8k_cled_hw_control_status()
267 if (led->port_num == 0 || led->port_num == 4) { in qca8k_cled_hw_control_status()
288 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_hw_control_set() local
290 struct qca8k_priv *priv = led->priv; in qca8k_cled_hw_control_set()
302 qca8k_get_control_led_reg(led->port_num, led->led_num, ®_info); in qca8k_cled_hw_control_set()
304 return regmap_update_bits(priv->regmap, reg_info.reg, in qca8k_cled_hw_control_set()
312 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_hw_control_get() local
314 struct qca8k_priv *priv = led->priv; in qca8k_cled_hw_control_get()
320 return -EINVAL; in qca8k_cled_hw_control_get()
322 qca8k_get_control_led_reg(led->port_num, led->led_num, ®_info); in qca8k_cled_hw_control_get()
324 ret = regmap_read(priv->regmap, reg_info.reg, &val); in qca8k_cled_hw_control_get()
352 struct qca8k_led *led = container_of(ldev, struct qca8k_led, cdev); in qca8k_cled_hw_control_get_device() local
353 struct qca8k_priv *priv = led->priv; in qca8k_cled_hw_control_get_device()
356 dp = dsa_to_port(priv->ds, qca8k_phy_to_port(led->port_num)); in qca8k_cled_hw_control_get_device()
359 if (dp->user) in qca8k_cled_hw_control_get_device()
360 return &dp->user->dev; in qca8k_cled_hw_control_get_device()
367 struct fwnode_handle *led = NULL, *leds = NULL; in qca8k_parse_port_leds() local
376 dev_dbg(priv->dev, "No Leds node specified in device tree for port %d!\n", in qca8k_parse_port_leds()
381 fwnode_for_each_child_node(leds, led) { in qca8k_parse_port_leds()
382 /* Reg represent the led number of the port. in qca8k_parse_port_leds()
385 * 1. is gigabit led in qca8k_parse_port_leds()
386 * 2. is mbit led in qca8k_parse_port_leds()
387 * 3. additional status led in qca8k_parse_port_leds()
389 if (fwnode_property_read_u32(led, "reg", &led_num)) in qca8k_parse_port_leds()
393 dev_warn(priv->dev, "Invalid LED reg %d defined for port %d", in qca8k_parse_port_leds()
400 port_led = &priv->ports_led[led_index]; in qca8k_parse_port_leds()
401 port_led->port_num = port_num; in qca8k_parse_port_leds()
402 port_led->led_num = led_num; in qca8k_parse_port_leds()
403 port_led->priv = priv; in qca8k_parse_port_leds()
405 state = led_init_default_state_get(led); in qca8k_parse_port_leds()
408 port_led->cdev.brightness = 1; in qca8k_parse_port_leds()
412 port_led->cdev.brightness = in qca8k_parse_port_leds()
416 port_led->cdev.brightness = 0; in qca8k_parse_port_leds()
420 port_led->cdev.max_brightness = 1; in qca8k_parse_port_leds()
421 port_led->cdev.brightness_set_blocking = qca8k_cled_brightness_set_blocking; in qca8k_parse_port_leds()
422 port_led->cdev.blink_set = qca8k_cled_blink_set; in qca8k_parse_port_leds()
423 port_led->cdev.hw_control_is_supported = qca8k_cled_hw_control_is_supported; in qca8k_parse_port_leds()
424 port_led->cdev.hw_control_set = qca8k_cled_hw_control_set; in qca8k_parse_port_leds()
425 port_led->cdev.hw_control_get = qca8k_cled_hw_control_get; in qca8k_parse_port_leds()
426 port_led->cdev.hw_control_get_device = qca8k_cled_hw_control_get_device; in qca8k_parse_port_leds()
427 port_led->cdev.hw_control_trigger = "netdev"; in qca8k_parse_port_leds()
429 init_data.fwnode = led; in qca8k_parse_port_leds()
432 priv->internal_mdio_bus->id, in qca8k_parse_port_leds()
435 fwnode_handle_put(led); in qca8k_parse_port_leds()
437 return -ENOMEM; in qca8k_parse_port_leds()
440 ret = devm_led_classdev_register_ext(priv->dev, &port_led->cdev, &init_data); in qca8k_parse_port_leds()
442 dev_warn(priv->dev, "Failed to init LED %d for port %d", led_num, port_num); in qca8k_parse_port_leds()
458 ports = device_get_named_child_node(priv->dev, "ports"); in qca8k_setup_led_ctrl()
460 dev_info(priv->dev, "No ports node specified in device tree!"); in qca8k_setup_led_ctrl()
475 * the correct port for LED setup. in qca8k_setup_led_ctrl()