| // SPDX-License-Identifier: (GPL-2.0+ OR MIT) |
| /* |
| * Copyright (c) 2024 Amlogic, Inc. All rights reserved. |
| */ |
| |
| #include <common.h> |
| #include <command.h> |
| |
| #include <amlogic/leds-main.h> |
| |
| static void do_turn_on_led(enum LED_ANIMATION led_animation, int led_index) |
| { |
| int i; |
| |
| if (led_index >= NUM_LEDS) |
| return; |
| |
| if (led_index != NUM_LEDS) { |
| turn_on_led(led_animation, led_index); |
| } else { |
| for (i = 0; i < NUM_LEDS; ++i) |
| turn_on_led(led_animation, i); |
| } |
| } |
| |
| int do_led_status_on(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| { |
| int led_animation; |
| int led_index = NUM_LEDS; |
| |
| if (argc < 2) { |
| printf("led_index parameter error\n"); |
| return -1; |
| } else { |
| led_animation = simple_strtoul(argv[1], NULL, 16); |
| if (argc >= 3) |
| led_index = simple_strtoul(argv[2], NULL, 16); |
| |
| switch (led_animation) { |
| case WHITE: |
| do_turn_on_led(WHITE, led_index); |
| break; |
| case YELLOW: |
| do_turn_on_led(YELLOW, led_index); |
| break; |
| case GREEN: |
| do_turn_on_led(GREEN, led_index); |
| break; |
| case BLUE: |
| do_turn_on_led(BLUE, led_index); |
| break; |
| case ORANGE: |
| do_turn_on_led(ORANGE, led_index); |
| break; |
| case PURPLE: |
| do_turn_on_led(PURPLE, led_index); |
| break; |
| case PINK: |
| do_turn_on_led(PINK, led_index); |
| break; |
| default: |
| pr_err("LED: unknown led animation\n"); |
| break; |
| } |
| } |
| return 0; |
| } |
| |
| int do_led_status_off(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| { |
| unsigned int led_index; |
| |
| if (argc < 1) { |
| printf("led_index parameter error\n"); |
| return -1; |
| } |
| led_index = simple_strtoul(argv[1], NULL, 10); |
| turn_off_led(led_index); |
| return 0; |
| } |
| |
| int do_show_udisk_led(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| { |
| udisk_update_led_status(); |
| return 0; |
| } |
| |
| int do_show_start_kernel_led(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
| { |
| const char *reboot_mode_val = env_get("reboot_mode"); |
| |
| if (strncmp(reboot_mode_val, "cold_boot", sizeof("cold_boot")) == 0) { |
| start_kernel_led_status(); |
| return -1; |
| } |
| return 0; |
| } |
| |
| U_BOOT_CMD(led_status_on, 3, 0, do_led_status_on, |
| "led_status_on [color] [index]", |
| "\n" |
| "color: White(0), yellow(1), Green:(2), Blue(3), orange(4), purple(5), pink(6)\n" |
| " led_status_on 0 3 : white 3 on\n" |
| " led_status_on 0 : all white on\n" |
| ); |
| |
| U_BOOT_CMD(led_status_off, 2, 0, do_led_status_off, |
| "led_status_off [index]", |
| "\n" |
| " led_status_off 3 : led 3 off\n" |
| ); |
| |
| U_BOOT_CMD(show_udisk_led, 1, 0, do_show_udisk_led, |
| "show_udisk_led", |
| "\n" |
| " show led status when udisk update\n" |
| ); |
| |
| U_BOOT_CMD(show_start_kernel_led, 1, 0, do_show_start_kernel_led, |
| "show_start_kernel_led", |
| "\n" |
| " show led status when start kernel\n" |
| ); |