From nobody Mon Feb 9 08:15:24 2026 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) (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 F145A83A0C for ; Mon, 25 Mar 2024 23:37:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711409853; cv=none; b=CadcDT2PGtF3/trhuw1fY5hg0jkO0oyiTDqJkjOTxLD8VqtpBuOtD058R7n/H0IIFInvKSLIJrMicQ3+DXhdGo78Z0vpTcf0e2cDEQv0mT4FY7tZPBL+xcHHJXO31VrWdsNgJZIURCUeSWpq5RAo5TuMoC8yv+f/0GzrDPnXBVE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711409853; c=relaxed/simple; bh=SeQce1gFW0K6iI86gWi0GbaKVMdi8pBaBD+m2qO3U+o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nlXGHYpRTNnj7fybIHVX3zdGJLalq51cmHG3BxVBvZ1dp/Jobrzv27yLy+E0/xpOGpTPsRzLXxpcqZCWJJz9tboaMEquBAgYjMG0PF3GnVaW26tuH76IHnj1LKG9q1F6FhM37Hfm1pzGfQ8QnYXzoyUvS+GJOHAqKizhUakZcE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=X7r7327u; arc=none smtp.client-ip=209.85.215.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="X7r7327u" Received: by mail-pg1-f176.google.com with SMTP id 41be03b00d2f7-5ce2aada130so3478519a12.1 for ; Mon, 25 Mar 2024 16:37:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711409851; x=1712014651; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=Xjzk4UlrSrkiNY4MQm3fy1SXk2w8u62oB9H2yAhe2y4=; b=X7r7327ukCopXcNDVK5Zb4vPn01or3mfsbQJVThzsCR4RaUN16cfmGB2A+POmU/xZt efQTLa7jh7BFElW4wcvYvFiUwghSXXeu3W6TOSCYSeuCtu2edjrwobWA+2oRgZS+r+YZ ACFzjkgbpQmXQm0S9U9V5dIN2Uf/AfrBZ6unI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711409851; x=1712014651; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Xjzk4UlrSrkiNY4MQm3fy1SXk2w8u62oB9H2yAhe2y4=; b=gEy2GyuBB8HmezSGOgVF50Eh8Bb7XfcS8yaEt4+189eRIKkZ7sXLsW3SEDdor9ikF2 BeL0d1TCf6ZCFGXmAMKXB0/Ed2V3VSpreaXxtQEHRQNTe7bDGmcJoQVPE7V/5pTeEea+ BsqiVfF3gGHLXWhnf2sPcCeiBirhFSnWjwVbVMGiQ343IZ/KoUkIFK+CbBY9Qugdk4BQ Iyk+QrRi2K0TckWb1Lk4GuUxxG5pWGUcYfHfyzSJ8jaCUYbRT/OXq2yCWbIoQFD9rMy/ AKifSMpfZ67bXNp0p1hwbdFIUzfUlIm7L5DG+MMH+LWerIiZTngURH40pe02ufsWMeIP 2UUw== X-Gm-Message-State: AOJu0Ywy35wCJoA38WU2ILZ33tBLM9bmcmcpfLX7umEdOW26JscfPt4I zTwqITuggj8pRnro0WZPgeZSP8ESdwOshTy64VBHzKsC2hApApAejxJtu74btA== X-Google-Smtp-Source: AGHT+IHos6yf4HEDXfACT1evg6Afi/lraKi98CPeCOt8FPOl7GJNXA8bS1mUPTItrMx+IQRMRVEKUQ== X-Received: by 2002:a05:6a20:7491:b0:1a3:c96e:be07 with SMTP id p17-20020a056a20749100b001a3c96ebe07mr1575943pzd.61.1711409851327; Mon, 25 Mar 2024 16:37:31 -0700 (PDT) Received: from pholla1.c.googlers.com (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with ESMTPSA id c14-20020a170903234e00b001e0e2fde71fsm526533plh.9.2024.03.25.16.37.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:37:30 -0700 (PDT) From: Pavan Holla Date: Mon, 25 Mar 2024 23:37:28 +0000 Subject: [PATCH 1/3] usb: typec: ucsi: Provide interface for UCSI transport 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240325-public-ucsi-h-v1-1-7c7e888edc0a@chromium.org> References: <20240325-public-ucsi-h-v1-0-7c7e888edc0a@chromium.org> In-Reply-To: <20240325-public-ucsi-h-v1-0-7c7e888edc0a@chromium.org> To: Greg Kroah-Hartman , Heikki Krogerus Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , Pavan Holla X-Mailer: b4 0.12.4 The ucsi.h include can be used by driver implementations that provide transport for UCSI commands. Signed-off-by: Pavan Holla --- MAINTAINERS | 1 + include/linux/usb/ucsi.h | 66 ++++++++++++++++++++++++++++++++++++++++++++= ++++ 2 files changed, 67 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index aa3b947fb080..e799d67a8fa5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -22987,6 +22987,7 @@ F: Documentation/ABI/testing/sysfs-class-typec F: Documentation/driver-api/usb/typec.rst F: drivers/usb/typec/ F: include/linux/usb/typec.h +F: include/linux/usb/ucsi.h =20 USB TYPEC INTEL PMC MUX DRIVER M: Heikki Krogerus diff --git a/include/linux/usb/ucsi.h b/include/linux/usb/ucsi.h new file mode 100644 index 000000000000..3ec1db968070 --- /dev/null +++ b/include/linux/usb/ucsi.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __LINUX_USB_UCSI_H +#define __LINUX_USB_UCSI_H + +#include +#include +#include + +/* -----------------------------------------------------------------------= --- */ + +struct ucsi; +struct ucsi_altmode; + +/* UCSI offsets (Bytes) */ +#define UCSI_VERSION 0 +#define UCSI_CCI 4 +#define UCSI_CONTROL 8 +#define UCSI_MESSAGE_IN 16 +#define UCSI_MESSAGE_OUT 32 +#define UCSIv2_MESSAGE_OUT 272 + +/* 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) +#define UCSI_CCI_NOT_SUPPORTED BIT(25) +#define UCSI_CCI_CANCEL_COMPLETE BIT(26) +#define UCSI_CCI_RESET_COMPLETE BIT(27) +#define UCSI_CCI_BUSY BIT(28) +#define UCSI_CCI_ACK_COMPLETE BIT(29) +#define UCSI_CCI_ERROR BIT(30) +#define UCSI_CCI_COMMAND_COMPLETE BIT(31) + +/** + * struct ucsi_operations - UCSI I/O operations + * @read: Read operation + * @sync_write: Blocking write operation + * @async_write: Non-blocking write operation + * @update_altmodes: Squashes duplicate DP altmodes + * + * Read and write routines for UCSI interface. @sync_write must wait for t= he + * Command Completion Event from the PPM before returning, and @async_writ= e must + * return immediately after sending the data to the PPM. + */ +struct ucsi_operations { + int (*read)(struct ucsi *ucsi, unsigned int offset, + void *val, size_t val_len); + int (*sync_write)(struct ucsi *ucsi, unsigned int offset, + const void *val, size_t val_len); + int (*async_write)(struct ucsi *ucsi, unsigned int offset, + const void *val, size_t val_len); + bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, + struct ucsi_altmode *updated); +}; + +struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations = *ops); +void ucsi_destroy(struct ucsi *ucsi); +int ucsi_register(struct ucsi *ucsi); +void ucsi_unregister(struct ucsi *ucsi); +int ucsi_resume(struct ucsi *ucsi); +void *ucsi_get_drvdata(struct ucsi *ucsi); +void ucsi_set_drvdata(struct ucsi *ucsi, void *data); + +void ucsi_connector_change(struct ucsi *ucsi, u8 num); + +#endif /* __LINUX_USB_UCSI_H */ --=20 2.44.0.396.g6e790dbe36-goog From nobody Mon Feb 9 08:15:24 2026 Received: from mail-pg1-f178.google.com (mail-pg1-f178.google.com [209.85.215.178]) (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 CAC5C839E7 for ; Mon, 25 Mar 2024 23:37:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711409854; cv=none; b=RxAKgAtoMLqiahhsrzdlB7oAb33DuMxtHDa+Mj7wurXn/Hlk12w796uZuNZhn2TPeU98whfuhgLIK9RM8n87bxLDRwCcFCRMY0o/ln5bFW01L3eEWPqPpcPdaPtH1for7puwj3bUdth3u3qTbW2Np8QhejfYFtVs1ZjyO0AP2lU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711409854; c=relaxed/simple; bh=jbSJ8EoUHTJOt2gEIo2bLB7/XqaW9sPGoBPW7n04aM8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=XkV7Qb4mBV55wbSZaJ3Rpk/Z5QJ8Ijv3GNL7xtXejAgnsNbA3gDG9KuMoYz6680JnIe4fqDAGxCgzYJ1Hz+dd0ICZHHNlFUq04Hg1XnUtNVx64TDTX2J5Nczq1fyKKN2B5EWpE0R9sVlbuZdL3D6KkExbm1dH2AG8cH0zrg09TY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=aOF7QkmN; arc=none smtp.client-ip=209.85.215.178 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="aOF7QkmN" Received: by mail-pg1-f178.google.com with SMTP id 41be03b00d2f7-5e152c757a5so2429937a12.2 for ; Mon, 25 Mar 2024 16:37:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711409852; x=1712014652; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cF9ERqG1zIS6eGrOVmXcQQcR69NGZdIYHtZJEychHus=; b=aOF7QkmNW6t14gHYntnsm58y4NZ0dUTkTwhcqs0w5cAMaeeNiDM/Mznq1Y+9img/cl 9b6d7EjBgnza64JGLAZPctDBZT0xSI3gGJYNoA+ZL5cgDp28qGb/tZUCFITpEp+xpR83 AIM20S9qKAu8NxMxLcbBgWzfOv7Y/0cvutPJQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711409852; x=1712014652; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cF9ERqG1zIS6eGrOVmXcQQcR69NGZdIYHtZJEychHus=; b=i7ijpbLXviUxOVbpXHxhpI2XYHrz+RNqtq/lHIYn3JKxPp0JLrpYs0liD+V1ORRrIU ZFfO31t2VbNbC24633VWld27V9HmU7Z7Fi5tulCbrRv6bWvFRtINdn4DaJ1NyDIOF2Ln lRxoDYg7qDZhI3DTIr93804OD9+/e2/lvgh31l2Lt/SDEPgtBTaR3sQAiMGsw1pGxTX7 7zUANHo6zPt06flY4sNMopfRyT/zAFMPdDO+cLzq0yUSf0zvIh5Ntxgv/BLjIVBO29Xu fC2IRV1ED2M9XJ7QTO1brcU8CCybBmVCg2jfugtI2+nAuB4r1CBtRmuj+sItDwJBmZDD mWiw== X-Gm-Message-State: AOJu0Yw2uQTC9lebKvsuaCeCQ/CE6WQ8yqI9zAV4MruppX3XfM7cU7VC mt3W+Jx4WDqu7rJo0lW+XCye6WgtDPzy/a0KYoeTPtWlOpXr+NC+ci8YnJheow== X-Google-Smtp-Source: AGHT+IFIknFZn12Y5kpDi6r+Yb6x3aRSrS6kXCzpnuoO03KZTCATHzV6Cdtk53AQr1VeQ0uVLJ+uWA== X-Received: by 2002:a17:902:d2cc:b0:1e0:cd89:752d with SMTP id n12-20020a170902d2cc00b001e0cd89752dmr3079566plc.39.1711409852098; Mon, 25 Mar 2024 16:37:32 -0700 (PDT) Received: from pholla1.c.googlers.com (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with ESMTPSA id c14-20020a170903234e00b001e0e2fde71fsm526533plh.9.2024.03.25.16.37.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:37:31 -0700 (PDT) From: Pavan Holla Date: Mon, 25 Mar 2024 23:37:29 +0000 Subject: [PATCH 2/3] usb: typec: ucsi: Import interface for UCSI transport 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240325-public-ucsi-h-v1-2-7c7e888edc0a@chromium.org> References: <20240325-public-ucsi-h-v1-0-7c7e888edc0a@chromium.org> In-Reply-To: <20240325-public-ucsi-h-v1-0-7c7e888edc0a@chromium.org> To: Greg Kroah-Hartman , Heikki Krogerus Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , Pavan Holla X-Mailer: b4 0.12.4 Import include/linux/usb/ucsi.h and remove any duplicate declarations. Signed-off-by: Pavan Holla --- drivers/usb/typec/ucsi/ucsi.h | 54 +--------------------------------------= ---- 1 file changed, 1 insertion(+), 53 deletions(-) diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h index 32daf5f58650..167951538030 100644 --- a/drivers/usb/typec/ucsi/ucsi.h +++ b/drivers/usb/typec/ucsi/ucsi.h @@ -10,22 +10,13 @@ #include #include #include +#include #include =20 /* -----------------------------------------------------------------------= --- */ =20 -struct ucsi; -struct ucsi_altmode; struct dentry; =20 -/* UCSI offsets (Bytes) */ -#define UCSI_VERSION 0 -#define UCSI_CCI 4 -#define UCSI_CONTROL 8 -#define UCSI_MESSAGE_IN 16 -#define UCSI_MESSAGE_OUT 32 -#define UCSIv2_MESSAGE_OUT 272 - /* UCSI versions */ #define UCSI_VERSION_1_2 0x0120 #define UCSI_VERSION_2_0 0x0200 @@ -42,48 +33,6 @@ struct dentry; */ #define UCSI_SPEC_REVISION_TO_BCD(_v_) (((_v_) + 1) << 8) =20 -/* 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) -#define UCSI_CCI_NOT_SUPPORTED BIT(25) -#define UCSI_CCI_CANCEL_COMPLETE BIT(26) -#define UCSI_CCI_RESET_COMPLETE BIT(27) -#define UCSI_CCI_BUSY BIT(28) -#define UCSI_CCI_ACK_COMPLETE BIT(29) -#define UCSI_CCI_ERROR BIT(30) -#define UCSI_CCI_COMMAND_COMPLETE BIT(31) - -/** - * struct ucsi_operations - UCSI I/O operations - * @read: Read operation - * @sync_write: Blocking write operation - * @async_write: Non-blocking write operation - * @update_altmodes: Squashes duplicate DP altmodes - * - * Read and write routines for UCSI interface. @sync_write must wait for t= he - * Command Completion Event from the PPM before returning, and @async_writ= e must - * return immediately after sending the data to the PPM. - */ -struct ucsi_operations { - int (*read)(struct ucsi *ucsi, unsigned int offset, - void *val, size_t val_len); - int (*sync_write)(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len); - int (*async_write)(struct ucsi *ucsi, unsigned int offset, - const void *val, size_t val_len); - bool (*update_altmodes)(struct ucsi *ucsi, struct ucsi_altmode *orig, - struct ucsi_altmode *updated); -}; - -struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations = *ops); -void ucsi_destroy(struct ucsi *ucsi); -int ucsi_register(struct ucsi *ucsi); -void ucsi_unregister(struct ucsi *ucsi); -void *ucsi_get_drvdata(struct ucsi *ucsi); -void ucsi_set_drvdata(struct ucsi *ucsi, void *data); - -void ucsi_connector_change(struct ucsi *ucsi, u8 num); - /* -----------------------------------------------------------------------= --- */ =20 /* Commands */ @@ -465,7 +414,6 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, void *retval, size_t size); =20 void ucsi_altmode_update_active(struct ucsi_connector *con); -int ucsi_resume(struct ucsi *ucsi); =20 #if IS_ENABLED(CONFIG_POWER_SUPPLY) int ucsi_register_port_psy(struct ucsi_connector *con); --=20 2.44.0.396.g6e790dbe36-goog From nobody Mon Feb 9 08:15:24 2026 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) (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 9F8895B5DD for ; Mon, 25 Mar 2024 23:37:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711409855; cv=none; b=DyT2faPz5C4UWNE4jQL/v3DfP0e1AQFYgdi2XEYidXeiqJ6a9hwZg58WUm+RMByMB8jF8PJxjnAwGJtWkWnHcfJmueFOsKC+bAvOoNLEeawT/+DYlUCMjwqeRrm+78k93sHZoku+au/Hq4xMYt8aLurgSqFZ7Hhcj9iCVojX/u0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711409855; c=relaxed/simple; bh=fsjkodhL8grV1QBLXNjixrtYC9NfJF+MMKlB8IzvKL4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=thg9X6nrIZ3qUmkPQhvnVnZZavu/EKPil9ilEZWIc5I+Xh9t4SmS6smrFWcKmeCJPObqloMoQBAIwD0t3kaJMwaI8BFSrRys4RXtyncOPXNFrSvpWPbzDkk/19JcwhuqT+ZWvR/89r62TVIIJ9A+B5q5knVeJ99eS8z+PTRvaEQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org; spf=pass smtp.mailfrom=chromium.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b=m8DVe7LG; arc=none smtp.client-ip=209.85.214.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=chromium.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="m8DVe7LG" Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-1dee5daa236so36432335ad.0 for ; Mon, 25 Mar 2024 16:37:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711409853; x=1712014653; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=8ca/Lt827hCMDYh5dE02lZPJJvXokhyEjRY2l8MfDd8=; b=m8DVe7LGiDkeJ1E63JSE5J4+pFOWLubczw2JwKPAgdenudXRagsNZJn7BkBEexNOVl NHXbAiUq9+Dj6w3GjQdLdnpwO7sDhOse/o+c9RuyUp5MjrPGRUphinUCqlKIpuUkx3Bx NMXcysqWMYDLZqPuMTklDvmI8I1Z2tVM3JX/Y= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711409853; x=1712014653; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8ca/Lt827hCMDYh5dE02lZPJJvXokhyEjRY2l8MfDd8=; b=PpCu8PAMhQoEvRMy3zNCSOapfwA3cqRVE4P2gGo809rfdzC/avghlIVJ8T4alyVHGQ dMcqLK31QH5QEvZBNF16LULSnuM6k1r0VCAx8v8eSlrZEYG2/NeF2PqL72OrUUdDWaCK ZY3lOClIg4jUD/9Hq2EeMfUuAqxcwuUY1NqSShYFPN8MsDqnnNbHyglMndTfXh3MUXPo gRnNBBBe5V8WgntyqI/bE4KsqAfBf2hj+tQAlydSwSi58Dg+UmtzeEmAoRLCTROHAy3z vk7O9fcPXC/xAWBoGc6zroZyCkUrMl1iCKI75ItGzr6849bwb5ot3XK1bDC6AyGlI1fS M4Fw== X-Gm-Message-State: AOJu0Yxk4h9wIDUD9fp3lMby6UZAoS0+4m5tWS0W8B+FKhWucvtZqsqk KV+thPji8+VEcYqjruvr+fGz9K/3327JFQ8K1x++0JTORdwhk7Rgu3KVCaA5sA== X-Google-Smtp-Source: AGHT+IFnJl6qjFmX9WZ3KeYDZtbolk+5wf36SUlZwdNoAbfHuV/X+Hz5oY5Wk0k6WeTdFPuA0mcoAA== X-Received: by 2002:a17:903:32d0:b0:1e0:ac80:5709 with SMTP id i16-20020a17090332d000b001e0ac805709mr10039412plr.48.1711409852808; Mon, 25 Mar 2024 16:37:32 -0700 (PDT) Received: from pholla1.c.googlers.com (210.73.125.34.bc.googleusercontent.com. [34.125.73.210]) by smtp.gmail.com with ESMTPSA id c14-20020a170903234e00b001e0e2fde71fsm526533plh.9.2024.03.25.16.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:37:32 -0700 (PDT) From: Pavan Holla Date: Mon, 25 Mar 2024 23:37:30 +0000 Subject: [PATCH 3/3] platform/chrome: cros_ec_ucsi: Implement UCSI PDC driver 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="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20240325-public-ucsi-h-v1-3-7c7e888edc0a@chromium.org> References: <20240325-public-ucsi-h-v1-0-7c7e888edc0a@chromium.org> In-Reply-To: <20240325-public-ucsi-h-v1-0-7c7e888edc0a@chromium.org> To: Greg Kroah-Hartman , Heikki Krogerus Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , Pavan Holla X-Mailer: b4 0.12.4 Implementation of transport driver for UCSI. This driver will be used if the ChromeOS EC implements a PPM. Signed-off-by: Pavan Holla --- drivers/platform/chrome/Kconfig | 14 ++ drivers/platform/chrome/Makefile | 1 + drivers/platform/chrome/cros_ec_ucsi.c | 247 +++++++++++++++++++++= ++++ include/linux/platform_data/cros_ec_commands.h | 19 ++ 4 files changed, 281 insertions(+) diff --git a/drivers/platform/chrome/Kconfig b/drivers/platform/chrome/Kcon= fig index 7a83346bfa53..67ab79a6815b 100644 --- a/drivers/platform/chrome/Kconfig +++ b/drivers/platform/chrome/Kconfig @@ -238,6 +238,20 @@ config CROS_EC_TYPEC To compile this driver as a module, choose M here: the module will be called cros-ec-typec. =20 +config CROS_EC_UCSI + tristate "UCSI Driver for ChromeOS EC" + depends on MFD_CROS_EC_DEV + depends on CROS_USBPD_NOTIFY + depends on TYPEC_UCSI + depends on !EXTCON_TCSS_CROS_EC + default MFD_CROS_EC_DEV + help + This driver enables UCSI support for a ChromeOS EC. The EC is + expected to implement a PPM. + + To compile the driver as a module, choose M here: the module + will be called cros_ec_ucsi. + config CROS_HPS_I2C tristate "ChromeOS HPS device" depends on HID && I2C && PM diff --git a/drivers/platform/chrome/Makefile b/drivers/platform/chrome/Mak= efile index 2dcc6ccc2302..85964e165a70 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_CROS_EC_UART) +=3D cros_ec_uart.o cros_ec_lpcs-objs :=3D cros_ec_lpc.o cros_ec_lpc_mec.o cros-ec-typec-objs :=3D cros_ec_typec.o cros_typec_vdm.o obj-$(CONFIG_CROS_EC_TYPEC) +=3D cros-ec-typec.o +obj-$(CONFIG_CROS_EC_UCSI) +=3D cros_ec_ucsi.o obj-$(CONFIG_CROS_EC_LPC) +=3D cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) +=3D cros_ec_proto.o cros_ec_trace.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) +=3D cros_kbd_led_backlight.o diff --git a/drivers/platform/chrome/cros_ec_ucsi.c b/drivers/platform/chro= me/cros_ec_ucsi.c new file mode 100644 index 000000000000..9fee300a3d93 --- /dev/null +++ b/drivers/platform/chrome/cros_ec_ucsi.c @@ -0,0 +1,247 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * UCSI driver for ChromeOS EC + * + * Copyright 2024 Google LLC. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DRV_NAME "cros-ec-ucsi" + +#define MAX_EC_DATA_SIZE 256 +#define WRITE_TMO_MS 500 + +#define COMMAND_PENDING 1 +#define ACK_PENDING 2 + +#define UCSI_COMMAND(_cmd_) ((_cmd_) & 0xff) +#define UCSI_ACK_CC_CI 0x04 + +struct cros_ucsi_data { + struct device *dev; + struct ucsi *ucsi; + + struct cros_ec_device *ec; + struct notifier_block nb; + struct work_struct work; + + struct completion complete; + unsigned long flags; +}; + +static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *va= l, + size_t val_len) +{ + struct cros_ucsi_data *udata =3D ucsi_get_drvdata(ucsi); + struct ec_params_ucsi_ppm_get req =3D { + .offset =3D offset, + .size =3D val_len, + }; + int ret; + + if (val_len > MAX_EC_DATA_SIZE) { + dev_err(udata->dev, "Can't read %zu bytes. Too big.", val_len); + return -EINVAL; + } + + ret =3D cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_GET, + &req, sizeof(req), val, val_len); + if (ret < 0) { + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=3D%d= ", ret); + return ret; + } + return 0; +} + +static int cros_ucsi_async_write(struct ucsi *ucsi, unsigned int offset, + const void *val, size_t val_len) +{ + struct cros_ucsi_data *udata =3D ucsi_get_drvdata(ucsi); + uint8_t ec_buffer[MAX_EC_DATA_SIZE + sizeof(struct ec_params_ucsi_ppm_set= )]; + struct ec_params_ucsi_ppm_set *req =3D (struct ec_params_ucsi_ppm_set *)e= c_buffer; + int ret =3D 0; + + if (val_len > MAX_EC_DATA_SIZE) { + dev_err(udata->dev, "Can't write %zu bytes. Too big.", val_len); + return -EINVAL; + } + + memset(req, 0, sizeof(ec_buffer)); + req->offset =3D offset; + memcpy(req->data, val, val_len); + ret =3D cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET, + req, sizeof(struct ec_params_ucsi_ppm_set) + val_len, NULL, 0); + + if (ret < 0) { + dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=3D%d= ", ret); + return ret; + } + return 0; +} + +static int cros_ucsi_sync_write(struct ucsi *ucsi, unsigned int offset, + const void *val, size_t val_len) +{ + struct cros_ucsi_data *udata =3D ucsi_get_drvdata(ucsi); + bool ack =3D UCSI_COMMAND(*(u64 *)val) =3D=3D UCSI_ACK_CC_CI; + int ret; + + if (ack) + set_bit(ACK_PENDING, &udata->flags); + else + set_bit(COMMAND_PENDING, &udata->flags); + + ret =3D cros_ucsi_async_write(ucsi, offset, val, val_len); + if (ret) + goto out; + + if (!wait_for_completion_timeout(&udata->complete, WRITE_TMO_MS)) + ret =3D -ETIMEDOUT; + +out: + if (ack) + clear_bit(ACK_PENDING, &udata->flags); + else + clear_bit(COMMAND_PENDING, &udata->flags); + return ret; +} + +struct ucsi_operations cros_ucsi_ops =3D { + .read =3D cros_ucsi_read, + .async_write =3D cros_ucsi_async_write, + .sync_write =3D cros_ucsi_sync_write, +}; + +static void cros_ucsi_work(struct work_struct *work) +{ + struct cros_ucsi_data *udata =3D container_of(work, struct cros_ucsi_data= , work); + u32 cci; + int ret; + + ret =3D cros_ucsi_read(udata->ucsi, UCSI_CCI, &cci, sizeof(cci)); + if (ret) + return; + + if (UCSI_CCI_CONNECTOR(cci)) + ucsi_connector_change(udata->ucsi, UCSI_CCI_CONNECTOR(cci)); + + if (cci & UCSI_CCI_ACK_COMPLETE && test_bit(ACK_PENDING, &udata->flags)) + complete(&udata->complete); + if (cci & UCSI_CCI_COMMAND_COMPLETE && + test_bit(COMMAND_PENDING, &udata->flags)) + complete(&udata->complete); +} + +static int cros_ucsi_event(struct notifier_block *nb, + unsigned long host_event, void *_notify) +{ + struct cros_ucsi_data *udata =3D container_of(nb, struct cros_ucsi_data, = nb); + + if (!(host_event & PD_EVENT_PPM)) + return NOTIFY_OK; + + dev_dbg(udata->dev, "UCSI notification received"); + flush_work(&udata->work); + schedule_work(&udata->work); + + return NOTIFY_OK; +} + +static int cros_ucsi_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct cros_ucsi_data *udata; + int ret; + + udata =3D devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL); + if (!udata) + return -ENOMEM; + + udata->dev =3D dev; + + udata->ec =3D ((struct cros_ec_dev *) dev_get_drvdata(pdev->dev.parent))-= >ec_dev; + if (!udata->ec) { + dev_err(dev, "couldn't find parent EC device\n"); + return -ENODEV; + } + + platform_set_drvdata(pdev, udata); + + INIT_WORK(&udata->work, cros_ucsi_work); + init_completion(&udata->complete); + + udata->ucsi =3D ucsi_create(udata->dev, &cros_ucsi_ops); + if (IS_ERR(udata->ucsi)) { + dev_err(dev, "failed to allocate UCSI instance\n"); + return PTR_ERR(udata->ucsi); + } + + ucsi_set_drvdata(udata->ucsi, udata); + + ret =3D ucsi_register(udata->ucsi); + if (ret) { + ucsi_destroy(udata->ucsi); + udata->ucsi =3D NULL; + return ret; + } + + udata->nb.notifier_call =3D cros_ucsi_event; + ret =3D cros_usbpd_register_notify(&udata->nb); + return ret; +} + +static int cros_ucsi_remove(struct platform_device *dev) +{ + struct cros_ucsi_data *udata =3D platform_get_drvdata(dev); + + if (udata->ucsi) { + ucsi_unregister(udata->ucsi); + ucsi_destroy(udata->ucsi); + udata->ucsi =3D NULL; + } + return 0; +} + +static int cros_ucsi_suspend(struct device *dev) +{ + struct cros_ucsi_data *udata =3D dev_get_drvdata(dev); + + cancel_work_sync(&udata->work); + + return 0; +} + +static int cros_ucsi_resume(struct device *dev) +{ + struct cros_ucsi_data *udata =3D dev_get_drvdata(dev); + + return ucsi_resume(udata->ucsi); +} + +static SIMPLE_DEV_PM_OPS(cros_ucsi_pm_ops, cros_ucsi_suspend, + cros_ucsi_resume); + +static struct platform_driver cros_ucsi_driver =3D { + .driver =3D { + .name =3D DRV_NAME, + .pm =3D &cros_ucsi_pm_ops, + }, + .probe =3D cros_ucsi_probe, + .remove =3D cros_ucsi_remove, +}; + +module_platform_driver(cros_ucsi_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("UCSI driver for ChromeOS EC."); +MODULE_ALIAS("platform:" DRV_NAME); diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux= /platform_data/cros_ec_commands.h index ecc47d5fe239..39f6f54bbe4c 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -4933,6 +4933,7 @@ struct ec_response_pd_status { #define PD_EVENT_POWER_CHANGE BIT(1) #define PD_EVENT_IDENTITY_RECEIVED BIT(2) #define PD_EVENT_DATA_SWAP BIT(3) +#define PD_EVENT_PPM BIT(5) struct ec_response_host_event_status { uint32_t status; /* PD MCU host event status */ } __ec_align4; @@ -5994,6 +5995,24 @@ struct ec_response_typec_vdm_response { =20 #undef VDO_MAX_SIZE =20 +/* + * Read/write interface for UCSI OPM <-> PPM communication. + */ +#define EC_CMD_UCSI_PPM_SET 0x0140 + +/* The data size is stored in the host command protocol header. */ +struct ec_params_ucsi_ppm_set { + uint16_t offset; + uint8_t data[]; +} __ec_align2; + +#define EC_CMD_UCSI_PPM_GET 0x0141 + +struct ec_params_ucsi_ppm_get { + uint16_t offset; + uint8_t size; +} __ec_align2; + /*************************************************************************= ****/ /* The command range 0x200-0x2FF is reserved for Rotor. */ =20 --=20 2.44.0.396.g6e790dbe36-goog