distribution/projects/Rockchip/packages/u-boot/patches/RK3566-X55/001-charge-led.patch
fewtarius 7bada0c6f0
* Fix issue with Powkiddy x55 booting when plugged into charger.
* Fix missing power LED when charging while powered off.
2023-05-26 16:23:02 +00:00

219 lines
7.4 KiB
Diff

diff --git a/arch/arm/dts/rk3568-evb.dts b/arch/arm/dts/rk3568-evb.dts
index 950bc3a..f893a9a 100644
--- a/arch/arm/dts/rk3568-evb.dts
+++ b/arch/arm/dts/rk3568-evb.dts
@@ -28,30 +28,77 @@
press-threshold-microvolt = <9>;
};
};
- leds: gpio-leds {
+ /*leds: gpio-leds {
compatible = "gpio-leds";
pinctrl-names = "default";
pinctrl-0 =<&leds_gpio>;
led@1 {
- gpios = <&gpio0 RK_PC5 GPIO_ACTIVE_HIGH>;
+ gpios = <&gpio4 RK_PC5 GPIO_ACTIVE_HIGH>;
label = "battery_full";
default-state="on";
retain-state-suspended;
};
led@2 {
- gpios = <&gpio0 RK_PC6 GPIO_ACTIVE_HIGH>;
+ gpios = <&gpio4 RK_PC6 GPIO_ACTIVE_HIGH>;
label = "battery_charging";
retain-state-suspended;
};
led@3 {
- gpios = <&gpio0 RK_PC7 GPIO_ACTIVE_HIGH>;
+ gpios = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>;
label = "low_power";
default-state="off";
retain-state-suspended;
};
+ };*/
+};
+
+&i2c0 {
+ rk817: pmic@20 {
+ battery {
+ compatible = "rk817,battery";
+ ocv_table = <3400 3553 3621 3688 3735 3768 3801
+ 3826 3843 3857 3878 3904 3934 3972
+ 4006 4020 4030 4044 4059 4083 4138>;
+ design_capacity = <3527>;
+ design_qmax = <3880>;
+ bat_res = <91>;
+ sleep_enter_current = <150>;
+ sleep_exit_current = <180>;
+ sleep_filter_current = <100>;
+ power_off_thresd = <3350>;
+ zero_algorithm_vol = <3300>;
+ max_soc_offset = <60>;
+ monitor_sec = <5>;
+ sample_res = <10>;
+ virtual_power = <0>;
+ // dc_det_gpio = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>;//uboot使用
+ charge_red_gpio = <&gpio4 RK_PB4 GPIO_ACTIVE_HIGH>;//充电指示灯 红
+ charge_green_gpio = <&gpio4 RK_PB5 GPIO_ACTIVE_HIGH>;//充电指示灯 绿
+ charge_yellow_gpio = <&gpio4 RK_PB6 GPIO_ACTIVE_HIGH>;//充电指示灯 黄
+ };
+
+ charger {
+ compatible = "rk817,charger";
+ min_input_voltage = <4500>;
+ max_input_current = <2000>;
+ max_chrg_current = <2000>;
+ max_chrg_voltage = <4300>;
+ chrg_term_mode = <0>;
+ chrg_finish_cur = <300>;
+ virtual_power = <0>;
+ dc_det_adc = <0>;
+ // dc_det_gpio = <&gpio4 RK_PC4 GPIO_ACTIVE_HIGH>;
+ charge_red_gpio = <&gpio4 RK_PB4 GPIO_ACTIVE_HIGH>;//充电指示灯 红
+ charge_green_gpio = <&gpio4 RK_PB5 GPIO_ACTIVE_HIGH>;//充电指示灯 绿
+ charge_yellow_gpio = <&gpio4 RK_PB6 GPIO_ACTIVE_HIGH>;//充电指示灯 黄
+ pinctrl-names = "default";
+ pinctrl-0 = <&charge_led_gpio>;
+ extcon = <&usb2phy0>;
+ gate_function_disable = <1>;
+ };
};
};
@@ -131,12 +178,20 @@
};
&pinctrl {
- gpio-leds {
+ /*gpio-leds {
leds_gpio: leds-gpio {
rockchip,pins =
- <0 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>,
- <0 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>,
- <0 RK_PC7 RK_FUNC_GPIO &pcfg_pull_none>;
+ <4 RK_PC5 RK_FUNC_GPIO &pcfg_pull_none>,
+ <4 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>,
+ <4 RK_PC4 RK_FUNC_GPIO &pcfg_pull_none>;
};
- };
+ };*/
+ led {
+ charge_led_gpio:charge-led-gpio{
+ rockchip,pins = <4 RK_PB4 RK_FUNC_GPIO &pcfg_pull_none>,
+ <4 RK_PB5 RK_FUNC_GPIO &pcfg_pull_none>,
+ <4 RK_PB6 RK_FUNC_GPIO &pcfg_pull_none>;
+ };
+
+ };
};
diff --git a/drivers/power/fuel_gauge/fg_rk817.c b/drivers/power/fuel_gauge/fg_rk817.c
index b5abb72..f54188c 100644
--- a/drivers/power/fuel_gauge/fg_rk817.c
+++ b/drivers/power/fuel_gauge/fg_rk817.c
@@ -256,6 +256,10 @@ struct rk817_battery_device {
u32 bat_res_up;
u32 bat_res_down;
u32 variant;
+ struct gpio_desc dc_det_gpio;
+ struct gpio_desc charge_red_gpio;
+ struct gpio_desc charge_green_gpio;
+ struct gpio_desc charge_yellow_gpio;
};
static u32 interpolate(int value, u32 *table, int size)
@@ -948,15 +952,27 @@ static int rk817_bat_update_get_current(struct udevice *dev)
return VIRTUAL_POWER_CUR;
}
+static int get_dc_statue(struct rk817_battery_device *battery)
+{
+
+// printf("%s.... dc status = %d \n",__func__,dm_gpio_get_value(&battery->dc_det_gpio));
+ if (dm_gpio_get_value(&battery->dc_det_gpio))
+ return true;
+ else
+ return false;
+}
static int rk817_bat_dwc_otg_check_dpdm(struct rk817_battery_device *battery)
{
if (battery->variant == RK809_ID) {
+ // printf("%s.... rk809 \n",__func__);
if (rk817_bat_read(battery, PMIC_SYS_STS) & PLUG_IN_STS)
return AC_CHARGER;
else
return NO_CHARGER;
} else {
+ // printf("%s.... rk817 \n",__func__);
return rockchip_chg_get_type();
+ // return get_dc_statue(battery);
}
}
@@ -1186,6 +1202,23 @@ static void rk817_bat_smooth_charge(struct rk817_battery_device *battery)
else if (battery->dsoc < 0)
battery->dsoc = 0;
+ //黄灯
+ if (get_dc_statue(battery)){
+ dm_gpio_set_value(&battery->charge_yellow_gpio,1);
+ if (battery->dsoc == 100)
+ dm_gpio_set_value(&battery->charge_yellow_gpio,0);
+ }else
+ dm_gpio_set_value(&battery->charge_yellow_gpio,0);
+
+ //红绿
+ if (battery->dsoc >= 15){
+ dm_gpio_set_value(&battery->charge_green_gpio,1); //电量足
+ dm_gpio_set_value(&battery->charge_red_gpio,0);
+ }else{
+ dm_gpio_set_value(&battery->charge_green_gpio,0); //电量不足
+ dm_gpio_set_value(&battery->charge_red_gpio,1);
+ }
+
rk817_bat_save_dsoc(battery, battery->dsoc);
rk817_bat_save_cap(battery, battery->remain_cap / 1000);
out:
@@ -1319,6 +1352,39 @@ static int rk817_fg_ofdata_to_platdata(struct udevice *dev)
battery->res_div = (value == SAMPLE_RES_20mR) ?
SAMPLE_RES_DIV2 : SAMPLE_RES_DIV1;
+ value = gpio_request_by_name_nodev(dev_ofnode(dev), "dc_det_gpio",
+ 0, &battery->dc_det_gpio,GPIOD_IS_IN);
+ if (!value) {
+ printf("DC is valid\n");
+ } else {
+ printf("DC is invalid\n");
+ }
+
+ value = gpio_request_by_name_nodev(dev_ofnode(dev), "charge_red_gpio",
+ 0, &battery->charge_red_gpio,GPIOD_IS_OUT);
+ if (!value) {
+ printf("charge_red_gpio is valid\n");
+ } else {
+ printf("charge_red_gpio is invalid\n");
+ }
+
+ value = gpio_request_by_name_nodev(dev_ofnode(dev), "charge_green_gpio",
+ 0, &battery->charge_green_gpio,GPIOD_IS_OUT);
+ if (!value) {
+ printf("charge_green_gpio is valid\n");
+ } else {
+ printf("charge_green_gpio is invalid\n");
+ }
+
+
+ value = gpio_request_by_name_nodev(dev_ofnode(dev), "charge_yellow_gpio",
+ 0, &battery->charge_yellow_gpio,GPIOD_IS_OUT);
+ if (!value) {
+ printf("charge_yellow_gpio is valid\n");
+ } else {
+ printf("charge_yellow_gpio is invalid\n");
+ }
+
DBG("OCV Value:");
for (i = 0; i < battery->ocv_size; i++)
DBG("%d ", battery->ocv_table[i]);