From patchwork Mon Nov 16 20:11:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910707 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B89CE15E6 for ; Mon, 16 Nov 2020 20:12:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9AEF7217A0 for ; Mon, 16 Nov 2020 20:12:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KuK5C60F" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727614AbgKPUMS (ORCPT ); Mon, 16 Nov 2020 15:12:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726440AbgKPUMR (ORCPT ); Mon, 16 Nov 2020 15:12:17 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C47C6C0613CF for ; Mon, 16 Nov 2020 12:12:17 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id t21so7877872pgl.3 for ; Mon, 16 Nov 2020 12:12:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TM34Y8/Xkbhi+35MDii+t1nA+9j+av7JM+nHGfjWGOI=; b=KuK5C60FGb0OkS1JeYNuK+sBpPP6TMURsm2/zlPeTiJsO5+A7OBpPseAaRRPbgm+po mtdcIf3rCYDmtf9lJIZXm9Qufu1cBEPtjIqcRP45wwj+cV/Z5vt8KoRAVazUvFqbkasA VUQSHgdNCJG6vSjN5SD3ALXec0K1CxZnKrfUI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TM34Y8/Xkbhi+35MDii+t1nA+9j+av7JM+nHGfjWGOI=; b=coAjt9R+aYz5fseOFiN5uQ5EyhmohjsFa/NmI2RWXtN3fiD+Hv3v6tMsWLay/kAzZu J8Q6FGfgAYS6o7Se+CBFjWoYG3XsMpIZeCI69NcamEsvh5JoMYiGSMRFfiYCGfCEB29X +LARWlYDihTVDY2rtfQUIxFD/Lz3p7kHCVIfau2bHjESvcZcvlBlvGoT3ZGs6TuTSDw+ xa3ZGPB7hZP1VUpDeCh0fdiQM/27ldbSs7RberrH3KLJjpSSGKcW0u3wDn4P5nMl7F2a tjtcdTZ+RUqgN2INgM1Vg1t3qyvvnk6EjQ8WmN3MHvCU8E2qUi/cEK/fcB0ktcV/bF5U RVNQ== X-Gm-Message-State: AOAM531xolQSqUN6RdPFwkLmQeJpse1sUTUyLSEbttPwkPvOjIr6+P2x lUA+0fNIb0eCylI0iUwNsgCSXazg6tGLkQ== X-Google-Smtp-Source: ABdhPJzicRYi1Z2xIFSKRLEjWTu4BcYXPR2VlejlzbefEvEyFDtZGOM3ew/a/YjWo0tuAhBWA1EIJQ== X-Received: by 2002:a65:560b:: with SMTP id l11mr756789pgs.63.1605557537362; Mon, 16 Nov 2020 12:12:17 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.12.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:12:17 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 01/11] usb: pd: Add captive Type C cable type Date: Mon, 16 Nov 2020 12:11:38 -0800 Message-Id: <20201116201150.2919178-2-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The USB Power Delivery Specification R3.0 adds a captive cable type to the "USB Type-C plug to USB Type-C/Captive" field (Bits 19-18, Passive/Active Cable VDO, Table 6-38 & 6-39). Add the corresponding definition to the Cable VDO header. Also add a helper macro to get the Type C cable connector type, when provided the cable VDO. Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reviewed-by: Benson Leung Reviewed-by: Greg Kroah-Hartman Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - No changes. include/linux/usb/pd_vdo.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/linux/usb/pd_vdo.h b/include/linux/usb/pd_vdo.h index 68bdc4e2f5a9..8c5cb5830754 100644 --- a/include/linux/usb/pd_vdo.h +++ b/include/linux/usb/pd_vdo.h @@ -177,7 +177,7 @@ * <31:28> :: Cable HW version * <27:24> :: Cable FW version * <23:20> :: Reserved, Shall be set to zero - * <19:18> :: type-C to Type-A/B/C (00b == A, 01 == B, 10 == C) + * <19:18> :: type-C to Type-A/B/C/Captive (00b == A, 01 == B, 10 == C, 11 == Captive) * <17> :: Type-C to Plug/Receptacle (0b == plug, 1b == receptacle) * <16:13> :: cable latency (0001 == <10ns(~1m length)) * <12:11> :: cable termination type (11b == both ends active VCONN req) @@ -193,6 +193,7 @@ #define CABLE_ATYPE 0 #define CABLE_BTYPE 1 #define CABLE_CTYPE 2 +#define CABLE_CAPTIVE 3 #define CABLE_PLUG 0 #define CABLE_RECEPTACLE 1 #define CABLE_CURR_1A5 0 @@ -208,6 +209,7 @@ | (tx1d) << 10 | (tx2d) << 9 | (rx1d) << 8 | (rx2d) << 7 \ | ((cur) & 0x3) << 5 | (vps) << 4 | (sopp) << 3 \ | ((usbss) & 0x7)) +#define VDO_TYPEC_CABLE_TYPE(vdo) (((vdo) >> 18) & 0x3) /* * AMA VDO From patchwork Mon Nov 16 20:11:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910709 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86DEE6C1 for ; Mon, 16 Nov 2020 20:12:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E44621D7E for ; Mon, 16 Nov 2020 20:12:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="gjPY0wXT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727061AbgKPUMc (ORCPT ); Mon, 16 Nov 2020 15:12:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726527AbgKPUMc (ORCPT ); Mon, 16 Nov 2020 15:12:32 -0500 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59D2EC0613CF for ; Mon, 16 Nov 2020 12:12:32 -0800 (PST) Received: by mail-pf1-x42f.google.com with SMTP id 131so4676431pfb.9 for ; Mon, 16 Nov 2020 12:12:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Cvu6lrdt5sZy1ojhENHDrSU3GodwauRNHyAm+VWqpcs=; b=gjPY0wXTqo9Qx1RyJPYWniFEfol4CKuM2+y3LeC50c4CZk2eoSmRz1Bsp/pjQginCG 7o/ITHdjWYLiWUrJQQSpRHt1nYI5xtfg7TebEtkV8LDWCIru2c2UeAwBey/ItZttFlHG bJHSwYTNqHv+OyWIeZsOA3P9Pslejvv/2nnUo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Cvu6lrdt5sZy1ojhENHDrSU3GodwauRNHyAm+VWqpcs=; b=Ix7ZWgJ8ORCuUmBZLlyI7cnBUGD9hjW8ygqBXKoHbmkA3LyJW+pgixIq/mvOewgfvt krajmnInekk6P9uQGuXhCFN1DsQjDDx/Oxc+sdsHGGek6gS/T4yjlJ/squoigw3eZ2wg fhLb0ZFNAIrqRe6qnfH5nU/oktPsqtMzpLZr3lBv6Ifx1Z+ye6skUZ7Pwi1RdOmINA52 lj2r3GIDqZXt4qzi9ZqdJ0VGzLdyqxrNr4b4mqUL3A2HUymfbtuyIj5YYeJLDDkkWAPD zxiVV0IqtlPn44zcKABI5giDhrtBznlIfBBWSWKvXYUy1B5fdFmBKLBottNLQXR/N6wj 1tfw== X-Gm-Message-State: AOAM530qciUfspVZqlVhSf5rtL0Rx5CAxlJZUlAdcAX7AiXm5aQXwDIy l38w2KhYgDEWL3DOqloicVs5uJYi6XxeEg== X-Google-Smtp-Source: ABdhPJyOIODki9q7kZpcNVhYPekDtBkuYujJD4AMyNwL1dPB5WkxFtOpDU/1cfMrzsAUJU1WjmfhVw== X-Received: by 2002:a63:d46:: with SMTP id 6mr726120pgn.227.1605557551908; Mon, 16 Nov 2020 12:12:31 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.12.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:12:31 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 02/11] usb: typec: Add number of altmodes partner attr Date: Mon, 16 Nov 2020 12:11:40 -0800 Message-Id: <20201116201150.2919178-3-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a user-visible attribute for the number of alternate modes available in a partner. This allows userspace to determine whether there are any remaining alternate modes left to be registered by the kernel driver. It can begin executing any policy state machine after all available alternate modes have been registered with the connector class framework. This value is set to "-1" initially, signifying that a valid number of alternate modes haven't been set for the partner. Also add a sysfs file which exposes this attribute. The file remains hidden as long as the attribute value is -1. Cc: Benson Leung Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - Added ABI/testing documentation entry for added sysfs file. - Changed name of the sysfs file to "number_of_alternate_modes" based on review comments. - Added is_visible() logic suggested by Heikki in the comments of v1. - Updated commit message. Documentation/ABI/testing/sysfs-class-typec | 8 +++ drivers/usb/typec/class.c | 66 ++++++++++++++++++++- include/linux/usb/typec.h | 1 + 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index b834671522d6..73ac7b461ae5 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -134,6 +134,14 @@ Description: Shows if the partner supports USB Power Delivery communication: Valid values: yes, no +What: /sys/class/typec/-partner/number_of_alternate_modes +Date: November 2020 +Contact: Prashant Malani +Description: + Shows the number of alternate modes which are advertised by the partner + during Power Delivery discovery. This file remains hidden until a value + greater than or equal to 0 is set by Type C port driver. + What: /sys/class/typec/-partner>/identity/ Date: April 2017 Contact: Heikki Krogerus diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index 35eec707cb51..c7412ddbd311 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -33,6 +33,7 @@ struct typec_partner { struct usb_pd_identity *identity; enum typec_accessory accessory; struct ida mode_ids; + int num_altmodes; }; struct typec_port { @@ -532,12 +533,43 @@ static ssize_t supports_usb_power_delivery_show(struct device *dev, } static DEVICE_ATTR_RO(supports_usb_power_delivery); +static ssize_t number_of_alternate_modes_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct typec_partner *p = to_typec_partner(dev); + + return sysfs_emit(buf, "%d\n", p->num_altmodes); +} +static DEVICE_ATTR_RO(number_of_alternate_modes); + static struct attribute *typec_partner_attrs[] = { &dev_attr_accessory_mode.attr, &dev_attr_supports_usb_power_delivery.attr, + &dev_attr_number_of_alternate_modes.attr, + NULL +}; + +static umode_t typec_partner_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct typec_partner *partner = to_typec_partner(kobj_to_dev(kobj)); + + if (attr == &dev_attr_number_of_alternate_modes.attr) { + if (partner->num_altmodes < 0) + return 0; + } + + return attr->mode; +} + +static struct attribute_group typec_partner_group = { + .is_visible = typec_partner_attr_is_visible, + .attrs = typec_partner_attrs +}; + +static const struct attribute_group *typec_partner_groups[] = { + &typec_partner_group, NULL }; -ATTRIBUTE_GROUPS(typec_partner); static void typec_partner_release(struct device *dev) { @@ -570,6 +602,37 @@ int typec_partner_set_identity(struct typec_partner *partner) } EXPORT_SYMBOL_GPL(typec_partner_set_identity); +/** + * typec_partner_set_num_altmodes - Set the number of available partner altmodes + * @partner: The partner to be updated. + * @num_alt_modes: The number of altmodes we want to specify as available. + * + * This routine is used to report the number of alternate modes supported by the + * partner. This value is *not* enforced in alternate mode registration routines. + * + * @partner.num_altmodes is set to -1 on partner registration, denoting that + * a valid value has not been set for it yet. + * + * Returns 0 on success or negative error number on failure. + */ +int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes) +{ + int ret; + + if (num_altmodes < 0) + return -EINVAL; + + partner->num_altmodes = num_altmodes; + ret = sysfs_update_group(&partner->dev.kobj, &typec_partner_group); + if (ret < 0) + return ret; + + sysfs_notify(&partner->dev.kobj, NULL, "number_of_alternate_modes"); + + return 0; +} +EXPORT_SYMBOL_GPL(typec_partner_set_num_altmodes); + /** * typec_partner_register_altmode - Register USB Type-C Partner Alternate Mode * @partner: USB Type-C Partner that supports the alternate mode @@ -612,6 +675,7 @@ struct typec_partner *typec_register_partner(struct typec_port *port, ida_init(&partner->mode_ids); partner->usb_pd = desc->usb_pd; partner->accessory = desc->accessory; + partner->num_altmodes = -1; if (desc->identity) { /* diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 6be558045942..bc6b1a71cb8a 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -126,6 +126,7 @@ struct typec_altmode_desc { enum typec_port_data roles; }; +int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmodes); struct typec_altmode *typec_partner_register_altmode(struct typec_partner *partner, const struct typec_altmode_desc *desc); From patchwork Mon Nov 16 20:11:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910711 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B661E15E6 for ; Mon, 16 Nov 2020 20:12:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 963B521D7E for ; Mon, 16 Nov 2020 20:12:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="IFLoEzJj" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726382AbgKPUMs (ORCPT ); Mon, 16 Nov 2020 15:12:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726268AbgKPUMs (ORCPT ); Mon, 16 Nov 2020 15:12:48 -0500 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C0ABC0613CF for ; Mon, 16 Nov 2020 12:12:48 -0800 (PST) Received: by mail-pf1-x42b.google.com with SMTP id c20so15203359pfr.8 for ; Mon, 16 Nov 2020 12:12:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=z8GPAvDAlSfkoQSjuEJ0bvEZ1CcveAaL6tNvl68OKZs=; b=IFLoEzJjWLLImXDDnVTRmjqX2AUVgv99PSEiGsPVR7Mxru8xFo8jKmIcsZ/BgBbVQB Exg8WzaGGACqVitl1qQN+/QX/vGJpnesS3dyDTUhboJ7+Dqyq30YW/n2bK43Al1s7Zkw IIal/QxDNEMrfVCqrByl88yBlHdJ0P0JlsBdg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=z8GPAvDAlSfkoQSjuEJ0bvEZ1CcveAaL6tNvl68OKZs=; b=IjTO+QuxZTiw0IoYvWPYcknQOi9nXw53HxL8XhjCbLuZeo/YpjZrCoHNbmMnQ9pmIj Kk6TQB9CmiwgaTqGuJwFELo4SLqw70vmESVYXeBzaT2dk8FNpGyAOSQRQLJkSPmd7bg7 hCMVRLkQMofhGSnHWOWH3TXKkLfKLCHCsZSAb1q0Yso7EYPe3yK3A1fIEwvQCsW1pK04 GJMBjfdjKwkyssEisBqgpmDJL//bumZSA0mNZa3zxMyQfec5QcQYeGLU6wDOerLZ+iTb QUH3Czu81tEnGaL3Q+/2oEyJSU8xivC28MST2ZGEWuaWyYCGpWpH98GY+MRBhbwBDJBe jX0Q== X-Gm-Message-State: AOAM533M/vhK71EKRf1BJMRTpKzddhTMSUk8xsvB+hxngXd2jzY8Nv1i EXrNzbYbWOQGBvYIrZXZejh9Cw== X-Google-Smtp-Source: ABdhPJz5S3hGVam/Wc98BfMyrQ4HACiQaUSbziR0hTykBa3o3ugwXnC4LQLkriyfxwRGosyBCvHIng== X-Received: by 2002:a17:90a:db54:: with SMTP id u20mr590997pjx.189.1605557567686; Mon, 16 Nov 2020 12:12:47 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.12.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:12:47 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani Subject: [PATCH v3 03/11] usb: typec: Add plug num_altmodes sysfs attr Date: Mon, 16 Nov 2020 12:11:42 -0800 Message-Id: <20201116201150.2919178-4-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a field to the typec_plug struct to record the number of available altmodes as well as the corresponding sysfs attribute to expose this to userspace. This allows userspace to determine whether there are any remaining alternate modes left to be registered by the kernel driver. It can begin executing any policy state machine after all available alternate modes have been registered with the connector class framework. This value is set to "-1" initially, signifying that a valid number of alternate modes haven't been set for the plug. The sysfs file remains hidden as long as the attribute value is -1. We re-use the partner attribute for number_of_alternate_modes since the usage and name is similar, and update the corresponding *_show() command to support both partner and plugs. Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. No version v2. Documentation/ABI/testing/sysfs-class-typec | 9 +++ drivers/usb/typec/class.c | 77 ++++++++++++++++++++- include/linux/usb/typec.h | 1 + 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-class-typec b/Documentation/ABI/testing/sysfs-class-typec index 73ac7b461ae5..29eccf5fb8ed 100644 --- a/Documentation/ABI/testing/sysfs-class-typec +++ b/Documentation/ABI/testing/sysfs-class-typec @@ -204,6 +204,15 @@ Description: - type-c - captive +What: /sys/class/typec/-/number_of_alternate_modes +Date: November 2020 +Contact: Prashant Malani +Description: + Shows the number of alternate modes which are advertised by the plug + associated with a particular cable during Power Delivery discovery. + This file remains hidden until a value greater than or equal to 0 + is set by Type C port driver. + What: /sys/class/typec/-cable/identity/ Date: April 2017 Contact: Heikki Krogerus diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index c7412ddbd311..e68798599ca8 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -18,6 +18,7 @@ struct typec_plug { struct device dev; enum typec_plug_index index; struct ida mode_ids; + int num_altmodes; }; struct typec_cable { @@ -536,9 +537,21 @@ static DEVICE_ATTR_RO(supports_usb_power_delivery); static ssize_t number_of_alternate_modes_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct typec_partner *p = to_typec_partner(dev); + struct typec_partner *partner; + struct typec_plug *plug; + int num_altmodes; + + if (is_typec_partner(dev)) { + partner = to_typec_partner(dev); + num_altmodes = partner->num_altmodes; + } else if (is_typec_plug(dev)) { + plug = to_typec_plug(dev); + num_altmodes = plug->num_altmodes; + } else { + return 0; + } - return sysfs_emit(buf, "%d\n", p->num_altmodes); + return sysfs_emit(buf, "%d\n", num_altmodes); } static DEVICE_ATTR_RO(number_of_alternate_modes); @@ -726,11 +739,70 @@ static void typec_plug_release(struct device *dev) kfree(plug); } +static struct attribute *typec_plug_attrs[] = { + &dev_attr_number_of_alternate_modes.attr, + NULL +}; + +static umode_t typec_plug_attr_is_visible(struct kobject *kobj, struct attribute *attr, int n) +{ + struct typec_plug *plug = to_typec_plug(kobj_to_dev(kobj)); + + if (attr == &dev_attr_number_of_alternate_modes.attr) { + if (plug->num_altmodes < 0) + return 0; + } + + return attr->mode; +} + +static struct attribute_group typec_plug_group = { + .is_visible = typec_plug_attr_is_visible, + .attrs = typec_plug_attrs +}; + +static const struct attribute_group *typec_plug_groups[] = { + &typec_plug_group, + NULL +}; + static const struct device_type typec_plug_dev_type = { .name = "typec_plug", + .groups = typec_plug_groups, .release = typec_plug_release, }; +/** + * typec_plug_set_num_altmodes - Set the number of available plug altmodes + * @plug: The plug to be updated. + * @num_altmodes: The number of altmodes we want to specify as available. + * + * This routine is used to report the number of alternate modes supported by the + * plug. This value is *not* enforced in alternate mode registration routines. + * + * @plug.num_altmodes is set to -1 on plug registration, denoting that + * a valid value has not been set for it yet. + * + * Returns 0 on success or negative error number on failure. + */ +int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes) +{ + int ret; + + if (num_altmodes < 0) + return -EINVAL; + + plug->num_altmodes = num_altmodes; + ret = sysfs_update_group(&plug->dev.kobj, &typec_plug_group); + if (ret < 0) + return ret; + + sysfs_notify(&plug->dev.kobj, NULL, "number_of_alternate_modes"); + + return 0; +} +EXPORT_SYMBOL_GPL(typec_plug_set_num_altmodes); + /** * typec_plug_register_altmode - Register USB Type-C Cable Plug Alternate Mode * @plug: USB Type-C Cable Plug that supports the alternate mode @@ -776,6 +848,7 @@ struct typec_plug *typec_register_plug(struct typec_cable *cable, sprintf(name, "plug%d", desc->index); ida_init(&plug->mode_ids); + plug->num_altmodes = -1; plug->index = desc->index; plug->dev.class = typec_class; plug->dev.parent = &cable->dev; diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index bc6b1a71cb8a..54475323f83b 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -130,6 +130,7 @@ int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmod struct typec_altmode *typec_partner_register_altmode(struct typec_partner *partner, const struct typec_altmode_desc *desc); +int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes); struct typec_altmode *typec_plug_register_altmode(struct typec_plug *plug, const struct typec_altmode_desc *desc); From patchwork Mon Nov 16 20:11:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910713 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 24B546C1 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F2533221FD for ; Mon, 16 Nov 2020 20:13:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="WS2G1M0w" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727319AbgKPUM5 (ORCPT ); Mon, 16 Nov 2020 15:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726281AbgKPUM4 (ORCPT ); Mon, 16 Nov 2020 15:12:56 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E61A0C0613CF for ; Mon, 16 Nov 2020 12:12:56 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id w6so15233931pfu.1 for ; Mon, 16 Nov 2020 12:12:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n4b+ds1Fe+TXuvmcjAO9zzkmygh5sQ/IQkjDCJxp9mk=; b=WS2G1M0wgzgMtOa+VULHym7vC8s+ANdoApBkc+zmQ+Cn4L2jklHLB7ij1gANegN7Vn 5NedFXA+ahgH4cuVvkxKBgMCCY67avPHnam5T5WlTnwv5gSFZGqHOj1RPcUCdRDj1JFn nnCdbid5PlRqPBMYx7MoDe1Vo29/ahsUmZnSY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n4b+ds1Fe+TXuvmcjAO9zzkmygh5sQ/IQkjDCJxp9mk=; b=brQimu+9mqb5sAjEWKxX8ZE8xq5/3LWHT5vgSbhuDTX9N3h9IjGXRArj2wQHnww9xV EHcapOgVIZdJiwWI52ZOHRJEpZzv/FPfDYQBnD9+tWfmHmRf9hxapQYfBCpIifYZU3Ea lGf5GYZnwSdGaP2Al7SWJqfkOHIQCrVmzMFnN/iVyWh0tqTIeZYqVN/pJ03ej7bHZQwY bF4nrJfLdZc4LXDiObEk+Ivr+nTlK3ZV9POCcQ3DGl7nbNKRv61jUpnyxrdXhRUDJ8eP 0PmS0i58lOEk+4jYz6wxzujNWaoWQXg/PuqXpQExUx1z7mzfBAdXGhuiMp3/E66MCuPm 1vbQ== X-Gm-Message-State: AOAM530ll3uvmY7jwjx2uFlfi3yHNFH4WKJ0e4gTzEpvAheudHnLtmJ4 x+OFgmf5j73nfa40FK2h/SvyXg== X-Google-Smtp-Source: ABdhPJweZoDIArS64rJtCe3Pkpd8uUBGRPfvPHVQRnPuouIOsSaicaeFqIlDzY/kdDwRvwyVYchVQQ== X-Received: by 2002:a17:90a:9a1:: with SMTP id 30mr653175pjo.52.1605557576232; Mon, 16 Nov 2020 12:12:56 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.12.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:12:55 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 04/11] platform/chrome: cros_ec_typec: Make disc_done flag partner-only Date: Mon, 16 Nov 2020 12:11:44 -0800 Message-Id: <20201116201150.2919178-5-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Change the disc_done flag, which indicates whether PD discovery is complete, to sop_disc_done instead, since we will process SOP and SOP' discovery data separately. Signed-off-by: Prashant Malani Reviewed-by: Greg Kroah-Hartman Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index ce031a10eb1b..801c3d2c1fbd 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -57,8 +57,8 @@ struct cros_typec_port { /* Port alt modes. */ struct typec_altmode p_altmode[CROS_EC_ALTMODE_MAX]; - /* Flag indicating that PD discovery data parsing is completed. */ - bool disc_done; + /* Flag indicating that PD partner discovery data parsing is completed. */ + bool sop_disc_done; struct ec_response_typec_discovery *sop_disc; struct list_head partner_mode_list; }; @@ -210,7 +210,7 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec, typec_unregister_partner(port->partner); port->partner = NULL; memset(&port->p_identity, 0, sizeof(port->p_identity)); - port->disc_done = false; + port->sop_disc_done = false; } static void cros_unregister_ports(struct cros_typec_data *typec) @@ -727,18 +727,13 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num return; } - if (typec->ports[port_num]->disc_done) - return; - /* Handle any events appropriately. */ - if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE) { + if (resp.events & PD_STATUS_EVENT_SOP_DISC_DONE && !typec->ports[port_num]->sop_disc_done) { ret = cros_typec_handle_sop_disc(typec, port_num); - if (ret < 0) { + if (ret < 0) dev_err(typec->dev, "Couldn't parse SOP Disc data, port: %d\n", port_num); - return; - } - - typec->ports[port_num]->disc_done = true; + else + typec->ports[port_num]->sop_disc_done = true; } } From patchwork Mon Nov 16 20:11:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910715 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60F7216C1 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3A1D2217A0 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="noWTjOQt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729295AbgKPUNJ (ORCPT ); Mon, 16 Nov 2020 15:13:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726980AbgKPUNH (ORCPT ); Mon, 16 Nov 2020 15:13:07 -0500 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF72C0613CF for ; Mon, 16 Nov 2020 12:13:07 -0800 (PST) Received: by mail-pg1-x543.google.com with SMTP id 34so10926567pgp.10 for ; Mon, 16 Nov 2020 12:13:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RCMqI38F9+XIUIyYtqumHY3HDKRkeDtWdAUlKq29RGI=; b=noWTjOQtjRfLv3wqepfM5xq1e0ZWG2Mrqfmq0pDljUMkzwggz9M4QD3VkCUAmMyUga GD9KCZiJwDAlwyyb+PRUQBBjlTzRYTiwrwj5rG1DFlYAxsg9ZDLQDdQYknxt+kNPZrmf Lt6ssatMc/iYPQqINiMGOks+2d8fO0A+ngRcs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RCMqI38F9+XIUIyYtqumHY3HDKRkeDtWdAUlKq29RGI=; b=EcWws1NTFrjUClMMZI6C9d+pi5jbIacQ0GaKkKrz51ts85+lXt+UnMk73s09kYgWIX HU5i3bkQemoW7zv7SwmKlIIHFuZPA80OeTsdpcg2kBxwcyXaUv/DsAP8MSebN0mVUZIi RWP30AAwy1nzQZd7FE6jmJBmpstgAY/IIovGb8rjbE4yDfdBFv+uQ4l++VxKGA2/ci37 mKsU1xP7jQfpBuljn4v2uDh/A7jtpjBRvJArJouMSzCq2W8JB3QU+VDrnNRonTfNHLTW /fyBf+Yt7xqt4UzUXxjZAtdW//XN/m29CDhuKIIJ+0bqKEjyULdV29VRNfDvR0PLhRKT jsrA== X-Gm-Message-State: AOAM531tcmgos3tTKMF84WphEy9ZyNoyBOzP1ZK8/LK9Gilv8saBkOZB qJomLE9Ct8b6LiGsp3C6xmo0zQ== X-Google-Smtp-Source: ABdhPJzfrG0aXm65pJDRx5dMPi1vuZxA7545qoR4CG22WaUZ6ETI97+YibuBEwlGcDLY8toOc1G4eQ== X-Received: by 2002:a17:90a:9c5:: with SMTP id 63mr586348pjo.195.1605557587242; Mon, 16 Nov 2020 12:13:07 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.13.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:13:06 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 05/11] platform/chrome: cros_ec_typec: Factor out PD identity parsing Date: Mon, 16 Nov 2020 12:11:46 -0800 Message-Id: <20201116201150.2919178-6-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Factor out the PD identity parsing code into a separate function. This way it can be re-used for Cable PD identity parsing in future patches. No functional changes are introduced by this patch. Signed-off-by: Prashant Malani Reviewed-by: Greg Kroah-Hartman Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 35 ++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 801c3d2c1fbd..f6d3c37c2c27 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -657,6 +657,28 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ return ret; } +/* + * Parse the PD identity data from the EC PD discovery responses and copy that to the supplied + * PD identity struct. + */ +static void cros_typec_parse_pd_identity(struct usb_pd_identity *id, + struct ec_response_typec_discovery *disc) +{ + int i; + + /* First, update the PD identity VDOs for the partner. */ + if (disc->identity_count > 0) + id->id_header = disc->discovery_vdo[0]; + if (disc->identity_count > 1) + id->cert_stat = disc->discovery_vdo[1]; + if (disc->identity_count > 2) + id->product = disc->discovery_vdo[2]; + + /* Copy the remaining identity VDOs till a maximum of 6. */ + for (i = 3; i < disc->identity_count && i < VDO_MAX_OBJECTS; i++) + id->vdo[i - 3] = disc->discovery_vdo[i]; +} + static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num) { struct cros_typec_port *port = typec->ports[port_num]; @@ -666,7 +688,6 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu .partner_type = TYPEC_PARTNER_SOP, }; int ret = 0; - int i; if (!port->partner) { dev_err(typec->dev, @@ -684,17 +705,7 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu goto disc_exit; } - /* First, update the PD identity VDOs for the partner. */ - if (sop_disc->identity_count > 0) - port->p_identity.id_header = sop_disc->discovery_vdo[0]; - if (sop_disc->identity_count > 1) - port->p_identity.cert_stat = sop_disc->discovery_vdo[1]; - if (sop_disc->identity_count > 2) - port->p_identity.product = sop_disc->discovery_vdo[2]; - - /* Copy the remaining identity VDOs till a maximum of 6. */ - for (i = 3; i < sop_disc->identity_count && i < VDO_MAX_OBJECTS; i++) - port->p_identity.vdo[i - 3] = sop_disc->discovery_vdo[i]; + cros_typec_parse_pd_identity(&port->p_identity, sop_disc); ret = typec_partner_set_identity(port->partner); if (ret < 0) { From patchwork Mon Nov 16 20:11:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910717 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9853B15E6 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72148217A0 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="MAytxneI" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731842AbgKPUNS (ORCPT ); Mon, 16 Nov 2020 15:13:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728944AbgKPUNS (ORCPT ); Mon, 16 Nov 2020 15:13:18 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E06BC0613CF for ; Mon, 16 Nov 2020 12:13:17 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id 81so5808087pgf.0 for ; Mon, 16 Nov 2020 12:13:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6KrG9tRhir5L1GUg30ALQcT/RDb/5YylxoplKqcEFfw=; b=MAytxneIq/7RufgdAa300IWC9MCTfwLsZ0ye7HvC/QBmn45dTOXRO+jE4ub2qz4Xam vXYu1wT3RVCvZirC1ck9b2Gs79EkN54vRjru4qpJUJn1pVMPAAJc81ux5phjKGrVD6lr fWJVXU7mQMp4Mfe/Ch5Ay2MpilYNy3fp4cnz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6KrG9tRhir5L1GUg30ALQcT/RDb/5YylxoplKqcEFfw=; b=B1or5t2UAZQOpm3P9QfBERuhgfWArK640eTsc9xsXvbZN2HyiFcTgn4jaay5w858bf 5M4uI3a3XNzY3PnUdrSiTsFiJit0rYWr90fuR7xRYzBudmxrzD3K/t2/JWbNV6oNvmlY /gZ8rsmxrK4xdMENK7s8t7HHl0OY5KgzxeqQxsxTDzU9zTMoxfjLWSbQhR7Bm7JB4WP1 4Ai39swhSHbhBoCU6TYmYc+gu5bg4ZoSxd5oCAxm/VDY+/S8/K5WZ9neJFm+7J87bp3i WGBtL1UkxDUloQsfpxxkwBD9AdyOVgmqauj49k2epDQoVmSSoUR6dff9Fpgmi6aFv+zI G4VQ== X-Gm-Message-State: AOAM532voLt4qsY9o9AIi7BnrxEkosgt6FLGAGU2r79PdJsBMxEUftAl tu98kQnbEghTf6gqvsyQFj8GiQ== X-Google-Smtp-Source: ABdhPJzJR0snbvciAIXOOeLQJa3CelPB9OUtxn4ERrUapXSzy2lIBqqkNKvG1TMJ7eFUPbfFjTTuvA== X-Received: by 2002:a17:90a:d913:: with SMTP id c19mr584421pjv.231.1605557596588; Mon, 16 Nov 2020 12:13:16 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:13:16 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 06/11] platform/chrome: cros_ec_typec: Rename discovery struct Date: Mon, 16 Nov 2020 12:11:48 -0800 Message-Id: <20201116201150.2919178-7-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Rename the sop_disc data struct which is used to store PD discovery data to the more generic name of disc_data. It can then be re-used to store and process cable discovery data. Signed-off-by: Prashant Malani Reviewed-by: Greg Kroah-Hartman Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index f6d3c37c2c27..3c8ff07c8803 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -59,7 +59,7 @@ struct cros_typec_port { /* Flag indicating that PD partner discovery data parsing is completed. */ bool sop_disc_done; - struct ec_response_typec_discovery *sop_disc; + struct ec_response_typec_discovery *disc_data; struct list_head partner_mode_list; }; @@ -323,8 +323,8 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) cros_typec_register_port_altmodes(typec, port_num); - cros_port->sop_disc = devm_kzalloc(dev, EC_PROTO2_MAX_RESPONSE_SIZE, GFP_KERNEL); - if (!cros_port->sop_disc) { + cros_port->disc_data = devm_kzalloc(dev, EC_PROTO2_MAX_RESPONSE_SIZE, GFP_KERNEL); + if (!cros_port->disc_data) { ret = -ENOMEM; goto unregister_ports; } @@ -617,7 +617,7 @@ static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num, static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_num) { struct cros_typec_port *port = typec->ports[port_num]; - struct ec_response_typec_discovery *sop_disc = port->sop_disc; + struct ec_response_typec_discovery *sop_disc = port->disc_data; struct cros_typec_altmode_node *node; struct typec_altmode_desc desc; struct typec_altmode *amode; @@ -682,7 +682,7 @@ static void cros_typec_parse_pd_identity(struct usb_pd_identity *id, static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num) { struct cros_typec_port *port = typec->ports[port_num]; - struct ec_response_typec_discovery *sop_disc = port->sop_disc; + struct ec_response_typec_discovery *sop_disc = port->disc_data; struct ec_params_typec_discovery req = { .port = port_num, .partner_type = TYPEC_PARTNER_SOP, From patchwork Mon Nov 16 20:11:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910719 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D189D17D5 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB80C217A0 for ; Mon, 16 Nov 2020 20:13:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="JNd0bE8+" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731865AbgKPUN2 (ORCPT ); Mon, 16 Nov 2020 15:13:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728768AbgKPUN2 (ORCPT ); Mon, 16 Nov 2020 15:13:28 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D3FDC0613CF for ; Mon, 16 Nov 2020 12:13:28 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id c20so15205148pfr.8 for ; Mon, 16 Nov 2020 12:13:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uZxKl4KnMpLhS0ObByuvx5Naa8y47uOCjdkpzZuISPg=; b=JNd0bE8+dxkH9Y6ebJC0QAcd73IqE4LlS5wACTH7/O9jFwmDqWIqSUr/wo54Fq7/5r gr7rMHs1LFQ1SLKSA+nf5xA9A2ve8JUCBC/lJekm5OfQgt2l5G0awla/dAv4aF8BnaHw qbLA4AF7kClaC4beqCyNnqieIXttFPWeHhFNw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uZxKl4KnMpLhS0ObByuvx5Naa8y47uOCjdkpzZuISPg=; b=HsubQMhe3Y0g13o0b9m4kGkAPouL7dWlxsx9enLbFzl0mVe2qpIjK/hQ9x2DWGZy+h rJAMTwtqC6HZ+EWoQ2BsgrXYQpWdAC4l8VuBmtqU6YffwGDMxSlo+Bh45yGxWX7kjd7A aoEn6ZcRyX1LTj0ioshg5+fxkbJh3QL5kHs+SMLup2O4iVVLvEHPE3qUjjB8BNRxIvHY oAwGTnAgx1DmrcFVqoMJ15ZMkq5aAkgb/IYvceeJXPsEjuET2eNk94C6llKQIgXzKvqp /XziKNgyRRSWh9biLdEOdEpDLP+T8D3WANF55xhgkxot2b9pAv5dS4Y06XtYiAFfKG+0 k9nw== X-Gm-Message-State: AOAM533TwDsTD7rvi2n7eeTv+UNOuHARRmWrk3HYngvJOhd2fUL6+bhQ Wfl16GALd1nvozHq98/bw+OvKg== X-Google-Smtp-Source: ABdhPJwLGEYmEckqZ667EUw/B0TMmVWDvk1hOtFQNyfqaw8uDscu4OT8/LCQMoy7YMyuYD2D8agRtg== X-Received: by 2002:a63:2155:: with SMTP id s21mr740412pgm.3.1605557607664; Mon, 16 Nov 2020 12:13:27 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.13.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:13:27 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 07/11] platform/chrome: cros_ec_typec: Register cable Date: Mon, 16 Nov 2020 12:11:50 -0800 Message-Id: <20201116201150.2919178-8-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org When the Chrome Embedded Controller notifies the driver that SOP' discovery is complete, retrieve the PD discovery data and register a cable object with the Type C connector class framework. Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reviewed-by: Greg Kroah-Hartman Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 67 +++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 3c8ff07c8803..5e7f0b4ebbec 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -44,8 +44,11 @@ struct cros_typec_port { /* Initial capabilities for the port. */ struct typec_capability caps; struct typec_partner *partner; + struct typec_cable *cable; /* Port partner PD identity info. */ struct usb_pd_identity p_identity; + /* Port cable PD identity info. */ + struct usb_pd_identity c_identity; struct typec_switch *ori_sw; struct typec_mux *mux; struct usb_role_switch *role_sw; @@ -59,6 +62,7 @@ struct cros_typec_port { /* Flag indicating that PD partner discovery data parsing is completed. */ bool sop_disc_done; + bool sop_prime_disc_done; struct ec_response_typec_discovery *disc_data; struct list_head partner_mode_list; }; @@ -213,6 +217,17 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec, port->sop_disc_done = false; } +static void cros_typec_remove_cable(struct cros_typec_data *typec, + int port_num) +{ + struct cros_typec_port *port = typec->ports[port_num]; + + typec_unregister_cable(port->cable); + port->cable = NULL; + memset(&port->c_identity, 0, sizeof(port->c_identity)); + port->sop_prime_disc_done = false; +} + static void cros_unregister_ports(struct cros_typec_data *typec) { int i; @@ -224,6 +239,9 @@ static void cros_unregister_ports(struct cros_typec_data *typec) if (typec->ports[i]->partner) cros_typec_remove_partner(typec, i); + if (typec->ports[i]->cable) + cros_typec_remove_cable(typec, i); + usb_role_switch_put(typec->ports[i]->role_sw); typec_switch_put(typec->ports[i]->ori_sw); typec_mux_put(typec->ports[i]->mux); @@ -600,6 +618,9 @@ static void cros_typec_set_port_params_v1(struct cros_typec_data *typec, if (!typec->ports[port_num]->partner) return; cros_typec_remove_partner(typec, port_num); + + if (typec->ports[port_num]->cable) + cros_typec_remove_cable(typec, port_num); } } @@ -679,6 +700,43 @@ static void cros_typec_parse_pd_identity(struct usb_pd_identity *id, id->vdo[i - 3] = disc->discovery_vdo[i]; } +static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int port_num) +{ + struct cros_typec_port *port = typec->ports[port_num]; + struct ec_response_typec_discovery *disc = port->disc_data; + struct typec_cable_desc desc = {}; + struct ec_params_typec_discovery req = { + .port = port_num, + .partner_type = TYPEC_PARTNER_SOP_PRIME, + }; + int ret = 0; + + memset(disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE); + ret = cros_typec_ec_command(typec, 0, EC_CMD_TYPEC_DISCOVERY, &req, sizeof(req), + disc, EC_PROTO2_MAX_RESPONSE_SIZE); + if (ret < 0) { + dev_err(typec->dev, "Failed to get SOP' discovery data for port: %d\n", port_num); + goto sop_prime_disc_exit; + } + + /* Parse the PD identity data, even if only 0s were returned. */ + cros_typec_parse_pd_identity(&port->c_identity, disc); + + if (disc->identity_count != 0) + desc.active = PD_IDH_PTYPE(port->c_identity.id_header) == IDH_PTYPE_ACABLE; + + desc.identity = &port->c_identity; + + port->cable = typec_register_cable(port->port, &desc); + if (IS_ERR(port->cable)) { + ret = PTR_ERR(port->cable); + port->cable = NULL; + } + +sop_prime_disc_exit: + return ret; +} + static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_num) { struct cros_typec_port *port = typec->ports[port_num]; @@ -746,6 +804,15 @@ static void cros_typec_handle_status(struct cros_typec_data *typec, int port_num else typec->ports[port_num]->sop_disc_done = true; } + + if (resp.events & PD_STATUS_EVENT_SOP_PRIME_DISC_DONE && + !typec->ports[port_num]->sop_prime_disc_done) { + ret = cros_typec_handle_sop_prime_disc(typec, port_num); + if (ret < 0) + dev_err(typec->dev, "Couldn't parse SOP' Disc data, port: %d\n", port_num); + else + typec->ports[port_num]->sop_prime_disc_done = true; + } } static int cros_typec_port_update(struct cros_typec_data *typec, int port_num) From patchwork Mon Nov 16 20:11:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910733 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 90EA715E6 for ; Mon, 16 Nov 2020 20:14:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67995222E8 for ; Mon, 16 Nov 2020 20:14:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KY0R+QOs" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731910AbgKPUNl (ORCPT ); Mon, 16 Nov 2020 15:13:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728944AbgKPUNl (ORCPT ); Mon, 16 Nov 2020 15:13:41 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 840E7C0613CF for ; Mon, 16 Nov 2020 12:13:41 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id 10so15215158pfp.5 for ; Mon, 16 Nov 2020 12:13:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cFs/450EOXSyFQGw0igAIis8gqnsSIn7PCkr4KqQMGo=; b=KY0R+QOsVfDpOLEeAT02x+Rn5QMZgXtGFY6ju46zCjJy1oGTXwH0wDCbRx/FRL/Gb/ b3Nkro3pogM6DJKQfNiKCpx6IY9zniAasFrFz/WXQLFu4h9KwuVwS52BwbH0Ck70rpey +u3MHd29St1gQZjpwb2pRbKnZpSO+BVSkMmtE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cFs/450EOXSyFQGw0igAIis8gqnsSIn7PCkr4KqQMGo=; b=o9CGjM7mUDygLeQRQnwBVKOzsyrBMgh9zyoYQ9VXFLv7wsX244SQBqEa1LZ7Ae0oUp a47VGCFFShjCOprYJnvCgsOxHlM9hfC4ZlT7KeVNU72jiw6qh1arZ9nQEA0/4MWq/QRb N/HDPHHgaHIsO/MtxMbsdNBKFpvfEdQX6KwdO9n0U3WeUtqUsHrlOysoogZ9rhctT0i6 8KYL8l5CyfxshwiKCtXPoZs1Vd2skRhBV7kndsrqHNFJcmOwh8wGRNh58qfDVZ5ArAjv vq+vT9B3RcBUE3YdW0TwuZdd03yBs+ySLwQ9zRPrcp8W4GMEfBuuZMcxca/R2bdoiola CaAw== X-Gm-Message-State: AOAM533i3MsItZ/evmy7hJLpnT6/M2ScsINJ9uUInbDO+CTJ0jzAkDXk aHzE+Ubn0V8cGFctZB+a6VZJJQ== X-Google-Smtp-Source: ABdhPJwLjVBFNCqymR9CCTS5I//EF5IZtI6bDa/COj1kNfSLyJQ5TJFbF66poMkZOrQ9CCpqcqjVTg== X-Received: by 2002:a62:445:0:b029:196:61fc:2756 with SMTP id 66-20020a6204450000b029019661fc2756mr4941288pfe.12.1605557621119; Mon, 16 Nov 2020 12:13:41 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.13.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:13:40 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 08/11] platform/chrome: cros_ec_typec: Store cable plug type Date: Mon, 16 Nov 2020 12:11:52 -0800 Message-Id: <20201116201150.2919178-9-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Use the PD VDO Type C cable plug type macro to retrieve and store the cable plug type in the cable descriptor. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Signed-off-by: Prashant Malani Reviewed-by: Greg Kroah-Hartman Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - No changes. drivers/platform/chrome/cros_ec_typec.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 5e7f0b4ebbec..cf609aa10567 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -709,6 +709,7 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p .port = port_num, .partner_type = TYPEC_PARTNER_SOP_PRIME, }; + u32 cable_plug_type; int ret = 0; memset(disc, 0, EC_PROTO2_MAX_RESPONSE_SIZE); @@ -722,8 +723,26 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p /* Parse the PD identity data, even if only 0s were returned. */ cros_typec_parse_pd_identity(&port->c_identity, disc); - if (disc->identity_count != 0) + if (disc->identity_count != 0) { + cable_plug_type = VDO_TYPEC_CABLE_TYPE(port->c_identity.vdo[0]); + switch (cable_plug_type) { + case CABLE_ATYPE: + desc.type = USB_PLUG_TYPE_A; + break; + case CABLE_BTYPE: + desc.type = USB_PLUG_TYPE_B; + break; + case CABLE_CTYPE: + desc.type = USB_PLUG_TYPE_C; + break; + case CABLE_CAPTIVE: + desc.type = USB_PLUG_CAPTIVE; + break; + default: + desc.type = USB_PLUG_NONE; + } desc.active = PD_IDH_PTYPE(port->c_identity.id_header) == IDH_PTYPE_ACABLE; + } desc.identity = &port->c_identity; From patchwork Mon Nov 16 20:11:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910735 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1D43316C1 for ; Mon, 16 Nov 2020 20:14:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A68B4217A0 for ; Mon, 16 Nov 2020 20:14:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="Bz5i1nkX" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731962AbgKPUN7 (ORCPT ); Mon, 16 Nov 2020 15:13:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731898AbgKPUN7 (ORCPT ); Mon, 16 Nov 2020 15:13:59 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 41222C0613CF for ; Mon, 16 Nov 2020 12:13:59 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id y7so15179373pfq.11 for ; Mon, 16 Nov 2020 12:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ratfCf17pWeTifPqw6qz8fSuUGcC46Cued5E0TpKD5Y=; b=Bz5i1nkX8TACC+DpQ312MjVtRNrtax07fBV6j/LqGABPtchYR8h9ZDA5zg3XtkSb9s 4IKtbpUltiM260HRu9PGELfP094Vz/HHk0q9vJXtypx8Zuf+OMh+qdad05MV4g2o5hj6 xkLTU3KSIZ6BGckfHMRjlnG+CTTiHns6EE3gM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ratfCf17pWeTifPqw6qz8fSuUGcC46Cued5E0TpKD5Y=; b=R4vkA8uBs5qS6tGvEvnb6AvOsvusZpzh5ultI7SURl44dJ8EvJ30kkgrYTVqqy+oxS ieVOL+u9DA9wiH0D+fbvEp9iMHOnyMEYx49VvMTvE0zPurgQGCiCtIS1SfmdJsWjG9sA OwU2PpphMxmlVSsrF9FD0s0zC62IH/+0jSo5lGxUvq710uhwI2zb31M8QstHXF0uhVde Wm49XbRASrT4KPBVQ0hXU4FNfv2i2i78D0tml5cCN61+Rpv9NE9+rbOl14AaoNzMx85d OYmIMPqGJAKfRfZOHB9w9KCOTlGBaFXJx/6kQL0P0Cqk0EYAwIuMK0k4DUil0OLK28GY OGJQ== X-Gm-Message-State: AOAM531n/1aYk+D0jW4Qypo655fNoB7jfai9XZf4HoW7oilTQkAD5ZIk z8uAB/2vpHBSXxjuWgLn7XYCKA== X-Google-Smtp-Source: ABdhPJw4CO5OhekTUdu47fZ2cmK8miC8tEAVY5AR1ERw8bdRUUPvqU2+pTmJDArG3RD6XiIpCKlamQ== X-Received: by 2002:a63:fd0b:: with SMTP id d11mr750236pgh.50.1605557638811; Mon, 16 Nov 2020 12:13:58 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:13:58 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 09/11] platform/chrome: cros_ec_typec: Set partner num_altmodes Date: Mon, 16 Nov 2020 12:11:54 -0800 Message-Id: <20201116201150.2919178-10-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Set the number of altmodes available for a registered partner using the Type C connector class framework routine. Cc: Heikki Krogerus Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. - Added Reviewed-by tags Changes in v2: - Patch introduced for the first time in v2. drivers/platform/chrome/cros_ec_typec.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index cf609aa10567..ad5e37bfd45d 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -642,6 +642,7 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ struct cros_typec_altmode_node *node; struct typec_altmode_desc desc; struct typec_altmode *amode; + int num_altmodes = 0; int ret = 0; int i, j; @@ -668,9 +669,16 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ node->amode = amode; list_add_tail(&node->list, &port->partner_mode_list); + num_altmodes++; } } + ret = typec_partner_set_num_altmodes(port->partner, num_altmodes); + if (ret < 0) { + dev_err(typec->dev, "Unable to set partner num_altmodes for port: %d\n", port_num); + goto err_cleanup; + } + return 0; err_cleanup: From patchwork Mon Nov 16 20:11:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910737 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E9E615E6 for ; Mon, 16 Nov 2020 20:15:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D426217A0 for ; Mon, 16 Nov 2020 20:15:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="G0fda/1l" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732062AbgKPUOk (ORCPT ); Mon, 16 Nov 2020 15:14:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726299AbgKPUOj (ORCPT ); Mon, 16 Nov 2020 15:14:39 -0500 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F986C0613CF for ; Mon, 16 Nov 2020 12:14:38 -0800 (PST) Received: by mail-pf1-x441.google.com with SMTP id 10so15217792pfp.5 for ; Mon, 16 Nov 2020 12:14:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lkeW7kPlf1ZJfdTSvhZEdTM2alKEpZYKM6J6Duyeiqs=; b=G0fda/1l3vepLRgMrXn4mch8EcJ0mX5Dze/zlKrH5DG0q6a+c/RqkNhhYwcBzFALi+ hw7A01l/r9XQ97Amocua3nNwt9wwTPlUEk+Vl2AO/JLQO9WMQFr9O39wt93DkBOvlolV 2Xuoy0o4h0reg7VTA6kXhU7A9BKxdD26nTmIU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lkeW7kPlf1ZJfdTSvhZEdTM2alKEpZYKM6J6Duyeiqs=; b=IJx2DaMzNo0RXa5z6ZtrpyuwZYhBQ6SuiLRejQwajxs3LAxHq4k84qDcX5Gc5Oeh1b TZIpE2B4oXRFep3cZleuJZYSbNYPXCEM0+5Hwui7r4b9mE669clb/B5MoKOcvyG/VpG8 8bfa1TrH7OtVzHitGVlGikPaIH5raW2JlVoQSKCANeN8PrjWpAw59G0iErS9VRMArAuo 00NsrwJIer9kmU7lBcq19Y5xUf1/HI1bw7noK5ARD3qyS5BhgzvXZFOkUhZvO265WIXw r3iM2D8XU8ZZBLj2lKK0HuJ9vtG3pVyOS1TAcEHj/Z2WKLp8l3SAoWulxiYk2EFCfYeq pdtw== X-Gm-Message-State: AOAM531mxLkQ9OCEcPgkkIBopFBfM0SNNGelQAuEDmY3kY2LIhDSyZvV 4FQ76HHRbX5bjsbdZ1FpGLa/d8q3ndmMdw== X-Google-Smtp-Source: ABdhPJyBUYAv0LeYlNPttfY6zlgdK/h8V3kY6Q7TgNcf9A2mST28n0XqbVwvx8vqeqw4pXCRo6CuHw== X-Received: by 2002:a17:90b:1490:: with SMTP id js16mr592093pjb.215.1605557678027; Mon, 16 Nov 2020 12:14:38 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.14.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:14:37 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 10/11] platform/chrome: cros_ec_typec: Register SOP' cable plug Date: Mon, 16 Nov 2020 12:11:56 -0800 Message-Id: <20201116201150.2919178-11-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In order to register cable alternate modes, we need to first register a plug object. Use the Type C connector class framework to register a SOP' plug for this purpose. Since a cable and plug go hand in hand, we can handle the registration and removal together. Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. No version v2. drivers/platform/chrome/cros_ec_typec.c | 35 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index ad5e37bfd45d..d2e154ae2362 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -45,6 +45,8 @@ struct cros_typec_port { struct typec_capability caps; struct typec_partner *partner; struct typec_cable *cable; + /* SOP' plug. */ + struct typec_plug *plug; /* Port partner PD identity info. */ struct usb_pd_identity p_identity; /* Port cable PD identity info. */ @@ -222,6 +224,8 @@ static void cros_typec_remove_cable(struct cros_typec_data *typec, { struct cros_typec_port *port = typec->ports[port_num]; + typec_unregister_plug(port->plug); + port->plug = NULL; typec_unregister_cable(port->cable); port->cable = NULL; memset(&port->c_identity, 0, sizeof(port->c_identity)); @@ -712,7 +716,8 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p { struct cros_typec_port *port = typec->ports[port_num]; struct ec_response_typec_discovery *disc = port->disc_data; - struct typec_cable_desc desc = {}; + struct typec_cable_desc c_desc = {}; + struct typec_plug_desc p_desc; struct ec_params_typec_discovery req = { .port = port_num, .partner_type = TYPEC_PARTNER_SOP_PRIME, @@ -735,32 +740,44 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p cable_plug_type = VDO_TYPEC_CABLE_TYPE(port->c_identity.vdo[0]); switch (cable_plug_type) { case CABLE_ATYPE: - desc.type = USB_PLUG_TYPE_A; + c_desc.type = USB_PLUG_TYPE_A; break; case CABLE_BTYPE: - desc.type = USB_PLUG_TYPE_B; + c_desc.type = USB_PLUG_TYPE_B; break; case CABLE_CTYPE: - desc.type = USB_PLUG_TYPE_C; + c_desc.type = USB_PLUG_TYPE_C; break; case CABLE_CAPTIVE: - desc.type = USB_PLUG_CAPTIVE; + c_desc.type = USB_PLUG_CAPTIVE; break; default: - desc.type = USB_PLUG_NONE; + c_desc.type = USB_PLUG_NONE; } - desc.active = PD_IDH_PTYPE(port->c_identity.id_header) == IDH_PTYPE_ACABLE; + c_desc.active = PD_IDH_PTYPE(port->c_identity.id_header) == IDH_PTYPE_ACABLE; } - desc.identity = &port->c_identity; + c_desc.identity = &port->c_identity; - port->cable = typec_register_cable(port->port, &desc); + port->cable = typec_register_cable(port->port, &c_desc); if (IS_ERR(port->cable)) { ret = PTR_ERR(port->cable); port->cable = NULL; + goto sop_prime_disc_exit; + } + + p_desc.index = TYPEC_PLUG_SOP_P; + port->plug = typec_register_plug(port->cable, &p_desc); + if (IS_ERR(port->plug)) { + ret = PTR_ERR(port->plug); + port->plug = NULL; + goto sop_prime_disc_exit; } + return 0; + sop_prime_disc_exit: + cros_typec_remove_cable(typec, port_num); return ret; } From patchwork Mon Nov 16 20:11:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 11910739 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 89B3C1391 for ; Mon, 16 Nov 2020 20:15:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6A5F5217A0 for ; Mon, 16 Nov 2020 20:15:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="cQYjoqQx" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732088AbgKPUOr (ORCPT ); Mon, 16 Nov 2020 15:14:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729225AbgKPUOr (ORCPT ); Mon, 16 Nov 2020 15:14:47 -0500 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79505C0613CF for ; Mon, 16 Nov 2020 12:14:47 -0800 (PST) Received: by mail-pg1-x542.google.com with SMTP id v21so1476957pgi.2 for ; Mon, 16 Nov 2020 12:14:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hsW48GZXWWHJHv9tGptpE4PtcEa1mg4qhIRMZyTuOLo=; b=cQYjoqQxQQLR5+pU3IDgXaENnQbouI7k9Vr1T9Snn6OobiwxSkkpNJQx72sHwhOnQ7 joUjDPG5FerMCcf0nscd3kYc8PqxYouvi84JmLgQ8lRLPMmwqJ0UMy2cAgqqb9/mNdhW JlEjyKBp8zk6xQ5zewHO7lIiUGvjraRaLxtJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hsW48GZXWWHJHv9tGptpE4PtcEa1mg4qhIRMZyTuOLo=; b=IVBR2JsApuerxwR9RkN8cwCbitbdfx9En6D/JOmvQCCceBLNHrvTFuIamL/pR9NB5Q pK8rvRArnf3SxNe2FN/5IH2vNRZklgAEeknuOeByXba5Q3eGyTZ4qDZM0t5oex3IgM31 WKVdAy/M9u5IzHCqOHwwJv0yFg6NGm2afvFx8TzIbSGXa4pstKgFUGloiIP2YhvM5Wfd g32pPPsigptX422+s+/NaQL63DdLSwaonJXjB00NVKAvdqTT497aOuDUmFAzuZIkP8OI hfkWG79mthXp262f4SWL+FnM4TuzUHeUvBYcUwuEor+DwrynWcPFwgw4uF3rnThb5nrA Tb2A== X-Gm-Message-State: AOAM5330bQ8DCyAzzfTa7KL3cHnDVge9G8SSiKXT74+ioj0FPVfOxfep SGFzV4XAoK2y6kX+20Akd0/OYA== X-Google-Smtp-Source: ABdhPJxKErvKZ+SwEAZlFuX0HP+OIap0RxuHTj3C37PMdqqnuKQopNWYSlAHDUI2lZDQahDFV2aC6Q== X-Received: by 2002:a62:f94d:0:b029:15c:f1a3:cd47 with SMTP id g13-20020a62f94d0000b029015cf1a3cd47mr15230109pfm.81.1605557687061; Mon, 16 Nov 2020 12:14:47 -0800 (PST) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:a28c:fdff:fef0:49dd]) by smtp.gmail.com with ESMTPSA id a12sm234577pjh.48.2020.11.16.12.14.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Nov 2020 12:14:46 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, gregkh@linuxfoundation.org, heikki.krogerus@linux.intel.com, enric.balletbo@collabora.com Cc: Prashant Malani , Benson Leung , Guenter Roeck Subject: [PATCH v3 11/11] platform/chrome: cros_ec_typec: Register plug altmodes Date: Mon, 16 Nov 2020 12:11:58 -0800 Message-Id: <20201116201150.2919178-12-pmalani@chromium.org> X-Mailer: git-send-email 2.29.2.299.gdc1121823c-goog In-Reply-To: <20201116201150.2919178-1-pmalani@chromium.org> References: <20201116201150.2919178-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Modify the altmode registration (and unregistration) code so that it can be used by both partners and plugs. Then, add code to register plug altmodes using the newly parameterized function. Also set the number of alternate modes for the plug using the associated Type C connector class function typec_plug_set_num_altmodes(). Signed-off-by: Prashant Malani Reviewed-by: Heikki Krogerus --- Changes in v3: - Re-arranged patch order and combined it with related series of patches. No version v2. drivers/platform/chrome/cros_ec_typec.c | 50 ++++++++++++++++++++----- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index d2e154ae2362..65c5d0090ccd 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -67,6 +67,7 @@ struct cros_typec_port { bool sop_prime_disc_done; struct ec_response_typec_discovery *disc_data; struct list_head partner_mode_list; + struct list_head plug_mode_list; }; /* Platform-specific data for the Chrome OS EC Type C controller. */ @@ -186,12 +187,15 @@ static int cros_typec_add_partner(struct cros_typec_data *typec, int port_num, return ret; } -static void cros_typec_unregister_altmodes(struct cros_typec_data *typec, int port_num) +static void cros_typec_unregister_altmodes(struct cros_typec_data *typec, int port_num, + bool is_partner) { struct cros_typec_port *port = typec->ports[port_num]; struct cros_typec_altmode_node *node, *tmp; + struct list_head *head; - list_for_each_entry_safe(node, tmp, &port->partner_mode_list, list) { + head = is_partner ? &port->partner_mode_list : &port->plug_mode_list; + list_for_each_entry_safe(node, tmp, head, list) { list_del(&node->list); typec_unregister_altmode(node->amode); devm_kfree(typec->dev, node); @@ -203,7 +207,7 @@ static void cros_typec_remove_partner(struct cros_typec_data *typec, { struct cros_typec_port *port = typec->ports[port_num]; - cros_typec_unregister_altmodes(typec, port_num); + cros_typec_unregister_altmodes(typec, port_num, true); port->state.alt = NULL; port->state.mode = TYPEC_STATE_USB; @@ -224,6 +228,8 @@ static void cros_typec_remove_cable(struct cros_typec_data *typec, { struct cros_typec_port *port = typec->ports[port_num]; + cros_typec_unregister_altmodes(typec, port_num, false); + typec_unregister_plug(port->plug); port->plug = NULL; typec_unregister_cable(port->cable); @@ -352,6 +358,7 @@ static int cros_typec_init_ports(struct cros_typec_data *typec) } INIT_LIST_HEAD(&cros_port->partner_mode_list); + INIT_LIST_HEAD(&cros_port->plug_mode_list); } return 0; @@ -639,7 +646,11 @@ static int cros_typec_get_mux_info(struct cros_typec_data *typec, int port_num, sizeof(req), resp, sizeof(*resp)); } -static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_num) +/* + * Helper function to register partner/plug altmodes. + */ +static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_num, + bool is_partner) { struct cros_typec_port *port = typec->ports[port_num]; struct ec_response_typec_discovery *sop_disc = port->disc_data; @@ -657,7 +668,11 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ desc.mode = j; desc.vdo = sop_disc->svids[i].mode_vdo[j]; - amode = typec_partner_register_altmode(port->partner, &desc); + if (is_partner) + amode = typec_partner_register_altmode(port->partner, &desc); + else + amode = typec_plug_register_altmode(port->plug, &desc); + if (IS_ERR(amode)) { ret = PTR_ERR(amode); goto err_cleanup; @@ -672,21 +687,30 @@ static int cros_typec_register_altmodes(struct cros_typec_data *typec, int port_ } node->amode = amode; - list_add_tail(&node->list, &port->partner_mode_list); + + if (is_partner) + list_add_tail(&node->list, &port->partner_mode_list); + else + list_add_tail(&node->list, &port->plug_mode_list); num_altmodes++; } } - ret = typec_partner_set_num_altmodes(port->partner, num_altmodes); + if (is_partner) + ret = typec_partner_set_num_altmodes(port->partner, num_altmodes); + else + ret = typec_plug_set_num_altmodes(port->plug, num_altmodes); + if (ret < 0) { - dev_err(typec->dev, "Unable to set partner num_altmodes for port: %d\n", port_num); + dev_err(typec->dev, "Unable to set %s num_altmodes for port: %d\n", + is_partner ? "partner" : "plug", port_num); goto err_cleanup; } return 0; err_cleanup: - cros_typec_unregister_altmodes(typec, port_num); + cros_typec_unregister_altmodes(typec, port_num, is_partner); return ret; } @@ -774,6 +798,12 @@ static int cros_typec_handle_sop_prime_disc(struct cros_typec_data *typec, int p goto sop_prime_disc_exit; } + ret = cros_typec_register_altmodes(typec, port_num, false); + if (ret < 0) { + dev_err(typec->dev, "Failed to register plug altmodes, port: %d\n", port_num); + goto sop_prime_disc_exit; + } + return 0; sop_prime_disc_exit: @@ -815,7 +845,7 @@ static int cros_typec_handle_sop_disc(struct cros_typec_data *typec, int port_nu goto disc_exit; } - ret = cros_typec_register_altmodes(typec, port_num); + ret = cros_typec_register_altmodes(typec, port_num, true); if (ret < 0) { dev_err(typec->dev, "Failed to register partner altmodes, port: %d\n", port_num); goto disc_exit;