// this is a device tree *overlay* file, concept described here:
// - <https://docs.kernel.org/devicetree/overlay-notes.html>
// the dtb deployed to the device will be, in effect, the union of the in-kernel rk3399-pinephone-pro.dts
// merged with this dts.
//
// resources for writing device tree overlays:
// - <https://developer.toradex.com/software/linux-resources/device-tree/device-tree-overlays-overview/>

/dts-v1/;
/plugin/;

/ {
        /* ensure this overlay applies only to the correct board */
        compatible = "pine64,pinephone-pro";
};

&{/} {
        bat: battery {
                /* these parameters are taken from megi's rk3399-pinephone-pro.dts */
                compatible = "simple-battery";
                voltage-min-design-microvolt = <3400000>;
                voltage-max-design-microvolt = <4350000>;
                energy-full-design-microwatt-hours = <11400000>;
                charge-full-design-microamp-hours = <3000000>;
                precharge-current-microamp = <120000>;
                charge-term-current-microamp = <150000>;
                constant-charge-current-max-microamp = <1500000>;
                constant-charge-voltage-max-microvolt = <4350000>;
                factory-internal-resistance-micro-ohms = <150000>;
                resistance-temp-table = <20 150>;
                ocv-capacity-celsius = <20>;
                ocv-capacity-table-0 =
                        <4308000 100>,
                        <4217000 95>,
                        <4161000 90>,
                        <4110000 85>,
                        <4066000 80>,
                        <4007000 75>,
                        <3974000 70>,
                        <3937000 65>,
                        <3896000 60>,
                        <3853000 55>,
                        <3827000 50>,
                        <3807000 45>,
                        <3793000 40>,
                        <3780000 35>,
                        <3768000 30>,
                        <3756000 25>,
                        <3740000 20>,
                        <3716000 15>,
                        <3689000 10>,
                        <3675000 5>,
                        <3400000 0>;
        };
};

&rk818 {
        battery {
                compatible = "rockchip,rk818-battery";
                ocv_table = <3400 3675 3689 3716 3740 3756 3768 3780
                        3793 3807 3827 3853 3896 3937 3974 4007 4066
                        4110 4161 4217 4308>;
                design_capacity = <2916>;
                design_qmax = <2708>;
                bat_res = <150>;
                max_input_current = <3000>;
                max_chrg_current = <2000>;
                max_chrg_voltage = <4350>;
                sleep_enter_current = <300>;
                sleep_exit_current = <300>;
                power_off_thresd = <3400>;
                zero_algorithm_vol = <3950>;
                fb_temperature = <105>;
                sample_res = <10>;
                max_soc_offset = <60>;
                energy_mode = <0>;
                monitor_sec = <5>;
                virtual_power = <0>;
                power_dc2otg = <0>;
                otg5v_suspend_enable = <1>;
        };

        charger {
                compatible = "rockchip,rk818-charger";
                // TODO: this requires declaring the fusb0 rail (which megi has helpfully done already)
                // power-supplies = <&fusb0>;
                monitored-battery = <&bat>;
        };

};
