Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp764528rdb; Tue, 23 Jan 2024 14:33:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEYv5BNl2DuCFSfoaMS2V3kzif8gyrV5a4tFeYSK4o2VC1ZvwaWWC8IAB78sj8wAbLRCkgU X-Received: by 2002:a17:90a:2ec5:b0:290:1464:e994 with SMTP id h5-20020a17090a2ec500b002901464e994mr3087268pjs.46.1706049197738; Tue, 23 Jan 2024 14:33:17 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706049197; cv=pass; d=google.com; s=arc-20160816; b=Wth3Kvu5yG6bmQZUnhi9+X7yQRB09+EJQy8hTGTA+HLWspw7ev0gfcjsyYzBvi8oum JnZa7fPbCDK7cBEkg8SBZeIf0bmbM8nD+7+ZCy+UIoLSdFdZiE8dGGVoVwoQAbEzCMXk uD63DMgkRvWQTxtW+heEkExGeHRSPlLEu2VwcOHE9v+0FOn3RVNpT65xd8D9LE+xxLTw eznp1fgI+0DavGBNoyz0Z4m6et43vB1r3vEMwRUAvjxzwT3SCK0yzl/xOfLXFsSwj5tQ TYT/R5alV8Xb7NiB+Zbl4or38Wq0x+tUgSJELO2xgd0nYQxwWhZEoEt3STYjOfP0bGDT sI/A== 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=KK7B2Hpvjem/TGRGJEqxUJ5QCI/gm35D+XD8uCyWzO0=; fh=LVFxb9qmsFs6dUX7fupkBnCNUcX/LgJnUOZeJK2Yu2I=; b=bgk/U/qgiqFol9CISIMZJg2uI4Ze+8j2EY0JkZ1pbacrSPmzW6Slfdmbv1kRg2XjfM 7Beb3hs7VY//iYuLa4PanjFjR/lpZjb8sFaQWyRlK0O1K+YrmmxZrjAARpex00PDA69z 88/GVfx2XLzvqv1kh/S54XkNLnlppgfBgI4hx8zzlS8G9N+D6FMRGwRZcyq9dbFcPN2K mCNhSbDaVNuclCjUp3XK9MYFO135V0V9yaiP6ABr05FPcUHe8axwkTaxGAQUY8UqQLmK tWVQHgMLCjaEnCGLbi7hsFqjydd3++KHGhV56H+SPy7RfVTkuYmGUB7H7avdMLgVKwU6 oJwA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=TGXJzSl8; arc=pass (i=1 spf=pass spfdomain=flex--abhishekpandit.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36150-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 z12-20020a17090abd8c00b0028c86e12f01si10382002pjr.41.2024.01.23.14.33.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Jan 2024 14:33:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-36150-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=TGXJzSl8; arc=pass (i=1 spf=pass spfdomain=flex--abhishekpandit.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-36150-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-36150-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 E46AE284CF4 for ; Tue, 23 Jan 2024 22:32:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DEF2C54BCE; Tue, 23 Jan 2024 22:30:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TGXJzSl8" Received: from mail-pf1-f202.google.com (mail-pf1-f202.google.com [209.85.210.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 980AC54BD6 for ; Tue, 23 Jan 2024 22:30:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706049050; cv=none; b=CQdYUz+BnZBnvHnT2I6XtQskiRByYSRj5FSTiRClv9tO6pJWLaw3k2nV0TIxdayieDo6XUG+sal1lgIV0ckQWq0jzEArd8RWJijEYsy5XueDh3FdeRQM1wwTS/6DaTLYkEqoI0mhAL5Na5IJodqTbfaT/DOOhcXC+h+bu/26HRg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706049050; c=relaxed/simple; bh=56wzal+YXRtHQbn7T/LWphhUaXqmgxriKJa43MLSexQ=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=fYDOM5vewvV72TbsdLzQi57UwPF8AnwC1LD8I3D0RjJKmSJ+MW1aVoiFL0ldpjYz5+IPu9MCJDYDfkJ+p2ljMg1iyl9qMuNkkHK8eNODcV4A8bRvuul1pjPkFdefp/bLTbTNIcwUrijhfgPrbxGWVYCnn4F5zSboqFQMn1rtnZM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--abhishekpandit.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=TGXJzSl8; arc=none smtp.client-ip=209.85.210.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--abhishekpandit.bounces.google.com Received: by mail-pf1-f202.google.com with SMTP id d2e1a72fcca58-6dbcdfde0eeso2444837b3a.1 for ; Tue, 23 Jan 2024 14:30:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706049048; x=1706653848; 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=KK7B2Hpvjem/TGRGJEqxUJ5QCI/gm35D+XD8uCyWzO0=; b=TGXJzSl8thIqjktun7+24Jdfz3Is/4acLKMif0NBATu7HoQ2f/j3wM6vHvpw79dB6x Ndx0ev+nghQxAoRlnwmg5IELEkuVSxdies5SyA0svatxm5gTubq4Onexjg/q1bH6ueJW mifsV+oeWKk2BDsjj1JLZVE4Udn2Wd9q+VmzA+J0h3MvanCUZBeG4zCi/fCcrcNeeSWt IeJ++qFV+XDmuBI480XN7sLogNoAQ+ep3Jus7cvFEU/rKJYWFMf5S17/kAhmUDyT6U2m igjXAB63t4IhuE46sjiXhoMgfC6KAXEs2+2AvUYIPmO+IOVq8OYhDVLCozlrc9v96ReY wC4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706049048; x=1706653848; 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=KK7B2Hpvjem/TGRGJEqxUJ5QCI/gm35D+XD8uCyWzO0=; b=IaGGwbNianKrcHBkCmTlQ7vg8XV/MhWBnnmTbaY3KI2q8HJ2n0arYAb7Ng1NKelW6o 8HFbCc6Ky7yGUlaL+w4xEtz9SKH3YITVEIKtwSdPyimxQUBCUzmIP4ZPC1rG3QVuo+lI 8vjvtnUDaNvxRXtaYIJl31Vc1AH15wtMt02jlzVE84ColZepSn6vwYQLLwSiZPWJSvYw y7ZTtOxUKFoh0R5WyMfwWOPokk2DoUfvEsuho/QoPnVA2eGPNyXwcNDB7S3ZHNGn8s/L VhC9DPaSHLNPs5MNLaRP1UiVDbk4RH/uqu+AfVVqOb/2uoJcExGDcSHIjLriI+b5M8nd itAg== X-Gm-Message-State: AOJu0Yzf4zkuB3imvdOfu200pB64VMSHXVZHffAl4W8JJCzKN97ozMUZ nVnLQmkOXM7GZF1//lboKxwulBR0M7W4jlgy+NmeluCaABWoTYr3OgzsoGpwoQbLu8mUzIAZTB4 Cmw3SOOZ6T1R0oh94w25pAzIwqrsQOjHdxg== X-Received: from abps.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:9b4]) (user=abhishekpandit job=sendgmr) by 2002:a05:6a00:985:b0:6db:d97b:6c98 with SMTP id u5-20020a056a00098500b006dbd97b6c98mr617462pfg.2.1706049047859; Tue, 23 Jan 2024 14:30:47 -0800 (PST) Date: Tue, 23 Jan 2024 14:30:36 -0800 In-Reply-To: <20240123223039.1471557-1-abhishekpandit@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240123223039.1471557-1-abhishekpandit@google.com> X-Mailer: git-send-email 2.43.0.429.g432eaa2c6b-goog Message-ID: <20240123143026.v1.3.Idf7d373c3cbb54058403cb951d644f1f09973d15@changeid> Subject: [PATCH v1 3/3] usb: typec: ucsi: Get PD revision for partner From: Abhishek Pandit-Subedi To: Heikki Krogerus , linux-usb@vger.kernel.org Cc: pmalani@chromium.org, jthies@google.com, Abhishek Pandit-Subedi , Andy Shevchenko , Bjorn Andersson , Dmitry Baryshkov , Fabrice Gasnier , Greg Kroah-Hartman , Hans de Goede , Neil Armstrong , Saranya Gopal , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" From: Abhishek Pandit-Subedi PD major revision for the port partner is described in GET_CONNECTOR_CAPABILITY and is only valid on UCSI 2.0 and newer. Update the pd_revision on the partner if the UCSI version is 2.0 or newer. Signed-off-by: Abhishek Pandit-Subedi --- $ cat /sys/class/typec/port2-partner/usb_power_delivery_revision 3.0 drivers/usb/typec/ucsi/ucsi.c | 25 +++++++++++++++++++++++++ drivers/usb/typec/ucsi/ucsi.h | 3 +++ 2 files changed, 28 insertions(+) diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c index 4edf785d203b..8e0a512853ba 100644 --- a/drivers/usb/typec/ucsi/ucsi.c +++ b/drivers/usb/typec/ucsi/ucsi.c @@ -782,6 +782,8 @@ static int ucsi_register_partner(struct ucsi_connector *con) } desc.usb_pd = pwr_opmode == UCSI_CONSTAT_PWR_OPMODE_PD; + desc.pd_revision = + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags); partner = typec_register_partner(con->port, &desc); if (IS_ERR(partner)) { @@ -856,6 +858,28 @@ static void ucsi_partner_change(struct ucsi_connector *con) con->num, u_role); } +static int ucsi_check_connector_capability(struct ucsi_connector *con) +{ + u64 command; + int ret; + + if (!con->partner && !IS_MIN_VERSION_2_0(con->ucsi)) + return 0; + + command = UCSI_GET_CONNECTOR_CAPABILITY | UCSI_CONNECTOR_NUMBER(con->num); + ret = ucsi_send_command(con->ucsi, command, &con->cap, sizeof(con->cap)); + if (ret < 0) { + dev_err(con->ucsi->dev, "GET_CONNECTOR_CAPABILITY failed (%d)\n", ret); + return ret; + } + + typec_partner_set_pd_revision( + con->partner, + UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV_AS_BCD(con->cap.flags)); + + return ret; +} + static int ucsi_check_connection(struct ucsi_connector *con) { u8 prev_flags = con->status.flags; @@ -925,6 +949,7 @@ static void ucsi_handle_connector_change(struct work_struct *work) if (con->status.flags & UCSI_CONSTAT_CONNECTED) { ucsi_register_partner(con); ucsi_partner_task(con, ucsi_check_connection, 1, HZ); + ucsi_partner_task(con, ucsi_check_connector_capability, 1, HZ); if (UCSI_CONSTAT_PWR_OPMODE(con->status.flags) == UCSI_CONSTAT_PWR_OPMODE_PD) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 94b373378f63..5e60328f398e 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -36,6 +36,9 @@ struct dentry; #define UCSI_BCD_GET_MINOR(_v_) (((_v_) >> 4) & 0x0F) #define UCSI_BCD_GET_SUBMINOR(_v_) ((_v_) & 0x0F) +#define IS_MIN_VERSION(ucsi, min_ver) ((ucsi)->version >= min_ver) +#define IS_MIN_VERSION_2_0(ucsi) IS_MIN_VERSION(ucsi, UCSI_VERSION_2_0) + /* Command Status and Connector Change Indication (CCI) bits */ #define UCSI_CCI_CONNECTOR(_c_) (((_c_) & GENMASK(7, 1)) >> 1) #define UCSI_CCI_LENGTH(_c_) (((_c_) & GENMASK(15, 8)) >> 8) -- 2.43.0.429.g432eaa2c6b-goog