Lines Matching refs:led
56 static int ns2_led_get_mode(struct ns2_led *led, enum ns2_led_modes *mode) in ns2_led_get_mode() argument
62 cmd_level = gpiod_get_value_cansleep(led->cmd); in ns2_led_get_mode()
63 slow_level = gpiod_get_value_cansleep(led->slow); in ns2_led_get_mode()
65 for (i = 0; i < led->num_modes; i++) { in ns2_led_get_mode()
66 if (cmd_level == led->modval[i].cmd_level && in ns2_led_get_mode()
67 slow_level == led->modval[i].slow_level) { in ns2_led_get_mode()
68 *mode = led->modval[i].mode; in ns2_led_get_mode()
76 static void ns2_led_set_mode(struct ns2_led *led, enum ns2_led_modes mode) in ns2_led_set_mode() argument
81 for (i = 0; i < led->num_modes; i++) in ns2_led_set_mode()
82 if (mode == led->modval[i].mode) in ns2_led_set_mode()
85 if (i == led->num_modes) in ns2_led_set_mode()
88 write_lock_irqsave(&led->rw_lock, flags); in ns2_led_set_mode()
90 if (!led->can_sleep) { in ns2_led_set_mode()
91 gpiod_set_value(led->cmd, led->modval[i].cmd_level); in ns2_led_set_mode()
92 gpiod_set_value(led->slow, led->modval[i].slow_level); in ns2_led_set_mode()
96 gpiod_set_value_cansleep(led->cmd, led->modval[i].cmd_level); in ns2_led_set_mode()
97 gpiod_set_value_cansleep(led->slow, led->modval[i].slow_level); in ns2_led_set_mode()
100 write_unlock_irqrestore(&led->rw_lock, flags); in ns2_led_set_mode()
106 struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev); in ns2_led_set() local
111 else if (led->sata) in ns2_led_set()
116 ns2_led_set_mode(led, mode); in ns2_led_set()
131 struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev); in ns2_led_sata_store() local
141 if (led->sata == enable) in ns2_led_sata_store()
144 led->sata = enable; in ns2_led_sata_store()
150 ns2_led_set_mode(led, NS_V2_LED_SATA); in ns2_led_sata_store()
152 ns2_led_set_mode(led, NS_V2_LED_ON); in ns2_led_sata_store()
162 struct ns2_led *led = container_of(led_cdev, struct ns2_led, cdev); in ns2_led_sata_show() local
164 return sprintf(buf, "%d\n", led->sata); in ns2_led_sata_show()
176 struct ns2_led *led) in ns2_led_register() argument
183 led->cmd = devm_fwnode_gpiod_get_index(dev, node, "cmd", 0, GPIOD_ASIS, in ns2_led_register()
185 if (IS_ERR(led->cmd)) in ns2_led_register()
186 return PTR_ERR(led->cmd); in ns2_led_register()
188 led->slow = devm_fwnode_gpiod_get_index(dev, node, "slow", 0, in ns2_led_register()
191 if (IS_ERR(led->slow)) in ns2_led_register()
192 return PTR_ERR(led->slow); in ns2_led_register()
208 rwlock_init(&led->rw_lock); in ns2_led_register()
210 led->cdev.blink_set = NULL; in ns2_led_register()
211 led->cdev.flags |= LED_CORE_SUSPENDRESUME; in ns2_led_register()
212 led->cdev.groups = ns2_led_groups; in ns2_led_register()
213 led->can_sleep = gpiod_cansleep(led->cmd) || gpiod_cansleep(led->slow); in ns2_led_register()
214 if (led->can_sleep) in ns2_led_register()
215 led->cdev.brightness_set_blocking = ns2_led_set_blocking; in ns2_led_register()
217 led->cdev.brightness_set = ns2_led_set; in ns2_led_register()
218 led->num_modes = nmodes; in ns2_led_register()
219 led->modval = modval; in ns2_led_register()
221 ret = ns2_led_get_mode(led, &mode); in ns2_led_register()
226 led->sata = (mode == NS_V2_LED_SATA) ? 1 : 0; in ns2_led_register()
227 led->cdev.brightness = (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL; in ns2_led_register()
231 ret = devm_led_classdev_register_ext(dev, &led->cdev, &init_data); in ns2_led_register()