diff mbox series

msm8998: Hacking the USB3 controller (force controller to host/source mode)

Message ID 00358fd5-1702-ec4c-8400-3807d50614c6@free.fr (mailing list archive)
State RFC
Headers show
Series msm8998: Hacking the USB3 controller (force controller to host/source mode) | expand

Commit Message

Marc Gonzalez Feb. 1, 2019, 2:40 p.m. UTC
Still no cookie. Perhaps VBUS needs to be kicked in the nads...
Boot log at https://pastebin.ubuntu.com/p/3fqgQkRmyF/
---
 drivers/base/regmap/regmap.c |  1 +
 drivers/mfd/qcom-spmi-pmic.c |  8 +++++++-
 drivers/spmi/spmi-pmic-arb.c | 10 +++++++++
 drivers/spmi/spmi.c          |  4 ++--
 lib/Makefile                 |  2 ++
 lib/usb.c                    | 39 ++++++++++++++++++++++++++++++++++++
 6 files changed, 61 insertions(+), 3 deletions(-)
 create mode 100644 lib/usb.c

Comments

Marc Gonzalez Feb. 5, 2019, 11:58 a.m. UTC | #1
On 01/02/2019 15:40, Marc Gonzalez wrote:

> Still no cookie. Perhaps VBUS needs to be kicked in the nads...
> Boot log at https://pastebin.ubuntu.com/p/3fqgQkRmyF/

Wait a second... It actually works!

usb 1-1: new high-speed USB device number 2 using xhci-hcd
usb 1-1: New USB device found, idVendor=05dc, idProduct=a838, bcdDevice=11.00
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: USB Flash Drive
usb 1-1: Manufacturer: Lexar
usb 1-1: SerialNumber: AAYW2W7I13BAR0JC
usb-storage 1-1:1.0: USB Mass Storage device detected
scsi host0: usb-storage 1-1:1.0
scsi 0:0:0:0: Direct-Access     Lexar    USB Flash Drive  1100 PQ: 0 ANSI: 6
sd 0:0:0:0: [sda] 62517248 512-byte logical blocks: (32.0 GB/29.8 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
 sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk
...
usb 2-1: USB disconnect, device number 2
sd 0:0:0:0: [sda] Synchronizing SCSI cache
sd 0:0:0:0: [sda] Synchronize Cache(10) failed: Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK


# lsusb -v

Bus 002 Device 001: ID 1d6b:0003  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.00
  bDeviceClass            9 
  bDeviceSubClass         0 
  bDeviceProtocol         3 
  bMaxPacketSize0         9
  idVendor           0x1d6b 
  idProduct          0x0003 
  bcdDevice            5.00
  iManufacturer           3 Linux 5.0.0-rc3 xhci-hcd
  iProduct                2 xHCI Host Controller
  iSerial                 1 xhci-hcd.0.auto
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x001f
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              12
        bMaxBurst               0
Hub Descriptor:
  bLength              12
  bDescriptorType      42
  nNbrPorts             1
  wHubCharacteristic 0x000a
    No power switching (usb 1.0)
    Per-port overcurrent protection
  bPwrOn2PwrGood       10 * 2 milli seconds
  bHubContrCurrent      0 milli Ampere
  bHubDecLat          0.0 micro seconds
  wHubDelay             0 nano seconds
  DeviceRemovable    0x00
 Hub Port Status:
   Port 1: 0000.02a0 5Gbps power Rx.Detect
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength       0x000f
  bNumDeviceCaps          1
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x02
      Latency Tolerance Messages (LTM) Supported
    wSpeedsSupported   0x0008
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   3
      Lowest fully-functional device speed is SuperSpeed (5Gbps)
    bU1DevExitLat           0 micro seconds
    bU2DevExitLat           0 micro seconds
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered

Bus 001 Device 002: ID 05dc:a838  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass            0 
  bDeviceSubClass         0 
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x05dc 
  idProduct          0xa838 
  bcdDevice           11.00
  iManufacturer           1 Lexar
  iProduct                2 USB Flash Drive
  iSerial                 3 AAYW2W7I13BAR0JC
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass         8 
      bInterfaceSubClass      6 
      bInterfaceProtocol     80 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength       0x0016
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000006
      BESL Link Power Management (LPM) Supported
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x00
    wSpeedsSupported   0x000c
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   2
      Lowest fully-functional device speed is High Speed (480Mbps)
    bU1DevExitLat           4 micro seconds
    bU2DevExitLat           4 micro seconds
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)

Bus 001 Device 001: ID 1d6b:0002  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.00
  bDeviceClass            9 
  bDeviceSubClass         0 
  bDeviceProtocol         1 
  bMaxPacketSize0        64
  idVendor           0x1d6b 
  idProduct          0x0002 
  bcdDevice            5.00
  iManufacturer           3 Linux 5.0.0-rc3 xhci-hcd
  iProduct                2 xHCI Host Controller
  iSerial                 1 xhci-hcd.0.auto
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0019
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xe0
      Self Powered
      Remote Wakeup
    MaxPower                0mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           1
      bInterfaceClass         9 
      bInterfaceSubClass      0 
      bInterfaceProtocol      0 
      iInterface              0 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0004  1x 4 bytes
        bInterval              12
Hub Descriptor:
  bLength               9
  bDescriptorType      41
  nNbrPorts             1
  wHubCharacteristic 0x000a
    No power switching (usb 1.0)
    Per-port overcurrent protection
    TT think time 8 FS bits
  bPwrOn2PwrGood       10 * 2 milli seconds
  bHubContrCurrent      0 milli Ampere
  DeviceRemovable    0x00
  PortPwrCtrlMask    0xff
 Hub Port Status:
   Port 1: 0000.0523 highspeed power L1 enable connect
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0001
  Self Powered


I do note a few warnings: (probably not too important)

can't get debug descriptor: Resource temporarily unavailable
can't get device qualifier: Resource temporarily unavailable
can't get debug descriptor: Resource temporarily unavailable


Another mass storage device:

usb 1-1: new high-speed USB device number 3 using xhci-hcd
usb 1-1: New USB device found, idVendor=0b95, idProduct=1790, bcdDevice= 1.00
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: AX88179
usb 1-1: Manufacturer: ASIX Elec. Corp.
usb 1-1: SerialNumber: 00000000000012
usb 1-1: USB disconnect, device number 3
usb 1-1: new high-speed USB device number 4 using xhci-hcd
usb 1-1: New USB device found, idVendor=13fe, idProduct=1f00, bcdDevice= 1.10
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 1-1: Product: DataTraveler 2.0
usb 1-1: Manufacturer: Kingston
usb 1-1: SerialNumber: 5B820E0006AB
usb-storage 1-1:1.0: USB Mass Storage device detected
scsi host0: usb-storage 1-1:1.0
scsi 0:0:0:0: Direct-Access     Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 0 CCS
sd 0:0:0:0: [sda] 7823360 512-byte logical blocks: (4.01 GB/3.73 GiB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] No Caching mode page found
sd 0:0:0:0: [sda] Assuming drive cache: write through
 sda:
sd 0:0:0:0: [sda] Attached SCSI removable disk
usb 1-1: USB disconnect, device number 4


I'll also give the USB Ethernet gizmo a try.

Regards.
Marc Gonzalez Feb. 5, 2019, 4:51 p.m. UTC | #2
If I plug in a USB-to-Ethernet gadget, the kernel sees something:

usb 2-1: new SuperSpeed Gen 1 USB device number 2 using xhci-hcd
usb 2-1: New USB device found, idVendor=0b95, idProduct=1790, bcdDevice= 1.00
usb 2-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
usb 2-1: Product: AX88179
usb 2-1: Manufacturer: ASIX Elec. Corp.
usb 2-1: SerialNumber: 00000000000012
ax88179_178a 2-1:1.0 eth0: register 'ax88179_178a' at usb-xhci-hcd.0.auto-1, ASIX AX88179 USB 3.0 Gigabit Ethernet, 00:0e:c6:fb:e2:41
usbcore: registered new interface driver ax88179_178a

# lsmod
Module                  Size  Used by    Not tainted
ax88179_178a           24576  0 
usbnet                 32768  1 ax88179_178a
mii                    20480  2 ax88179_178a,usbnet


But the eth LEDs don't turn on (or blink) when I plug in a cable.
Could it be a power/voltage issue?

# lsusb -v

Bus 002 Device 003: ID 0b95:1790  
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               3.00
  bDeviceClass          255 
  bDeviceSubClass       255 
  bDeviceProtocol         0 
  bMaxPacketSize0         9
  idVendor           0x0b95 
  idProduct          0x1790 
  bcdDevice            1.00
  iManufacturer           1 ASIX Elec. Corp.
  iProduct                2 AX88179
  iSerial                 3 00000000000012
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0039
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0xa0
      (Bus Powered)
      Remote Wakeup
    MaxPower              496mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           3
      bInterfaceClass       255 
      bInterfaceSubClass    255 
      bInterfaceProtocol      0 
      iInterface              4 Network_Interface
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            3
          Transfer Type            Interrupt
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0008  1x 8 bytes
        bInterval              11
        bMaxBurst               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x82  EP 2 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst               3
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x03  EP 3 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0400  1x 1024 bytes
        bInterval               0
        bMaxBurst              15
Binary Object Store Descriptor:
  bLength                 5
  bDescriptorType        15
  wTotalLength       0x0016
  bNumDeviceCaps          2
  USB 2.0 Extension Device Capability:
    bLength                 7
    bDescriptorType        16
    bDevCapabilityType      2
    bmAttributes   0x00000002
      HIRD Link Power Management (LPM) Supported
  SuperSpeed USB Device Capability:
    bLength                10
    bDescriptorType        16
    bDevCapabilityType      3
    bmAttributes         0x00
    wSpeedsSupported   0x000e
      Device can operate at Full Speed (12Mbps)
      Device can operate at High Speed (480Mbps)
      Device can operate at SuperSpeed (5Gbps)
    bFunctionalitySupport   1
      Lowest fully-functional device speed is Full Speed (12Mbps)
    bU1DevExitLat           1 micro seconds
    bU2DevExitLat         101 micro seconds
can't get debug descriptor: Resource temporarily unavailable
Device Status:     0x0000
  (Bus Powered)
diff mbox series

Patch

diff --git a/drivers/base/regmap/regmap.c b/drivers/base/regmap/regmap.c
index 4f822e087def..7957a803683b 100644
--- a/drivers/base/regmap/regmap.c
+++ b/drivers/base/regmap/regmap.c
@@ -2879,6 +2879,7 @@  static int _regmap_update_bits(struct regmap *map, unsigned int reg,
 
 		tmp = orig & ~mask;
 		tmp |= val & mask;
+		printk("%s: reg=%x old=%x new=%x\n", __func__, reg, orig, tmp);
 
 		if (force_write || (tmp != orig)) {
 			ret = _regmap_write(map, reg, tmp);
diff --git a/drivers/mfd/qcom-spmi-pmic.c b/drivers/mfd/qcom-spmi-pmic.c
index e2e95de649a4..2b2283d1f2cf 100644
--- a/drivers/mfd/qcom-spmi-pmic.c
+++ b/drivers/mfd/qcom-spmi-pmic.c
@@ -124,8 +124,11 @@  static const struct regmap_config spmi_regmap_config = {
 	.fast_io	= true,
 };
 
+extern int my_smblib_set_prop_typec_power_role(struct regmap *map);
+
 static int pmic_spmi_probe(struct spmi_device *sdev)
 {
+	int err;
 	struct regmap *regmap;
 
 	regmap = devm_regmap_init_spmi_ext(sdev, &spmi_regmap_config);
@@ -136,7 +139,10 @@  static int pmic_spmi_probe(struct spmi_device *sdev)
 	if (sdev->usid % 2 == 0)
 		pmic_spmi_show_revid(regmap, &sdev->dev);
 
-	return devm_of_platform_populate(&sdev->dev);
+	err = devm_of_platform_populate(&sdev->dev);
+	if (sdev->usid == 2) // Trying to reach pmi8998_pdphy
+		my_smblib_set_prop_typec_power_role(regmap);
+	return err;
 }
 
 MODULE_DEVICE_TABLE(of, pmic_spmi_id_table);
diff --git a/drivers/spmi/spmi-pmic-arb.c b/drivers/spmi/spmi-pmic-arb.c
index 360b8218f322..4ffed22c77ed 100644
--- a/drivers/spmi/spmi-pmic-arb.c
+++ b/drivers/spmi/spmi-pmic-arb.c
@@ -341,6 +341,12 @@  static int pmic_arb_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid)
 	return pmic_arb->ver_ops->non_data_cmd(ctrl, opc, sid);
 }
 
+#ifdef FOO
+extern void my_dump_stack(int depth);
+#else
+static void my_dump_stack(int depth) { }
+#endif
+
 static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
 			     u16 addr, u8 *buf, size_t len)
 {
@@ -351,6 +357,8 @@  static int pmic_arb_read_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
 	int rc;
 	u32 offset;
 
+	printk("%s: opcode=%x sid=%x addr=%x len=%zu\n", __func__, opc, sid, addr, len);
+	my_dump_stack(14);
 	rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr,
 				       PMIC_ARB_CHANNEL_OBS);
 	if (rc < 0)
@@ -404,6 +412,8 @@  static int pmic_arb_write_cmd(struct spmi_controller *ctrl, u8 opc, u8 sid,
 	int rc;
 	u32 offset;
 
+	printk("%s: opcode=%x sid=%x addr=%x len=%zu\n", __func__, opc, sid, addr, len);
+	my_dump_stack(14);
 	rc = pmic_arb->ver_ops->offset(pmic_arb, sid, addr,
 					PMIC_ARB_CHANNEL_RW);
 	if (rc < 0)
diff --git a/drivers/spmi/spmi.c b/drivers/spmi/spmi.c
index aa3edabc2b0f..f8d42895c905 100644
--- a/drivers/spmi/spmi.c
+++ b/drivers/spmi/spmi.c
@@ -109,7 +109,7 @@  spmi_cmd(struct spmi_controller *ctrl, u8 opcode, u8 sid)
 	return ret;
 }
 
-static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode,
+static int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode,
 				u8 sid, u16 addr, u8 *buf, size_t len)
 {
 	int ret;
@@ -123,7 +123,7 @@  static inline int spmi_read_cmd(struct spmi_controller *ctrl, u8 opcode,
 	return ret;
 }
 
-static inline int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode,
+static int spmi_write_cmd(struct spmi_controller *ctrl, u8 opcode,
 				 u8 sid, u16 addr, const u8 *buf, size_t len)
 {
 	int ret;
diff --git a/lib/Makefile b/lib/Makefile
index bff7337b46f8..8b2665edb68c 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -3,6 +3,8 @@ 
 # Makefile for some libs needed in the kernel.
 #
 
+obj-y += usb.o
+
 ifdef CONFIG_FUNCTION_TRACER
 ORIG_CFLAGS := $(KBUILD_CFLAGS)
 KBUILD_CFLAGS = $(subst $(CC_FLAGS_FTRACE),,$(ORIG_CFLAGS))
diff --git a/lib/usb.c b/lib/usb.c
new file mode 100644
index 000000000000..cb5d4f850620
--- /dev/null
+++ b/lib/usb.c
@@ -0,0 +1,39 @@ 
+#include <linux/regmap.h>
+
+#define DFP_EN_CMD_BIT BIT(1)
+
+#define USBIN_BASE	0x1300
+#define MISC_BASE	0x1600
+
+#define TM_IO_DTEST4_SEL (MISC_BASE + 0xe9)
+#define TYPE_C_INTRPT_ENB_SOFTWARE_CTRL_REG (USBIN_BASE + 0x68)
+#define TYPEC_POWER_ROLE_CMD_MASK GENMASK(2, 0)
+
+static int smblib_write(struct regmap *map, u16 addr, u8 val)
+{
+	printk("%s: addr=%x val=%x", __func__, addr, val);
+	return regmap_write(map, addr, val);
+}
+
+static int smblib_masked_write(struct regmap *map, u16 addr, u8 mask, u8 val)
+{
+	printk("%s: addr=%x val=%x", __func__, addr, val);
+	return regmap_update_bits(map, addr, mask, val);
+}
+
+int my_smblib_set_prop_typec_power_role(struct regmap *map)
+{
+	int rc = 0;
+	int power_role = DFP_EN_CMD_BIT;
+
+	/* restore PBS workaround back to 0xA5 */
+	rc = smblib_write(map, TM_IO_DTEST4_SEL, 0xA5);
+	if (rc < 0)
+		pr_err("Couldn't write to TM_IO_DTEST4_SEL rc=%d\n", rc);
+
+	rc = smblib_masked_write(map, TYPE_C_INTRPT_ENB_SOFTWARE_CTRL_REG, TYPEC_POWER_ROLE_CMD_MASK, power_role);
+	if (rc < 0)
+		pr_err("Couldn't write 0x%02x to TYPE_C_INTRPT_ENB_SOFTWARE_CTRL rc=%d\n", power_role, rc);
+
+	return rc;
+}