blob: 8a97340b0d53ad8a08ce04186bcd612aeaa5e2fa [file] [log] [blame]
junyi.zhaob7b6fcd2023-08-03 17:11:44 +08001#include "../drivers/amlogic/leds/fd650.h"
2#include <string.h>
3#include <common.h>
4#include <command.h>
5#include <dm.h>
6#include <led.h>
7#include <dm/uclass-internal.h>
8
9#define LEDMAPNUM 22
10
11typedef struct _led_bitmap {
12 u_int8 character;
13 u_int8 bitmap;
14} led_bitmap;
15
16const led_bitmap bcd_decode_tab[LEDMAPNUM] = {
17 {'0', 0x3F}, {'1', 0x06}, {'2', 0x5B}, {'3', 0x4F},
18 {'4', 0x66}, {'5', 0x6D}, {'6', 0x7D}, {'7', 0x07},
19 {'8', 0x7F}, {'9', 0x6F}, {'a', 0x77}, {'A', 0x77},
20 {'b', 0x7C}, {'B', 0x7C}, {'c', 0x58}, {'C', 0x39},
21 {'d', 0x5E}, {'D', 0x5E}, {'e', 0x79}, {'E', 0x79},
22 {'f', 0x71}, {'F', 0x71}
23};
24
25u_int8 led_get_code(char ch)
26{
27 u_int8 i, bitmap = 0x00;
28
29 for (i = 0; i < LEDMAPNUM; i++)
30 {
31 if (bcd_decode_tab[i].character == ch) {
32 bitmap = bcd_decode_tab[i].bitmap;
33 break;
34 }
35 }
36
37 return bitmap;
38}
39
40void led_show_650( char *str, unsigned char sec_flag, unsigned char lock)
41{
42 int i, iLenth;
43 int ret;
44 int data[4] = {0x00, 0x00, 0x00, 0x00};
45 struct udevice *dev;
46 struct fd650_bus *bus;
47
48 ret = led_get_by_label("fd650", &dev);
49 if (ret) {
50 printf("LED 'fd650' not found (err=%d)\n", ret);
51 return;
52 }
53 bus = dev_get_priv(dev);
54 if (strcmp(str, "") == 0 )
55 return;
56 iLenth = strlen(str);
57 if (iLenth > 4)
58 iLenth = 4;
59 for (i = 0; i < iLenth; i++) {
60 data[i] = led_get_code(str[i]);
61 }
62 fd650_write(bus, FD650_SYSON_8);
63 fd650_write(bus, FD650_DIG0 | (u_int8)data[0] | FD650_DOT);
64 if (sec_flag)
65 fd650_write(bus, FD650_DIG1 | (u_int8)data[1] | FD650_DOT );
66 else
67 fd650_write(bus, FD650_DIG1 | (u_int8)data[1] );
68 if (lock)
69 fd650_write(bus, FD650_DIG2 | (u_int8)data[2] | FD650_DOT);
70 else
71 fd650_write(bus, FD650_DIG2 | (u_int8)data[2]);
72 fd650_write(bus, FD650_DIG3 | (u_int8)data[3] | FD650_DOT);
73}
74
75int do_led_display(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
76{
77 char *display_str;
78
79 /* Validate arguments */
80 if (argc < 2)
81 return CMD_RET_USAGE;
82 display_str = argv[1];
83 led_show_650(display_str, 1, 1);
84
85 return 0;
86}
87
88U_BOOT_CMD(
89 led_display, 4, 1, do_led_display,
90 "display string on led",
91 "led <string>\tShow string on led\n"
92);