Skip to content

Commit

Permalink
WIP: updated charger with power switching
Browse files Browse the repository at this point in the history
Added power switching for USB. Due to HW design faults it is not perfect.

HW design faults:
- USB-ID of microUSB for HOST and OTG is connected together
- USB power is connected together
- unsolved USB-charger vs. DCDC booster from battery (no HW interlock)

Due to this faults, very limited functions:
- USB-charger connected to (any) USB, later second USB can used as USB-device, powered from USB-charger
- USB-device connected to (any or both) USB, powered from DCDC booster
- USB-device connected to (any) USB and later connected USB-charger, powered from DCDC booster and USB-charger simultaneously !!!
	- added one per hour shutdown DCDC booster and test if USB-charger is present (it restarts USB-device) it starts charging after this test
- USB-charger and USB-device connected and later remove USB-charger, switch to DCDC booster (it restarts USB-device)
- USB-host can be connected only to USB-OTG (left, next to audio)
  • Loading branch information
mcerveny committed Oct 1, 2021
1 parent 8ba72d7 commit e9c7d9f
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 92 deletions.
72 changes: 36 additions & 36 deletions arch/arm/boot/dts/rk3128-wx8.dts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@
};
};

usb-control {
compatible = "rockchip,rk3126-usb-control";
host_drv_gpio = <&gpio3 0x14 0x00>;
// otg_drv_gpio power gpio for OTG
rockchip,grf = <&grf>;
rockchip,remote_wakeup;
rockchip,usb_irq_wakeup;
};

keys {
autorepeat;
compatible = "gpio-keys";
Expand Down Expand Up @@ -294,22 +285,27 @@
power-supply {
compatible = "wx8-charger";

pinctrl-0 = <&chg_ok &chg_led &dc_det_gpio &host_drv_gpio1 &host_drv_gpio2>;
pinctrl-0 = <&charging_gpio &dc_det_gpio &usb2sys_gpio &boost2usb_gpio>;
pinctrl-names = "default";

//chg_en RK_GPIO3 0x11
dc_det_gpio = <&gpio0 0x11 GPIO_ACTIVE_HIGH>;
chg_ok_gpio = <&gpio3 0x1a GPIO_ACTIVE_LOW>;
led_power_gpio = <&gpio1 0x07 GPIO_ACTIVE_LOW>;
//host_drv_gpio1 = <&gpio3 0x15 0x00>;
usb_boost_gpio = <&gpio1 0x09 GPIO_ACTIVE_HIGH>;
dc_det_gpio = <&gpio0 0x11 GPIO_ACTIVE_HIGH>; // input, works only when usb2sys_gpio
charging_gpio = <&gpio3 0x1a GPIO_ACTIVE_LOW>; // input, /CHRG output from TP4056

// both output cannot be active in same time (eg. LOW-LOW or HIGH-HIGH is allowed), beaware loop boost->usb->sys->boost
usb2sys_gpio = <&gpio3 0x15 GPIO_ACTIVE_LOW>; // output, power switch "vcc_usb" -> "vcc_sys" & "vcc_charger"
boost2usb_gpio = <&gpio1 0x09 GPIO_ACTIVE_HIGH>;// output, power switch "vcc_booster" -> vcc_usb"

io-channels = <&saradc 2>;
ref_voltage = <3300>; // from saradc -> vref-supply -> ?
voltage_divider = <200 200>; // adc resistot divider
discharge_table = <3400 3603 3706 3750 3773 3790 3825 3905 3997 4094 4205>;
charge_table = <3400 3603 3706 3750 3773 3790 3825 4905 3997 4094 4205>;
design_capacity = <3000>;
ref_voltage = <3300>; // mV, from saradc -> vref-supply -> ?
voltage_divider = <200 200>; // adc resistor divider

// TODO: calibration to real values
discharge_table = <3400 3603 3706 3750 3773 3790 3825 3905 3997 4094 4170>; // mV
charge_table = <3400 3603 3706 3750 3773 3790 3825 3905 3997 4094 4240>; // mV

design_capacity = <3000>; // mAh, battery "GSL475568"

extcon = <&u2phy>;
};
};

Expand Down Expand Up @@ -404,9 +400,6 @@

};

// unknown driver adc-battery { compatible = "rk30-adc-battery"; }
// unknown driver adc-pot { compatible = "gpio-keys-volume"; }

&dmc {
status = "okay";
center-supply = <&vdd_log>;
Expand Down Expand Up @@ -680,23 +673,15 @@
};

power {
chg_en: chg-en {
rockchip,pins = <RK_GPIO3 0x11 0x00 &pcfg_output_high>;
};

chg_ok: chg-ok {
charging_gpio: charging-gpio {
rockchip,pins = <RK_GPIO3 0x1a 0x00 &pcfg_pull_default>;
};

chg_led: chg-led {
rockchip,pins = <RK_GPIO1 0x07 0x00 &pcfg_pull_default>;
};

host_drv_gpio1: host-drv-gpio1 {
usb2sys_gpio: usb2sys-gpio {
rockchip,pins = <RK_GPIO3 0x15 0x00 &pcfg_pull_default>;
};

host_drv_gpio2: host-drv-gpio2 {
boost2usb_gpio: boost2usb-gpio {
rockchip,pins = <RK_GPIO1 0x09 0x00 &pcfg_pull_default>;
};

Expand All @@ -707,8 +692,23 @@

unresolved {
// now over /sys/class/gpio/
pm_enable: pm-enable {
boosters_enable: boosters-enable {
rockchip,pins = <RK_GPIO2 0x1d 0x00 &pcfg_pull_default>;
};

// unknown driver compatible = "rockchip,rk3126-usb-control"
host_drv_gpio: host-drv-gpio {
rockchip,pins = <RK_GPIO3 0x14 0x00 &pcfg_pull_default>;
};

// unknown driver function in original driver compatible = "rockchip,rk3126-usb-control"
chg_en: chg-en {
rockchip,pins = <RK_GPIO3 0x11 0x00 &pcfg_pull_default>;
};

// unknown driver function in original driver compatible = "rockchip,rk3126-usb-control"
led_power_gpio: led-power-gpio {
rockchip,pins = <RK_GPIO1 0x07 0x00 &pcfg_pull_default>;
};
};
};
2 changes: 0 additions & 2 deletions arch/arm/configs/wx8_defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,6 @@ CONFIG_USB_CONFIGFS=y
CONFIG_USB_CONFIGFS_MASS_STORAGE=y
CONFIG_USB_CONFIGFS_F_FS=y
CONFIG_USB_CONFIGFS_UEVENT=y
CONFIG_USB20_HOST=y
CONFIG_USB20_OTG=y
CONFIG_MMC=y
CONFIG_MMC_BLOCK_MINORS=16
CONFIG_MMC_DW=y
Expand Down
Loading

0 comments on commit e9c7d9f

Please sign in to comment.