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

Bryan O'Donoghue May 7, 2023, 9:09 p.m. UTC | #1
On 02/05/2023 12:47, Konrad Dybcio wrote:
>>          connector {
>>                  compatible = "usb-c-connector";
>>                  ports {
>>                          #address-cells = <1>;
>>                          #size-cells = <0>;
>>
>>                          port@0 {
>>                                  reg = <0>;
>>                                  pm8150b_role_switch_out: endpoint {
>>                                          remote-endpoint = <&dwc3_role_switch_in>;
>>                                  };
>>                          };
> ====

Hmm, I'm actually recoiling from doing this now that I look at it.

- Every other implementation defines the connector in the platfrom
   dts not the core dtsi

- The connector would have to be named something like
   pm8150b_type_connector which is not consistent with the
   rest of the Type-C connector namespace


Yes it can be done that the connector with the ports can be defined in 
the pm8150b dtsi but TBH I think it is more confusing that way and not 
consistent with other implementations.

I'm citing prior art here I just think this is nicer/easier to follow

- arch/arm64/boot/dts/qcom/sc8280xp.dtsi
- arch/arm64/boot/dts/qcom/sc8280xp-lenovo-thinkpad-x13s.dts

So for now

https://imgflip.com/i/7kw6ck

---
bod