From patchwork Tue Sep 10 10:15:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798279 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 E45CE18CBE2 for ; Tue, 10 Sep 2024 10:15:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963339; cv=none; b=o2Z31drtUMLJN0wTidTgZ64OdlgmZYtqunpBr22rxAiVOa4WjM3i7/7Exm1MHyVrL5UrjPF4jTI0NtQoczWZt2v9xQ7iq6o7VSpt9H+tF5N3mkXbd2UNJ8/pipuQi/5y47jyyLOcRhSVQ29jlaETepwGQQ7S5NgHzXp8pBmP0l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963339; c=relaxed/simple; bh=P845PChozNDR5SGQbooLDKSy6BNU+jWzs4r3D6gy+s0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FnjvF7G+Art7x71e0Z4KkJVedxQF0F8zqpEP/LXpgLM+U+TK04VXRQPsMOKxlK2l9oONqp4HsvtdnCbeaNiu4iHSvrXn3mW5VPxcGZOdKBEcZTJE2L53N0Xg2HXsO0sN6TBr5IKsrSuvGo5djIEixGbvMVL+PjTzIDYJnZbZgcs= 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=gTI4xytq; arc=none smtp.client-ip=209.85.208.51 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="gTI4xytq" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-5becd359800so5007881a12.0 for ; Tue, 10 Sep 2024 03:15:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963336; x=1726568136; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=14fOqglI4gqlZHINscrTLoCf9Zlvu7dl6ljaBQHSUuQ=; b=gTI4xytqTT29ZBAQdYp/Wgdq+sEc1uxh+Wk1cXQQFxLNodi06cfmNK6AC4hC91dzzo mHax4YORAGeRIwDtNcSYEscnLcUyrH3TC4GZ41kSg6COhuWSbYqNzDyspXO8fIHBhEXS 5OmZtzn7zW0Mkw9Ll7bII3+WqzSF4gVNB55wA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963336; x=1726568136; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=14fOqglI4gqlZHINscrTLoCf9Zlvu7dl6ljaBQHSUuQ=; b=sie4n4lwD38ogSEBFM+dHFzD/8E9BpEQW7fGBIl7cNQvkLexI5W7NQ4T+WiN6f882K d8zXv24QN3bXqZJATNWGaTHGdSNECeOU8UgK57o+P2jMit8d1BfsZu9N/wcUQY67vdQt lCAuruiFrwX9ZtGKptPsC9VviGf/HwXer/+9SLClqd/ZBdp0jNU1TOK8ghQAWwtc62C3 qkW0TblPqcX+I2fjMgZ+ft65HqSOOktzWMSEPcP0jKNzz1lCx3RYOoOyB1tB4424p9Op TLcybfZrTXeNHna1j19iFXTNOHMK6WIkUNGzSJ+qhyPZzJXEzCQjUGq4oVpXnXqRjhJm YJYw== X-Forwarded-Encrypted: i=1; AJvYcCV5LEJzV9Qd4xk5jHHrC6JUyHfnNE4ZMsG9+y4K6IqZCKIK+ghODBwVLPey4rfZUW/u573wVa/ow/bkKr7no8k=@lists.linux.dev X-Gm-Message-State: AOJu0Yx3wth8hgZVWY6gZISvtWY3Puv99ZgiHpN/jhnqa9qhU4z/GTZv 85euHCrLBBL7rS1oTglFSanQUt0M+buqc8jHXte/oQOa4Mti9EXPA0PUoeCK X-Google-Smtp-Source: AGHT+IHf3x52xmPmWW27g7tPZAnY8Wi/THOklHIPEmyuKAyafMoyrrGYgmExnYJC5b9NF8LHKNzaSg== X-Received: by 2002:a05:6402:34c8:b0:5be:fadc:e13c with SMTP id 4fb4d7f45d1cf-5c3dc77ff52mr9531818a12.4.1725963336069; Tue, 10 Sep 2024 03:15:36 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:35 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 1/8] platform/chrome: Update ChromeOS EC header for UCSI Date: Tue, 10 Sep 2024 10:15:20 +0000 Message-ID: <20240910101527.603452-2-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Pavan Holla Add EC host commands for reading and writing UCSI structures in the EC. The corresponding kernel driver is cros-ec-ucsi. Also update PD events supported by the EC. Signed-off-by: Pavan Holla Signed-off-by: Łukasz Bartosik Acked-by: Tzung-Bi Shih --- .../linux/platform_data/cros_ec_commands.h | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index e574b790be6f..8dbb6a769e4f 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -5012,8 +5012,11 @@ 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_TYPEC BIT(4) +#define PD_EVENT_PPM BIT(5) + struct ec_response_host_event_status { - uint32_t status; /* PD MCU host event status */ + uint32_t status; /* PD MCU host event status */ } __ec_align4; /* Set USB type-C port role and muxes */ @@ -6073,6 +6076,29 @@ struct ec_response_typec_vdm_response { #undef VDO_MAX_SIZE +/* + * UCSI OPM-PPM commands + * + * These commands are used for communication between OPM and PPM. + * Only UCSI3.0 is tested. + */ + +#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 + +/* For 'GET' sub-commands, data will be returned as a raw payload. */ +struct ec_params_ucsi_ppm_get { + uint16_t offset; + uint8_t size; +} __ec_align2; + /*****************************************************************************/ /* The command range 0x200-0x2FF is reserved for Rotor. */ From patchwork Tue Sep 10 10:15:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798281 Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (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 53D4D18B498 for ; Tue, 10 Sep 2024 10:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963341; cv=none; b=j5185W5fyUnNluJLPDV2X4yzwKr3bC4cjsZOeQDZ4U0FMN/wl7vegpM2ZKYPs791HmIVZabBKdecZSSrAxWVZ4tJ8VSK2+J+sA+4DM1yT7L3537ToyMZKFR1xGRxwhzCy9FsvxtubSMLzaKTqKdiN6B0pWiV3HmE7cJmr9pIKTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963341; c=relaxed/simple; bh=+8hk+kJmR2SsDvw10WpS8DsYjndB+0n7l87NsIhLzJY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=URjv+6Mddqp8VBSjZHAln0SSwDZ5cFViBmgMQ8DLVDxlbpvFfhRVyR8fxMVbEWp8Cv+AxaBicNV0qXPb+ZZH5+0Y/XGva45XAR2bLeC2niOC8BVRH/F24ePRjTSAxVdyZO79aZyX/uFu9wMZ2sRSKNL0xG57pMRKsy53bzM3MTM= 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=ifJvFpb5; arc=none smtp.client-ip=209.85.218.49 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="ifJvFpb5" Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-a8d3e662791so168206266b.1 for ; Tue, 10 Sep 2024 03:15:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963338; x=1726568138; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=83DCmEuq7JrWTmbULmBpjHQMPEO/K0lZCYAd0BrN8Kc=; b=ifJvFpb5h1+O31jefp3u7g8zbfBMc74j1k8qn1a48FZdbsunAVH/A0oQFMjqgYojk9 i4ZuiuCVPHZHZG3LGF2lujqr8mDaUVCiOHd+MNzeGUbcioTeTYPE6d/ttSCo5snN64py x5ZtbPh76fwQy/lK9vRqe4PRn+YCWkgUTCPu8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963338; x=1726568138; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=83DCmEuq7JrWTmbULmBpjHQMPEO/K0lZCYAd0BrN8Kc=; b=JkfQrQFNtMny46NWWA+WNkUcmAbBYbmEy5iSRS6JQKJ5jTwp2j+jMPdxmbp8ZJ3Nil tlBT9QzMS0dSq26lcIxoUjjW4QUI0wNDRC9VtR8XPO8+Fv9irDW3qURWTN3A98snIY5c pMUiBEMW/bF6f3//cQX1tpmNpSB7JY8yWpUJMcElkaXp/pUMTROex1vdLGaPuQc4JaHX jrm/z2RJTSuKydfnc+/TMfhOEuWh+wPPUiB/oORRi0X25Zcq7WhQEiucQd58Fe5KD8jN ThLQiQ8eIWyLoxXlNAb5DszGHjh81qdrlwfHSUD6dn7ObDR0S+aRnvh1C9IZ7B8X4xEh lXkQ== X-Forwarded-Encrypted: i=1; AJvYcCXihAM7a0gDgCLb8hczoKR3q9Di8MZ9xf/GZO6ymI6DF7xCIErqm5BBnxfdmAVAWxffHzLNgkJYsiUjjjESmwY=@lists.linux.dev X-Gm-Message-State: AOJu0Yx6E6EI4VU6hV7+8NSUpo44klv+1z2RiNLZa5t7y5UlMIkYCg3h CAIqY1HwVVnEUDCXCCSSbABA3IHQ2ueySxnfITfxOPq7OklMWUjuZsL6l/NB X-Google-Smtp-Source: AGHT+IHE4rrZXnsK6QRB1ACp9FxoMImuTXf20860U02c9qcu6cfe7aWIFZs39uplA7VdzTCrQ45ZPg== X-Received: by 2002:a05:6402:360a:b0:5c2:6a73:d13b with SMTP id 4fb4d7f45d1cf-5c3dc7c02d8mr12419030a12.34.1725963336780; Tue, 10 Sep 2024 03:15:36 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:36 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 2/8] platform/chrome: Update EC feature flags Date: Tue, 10 Sep 2024 10:15:21 +0000 Message-ID: <20240910101527.603452-3-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Pavan Holla Define EC_FEATURE_UCSI_PPM to enable usage of the cros_ec_ucsi driver. Also, add any feature flags that are implemented by the EC but are missing in the kernel header. Signed-off-by: Pavan Holla Signed-off-by: Łukasz Bartosik Acked-by: Tzung-Bi Shih --- .../linux/platform_data/cros_ec_commands.h | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/platform_data/cros_ec_commands.h b/include/linux/platform_data/cros_ec_commands.h index 8dbb6a769e4f..ecf290a0c98f 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -1312,6 +1312,38 @@ enum ec_feature_code { * The EC supports the AP composing VDMs for us to send. */ EC_FEATURE_TYPEC_AP_VDM_SEND = 46, + /* + * The EC supports system safe mode panic recovery. + */ + EC_FEATURE_SYSTEM_SAFE_MODE = 47, + /* + * The EC will reboot on runtime assertion failures. + */ + EC_FEATURE_ASSERT_REBOOTS = 48, + /* + * The EC image is built with tokenized logging enabled. + */ + EC_FEATURE_TOKENIZED_LOGGING = 49, + /* + * The EC supports triggering an STB dump. + */ + EC_FEATURE_AMD_STB_DUMP = 50, + /* + * The EC supports memory dump commands. + */ + EC_FEATURE_MEMORY_DUMP = 51, + /* + * The EC supports DP2.1 capability + */ + EC_FEATURE_TYPEC_DP2_1 = 52, + /* + * The MCU is System Companion Processor Core 1 + */ + EC_FEATURE_SCP_C1 = 53, + /* + * The EC supports UCSI PPM. + */ + EC_FEATURE_UCSI_PPM = 54, }; #define EC_FEATURE_MASK_0(event_code) BIT(event_code % 32) From patchwork Tue Sep 10 10:15:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798282 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 926471917FE for ; Tue, 10 Sep 2024 10:15:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963343; cv=none; b=lK89snK/AIBkhtRXT2eziorppVdzOpLRJTYCy7LrcioXW3uKbDgOVF9JziWDavj49nb5MnkATCL1cZzDGVqheEd3xkkES0PCOUprHGHt7jY1rmhb+/0oiN79D1giPknXsbCs33d519+4+QOGdGdG1FoyCfOPcXfkPD7y56QBl/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963343; c=relaxed/simple; bh=ZQDCGufaicLbze1wbf5pJcnHwNLAL3tisQvp2YFyPA0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oI55+KMdSO0rZ6K9HRRdDXzB6JfYQ90kh2jtxpmpl7GMjeJKOYGsLJ+L52NcmFSGr6bDsspeslObsuxB+sFyojixozxOu+1iPhPX/PksaIIsqgxQIok0xOTAWTZE9fb1IijjE05GyJxp9Qu6WDCyPHNE/8ksJoy/oEWMilQhi6I= 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=NEFj0BYx; arc=none smtp.client-ip=209.85.208.54 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="NEFj0BYx" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5c255e3c327so5789293a12.1 for ; Tue, 10 Sep 2024 03:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963340; x=1726568140; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=u994fB1SgApV7RSebqLQItZQFEAtWCMCiSZGqHuvL1U=; b=NEFj0BYx+MjvTCZaW7GZ83sQKKIe/X10gZw4+tSTZwHdm8EG+uMCTPEQcH5JEiWMQO 54NJ9VeZSz7tkV61Mdvm4a/JEru0lVRaQG5EI01DYVXBSrJuuW2pwTjIvJr4Bfm6SdLA nZ3B7+JFkanYoWCIqmkt5/YAHhsquJZj4jh5M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963340; x=1726568140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=u994fB1SgApV7RSebqLQItZQFEAtWCMCiSZGqHuvL1U=; b=uq4CornGAM8KLgh4RqNzRrs9aWFBHeMQTS4OTJ3l9aq2W+0irYHYhPD9s1QNc+GAjY fcdn+/tuY/VrEeJ4AFiKJnhPLHcogy1D8C//39Ewv4FDBsrSukhp94b5Q7bxvOJV9gCQ p6mYxmKMm+Q2VTI5VDE0UrBg2Dc8bcqwC6U9eZOW8c4GWTkJTwYJcdBYmZZqSQKkfDEL WkvZawx0zk+QzsG5qunaLYPinIAwIocyShHt+RkckETRe/WtrIHaBW9ETNvZ4rhjfU1z j2dgwYJksU18ShZmNOfm1UlpA9T7ezzd3Arm2zydogxmzQiUL4t1PanIg4CFnL9ojJQF EcTw== X-Forwarded-Encrypted: i=1; AJvYcCUbWGBNw6CS4oB5uB/TNXdo+KwcJga6k1JbU4JwxJMrhdEvyt7PV3v6pG7Fe4CQzyxmrw8yS1MLxhxKUng5rMU=@lists.linux.dev X-Gm-Message-State: AOJu0YwggQJvNrkj/owZMyfvMpJ3sDHxHQYiM1RsQHSl+kKhsCEEKxnN U6lezbGsfyVp8RStL9W2P54edyj8CucyYAIvMVrEdyurdKQNG29MRKE4BwC0 X-Google-Smtp-Source: AGHT+IG3s8QST6X2F6vf50wASNqCJhio8h7iTB7h6nIcNH5oM0FEntoyhBEC9GSwte6pCcDJ3HXZLQ== X-Received: by 2002:a05:6402:234e:b0:5af:30d9:e2b6 with SMTP id 4fb4d7f45d1cf-5c3dc7bb1acmr9604653a12.23.1725963339565; Tue, 10 Sep 2024 03:15:39 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:36 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 3/8] usb: typec: ucsi: Implement ChromeOS UCSI driver Date: Tue, 10 Sep 2024 10:15:22 +0000 Message-ID: <20240910101527.603452-4-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Pavan Holla Implementation of a UCSI transport driver for ChromeOS. This driver will be loaded if the ChromeOS EC implements a PPM. Signed-off-by: Pavan Holla Co-developed-by: Łukasz Bartosik Signed-off-by: Łukasz Bartosik --- MAINTAINERS | 7 + drivers/usb/typec/ucsi/Kconfig | 13 ++ drivers/usb/typec/ucsi/Makefile | 1 + drivers/usb/typec/ucsi/cros_ec_ucsi.c | 273 ++++++++++++++++++++++++++ 4 files changed, 294 insertions(+) create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi.c diff --git a/MAINTAINERS b/MAINTAINERS index fe83ba7194ea..8c030ea0b503 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5300,6 +5300,13 @@ L: chrome-platform@lists.linux.dev S: Maintained F: drivers/watchdog/cros_ec_wdt.c +CHROMEOS UCSI DRIVER +M: Abhishek Pandit-Subedi +M: Łukasz Bartosik +L: chrome-platform@lists.linux.dev +S: Maintained +F: drivers/usb/typec/ucsi/cros_ec_ucsi.c + CHRONTEL CH7322 CEC DRIVER M: Joe Tessler L: linux-media@vger.kernel.org diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig index 680e1b87b152..75559601fe8f 100644 --- a/drivers/usb/typec/ucsi/Kconfig +++ b/drivers/usb/typec/ucsi/Kconfig @@ -69,6 +69,19 @@ config UCSI_PMIC_GLINK To compile the driver as a module, choose M here: the module will be called ucsi_glink. +config CROS_EC_UCSI + tristate "UCSI Driver for ChromeOS EC" + depends on MFD_CROS_EC_DEV + depends on CROS_USBPD_NOTIFY + 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 UCSI_LENOVO_YOGA_C630 tristate "UCSI Interface Driver for Lenovo Yoga C630" depends on EC_LENOVO_YOGA_C630 diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile index aed41d23887b..be98a879104d 100644 --- a/drivers/usb/typec/ucsi/Makefile +++ b/drivers/usb/typec/ucsi/Makefile @@ -21,4 +21,5 @@ obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o +obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c new file mode 100644 index 000000000000..20e608097fc6 --- /dev/null +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -0,0 +1,273 @@ +// 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 + +#include "ucsi.h" + +/* + * Maximum size in bytes of a UCSI message between AP and EC + */ +#define MAX_EC_DATA_SIZE 256 + +/* + * Maximum time in miliseconds the cros_ec_ucsi driver + * will wait for a response to a command or and ack. + */ +#define WRITE_TMO_MS 5000 + +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_read_version(struct ucsi *ucsi, u16 *version) +{ + return cros_ucsi_read(ucsi, UCSI_VERSION, version, sizeof(*version)); +} + +static int cros_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) +{ + return cros_ucsi_read(ucsi, UCSI_CCI, cci, sizeof(*cci)); +} + +static int cros_ucsi_read_message_in(struct ucsi *ucsi, void *val, + size_t val_len) +{ + return cros_ucsi_read(ucsi, UCSI_MESSAGE_IN, val, val_len); +} + +static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd) +{ + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); + u8 ec_buf[sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd)]; + struct ec_params_ucsi_ppm_set *req = (struct ec_params_ucsi_ppm_set *) ec_buf; + int ret; + + req->offset = UCSI_CONTROL; + memcpy(req->data, &cmd, sizeof(cmd)); + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET, + req, sizeof(ec_buf), 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_control(struct ucsi *ucsi, u64 cmd) +{ + struct cros_ucsi_data *udata = ucsi_get_drvdata(ucsi); + bool ack = UCSI_COMMAND(cmd) == 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_control(ucsi, cmd); + 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_version = cros_ucsi_read_version, + .read_cci = cros_ucsi_read_cci, + .read_message_in = cros_ucsi_read_message_in, + .async_control = cros_ucsi_async_control, + .sync_control = cros_ucsi_sync_control, +}; + +static void cros_ucsi_work(struct work_struct *work) +{ + struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work); + u32 cci; + + if (cros_ucsi_read_cci(udata->ucsi, &cci)) + return; + + if (UCSI_CCI_CONNECTOR(cci)) + ucsi_connector_change(udata->ucsi, UCSI_CCI_CONNECTOR(cci)); + + if (cci & UCSI_CCI_ACK_COMPLETE && + test_and_clear_bit(ACK_PENDING, &udata->flags)) + complete(&udata->complete); + if (cci & UCSI_CCI_COMMAND_COMPLETE && + test_and_clear_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 void cros_ucsi_destroy(struct cros_ucsi_data *udata) +{ + cros_usbpd_unregister_notify(&udata->nb); + cancel_work_sync(&udata->work); + ucsi_destroy(udata->ucsi); +} + +static int cros_ucsi_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct cros_ec_dev *ec_data = dev_get_drvdata(dev->parent); + struct cros_ucsi_data *udata; + int ret; + + udata = devm_kzalloc(dev, sizeof(*udata), GFP_KERNEL); + if (!udata) + return -ENOMEM; + + udata->dev = dev; + + udata->ec = ec_data->ec_dev; + if (!udata->ec) { + dev_err(dev, "couldn't find parent EC device"); + return -ENODEV; + } + + platform_set_drvdata(pdev, udata); + + INIT_WORK(&udata->work, cros_ucsi_work); + init_completion(&udata->complete); + + udata->ucsi = ucsi_create(dev, &cros_ucsi_ops); + if (IS_ERR(udata->ucsi)) { + dev_err(dev, "failed to allocate UCSI instance"); + return PTR_ERR(udata->ucsi); + } + + ucsi_set_drvdata(udata->ucsi, udata); + + udata->nb.notifier_call = cros_ucsi_event; + ret = cros_usbpd_register_notify(&udata->nb); + if (ret) { + dev_err(dev, "failed to register notifier: error=%d", ret); + ucsi_destroy(udata->ucsi); + return ret; + } + + ret = ucsi_register(udata->ucsi); + if (ret) { + dev_err(dev, "failed to register UCSI: error=%d", ret); + cros_ucsi_destroy(udata); + return ret; + } + + return 0; +} + +static void cros_ucsi_remove(struct platform_device *dev) +{ + struct cros_ucsi_data *udata = platform_get_drvdata(dev); + + ucsi_unregister(udata->ucsi); + cros_ucsi_destroy(udata); +} + +static int __maybe_unused cros_ucsi_suspend(struct device *dev) +{ + struct cros_ucsi_data *udata = dev_get_drvdata(dev); + + cancel_work_sync(&udata->work); + + return 0; +} + +static int __maybe_unused 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 const struct platform_device_id cros_ucsi_id[] = { + { KBUILD_MODNAME, 0 }, + {} +}; +MODULE_DEVICE_TABLE(platform, cros_ucsi_id); + +static struct platform_driver cros_ucsi_driver = { + .driver = { + .name = KBUILD_MODNAME, + .pm = &cros_ucsi_pm_ops, + }, + .id_table = cros_ucsi_id, + .probe = cros_ucsi_probe, + .remove = cros_ucsi_remove, +}; + +module_platform_driver(cros_ucsi_driver); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("UCSI driver for ChromeOS EC"); From patchwork Tue Sep 10 10:15:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798283 Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (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 2CF7A191F6F for ; Tue, 10 Sep 2024 10:15:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963343; cv=none; b=izlyBQ3N8cfyu/VHqJUs/ANGb2LFWjvN1WcZ/NFVRjnB0VjWcyD327pM5WdhFlyJpzzrxhE8ynIqS5VYDf4VkJICa3LhLqzVj+LUidRZCvI0RUuecRiaNhSWrrH83c9AeVCMV2wuSAOn2Z998nzC4d6zoyrDlx5Vym8SbicFhmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963343; c=relaxed/simple; bh=lKcBF8gwOmt/ffGeVilM/VC//BkP07Qg7KfFhbt/ATM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=cBiRzvwAHH4eXhsepOVD2oUME2XLnR7/skFgM25fUbyaaxJSqw9UUcQONmZLW8mxyTJBAcG1bjUr6usLGamBoeFQRz7Cne0x6YE83PVD3KCTVWHyJZTGHWFTdWcD38rILdXK43vNLySEUocH79ZHB5xXlEVRC9i9MnkkB/C/G2Y= 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=Z4EYK9ZG; arc=none smtp.client-ip=209.85.167.54 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="Z4EYK9ZG" Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-5365d3f9d34so3775392e87.3 for ; Tue, 10 Sep 2024 03:15:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963340; x=1726568140; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=d8X/ITKpB8AA7PfOztOSGy2OE3K0m/AlkMzm5sCSbuU=; b=Z4EYK9ZG5x1MKw+GVqaG52QEQQUwjtbIDAkoFvM38To1ia91Rr2Wge577akSNizY3z 24+DraoROblg73wM6o7a+8byYwsKozGMdBmYwWnei8SbdSbBmUVuLhgMyB2nlKZbhjuL zNhKFDEGbWgykbafvPhtR1LSrugXt7Gyz/bog= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963340; x=1726568140; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=d8X/ITKpB8AA7PfOztOSGy2OE3K0m/AlkMzm5sCSbuU=; b=FERhpUtAHa4dBb6qbsMh25cvHDidp5nLgcTkCU4nOiktfuwBGcLwoihK+0ushd6kT+ +15Wydu8AQ+6Mmc3h4f2tcRmpdkNFbsSFMqkdDZqy8TF0lNBEL41Qtsfrogkam7mS18v fqfzxxZhkvg2SLaAHy/TYJ7jjHWAogB/RUc2FuiYsgmqPoroJzUuEu7pm4p/szxOaZ60 58JnoOSIf0qxRdev4qO8EyCFf/OCfwf5EyVXPY6MyPNyY8pYXx0g0gBHySspyQsBfxtf HPHAQgC7rtpzGI50eYwJTWIhs1QjLkPfHELxUXeeR5L1IRQcxrcy+A6EbtSw1fI5V0hT sH2g== X-Forwarded-Encrypted: i=1; AJvYcCUB7OyAzzXs9YYXviFAjIpT/3ltJDkEg3mHzEtvM9qr6lCpLlKhBeNd3GgvQQVLBjDdG4CGLNzFbsFT7zop6YM=@lists.linux.dev X-Gm-Message-State: AOJu0YxilQJ9WOOaeA+pByLgK7FLPuEspxRAi6ceGflt4z4nc8dCEMPw HLnQJnj2AoBFqXJGya0NF4/9NtLTg7PdvOuOr7UAQjcsfCqDsAZS2ZkFMQpC X-Google-Smtp-Source: AGHT+IEmWkkPyz1oxTksKWySx9B5Qd1qQQdKYCW6OpqyNaZ/PupJucqIzyjiUeUuE62f//tDSeOB4w== X-Received: by 2002:a05:6512:695:b0:52e:97b3:42a1 with SMTP id 2adb3069b0e04-536587b2c9emr7792710e87.24.1725963340124; Tue, 10 Sep 2024 03:15:40 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:39 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 4/8] usb: typec: cros_ec_ucsi: Use complete instead of resume Date: Tue, 10 Sep 2024 10:15:23 +0000 Message-ID: <20240910101527.603452-5-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Abhishek Pandit-Subedi On platforms using cros_ec_lpc, resume is split into .resume_early and .complete. To avoid missing EC events, use .complete to schedule work when resuming. Signed-off-by: Abhishek Pandit-Subedi Signed-off-by: Łukasz Bartosik --- drivers/usb/typec/ucsi/cros_ec_ucsi.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c index 20e608097fc6..422b3b14028c 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -241,15 +241,18 @@ static int __maybe_unused cros_ucsi_suspend(struct device *dev) return 0; } -static int __maybe_unused cros_ucsi_resume(struct device *dev) +static void __maybe_unused cros_ucsi_complete(struct device *dev) { struct cros_ucsi_data *udata = dev_get_drvdata(dev); - - return ucsi_resume(udata->ucsi); + ucsi_resume(udata->ucsi); } -static SIMPLE_DEV_PM_OPS(cros_ucsi_pm_ops, cros_ucsi_suspend, - cros_ucsi_resume); +static const struct dev_pm_ops cros_ucsi_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .suspend = cros_ucsi_suspend, + .complete = cros_ucsi_complete, +#endif +}; static const struct platform_device_id cros_ucsi_id[] = { { KBUILD_MODNAME, 0 }, From patchwork Tue Sep 10 10:15:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798284 Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) (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 59608191F82 for ; Tue, 10 Sep 2024 10:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963346; cv=none; b=W5MVLkICXf4cNCR4upHA4DvjgQ0lv7PKwG5eK/EsMxZbk7e2FOt6zD/J6wshvnUMByXlletr1TyRMDgN+tI1B+RjrNWT9vZQpC6BZKVaW5HqnJ9vhk/O3Rq5+fbjnDS8dFOXSeG5ttgYepgQXpjG9FWD70vzZQ0elKPaKIGCJ/U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963346; c=relaxed/simple; bh=DL0ES7GQTcBR+O0ekDUc5sXgU65md8CXp2+82FUPG+M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=O6H/OS0BJojUrDETEMkacruMoxfatcPaDOB4XjxgqBdh3shfdk2R305avSoCIwjBvxLio4vt5uh0G/QcQinYcd4eNTxBOu+hxINP14VPj2WyKuQ8ACSf2GUtwCTZjMXzmfTJamW4ddOAxAkqH2ozTt1kCyoaQr10lK3xR+LzZnY= 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=ZGbHcANU; arc=none smtp.client-ip=209.85.208.54 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="ZGbHcANU" Received: by mail-ed1-f54.google.com with SMTP id 4fb4d7f45d1cf-5c3d8d3ebbdso1301881a12.0 for ; Tue, 10 Sep 2024 03:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963343; x=1726568143; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0mV7s2/c0ENI+DAgLmXgDu7uFl4rCLD3wDrwUZ7SKho=; b=ZGbHcANUh5RaVVS+hgKUxkuM3nkj1qWqDKjEoxX2z4PsXoYM7J280HGoP/aJCT6oCx NK/IDjACuRWQ1iBx0nhz8qIcDaq61yu2zaIzRszQVwhcVVvJlzlAef8frXINn+q4xH79 x/6yfk8ublPOnp+kKDKBRQwCyhL5qQm5ZDRcc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963343; x=1726568143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0mV7s2/c0ENI+DAgLmXgDu7uFl4rCLD3wDrwUZ7SKho=; b=OHyZMoUoSV4QW7IeRRQ0k3BwmeLIE4zF/RFghXNLRg4UmwbEddgCPI47I+hUhtDTve vr2fATYVJ7qyeiy76Dfv79OJT49BwpFmSxg1zzJ2j0GrNpG3Gn5WJsuF3IuO3zAMxayw AbJhYBtyseNEFn811hXXKPYzgNE121WDN0liL28LP0u51yuy3KC2Gw2m5OJiUfqfXtGN WtJVPj6suPmqFfnyzT2XEWknFNIihn2pUXGXZf3U6cPUQwu6zMI/nk5q6wd5HMMbsDpf Ds7PZaNu/jzrVqN5KVw1YmvLQhqPBI2t2qu05rNJ9Tshc01e4FcEoJ37fDJg9HQlTojE ZwcQ== X-Forwarded-Encrypted: i=1; AJvYcCUzrtQtHzn6+3XAn96vpZp9XXI5ssAgMRxfN7I9wgMbL7Ai8fNUNcSG5lCqXly5rIvb52uJlz0b2Y/xbTNwEN8=@lists.linux.dev X-Gm-Message-State: AOJu0Yxa/Kko3NxLyXy8EIuHJzhWT0xH0eS5o1fqhzFdaZrRqEVSSmeN 4IRH1SCaplUzx/+CMgTDgNA7Enm5fbYt+G2v7INJh7oS/zxdSaoLYT7B2aDo X-Google-Smtp-Source: AGHT+IHMlhonJbaZfa1GMj5EzQdDJRpA3hiqFQeMvTdoDzv0sPWqFnTEoc1JUOnwydyVp91uXQ7R0Q== X-Received: by 2002:a05:6402:4315:b0:5be:d595:5413 with SMTP id 4fb4d7f45d1cf-5c4015ce1b3mr2683973a12.3.1725963341881; Tue, 10 Sep 2024 03:15:41 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:40 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 5/8] usb: typec: cros_ec_ucsi: Add trace events Date: Tue, 10 Sep 2024 10:15:24 +0000 Message-ID: <20240910101527.603452-6-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add trace events to ChromeOS UCSI driver to enable debugging. Signed-off-by: Łukasz Bartosik --- MAINTAINERS | 1 + drivers/usb/typec/ucsi/cros_ec_ucsi.c | 8 ++ drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h | 92 +++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h diff --git a/MAINTAINERS b/MAINTAINERS index 8c030ea0b503..d084f32208f0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5306,6 +5306,7 @@ M: Łukasz Bartosik L: chrome-platform@lists.linux.dev S: Maintained F: drivers/usb/typec/ucsi/cros_ec_ucsi.c +F: drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h CHRONTEL CH7322 CEC DRIVER M: Joe Tessler diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi.c index 422b3b14028c..70185616ec86 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -16,7 +16,9 @@ #include #include +#define CREATE_TRACE_POINTS #include "ucsi.h" +#include "cros_ec_ucsi_trace.h" /* * Maximum size in bytes of a UCSI message between AP and EC @@ -62,6 +64,8 @@ static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val, dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_GET: error=%d", ret); return ret; } + + trace_cros_ec_opm_to_ppm_rd(offset, val, val_len); return 0; } @@ -96,6 +100,8 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd) dev_warn(udata->dev, "Failed to send EC message UCSI_PPM_SET: error=%d", ret); return ret; } + + trace_cros_ec_opm_to_ppm_wr(req->offset, &cmd, sizeof(cmd)); return 0; } @@ -138,6 +144,8 @@ static void cros_ucsi_work(struct work_struct *work) struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work); u32 cci; + trace_cros_ec_ppm_to_opm(0); + if (cros_ucsi_read_cci(udata->ucsi, &cci)) return; diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h b/drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h new file mode 100644 index 000000000000..b765ef5c8236 --- /dev/null +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#undef TRACE_SYSTEM +#define TRACE_SYSTEM cros_ec_ucsi + +#if !defined(__CROS_EC_UCSI_TRACE_H) || defined(TRACE_HEADER_MULTI_READ) +#define __CROS_EC_UCSI_TRACE_H + +#include + +#define decode_cmd(cmd) \ + __print_symbolic(cmd, \ + { 0, "Unknown command" }, \ + { UCSI_PPM_RESET, "PPM_RESET" }, \ + { UCSI_CONNECTOR_RESET, "CONNECTOR_RESET," }, \ + { UCSI_ACK_CC_CI, "ACK_CC_CI" }, \ + { UCSI_SET_NOTIFICATION_ENABLE, "SET_NOTIFICATION_ENABLE" }, \ + { UCSI_GET_CAPABILITY, "GET_CAPABILITY" }, \ + { UCSI_GET_CONNECTOR_CAPABILITY, "GET_CONNECTOR_CAPABILITY" }, \ + { UCSI_SET_UOM, "SET_UOM" }, \ + { UCSI_SET_UOR, "SET_UOR" }, \ + { UCSI_SET_PDM, "SET_PDM" }, \ + { UCSI_SET_PDR, "SET_PDR" }, \ + { UCSI_GET_ALTERNATE_MODES, "GET_ALTERNATE_MODES" }, \ + { UCSI_GET_CAM_SUPPORTED, "GET_CAM_SUPPORTED" }, \ + { UCSI_GET_CURRENT_CAM, "GET_CURRENT_CAM" }, \ + { UCSI_SET_NEW_CAM, "SET_NEW_CAM" }, \ + { UCSI_GET_PDOS, "GET_PDOS" }, \ + { UCSI_GET_CABLE_PROPERTY, "GET_CABLE_PROPERTY" }, \ + { UCSI_GET_CONNECTOR_STATUS, "GET_CONNECTOR_STATUS" }, \ + { UCSI_GET_ERROR_STATUS, "GET_ERROR_STATUS" }) + +#define decode_offset(offset) \ + __print_symbolic(offset, \ + { UCSI_VERSION, "VER" }, \ + { UCSI_CCI, "CCI" }, \ + { UCSI_CONTROL, "CTRL" }, \ + { UCSI_MESSAGE_IN, "MSG_IN" }, \ + { UCSI_MESSAGE_OUT, "MSG_OUT" }, \ + { UCSIv2_MESSAGE_OUT, "MSG_OUTv2" }) + +DECLARE_EVENT_CLASS(cros_ec_opm_to_ppm, + TP_PROTO(u16 offset, const void *value, size_t length), + TP_ARGS(offset, value, length), + TP_STRUCT__entry( + __field(u8, cmd) + __field(u16, offset) + __field(size_t, length) + __dynamic_array(char, msg, length) + ), + TP_fast_assign( + __entry->cmd = *((u64 *) value + 3); + __entry->offset = offset; + __entry->length = length; + memcpy(__get_dynamic_array(msg), value, length); + ), + TP_printk("(%s) %s: %s", + decode_offset(__entry->offset), + __entry->offset == UCSI_CONTROL ? + decode_cmd(__entry->cmd) : "", + __print_hex(__get_dynamic_array(msg), __entry->length)) +); + +DEFINE_EVENT(cros_ec_opm_to_ppm, cros_ec_opm_to_ppm_rd, + TP_PROTO(u16 offset, const void *value, size_t length), + TP_ARGS(offset, value, length) +); + +DEFINE_EVENT(cros_ec_opm_to_ppm, cros_ec_opm_to_ppm_wr, + TP_PROTO(u16 offset, const void *value, size_t length), + TP_ARGS(offset, value, length) +); + +TRACE_EVENT(cros_ec_ppm_to_opm, + TP_PROTO(int x), + TP_ARGS(x), + TP_STRUCT__entry(__array(char, x, 0)), + TP_fast_assign((void)x), + TP_printk("notification%s", "") +); + +#endif /* __CROS_EC_UCSI_TRACE_H */ + +/* This part must be outside protection */ + +#undef TRACE_INCLUDE_PATH +#define TRACE_INCLUDE_PATH . + +#undef TRACE_INCLUDE_FILE +#define TRACE_INCLUDE_FILE cros_ec_ucsi_trace + +#include From patchwork Tue Sep 10 10:15:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798285 Received: from mail-lj1-f178.google.com (mail-lj1-f178.google.com [209.85.208.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 8A4391946C4 for ; Tue, 10 Sep 2024 10:15:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963346; cv=none; b=QLLtHnnOufQpkuLz+Dtxs6fHVM650xtxOj3HOtkNQ3J8FVMwLxS+1F2K8BFhouK1h8ytQtyZP5VF7O9HSBBkaarVvMyzMoRathREnryjOxSghi5MQE72tT+EugAcaG3oyItvZv9DKNSQ7UoJkUGdWZu2OiwipIH2iSW0i7lMbx8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963346; c=relaxed/simple; bh=iXPIP6+YQyOdRHDOYj91I1S82qPxTNJ9cmgwoqMYGps=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CxwtRIETr5NBRB6m7fXQWt8pn6SVkNhvXrq0ZesTa4+MLBPzRER5vBsurW/EgvZHltnW4iFUFf2BkRXOfn9/7MGGc2yIMzPUKMsQmLca5j4Ap+PHhr1mh8Pt5Sp3+PIplnjZHJJ/HEfXFWaCsfjfffVe/LOr7S+uSYCtlQQ6Y/I= 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=obzLczQV; arc=none smtp.client-ip=209.85.208.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="obzLczQV" Received: by mail-lj1-f178.google.com with SMTP id 38308e7fff4ca-2f66423686bso51282911fa.3 for ; Tue, 10 Sep 2024 03:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963343; x=1726568143; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VYHsXwSttfzZMC12xnE6xhPab+ybIDxMmR3RdSOS+3Y=; b=obzLczQV7kmPGaQl5Ym1tnTWsq+W7NHAE8WS0KLLbABh7VoGPRFBXQbmheJkoxnH3v xJ8g8U7VdmEAss/7uUvOIHhJkRRJwFZHhmsKNnPtnF7Vqw3jRaLgzG2t6efFqf9YS5ja hHVz7eKVir+5I3YqDDTbbkfY5jL0WHgIxRsWU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963343; x=1726568143; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VYHsXwSttfzZMC12xnE6xhPab+ybIDxMmR3RdSOS+3Y=; b=pKNg+Wx2uOhZ/MbefhJEQ4/9ogRAFgeNptxAVp1DLJJJ2tpAy6PoADsbbNt53Z7+0w mkagerRyKY8DA5lTJwGVHZuiE37FtmSHqZgR6/r7Zv0NwCyqg0QzgP2P1ApXfUyXN+eZ TTDEjP6IQAqmB+ikP9tiEzbvv7MYV5vHxPx2wEyo1omveFy+yoQ27WalcRF8zsLSxgf/ bwrF4ji0LIHoWTu6S+pzQo2MeQI1vLXh425T9lI1m1PvPqDL4Mdv0j84BMTR9eAeG/ko iU5avfczcwllRewvO3NpSGAhBQRWkaeUTr8XQhLtIVUr2GBHji7aFlwAVhwPUnZ66HX7 IP7Q== X-Forwarded-Encrypted: i=1; AJvYcCXiakeRgnoY0g6hsrfXDDdkOLsalWlguoK8g/Dd+/9L4ScLU7FXePWq470rkusUzYqtI35E8lRMG8B384l7MIA=@lists.linux.dev X-Gm-Message-State: AOJu0Yz6Q2wr9eIYapHon5TVrc9rbTvxczD9cGEEGx6l5+WiGAZZUyZe Q9N7znpcZY6pgKbya0tqsb2rm/QDAeWpebWcxokDETi6QXp3SIZaElPENieS X-Google-Smtp-Source: AGHT+IE5gd9tsanQl8hD6vroVjUks4Szy7+74eAS8FDkQ7MxuIpXNVdiLiYd8bOh8AI3dl/HCa2e8w== X-Received: by 2002:a2e:b8c7:0:b0:2ef:2555:e52f with SMTP id 38308e7fff4ca-2f751f5d04dmr106355401fa.35.1725963342576; Tue, 10 Sep 2024 03:15:42 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:42 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 6/8] usb: typec: cros_ec_ucsi: Add netlink Date: Tue, 10 Sep 2024 10:15:25 +0000 Message-ID: <20240910101527.603452-7-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add netlink to ChromeOS UCSI driver to allow forwarding of UCSI messages to userspace for debugging and testing purposes. Signed-off-by: Łukasz Bartosik --- MAINTAINERS | 4 +- drivers/usb/typec/ucsi/Makefile | 4 +- .../{cros_ec_ucsi.c => cros_ec_ucsi_main.c} | 66 +++++++++++++- drivers/usb/typec/ucsi/cros_ec_ucsi_nl.c | 87 +++++++++++++++++++ drivers/usb/typec/ucsi/cros_ec_ucsi_nl.h | 52 +++++++++++ 5 files changed, 209 insertions(+), 4 deletions(-) rename drivers/usb/typec/ucsi/{cros_ec_ucsi.c => cros_ec_ucsi_main.c} (79%) create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi_nl.c create mode 100644 drivers/usb/typec/ucsi/cros_ec_ucsi_nl.h diff --git a/MAINTAINERS b/MAINTAINERS index d084f32208f0..2afb406a24ce 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5305,7 +5305,9 @@ M: Abhishek Pandit-Subedi M: Łukasz Bartosik L: chrome-platform@lists.linux.dev S: Maintained -F: drivers/usb/typec/ucsi/cros_ec_ucsi.c +F: drivers/usb/typec/ucsi/cros_ec_ucsi_main.c +F: drivers/usb/typec/ucsi/cros_ec_ucsi_nl.c +F: drivers/usb/typec/ucsi/cros_ec_ucsi_nl.h F: drivers/usb/typec/ucsi/cros_ec_ucsi_trace.h CHRONTEL CH7322 CEC DRIVER diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile index be98a879104d..82d960394c39 100644 --- a/drivers/usb/typec/ucsi/Makefile +++ b/drivers/usb/typec/ucsi/Makefile @@ -21,5 +21,7 @@ obj-$(CONFIG_UCSI_ACPI) += ucsi_acpi.o obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o -obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o + +obj-$(CONFIG_CROS_EC_UCSI) += cros_ec_ucsi.o +cros_ec_ucsi-y := cros_ec_ucsi_main.o cros_ec_ucsi_nl.o diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi.c b/drivers/usb/typec/ucsi/cros_ec_ucsi_main.c similarity index 79% rename from drivers/usb/typec/ucsi/cros_ec_ucsi.c rename to drivers/usb/typec/ucsi/cros_ec_ucsi_main.c index 70185616ec86..008b61921278 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi_main.c @@ -19,6 +19,7 @@ #define CREATE_TRACE_POINTS #include "ucsi.h" #include "cros_ec_ucsi_trace.h" +#include "cros_ec_ucsi_nl.h" /* * Maximum size in bytes of a UCSI message between AP and EC @@ -43,6 +44,43 @@ struct cros_ucsi_data { unsigned long flags; }; +/* + * When set to true the cros_ec_ucsi driver will forward all UCSI messages + * exchanged between OPM <-> PPM to userspace through netlink + */ +static bool is_ap_sniffer_en; + +static ssize_t enable_ap_sniffer_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + return sprintf(buf, "%d\n", is_ap_sniffer_en); +} + +static ssize_t enable_ap_sniffer_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + u8 value; + + if (kstrtou8(buf, 0, &value)) + return -EINVAL; + + is_ap_sniffer_en = value ? 1 : 0; + return count; +} + +static DEVICE_ATTR_RW(enable_ap_sniffer); + +static struct attribute *cros_ec_ucsi_attrs[] = { + &dev_attr_enable_ap_sniffer.attr, + NULL +}; + +static const struct attribute_group cros_ec_ucsi_attrs_grp = { + .attrs = cros_ec_ucsi_attrs, +}; + static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val, size_t val_len) { @@ -65,6 +103,9 @@ static int cros_ucsi_read(struct ucsi *ucsi, unsigned int offset, void *val, return ret; } + if (is_ap_sniffer_en) + nl_cros_ec_bcast_msg(NL_CROS_EC_TO_PPM, NL_CROS_EC_RD, offset, + val, val_len); trace_cros_ec_opm_to_ppm_rd(offset, val, val_len); return 0; } @@ -101,6 +142,9 @@ static int cros_ucsi_async_control(struct ucsi *ucsi, u64 cmd) return ret; } + if (is_ap_sniffer_en) + nl_cros_ec_bcast_msg(NL_CROS_EC_TO_PPM, NL_CROS_EC_WR, + req->offset, (u8 *) &cmd, sizeof(cmd)); trace_cros_ec_opm_to_ppm_wr(req->offset, &cmd, sizeof(cmd)); return 0; } @@ -144,6 +188,8 @@ static void cros_ucsi_work(struct work_struct *work) struct cros_ucsi_data *udata = container_of(work, struct cros_ucsi_data, work); u32 cci; + if (is_ap_sniffer_en) + nl_cros_ec_bcast_msg(NL_CROS_EC_TO_OPM, 0, 0, NULL, 0); trace_cros_ec_ppm_to_opm(0); if (cros_ucsi_read_cci(udata->ucsi, &cci)) @@ -229,13 +275,29 @@ static int cros_ucsi_probe(struct platform_device *pdev) return ret; } + ret = nl_cros_ec_register(); + if (ret) { + dev_err(dev, "failed to register netlink: error=%d", ret); + cros_ucsi_destroy(udata); + return ret; + } + + ret = sysfs_create_group(&dev->kobj, &cros_ec_ucsi_attrs_grp); + if (ret) { + dev_err(dev, "failed to register sysfs group: error=%d", ret); + cros_ucsi_destroy(udata); + return ret; + } + return 0; } -static void cros_ucsi_remove(struct platform_device *dev) +static void cros_ucsi_remove(struct platform_device *pdev) { - struct cros_ucsi_data *udata = platform_get_drvdata(dev); + struct cros_ucsi_data *udata = platform_get_drvdata(pdev); + sysfs_remove_group(&pdev->dev.kobj, &cros_ec_ucsi_attrs_grp); + nl_cros_ec_unregister(); ucsi_unregister(udata->ucsi); cros_ucsi_destroy(udata); } diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi_nl.c b/drivers/usb/typec/ucsi/cros_ec_ucsi_nl.c new file mode 100644 index 000000000000..360568044891 --- /dev/null +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi_nl.c @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include "cros_ec_ucsi_nl.h" + +static const struct genl_multicast_group nl_mc_grps[] = { + { .name = NL_CROS_EC_MC_GRP_NAME }, +}; + +static struct genl_family genl_fam = { + .name = NL_CROS_EC_NAME, + .version = NL_CROS_EC_VER, + .maxattr = NL_CROS_EC_A_MAX, + .mcgrps = nl_mc_grps, + .n_mcgrps = ARRAY_SIZE(nl_mc_grps), +}; + +int nl_cros_ec_register(void) +{ + return genl_register_family(&genl_fam); +} + +void nl_cros_ec_unregister(void) +{ + genl_unregister_family(&genl_fam); +} + +int nl_cros_ec_bcast_msg(enum nl_cros_ec_msg_dir dir, + enum nl_cros_ec_cmd_type cmd_type, + u16 offset, const u8 *payload, size_t msg_size) +{ + struct timespec64 ts; + struct sk_buff *skb; + int ret = -ENOMEM; + void *hdr; + + skb = genlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!skb) + return -ENOMEM; + + hdr = genlmsg_put(skb, 0, 0, &genl_fam, 0, NL_CROS_EC_C_UCSI); + if (!hdr) + goto free_mem; + + ret = nla_put_u8(skb, NL_CROS_EC_A_SRC, NL_CROS_EC_AP); + if (ret) + goto cancel; + + ret = nla_put_u8(skb, NL_CROS_EC_A_DIR, dir); + if (ret) + goto cancel; + + ret = nla_put_u16(skb, NL_CROS_EC_A_OFFSET, offset); + if (ret) + goto cancel; + + ret = nla_put_u8(skb, NL_CROS_EC_A_CMD_TYPE, cmd_type); + if (ret) + goto cancel; + + ktime_get_ts64(&ts); + ret = nla_put_u32(skb, NL_CROS_EC_A_TSTAMP_SEC, (u32)ts.tv_sec); + if (ret) + goto cancel; + + ret = nla_put_u32(skb, NL_CROS_EC_A_TSTAMP_USEC, + (u32)(ts.tv_nsec/1000)); + if (ret) + goto cancel; + + ret = nla_put(skb, NL_CROS_EC_A_PAYLOAD, msg_size, payload); + if (ret) + goto cancel; + + genlmsg_end(skb, hdr); + + ret = genlmsg_multicast(&genl_fam, skb, 0, 0, GFP_KERNEL); + if (ret && ret != -ESRCH) + goto free_mem; + + return 0; +cancel: + genlmsg_cancel(skb, hdr); +free_mem: + nlmsg_free(skb); + return ret; +} diff --git a/drivers/usb/typec/ucsi/cros_ec_ucsi_nl.h b/drivers/usb/typec/ucsi/cros_ec_ucsi_nl.h new file mode 100644 index 000000000000..c6192d8ace56 --- /dev/null +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi_nl.h @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef __DRIVER_USB_TYPEC_CROS_EC_UCSI_NL_H +#define __DRIVER_USB_TYPEC_CROS_EC_UCSI_NL_H + +#define NL_CROS_EC_NAME "cros_ec_ucsi" +#define NL_CROS_EC_VER 1 +#define NL_CROS_EC_MC_GRP_NAME "cros_ec_ucsi_mc" + +/* attributes */ +enum nl_cros_ec_attrs { + NL_CROS_EC_A_SRC, + NL_CROS_EC_A_DIR, + NL_CROS_EC_A_OFFSET, + NL_CROS_EC_A_CMD_TYPE, + NL_CROS_EC_A_TSTAMP_SEC, + NL_CROS_EC_A_TSTAMP_USEC, + NL_CROS_EC_A_PAYLOAD, + NL_CROS_EC_A_MAX +}; + +enum nl_cros_ec_cmds { + NL_CROS_EC_C_UCSI, + NL_CROS_EC_C_MAX +}; + +/* where message was captured - EC or AP */ +enum nl_cros_ec_src { + NL_CROS_EC_AP, + NL_CROS_EC_EC +}; + +/* message destination */ +enum nl_cros_ec_msg_dir { + NL_CROS_EC_TO_PPM, + NL_CROS_EC_TO_OPM, + NL_CROS_EC_TO_LPM +}; + +/* command type - read or write */ +enum nl_cros_ec_cmd_type { + NL_CROS_EC_RD, + NL_CROS_EC_WR +}; + +int nl_cros_ec_register(void); +void nl_cros_ec_unregister(void); +int nl_cros_ec_bcast_msg(enum nl_cros_ec_msg_dir dir, + enum nl_cros_ec_cmd_type cmd_type, + u16 offset, const u8 *payload, size_t msg_size); + +#endif /* __DRIVER_USB_TYPEC_CROS_EC_UCSI_NL_H */ From patchwork Tue Sep 10 10:15:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798286 Received: from mail-ed1-f42.google.com (mail-ed1-f42.google.com [209.85.208.42]) (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 8E4D118CC17 for ; Tue, 10 Sep 2024 10:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963347; cv=none; b=CtFdvpkFahGp60YeyHJ79ei7iap7+ZB9FMrB/uExYSs19buog8lUkGHwkFS+PGbu8E0JFEWJjWPDJMsuVmVWkKg8CyIvavqsb5lcu9jUbVgQWAsrToj5CDB6Z2InUDd4+l1WAQcLhn1IGtGYxKwRdiu5ObUyvqb4C4Tk2MLiyXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963347; c=relaxed/simple; bh=YD468ry7hUMKcsYIUjPS512IHcVzElRgJKXYwiiKeKU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=ivL9AkOHhgTYRB+CgT5Ahs4jsPnD9DfuIgU62R0yHsfidffIvhgnQazpqf3aPypBSAUFgcuIxTWpQXgTbjIpoowxbBrljv7iRut19M32T53jjZ5jVRNH45q1jRwC2eMCfR6+YoC60TUFpI4U63goqErRIDTsoFItTpHpjKxOgsk= 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=i3p2lkUT; arc=none smtp.client-ip=209.85.208.42 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="i3p2lkUT" Received: by mail-ed1-f42.google.com with SMTP id 4fb4d7f45d1cf-5c241feb80dso12183902a12.0 for ; Tue, 10 Sep 2024 03:15:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963344; x=1726568144; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FeqFZCtBiSpM67nMSPMG8nnVJnw0zyk4FGk4Kpm9II8=; b=i3p2lkUTX/wamyksS4/jueezFYXF3eIchptqPtzLvWh//ZJ69Lz/vrolbWIxySpPfP 4Ucrda+vJFCqS99c/Bue5NgRfa3G1s7X9+gPNhWOM9Ct1EcacYoJv81WBfsaSUA6kd/4 v0XCoTr75qh4Gb94J3ALomA11rY652NjxIKIo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963344; x=1726568144; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FeqFZCtBiSpM67nMSPMG8nnVJnw0zyk4FGk4Kpm9II8=; b=qCsVevkqrHEaWcsGlylnQOczOaFqIRHCgP266cjaTf3fOlm9DKs3sDQqnMSWIwKKjm lYv2ODtTCfMLcASfKr27N0pGnLjRGubJJ2Fe7jqlpEyuSTsVi7nyuqVMfogLAazI6M34 FM1D+pD7gJbsWbdhlmVr8+Ezu8Kwy8Drta+ClaerqXN5ZSglfr0y3QYnPzPvJYINRImT UO1SFgpyWRclI/OfFFJmTtVr0CTXSb0meq52cefRH1UGcxOMh3lK1Oc3AcJI7YTVW3N5 M06e7+5poAkVDt04JdIzPlGYE0mSqSHFgFumVy0wCu5a1t0nJUO24y5HyLqdNkkzSDiE Yleg== X-Forwarded-Encrypted: i=1; AJvYcCXO+9Yf+z0lCZwqg6uf8JTqvvrlJrUcjMzIeLpkOjTZTus6puxPECDvtDHL7x8K1Fdq/TfyukQeFIaoVH0Ad5I=@lists.linux.dev X-Gm-Message-State: AOJu0YyU11C/WP7fcIYbRwE4uaLvMmRXvoGkoSZKvyhwr+h9e3QNhHX2 yQsh7YXmqS23IypyNcyExdk6F5la2M4jz2hIaQhwb6WvHq8NEMliHCtGmd80 X-Google-Smtp-Source: AGHT+IFMu22ltsq0YAzHIeMzdsOV+gf/uOgHmWy5zGWIum1KNPXBI5poW2rPcZak4GbDH82Fy3I0TQ== X-Received: by 2002:a05:6402:51cb:b0:5c2:7009:b223 with SMTP id 4fb4d7f45d1cf-5c4015ce1bemr2907203a12.1.1725963343031; Tue, 10 Sep 2024 03:15:43 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:42 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 7/8] mfd: cros_ec: Load cros_ec_ucsi on supported ECs Date: Tue, 10 Sep 2024 10:15:26 +0000 Message-ID: <20240910101527.603452-8-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Pavan Holla Load cros_ec_ucsi driver if the ChromeOS EC implements UCSI Platform Policy Manager (PPM). Signed-off-by: Pavan Holla Signed-off-by: Łukasz Bartosik --- drivers/mfd/cros_ec_dev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index e2aae8918679..d5d63df7fcbd 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -108,6 +108,10 @@ static const struct mfd_cell cros_ec_keyboard_leds_cells[] = { { .name = "cros-keyboard-leds", }, }; +static const struct mfd_cell cros_ec_ucsi_cells[] = { + { .name = "cros_ec_ucsi", }, +}; + static const struct cros_feature_to_cells cros_subdevices[] = { { .id = EC_FEATURE_CEC, @@ -124,6 +128,11 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_ec_rtc_cells, .num_cells = ARRAY_SIZE(cros_ec_rtc_cells), }, + { + .id = EC_FEATURE_UCSI_PPM, + .mfd_cells = cros_ec_ucsi_cells, + .num_cells = ARRAY_SIZE(cros_ec_ucsi_cells), + }, { .id = EC_FEATURE_USB_PD, .mfd_cells = cros_usbpd_charger_cells, From patchwork Tue Sep 10 10:15:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13798287 Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (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 8CA9619AD81 for ; Tue, 10 Sep 2024 10:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963349; cv=none; b=U5wYfkfM+h1l47NPSftynfy+I7rtXI20/1+4e5Ov8F/RLB/3kl8PhxwUvtzVpl8mpPx6ZxFDwrBJnP+XK3A7aSwH5NSzqetazl1scb0xPXo3bQgXY92LtAizTmwRdJBQrwwpaQAtY10YNrP2gfcERJxuoGIKTGCuYnpbiIKYW1w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725963349; c=relaxed/simple; bh=tSQJHbj2LLXTeUHGgMMfJ5BWAL/nLVLLEk1C+o3nHws=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BmDVnHvjO43bC8g+W02UlK43lf2gHiQHm9t+ZvGqp1E/1mWrEH0J+Cw4Rov7Khv8+uISxeE96NV/OEJxg04UND5H4Ih+wB41LBykRMglxdqBFD/I/z1enkqzzr9x1AQNrYjTXyq0jf5wmsRFZ3XFTrLqoXVK7RtRmluKAfX5DPM= 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=krsaad2a; arc=none smtp.client-ip=209.85.208.179 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="krsaad2a" Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2f754d4a6e4so44062931fa.3 for ; Tue, 10 Sep 2024 03:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725963346; x=1726568146; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=e6E5yTq083nuSzrDbz7WTLj5zuoz2JOMDpjBBNEDmzQ=; b=krsaad2aAqmL+JbWkWMUHqx5iQkFj7dXxwuX3ASlvqQO731f3gLQ62XneW8wl45BUc cYj0yBdamktfyuMB5GIsojBQGkryVEKYWA6E0IOoFoe84FaKm9AX7NU4g8lv7bMhEGrl im1Ag95QBC1uHEsIBFmqbGshqHHPTTz/sDjVk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725963346; x=1726568146; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=e6E5yTq083nuSzrDbz7WTLj5zuoz2JOMDpjBBNEDmzQ=; b=kbuQq5KdhpASeusBl29g5lxlgb8z7roxfZzVvCnfY734wlIM6C0L0ryYV+eQ6CP/KA WpL+cPyQHaN0b0aWVhekS53a7eCVma/BQXf1xaKFj8Swgr+GGforN1jxERR9FXeUYp6d +CyxkwYICHqkkW3GZYyez9YuxdD4uEBctBdmtzrCc+769QtV0HTBCk9rV9PiNZMEUNaa DoxdEi1y7ne5g+Nfa12pvy5vtaW6fHNQZ5Qha63ohICj2Gt3cd8BE6luSd6FibQSR1lL oyMUNS4DUqaEtn+XKT7SCPlXYJpgPvF9DhZ4I7ZYGQGgS8ZvuwljPGkuwzFI4g9jJ69S Z2cQ== X-Forwarded-Encrypted: i=1; AJvYcCW63ywWhyvu/C6zWLHvZojgkNyNjDnNGF3bCDocgRuxYT/dvnitTvaSjtHG6myB0gZsSxlK1rGoqB8hPahWlRg=@lists.linux.dev X-Gm-Message-State: AOJu0Yz5osP1KSvjdEmeDZXghTY4+KsFbxWxq+CnHnXt+4m65dn0RUP7 awkaR4S9qh6EiASjcR2Sl52mz2KQFGbXfIhp5msq6VI0hygHNp532yQhDCwt X-Google-Smtp-Source: AGHT+IHaKe6rWjU3xH9ycsM7F8BdbXD7rsT077HrnyCJDew/oIYr2SQOxzYhjp9tGDoTKY9rIz0ULg== X-Received: by 2002:a2e:5109:0:b0:2f5:806:5cee with SMTP id 38308e7fff4ca-2f751ec7daamr64177571fa.11.1725963345513; Tue, 10 Sep 2024 03:15:45 -0700 (PDT) Received: from ukaszb-ng.c.googlers.com.com (140.20.91.34.bc.googleusercontent.com. [34.91.20.140]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c3ebd424f0sm4075401a12.7.2024.09.10.03.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2024 03:15:43 -0700 (PDT) From: =?utf-8?q?=C5=81ukasz_Bartosik?= To: Heikki Krogerus , Greg Kroah-Hartman , Lee Jones , Benson Leung , Guenter Roeck Cc: Abhishek Pandit-Subedi , Pavan Holla , Tzung-Bi Shih , linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Subject: [PATCH v6 8/8] mfd: cros_ec: Don't load charger with UCSI Date: Tue, 10 Sep 2024 10:15:27 +0000 Message-ID: <20240910101527.603452-9-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.598.g6f2099f65c-goog In-Reply-To: <20240910101527.603452-1-ukaszb@chromium.org> References: <20240910101527.603452-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: chrome-platform@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Abhishek Pandit-Subedi When UCSI is enabled, don't load cros_usbpd_charger and cros_usbpd_logger drivers. Charger functionality is provided by the UCSI driver already and logging will need to be added. Signed-off-by: Abhishek Pandit-Subedi Signed-off-by: Łukasz Bartosik --- drivers/mfd/cros_ec_dev.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/mfd/cros_ec_dev.c b/drivers/mfd/cros_ec_dev.c index d5d63df7fcbd..bc083c7b21de 100644 --- a/drivers/mfd/cros_ec_dev.c +++ b/drivers/mfd/cros_ec_dev.c @@ -133,11 +133,6 @@ static const struct cros_feature_to_cells cros_subdevices[] = { .mfd_cells = cros_ec_ucsi_cells, .num_cells = ARRAY_SIZE(cros_ec_ucsi_cells), }, - { - .id = EC_FEATURE_USB_PD, - .mfd_cells = cros_usbpd_charger_cells, - .num_cells = ARRAY_SIZE(cros_usbpd_charger_cells), - }, { .id = EC_FEATURE_HANG_DETECT, .mfd_cells = cros_ec_wdt_cells, @@ -261,6 +256,21 @@ static int ec_device_probe(struct platform_device *pdev) } } + /* + * UCSI provides power supply information so we don't need to separately + * load the cros_usbpd_charger driver. + */ + if (cros_ec_check_features(ec, EC_FEATURE_USB_PD) && + !cros_ec_check_features(ec, EC_FEATURE_UCSI_PPM)) { + retval = mfd_add_hotplug_devices(ec->dev, + cros_usbpd_charger_cells, + ARRAY_SIZE(cros_usbpd_charger_cells)); + + if (retval) + dev_warn(ec->dev, "failed to add usbpd-charger: %d\n", + retval); + } + /* * Lightbar is a special case. Newer devices support autodetection, * but older ones do not.