From patchwork Tue Sep 3 16:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13789061 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 C66051885AF for ; Tue, 3 Sep 2024 16:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381042; cv=none; b=NLQ9UVtRoKTY82Y5ms5J6OE4gCKdIbdfM/cWNmeYnQD2s7pwY6/BQgZCY9t2vTV5O60qwFaYsuDix7rffITrzxVcSCmRgl8R6z0novSWOQTNMHqiGEmWcypZExChpBxvJczgVUOri/mACbqe25T57/o56L0IQRdFiBmkCL3Ls9I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381042; c=relaxed/simple; bh=YoYRUae+dYQ0d52pIU8556BecxqaS32GRkSA+SJ61gE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=a/hrhfwK60h5VTAMZhVwDXk1+chhwF8Avw6wW/bC8a8ME6eU+V8MWUL6ft2dLs91c79YEm+r2Olrzlj0PS13GRY+oEDTdX64NWFhow1/QZhFEIZS60YG+kTwhiPTN0v6Mpzr6+aa+Y7X02xkRoRqznujORl6ojOZ+ym2foTTuww= 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=ZyLEmtWb; arc=none smtp.client-ip=209.85.218.53 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="ZyLEmtWb" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a86abbd68ffso921347466b.0 for ; Tue, 03 Sep 2024 09:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381038; x=1725985838; darn=vger.kernel.org; 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=+TIEYy+uyd2jXHZkwyaKTeT93BGHARFcg0AcutZlTKg=; b=ZyLEmtWbOR81W5x0c7oHltmSDlIbKv8U9AF0W987+NBIfZONk7+TbhRatOm4EsYxk6 pHRICIvCjXB+Osal3NhZBRddXHW3ic6t+ZBWOhJHxJdBpKxUfXSWfWLxFLrQ3SO+QIkb 2dUneqcIUmdkXhey2yRkxwc3d13aSAwWJ15Ag= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381038; x=1725985838; 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=+TIEYy+uyd2jXHZkwyaKTeT93BGHARFcg0AcutZlTKg=; b=u14l7SC1MM0rDUXA67cEyI7yNGopGXLP1GhjFuW5CdkVavfIxmJEoo4llLAC80VfAh TDWEYWJNAEbC1wKWWxfR3IZXdwNAnR3DnW7mj4jO/MVUTSAiTEz4MpCUgaffmu2e9HLt 7Wp12eaaG62EvHpAjaUCdHB06sfrPPpOCxq2uD1Mig3rvq6HA1KAMAPhgk44a2vHaubJ uUnYb9DfhWaBc503lueimL8MXTvlLfalLUGdtH4ivEijjGdHA+h3T5qmAdCU55rlTn28 xX3fZ1HRxQ/k2XoYXbuXii5xrksH6p7dMSFyKjp5aQToeqLk3ENHz1fsnRqhzV5k9Hox RO1g== X-Forwarded-Encrypted: i=1; AJvYcCWU/SLgLWDKxlGdc1q4YISlFeUI1kApXB40JixDMh7eGAe88xqBV/9+5Vr6Cb8Qj6OnqYz2Sbar+dM=@vger.kernel.org X-Gm-Message-State: AOJu0Yw4GZVmCVGCV0SbH2if+sCJSGiQFEQMHyLeHJCMMZ7GYaTVSA/V WZiqNfO7rwy9E9HtxmIlobyGIDTgfWm6vGAyLzFuoW+dpS75eQy+ua31gBDY X-Google-Smtp-Source: AGHT+IEKzUEnyVSCRCC18/H9KWxWbNBNtHfr6WvIUVO7/ZCeHwJZ9cd+GxR/nFZmj5QvFglMz/D6zw== X-Received: by 2002:a17:907:e292:b0:a6e:f869:d718 with SMTP id a640c23a62f3a-a89a2927ae1mr1377312166b.21.1725381037341; Tue, 03 Sep 2024 09:30:37 -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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30: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 v5 1/8] platform/chrome: Update ChromeOS EC header for UCSI Date: Tue, 3 Sep 2024 16:30:26 +0000 Message-ID: <20240903163033.3170815-2-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 --- .../linux/platform_data/cros_ec_commands.h | 22 ++++++++++++++++++- 1 file changed, 21 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..08b6c98ed890 100644 --- a/include/linux/platform_data/cros_ec_commands.h +++ b/include/linux/platform_data/cros_ec_commands.h @@ -5012,8 +5012,10 @@ 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 */ + u32 status; /* PD MCU host event status */ } __ec_align4; /* Set USB type-C port role and muxes */ @@ -6073,6 +6075,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 { + u16 offset; + u8 data[]; +} __ec_align2; + +#define EC_CMD_UCSI_PPM_GET 0x0141 + +struct ec_params_ucsi_ppm_get { + u16 offset; + u8 size; +} __ec_align2; + /*****************************************************************************/ /* The command range 0x200-0x2FF is reserved for Rotor. */ From patchwork Tue Sep 3 16:30:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13789060 Received: from mail-ej1-f52.google.com (mail-ej1-f52.google.com [209.85.218.52]) (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 2CF2218A951 for ; Tue, 3 Sep 2024 16:30:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381041; cv=none; b=lawZnHSyWgmz13YQSS9qZH09Q0ttAwaAV1kjBvXey1z3x7dhee7PYkf68mhH/45xHsjSWp5d7/BonI5J0RiSENes5t33LUnJD/Mh1VGwbz5juiYPhrwWQKv4gNuVO4bY9AsRwLv28BrIr4TumaYEcnj+f+Sc7KpHWo55v6oLGyE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381041; c=relaxed/simple; bh=fTy0stzS7yha36slypwt20Uo6AK6glJZ8X0uewkOtAg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ihseYptzDjO3GmQf7hrj2vaYq9A6+WbggJ2SsH+tFqO+V9M42RfFMXI729mvKuhF6u7YFWla2k67EFJccgVAZL7unEmLyDkYkmncApTUNnZ283exm+11DCPtpujNefMG1WQpTNJkYkcYKkx2lQEp64wP0qd803dZ/u28RUoKgwY= 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=H92zF59h; arc=none smtp.client-ip=209.85.218.52 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="H92zF59h" Received: by mail-ej1-f52.google.com with SMTP id a640c23a62f3a-a86984e035aso671497566b.2 for ; Tue, 03 Sep 2024 09:30:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381038; x=1725985838; darn=vger.kernel.org; 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=wUgbNEkhKAhMTH2sDvk5W7gqHhDqqd1S8pfms1rAE3M=; b=H92zF59hEV7+X0DfDHqolTAmf+AsDM9hVlG8dFhJoymPt9v0+MddhPobSwEsAnHs6r hlzu7Zvkp1pjn9nff0Xl/1M8nigcoJFAeh2j4OD3EbQvENRkZkmDburiLC2+i42K2LnP qmnjtJbVlBq7JH+NAKP9XLfX3BXtx+OWmQd0w= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381038; x=1725985838; 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=wUgbNEkhKAhMTH2sDvk5W7gqHhDqqd1S8pfms1rAE3M=; b=PZV1PdlDLeKr6q1aeKbhLGwXOU+0txtI0H9LAn0nkTPoR4qzmGVNkX7MSO/ULp7str oXZ+O3F79HsBttEfW0qYXDyLA6Kx4Modk9x4T5hFDEpXeZ5l8HyHwhOC6iKVB3lhsHcQ h5pN4h6/3AnGMaPgWe08VjOv0t5X9RDbWj5J4mRYoHSkOyucG+JGix0yrSXXICm4u317 kAekApFON6uhm9zNS7NIiTRMx78inFJosurNphzJnUKjf9OqEs/F83c34+924poARxBo 12hCQubNwwzE6u3eAAup/xs6YiwHa3k+3DNjiZdmN1obnOy9dZLRPa7TqgVVRhY4ae4d jxxA== X-Forwarded-Encrypted: i=1; AJvYcCXpTp3XTP79mVwZSzyJ24xXnI/lHTtde0Ri34OOzCPV+f6Lbw45pmBm8qvs0eGXERow52GnkNy+Jvs=@vger.kernel.org X-Gm-Message-State: AOJu0YwQ3DApNnkUDahx0UGu+EO+282whKDTu8kP9h4tpWNa6gL0AmQX YQWczPCVlwOjv5fzg3U2KhPGgJIyW3Bn49EIyfaUoGn9ICRP2Zq8q40TDlzs X-Google-Smtp-Source: AGHT+IEpqLZizoWT23KCkNz8O9QOEGS3Ya+RF47OFDRd3WiRqN+a/JFqMC37tQh7DBKbDOaj741jFA== X-Received: by 2002:a17:907:980c:b0:a86:8f57:7de0 with SMTP id a640c23a62f3a-a89a37aa9famr994346366b.49.1725381037969; Tue, 03 Sep 2024 09:30:37 -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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30:37 -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 v5 2/8] platform/chrome: Update EC feature flags Date: Tue, 3 Sep 2024 16:30:27 +0000 Message-ID: <20240903163033.3170815-3-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 --- .../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 08b6c98ed890..2998d956ba14 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 3 16:30:28 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: 13789063 Received: from mail-ej1-f53.google.com (mail-ej1-f53.google.com [209.85.218.53]) (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 1F04118BC18 for ; Tue, 3 Sep 2024 16:30:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381045; cv=none; b=RSYNJ+GsS8ePj5dlersBBkX1DJ4NkI7YnlQEKapev+BI8iRW+TnpAH/lZWG7sfr3YZmWrJ6ooZ06Bw99gXooONZfkPHBddUcj4DQdxD3x7V7E//EHdhquE3VNTcnF9fSohZZy5Y1SMUtrI0n3dcslhV13lTtUEBBtcslq6LifTc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381045; c=relaxed/simple; bh=vTRuLlfvWuopIWmn6DVr481Us5MEGp1wGVFB8sy25Eo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=bPM+EXSWYZZyjvsMJ+RT3FaogaefjrdWZSNXN59G3i1phQJM2Ttp0S82mGxGVDZJJml59cr0lE0hsQSYr6P7OZm4JswdFjqhZxaVVHUPxv9V3pwGBFqhOCfX3HE2mMAdjJzLQUMAIBZth797AVqoVYaxYwLQhiJ6b1rqfBLK1hw= 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=KJNusvLo; arc=none smtp.client-ip=209.85.218.53 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="KJNusvLo" Received: by mail-ej1-f53.google.com with SMTP id a640c23a62f3a-a867a564911so657164166b.2 for ; Tue, 03 Sep 2024 09:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381041; x=1725985841; darn=vger.kernel.org; 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=hGNG7VqOqA7a3CcmIQ5Fr+14bO5AQWP3+yZKbMz0Umk=; b=KJNusvLo6CsfFWjzGNOTSbtMvU+bOxL8YqTL9drfr+9keiShAkFTqXzF74e2rNLMj7 t4HbKW8H6IQ5gqV39f+pLetwFs8KWrAYuUZv4029P5IgTkHDF6xUnzBQ79mXbkX56IbE +stJJiBgPzlJ4bQPtCybG1ToivgJRzavo7hD0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381041; x=1725985841; 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=hGNG7VqOqA7a3CcmIQ5Fr+14bO5AQWP3+yZKbMz0Umk=; b=a+W1qw5MMFgq0f2tIGZ4hekvIcn8WUbLIP64APurKP/Xx3Ef2VXVV6+p0FyKMrJHUB q7Gdk4qj1uZCqwqSlSZuAgQKtAF3MmQNsdfTsRtaLaaDzIrx9VR62TIKCBczvhyh+GlI tvHJEuSyYx3dqA4htN8cZG1TJ3Wqi4IIBmvtI97tiRqt+nZVIeiSxb5dGr6WFVnlIx0H mP9wIT43FHcx/+t25gV3E8C3lrvLAgwxke83XwKM6/f3tXiPo2tDsGlH6qpLdxOHkWpg eEtgtQpv9bk39Vw4eEwWKdpwZr3+JQ2ZsBSpERCKBsufKRodw+ooLObIeBcOPZg8Nz9C mqsQ== X-Forwarded-Encrypted: i=1; AJvYcCWUyRg+vb0UjXTMmqYvXrhIx+AkKxLfBofiTNAhKjrLShpZWqjsk+w+kltEnvAWULA1u6Mr1zHplUM=@vger.kernel.org X-Gm-Message-State: AOJu0YyTM9SjkQK0/iRiJUlssMf4dP8gyK7zqQaarBqHFfgWUzRbBzxs ozlwZm97OlDVyoWUQLnumX9RN21dSlp5c5hNySDgBD8hZrwyCFX8BOSMHRbvi80mPD++gEbR/a8 SU4A= X-Google-Smtp-Source: AGHT+IEDE8yHERxFk1NIHAD4Q3IIoyLgyaKQJAXw/JMp+1y4pDlx7RrsMeDQvHXDtGFI4as4x5gJdA== X-Received: by 2002:a17:907:868c:b0:a72:5470:1d6a with SMTP id a640c23a62f3a-a89b956d186mr887477566b.35.1725381040749; Tue, 03 Sep 2024 09:30: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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30:38 -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 v5 3/8] usb: typec: ucsi: Implement ChromeOS UCSI driver Date: Tue, 3 Sep 2024 16:30:28 +0000 Message-ID: <20240903163033.3170815-4-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 Reviewed-by: Heikki Krogerus --- MAINTAINERS | 7 + drivers/usb/typec/ucsi/Kconfig | 13 ++ drivers/usb/typec/ucsi/Makefile | 1 + drivers/usb/typec/ucsi/cros_ec_ucsi.c | 278 ++++++++++++++++++++++++++ 4 files changed, 299 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..6b9dc05a4960 --- /dev/null +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -0,0 +1,278 @@ +// 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); + struct ec_params_ucsi_ppm_set *req; + size_t req_len; + int ret; + + req_len = sizeof(struct ec_params_ucsi_ppm_set) + sizeof(cmd); + req = kzalloc(req_len, GFP_KERNEL); + if (!req) + return -ENOMEM; + + req->offset = UCSI_CONTROL; + memcpy(req->data, &cmd, sizeof(cmd)); + ret = cros_ec_cmd(udata->ec, 0, EC_CMD_UCSI_PPM_SET, + req, req_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_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(udata->ucsi, UCSI_CCI, &cci, sizeof(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 3 16:30:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13789062 Received: from mail-ed1-f46.google.com (mail-ed1-f46.google.com [209.85.208.46]) (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 52BD918BC1D for ; Tue, 3 Sep 2024 16:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381044; cv=none; b=ebI9nTETTMh2g5gLG3LxzRakk5fpMeTYM4LdosD0w0XMdIId0SsX+6teVgj+eiLRLe/KnRpTEh+RNMAfl2xZzQOmOL13Y9tQgPuhc2bWVAtmLvoDgikG+rhR1C0E6GTeXYglJT/lZ4RrXwaRF1K/Q5S/V5CWmh8H1o8u8o0OVME= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381044; c=relaxed/simple; bh=NcRnI43j/32UrWwYS5V8VP4i4dLvb1AxJbQbRzMkl6I=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cHtvHTGRX5bVXWR7vx5J+XZPm22Az7aaO+QN+XS6fD8VcEpZPGEW4FQsx3LpPPcOv/+u0hyBsMj7b4N8xTq5CNmdHTGd8y8prgY02M1K9xjnvRF1Z8ex2IoBn+uYW8n+xeu0Jz/90WB9/oXFSbKa+wQY0DXzlGsgEwlhcIa/Zrk= 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=WyeQftBq; arc=none smtp.client-ip=209.85.208.46 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="WyeQftBq" Received: by mail-ed1-f46.google.com with SMTP id 4fb4d7f45d1cf-5bf01bdaff0so5195234a12.3 for ; Tue, 03 Sep 2024 09:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381042; x=1725985842; darn=vger.kernel.org; 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=Ch/nQk7xshZBBT85KVmRAI7T7THUEBQ92ebPsEv0TVI=; b=WyeQftBqWryvhch54aBzoZZygIYZn1xa+ueEP4ZjlbSAUGVs5pxJeEBxJDWlK6mllM vfR261xXsp1okmQKauaemKpLt87D55N5YqO5LEq1Y80w6SQ2OBKDdiDhamZxvvNO/OD+ 84tY6i5cO21HXFu19dmu1gDmF3By5OmuVs8XQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381042; x=1725985842; 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=Ch/nQk7xshZBBT85KVmRAI7T7THUEBQ92ebPsEv0TVI=; b=k7OZPumWc6FXRxzr4BbBbhQcAOZH+bzYDv11fba5HmeppLkiqQ+uiQMGej6Y3Kh3Wz 8rp1lXQPDs8Ctq/QyIlaMsyn8A089dZIu+cNFRHMif74vKrnhCBQ/UNeRRah5COdR2yc LX5hj6tLQSeL3YfsipJQTqrF8TgxqfXnfQ7+6O4lxwo074iWhylBwIl4dZ0bPwDmw7qa dRu10QQbl+Z1I4ctajLI0KX+Dj+2T0qTjDdTlcngvXjru/mpFu49/FLbusc0rQm5vhdL JgYNlNCf+VCltbXMvh3wPB75qO6fG0EBIAHVFz+9C9vIZhSfRPnUyvVm+CGy3UuSTpGQ +ZGg== X-Forwarded-Encrypted: i=1; AJvYcCVxR4QfYbZOBP604FU4YUK+ipKU0EzqoBBzua7GopXNglUBcZHwfccKyPWz9phNW1KTedzswOap+dE=@vger.kernel.org X-Gm-Message-State: AOJu0YzLgygBvgmEDU6CvcaIHgkso9IhT9fLZovGEfFCDz6DzdDjwMuy hwMiMgifEFiKg9Iec58Pa20QFpGRNyfJJf2vmSi6IeV24KMsvL1hmDRfDHVj X-Google-Smtp-Source: AGHT+IHPa9Qvf/PS48YGwqnSZBUWQ/hXpFMaONG1d+Jtps88oT2k5Dw5JhWbGgaxI5p+BF5VuNzo6g== X-Received: by 2002:a17:907:9813:b0:a6f:593f:d336 with SMTP id a640c23a62f3a-a897f77ea6amr1213890066b.11.1725381041378; Tue, 03 Sep 2024 09:30: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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30: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 v5 4/8] usb: typec: cros_ec_ucsi: Use complete instead of resume Date: Tue, 3 Sep 2024 16:30:29 +0000 Message-ID: <20240903163033.3170815-5-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 --- 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 6b9dc05a4960..4a3369c649bf 100644 --- a/drivers/usb/typec/ucsi/cros_ec_ucsi.c +++ b/drivers/usb/typec/ucsi/cros_ec_ucsi.c @@ -246,15 +246,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 3 16:30:30 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: 13789064 Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.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 EB42E18BB98 for ; Tue, 3 Sep 2024 16:30:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381045; cv=none; b=e2yu3NTWCxKR15fGZwg2QhUXT4mFFIPx0CGqiijIUFRfD+HYrrC4qxxgMWNTVpQ7ajpTka8uh6xNX97B5Wn6s0xLp3KEIkqCbGKiMQdi6UG3YFYdKdxr67JuqZhlgSmfUz50V7WSVkIcAnJq841gzz4oRfyMsgx+ydWI2A5ai10= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381045; c=relaxed/simple; bh=TsmOE9Ka/cnWkIMlbMKgGfPc39w+hTp4h9HPdq+aFvg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=RQBJsToygmXz4sv+/de9xNO/BWQOCyA8Bxss/QNUmmA2J3NgVAXJUjUrEmAreecZ9ryVvKzM/MebjLRKpom7U6WeCgOiKtQC553KNdkF4adliNUyXCCejIFnaNGudki5ELErQ8ogMd3sMiFLVIVdl/xmubKOXdazxk4y2fNgB0c= 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=G2W1eHW8; arc=none smtp.client-ip=209.85.218.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="G2W1eHW8" Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a83597ce5beso886882766b.1 for ; Tue, 03 Sep 2024 09:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381042; x=1725985842; darn=vger.kernel.org; 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=rtMD3IMlTRzDoSIZAH1mJmZO2t72h7tff8Sou3zt11w=; b=G2W1eHW8Fzh3vBgb3ZywWof6DiqsGGVvnmJdLIwdn+R91P5GvbxTzH0IBM4vP6UPAC YrEVFJZMukbcLUVwfVlZyPW5TRDP6EBR1nmZjOu/lrOZrZ8eYdbqY8ptE/yiSykvqwx2 YB8iEbC3cYwLhFEYj1Nb8DqGAwDS5QGiYp2NQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381042; x=1725985842; 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=rtMD3IMlTRzDoSIZAH1mJmZO2t72h7tff8Sou3zt11w=; b=m+x95UOvbGkTCbrGA2dQzzmpWsMjnOSt/2f+btv4FUzQywc4chEfcJ3fdxyIxg/j5F U4r1PV/I9jQl+SY2brgL/ldlTy6f6tBKwpQmBASQU/tnb7Bl88rDhf0rw16v+zhjHF1i tcmTxGD2uqhKXQZFzwwmzWVg/HyckG99psUlyHYl650VIAIB1yOVvfFOFgyUerV9imkx s+0c2XzhUUfBdayFOdSusHSK9D6rdRmsXwVYylDBM6q7ofLttVfnry72Wd4MvV3z3SRI vf6kxYo0E1+orzWI/rcsTQzrGJtGp7XMlGNHIrszh+OgC6NHtvfXyyrxLa38VmGdSRAE Sdrg== X-Forwarded-Encrypted: i=1; AJvYcCWM1fG8qExwAxR96V1f3zYKBBqKRXWg8MKYDhW1klXTYwqv9lT6sM+FS88H/V50IRa6/BW+rA5dtfI=@vger.kernel.org X-Gm-Message-State: AOJu0YyoclTFvOEst8fZSOefVYMSNi/1DmNoPnaBDAkuuaGeUb60y1Aa hursjYbT0Jc/Jr2StR+NGR3igRSe21GPBbkoZCicaCvEid1ewfX7uA8z22Q2 X-Google-Smtp-Source: AGHT+IEpNCPxVCdSEzTX2L1luDog7Pdct+Z7ieU4407jTg3v6KUKlvKALbxBkKJpVDEajJiHx9Lcww== X-Received: by 2002:a17:907:1ca4:b0:a86:84c3:a87 with SMTP id a640c23a62f3a-a89827a9635mr1883312666b.24.1725381041877; Tue, 03 Sep 2024 09:30: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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30:41 -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 v5 5/8] usb: typec: cros_ec_ucsi: Add trace events Date: Tue, 3 Sep 2024 16:30:30 +0000 Message-ID: <20240903163033.3170815-6-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 4a3369c649bf..6e020b7ed352 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; } @@ -101,6 +105,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; } @@ -143,6 +149,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(udata->ucsi, UCSI_CCI, &cci, sizeof(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 3 16:30:31 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: 13789067 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) (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 6618E18C330 for ; Tue, 3 Sep 2024 16:30:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.46 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381049; cv=none; b=d2F5wLQP5pqjABhy7K7Xklxfpkl4e4RYzufEoH5oZUt1WsaPoDMxBHNTkd5EPK4OsVfhPw1pfAbZ4Q2HpXuuNRBPJjfK1TE/EYhP+4awD7jMI9+lKfs6b481XOEqUz6fRFnr1RrR8z6khvHxPM09VhYkNPZhC0J2Kh9VzEve8aE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381049; c=relaxed/simple; bh=mCdGYWNHHO/tbQlNcFfhMCqSW2ANKpTEqGnHcisueOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=i9/8JLCxRe0ythL1HkjCx0gtg1tSSJq2+zQtaUJ1ZXjHK8eDiPHXjT1bmPXwOnNa1nlQ3P2FOY1RNrknHIfe4Sn2jdDavyMZeDRXXg1iJNLu/mhc5aFUJZdccxLaEIs6C0H/hdkSvErN57dc25zFPH230OE0YrUkh3boug2JDsI= 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=julXsxfP; arc=none smtp.client-ip=209.85.218.46 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="julXsxfP" Received: by mail-ej1-f46.google.com with SMTP id a640c23a62f3a-a7a843bef98so575341266b.2 for ; Tue, 03 Sep 2024 09:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381045; x=1725985845; darn=vger.kernel.org; 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=NxcV//IAhkQd7LQcdadk+UOgpPMTX9FwkzJ2LjdNqvI=; b=julXsxfPrRIw8ApPgejgcqTwKoCf4D0YLNFvNIc9j4eh2sb/SRavU4MpK2pP0aEB8u OZM0mulMQobFwCKMBG1v8t+s9/BfXdxZBD19ANLRdas2AfGhaZoOwmHycH76i+DbcV/r f386SJYrp6nqo0ItR3cCpZ3++6nfoJ1qt8Gac= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381045; x=1725985845; 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=NxcV//IAhkQd7LQcdadk+UOgpPMTX9FwkzJ2LjdNqvI=; b=sLWmY1qMRNoOV8HiVDPoMSMVi2I1CxS4LZADeBcu3QhLJUxq539gP5X0/LoIgLj00+ EcocJNGnYrbxo5m2hpcS1mhnMRpiE+AlA5PXW981PNtceDup9cT67U/6lk8k4k/I66ee c1EqKLHZZXMiA49belqFLzsY8napFqugpaVphYSlzVK9jowPolie5Vjns8xOlmmdzDWu nyGDfbTkpaFi6NvefGP48TaKgDyIP3EeNsD9ki56JZkR8B6ODbxs5Q+/CSI4GLEOE+60 Il8b9eSA/Z03MCH1JkYDr2A8zYi/jdHsiSm9aOiI0UcJkcE7rb2GxmySpybKjDE4jhzN 0lnA== X-Forwarded-Encrypted: i=1; AJvYcCWblJw1JdwUl2DU6NaOEQCQ2eHX1AVWnklG0P1ZoQR0MAlZia5vdnuCDrstRr2gyV7FjfoxS5P7ao8=@vger.kernel.org X-Gm-Message-State: AOJu0Ywsg5wCnNSurxmoTVP5KY048oZOwmGmWUh1FQ0Okts0zyt8wiJi JrFvE+7rbWtnGoJ5bs9jcZF0u+rVwvM5nb4JuBgHvn58cBLBvuju2/B83J0x X-Google-Smtp-Source: AGHT+IG2Tn7zjsx8akiIsUo61+AjmFBG9qt+248I2jRzUoxenig7hW6Nk5ig2ktr0aRuwtQ4MIykPg== X-Received: by 2002:a17:907:d08:b0:a86:8f32:3a68 with SMTP id a640c23a62f3a-a89d879c0femr853999866b.37.1725381044254; Tue, 03 Sep 2024 09:30:44 -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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30: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 v5 6/8] usb: typec: cros_ec_ucsi: Add netlink Date: Tue, 3 Sep 2024 16:30:31 +0000 Message-ID: <20240903163033.3170815-7-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 6e020b7ed352..85edfa95782a 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; } @@ -106,6 +147,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; } @@ -149,6 +193,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(udata->ucsi, UCSI_CCI, &cci, sizeof(cci))) @@ -234,13 +280,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 3 16:30:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13789065 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.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 C2CE618BB98 for ; Tue, 3 Sep 2024 16:30:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381048; cv=none; b=FjwKoCXv5xGK3GFd0JUAHYZ6Ygdzui76Q+K7K4S3h11LcXQfj4tqyFfB3Tb7IMSnXiOgB3lb6depCKYsARIxglVz7PGffBgEMgDB7cM+VkASkrbiJCIOqkjcAkRakB7+ayOzIepiTVVWe4E2ByDKj+OfUeWkOB3ObEqqhjy2/KI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381048; c=relaxed/simple; bh=zeFAAnixERBujmnP+OfMoylgALYCdPQWy5IZUOiSTn0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JHRkfR/zYhiKpyeqEfhg0BNWupz9tU3rim2AGj5+oLZsixuoJTaw0qyyl+lq0d/PIBy33wgKQ/vWeIe3XCPD4qK9FVKilLWEAGUOjzpp3yRYpRx+94pn3AAs5TeDqX/ex1VtfGCMLrzETV1+mgYJ+TP4qBDYua/ScElSKYtsn9I= 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=i7NwbGri; arc=none smtp.client-ip=209.85.218.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="i7NwbGri" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a89c8db505bso357432066b.0 for ; Tue, 03 Sep 2024 09:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381045; x=1725985845; darn=vger.kernel.org; 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=1529kCYToVWA/SvyL2miiVbvfe9UVSeUX+iIF/erMtM=; b=i7NwbGrigDbN2NP4Qo3v8Kt5xvTdLcYBhYpgPiLuaYiBs+hF6fHh8w9ixqStX6Z50D fe8is4TCeTFh01ngggKmgpqcT4sqetuzJ1Z3eH/IuBQzHrLOCuYJB3rhdPlR+D0Xjg/X UVrY6Qdd3FUczgBd+xHfP2hDE0jlQ8/+rAN/o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381045; x=1725985845; 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=1529kCYToVWA/SvyL2miiVbvfe9UVSeUX+iIF/erMtM=; b=to/5ZxQzUEY4OL6EHTHtWvCZ5tE6d4btFZzkXdpxKfm7vU3sDujcY9FurIdRKDFihw xEe2C0O4Q9tfcOmFNO9NWpG0fOSDtKP2BnqknJYlxSW0ih/s4lLbJcyuXnjLbgx93Uuo Ew+mOXDX/LUd97qx4D2sUKZhvHij/T02BgxmOmFWa0cz7HZRuKg5QmEZU3XFV2ZuD7+a J6IA1t6Nf/GDrpJYn1una2JgiP7dzp1IyrzcG66iAeMN4jl0AWYcz6F0YPnY69Q6M2ha ay/ZPfOurd8g/q4dqtX7O5LhtshF3E6gLuZmRrIO3r2lx1rfbMyVlDsm2Cs0aCghMTlB fg2w== X-Forwarded-Encrypted: i=1; AJvYcCXKNCTdJMKmZLdO1JoNCurO7//e6yl8tuvfo2GD8h5AFFyKc0O25mkvVNg6SNDabQvEY2wabxYTPKU=@vger.kernel.org X-Gm-Message-State: AOJu0YzqTbBhSjBnHyCUFDQtBDjMBYXUbm8ITdrzMXJe5va1HW60OcxF Md20zNVQjm4gZGqEMnaFD7FTQlSNUSQdCCCfjraFJisrFqsTf/gzcUKowex3 X-Google-Smtp-Source: AGHT+IE98mHJ5UpNz2yGMEBg9I4YslwHEn6KQq1me3zTIU0zpG7qP0AN3s2VlMVbsPYfg6dglKz0Dw== X-Received: by 2002:a17:907:9690:b0:a86:78fd:1df0 with SMTP id a640c23a62f3a-a8a32ed8959mr101502266b.34.1725381044779; Tue, 03 Sep 2024 09:30:44 -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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30:44 -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 v5 7/8] mfd: cros_ec: Load cros_ec_ucsi on supported ECs Date: Tue, 3 Sep 2024 16:30:32 +0000 Message-ID: <20240903163033.3170815-8-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 --- 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 3 16:30:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?=C5=81ukasz_Bartosik?= X-Patchwork-Id: 13789066 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.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 67C2818BBB0 for ; Tue, 3 Sep 2024 16:30:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381049; cv=none; b=hWbBTD8Ab2qf0FwVh2OR+xfctDHBK2p1wYZ02mbmlbMcDlYwu73jtpE6xhKrwBsYboa5vcPOuuy0kmi2YEz4YSbcl7VCsMwNVhXOmqCdYwYwzO+10in/4yyXApbfdQ9xQuPJh872RDy0BK6o3L9c2r4DIRBra7Mdx19GLSeYPvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725381049; c=relaxed/simple; bh=+SIfP7UISjPZqy3MROtCCerdpwFBvqDPS8zBDXoCQ6E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SI1eetJKL532QFK1Lyg6qCZ20rs0hV1HoeIJ3IjDzwPSpLjH1ZRyzuzzpQ7pn25CnlA3Wsd/sWeQ+OFhx5y3cV6YAvWljmwTSuk2D3DlxwVdVIa9Qj3ZTgZJcxdNjp0nLxt5SpjiVpvA4Xct0rbI9+ft1PxI96996FaG9+leaws= 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=nIPr/qqK; arc=none smtp.client-ip=209.85.218.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="nIPr/qqK" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-a86acbaddb4so661388766b.1 for ; Tue, 03 Sep 2024 09:30:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1725381046; x=1725985846; darn=vger.kernel.org; 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=abnaghlK+pw02PpQ8vIksrIw0Rsf4nvWXUu7Ofg0f3k=; b=nIPr/qqKDQWv8JYtRlpHJsa24FL1z7figrDB2cy2mm5nDRQ0lpkt8j1U33NNgadMY7 0xOD44BHcz3QW+LnMNy5I6ETKAPhmZqnVkpWAtf0yxIkwDYEK8xUxGBj6m63x8GxB+TD FJndg1fl8/2WCLsVmgi3Ekvug0QNx3Nwrpsns= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725381046; x=1725985846; 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=abnaghlK+pw02PpQ8vIksrIw0Rsf4nvWXUu7Ofg0f3k=; b=QOXxoeaEqDU22SRtCmEB69WMsxUV5zPJdvlBJVKoB8jmY51Xp8wDsAnOGVj5YeE8OL vSXELNjveWDTdjgrbicDM6P2YZysfVkFggI7peNHA0i2F8CLmbf+VKOfxGhJtbkLcM02 nw7urEgGzuHQ2VGHcTnp6wIN5oSRDm8hXU9fPL8PNZr7Jei0ELdDz/E1Y1jhUTVa7eao fKE8vpvrZXjgGHLgk3XSlswmCvvs5kugsgqH0y4Yu/AjkGNcgseFlO/BEmozONA49wZY FGrQJgE9rhdx9vpydpgdmiR0oGUu5tLQ1gg26gRLka7viS3fX0kgXcV1sVGv1NDvuqqX seDA== X-Forwarded-Encrypted: i=1; AJvYcCXcH2RgR4zChKQQn9fAyJAjZjTC515MYrrAuhGpq8V5OjoE5iEOaQ7Ood7lSONXvsGbjQG6Ojo4W4g=@vger.kernel.org X-Gm-Message-State: AOJu0YxGYurSWcaB/pRM2isQfwBqv8AfligC6Lxnvt90Gc1IvTuGqO1n C13x4LFhC4VLPoUoB+fJmsvSQLlmH6PEWeezm8kOSTm+vUOUmq3uft2bnld2 X-Google-Smtp-Source: AGHT+IGyA2BXvcyBi9Eat2Zpbm/KcDxn+TOMa7RYJ393x/0cWxbrH8YSipKSJQZfPaSIpsa1AvtybA== X-Received: by 2002:a17:907:1c0a:b0:a7a:ab8a:380 with SMTP id a640c23a62f3a-a897fad872amr1435845166b.69.1725381045331; Tue, 03 Sep 2024 09:30: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 a640c23a62f3a-a8989196bc4sm700685866b.125.2024.09.03.09.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Sep 2024 09:30:44 -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 v5 8/8] mfd: cros_ec: Don't load charger with UCSI Date: Tue, 3 Sep 2024 16:30:33 +0000 Message-ID: <20240903163033.3170815-9-ukaszb@chromium.org> X-Mailer: git-send-email 2.46.0.469.g59c65b2a67-goog In-Reply-To: <20240903163033.3170815-1-ukaszb@chromium.org> References: <20240903163033.3170815-1-ukaszb@chromium.org> Precedence: bulk X-Mailing-List: linux-usb@vger.kernel.org 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 --- 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.