From patchwork Mon Mar 25 23:42:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavan Holla X-Patchwork-Id: 13603174 Received: from mail-ot1-f45.google.com (mail-ot1-f45.google.com [209.85.210.45]) (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 5C93683CA7 for ; Mon, 25 Mar 2024 23:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410150; cv=none; b=K7H3faKXfr/4WShGXlauLxSUXJK5BA3NNhr+Na9UP5zI55H66lqEPNEZMCuEcXQfnYkWy+VejOV5Al2h1PMBJaL+3rjISuBc0Bjnw8bLprPSGJCHdeHzGLB7aRGUq7f2jlujM4l4rgUkC78MmQqSBKY9O0+1LmwdaHhqJPw5KPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410150; c=relaxed/simple; bh=SeQce1gFW0K6iI86gWi0GbaKVMdi8pBaBD+m2qO3U+o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eB5k4vUvv3N322yczjIUmCHL0yBl/HSMuTOkT7EssGA+51mAvCXEst89RkMK8Y1RcmJv6FPB0F25uv/Ybar9yTkgqW2Z/NVSlr8pUu1atBixdNlLnnQzP4qhCJyivcPW/lUs2FEYsefvyMu2R12WIe6Mu4O/yxnOyY8TvWaabjw= 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=KX0XQ+nc; arc=none smtp.client-ip=209.85.210.45 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="KX0XQ+nc" Received: by mail-ot1-f45.google.com with SMTP id 46e09a7af769-6e677008501so3019370a34.1 for ; Mon, 25 Mar 2024 16:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711410147; x=1712014947; darn=lists.linux.dev; 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=KX0XQ+ncQZScABC9W2C3ASc+QsGUWHy583DojrRDZmy+Da96B3Jn6n1bOz1pdvMTtG B5zjkTTxFXY9yjkWQVsy/sl8gPUxykJpY1jt0tmosviSkx1i/k1URemvXvgOOx0GNS1V mOjg4S5GEzbUljqdW8NW9Sgk0YyABlIOEVKxI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711410147; x=1712014947; 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=JftAvr4dQWslpMzwdLo7JoWh/06mW2S0CBnoPBjFXLXHIySf6qAg/x6CNsCo5rCAoM xVGUaR23Yee39SE2JzcGG3j9R6LlY009DDwG5p4gYdtDyucvPDTe7zPp8QANfp8Uhy7l 359QnJoNk28CMBKFIhjorW6Iy2yw+bXukZvcEVK6Fe+m60iR+xe7KKwwk6KxD6LymHWc qArlikLaHfCkjz3ichK7YZIOzr18fr+QzfxjaaakaMAUUrYwENggwureHLFS19vPUo05 VEFiMPYIxwUn4YIeI7+Ro+3SYqYsbjWFQ7xyDlpLNhqSj0Lj9NF5C0GjE0B5mZWdrGsS RUIQ== X-Forwarded-Encrypted: i=1; AJvYcCUf6dCxkX9S+zSakamafqaCtF0TxCGuj2am0jWTTFcSjHvViG5GhB7HCCXUo4r0O8KTH/KC23egPxA8tiZLqAXM8m7ed/jhj96ukrdaiXYU X-Gm-Message-State: AOJu0Yw+LH5xaxUBqy9lK2DJYLWiipjEJ/KVCsmKZdpTLb22WOql3pfS b4Kj0tOfdwTNvnzBuiLcm3tXkwBM9+hT/l8DlE7dIwylzIV+yxokG9cAiW6nB2sLjEFr+nULGfk = X-Google-Smtp-Source: AGHT+IHOQHJIiFr3Qyf80KKrpxpe99WiMfSTkA4PVy4Z9qbl88vOkaegWkYPoXJ3Lr2DgnAnuU9Neg== X-Received: by 2002:a05:6870:c689:b0:229:87f6:ee8a with SMTP id cv9-20020a056870c68900b0022987f6ee8amr9631946oab.30.1711410147426; Mon, 25 Mar 2024 16:42:27 -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 e12-20020aa7824c000000b006e5f754646csm4705250pfn.139.2024.03.25.16.42.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:42:27 -0700 (PDT) From: Pavan Holla Date: Mon, 25 Mar 2024 23:42:25 +0000 Subject: [PATCH v2 1/3] usb: typec: ucsi: Provide interface for UCSI transport Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240325-public-ucsi-h-v2-1-a6d716968bb1@chromium.org> References: <20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org> In-Reply-To: <20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org> To: Greg Kroah-Hartman , Heikki Krogerus , Benson Leung , Tzung-Bi Shih , Guenter Roeck Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , chrome-platform@lists.linux.dev, 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 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 the + * Command Completion Event from the PPM before returning, and @async_write 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 */ From patchwork Mon Mar 25 23:42:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavan Holla X-Patchwork-Id: 13603175 Received: from mail-oa1-f47.google.com (mail-oa1-f47.google.com [209.85.160.47]) (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 0DFF184D11 for ; Mon, 25 Mar 2024 23:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410150; cv=none; b=VWr9HmZ0gJGaRGbiGHLvznudvIzCB/qDaPlGK0ZKZGKSUPGJfEGJ+98flruH4uNdfa7XmzsAd3CsFXsd+/0ab3LKUnrmZxnCG2CQ6XCoFthvKJlN8JhC0+GSnS07FN2yVXTAJRnNERMk7rcWw7zp6eGn5oe+rKxnpNbPWWcCYCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410150; c=relaxed/simple; bh=jbSJ8EoUHTJOt2gEIo2bLB7/XqaW9sPGoBPW7n04aM8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=t/fsqbwmjN7KI84K7PRDwETmxJ1CRHivyEvaTzenEVU5WlUazzSuTcWE8LkfhpZzbc319x675uQPwgm9kWFMEpwYL6xySV4zsne9g6QFzZGZIkrDOw6cmLO0gAAjbkD9egEb6vBqHUH08giyViCYA4Wnl16ijF/ezXKBXUy0e4E= 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=Wsu2JmDj; arc=none smtp.client-ip=209.85.160.47 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="Wsu2JmDj" Received: by mail-oa1-f47.google.com with SMTP id 586e51a60fabf-221e1910c3bso2496146fac.1 for ; Mon, 25 Mar 2024 16:42:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711410148; x=1712014948; darn=lists.linux.dev; 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=Wsu2JmDj4rcZQZbZxEcWc+z1DZBy9dTtij+t2s7cR2jP3IUvra9d6q7VeKXxBbfpU7 Yl1WXThMRLTy8ZzPVzjUdJXNBf9bCYMoVbxNzYYxxSM4MME1EcTZirxa3fl+EnqAH1/2 TOoqbyVqiLbAvepIWXue1mKKtMwxJAibHUMKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711410148; x=1712014948; 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=lBkXnCE3A00e3I9UB82RzQRDJDlnYEOTHMNBRpfdmOZakA8Cn2XkKMO0CTH22PNNx+ JNTVhan4yOKSAsuufb5sAEZI6DAWuWQpyWKq504wp53piUjMyQbstU8UTazI/UJr+4a7 NoivY4J6UHPWmkgxW6GxNQJbsBEPeJcHx38fGoIG9PPjpsYaSRWaxDpH44xwSUz6kREs o10hVnB+Mt7L8gPjPbDEqtGW0yzVSmmbGSaq645dEdfMqGzxsWhYekmpOsuZUo9xhJz3 QzXq8wGOjoAJtIwQYgJhOVkYCPD4Xi+/MUSAe3hky1qY+HRLMaTCXiPshZQ0eqkdpDHA 1Wuw== X-Forwarded-Encrypted: i=1; AJvYcCXVDAfu/u9QJBbnVltOwLaIri+OC5jI91HOUmXKXia2/z37U8TdekGRA4uo/DRqS2VjAoO02hkQb97zZIqs6SaBUD+Cwq5Fd5WfVOcaIlDL X-Gm-Message-State: AOJu0Yyy1HNR28URS4UdV4ZIZfqFZlzj78CnY1GR+tMqDl3+xffMvZ5G hIj6TLTZS84hfF67AAwWtDrEn6MkLlZwueq9hOx+D3vVeK5lz0SoUqc3ATezhg== X-Google-Smtp-Source: AGHT+IFfqUoFUiQ3FrCIorattkPr5kkTc+89j+fGmnMi8wh4pRSenLSBlVADwPUv8ovpzetIZDte0w== X-Received: by 2002:a05:6870:d8ca:b0:21f:df18:349b with SMTP id of10-20020a056870d8ca00b0021fdf18349bmr9488740oac.35.1711410148244; Mon, 25 Mar 2024 16:42:28 -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 e12-20020aa7824c000000b006e5f754646csm4705250pfn.139.2024.03.25.16.42.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:42:27 -0700 (PDT) From: Pavan Holla Date: Mon, 25 Mar 2024 23:42:26 +0000 Subject: [PATCH v2 2/3] usb: typec: ucsi: Import interface for UCSI transport Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240325-public-ucsi-h-v2-2-a6d716968bb1@chromium.org> References: <20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org> In-Reply-To: <20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org> To: Greg Kroah-Hartman , Heikki Krogerus , Benson Leung , Tzung-Bi Shih , Guenter Roeck Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , chrome-platform@lists.linux.dev, 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 /* -------------------------------------------------------------------------- */ -struct ucsi; -struct ucsi_altmode; struct dentry; -/* 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) -/* 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 the - * Command Completion Event from the PPM before returning, and @async_write 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); - /* -------------------------------------------------------------------------- */ /* Commands */ @@ -465,7 +414,6 @@ int ucsi_send_command(struct ucsi *ucsi, u64 command, void *retval, size_t size); void ucsi_altmode_update_active(struct ucsi_connector *con); -int ucsi_resume(struct ucsi *ucsi); #if IS_ENABLED(CONFIG_POWER_SUPPLY) int ucsi_register_port_psy(struct ucsi_connector *con); From patchwork Mon Mar 25 23:42:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavan Holla X-Patchwork-Id: 13603176 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.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 ECACD84D37 for ; Mon, 25 Mar 2024 23:42:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410151; cv=none; b=Cx+UgbCGjucGo2w7K4ifZk6uArvV+tDPRHwp8wShoRlIGkO0KS3kYDGWvopwHxwWzPX/RIf9/fW2BZkSx70AhnlxQRhCSj7KeGQIEf0rv62ZkNHDlYQ1P4j3TMgldE/Jylvgmnqin2T1vC6iVY8ZrF5a1QYV0Trw4hZ1Zznyxu0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711410151; c=relaxed/simple; bh=fsjkodhL8grV1QBLXNjixrtYC9NfJF+MMKlB8IzvKL4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=I4St6vmEIy/fgolOcP5ZRbf+fU+xELTnFsXmGwCtTwOvdiNeM4evS95l6dzDXNpB469361z7DkRmLXIB6MIR252Jc2nEFJRTvFoQgd4ECuPYDhFQsd4XM+dHEbizat65hhfkZugglR1VFv/4NhT0n1U//XkuY7SARdX9MxRDBZ8= 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=YHHPuYDc; arc=none smtp.client-ip=209.85.210.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="YHHPuYDc" Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e740fff1d8so3477252b3a.1 for ; Mon, 25 Mar 2024 16:42:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1711410149; x=1712014949; darn=lists.linux.dev; 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=YHHPuYDcF6GJbMxmmraYN8Bo6yhDLL7nStjkJmmE/Hz1x/EIwDbslMP6H0U1PsR0X7 XlEVtGfijLjqWYauB6tQYSKBJ+LqXthGaoyP18HLc/ikhZyVDrXbR8hEJNcyYU81+/ui zn7rIt0fpzhvd57fN4qa60bbRf997lF9Np3HY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711410149; x=1712014949; 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=TbqZ994xqmMZJ6qTnlrdTh3RfXvbz1xXogHh4+nWAmVRmZq1aIRunT9PgohqGqOVss gYpyvfHRwBkPWcJUq46BDt4qOT9AK/Vuo2ZzoggPj/BRJIAYkneIX+1Pd6ut2UzztqhA j4XUnDApnI6nYe8B23+XEZutp8a5HFzOnuRgjQNu87OdV04QmQCsoCqnUISunNlMu34J AKWx9yF6HPXq/iZjO30/Mz9H2QPNfjh50dF475kQVwLiZEkTa0rJLxUKC/6Q1JaWUxQC poldNTKNbPeeohjjNNWjqM17trkRhWOhm2RMpxBE1a+Q4MrTX8/IAQ8iP6ww/2dGf2ad Qalw== X-Forwarded-Encrypted: i=1; AJvYcCUYgtMwR1o5Xn7VNU6TI0s5tuQpuz+is6928IDHWPBPiPi7utKV6HWDLXu8UPdKUXa7H2wQrkrsz4OmrJujAIPJUHutvcwXjN4+VuqSquiZ X-Gm-Message-State: AOJu0YxytTnkv37ausDOwHcRMWj1gWWq4LtzE7Np1aBF4W5ohtKli4sm TOzhW3dL1zSkI8NcH+p2fTuc7o/kXLNRMcK2xe0ozqCmbAVezDaR0XcETtB9aw== X-Google-Smtp-Source: AGHT+IFwYOye/EwjEDySLlO26UqAhGZnkSQngTI9ec0QPp9cogBBG7/AB25Te6NR1yj2dOb/oFbMxw== X-Received: by 2002:a05:6a00:92a8:b0:6ea:b82d:6205 with SMTP id jw40-20020a056a0092a800b006eab82d6205mr1142055pfb.16.1711410149156; Mon, 25 Mar 2024 16:42:29 -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 e12-20020aa7824c000000b006e5f754646csm4705250pfn.139.2024.03.25.16.42.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Mar 2024 16:42:28 -0700 (PDT) From: Pavan Holla Date: Mon, 25 Mar 2024 23:42:27 +0000 Subject: [PATCH v2 3/3] platform/chrome: cros_ec_ucsi: Implement UCSI PDC driver Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240325-public-ucsi-h-v2-3-a6d716968bb1@chromium.org> References: <20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org> In-Reply-To: <20240325-public-ucsi-h-v2-0-a6d716968bb1@chromium.org> To: Greg Kroah-Hartman , Heikki Krogerus , Benson Leung , Tzung-Bi Shih , Guenter Roeck Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, Abhishek Pandit-Subedi , chrome-platform@lists.linux.dev, 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/Kconfig 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. +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/Makefile index 2dcc6ccc2302..85964e165a70 100644 --- a/drivers/platform/chrome/Makefile +++ b/drivers/platform/chrome/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_CROS_EC_UART) += cros_ec_uart.o cros_ec_lpcs-objs := cros_ec_lpc.o cros_ec_lpc_mec.o cros-ec-typec-objs := cros_ec_typec.o cros_typec_vdm.o obj-$(CONFIG_CROS_EC_TYPEC) += cros-ec-typec.o +obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o obj-$(CONFIG_CROS_EC_LPC) += cros_ec_lpcs.o obj-$(CONFIG_CROS_EC_PROTO) += cros_ec_proto.o cros_ec_trace.o obj-$(CONFIG_CROS_KBD_LED_BACKLIGHT) += cros_kbd_led_backlight.o diff --git a/drivers/platform/chrome/cros_ec_ucsi.c b/drivers/platform/chrome/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 *val, + size_t val_len) +{ + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); + struct ec_params_ucsi_ppm_get req = { + .offset = offset, + .size = 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 = 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=%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 = 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 = (struct ec_params_ucsi_ppm_set *)ec_buffer; + int ret = 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 = offset; + memcpy(req->data, val, val_len); + ret = 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=%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 = ucsi_get_drvdata(ucsi); + bool ack = UCSI_COMMAND(*(u64 *)val) == UCSI_ACK_CC_CI; + int ret; + + if (ack) + set_bit(ACK_PENDING, &udata->flags); + else + set_bit(COMMAND_PENDING, &udata->flags); + + ret = cros_ucsi_async_write(ucsi, offset, val, val_len); + if (ret) + goto out; + + if (!wait_for_completion_timeout(&udata->complete, WRITE_TMO_MS)) + ret = -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 = { + .read = cros_ucsi_read, + .async_write = cros_ucsi_async_write, + .sync_write = cros_ucsi_sync_write, +}; + +static void cros_ucsi_work(struct work_struct *work) +{ + struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work); + u32 cci; + int ret; + + ret = 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 = 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 = &pdev->dev; + struct cros_ucsi_data *udata; + int ret; + + udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL); + if (!udata) + return -ENOMEM; + + udata->dev = dev; + + udata->ec = ((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 = 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 = ucsi_register(udata->ucsi); + if (ret) { + ucsi_destroy(udata->ucsi); + udata->ucsi = NULL; + return ret; + } + + udata->nb.notifier_call = cros_ucsi_event; + ret = cros_usbpd_register_notify(&udata->nb); + return ret; +} + +static int cros_ucsi_remove(struct platform_device *dev) +{ + struct cros_ucsi_data *udata = platform_get_drvdata(dev); + + if (udata->ucsi) { + ucsi_unregister(udata->ucsi); + ucsi_destroy(udata->ucsi); + udata->ucsi = NULL; + } + return 0; +} + +static int cros_ucsi_suspend(struct device *dev) +{ + struct cros_ucsi_data *udata = dev_get_drvdata(dev); + + cancel_work_sync(&udata->work); + + return 0; +} + +static int cros_ucsi_resume(struct device *dev) +{ + struct cros_ucsi_data *udata = 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 = { + .driver = { + .name = DRV_NAME, + .pm = &cros_ucsi_pm_ops, + }, + .probe = cros_ucsi_probe, + .remove = 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 { #undef VDO_MAX_SIZE +/* + * 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. */