1 /* 2 * (C) Copyright 2017 Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <common.h> 8 #include <command.h> 9 #include <dm.h> 10 #include <power/charge_display.h> 11 #include <power/charge_animation.h> 12 13 static int do_charge_display(cmd_tbl_t *cmdtp, int flag, int argc, 14 char *const argv[]) 15 { 16 17 struct charge_animation_pdata *pdata; 18 struct udevice *dev; 19 int screen_voltage; 20 int on_voltage; 21 int on_soc; 22 int save[3]; 23 int ret; 24 25 if (argc != 4 && argc != 1) 26 return CMD_RET_USAGE; 27 28 ret = uclass_get_device(UCLASS_CHARGE_DISPLAY, 0, &dev); 29 if (ret) { 30 if (ret != -ENODEV) { 31 printf("Get UCLASS CHARGE DISPLAY failed: %d\n", ret); 32 return ret; 33 } 34 35 return 0; 36 } 37 38 if (argc == 4) { 39 pdata = dev_get_platdata(dev); 40 save[0] = pdata->exit_charge_level; 41 save[1] = pdata->exit_charge_voltage; 42 save[2] = pdata->screen_on_voltage; 43 44 on_soc = simple_strtoul(argv[1], NULL, 0); 45 on_voltage = simple_strtoul(argv[2], NULL, 0); 46 screen_voltage = simple_strtoul(argv[3], NULL, 0); 47 debug("new: on_soc=%d, on_voltage=%d, screen_voltage=%d\n", 48 on_soc, on_voltage, screen_voltage); 49 50 pdata->exit_charge_level = on_soc; 51 pdata->exit_charge_voltage = on_voltage; 52 pdata->screen_on_voltage = screen_voltage; 53 54 charge_display_show(dev); 55 56 pdata->exit_charge_level = save[0]; 57 pdata->exit_charge_voltage = save[1]; 58 pdata->screen_on_voltage = save[2]; 59 } else if (argc == 1) { 60 charge_display_show(dev); 61 } else { 62 return CMD_RET_USAGE; 63 } 64 65 return 0; 66 } 67 68 U_BOOT_CMD(charge, 4, 0, do_charge_display, 69 "Charge display", 70 "-charge\n" 71 "-charge <power on soc> <power on voltage> <screen on voltage>" 72 ); 73