Skip to content

Support for SAM USB-C Events #35

Open
linux-surface/kernel
#184

Description

@qzed

Quoting myself from #33:

There is indeed some SAM stuff going on in the SurfaceUsbCMuxAcpiFilterDriver.sys using the USC subsystem. There seem to be two methods, specifically. A FilterGetPortNumbers and a FilterSendUSBCAck. In addition to that, there's a PdEventInfoUpdateFromSamToSoc function, which might be some part of a PD event handler by its name.

In fact all three functions are called in the same ProcessUsbCResponse function, first getting the port number(s?), then updating the PD event info, then sending the ACK back. I think what's happening is that SAM might send a PD event when a USB-C source is plugged in. This is then handled by that process-response function.

I think we might need to have to log SAM events on Windows to get a better idea on what's going on with that.

Turns out we can enable and receive events on Linux (using the standard SAM event registry) when I plug in my phone for charging, but I should probably get some USB-C power meter and a powerful enough USB-C charger to see if there are any changes. Also I don't know yet what to send back to SAM via the ACK command.

Interestingly, when I enable SAM events, the port seems to do something (at very least cut power for a brief moment) as my phone screen turns on. Phone says "fast charging" regardless of events being enabled/disabled though...

Activity

  1. added
    A: SAM
    on Jun 22, 2022
  2. gus33000 commented on Jun 23, 2022

    @gus33000

    The SurfaceUsbCMuxAcpiFilterDriver.sys filter driver is designed to sit in the middle of ACPI.sys IOCTL events.

    In order to enable Display Port for Windows GPU driver normally the UCSI Driver from qualcomm notifies either via an interface or via an ACPI notify function the GPU device that a cable got inserted at this port number in this orientation. And it does so by getting notified from PmicGlink (missing on the Surface Pro X)

    Given the Pro X doesn't make use of PmicGlink/BattMngr/PTCC in ADSP.mbn and instead uses SAM this is broken.

    So the filter driver serves as getting notifications from SAM and then making qualcomm's driver react by notifying it of an pmicglink event (even though there's no pmicglink), so the GPU driver can setup display port output.

    This is one of the functionality of that driver that I gathered, but I'm not sure if it does anything else.

  3. qzed commented on Jun 23, 2022

    @qzed
    MemberAuthor

    Thanks for your insights!

    I've experimented a bit more with various USB devices, but I don't have a powerful enough USB-C charger here, so I probably can't look at power-delivery stuff properly.

    Events have 11 bytes and start off with a sequence number. Also, if events are not ACKed, the last event repeats for up to a total of 5 events being sent for one action (all with the same sequence number, which is simply incremented for new events).

    So far, I've gathered the following structure. I've tested the display-port part of this with the Surface USB-C hub and its HDMI output, so this might be a bit different for more/other display connections.

    struct usbc_event {
        u32 sequence_number;   // sequence number, increases with each new event (might also be smaller than 32 bit)
        u8 port_id;            // ID/index of the USB-C port, top=1, bottom=0
        u8 cable_orientation;  // 0=normal, 1=flipped, 2=disconnect
        u8 event_type;         // 0=disconnect, 1=connect, 3=dp_link_change?
        u8 unknown1;           // 2 on USB-C disconnect, 0 for everything else observed so far
        u8 dp_link_prop;       // some DP link ID?, only set on DP change, 4 or 10 for HDMI port (depending on orientation)
        u8 dp_link_conn;       // 1=connect_display, 0=disconnect_display
        u8 unknown2;           // seems to be zero
    };

    I guess the event payload might be different for different (sub-)types of events.

    @gus33000 You wouldn't happen to know what data specifically needs to be sent via glink (and/or could fill in the gaps of the struct above) and to which specific endpoints? I assume the display-port controller (mdss-mdp) is one?

  4. qzed commented on Jun 23, 2022

    @qzed
    MemberAuthor

    The ACK command sent back to SAM seems to have the following properties: Target category 0x1b, target ID 0x01, instance ID 0x01, command ID 0x03. Multiple (re-)tries are attempted when the command fails.

    The command payload is 12 bytes with the following structure

    struct usbc_ack_to_sam {
        u32 sequence_number;  // the sequence number of the event to ACK
        u32 unknown1;         // seems to be port ID cast to u32?
        u32 unknown2;         // some bool (or byte?) returned from PdEventInfoUpdateFromSamToSoc or zero
    };

    Interestingly, only the LSB of unknown2 seems to be set. So could be that the rest is just padding, but that's fairly unusual for SAM communication.

  5. changed the title [-]Support for SAM USB-C Power Delivery Events[/-] [+]Support for SAM USB-C Events[/+] on Jun 23, 2022
  6. gus33000 commented on Jun 27, 2022

    @gus33000

    @gus33000 You wouldn't happen to know what data specifically needs to be sent via glink (and/or could fill in the gaps of the struct above) and to which specific endpoints? I assume the display-port controller (mdss-mdp) is one?

    Actually the filter doesn't send anything via Glink, the Surface Pro X does not provide the Pmic Glink interface at all (so no USB-C handled by ADSP, no battery management handled by ADSP). But due to how the Qualcomm GPU DirectX driver is built they needed to reuse that UCSI driver to make DisplayPort connections work.

    I'm currently working on the same sort of thing for the Surface Duo.
    The UCSI driver is able to make calls directly to the GPU driver to tell it, I detected a cable in DP AltMode with this pin assignment and this orientation, then the GPU driver enables the DisplayPort connection and sets up MDSS / DP PHY etc. It also tells the GPU driver which port was detected (this ultimately depends on the amount of EXTERNAL connections defined in ACPI for the GPU device)
    The UCSI driver is basically a shim, listening to the QcPmicGlink8180.sys driver (not present on the Pro X), and that PmicGlink driver sends IOCTLs to the UCSI driver to notify it of changes.
    The role of that filter driver is to send IOCTLs to the UCSI driver when needed so it can tell the GPU driver a DP connection needs to be setup. (essentially re-implementing missing functionality due to the Qualcomm Pmic Glink stack not being present on this device)

    Unfortunately I can't help much with SAM events as my device doesn't use them so I can't really complete the structure for you, but I do actually need to not use PmicGlink (just like on the Surface Pro X) because Android platforms of the time also did not have the USB-C/charging code in ADSP instead implementing it directly in the kernel/HLOS. Previous Qualcomm Windows Platforms (SDM845/Snapdragon 850) did not use PmicGlink either.

    In a way it makes sense they would not use ADSP/PmicGlink here, they already have SAM for this.

    From what I can see though you also have a Surface UCSI over HID driver (SurfaceUcmUcsiHidClient.sys) that likely uses the same events the filter uses to notify the GPU driver, but for providing standard USB-C UCSI functionality (for the other ports), so I'm not saying it's only used for that purpose, just that PmicGlink is out of reach on the Surface Pro X.

  7. qzed commented on Jun 27, 2022

    @qzed
    MemberAuthor

    Ah sorry, I misunderstood earlier then (I thought only the Glink endpoint for USB-C was not present). Thanks for clearing that up. @andersson is working on Display Ports for the Lenovo Flex 5G, which uses the same SC8180X SoC. That apparently uses Glink, so I can then hopefully see what needs to be replaced and gauge the remaining fields.

    From what I can see though you also have a Surface UCSI over HID driver (SurfaceUcmUcsiHidClient.sys) that likely uses the same events the filter uses to notify the GPU driver, but for providing standard USB-C UCSI functionality (for the other ports), so I'm not saying it's only used for that purpose, just that PmicGlink is out of reach on the Surface Pro X.

    As far as I know, that driver is also present on a bunch of other x86 Surface devices as well. The respective device is some SAM-provided HID device, at least according to the Windows Device Manager. Unfortunately, I haven't been able to receive any input events from that, so I'm not sure whether it provides some (e.g. when devices are connected/disconnected), whether the command to enable events is wrong, or whether it just doesn't provide any. Also, the SPX doesn't have any other USB-C ports, so if it plays a similar role as the SAM notifications, it might not be used at all...

    Here's the descriptor for that device: t1i0.c.txt. However, I'm not even sure if that's the right device since that reports an id of 045e:0922 (whereas the .inf for the driver has 045e:ff00 and 045e:f900?). But that's the only other HID device I've found via SAM. So could be that it's some virtual device.

  8. JValdivia23 commented on Nov 2, 2026

    @JValdivia23

    Mystery solved — and I just opened an upstream driver PR for this in linux-surface/kernel#184 (companion config PR: linux-surface/linux-surface#2354 or see linked PR).

    How SurfaceUcmUcsiHidClient.sys / Surface UCSI-over-HID Works

    1. HID Matching (HID\VID_045E&UP:FF00_U:F900):

      • UP:FF00_U:F900 in SurfaceUcmUcsiHidClient.inf is the HID Application Collection Usage Page (0xFF00) and Usage (0xF900), not the USB/SSAM Product ID. That is why it appears under 045E:0922 on Surface Pro X and 045E:09A6 on Surface Book 3.
      • Note that sibling SSAM HID collections can share the same VID:PID (for example, on Surface Book 3 045E:09A6 has two separate HID interfaces: 0xFF00:0xF900 for the UCSI PPM and 0xFF0B:0x0101 for Base CFU firmware updates). Assigning a dedicated HID_GROUP_SURFACE_UCSI in hid_scan_collection() lets ucsi_surface_hid bind exclusively to 0xFF00:0xF900 across all Surface models.
    2. HID Report Layout (109-byte descriptor):

      • Feature Report 0x32 (49 bytes = 1-byte Report ID + 48-byte UCSI v1.x data structure):
        • +0x00 (u8): Report ID (0x32)
        • +0x01 (__le16): VERSION (note: uninitialized in SAM RAM prior to the first UCSI_PPM_RESET after cold boot — e.g. 0x7628 on SB3 — so read_version() must sanitize pre-reset values outside {0x0100, 0x0110, 0x0120} to 0x0110)
        • +0x03 (__le16): RESERVED / sequence (0)
        • +0x05 (__le32): CCI
        • +0x09 (__le64): CONTROL
        • +0x11 (u8[16]): MESSAGE_IN
        • +0x21 (u8[16]): MESSAGE_OUT
      • Input Report 0x32: Asynchronous notification emitted by SAM whenever CCI changes — but SAM stays completely silent until initialized via SET_REPORT(Feature 0x32) with UCSI_PPM_RESET (0x01) followed by UCSI_SET_NOTIFICATION_ENABLE (0x05), which explains why raw hidraw reads showed no traffic earlier.
      • Feature Report 0x33 (3 bytes): [0x33, num_connectors, udc_supported] (e.g. connectors=1, udc_supported=0 on Surface Book 3).

    Tested live on Surface Book 3 (7.3.0, /sys/class/typec/port0 Type-C 1.3 / USB PD 3.0 + ucsi-source-psy-*); testing on Surface Pro X (045E:0922) would be very welcome!

  9. qzed commented on Nov 2, 2026

    @qzed
    MemberAuthor

    Finally got around to looking at this again, together with the UCSI-over-HID driver from linux-surface/kernel#184. Summary of what we now know about USB-C on the Surface Pro X:

    Overview

    There are two separate SAM interfaces for the two USB-C ports, mirroring what Qualcomm does with pmic_glink_altmode + ucsi_glink on other SC8180X/SC8280XP devices:

    USC events (TC 0x1b) UCSI over HID (TC 0x15)
    Windows driver SurfaceUsbCMuxAcpiFilterDriver SurfaceUcmUcsiHidClient
    Provides port, connect/disconnect, orientation, DP mode, HPD standard UCSI 1.x PPM: roles, PD contract, PDOs, partners, alt modes
    Needed for configuring the SoC side (QMP PHY orientation, USB/DP mux, HPD to the DP controller) typec class / power-supply reporting

    The two are coupled: the PPM only reflects the actual port state once the host handles (enables and ACKs) the USC events. Without that, GET_CONNECTOR_STATUS reports both connectors as disconnected, regardless of what's plugged in. This is presumably why I never got anything useful out of the HID device back then.

    USC events

    • Enable: via the SAM event registry (TC 0x01, TID 0x01, CID 0x0b/0x0c), target category 0x1b, instance ID 0x01.
    • Event: TC 0x1b, TID 0x01, CID 0x02, IID 0x00, 11-byte payload:
      struct ssam_usc_event {
          __le32 seq;         // sequence number, incremented per event
          u8 port;            // 0 = bottom, 1 = top
          u8 orientation;     // 0 = normal, 1 = flipped, 2 = disconnected
          u8 type;            // 0 = disconnect, 1 = connect (USB), 3 = DP alt mode
          u8 unknown1;        // 0x02 on disconnect, 0x00 otherwise
          u8 dp_mode;         // DP only: 0x04 (normal orientation), 0x0a (flipped)
          u8 dp_hpd;          // DP only: HPD state
          u8 unknown2;        // always 0 so far
      } __packed;
    • ACK: TC 0x1b, TID 0x01, IID 0x01, CID 0x03, 12-byte payload { __le32 seq; __le32 port; __le32 flag; }. Without an ACK, SAM re-sends the last event per port every 2 s, five times in total, and only then updates the UCSI PPM (i.e. a ~10 s delay). The flag (Windows: LSB of the result of PdEventInfoUpdateFromSamToSoc) has no visible effect: both 0 and 1 stop the re-sends, and the PPM updates immediately either way.
    • On enable, SAM sends a burst containing the (queued) last events and current state of both ports. Events should be treated as full state (not deltas) and processed in order; the last event per port is the current state.
    • DP: a DP connection is reported as type=3 instead of type=1. HPD (dp_hpd) sometimes comes in the same event, sometimes as a second type=3 event ~220 ms later. The dp_mode value depends on the orientation (0x04/0x0a); its exact meaning is still unclear (0x04 would match pin assignment C, 0x0a doesn't fit that scheme). A DP+USB hub (pin assignment D) would help to figure this out.
    • Port mapping: bottom = port 0 = UCSI connector 1, top = port 1 = UCSI connector 2.

    Side note: Currently, SuperSpeed only works in one orientation on Linux (flipped = USB 2 only), because nothing tells the QMP PHY about the orientation. A driver for these events would fix that via typec_switch_set().

    UCSI over HID

    • Device: HID 045E:0922 at SSAM 01:15:01:00:00 (TID 1, IID 0). This is the only HID instance on TID 1 (probed IIDs 0x00–0x1f); the t1i0 dump above was correct. Windows lists it as Target_SAM&Category_HID … SID_DEVICE_01, Location 1. It's not part of the SPX registry group yet.
    • Events: need to be enabled via the SAM registry. The REG registry (SSAM_EVENT_REGISTRY_REG(1), what surface_hid currently uses) never responds, so hid_hw_start() times out. Without any enable, SAM sends the input reports with RQID 0 and they get dropped (rtl: dropping unexpected command message (rqid = 0x0000)). Note: enables persist across our disable (and seemingly some reboots), so test from a fresh boot.
    • With the USC events handled, everything works: correct connector status (power/data role, PD contract, partner type), partner PDOs (e.g. 5/9/12 V @ 3 A from a USB-C monitor), DP alt mode of the partner, and connector-change notifications, so partners appear and disappear automatically.
    • PPM quirks (details in the kernel PR):
      • unsupported commands (e.g. GET_CABLE_PROPERTY) are answered with only NOT_SUPPORTED set, without COMMAND_COMPLETE;
      • GET_ALTERNATE_MODES responses have an extra leading byte;
      • the VERSION field is garbage on every read;
      • RESET_COMPLETE is often still set after boot.

    What's needed

    1. Registry: SPX nodes for the UCSI HID device (01:15:01:00:00) and the USC events.
    2. surface_hid: support selecting the SAM event registry per device.
    3. ucsi_surface_hid (kernel#184) with the quirks above.
    4. A new driver for the USC events (along the lines of pmic_glink_altmode), plus the DT connector graph (QMP PHYs, dwc3, mdss_dp0/1).

    Also confirmed working on the SPX (kernel#184): input_power_limit from SAM Artg (60 W charger → 60000000 µW).

  10. valpackett commented on Nov 2, 2026

    @valpackett

    Hi, I've been experimenting with this, can't believe I haven't written anything in the thread earlier.

        u8 type;            // 0 = disconnect, 1 = connect (USB), 3 = DP alt mode
        u8 unknown1;        // 0x02 on disconnect, 0x00 otherwise
        u8 dp_mode;         // DP only: 0x04 (normal orientation), 0x0a (flipped)
    

    These are actually:

        u8 alt_mode;           // 0=nothing, 1=usb, 2=4xDP, 3=2xDP+2xSS
        u8 unknown1;           // 2 on USB-C disconnect, 1 on 4xDP
        u8 pin_assignment;       // Lanes used for DP?? 4xDP: 0011/1001, 2xDP: 0100/1010 // was: some DP link ID?, only set on DP change, 4 or 10 for HDMI port (depending on orientation)
    
    Very early WIP does not work yet driver
    // SPDX-icense-Identifier: GPL-2.0+
    /*
     * USB Type-C port driver for Microsoft Surface devices where the
     * Surface System Aggregator Module (SSAM) is fully managing the ports.
     *
     * Copyright (C) 2026 Val Packett <val@packett.cool>
     */
    
    #include <linux/fwnode.h>
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/slab.h>
    #include <linux/types.h>
    
    #include <linux/surface_aggregator/device.h>
    #include <linux/usb/typec.h>
    #include <linux/usb/typec_dp.h>
    
    // #include <drm/bridge/aux-bridge.h>
    
    #define STCM_ORIENTATION_NORMAL 0
    #define STCM_ORIENTATION_REVERSE 1
    #define STCM_ORIENTATION_DISCONNECTED 2
    
    #define STCM_MODE_NOTHING 1
    #define STCM_MODE_SS_ONLY 1
    #define STCM_MODE_DP_ONLY 2
    #define STCM_MODE_SS_DP 3
    
    struct stcm_event {
        __le32 sequence_number;   // sequence number, increases with each new event (might also be smaller than 32 bit)
        u8 port_id;            // ID/index of the USB-C port, top=1, bottom=0
        u8 cable_orientation;  // 0=normal, 1=flipped, 2=disconnect
        u8 alt_mode;           // 0=nothing, 1=usb, 2=4xDP, 3=2xDP+2xSS
        u8 unknown1;           // 2 on USB-C disconnect, 1 on 4xDP
        u8 pin_assignment;       // Lanes used for DP?? 4xDP: 0011/1001, 2xDP: 0100/1010 // some DP link ID?, only set on DP change, 4 or 10 for HDMI port (depending on orientation)
        u8 dp_hpd;       // 1=connect_display, 0=disconnect_display
        u8 unknown2;           // seems to be zero. irq?
    } __packed;
    
    // [bit:reverse?] [] [] [bit:4xDP?]
    
    
    static enum typec_orientation map_orientation(u8 orientation)
    {
    	switch (orientation) {
    	case STCM_ORIENTATION_NORMAL:
    		return TYPEC_ORIENTATION_NORMAL;
    	case STCM_ORIENTATION_REVERSE:
    		return TYPEC_ORIENTATION_REVERSE;
    	case STCM_ORIENTATION_DISCONNECTED:
    		return TYPEC_ORIENTATION_NONE;
    	default:
    		pr_warn("unrecognized cable orientation %d", orientation);
    		return TYPEC_ORIENTATION_NONE;
    	}
    }
    
    struct stcm_ack_cmd {
        __le32 sequence_number;  // the sequence number of the event to ACK
        __le32 unknown1;         // seems to be port ID cast to u32?
        __le32 unknown2;         // some bool (or byte?) returned from PdEventInfoUpdateFromSamToSoc or zero
    } __packed;
    
    SSAM_DEFINE_SYNC_REQUEST_W(__ssam_typec_ack, struct stcm_ack_cmd, {
    	.target_category = SSAM_SSH_TC_USC,
    	.target_id       = SSAM_SSH_TID_SAM,
    	.instance_id     = 0x01,
    	.command_id      = 0x03,
    });
    
    struct surface_typec_port {
    	struct typec_capability	cap;
    	// struct device		*dev;
    	struct typec_partner	*partner;
    	struct typec_port	*port;
    	struct typec_altmode *dp_mode;
    	u8 alt_mode;
    };
    
    struct surface_typec {
    	struct ssam_device *sdev;
    	struct ssam_event_notifier notif;
    
    	struct surface_typec_port ports[2];
    };
    
    static u32 surface_typec_notify(struct ssam_event_notifier *nf, const struct ssam_event *event)
    {
    	struct surface_typec *stcm;
    	struct surface_typec_port *port;
    	struct stcm_event *evt;
    	struct typec_partner_desc desc = {};
    	enum typec_data_role data_role;
    	// int status;
    
    	stcm = container_of(nf, struct surface_typec, notif);
    
    	dev_warn(&stcm->sdev->dev, "typec event (cid = %#04x, iid = %#04x, tid = %#04x) [%d]: %*ph\n",
    		event->command_id, event->instance_id, event->target_id, event->length, event->length, event->data);
    	if (event->length != sizeof(struct stcm_event)) {
    		dev_warn(&stcm->sdev->dev, "unexpected event length %d", event->length);
    		// return SSAM_NOTIF_HANDLED;
    	}
    
    	evt = (struct stcm_event *)event->data;
    	if (evt->port_id >= ARRAY_SIZE(stcm->ports)) {
    		dev_err(&stcm->sdev->dev, "port %d out of range", evt->port_id);
    		return SSAM_NOTIF_HANDLED;
    	}
    
    	port = &stcm->ports[evt->port_id];
    	if (!port->port) {
    		dev_warn(&stcm->sdev->dev, "received event for uninitialized port %d", evt->port_id);
    		return SSAM_NOTIF_HANDLED;
    	}
    
    	if (port->alt_mode != evt->alt_mode) {
    		if (port->partner) {
    			typec_unregister_partner(port->partner);
    			port->partner = NULL;
    		}
    		struct typec_displayport_data dp_data;
    
    		typec_set_data_role(port->port, TYPEC_HOST);
    		switch (evt->alt_mode) {
    		case STCM_MODE_NOTHING:
    			break;
    		case STCM_MODE_SS_DP:
    		case STCM_MODE_DP_ONLY:
    			dp_data.status = DP_STATUS_ENABLED;
    			if (evt->unknown2)
    				dp_data.status |= DP_STATUS_IRQ_HPD;
    			if (evt->dp_hpd)
    				dp_data.status |= DP_STATUS_HPD_STATE;
    			dp_data.conf = DP_CONF_SET_PIN_ASSIGN(BIT(evt->alt_mode == STCM_MODE_DP_ONLY ? DP_PIN_ASSIGN_C : DP_PIN_ASSIGN_D));
    			fallthrough;
    		default:
    			port->partner = typec_register_partner(port->port, &desc);
    			if (IS_ERR(port->partner)) {
    				dev_err(&stcm->sdev->dev, "failed to register partner: %ld\n",
    					PTR_ERR(port->partner));
    				port->partner = NULL;
    			}
    			// int ret = typec_mux_set(port->port->mux, &port->state);
    		}
    	}
    
    	typec_set_orientation(port->port, map_orientation(evt->cable_orientation));
    
    	return SSAM_NOTIF_HANDLED;
    }
    
    static int surface_typec_probe(struct ssam_device *sdev)
    {
    	struct surface_typec *stcm;
    	struct device *ctrl_dev = ssam_controller_device(sdev->ctrl);
    	int ret;
    
    	stcm = devm_kzalloc(&sdev->dev, sizeof(*stcm), GFP_KERNEL);
    	if (!stcm)
    		return -ENOMEM;
    
    	stcm->sdev = sdev;
    
    	stcm->notif.base.priority = 1;
    	stcm->notif.base.fn = surface_typec_notify;
    	stcm->notif.event.reg = SSAM_EVENT_REGISTRY_SAM;
    	stcm->notif.event.id.target_category = SSAM_SSH_TC_USC;
    	stcm->notif.event.id.instance = 0;
    	stcm->notif.event.mask = SSAM_EVENT_MASK_NONE;
    	stcm->notif.event.flags = SSAM_EVENT_SEQUENCED;
    
    	ssam_device_set_drvdata(sdev, stcm);
    
    	device_for_each_named_child_node_scoped(ctrl_dev, connector, "connector") {
    		struct surface_typec_port *port;
    		u32 reg;
    
    		ret = fwnode_property_read_u32(connector, "reg", &reg);
    		if (ret < 0)
    			goto err_fwnode;
    
    		if (reg >= ARRAY_SIZE(stcm->ports)) {
    			dev_err(&sdev->dev, "connector port %d out of range\n", reg);
    			ret = EINVAL;
    			goto err_fwnode;
    		}
    
    		dev_err(&sdev->dev, "connector port %d..\n", reg);
    		port = &stcm->ports[reg];
    
    		ret = typec_get_fw_cap(&port->cap, connector);
    		if (ret)
    			goto err_fwnode;
    
    		port->cap.revision = USB_TYPEC_REV_1_2;
    		port->cap.orientation_aware = true;
    		port->cap.driver_data = stcm;
    		// port->cap.ops = ;
    		port->port = typec_register_port(&sdev->dev, &port->cap);
    		if (IS_ERR(port->port)) {
    			ret = PTR_ERR(port->port);
    			port->port = NULL;
    			goto err_fwnode;
    		}
    
    		struct typec_altmode_desc desc = {
    			.svid = USB_TYPEC_DP_SID,
    			.mode = USB_TYPEC_DP_MODE,
    			.vdo = DP_CAP_DFP_D | DP_CAP_RECEPTACLE | DP_CONF_SET_PIN_ASSIGN(BIT(DP_PIN_ASSIGN_C) | BIT(DP_PIN_ASSIGN_D)), // E?
    		};
    		// port->dp_mode =
    		if (IS_ERR(port->dp_mode)) {
    			ret = PTR_ERR(port->dp_mode);
    			port->dp_mode = NULL;
    			goto err_fwnode;
    
    		}
    	}
    
    	return ssam_device_notifier_register(stcm->sdev, &stcm->notif);
    
    err_fwnode:
    	// TODO reuse for destruction, destroy altmode
    	for (int i = 0; i < ARRAY_SIZE(stcm->ports); i++)
    		if (stcm->ports[i].port && !IS_ERR(stcm->ports[i].port))
    			typec_unregister_port(stcm->ports[i].port);
    	kfree(stcm);
    	return ret;
    }
    
    static const struct ssam_device_id surface_typec_match[] = {
    	{ SSAM_SDEV(USC, SAM, 0x00, 0x00) },
    	{ SSAM_SDEV(USC, SAM, 0x01, 0x00) },
    	{ },
    };
    MODULE_DEVICE_TABLE(ssam, surface_typec_match);
    
    static struct ssam_device_driver surface_typec_driver = {
    	.probe = surface_typec_probe,
    	.match_table = surface_typec_match,
    	.driver = {
    		.name = "surface_typec",
    		.probe_type = PROBE_PREFER_ASYNCHRONOUS,
    	},
    };
    module_ssam_device_driver(surface_typec_driver);
    
    MODULE_AUTHOR("Val Packett <val@packett.cool>");
    MODULE_DESCRIPTION("USB Type-C port driver for Surface System Aggregator Module");
    MODULE_LICENSE("GPL");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A: SAM

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions