b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame^] | 1 | #include <errno.h> |
| 2 | #include <common.h> |
| 3 | #include <command.h> |
| 4 | #include <linux/types.h> |
| 5 | #ifdef CONFIG_LCD_DISP |
| 6 | #include <asm/arch/pxa1826fb.h> |
| 7 | #endif |
| 8 | |
| 9 | #define MAX_LCD_STAGE 20 |
| 10 | |
| 11 | __weak void lcd_show_battery_stage(int stage) {} |
| 12 | __weak void lcd_show_log(void) {} |
| 13 | |
| 14 | u8 bat_20_stage_array[MAX_LCD_STAGE] = { |
| 15 | 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, |
| 16 | 55, 60, 65, 70, 75, 80, 85, 90, 95, 100 |
| 17 | }; |
| 18 | |
| 19 | static int get_bat_base_stage(int percent) |
| 20 | { |
| 21 | int i; |
| 22 | |
| 23 | for(i = 0; i < MAX_LCD_STAGE; i++) { |
| 24 | if (percent < bat_20_stage_array[i]) |
| 25 | return i; |
| 26 | else |
| 27 | continue; |
| 28 | } |
| 29 | |
| 30 | return i; |
| 31 | } |
| 32 | |
| 33 | void lcd_show_bat_charging(int percent) |
| 34 | { |
| 35 | int current_stage; |
| 36 | static int base_stage, disp_stage = 0xffff; |
| 37 | |
| 38 | if (percent >= 100) { |
| 39 | lcd_show_battery_stage(MAX_LCD_STAGE); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | current_stage = get_bat_base_stage(percent); |
| 44 | if (disp_stage == 0xffff) { /* the 1st entry */ |
| 45 | disp_stage = current_stage; |
| 46 | base_stage = current_stage; |
| 47 | } else { |
| 48 | /* update base stage */ |
| 49 | if (current_stage != base_stage) |
| 50 | base_stage = current_stage; |
| 51 | /* display stage round back */ |
| 52 | if (disp_stage > MAX_LCD_STAGE) |
| 53 | disp_stage = base_stage; |
| 54 | } |
| 55 | |
| 56 | debug("current_stage: %d\n", current_stage); |
| 57 | debug("disp_stage: %d\n", disp_stage); |
| 58 | debug("base_stage: %d\n", base_stage); |
| 59 | lcd_show_battery_stage(disp_stage); |
| 60 | disp_stage++; |
| 61 | } |
| 62 | |
| 63 | void lcd_show_bat_soc(int percent) |
| 64 | { |
| 65 | int base_stage; |
| 66 | |
| 67 | if (percent >= 100) { |
| 68 | lcd_show_battery_stage(MAX_LCD_STAGE); |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | base_stage = get_bat_base_stage(percent); |
| 73 | lcd_show_battery_stage(base_stage); |
| 74 | } |
| 75 | |
| 76 | void lcd_show_no_battery(void) |
| 77 | { |
| 78 | lcd_show_battery_stage(-1); |
| 79 | } |
| 80 | |
| 81 | void lcd_show_mrvl_log(void) |
| 82 | { |
| 83 | lcd_show_log(); |
| 84 | } |