mbox series

[v6,00/13] Add Qualcomm PMIC TPCM support

Message ID 20230501121111.1058190-1-bryan.odonoghue@linaro.org
Headers show
Series Add Qualcomm PMIC TPCM support | expand

Message

Bryan O'Donoghue May 1, 2023, 12:10 p.m. UTC
I'm dropping the previous V1-V5 log because the text is getting too long
here's a link to the previous cover letter instead
Link: https://lore.kernel.org/linux-usb/20230413113438.1577658-1-bryan.odonoghue@linaro.org/

Bootable tree
Link: https://git.codelinaro.org/bryan.odonoghue/kernel/-/tree/linux-next-23-04-28-pm8150b-tcpm-qcom-wrapper-typec-mux-bjorn 

Please note patch#5 and patch#6 should be merged in tandem not separately.

V6:

- I found an off-by-one bug when connecting a Type-C DP cable from Amazon
  which sends the max PD PDU - bod patch#7

- Drops the partial PHY orientation patch in favour of Bjorn's sc8280xp series
 
- Updates the commit log for the driver per Heikki's comment patch#7
- Adds Heikki's Acked-by to the driver patch#7

- Ammends commit log text - Marijn patch#4
- Typos highlithed - Marijn patch#4

- Adds Reviewed-by - Krzysztof patch#1
- Makes port@0 input required - Krzysztof patch#4
- Incorporate's Krzysztof's comments for quotation marks, minItems patch#5
- Adds Reviewed-by - Krzysztof patch#6

- Defines port/endpoint in sm8250.dtsi - patch#13 Konrad

- Luca. Would appreciate your testing.
  I don't see anything wrong with your reference dts
  Link: https://github.com/z3ntu/linux/blob/5db89528bd6f0f2e6027f2ad64a9178699be9bc0/arch/arm64/boot/dts/qcom/sm7225-fairphone-fp4.dts

  If we still can't get it working for you with Bjorn's patches maybe I can find
  a few cycles to debug with a FP4 after landing the 8250 bit.

  Caleb has something working for the rb3 based on these patches so, the gap can't be too big.

Here's how I'm testing using an RB5/SM8250

A) Confirm device mode works in both orientations

- Boot to a Linux shell
- Run usb-ecm-up.sh [1]
- This provides usb0 on the device side @ 192.168.8.2
- Attach Type-C cable to host PC
- On host PC "sudo ifconfig usb0 192.168.8.1"
- Ping 192.168.8.2 confirming ping works
- Switch cable orientation
- On the PC side re-assign the ip address "sudo ifconfig usb0 192.168.8.1"
- Ping again confirming connectivity

B) Test automatic host-mode transition, orientation and SuperSpeed
- Remove cable from PC
- Attach a Type-C USB key
- Validate the orientation detection
  cat /sys/class/typec/port0/orientation 
  normal 
- Confirm the RB5 sees the USB key as a SuperSpeed device
- Remove USB key and physically invert it along the horizontal axis
- Re-insert the key
- Confirm the RB5 sees the USB key as a SuperSpeed device
- Validate the orientation detection
  cat /sys/class/typec/port0/orientation 
  reverse

C) Test Type-C accessory automatic host-mode transition, orientation and SuperSpeed
- Remove USB key from RB5
- Attach a Type-C USB accessory
- Validate the orientation detection
  cat /sys/class/typec/port0/orientation 
  normal
- Attach a SuperSpeed capable USB key to the Type-C accessory
- Confirm the RB5 sees the USB key as a SuperSpeed device
- Remove the USB key from the Type-C accessory
- Remove the Type-C accessory from the RB5
- Physically invert the Type-C accessory along the horizontal axis
- Re-insert the Type-C accessory
- Validate the orientation detection
  cat /sys/class/typec/port0/orientation 
  reverse
- Re-insert the key
- Confirm the RB5 sees the USB key as a SuperSpeed device

D) Goto Test-A
- Confirming that automatic switch to device mode happens
- Repeat the above loop in ~ any order

[1] usb-ecm-up.sh 
#!/usr/bin/env bash

# load libcomposite module
modprobe libcomposite

# ensure function is loaded
modprobe usb_f_ecm
modprobe usb_f_ncm

mount -t configfs none /sys/kernel/config/

# create a gadget
mkdir /sys/kernel/config/usb_gadget/g0

# cd to its configfs node
cd /sys/kernel/config/usb_gadget/g0

# configure it (vid/pid can be anything if USB Class is used for driver compat)
echo 0x0525 > idVendor
echo 0xa4a4 > idProduct

# configure its serial/mfg/product
mkdir strings/0x409

echo 0xCAFEBABE > strings/0x409/serialnumber
echo Linaro > strings/0x409/manufacturer
echo qrb5165-rb5 > strings/0x409/product

# create configs
mkdir configs/c.1
mkdir configs/c.1/strings/0x409

# create the function (name must match a usb_f_<name> module such as 'acm')
mkdir functions/ncm.0

echo "CDC ECM" > configs/c.1/strings/0x409/configuration

# associate function with config
ln -s functions/ncm.0 configs/c.1

# Set USB version 3.1
echo 0x0310 > bcdUSB

echo "super-speed-plus" > max_speed

# enable gadget by binding it to a UDC from /sys/class/udc
echo a600000.usb > UDC
# to unbind it: echo "" > UDC; sleep 1; rm -rf /sys/kernel/config/usb_gadget/g0

sleep 1

ifconfig usb0 192.168.8.2

Bryan O'Donoghue (13):
  dt-bindings: regulator: qcom,usb-vbus-regulator: Mark reg as required
  dt-bindings: regulator: qcom,usb-vbus-regulator: Mark
    regulator-*-microamp required
  dt-bindings: phy: qcom,sc7180-qmp-usb3-dp-phy: Add orientation-switch
    as optional
  dt-bindings: phy: qcom,sc7180-qmp-usb3-dp-phy: Add input and output
    ports
  dt-bindings: usb: Add Qualcomm PMIC Type-C
  dt-bindings: mfd: qcom,spmi-pmic: Add typec to SPMI device types
  usb: typec: qcom: Add Qualcomm PMIC Type-C driver
  arm64: dts: qcom: sm8250: Define ports for qmpphy
    orientation-switching
  arm64: dts: qcom: pm8150b: Add a TCPM description
  arm64: dts: qcom: qrb5165-rb5: Switch on Type-C VBUS boost
  arm64: dts: qcom: qrb5165-rb5: Switch on basic TCPM
  arm64: dts: qcom: qrb5165-rb5: Switch on TCPM usb-role-switching for
    usb_1
  arm64: dts: qcom: qrb5165-rb5: Switch on TCPM orientation-switch for
    usb_1_qmpphy

 .../bindings/mfd/qcom,spmi-pmic.yaml          |   4 +
 .../phy/qcom,sc7180-qmp-usb3-dp-phy.yaml      |  44 ++
 .../regulator/qcom,usb-vbus-regulator.yaml    |  10 +-
 .../bindings/usb/qcom,pmic-typec.yaml         | 190 ++++++
 MAINTAINERS                                   |  10 +
 arch/arm64/boot/dts/qcom/pm8150b.dtsi         |  40 ++
 arch/arm64/boot/dts/qcom/qrb5165-rb5.dts      |  56 +-
 arch/arm64/boot/dts/qcom/sm8250.dtsi          |  17 +
 drivers/usb/typec/Kconfig                     |  13 -
 drivers/usb/typec/Makefile                    |   1 -
 drivers/usb/typec/qcom-pmic-typec.c           | 261 --------
 drivers/usb/typec/tcpm/Kconfig                |  11 +
 drivers/usb/typec/tcpm/Makefile               |   1 +
 drivers/usb/typec/tcpm/qcom/Makefile          |   6 +
 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c | 362 +++++++++++
 .../typec/tcpm/qcom/qcom_pmic_typec_pdphy.c   | 528 +++++++++++++++++
 .../typec/tcpm/qcom/qcom_pmic_typec_pdphy.h   | 115 ++++
 .../typec/tcpm/qcom/qcom_pmic_typec_port.c    | 560 ++++++++++++++++++
 .../typec/tcpm/qcom/qcom_pmic_typec_port.h    | 194 ++++++
 19 files changed, 2146 insertions(+), 277 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/qcom,pmic-typec.yaml
 delete mode 100644 drivers/usb/typec/qcom-pmic-typec.c
 create mode 100644 drivers/usb/typec/tcpm/qcom/Makefile
 create mode 100644 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec.c
 create mode 100644 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.c
 create mode 100644 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_pdphy.h
 create mode 100644 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.c
 create mode 100644 drivers/usb/typec/tcpm/qcom/qcom_pmic_typec_port.h

Comments

Konrad Dybcio May 2, 2023, 10:56 a.m. UTC | #1
On 1.05.2023 14:11, Bryan O'Donoghue wrote:
> Switch on VBUS for the Type-C port. We need to support a higher amperage
> than the bootloader set 2 Amps.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
>  arch/arm64/boot/dts/qcom/qrb5165-rb5.dts | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts b/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> index dd924331b0eea..b326bdeeb7742 100644
> --- a/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> +++ b/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> @@ -1338,3 +1338,9 @@ &qup_spi0_data_clk {
>  	drive-strength = <6>;
>  	bias-disable;
>  };
> +
> +&pm8150b_vbus {
> +	regulator-min-microamp = <500000>;
> +	regulator-max-microamp = <3000000>;
> +	status = "okay";
> +};
Krzysztof Kozlowski May 2, 2023, 10:56 a.m. UTC | #2
On 01/05/2023 14:11, Bryan O'Donoghue wrote:
> Add a description for the Type-C silicon interface inside Qualcomm's
> PM8150b hardware block.
> 
> Based on original work by Wesley.
> 
> Signed-off-by: Wesley Cheng <wcheng@codeaurora.org>
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---

Thank you for your patch. There is something to discuss/improve.

Two nits below

> +                    port@1 {
> +                        reg = <1>;
> +                        pmic_typec_role_switch_out: endpoint {
> +                            remote-endpoint = <&usb_controller_role_switch_in>;
> +                        };
> +                    };
> +                };
> +            };
> +        };
> +    };
> +
> +    usb_controller {

No underscores in node names, just "usb"

> +        dr_mode = "otg";
> +        usb-role-switch;
> +        port {
> +            usb_controller_role_switch_in: endpoint {
> +                remote-endpoint = <&pmic_typec_role_switch_out>;
> +            };
> +        };
> +    };
> +
> +    usb_phy {

usb-phy


With fixes above:

Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>

Best regards,
Krzysztof
Konrad Dybcio May 2, 2023, 10:57 a.m. UTC | #3
On 1.05.2023 14:11, Bryan O'Donoghue wrote:
> Switch on TCPM for the RB5. Here we declare as a source only not a sink
> since qrb5165 doesn't support powering exclusively from the type-c port.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>  arch/arm64/boot/dts/qcom/qrb5165-rb5.dts | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts b/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> index b326bdeeb7742..1e0b6fd59abc9 100644
> --- a/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> +++ b/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> @@ -9,6 +9,7 @@
>  #include <dt-bindings/regulator/qcom,rpmh-regulator.h>
>  #include <dt-bindings/sound/qcom,q6afe.h>
>  #include <dt-bindings/sound/qcom,q6asm.h>
> +#include <dt-bindings/usb/pd.h>
>  #include "sm8250.dtsi"
>  #include "pm8150.dtsi"
>  #include "pm8150b.dtsi"
> @@ -1344,3 +1345,19 @@ &pm8150b_vbus {
>  	regulator-max-microamp = <3000000>;
>  	status = "okay";
>  };
> +
> +&pm8150b_typec {
> +	status = "okay";
Missing newline

Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
> +	connector {
> +		compatible = "usb-c-connector";
> +
> +		power-role = "source";
> +		data-role = "dual";
> +		self-powered;
> +
> +		source-pdos = <PDO_FIXED(5000, 3000,
> +					 PDO_FIXED_DUAL_ROLE |
> +					 PDO_FIXED_USB_COMM |
> +					 PDO_FIXED_DATA_SWAP)>;
> +	};
> +};
Konrad Dybcio May 2, 2023, 11:01 a.m. UTC | #4
On 1.05.2023 14:11, Bryan O'Donoghue wrote:
> Switch on USB orientation-switching for usb_1_qmp via TCPM. Detecting the
> orientation switch is required to get the PHY to reset and bring-up the PHY
> with the CC lines set to the appropriate lane.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>  arch/arm64/boot/dts/qcom/qrb5165-rb5.dts | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts b/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> index b5cc45358a474..8935a8e327904 100644
> --- a/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> +++ b/arch/arm64/boot/dts/qcom/qrb5165-rb5.dts
> @@ -1295,6 +1295,14 @@ &usb_1_qmpphy {
>  
>  	vdda-phy-supply = <&vreg_l9a_1p2>;
>  	vdda-pll-supply = <&vreg_l18a_0p92>;
> +	orientation-switch;
> +	ports {
> +		port@1 {
> +			qmpphy_typec_mux_in: endpoint {
You defined these ports in patch 6, you can simply reference the
labels and assign endpoints.

Konrad
> +				remote-endpoint = <&pm8150b_typec_mux_out>;
> +			};
> +		};
> +	};
>  };
>  
>  &usb_2 {
> @@ -1375,6 +1383,12 @@ pm8150b_role_switch_out: endpoint {
>  					remote-endpoint = <&dwc3_role_switch_in>;
>  				};
>  			};
> +			port@1 {
> +				reg = <1>;
> +				pm8150b_typec_mux_out: endpoint {
> +					remote-endpoint = <&qmpphy_typec_mux_in>;
> +				};
> +			};
>  		};
>  	};
>  };
Konrad Dybcio May 2, 2023, 11:01 a.m. UTC | #5
On 1.05.2023 14:11, Bryan O'Donoghue wrote:
> ports for orientation switching input and output. The individual board dts
> files will instantiate port@0 and port@1 depending on the supported
> feature-set.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org>

Konrad
>  arch/arm64/boot/dts/qcom/sm8250.dtsi | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/arch/arm64/boot/dts/qcom/sm8250.dtsi b/arch/arm64/boot/dts/qcom/sm8250.dtsi
> index a91d1175255e8..af16d3ba76b8e 100644
> --- a/arch/arm64/boot/dts/qcom/sm8250.dtsi
> +++ b/arch/arm64/boot/dts/qcom/sm8250.dtsi
> @@ -3581,6 +3581,19 @@ dp_phy: dp-phy@88ea200 {
>  				#phy-cells = <0>;
>  				#clock-cells = <1>;
>  			};
> +
> +			ports {
> +				#address-cells = <1>;
> +				#size-cells = <0>;
> +
> +				port@0 {
> +					reg = <0>;
> +				};
> +
> +				port@1 {
> +					reg = <1>;
> +				};
> +			};
>  		};
>  
>  		usb_2_qmpphy: phy@88eb000 {