Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp143413lqs; Mon, 4 Mar 2024 19:01:00 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU2ym2dff02llAg+w+UuCBYfjV6/sG5x1OmB2gctbIm+TnQfn6PhIH5kqYsUwR/K4fLpzeCeHtyKp/+tO8lUVaIRfbZsWm7jU7mZ6tLgQ== X-Google-Smtp-Source: AGHT+IGYhBbZn1XuuAxE4uWYp3oizNAzE8dS/Zoa3YQ2C6B6x65uS3fm0tcq87AYxEs5NSSCIrL+ X-Received: by 2002:a05:6a20:12ca:b0:1a1:45e4:845c with SMTP id v10-20020a056a2012ca00b001a145e4845cmr830864pzg.14.1709607659817; Mon, 04 Mar 2024 19:00:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709607659; cv=pass; d=google.com; s=arc-20160816; b=02WN6VXOWohWjh+aJb+0hcy2egT8GrJsxSEAeVF6oTnJMP1pcbsRmCNguWEqiFBX7q fGfPKFcnTzSeZHzCQ8a1FwNN+7IDnmF/kUWrJuKj8UMLA1NwiEbhA7OZffFq7BzqOdK0 VYTTsXj8hnx6FBrFTE9+OUx1C237z8xIztunpOsdMoKvP0Cl4/JO/OgFaniyuy+HD2UC Tm9juK1h1emvO48Q4LJAtXvQLEvnArltrXMNDD2/G5dpuoOO6glJiTadKfhTtuJjm9B0 K7P/cWtkVogRK46SOqgb+qRBQV65AHVmL5xGw43FPvTzElAV6IPHqcp3giY+1HXcR9+Z KQ4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=gXQ4wGCONRrVmtWgcmqK76P+N3TnCyhONDuiY0mqDpk=; fh=OHAgNkh9iFfCilRNix3bLcD1KmVKUcy+3gehFXBOGas=; b=yhj6D3Vc4gzVkRjpgTK6MTtMSFYjX2QpXMSR/uCUzWNcZn9tyicWiEuhfFB6LDm68j jE1BUd5vgw3lSwBQQvGi4pZmspL84YfBxNNduX+q8bzafM1bBYYkXLCRoHCfCaIT795i 19OsgEqirpYnsVS6gO+UNBjrycdHAJmMJQmS1be4XMUdYzIVO4Ns657ZZhAofRhbEPKe Gukd44TaYEElR3YsrITXTegl29oxNaTTvWYZZpMg9/Mpw5Z5FgnLTCzzMhKb7MQOcZzH 3rWj8ViMqAaS0Pw+3XynXwENNJAgocEqRirTr5Ig83CYNsveXhnt8B49sLKZgUZuCc0Y FDPA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yt3e/lp0"; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91591-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id v13-20020a056a00148d00b006e63d1540f2si313538pfu.187.2024.03.04.19.00.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 19:00:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91591-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b="yt3e/lp0"; arc=pass (i=1 spf=pass spfdomain=flex--jthies.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-91591-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91591-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id AC247287C22 for ; Tue, 5 Mar 2024 02:59:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B737238398; Tue, 5 Mar 2024 02:58:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="yt3e/lp0" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1E0A1374FD for ; Tue, 5 Mar 2024 02:58:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709607535; cv=none; b=lDTkkNzoo2bryc4KL5awnoS1QtxpgQixjH9RFurlSWcbR99vXiuN5EZEaapFl5/ikc73WsgE/Fs/YGrvdIJAgXoCu+Wr136190aEBBjQEZaeqdFJi/5WkgDVzPAU9A5ohU6Ree9UzaFX0jgq3dKXLydhShm0M0c9adaipkpjCrw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709607535; c=relaxed/simple; bh=guhJAh/g2XFvEwZmsYrQ52rgsrhkR0OPJnBbF/E6H3Y=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=WH93agNTQB0MeGftiUYhWA04ZeX7s+1JjK6+3OuzLe8clA2AUqgUIMfBL0fg84bXcnS787iZEilnbOQ8nqHvZFvtkCAO8x6h82YxAxNZM6nVoQ1ZXdr3+4AjVEWdPjotzP1d8mQdYdlZgw5o4usyEyc4aEvNZkOFNiO2UFr4NLQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=yt3e/lp0; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--jthies.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-60948e99cd4so78759887b3.1 for ; Mon, 04 Mar 2024 18:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709607533; x=1710212333; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=gXQ4wGCONRrVmtWgcmqK76P+N3TnCyhONDuiY0mqDpk=; b=yt3e/lp0SVs8n/vOipsEcpZwsTo4VBSMQIzXllvwhzuGl+U0L+KbkADza5ZL3FmGTm 8izE0xVVTYuNmUY0KOG1Gh1ATUrgTAgbR1QIQGpiU8k+IH2xLIsawOQ+3Ky+3xiNRh3g MCRAcE1jJPg3Nb3uKbcYsel79c+teoDaxV9EDbaQaBVNn+F84MhNI4xP9V4lgTBezL7i HhcEr1vkLGFQFzIeqzT37tNQyGQCVSASFczX3Pla4zcF3J1FhgPDYAA4Njz3xEqBKbp6 rWh+lzlx86tODLjxX7stpJn8vPdTke4V5Sl7BnWa9/DIuEsuPicNuHB0kdSRSmxzlr0k cWBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709607533; x=1710212333; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=gXQ4wGCONRrVmtWgcmqK76P+N3TnCyhONDuiY0mqDpk=; b=t6cVRo5POTeqitXh22njUB9Sv6sMAQaBTW8PtC0bx/DVkFM4jfnfsW26uAR7DkI5cp hHRoRO/K4NQZof/PhGkQ9Ihn3V0MTLenvNpjZDnFMYW69gFJchq6vs44mORAVvI3QoWP yeby+DbCtF7QjNMQrZkdg7MOXYhulFM9fa2AYSgUnsbPYkWNiflHX0InGyMH3Dff9ASA M6SWDlgkRRnM0Xlg//5levEcgDyK3LGbeiE+1+B4wc2f3kHEeQkK87eKk6d9YIiHJxqD raymIT2lMEALPESG5GKqquoy3Lnp/XIMbDoNVNMDojltd9V3nvsJuIIRcHoBsjFXP7LX myRw== X-Forwarded-Encrypted: i=1; AJvYcCXLi31sN71gtzCUIdi20cYciI7Zcp7v5Vic5OUohLOzX6yhmbZ6v3BIj9MzyWCKVAaadhLsd1XaW9kwbEqfCLOTOtG0HUy//FsHpxUU X-Gm-Message-State: AOJu0YykEU2jPN5WcjYB94k3AHvvZeUZEUAMO9DenQ9HEUbKj7L9YEAH 0R9cnetvRqblP0JF4/j10M+LrxMtxGONs3pRNrFgOxwmqhqPt0VVBS+m8/GuhYR8T1DRbPobF+3 l7Q== X-Received: from jthies.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:23db]) (user=jthies job=sendgmr) by 2002:a05:6902:1505:b0:dc6:d890:1a97 with SMTP id q5-20020a056902150500b00dc6d8901a97mr394802ybu.9.1709607533143; Mon, 04 Mar 2024 18:58:53 -0800 (PST) Date: Tue, 5 Mar 2024 02:58:02 +0000 In-Reply-To: <20240305025804.1290919-1-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240305025804.1290919-1-jthies@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240305025804.1290919-3-jthies@google.com> Subject: [PATCH v4 2/4] usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY From: Jameson Thies To: heikki.krogerus@linux.intel.com, linux-usb@vger.kernel.org Cc: jthies@google.com, pmalani@chromium.org, bleung@google.com, abhishekpandit@chromium.org, andersson@kernel.org, dmitry.baryshkov@linaro.org, fabrice.gasnier@foss.st.com, gregkh@linuxfoundation.org, hdegoede@redhat.com, neil.armstrong@linaro.org, rajaram.regupathy@intel.com, saranya.gopal@intel.com, linux-kernel@vger.kernel.org, Benson Leung Content-Type: text/plain; charset="UTF-8" Register cables with the Type-C Connector Class in the UCSI driver based on the PPM response to GET_CABLE_PROPERTY. Registered cable properties include plug type, cable type and major revision. Reviewed-by: Benson Leung Reviewed-by: Prashant Malani Reviewed-by: Dmitry Baryshkov Reviewed-by: Heikki Krogerus Signed-off-by: Jameson Thies --- Expected cable properties populate the USB Type-C connector class sysfs paths: nospike-rev4 /sys/class/typec # ls port0-cable device identity plug_type port0-plug0 power subsystem type uevent usb_power_delivery_revision Changes in v4: - None. Changes in v3: - None. Changes in v2: - Shortened lines to within 80 characters. - Tested on usb-testing branch merged with chromeOS 6.8-rc2 kernel. drivers/usb/typec/ucsi/ucsi.c | 73 +++++++++++++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 5 +++ 2 files changed, 78 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index ae105383e69e7..7c84687b5d1a3 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -734,6 +734,52 @@ static void ucsi_unregister_partner_pdos(struct ucsi_connector *con) con->partner_pd = NULL; } +static int ucsi_register_cable(struct ucsi_connector *con) +{ + struct typec_cable *cable; + struct typec_cable_desc desc = {}; + + switch (UCSI_CABLE_PROP_FLAG_PLUG_TYPE(con->cable_prop.flags)) { + case UCSI_CABLE_PROPERTY_PLUG_TYPE_A: + desc.type = USB_PLUG_TYPE_A; + break; + case UCSI_CABLE_PROPERTY_PLUG_TYPE_B: + desc.type = USB_PLUG_TYPE_B; + break; + case UCSI_CABLE_PROPERTY_PLUG_TYPE_C: + desc.type = USB_PLUG_TYPE_C; + break; + default: + desc.type = USB_PLUG_NONE; + break; + } + + desc.active = !!(UCSI_CABLE_PROP_FLAG_ACTIVE_CABLE & + con->cable_prop.flags); + desc.pd_revision = UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD( + con->cable_prop.flags); + + cable = typec_register_cable(con->port, &desc); + if (IS_ERR(cable)) { + dev_err(con->ucsi->dev, + "con%d: failed to register cable (%ld)\n", con->num, + PTR_ERR(cable)); + return PTR_ERR(cable); + } + + con->cable = cable; + return 0; +} + +static void ucsi_unregister_cable(struct ucsi_connector *con) +{ + if (!con->cable) + return; + + typec_unregister_cable(con->cable); + con->cable = NULL; +} + static void ucsi_pwr_opmode_change(struct ucsi_connector *con) { switch (UCSI_CONSTAT_PWR_OPMODE(con->status.flags)) { @@ -807,6 +853,7 @@ static void ucsi_unregister_partner(struct ucsi_connector *con) typec_partner_set_usb_power_delivery(con->partner, NULL); ucsi_unregister_partner_pdos(con); ucsi_unregister_altmodes(con, UCSI_RECIPIENT_SOP); + ucsi_unregister_cable(con); typec_unregister_partner(con->partner); con->partner = NULL; } @@ -907,6 +954,30 @@ static int ucsi_check_connection(struct ucsi_connector *con) return 0; } +static int ucsi_check_cable(struct ucsi_connector *con) +{ + u64 command; + int ret; + + if (con->cable) + return 0; + + command = UCSI_GET_CABLE_PROPERTY | UCSI_CONNECTOR_NUMBER(con->num); + ret = ucsi_send_command(con->ucsi, command, &con->cable_prop, + sizeof(con->cable_prop)); + if (ret < 0) { + dev_err(con->ucsi->dev, "GET_CABLE_PROPERTY failed (%d)\n", + ret); + return ret; + } + + ret = ucsi_register_cable(con); + if (ret < 0) + return ret; + + return 0; +} + static void ucsi_handle_connector_change(struct work_struct *work) { struct ucsi_connector *con = container_of(work, struct ucsi_connector, @@ -948,6 +1019,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) ucsi_register_partner(con); ucsi_partner_task(con, ucsi_check_connection, 1, HZ); ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); + ucsi_partner_task(con, ucsi_check_cable, 1, HZ); if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == UCSI_CONSTAT_PWR_OPMODE_PD) @@ -1346,6 +1418,7 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con) ucsi_register_partner(con); ucsi_pwr_opmode_change(con); ucsi_port_psy_changed(con); + ucsi_check_cable(con); } /* Only notify USB controller if partner supports USB data */ diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 469a2baf472e4..f0aabef0b7c64 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -265,6 +265,9 @@ struct ucsi_cable_property { #define UCSI_CABLE_PROPERTY_PLUG_TYPE_C 2 #define UCSI_CABLE_PROPERTY_PLUG_OTHER 3 #define UCSI_CABLE_PROP_FLAG_MODE_SUPPORT BIT(5) +#define UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV(_f_) (((_f_) & GENMASK(7, 6)) >> 6) +#define UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV_AS_BCD(_f_) \ + UCSI_SPEC_REVISION_TO_BCD(UCSI_CABLE_PROP_FLAG_PD_MAJOR_REV(_f_)) u8 latency; } __packed; @@ -400,6 +403,7 @@ struct ucsi_connector { struct typec_port *port; struct typec_partner *partner; + struct typec_cable *cable; struct typec_altmode *port_altmode[UCSI_MAX_ALTMODES]; struct typec_altmode *partner_altmode[UCSI_MAX_ALTMODES]; @@ -408,6 +412,7 @@ struct ucsi_connector { struct ucsi_connector_status status; struct ucsi_connector_capability cap; + struct ucsi_cable_property cable_prop; struct power_supply *psy; struct power_supply_desc psy_desc; u32 rdo; -- 2.44.0.rc1.240.g4c46232300-goog