From cdd89beea1d48b89c052b40a6dc0e399273769db Mon Sep 17 00:00:00 2001 From: "yaqiang.li" Date: Wed, 9 Nov 2022 12:12:56 +0800 Subject: [PATCH] regulator: Add hpu3501 regulator and update dts Signed-off-by: yaqiang.li --- arch/arm64/boot/dts/hobot/hobot-x3-dvb.dts | 104 +++++++++++++++++ arch/arm64/boot/dts/hobot/hobot-x3-pi.dts | 128 +++++++++++++++++++++ drivers/regulator/hpu3501.h | 101 ++++++++++++++++ 3 files changed, 333 insertions(+) create mode 100644 drivers/regulator/hpu3501.h diff --git a/arch/arm64/boot/dts/hobot/hobot-x3-dvb.dts b/arch/arm64/boot/dts/hobot/hobot-x3-dvb.dts index 3d3500118..c3afda7b1 100644 --- a/arch/arm64/boot/dts/hobot/hobot-x3-dvb.dts +++ b/arch/arm64/boot/dts/hobot/hobot-x3-dvb.dts @@ -144,6 +144,64 @@ turbo-mode; }; }; + + cpu_opp_table_hobot: cpu_opp_table_hobot { + compatible = "operating-points-v2"; + opp-shared; + opp00 { + opp-hz = /bits/ 64 <1200000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp01 { + opp-hz = /bits/ 64 <1000000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp02 { + opp-hz = /bits/ 64 <800000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp03 { + opp-hz = /bits/ 64 <500000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp04 { + opp-hz = /bits/ 64 <240000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp05 { + opp-hz = /bits/ 64 <1500000000>; + opp-microvolt = <990000>; + clock-latency-ns = <500000>; + turbo-mode; + }; + }; + + camera_pd_dc_2v8: camera_pd_dc_2v8 { + status = "disabled"; + compatible = "regulator-gpio"; + regulator-name = "VCC28_CAM"; + regulator-min-microvolt = <2800000>; + regulator-max-microvolt = <3000000>; + enable-gpio = <&gpios 92 0>; + states = <3000000 0>; + enable-active-high; + }; + + camera_pd_dc_1v8: camera_pd_dc_1v8 { + status = "disabled"; + compatible = "regulator-gpio"; + regulator-name = "VCC18_CAM"; + regulator-min-microvolt = <1800000>; + regulator-max-microvolt = <1800000>; + enable-gpio = <&gpios 93 0>; + states = <1800000 0>; + enable-active-high; + }; }; &i2c0 { @@ -188,10 +246,45 @@ }; }; + hpu3501@1e { + compatible = "hobot-pmic,hpu3501"; + reg = <0x1e>; + status = "disabled"; + regulators { + cnn0_pd_reg_hobot: BUCK3 { + regulator-name = "VCC_CNN0"; + regulator-min-microvolt = <820000>; + regulator-max-microvolt = <1000000>; + regulator-enable-ramp-delay = <3000>; + }; + + cnn1_pd_reg_hobot: BUCK4 { + regulator-name = "VCC_CNN1"; + regulator-min-microvolt = <820000>; + regulator-max-microvolt = <1000000>; + regulator-enable-ramp-delay = <3000>; + }; + + cpu_pd_reg_hobot: BUCK5 { + regulator-name = "VCC_CPU"; + regulator-min-microvolt = <795000>; + regulator-max-microvolt = <990000>; + regulator-always-on; + }; + + vdd_usb_0v8_hobot: LDO3 { + regulator-name = "USB_V_8"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-enable-ramp-delay = <3000>; + }; + }; + }; }; &usbdrd3_0 { usb_0v8-supply = <&vdd_usb_0v8>; + usb_0v8-supply_hobot = <&vdd_usb_0v8_hobot>; }; &dwc3_powersave { @@ -224,31 +317,40 @@ &cpu0 { cpu-supply = <&cpu_pd_reg>; + cpu-supply-hobot = <&cpu_pd_reg_hobot>; cpu-supply-dc = <&cpu_pd_reg_dc>; operating-points-v2-dc = <&cpu_opp_table_dc>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; }; &cpu1 { cpu-supply = <&cpu_pd_reg>; + cpu-supply-hobot = <&cpu_pd_reg_hobot>; cpu-supply-dc = <&cpu_pd_reg_dc>; operating-points-v2-dc = <&cpu_opp_table_dc>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; }; &cpu2 { cpu-supply = <&cpu_pd_reg>; + cpu-supply-hobot = <&cpu_pd_reg_hobot>; cpu-supply-dc = <&cpu_pd_reg_dc>; operating-points-v2-dc = <&cpu_opp_table_dc>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; }; &cpu3 { cpu-supply = <&cpu_pd_reg>; + cpu-supply-hobot = <&cpu_pd_reg_hobot>; cpu-supply-dc = <&cpu_pd_reg_dc>; operating-points-v2-dc = <&cpu_opp_table_dc>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; }; &cnn0 { cnn-supply = <&cnn0_pd_reg>; cnn-supply-dc = <&cnn0_pd_reg_dc>; + cnn-supply-hobot = <&cnn0_pd_reg_hobot>; operating-points-v2-dc = <&cnn_opp_table_dc>; operating-points-v2-lite = <&cnn_opp_table_lite>; operating-points-v2-dc-lite = <&cnn_opp_table_dc_lite>; @@ -259,6 +361,7 @@ &cnn1 { cnn-supply = <&cnn1_pd_reg>; cnn-supply-dc = <&cnn1_pd_reg_dc>; + cnn-supply-hobot = <&cnn1_pd_reg_hobot>; operating-points-v2-dc = <&cnn_opp_table_dc>; operating-points-v2-lite = <&cnn_opp_table_lite>; operating-points-v2-dc-lite = <&cnn_opp_table_dc_lite>; @@ -316,3 +419,4 @@ status = "disabled"; // camera_check_irq_pin = <117>; // camera lock check pin }; + diff --git a/arch/arm64/boot/dts/hobot/hobot-x3-pi.dts b/arch/arm64/boot/dts/hobot/hobot-x3-pi.dts index 7cf0ddbb7..6bafbef58 100755 --- a/arch/arm64/boot/dts/hobot/hobot-x3-pi.dts +++ b/arch/arm64/boot/dts/hobot/hobot-x3-pi.dts @@ -171,6 +171,42 @@ regulator-boot-on; enable-active-high; }; + + cpu_opp_table_hobot: cpu_opp_table_hobot { + compatible = "operating-points-v2"; + opp-shared; + opp00 { + opp-hz = /bits/ 64 <1200000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp01 { + opp-hz = /bits/ 64 <1000000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp02 { + opp-hz = /bits/ 64 <800000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp03 { + opp-hz = /bits/ 64 <500000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp04 { + opp-hz = /bits/ 64 <240000000>; + opp-microvolt = <795000>; + clock-latency-ns = <500000>; + }; + opp05 { + opp-hz = /bits/ 64 <1500000000>; + opp-microvolt = <990000>; + clock-latency-ns = <500000>; + turbo-mode; + }; + }; }; &power { @@ -256,6 +292,40 @@ rst-gpio = <&gpios 64 0>; status = "okay"; }; + hpu3501@1e { + compatible = "hobot-pmic,hpu3501"; + reg = <0x1e>; + status = "disabled"; + regulators { + cnn0_pd_reg_hobot: BUCK3 { + regulator-name = "VCC_CNN0"; + regulator-min-microvolt = <820000>; + regulator-max-microvolt = <1000000>; + regulator-enable-ramp-delay = <3000>; + }; + + cnn1_pd_reg_hobot: BUCK4 { + regulator-name = "VCC_CNN1"; + regulator-min-microvolt = <820000>; + regulator-max-microvolt = <1000000>; + regulator-enable-ramp-delay = <3000>; + }; + + cpu_pd_reg_hobot: BUCK5 { + regulator-name = "VCC_CPU"; + regulator-min-microvolt = <795000>; + regulator-max-microvolt = <990000>; + regulator-always-on; + }; + + vdd_usb_0v8_hobot: LDO3 { + regulator-name = "USB_V_8"; + regulator-min-microvolt = <3300000>; + regulator-max-microvolt = <3300000>; + regulator-enable-ramp-delay = <3000>; + }; + }; + }; }; &uart0 { @@ -283,6 +353,7 @@ &usbdrd3_0 { status = "okay"; + usb_0v8-supply_hobot = <&vdd_usb_0v8_hobot>; }; &usbdrd_dwc3_0 { @@ -469,6 +540,63 @@ }; }; +&cnn_opp_table { + opp00 { + opp-hz = /bits/ 64 <1000000000>; + opp-microvolt = <820000>; + clock-latency-ns = <500000>; + }; + opp01 { + opp-hz = /bits/ 64 <800000000>; + opp-microvolt = <820000>; + clock-latency-ns = <500000>; + }; + opp02 { + opp-hz = /bits/ 64 <400000000>; + opp-microvolt = <820000>; + clock-latency-ns = <500000>; + }; + opp03 { + opp-hz = /bits/ 64 <600000000>; + opp-microvolt = <820000>; + clock-latency-ns = <500000>; + }; +}; + + +&cpu0 { + cpu-supply-hobot = <&cpu_pd_reg_hobot>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; +}; + +&cpu1 { + cpu-supply-hobot = <&cpu_pd_reg_hobot>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; +}; + +&cpu2 { + cpu-supply-hobot = <&cpu_pd_reg_hobot>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; +}; + +&cpu3 { + cpu-supply-hobot = <&cpu_pd_reg_hobot>; + operating-points-v2-hobot = <&cpu_opp_table_hobot>; +}; + +&cnn0 { + cnn-supply-hobot = <&cnn0_pd_reg_hobot>; + governor = "userspace"; + max_freq = /bits/ 64 <1000000000>; +}; + +&cnn1 { + cnn-supply-hobot = <&cnn1_pd_reg_hobot>; + governor = "userspace"; + max_freq = /bits/ 64 <1000000000>; +}; + + &sdio0 { status = "okay"; bus-width = <8>; diff --git a/drivers/regulator/hpu3501.h b/drivers/regulator/hpu3501.h new file mode 100644 index 000000000..34db91846 --- /dev/null +++ b/drivers/regulator/hpu3501.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2022 Horizon Robotics + * + * This file is licensed under the terms of the GNU General Public + * License version 2. This program is licensed "as is" without any + * warranty of any kind, whether express or implied. + * + */ + +#ifndef DRIVERS_REGULATOR_HPU3501_H_ +#define DRIVERS_REGULATOR_HPU3501_H_ + +#include + +#define HPU3501_EN_PIN_RMPR 0X6 +#define HPU3501_OCP_CFG1R 0x8 +#define HPU3501_OCP_CFG2R 0x9 + +#define HPU3501_ON_OFF_CTRL 0x10 +#define HPU3501_BUCK1_ENA_BIT 0x1 +#define HPU3501_BUCK2_ENA_BIT 0x2 +#define HPU3501_BUCK3_ENA_BIT 0x4 +#define HPU3501_BUCK4_ENA_BIT 0x8 +#define HPU3501_BUCK5_ENA_BIT 0x10 +#define HPU3501_LDO1_ENA_BIT 0x20 +#define HPU3501_LDO2_CFG1_ENA_BIT 0x40 +#define HPU3501_LDO2_CFG2_ENA_BIT 0x40 +#define HPU3501_LDO3_ENA_BIT 0x80 +#define HPU3501_POWER_OFF 0 + +#define HPU3501_FAULT_CFGR 0Xa + +#define HPU3501_BUCK1_VSET 0x18 +#define HPU3501_BUCK2_VSET 0x1a +#define HPU3501_BUCK3_VSET 0x1c +#define HPU3501_BUCK4_VSET 0x1e +#define HPU3501_BUCK5_VSET 0x20 +#define HPU3501_LDO1_VSET 0x22 +#define HPU3501_LDO2_CFG1_VSET 0x24 +#define HPU3501_LDO2_CFG2_VSET 0x25 +#define HPU3501_LDO3_VSET 0x27 + +/* VSET - [7:0] */ +#define HPU3501_VSET_MASK8 0xff + +#define HPU3501_VOLTAGE_NUM256 256 + +enum { + ID_BUCK1, + ID_BUCK2, + ID_BUCK3, + ID_BUCK4, + ID_BUCK5, + + ID_LDO1, + ID_LDO2_CFG1, + ID_LDO2_CFG2, + ID_LDO3, +}; + +/** + * master: ture master pmic, false slave pmic + * en_pin_map: rigister 0x06 configuration + * fault_cfgr: rigister 0x0a configuration + * ocp_cfg1r: rigister 0x08 configuration + * ocp_cfg2r: rigister 0x09 configuration + */ +struct hpu3501 { + struct regmap *regmap; + bool master; + u32 en_pin_map; + u32 fault_cfgr; + u32 ocp_cfg1r; + u32 ocp_cfg2r; +}; + +/** + * hpu3501_regulator_data - regulator data + * @id: regulator id + * @name: regulator name + * @init_data: regulator init data + * @of_node: device tree node (optional) + */ +struct hpu3501_regulator_data { + int id; + const char *name; + struct regulator_init_data *init_data; + struct device_node *of_node; +}; + +/** + * hpu3501_platform_data - platform data for hpu3501 + * @num_regulators: number of regulators used + * @regulators: pointer to regulators used + */ +struct hpu3501_platform_data { + int num_regulators; + struct hpu3501_regulator_data *regulators; +}; + +#endif // DRIVERS_REGULATOR_HPU3501_H_