Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp1198590rbb; Mon, 26 Feb 2024 01:42:03 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVRPMxZRgFz+TzcoaDhUS5IZjH+qSHE95IsACUpf1HrIoKtlv9555l+XuC4PW5+tz9Q1uDZDq41Ug2n4tWCler43BmArmD1h6m4JF8ULw== X-Google-Smtp-Source: AGHT+IGprfDDWkVwyHWvpBScXLy45HlgyVVtbQMz8N0sHY0y08EOzUNrulwKqinFBPF7Ks24QjUO X-Received: by 2002:a05:6a20:2d23:b0:1a0:ee92:b6d2 with SMTP id g35-20020a056a202d2300b001a0ee92b6d2mr4986137pzl.14.1708940522759; Mon, 26 Feb 2024 01:42:02 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708940522; cv=pass; d=google.com; s=arc-20160816; b=OLjroWSepL2ILSX/h/TdPR+mWm6o7zNQviwxik0hHquGDQ/+xORS7vD3SPqm5F+YSO qVbUNAoywQGL6BF3cDVUJbjFPTKTrb50r4TxJMegxkPkkBku4W6e6oekqoPFShGG9YcA adifusDcpz9w+VyWY61xWk4NV1g32a/0Mz7sJ81E1O7WBFm8HQAJpLyZGjMsGM1mV9aO 4lir/dtQuQDW9jto/CU+7N+sGW157IodN33uPFLZZVld/a+pEPbF4620uL2VdLyADANc 3r8odBO7TGipOrEqL0BJ3VcmEjdamLCgy1GbVDPTQzgn5NNJXmZfqYkhiAqioseRuEd8 C02Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=2s/LA0GImOynuShBQOW0UTYbgfB6exaazXO+Fxkd/hs=; fh=IgDv2fqL49gOboXXzCXMN0XID3/S4C2lxLde4mXZeek=; b=TGv1ioyX6OorPSFv4gQPJgL8IthHqNoHcI32W2oMXoyWP15vAVvDioHFZ9OfRG8wLg 94y0PEym/ekesb/dkqpM+IbUp3vMoGXyfNS46mVOffptPkH7E6IffzZ2LAqK3jYJg3FB ohVR1i8nryIVxHkyyX8NaxzZp+4eV1eFsiaav+YbDyRHDTk2xSd2hAMxSfXYo+vih+q2 1sDKANuTrB+Uv8KHcSy6mTi5Hda3EaTvile36jYG4eVa9aoRtoI+hfxlfXD8foJKnaU+ A++iQgYLKSDGb+yyFZ4oz8fM6TdMTQBX8a1SGfHmD0Vjc1jTwX96mYPsm3TfoDS5HodD OH0w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XOBc0yUZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-81005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id h7-20020a635307000000b005e43a9f911fsi3441463pgb.53.2024.02.26.01.42.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Feb 2024 01:42:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-81005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=XOBc0yUZ; arc=pass (i=1 dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-81005-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-81005-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.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 5541A284B9C for ; Mon, 26 Feb 2024 09:42:02 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E20187A703; Mon, 26 Feb 2024 09:05:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="XOBc0yUZ" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 09A1921A14; Mon, 26 Feb 2024 09:05:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.12 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708938340; cv=none; b=E2cYkvMiazkm2Do1as/b0mb24m6+Ki+lMp1mZiI1brHYZftPh1Bg5fqUdA+qlipS8PQGq3Mm6MMbGNKTDhagQvkUJ34UDnEAbY6VCO7XfHEgTqPxxErX7qJubqtqt9VKho6kKTNXlhiP+qCtNWNI8A4nxyFsZZAEV0E25KnR0Qc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708938340; c=relaxed/simple; bh=S8gKWyE7cMaxsz53QmeYdf2C4bKVTLAnugHHvwdiP9s=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=oVvLf2CYWmPDB0+wZHHFy8MAbbaUB33A/kJusVijH1dEJlMOUf8MVvqFmF+XyhGqAza61iSeIJ4DAaVrokXSDwqpAn/YCYIVLORk3K5NWpjcsU97AG8/wnk6Bo55ZTsoX42gf2mEJ82bN9wRZEE7UoJnKNYFGiMhoiTAmQj56wo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=XOBc0yUZ; arc=none smtp.client-ip=192.198.163.12 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708938339; x=1740474339; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=S8gKWyE7cMaxsz53QmeYdf2C4bKVTLAnugHHvwdiP9s=; b=XOBc0yUZXTFR3LvjFuV8zo39tRbmqM37EK8/zZc64JchVzQ08sYNyxXE jNJE+A3XXFgYkUwWGyUcfcpSq8TNYAaYx9e7rDG5wRy3nMf6r5c9X8Zwv rT185w10wOFuiOsc/cV7GCkz+3F2VbHxLNmKcCtX6V1sRPDncvwxfaKhO 3r9SXlv0Xoul66zIlqq+kq5EnDCmVZkEaLEhrdlUeFn/iwmcbHzkEhNiM j2wp3YgbStY9wbJ288HEM1BXKv10xVoL6VSagjLlMGy1r9eHCXtpQrr0V u01Z5f6DtdaIp+wp96MdEvqJA6DcVRMhGu9jAPITxZhxWGy8QF8zG0KUG A==; X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="6997608" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="6997608" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmvoesa106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2024 01:05:38 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10995"; a="937029619" X-IronPort-AV: E=Sophos;i="6.06,185,1705392000"; d="scan'208";a="937029619" Received: from kuha.fi.intel.com ([10.237.72.185]) by fmsmga001.fm.intel.com with SMTP; 26 Feb 2024 01:05:33 -0800 Received: by kuha.fi.intel.com (sSMTP sendmail emulation); Mon, 26 Feb 2024 11:05:32 +0200 Date: Mon, 26 Feb 2024 11:05:32 +0200 From: Heikki Krogerus To: Jameson Thies Cc: linux-usb@vger.kernel.org, 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 Subject: Re: [PATCH 2/4] usb: typec: ucsi: Register cables based on GET_CABLE_PROPERTY Message-ID: References: <20240223010328.2826774-1-jthies@google.com> <20240223010328.2826774-3-jthies@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240223010328.2826774-3-jthies@google.com> On Fri, Feb 23, 2024 at 01:03:26AM +0000, Jameson Thies wrote: > 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. > > Signed-off-by: Jameson Thies Reviewed-by: Heikki Krogerus > --- > Tested on v6.6 kernel. Expected cable properties populate the USB Type-C > connector class sysfs paths: > redrix-rev3 /sys/class/typec # ls port2-cable > device identity plug_type port2-plug0 power subsystem type uevent > usb_power_delivery_revision > > drivers/usb/typec/ucsi/ucsi.c | 69 +++++++++++++++++++++++++++++++++++ > drivers/usb/typec/ucsi/ucsi.h | 5 +++ > 2 files changed, 74 insertions(+) > > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c > index ae105383e69e..15e82f5fab37 100644 > --- a/drivers/usb/typec/ucsi/ucsi.c > +++ b/drivers/usb/typec/ucsi/ucsi.c > @@ -734,6 +734,50 @@ 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 +851,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 +952,28 @@ 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 +1015,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 +1414,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 469a2baf472e..f0aabef0b7c6 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.rc0.258.g7320e95886-goog -- heikki