From patchwork Fri Dec 27 17:13:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengyu Luo X-Patchwork-Id: 13922049 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 787B135974; Fri, 27 Dec 2024 17:15:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319730; cv=none; b=lJHA2NhYKgT8GmQwvjr88eWBgTTw6+QuGhkIjyTiHn7eE/xN6CsZH5N/hJ+hVIAl1edZjoPwSQBh7/utdwy1Up/L2KmpmiDv4QIr5GTc2TNHjjUIpsMsW8iXY4Vx8Wu4ql4GpGtGQ3lQbl4SrME+xaWYToSN+OAJod7aJvfcOG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319730; c=relaxed/simple; bh=P6D0+6QQngFutJoilW+irGFKIWthCOIahNe4+TNdzqM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kfn7c+236QQ91R/mBT4zQWoS4QkzIRoczFvbhBPkVNL9dWBo4wxxBMpe7PPMsD2/9l+FrqjJeb/3ASfqJAqR2VmK2uX2cyrGsUpZPYGtM83AsGU1g522AX3575H8elfmbEIxXgZ6ZsLZLXHVK7LG+3DLqZEl3P24p9N2tZ/pqS4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=MemUQStJ; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MemUQStJ" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-2163dc5155fso88858725ad.0; Fri, 27 Dec 2024 09:15:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735319728; x=1735924528; 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=1VAUvk7RBIs42sziCKORnbSfkimwL77gcLuSYfajjTk=; b=MemUQStJ38xrWBcNK46U9nC+aBmqQXbumpBFWO0CRuLwMvtPL18wIls4AFJOVWA1ll Nj417aU9b382IVOcg9zWHcduDp6/epLlIqRIEJ08tJFtZeVy3GHdvdIJtnJuvAmQT3CP SS07yf2BS1zs4wbg7uUG0pMALC/sGZTRYa6gfXcf83gT3Sp/H/JyyfHe2EXobZ1hh31j ok7Tk+/w/RIrX5uWVC7T7/wTadoey+oul8cvuhRVviMrrIqrO1BwPuuElBoveje4JVZI U+UlliZ/xBzydCdsCPGzBhP5vld8n6OvGv13lFn44wxeJjFLl/1ns7+nUL4np4IzZLy9 Yq4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735319728; x=1735924528; 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=1VAUvk7RBIs42sziCKORnbSfkimwL77gcLuSYfajjTk=; b=mpkT/KqO9y024JhfWN8MvBwrs4yxS64e29svD0D/Unv2/caXj7NZuLcbJESadfaZMb UKXJy8OtSmSUF8QhIq04auPEgFJEikIg31Kf+oibds6VtIyEUYMvV5QYNf/6JGloJk+V lqyplMW2GcM10n2z+i17Xr59XNu8qpwkquigpGrRk76eYkMflWOt7o3Gf/zGT4T2WUms 9TbJYWIClh7XiAZMWH8bRSfLM8N+7qYcrYAmfwNPf1P+qb/hu8J/k1wAHF57vlxTtoUC o/jQDpPu4Pr1KUvMjvCqsuU2kvn/Osd3+k/Vs6Ovll/FN854rcJrguMxE7sJVD9iX92c fGFw== X-Forwarded-Encrypted: i=1; AJvYcCUhu9bX1PoCHTx1ZuJZXjUCnreSIwn26isCbOWH9dTttTU/qStO7OWkZMGJ4/c9EkGrTLcoI4PoPjHB@vger.kernel.org, AJvYcCVdleLLfNj+hThfp8JH9xfUJwk3N5Eg7cqaJO4PQZGC60d+58reeKD0/nT7O11WtH100H4NVgVfrkVut1lQ@vger.kernel.org, AJvYcCVgtoHDuMn1I0KTrlsmIBXgL3HbtKOzeuXwjY4Vov/TlyG7PNz8+Jqo23wQULNvas4k+EsSLngrHhU=@vger.kernel.org, AJvYcCX1EGfdk9XDaLGcwq4O64y32v/SClQCl6URNZeZG4awy4SxlmO5TpbzvDdMsaoAEju3AAPIeYxCsBQmkpai@vger.kernel.org, AJvYcCXv1nC6VWCSYk7khn8X0EMjbecLrQNoIF2azwxU9EhMT2UHG9Kd3FDJxukrfmEuCnPI9gJje/OvLw3xI88lwvYqRSmk+g==@vger.kernel.org X-Gm-Message-State: AOJu0YyTAxzEqy8CsyJDtpTu66SIYX7vMXHvYGioGIY9GNEnYntkgX1u 12sY2XJxNX4v65vKC89Y9V5g4OHLsI6DFrTMNyVjpgM8e2OvfFb9WLdnOGzpATb7e4nH X-Gm-Gg: ASbGncvdgKSXE/TqCkZjC57RoknW8GJmeO8y28ZEFiXD7XIoYCjNRvirZziFNQ4CU4S JcAZ6TXVbCZtnnd+u+v8+u++x0eouOABSqcgnxMNba+N6OJ870zjhU4na49Gnt5i+TW4ONjQgfn mBYq7lvtGs8pKt0TPM9UtO6npqjFW2FPXV8uT/pGpzcJXtrEGfd+Y5KE2B84x1/LnmP+uKwU5UZ mr9ryy5lOdoObLjJ0boKxS+HXQyoiLvP+9vBgNh0q8= X-Google-Smtp-Source: AGHT+IEPr8iaPSgHKsDtMx1pH5avIF3Rej3lFgiK3Oyf8vLucpQfyG31/G0JZeNcPMJvdkZzIEM6Fw== X-Received: by 2002:a17:90b:3cc6:b0:2ee:aa95:6de9 with SMTP id 98e67ed59e1d1-2f452eed7e1mr41094794a91.33.1735319727649; Fri, 27 Dec 2024 09:15:27 -0800 (PST) Received: from nuvole.. ([2a09:bac1:76a0:dd10::2e9:62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f5227sm138566925ad.185.2024.12.27.09.15.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 09:15:27 -0800 (PST) From: Pengyu Luo To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Bryan O'Donoghue , Sebastian Reichel , Heikki Krogerus , Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, Dmitry Baryshkov , Nikita Travkin , Pengyu Luo Subject: [PATCH 1/5] dt-bindings: platform: Add Huawei Matebook E Go EC Date: Sat, 28 Dec 2024 01:13:49 +0800 Message-ID: <20241227171353.404432-2-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241227171353.404432-1-mitltlatltl@gmail.com> References: <20241227171353.404432-1-mitltlatltl@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add binding for the EC found in the Huawei Matebook E Go (sc8280xp) and Huawei Matebook E Go LTE (sc8180x) 2in1 tablet. Signed-off-by: Pengyu Luo --- .../bindings/platform/huawei,gaokun-ec.yaml | 116 ++++++++++++++++++ 1 file changed, 116 insertions(+) create mode 100644 Documentation/devicetree/bindings/platform/huawei,gaokun-ec.yaml diff --git a/Documentation/devicetree/bindings/platform/huawei,gaokun-ec.yaml b/Documentation/devicetree/bindings/platform/huawei,gaokun-ec.yaml new file mode 100644 index 000000000..f5488b57b --- /dev/null +++ b/Documentation/devicetree/bindings/platform/huawei,gaokun-ec.yaml @@ -0,0 +1,116 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/platform/huawei,gaokun-ec.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Huawei Matebook E Go Embedded Controller + +maintainers: + - Pengyu Luo + +description: + Different from other Qualcomm Snapdragon sc8180x sc8280xp based machines, + the Huawei Matebook E Go tablets use embedded controllers while others + use something called pmic glink which handles battery, UCSI, USB Type-C DP + alt mode. Huawei one handles even more, like charging thresholds, FN lock, + lid status, HPD events for the USB Type-C DP alt mode, etc. + +properties: + compatible: + items: + - enum: + - huawei,sc8180x-gaokun-ec + - huawei,sc8280xp-gaokun-ec + - const: huawei,gaokun-ec + + reg: + const: 0x38 + + interrupts: + maxItems: 1 + + connector: + $ref: /schemas/connector/usb-connector.yaml# + +required: + - compatible + - reg + - interrupts + +additionalProperties: false + +examples: + - | + #include + i2c15 { + clock-frequency = <400000>; + + pinctrl-names = "default"; + pinctrl-0 = <&i2c15_default>; + + embedded-controller@38 { + compatible = "huawei,sc8280xp-gaokun-ec", ""huawei,gaokun-ec"; + reg = <0x38>; + + interrupts-extended = <&tlmm 107 IRQ_TYPE_LEVEL_LOW>; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + ucsi0_ss_in: endpoint { + remote-endpoint = <&usb_0_qmpphy_out>; + }; + }; + + port@1 { + reg = <1>; + + ucsi0_sbu: endpoint { + remote-endpoint = <&usb0_sbu_mux>; + }; + }; + }; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + ucsi1_ss_in: endpoint { + remote-endpoint = <&usb_1_qmpphy_out>; + }; + }; + + port@1 { + reg = <1>; + + ucsi1_sbu: endpoint { + remote-endpoint = <&usb1_sbu_mux>; + }; + }; + }; + }; + }; From patchwork Fri Dec 27 17:13:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengyu Luo X-Patchwork-Id: 13922050 Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) (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 617E535974; Fri, 27 Dec 2024 17:15:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319736; cv=none; b=ps3z4QrbcNV7Buc34tT8qzkRtDd6hkmDdkFO/Wrp4WA6ANnPoHPup25mwqwi83R70aATPRZiLVWKB7nWcm1vt5lQLVkf+vFdgSesk4WmVP5yS5XmF64iQJ4A6yW4JDzePqBnmI9XHxJrMCFEDH39euiVOoVN7wAvGd0pLsdZd8Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319736; c=relaxed/simple; bh=WoWWuX9D0EPFssLKQ0lws001L82HD047Q+6Cn79ziLI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=A9QQ2XDT0fnZuRuPmeVFkNul6QyGkSe3FJZOc+DixdnPCyuiYGoEEstaRRk+mxGoW+2FGk6aLBsn98/CVFqYjy9WDGfSchAGK093Gw5G2dIyjrOCsAWoQVuLsmhAXz46LNSZv1+392jZLrZ8BECYK0kJ/n6xSxQe6pwvXiZLYCo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Og/2Q5aZ; arc=none smtp.client-ip=209.85.214.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Og/2Q5aZ" Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-2165cb60719so92051275ad.0; Fri, 27 Dec 2024 09:15:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735319734; x=1735924534; 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=u2hfiQhPzSgHrBlx838Ib/oJn1ApDYkgvtk1gQ24Sv0=; b=Og/2Q5aZEp+cmDngdJV2YrY9X0Mi4vszohOE2BdxEsdT/iMO84jxJiF+nSAh4IAWLS ubiVdC5GPR+WI53peTfEDlECEaccUNNtLRXVaZmigao1K8qARsliMv3FrEX1RxJm7o58 lkgf9Rq41e7Vg3sTHbc5h3y5FxdZAFs5RzgG2USrN0xNiyFegxdT8r4fnZhWlPv4whdr 336F+kfYaO5VlywvHS87+wVCteDLtDjILbF0tQPMAU8si/yMU8DEvT3bxlmM3JzwZc3C K0BLbRvc/3q+saXW9cLPnX6vW/G1S/HuDbdTXe3GzzXm/Dj5mQYJ2WmMO8u0kZeLu5Va z71w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735319734; x=1735924534; 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=u2hfiQhPzSgHrBlx838Ib/oJn1ApDYkgvtk1gQ24Sv0=; b=heNlvYYy43fmFwEyql4X3cMhNvvDSGaEH0zCTlMUlpIoq4IIl4xu3tlaBSnxliwLG+ yTYApHJY94Wk60oeeH6/2oRr9g18i8JAKW3SrMAHkVtM8Md9jbYIW0ItCqsse+D2OneP 2qmkDkj7sUtwbxLDOPCV8V0Nalcgw3D7KRDx6LSRnc8Fmb4pZAIkQZj2zdffZTDl1Mhr EILfDJySemD7t6KZ+XDiaSUUYhaJ9HHQmByEFddRhq9WwwDqw7VzDvcpuPgceZakoAZy DKhINFYjrKONAAHEDaP4ReH+2s0xyX9pzh9Mtr/5iugfxuHqBmPRTkvTkAEpVGEakU3p UeYA== X-Forwarded-Encrypted: i=1; AJvYcCUmtwyn/jODOVwyFnQ3CmKjnqtPUbS4EDoViwLXS6tdFLPIR9jDu6uU6XsU4LzeYngjeX4+dxGD9s4=@vger.kernel.org, AJvYcCUrCvKf42fJCXoSAA/Eg2foJhbuVAT4dNGBYhalfazX5qVQCJB1XI5cPEq1/onelwJxEHnPKU5oiJ7fSCo3@vger.kernel.org, AJvYcCWFrlFA6F7UMLUjD7p5ny3JcEDCFwecAWFTAGqFVGPK6SlU3P5WTeWvaYL9k3f3TIcOvkbnLcY1MthR@vger.kernel.org, AJvYcCXE4ygmxIIGIN5gQawQn1yozwmKU54Tj4lD7pazkRTAVsGnrUTDpVIgurhQdoCrmAPUs+5rhLA7cJQ+4nKHZZpT6TkXuw==@vger.kernel.org, AJvYcCXFepuiFhnqCHUF3Kg5uUcpS/+E2WMEw9k+pEW7KbXPCloasjbNYCTJlpycnS4aEw5YKmyfqR78dlf/YaZ0@vger.kernel.org X-Gm-Message-State: AOJu0Ywm0F5R3mkCvc9MRF7AkQZAu2WBd8N3yR2zB8g48bAPxhaWZIME aPzERS9KPjBkaJAppfgSJwZOFbv2bnnfL9MxJgTzrfJ6MbKiCdwSYUqnitCksrYDQLHH X-Gm-Gg: ASbGncvDEJiDKOa+d3tOuOGb7e+luEDjaoYk1uoP7Whab/fgowhmUAKy2tlO8upiDsJ Z1leOjsHiWq55+y4YFiB3CPScW0lVFYCsQEbgNtyYUtNcQT9vodL2jeKCszjaARAMAUA/aTuxnI BzgF/Bjhi0AKlFnCMZnCo1hh+Sg0mcXgjPp1IdTtBRin8N2JZNdRonwmk1qGbrpYz28C0iLuisa n0RSmg0dZwQ9Gposl19Z6SmxcnwFtO71cm+WMUo/4M= X-Google-Smtp-Source: AGHT+IEn8+hvUl0ELflaZHE8/bx1e0GFRujkLeLQU6y4a+RNOo+MJnBLeznSkwZG937TUgLLqaTnow== X-Received: by 2002:a17:903:1209:b0:215:b9a7:5282 with SMTP id d9443c01a7336-219e6eb417dmr364834635ad.26.1735319733394; Fri, 27 Dec 2024 09:15:33 -0800 (PST) Received: from nuvole.. ([2a09:bac1:76a0:dd10::2e9:62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f5227sm138566925ad.185.2024.12.27.09.15.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 09:15:32 -0800 (PST) From: Pengyu Luo To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Bryan O'Donoghue , Sebastian Reichel , Heikki Krogerus , Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, Dmitry Baryshkov , Nikita Travkin , Pengyu Luo Subject: [PATCH 2/5] platform: arm64: add Huawei Matebook E Go (sc8280xp) EC driver Date: Sat, 28 Dec 2024 01:13:50 +0800 Message-ID: <20241227171353.404432-3-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241227171353.404432-1-mitltlatltl@gmail.com> References: <20241227171353.404432-1-mitltlatltl@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 There are 3 variants, Huawei released first 2 at the same time. Huawei Matebook E Go LTE(sc8180x), codename should be gaokun2. Huawei Matebook E Go(sc8280xp@3.0GHz), codename is gaokun3. Huawei Matebook E Go 2023(sc8280xp@2.69GHz). Adding support for the latter two variants for now, this driver should also work for the sc8180x variant according to acpi table files, but I don't have the device yet. Different from other Qualcomm Snapdragon sc8280xp based machines, the Huawei Matebook E Go uses an embedded controller while others use something called pmic glink. This embedded controller can be used to perform a set of various functions, including, but not limited: - Battery and charger monitoring; - Charge control and smart charge; - Fn_lock settings; - Tablet lid status; - Temperature sensors; - USB Type-C notifications (ports orientation, DP alt mode HPD); - USB Type-C PD (according to observation, up to 48w). Add the driver for the EC, that creates devices for UCSI, wmi and power supply devices. Signed-off-by: Pengyu Luo --- drivers/platform/arm64/Kconfig | 19 + drivers/platform/arm64/Makefile | 2 + drivers/platform/arm64/huawei-gaokun-ec.c | 598 ++++++++++++++++++ drivers/platform/arm64/huawei-gaokun-wmi.c | 283 +++++++++ .../linux/platform_data/huawei-gaokun-ec.h | 90 +++ 5 files changed, 992 insertions(+) create mode 100644 drivers/platform/arm64/huawei-gaokun-ec.c create mode 100644 drivers/platform/arm64/huawei-gaokun-wmi.c create mode 100644 include/linux/platform_data/huawei-gaokun-ec.h diff --git a/drivers/platform/arm64/Kconfig b/drivers/platform/arm64/Kconfig index f88395ea3..eb7fbacf0 100644 --- a/drivers/platform/arm64/Kconfig +++ b/drivers/platform/arm64/Kconfig @@ -33,6 +33,25 @@ config EC_ACER_ASPIRE1 laptop where this information is not properly exposed via the standard ACPI devices. +config EC_HUAWEI_GAOKUN + tristate "Huawei Matebook E Go (sc8280xp) Embedded Controller driver" + depends on ARCH_QCOM || COMPILE_TEST + depends on I2C + depends on DRM + depends on POWER_SUPPLY + depends on INPUT + help + Say Y here to enable the EC driver for Huawei Matebook E Go 2in1 + tablet. The driver handles battery(information, charge control) and + USB Type-C DP HPD events as well as some misc functions like the lid + sensor and temperature sensors, etc. + + This driver provides battery and AC status support for the mentioned + laptop where this information is not properly exposed via the + standard ACPI devices. + + Say M or Y here to include this support. + config EC_LENOVO_YOGA_C630 tristate "Lenovo Yoga C630 Embedded Controller driver" depends on ARCH_QCOM || COMPILE_TEST diff --git a/drivers/platform/arm64/Makefile b/drivers/platform/arm64/Makefile index b2ae9114f..ed32ad6c0 100644 --- a/drivers/platform/arm64/Makefile +++ b/drivers/platform/arm64/Makefile @@ -6,4 +6,6 @@ # obj-$(CONFIG_EC_ACER_ASPIRE1) += acer-aspire1-ec.o +obj-$(CONFIG_EC_HUAWEI_GAOKUN) += huawei-gaokun-ec.o +obj-$(CONFIG_EC_HUAWEI_GAOKUN) += huawei-gaokun-wmi.o obj-$(CONFIG_EC_LENOVO_YOGA_C630) += lenovo-yoga-c630.o diff --git a/drivers/platform/arm64/huawei-gaokun-ec.c b/drivers/platform/arm64/huawei-gaokun-ec.c new file mode 100644 index 000000000..c1c657f7b --- /dev/null +++ b/drivers/platform/arm64/huawei-gaokun-ec.c @@ -0,0 +1,598 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * huawei-gaokun-ec - An EC driver for HUAWEI Matebook E Go (sc8280xp) + * + * reference: drivers/platform/arm64/acer-aspire1-ec.c + * drivers/platform/arm64/lenovo-yoga-c630.c + * + * Copyright (C) 2024 Pengyu Luo + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#define EC_EVENT 0x06 + +/* Also can be found in ACPI specification 12.3 */ +#define EC_READ 0x80 +#define EC_WRITE 0x81 +#define EC_BURST 0x82 +#define EC_QUERY 0x84 + + +#define EC_EVENT_LID 0x81 + +#define EC_LID_STATE 0x80 +#define EC_LID_OPEN BIT(1) + +#define UCSI_REG_SIZE 7 + +/* for tx, command sequences are arranged as + * {master_cmd, slave_cmd, data_len, data_seq} + */ +#define REQ_HDR_SIZE 3 +#define INPUT_SIZE_OFFSET 2 +#define INPUT_DATA_OFFSET 3 + +/* for rx, data sequences are arranged as + * {status, data_len(unreliable), data_seq} + */ +#define RESP_HDR_SIZE 2 +#define DATA_OFFSET 2 + + +struct gaokun_ec { + struct i2c_client *client; + struct mutex lock; + struct blocking_notifier_head notifier_list; + struct input_dev *idev; + bool suspended; +}; + +static int gaokun_ec_request(struct gaokun_ec *ec, const u8 *req, + size_t resp_len, u8 *resp) +{ + struct i2c_client *client = ec->client; + struct i2c_msg msgs[2] = { + { + .addr = client->addr, + .flags = client->flags, + .len = req[INPUT_SIZE_OFFSET] + REQ_HDR_SIZE, + .buf = req, + }, { + .addr = client->addr, + .flags = client->flags | I2C_M_RD, + .len = resp_len, + .buf = resp, + }, + }; + + mutex_lock(&ec->lock); + + i2c_transfer(client->adapter, msgs, 2); + usleep_range(2000, 2500); + + mutex_unlock(&ec->lock); + + return *resp; +} + +/* -------------------------------------------------------------------------- */ +/* Common API */ + +/** + * gaokun_ec_read - read from EC + * @ec: The gaokun_ec + * @req: The sequence to request + * @resp_len: The size to read + * @resp: Where the data are read to + * + * This function is used to read data after writing a magic sequence to EC. + * All EC operations dependent on this functions. + * + * Huawei uses magic sequences everywhere to complete various functions, all + * these sequences are passed to ECCD(a ACPI method which is quiet similar + * to gaokun_ec_request), there is no good abstraction to generalize these + * sequences, so just wrap it for now. Almost all magic sequences are kept + * in this file. + */ +int gaokun_ec_read(struct gaokun_ec *ec, const u8 *req, + size_t resp_len, u8 *resp) +{ + return gaokun_ec_request(ec, req, resp_len, resp); +} +EXPORT_SYMBOL_GPL(gaokun_ec_read); + +/** + * gaokun_ec_write - write to EC + * @ec: The gaokun_ec + * @req: The sequence to request + * + * This function has no big difference from gaokun_ec_read. When caller care + * only write status and no actual data are returnd, then use it. + */ +int gaokun_ec_write(struct gaokun_ec *ec, u8 *req) +{ + u8 resp[RESP_HDR_SIZE]; + + return gaokun_ec_request(ec, req, sizeof(resp), resp); +} +EXPORT_SYMBOL_GPL(gaokun_ec_write); + +int gaokun_ec_read_byte(struct gaokun_ec *ec, u8 *req, u8 *byte) +{ + int ret; + u8 resp[RESP_HDR_SIZE + sizeof(*byte)]; + + ret = gaokun_ec_read(ec, req, sizeof(resp), resp); + *byte = resp[DATA_OFFSET]; + + return ret; +} +EXPORT_SYMBOL_GPL(gaokun_ec_read_byte); + +int gaokun_ec_register_notify(struct gaokun_ec *ec, struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&ec->notifier_list, nb); +} +EXPORT_SYMBOL_GPL(gaokun_ec_register_notify); + +void gaokun_ec_unregister_notify(struct gaokun_ec *ec, struct notifier_block *nb) +{ + blocking_notifier_chain_unregister(&ec->notifier_list, nb); +} +EXPORT_SYMBOL_GPL(gaokun_ec_unregister_notify); + +/* -------------------------------------------------------------------------- */ +/* API For PSY */ + +int gaokun_ec_psy_multi_read(struct gaokun_ec *ec, u8 reg, + size_t resp_len, u8 *resp) +{ + int i, ret; + u8 _resp[RESP_HDR_SIZE + 1]; + u8 req[REQ_HDR_SIZE + 1] = {0x02, EC_READ, 1, }; + + for (i = 0; i < resp_len; ++i) { + req[INPUT_DATA_OFFSET] = reg++; + ret = gaokun_ec_read(ec, req, sizeof(_resp), _resp); + if (ret) + return -EIO; + resp[i] = _resp[DATA_OFFSET]; + } + + return 0; +} +EXPORT_SYMBOL_GPL(gaokun_ec_psy_multi_read); + +/* -------------------------------------------------------------------------- */ +/* API For WMI */ + +/* Battery charging threshold */ +int gaokun_ec_wmi_get_threshold(struct gaokun_ec *ec, u8 *value, int ind) +{ + /* GBTT */ + return gaokun_ec_read_byte(ec, (u8 []){0x02, 0x69, 1, ind}, value); +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_get_threshold); + +int gaokun_ec_wmi_set_threshold(struct gaokun_ec *ec, u8 start, u8 end) +{ + /* SBTT */ + int ret; + u8 req[REQ_HDR_SIZE + 2] = {0x02, 0x68, 2, 3, 0x5a}; + + ret = gaokun_ec_write(ec, req); + if (ret) + return -EIO; + + if (start == 0 && end == 0) + return -EINVAL; + + if (start >= 0 && start <= end && end <= 100) { + req[INPUT_DATA_OFFSET] = 1; + req[INPUT_DATA_OFFSET + 1] = start; + ret = gaokun_ec_write(ec, req); + if (ret) + return -EIO; + + req[INPUT_DATA_OFFSET] = 2; + req[INPUT_DATA_OFFSET + 1] = end; + ret = gaokun_ec_write(ec, req); + } else { + return -EINVAL; + } + + return ret; +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_set_threshold); + +/* Smart charge param */ +int gaokun_ec_wmi_get_smart_charge_param(struct gaokun_ec *ec, u8 *value) +{ + /* GBAC */ + return gaokun_ec_read_byte(ec, (u8 []){0x02, 0xE6, 0}, value); +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_get_smart_charge_param); + +int gaokun_ec_wmi_set_smart_charge_param(struct gaokun_ec *ec, u8 value) +{ + /* SBAC */ + if (value < 0 || value > 2) + return -EINVAL; + + return gaokun_ec_write(ec, (u8 []){0x02, 0xE5, 1, value}); +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_set_smart_charge_param); + +/* Smart charge */ +int gaokun_ec_wmi_get_smart_charge(struct gaokun_ec *ec, + u8 data[GAOKUN_SMART_CHARGE_DATA_SIZE]) +{ + /* GBCM */ + u8 req[REQ_HDR_SIZE] = {0x02, 0xE4, 0}; + u8 resp[RESP_HDR_SIZE + 4]; + int ret; + + ret = gaokun_ec_read(ec, req, sizeof(resp), resp); + if (ret) + return -EIO; + + data[0] = resp[DATA_OFFSET]; + data[1] = resp[DATA_OFFSET + 1]; + data[2] = resp[DATA_OFFSET + 2]; + data[3] = resp[DATA_OFFSET + 3]; + + return 0; +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_get_smart_charge); + +int gaokun_ec_wmi_set_smart_charge(struct gaokun_ec *ec, + u8 data[GAOKUN_SMART_CHARGE_DATA_SIZE]) +{ + /* SBCM */ + u8 req[REQ_HDR_SIZE + GAOKUN_SMART_CHARGE_DATA_SIZE] = {0x02, 0XE3, 4,}; + + if (!(data[2] >= 0 && data[2] <= data[3] && data[3] <= 100)) + return -EINVAL; + + memcpy(req + INPUT_DATA_OFFSET, data, GAOKUN_SMART_CHARGE_DATA_SIZE); + + return gaokun_ec_write(ec, req); +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_set_smart_charge); + +/* Fn lock */ +int gaokun_ec_wmi_get_fn_lock(struct gaokun_ec *ec, u8 *on) +{ + /* GFRS */ + int ret; + u8 val; + u8 req[REQ_HDR_SIZE] = {0x02, 0x6B, 0}; + + ret = gaokun_ec_read_byte(ec, req, &val); + if (val == 0x55) + *on = 0; + else if (val == 0x5A) + *on = 1; + else + return -EIO; + + return ret; +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_get_fn_lock); + +int gaokun_ec_wmi_set_fn_lock(struct gaokun_ec *ec, u8 on) +{ + /* SFRS */ + u8 req[REQ_HDR_SIZE + 1] = {0x02, 0x6C, 1,}; + + if (on == 0) + req[INPUT_DATA_OFFSET] = 0x55; + else if (on == 1) + req[INPUT_DATA_OFFSET] = 0x5A; + else + return -EINVAL; + + return gaokun_ec_write(ec, req); +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_set_fn_lock); + +/* Thermal Zone */ +/* Range from 0 to 0x2C, partial valid */ +static const u8 temp_reg[] = {0x05, 0x07, 0x08, 0x0E, 0x0F, 0x12, 0x15, 0x1E, + 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, + 0x27, 0x28, 0x29, 0x2A}; + +int gaokun_ec_wmi_get_temp(struct gaokun_ec *ec, s16 temp[GAOKUN_TZ_REG_NUM]) +{ + /* GTMP */ + u8 req[REQ_HDR_SIZE] = {0x02, 0x61, 1,}; + u8 resp[RESP_HDR_SIZE + sizeof(s16)]; + int ret, i = 0; + + while (i < GAOKUN_TZ_REG_NUM) { + req[INPUT_DATA_OFFSET] = temp_reg[i]; + ret = gaokun_ec_read(ec, req, sizeof(resp), resp); + if (ret) + return -EIO; + temp[i++] = *(s16 *)(resp + DATA_OFFSET); + } + + return 0; +} +EXPORT_SYMBOL_GPL(gaokun_ec_wmi_get_temp); + +/* -------------------------------------------------------------------------- */ +/* API For UCSI */ + +int gaokun_ec_ucsi_read(struct gaokun_ec *ec, + u8 resp[GAOKUN_UCSI_READ_SIZE]) +{ + u8 req[REQ_HDR_SIZE] = {0x3, 0xD5, 0}; + u8 _resp[RESP_HDR_SIZE + GAOKUN_UCSI_READ_SIZE]; + int ret; + + ret = gaokun_ec_read(ec, req, sizeof(_resp), _resp); + if (ret) + return ret; + + memcpy(resp, _resp + DATA_OFFSET, GAOKUN_UCSI_READ_SIZE); + return 0; +} +EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_read); + +int gaokun_ec_ucsi_write(struct gaokun_ec *ec, + const u8 req[GAOKUN_UCSI_WRITE_SIZE]) +{ + u8 _req[REQ_HDR_SIZE + GAOKUN_UCSI_WRITE_SIZE]; + + _req[0] = 0x03; + _req[1] = 0xD4; + _req[INPUT_SIZE_OFFSET] = GAOKUN_UCSI_WRITE_SIZE; + memcpy(_req + INPUT_DATA_OFFSET, req, GAOKUN_UCSI_WRITE_SIZE); + + return gaokun_ec_write(ec, _req); +} +EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_write); + +int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, u8 *ureg) +{ + u8 req[REQ_HDR_SIZE] = {0x03, 0xD3, 0}; + u8 _resp[RESP_HDR_SIZE + UCSI_REG_SIZE]; + int ret; + + ret = gaokun_ec_read(ec, req, sizeof(_resp), _resp); + if (ret) + return ret; + + memcpy(ureg, _resp + DATA_OFFSET, UCSI_REG_SIZE); + + return 0; +} +EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_get_reg); + +int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id) +{ + u8 req[REQ_HDR_SIZE + 1] = {0x03, 0xD2, 1, 0}; + + if (port_id >= 0) + req[INPUT_DATA_OFFSET] = 1 << port_id; + + return gaokun_ec_write(ec, req); +} +EXPORT_SYMBOL_GPL(gaokun_ec_ucsi_pan_ack); + +/* -------------------------------------------------------------------------- */ +/* Modern Standby */ + +static int gaokun_ec_suspend(struct device *dev) +{ + struct gaokun_ec *ec = dev_get_drvdata(dev); + u8 req[REQ_HDR_SIZE + 1] = {0x02, 0xB2, 1, 0xDB}; + int ret; + + if (ec->suspended) + return 0; + + ret = gaokun_ec_write(ec, req); + + if (ret) + return ret; + + ec->suspended = true; + + return 0; +} + +static int gaokun_ec_resume(struct device *dev) +{ + struct gaokun_ec *ec = dev_get_drvdata(dev); + u8 req[REQ_HDR_SIZE + 1] = {0x02, 0xB2, 1, 0xEB}; + int ret; + int i; + + if (!ec->suspended) + return 0; + + for (i = 0; i < 3; i++) { + ret = gaokun_ec_write(ec, req); + if (ret == 0) + break; + + msleep(100); + }; + + ec->suspended = false; + + return 0; +} + +static void gaokun_aux_release(struct device *dev) +{ + struct auxiliary_device *adev = to_auxiliary_dev(dev); + + kfree(adev); +} + +static void gaokun_aux_remove(void *data) +{ + struct auxiliary_device *adev = data; + + auxiliary_device_delete(adev); + auxiliary_device_uninit(adev); +} + +static int gaokun_aux_init(struct device *parent, const char *name, + struct gaokun_ec *ec) +{ + struct auxiliary_device *adev; + int ret; + + adev = kzalloc(sizeof(*adev), GFP_KERNEL); + if (!adev) + return -ENOMEM; + + adev->name = name; + adev->id = 0; + adev->dev.parent = parent; + adev->dev.release = gaokun_aux_release; + adev->dev.platform_data = ec; + /* Allow aux devices to access parent's DT nodes directly */ + device_set_of_node_from_dev(&adev->dev, parent); + + ret = auxiliary_device_init(adev); + if (ret) { + kfree(adev); + return ret; + } + + ret = auxiliary_device_add(adev); + if (ret) { + auxiliary_device_uninit(adev); + return ret; + } + + return devm_add_action_or_reset(parent, gaokun_aux_remove, adev); +} + +/* -------------------------------------------------------------------------- */ +/* EC */ + +static irqreturn_t gaokun_ec_irq_handler(int irq, void *data) +{ + struct gaokun_ec *ec = data; + u8 req[REQ_HDR_SIZE] = {EC_EVENT, EC_QUERY, 0}; + u8 status, id; + int ret; + + ret = gaokun_ec_read_byte(ec, req, &id); + if (ret) + return IRQ_HANDLED; + + switch (id) { + case 0x0: /* No event */ + break; + + case EC_EVENT_LID: + gaokun_ec_psy_read_byte(ec, EC_LID_STATE, &status); + status = EC_LID_OPEN & status; + input_report_switch(ec->idev, SW_LID, !status); + input_sync(ec->idev); + break; + + default: + blocking_notifier_call_chain(&ec->notifier_list, id, ec); + } + + return IRQ_HANDLED; +} + +static int gaokun_ec_probe(struct i2c_client *client) +{ + struct device *dev = &client->dev; + struct gaokun_ec *ec; + int ret; + + ec = devm_kzalloc(dev, sizeof(*ec), GFP_KERNEL); + if (!ec) + return -ENOMEM; + + mutex_init(&ec->lock); + ec->client = client; + i2c_set_clientdata(client, ec); + BLOCKING_INIT_NOTIFIER_HEAD(&ec->notifier_list); + + /* Lid switch */ + ec->idev = devm_input_allocate_device(dev); + if (!ec->idev) + return -ENOMEM; + + ec->idev->name = "LID"; + ec->idev->phys = "gaokun-ec/input0"; + input_set_capability(ec->idev, EV_SW, SW_LID); + + ret = input_register_device(ec->idev); + if (ret) + return dev_err_probe(dev, ret, "Failed to register input device\n"); + + ret = gaokun_aux_init(dev, "psy", ec); + if (ret) + return ret; + + ret = gaokun_aux_init(dev, "wmi", ec); + if (ret) + return ret; + + ret = gaokun_aux_init(dev, "ucsi", ec); + if (ret) + return ret; + + ret = devm_request_threaded_irq(dev, client->irq, NULL, + gaokun_ec_irq_handler, IRQF_ONESHOT, + dev_name(dev), ec); + if (ret) + return dev_err_probe(dev, ret, "Failed to request irq\n"); + + return 0; +} + +static const struct i2c_device_id gaokun_ec_id[] = { + { "gaokun-ec", }, + { } +}; +MODULE_DEVICE_TABLE(i2c, gaokun_ec_id); + +static const struct of_device_id gaokun_ec_of_match[] = { + { .compatible = "huawei,gaokun-ec", }, + { } +}; +MODULE_DEVICE_TABLE(of, gaokun_ec_of_match); + +static const struct dev_pm_ops gaokun_ec_pm_ops = { + NOIRQ_SYSTEM_SLEEP_PM_OPS(gaokun_ec_suspend, gaokun_ec_resume) +}; + +static struct i2c_driver gaokun_ec_driver = { + .driver = { + .name = "gaokun-ec", + .of_match_table = gaokun_ec_of_match, + .pm = &gaokun_ec_pm_ops, + }, + .probe = gaokun_ec_probe, + .id_table = gaokun_ec_id, +}; +module_i2c_driver(gaokun_ec_driver); + +MODULE_DESCRIPTION("HUAWEI Matebook E Go EC driver"); +MODULE_AUTHOR("Pengyu Luo "); +MODULE_LICENSE("GPL"); diff --git a/drivers/platform/arm64/huawei-gaokun-wmi.c b/drivers/platform/arm64/huawei-gaokun-wmi.c new file mode 100644 index 000000000..793cb1659 --- /dev/null +++ b/drivers/platform/arm64/huawei-gaokun-wmi.c @@ -0,0 +1,283 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * huawei-gaokun-wmi - A WMI driver for HUAWEI Matebook E Go (sc8280xp) + * + * reference: drivers/platform/x86/huawei-wmi.c + * + * Copyright (C) 2024 Pengyu Luo + */ + +#include +#include +#include +#include +#include + +#include + +struct gaokun_wmi { + struct gaokun_ec *ec; + struct device *dev; + struct platform_device *wmi; +}; + +/* -------------------------------------------------------------------------- */ +/* Battery charging threshold */ + +enum gaokun_wmi_threshold_ind { + START = 1, + END = 2, +}; + +static ssize_t charge_control_thresholds_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int ret; + u8 start, end; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + ret = gaokun_ec_wmi_get_threshold(ecwmi->ec, &start, START) + || gaokun_ec_wmi_get_threshold(ecwmi->ec, &end, END); + if (ret) + return ret; + + return sysfs_emit(buf, "%d %d\n", start, end); +} + +static ssize_t charge_control_thresholds_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int ret; + u8 start, end; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + if (sscanf(buf, "%hhd %hhd", &start, &end) != 2) + return -EINVAL; + + ret = gaokun_ec_wmi_set_threshold(ecwmi->ec, start, end); + if (ret) + return ret; + + return size; +} + +static DEVICE_ATTR_RW(charge_control_thresholds); + +/* -------------------------------------------------------------------------- */ +/* Smart charge param */ + +static ssize_t smart_charge_param_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int ret; + u8 value; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + ret = gaokun_ec_wmi_get_smart_charge_param(ecwmi->ec, &value); + if (ret) + return ret; + + return sysfs_emit(buf, "%d\n", value); +} + +static ssize_t smart_charge_param_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int ret; + u8 value; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + if (kstrtou8(buf, 10, &value)) + return -EINVAL; + + ret = gaokun_ec_wmi_set_smart_charge_param(ecwmi->ec, value); + if (ret) + return ret; + + return size; +} + +static DEVICE_ATTR_RW(smart_charge_param); + +/* -------------------------------------------------------------------------- */ +/* Smart charge */ + +static ssize_t smart_charge_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int ret; + u8 bf[GAOKUN_SMART_CHARGE_DATA_SIZE]; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + ret = gaokun_ec_wmi_get_smart_charge(ecwmi->ec, bf); + if (ret) + return ret; + + return sysfs_emit(buf, "%d %d %d %d\n", + bf[0], bf[1], bf[2], bf[3]); +} + +static ssize_t smart_charge_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int ret; + u8 bf[GAOKUN_SMART_CHARGE_DATA_SIZE]; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + if (sscanf(buf, "%hhd %hhd %hhd %hhd", bf, bf + 1, bf + 2, bf + 3) != 4) + return -EINVAL; + + ret = gaokun_ec_wmi_set_smart_charge(ecwmi->ec, bf); + if (ret) + return ret; + + return size; +} + +static DEVICE_ATTR_RW(smart_charge); + +/* -------------------------------------------------------------------------- */ +/* Fn lock */ + +static ssize_t fn_lock_state_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + int ret; + u8 on; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + ret = gaokun_ec_wmi_get_fn_lock(ecwmi->ec, &on); + if (ret) + return ret; + + return sysfs_emit(buf, "%d\n", on); +} + +static ssize_t fn_lock_state_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t size) +{ + int ret; + u8 on; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + if (kstrtou8(buf, 10, &on)) + return -EINVAL; + + ret = gaokun_ec_wmi_set_fn_lock(ecwmi->ec, on); + if (ret) + return ret; + + return size; +} + +static DEVICE_ATTR_RW(fn_lock_state); + +/* -------------------------------------------------------------------------- */ +/* Thermal Zone */ + +static ssize_t temperature_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + + int ret, len, i; + char *ptr = buf; + s16 value; + s16 temp[GAOKUN_TZ_REG_NUM]; + struct gaokun_wmi *ecwmi = dev_get_drvdata(dev); + + ret = gaokun_ec_wmi_get_temp(ecwmi->ec, temp); + if (ret) + return ret; + + i = 0; + len = 0; + while (i < GAOKUN_TZ_REG_NUM) { + value = temp[i++]; + if (value < 0) { + len += sprintf(ptr + len, "-"); + value = -value; + } + len += sprintf(ptr + len, "%d.%d ", value / 10, value % 10); + } + len += sprintf(ptr + len, "\n"); + + return len; +} + +static DEVICE_ATTR_RO(temperature); + +static struct attribute *gaokun_wmi_features_attrs[] = { + &dev_attr_charge_control_thresholds.attr, + &dev_attr_smart_charge_param.attr, + &dev_attr_smart_charge.attr, + &dev_attr_fn_lock_state.attr, + &dev_attr_temperature.attr, + NULL, +}; +ATTRIBUTE_GROUPS(gaokun_wmi_features); + +static int gaokun_wmi_probe(struct auxiliary_device *adev, + const struct auxiliary_device_id *id) +{ + struct gaokun_ec *ec = adev->dev.platform_data; + struct device *dev = &adev->dev; + struct gaokun_wmi *ecwmi; + + ecwmi = devm_kzalloc(&adev->dev, sizeof(*ecwmi), GFP_KERNEL); + if (!ecwmi) + return -ENOMEM; + + ecwmi->ec = ec; + ecwmi->dev = dev; + + auxiliary_set_drvdata(adev, ecwmi); + + /* make it under /sys/devices/platform, convenient for sysfs I/O, + * while adev is under + * /sys/devices/platform/soc@0/ac0000.geniqup/a9c000.i2c/i2c-15/15-0038/ + */ + ecwmi->wmi = platform_device_register_simple("gaokun-wmi", -1, NULL, 0); + if (IS_ERR(ecwmi->wmi)) + return dev_err_probe(dev, PTR_ERR(ecwmi->wmi), + "Failed to register wmi platform device\n"); + + platform_set_drvdata(ecwmi->wmi, ecwmi); + + return device_add_groups(&ecwmi->wmi->dev, gaokun_wmi_features_groups); +} + +static void gaokun_wmi_remove(struct auxiliary_device *adev) +{ + struct gaokun_wmi *ecwmi = auxiliary_get_drvdata(adev); + struct platform_device *wmi = ecwmi->wmi; + + device_remove_groups(&wmi->dev, gaokun_wmi_features_groups); + platform_device_unregister(ecwmi->wmi); +} + +static const struct auxiliary_device_id gaokun_wmi_id_table[] = { + { .name = GAOKUN_MOD_NAME "." GAOKUN_DEV_WMI, }, + {} +}; +MODULE_DEVICE_TABLE(auxiliary, gaokun_wmi_id_table); + +static struct auxiliary_driver gaokun_wmi_driver = { + .name = GAOKUN_DEV_WMI, + .id_table = gaokun_wmi_id_table, + .probe = gaokun_wmi_probe, + .remove = gaokun_wmi_remove, +}; + +module_auxiliary_driver(gaokun_wmi_driver); + +MODULE_DESCRIPTION("HUAWEI Matebook E Go WMI driver"); +MODULE_LICENSE("GPL"); diff --git a/include/linux/platform_data/huawei-gaokun-ec.h b/include/linux/platform_data/huawei-gaokun-ec.h new file mode 100644 index 000000000..a649e9ecf --- /dev/null +++ b/include/linux/platform_data/huawei-gaokun-ec.h @@ -0,0 +1,90 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Huawei Matebook E Go (sc8280xp) Embedded Controller + * + * Copyright (C) 2024 Pengyu Luo + * + */ + +#ifndef __HUAWEI_GAOKUN_EC_H__ +#define __HUAWEI_GAOKUN_EC_H__ + +#define GAOKUN_UCSI_CCI_SIZE 4 +#define GAOKUN_UCSI_DATA_SIZE 16 +#define GAOKUN_UCSI_READ_SIZE (GAOKUN_UCSI_CCI_SIZE + GAOKUN_UCSI_DATA_SIZE) +#define GAOKUN_UCSI_WRITE_SIZE 0x18 + +#define GAOKUN_TZ_REG_NUM 20 +#define GAOKUN_SMART_CHARGE_DATA_SIZE 4 /* mode, delay, start, end */ + +/* -------------------------------------------------------------------------- */ + +struct gaokun_ec; +struct notifier_block; + +#define GAOKUN_MOD_NAME "huawei_gaokun_ec" +#define GAOKUN_DEV_PSY "psy" +#define GAOKUN_DEV_WMI "wmi" +#define GAOKUN_DEV_UCSI "ucsi" + +/* -------------------------------------------------------------------------- */ +/* Common API */ + +int gaokun_ec_register_notify(struct gaokun_ec *ec, + struct notifier_block *nb); +void gaokun_ec_unregister_notify(struct gaokun_ec *ec, + struct notifier_block *nb); + +int gaokun_ec_read(struct gaokun_ec *ec, const u8 *req, + size_t resp_len, u8 *resp); +int gaokun_ec_write(struct gaokun_ec *ec, u8 *req); +int gaokun_ec_read_byte(struct gaokun_ec *ec, u8 *req, u8 *byte); + +/* -------------------------------------------------------------------------- */ +/* API For PSY */ + +int gaokun_ec_psy_multi_read(struct gaokun_ec *ec, u8 reg, + size_t resp_len, u8 *resp); + +static inline int gaokun_ec_psy_read_byte(struct gaokun_ec *ec, + u8 reg, u8 *byte) +{ + return gaokun_ec_psy_multi_read(ec, reg, 1, byte); +} + +static inline int gaokun_ec_psy_read_word(struct gaokun_ec *ec, + u8 reg, u16 *word) +{ + return gaokun_ec_psy_multi_read(ec, reg, 2, (u8 *)word); +} + +/* -------------------------------------------------------------------------- */ +/* API For WMI */ + +int gaokun_ec_wmi_get_threshold(struct gaokun_ec *ec, u8 *value, int ind); +int gaokun_ec_wmi_set_threshold(struct gaokun_ec *ec, u8 start, u8 end); + +int gaokun_ec_wmi_get_smart_charge_param(struct gaokun_ec *ec, u8 *value); +int gaokun_ec_wmi_set_smart_charge_param(struct gaokun_ec *ec, u8 value); + +int gaokun_ec_wmi_get_smart_charge(struct gaokun_ec *ec, + u8 data[GAOKUN_SMART_CHARGE_DATA_SIZE]); +int gaokun_ec_wmi_set_smart_charge(struct gaokun_ec *ec, + u8 data[GAOKUN_SMART_CHARGE_DATA_SIZE]); + +int gaokun_ec_wmi_get_fn_lock(struct gaokun_ec *ec, u8 *on); +int gaokun_ec_wmi_set_fn_lock(struct gaokun_ec *ec, u8 on); + +int gaokun_ec_wmi_get_temp(struct gaokun_ec *ec, s16 temp[GAOKUN_TZ_REG_NUM]); + +/* -------------------------------------------------------------------------- */ +/* API For UCSI */ + +int gaokun_ec_ucsi_read(struct gaokun_ec *ec, u8 resp[GAOKUN_UCSI_READ_SIZE]); +int gaokun_ec_ucsi_write(struct gaokun_ec *ec, + const u8 req[GAOKUN_UCSI_WRITE_SIZE]); + +int gaokun_ec_ucsi_get_reg(struct gaokun_ec *ec, u8 *ureg); +int gaokun_ec_ucsi_pan_ack(struct gaokun_ec *ec, int port_id); + + +#endif /* __HUAWEI_GAOKUN_EC_H__ */ From patchwork Fri Dec 27 17:13:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengyu Luo X-Patchwork-Id: 13922051 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 A02851F8697; Fri, 27 Dec 2024 17:15:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319741; cv=none; b=s+Bacblsbbl9bN9gjLHJUpQUfeK0CbDDQbQ8RRbDmzHGx2r/fR5RXaaOQkJL6UqpihU7buzYg9yFTRKKdY/tiKRR3SBTx7/mXjFXzKlRVAItvgSqh2V0jqdpBqbIpqIXUnpIPwZYwLNVlnH0fyERDb7kZ2LfKAc5q7IqYE4AUI8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319741; c=relaxed/simple; bh=mdwOStdBuKl43dStixJcmAf3kFLlRgS+OF1uMIKc2pU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=H/eeFm+txKCjAFufbEmLyaZLbTMQGDXtTSlSnEh0lhnWd+7StVJqSTBon3ano1NOa91yBlyxcaOfTtuDWC+slUQP7d1pSvRWUc0ScYWjtgP9i2e9Xv7jj53dNUb5dPo+m/akZhy/vLCT3i0/Ad8uyBjxI2pTsHkKduTvzia+eDY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fwA/Iesy; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fwA/Iesy" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-21619108a6bso83615845ad.3; Fri, 27 Dec 2024 09:15:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735319739; x=1735924539; 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=cR+Kbj/tlw2NvrjzC38Sr9CFS1Wcs9+3deLrkf74fVA=; b=fwA/IesymZO0Wyll0tATb6jXD/eKGeB6OcOydoOQEPXzw8oP9LCx8PAZzPuNSIGYLA tjO/w7wIRuuQlAysC9dMPTvMYrSE3GA0I+seoU3S/XNsVckXDTyt5JBNBN2LnvbPZWL1 MpqxmBPSQM7zbTCSHf+4UdNh3hdXtv4UOG3UOZ9Nug6JQRHOweJO1lb/ScYPln883dHM FlXNRUFcvsvRaNTCcQDrihSmb8zcAdNrvqrDnVxUdAcwUL8wz3HGRztQCh4HpiW4UflZ LaxpZSTrE3UmKFVHn1Io9Nsz1lGI/iIpos5J2aoUzEsXueMCpZqjdoWrRYi/zoYuIDYJ a1hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735319739; x=1735924539; 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=cR+Kbj/tlw2NvrjzC38Sr9CFS1Wcs9+3deLrkf74fVA=; b=gSzJ1RCgK3f/3sPhp3qVMyUZwIHrJxDhgOgoxFks+plwtAq9UNhrkr4aPaK5s5IiVK gAHqynaREuDsA0EplHEph8miVx/yfT6T74fP3nCadwEmHoe/EVGUb0p+pSGNxJ3quoZL k2rhjQxrH8iDBYYLk+WBG4jRUMeGdJuxP+f7EkgPF7OU7zhR2UN2ZnNNvpJFWieHWSYl hb1NierhKzYdnmsV75t5Ev7yu0bn+T6v7oAy5+ZA1mwYs/KClg/pevQkRoNUZ/pIxxYo TZuASCQaKvqTROD06C+RIj8GBgU8jjGhzSO2wYxQiA9f4G03oj1FmUsuCVFDCIfg6WE9 W3Mw== X-Forwarded-Encrypted: i=1; AJvYcCUSD6CNrduwaGb2W33DfpYd/LMg8/aoe0byl6V5Zs8AogBS0+BpXin9GIqMphFD3wW8FKTWj0iKEr6c30hS@vger.kernel.org, AJvYcCVbACSMM9c1Zx63vjOLy37OZ44uNav0+FtXk/inHSXyIOXJxrH66qp+7EGwdBNODDL3c9YEhHIb5iJ6imTs2tcR4OdFVg==@vger.kernel.org, AJvYcCWJ8jOScxipk4w5nwUoiwd15jmlqaJML0ofyhT/bDijhvKHveTPJO0JjESC9WzS5BBH0MUdoMpxfK4=@vger.kernel.org, AJvYcCWf8q1gIhJyjEFkRQuNNPu2vnIOuQDK1Sngtka90e4TkO8Ylj/l4NjpOb+9eh+4LE3ObKmeSJ6x0hzw@vger.kernel.org, AJvYcCWmQfoBbmnRvfLqPJvz4OlEXeZNkTYWArZGDXyZlN9YKaAEq4XL8WfYHLIYVdj6HMOP7MkdL7Xs+Z6l0B59@vger.kernel.org X-Gm-Message-State: AOJu0YxxfQoZn4ifxERYLkeBMb9yaiTdJclmYApYiVn5WV8WIhXNtByY JQk66rTRBvm0vFk6NzOm1ib9ZNh10gj8nRrizjtNLS0iHEFGPxyW X-Gm-Gg: ASbGncso6JJSc4fzJuNaTwD/ET+zLQEexpKKhAsbuQ9ulBWjVLbLx1duFpoc6Mwmr/p iBhShDyuWWx44zKXaCEJgUoCTTjc48/ohMKTDWWBR1Vzz/Nqp4YPARSV167b2NY+K67CT4VOJI6 wBT0mMURsuIKpdZrNEY6BQIbMPbXcIEw70OtYaepAIOssJGD9GzSkEgOUvzAfXcLINXdl/dY7uZ NzLeGJSsZzmHemfvDTTBc+40JzgeEnfVZuzRGj7liI= X-Google-Smtp-Source: AGHT+IGNQ7bPyRYgTtJ7vKlz86qrwyxLneTcNoNKDIdXTnvRrgZYymSBotOkOGAkVm7kIqUb+zfIYA== X-Received: by 2002:a17:903:234f:b0:216:4b6f:ddda with SMTP id d9443c01a7336-219e6f0e6c3mr364070815ad.35.1735319739082; Fri, 27 Dec 2024 09:15:39 -0800 (PST) Received: from nuvole.. ([2a09:bac1:76a0:dd10::2e9:62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f5227sm138566925ad.185.2024.12.27.09.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 09:15:38 -0800 (PST) From: Pengyu Luo To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Bryan O'Donoghue , Sebastian Reichel , Heikki Krogerus , Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, Dmitry Baryshkov , Nikita Travkin , Pengyu Luo Subject: [PATCH 3/5] usb: typec: ucsi: add Huawei Matebook E Go (sc8280xp) ucsi driver Date: Sat, 28 Dec 2024 01:13:51 +0800 Message-ID: <20241227171353.404432-4-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241227171353.404432-1-mitltlatltl@gmail.com> References: <20241227171353.404432-1-mitltlatltl@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The Huawei Matebook E Go (sc8280xp) tablet provides implements UCSI interface in the onboard EC. Add the glue driver to interface the platform's UCSI implementation. Signed-off-by: Pengyu Luo --- drivers/usb/typec/ucsi/Kconfig | 9 + drivers/usb/typec/ucsi/Makefile | 1 + drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c | 481 ++++++++++++++++++++ 3 files changed, 491 insertions(+) create mode 100644 drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c diff --git a/drivers/usb/typec/ucsi/Kconfig b/drivers/usb/typec/ucsi/Kconfig index 680e1b87b..0d0f07488 100644 --- a/drivers/usb/typec/ucsi/Kconfig +++ b/drivers/usb/typec/ucsi/Kconfig @@ -78,4 +78,13 @@ config UCSI_LENOVO_YOGA_C630 To compile the driver as a module, choose M here: the module will be called ucsi_yoga_c630. +config UCSI_HUAWEI_GAOKUN + tristate "UCSI Interface Driver for Huawei Matebook E Go (sc8280xp)" + depends on EC_HUAWEI_GAOKUN + help + This driver enables UCSI support on the Huawei Matebook E Go tablet. + + To compile the driver as a module, choose M here: the module will be + called ucsi_huawei_gaokun. + endif diff --git a/drivers/usb/typec/ucsi/Makefile b/drivers/usb/typec/ucsi/Makefile index aed41d238..0b400122b 100644 --- a/drivers/usb/typec/ucsi/Makefile +++ b/drivers/usb/typec/ucsi/Makefile @@ -22,3 +22,4 @@ obj-$(CONFIG_UCSI_CCG) += ucsi_ccg.o obj-$(CONFIG_UCSI_STM32G0) += ucsi_stm32g0.o obj-$(CONFIG_UCSI_PMIC_GLINK) += ucsi_glink.o obj-$(CONFIG_UCSI_LENOVO_YOGA_C630) += ucsi_yoga_c630.o +obj-$(CONFIG_UCSI_HUAWEI_GAOKUN) += ucsi_huawei_gaokun.o diff --git a/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c new file mode 100644 index 000000000..84ed0407d --- /dev/null +++ b/drivers/usb/typec/ucsi/ucsi_huawei_gaokun.c @@ -0,0 +1,481 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ucsi-huawei-gaokun - A UCSI driver for HUAWEI Matebook E Go (sc8280xp) + * + * reference: drivers/usb/typec/ucsi/ucsi_yoga_c630.c + * drivers/usb/typec/ucsi/ucsi_glink.c + * drivers/soc/qcom/pmic_glink_altmode.c + * + * Copyright (C) 2024 Pengyu Luo + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "ucsi.h" +#include + + +#define EC_EVENT_UCSI 0x21 +#define EC_EVENT_USB 0x22 + +#define GAOKUN_CCX_MASK GENMASK(1, 0) +#define GAOKUN_MUX_MASK GENMASK(3, 2) + +#define GAOKUN_DPAM_MASK GENMASK(3, 0) +#define GAOKUN_HPD_STATE_MASK BIT(4) +#define GAOKUN_HPD_IRQ_MASK BIT(5) + +#define CCX_TO_ORI(ccx) (++ccx % 3) + +#define GET_IDX(updt) (ffs(updt) - 1) + +/* Configuration Channel Extension */ +enum gaokun_ucsi_ccx { + USBC_CCX_NORMAL, + USBC_CCX_REVERSE, + USBC_CCX_NONE, +}; + +enum gaokun_ucsi_mux { + USBC_MUX_NONE, + USBC_MUX_USB_2L, + USBC_MUX_DP_4L, + USBC_MUX_USB_DP, +}; + +struct gaokun_ucsi_reg { + u8 port_num; + u8 port_updt; + u8 port_data[4]; + u8 checksum; + u8 reserved; +} __packed; + +struct gaokun_ucsi_port { + struct completion usb_ack; + spinlock_t lock; + + struct gaokun_ucsi *ucsi; + struct auxiliary_device *bridge; + + int idx; + enum gaokun_ucsi_ccx ccx; + enum gaokun_ucsi_mux mux; + u8 mode; + u16 svid; + u8 hpd_state; + u8 hpd_irq; +}; + +struct gaokun_ucsi { + struct gaokun_ec *ec; + struct ucsi *ucsi; + struct gaokun_ucsi_port *ports; + struct device *dev; + struct work_struct work; + struct notifier_block nb; + u16 version; + u8 port_num; +}; + +/* -------------------------------------------------------------------------- */ +/* For UCSI */ + +static int gaokun_ucsi_read_version(struct ucsi *ucsi, u16 *version) +{ + struct gaokun_ucsi *uec = ucsi_get_drvdata(ucsi); + + *version = uec->version; + + return 0; +} + +static int gaokun_ucsi_read_cci(struct ucsi *ucsi, u32 *cci) +{ + struct gaokun_ucsi *uec = ucsi_get_drvdata(ucsi); + u8 buf[GAOKUN_UCSI_READ_SIZE]; + int ret; + + ret = gaokun_ec_ucsi_read(uec->ec, buf); + if (ret) + return ret; + + memcpy(cci, buf, sizeof(*cci)); + + return 0; +} + +static int gaokun_ucsi_read_message_in(struct ucsi *ucsi, + void *val, size_t val_len) +{ + struct gaokun_ucsi *uec = ucsi_get_drvdata(ucsi); + u8 buf[GAOKUN_UCSI_READ_SIZE]; + int ret; + + ret = gaokun_ec_ucsi_read(uec->ec, buf); + if (ret) + return ret; + + memcpy(val, buf + GAOKUN_UCSI_CCI_SIZE, + min(val_len, GAOKUN_UCSI_DATA_SIZE)); + + return 0; +} + +static int gaokun_ucsi_async_control(struct ucsi *ucsi, u64 command) +{ + struct gaokun_ucsi *uec = ucsi_get_drvdata(ucsi); + u8 buf[GAOKUN_UCSI_WRITE_SIZE] = {}; + + memcpy(buf, &command, sizeof(command)); + + return gaokun_ec_ucsi_write(uec->ec, buf); +} + +static void gaokun_ucsi_update_connector(struct ucsi_connector *con) +{ + struct gaokun_ucsi *uec = ucsi_get_drvdata(con->ucsi); + + if (con->num > uec->port_num) + return; + + con->typec_cap.orientation_aware = true; +} + +static void gaokun_set_orientation(struct ucsi_connector *con, + struct gaokun_ucsi_port *port) +{ + enum gaokun_ucsi_ccx ccx; + unsigned long flags; + + spin_lock_irqsave(&port->lock, flags); + ccx = port->ccx; + spin_unlock_irqrestore(&port->lock, flags); + + typec_set_orientation(con->port, CCX_TO_ORI(ccx)); +} + +static void gaokun_ucsi_connector_status(struct ucsi_connector *con) +{ + struct gaokun_ucsi *uec = ucsi_get_drvdata(con->ucsi); + int idx; + + idx = con->num - 1; + if (con->num > uec->port_num) { + dev_warn(uec->ucsi->dev, "set orientation out of range: con%d\n", idx); + return; + } + + gaokun_set_orientation(con, &uec->ports[idx]); +} + +const struct ucsi_operations gaokun_ucsi_ops = { + .read_version = gaokun_ucsi_read_version, + .read_cci = gaokun_ucsi_read_cci, + .read_message_in = gaokun_ucsi_read_message_in, + .sync_control = ucsi_sync_control_common, + .async_control = gaokun_ucsi_async_control, + .update_connector = gaokun_ucsi_update_connector, + .connector_status = gaokun_ucsi_connector_status, +}; + +/* -------------------------------------------------------------------------- */ +/* For Altmode */ + +static void gaokun_ucsi_port_update(struct gaokun_ucsi_port *port, + const u8 *port_data) +{ + unsigned long flags; + u8 dcc, ddi; + int offset = port->idx * 2; /* every port has 2 Bytes data */ + + dcc = port_data[offset]; + ddi = port_data[offset + 1]; + + spin_lock_irqsave(&port->lock, flags); + + port->ccx = FIELD_GET(GAOKUN_CCX_MASK, dcc); + port->mux = FIELD_GET(GAOKUN_MUX_MASK, dcc); + port->mode = FIELD_GET(GAOKUN_DPAM_MASK, ddi); + port->hpd_state = FIELD_GET(GAOKUN_HPD_STATE_MASK, ddi); + port->hpd_irq = FIELD_GET(GAOKUN_HPD_IRQ_MASK, ddi); + + switch (port->mux) { + case USBC_MUX_NONE: + port->svid = 0; + break; + case USBC_MUX_USB_2L: + port->svid = USB_SID_PD; + break; + case USBC_MUX_DP_4L: + case USBC_MUX_USB_DP: + port->svid = USB_SID_DISPLAYPORT; + if (port->ccx == USBC_CCX_REVERSE) + port->mode -= 6; + break; + default: + break; + } + + spin_unlock_irqrestore(&port->lock, flags); +} + +static int gaokun_ucsi_refresh(struct gaokun_ucsi *uec) +{ + struct gaokun_ucsi_reg ureg; + int ret, idx; + + ret = gaokun_ec_ucsi_get_reg(uec->ec, (u8 *)&ureg); + if (ret) + return -EIO; + + uec->port_num = ureg.port_num; + idx = GET_IDX(ureg.port_updt); + + if (idx >= 0 && idx < ureg.port_num) + gaokun_ucsi_port_update(&uec->ports[idx], ureg.port_data); + + return idx; +} + +static void gaokun_ucsi_handle_altmode(struct gaokun_ucsi_port *port) +{ + struct gaokun_ucsi *uec = port->ucsi; + int idx = port->idx; + + if (idx >= uec->ucsi->cap.num_connectors || !uec->ucsi->connector) { + dev_warn(uec->ucsi->dev, "altmode port out of range: %d\n", idx); + return; + } + + /* UCSI callback .connector_status() have set orientation */ + if (port->bridge) + drm_aux_hpd_bridge_notify(&port->bridge->dev, + port->hpd_state ? + connector_status_connected : + connector_status_disconnected); + + gaokun_ec_ucsi_pan_ack(uec->ec, port->idx); +} + +static void gaokun_ucsi_altmode_notify_ind(struct gaokun_ucsi *uec) +{ + int idx; + + idx = gaokun_ucsi_refresh(uec); + if (idx < 0) + gaokun_ec_ucsi_pan_ack(uec->ec, idx); + else + gaokun_ucsi_handle_altmode(&uec->ports[idx]); +} + +/* + * USB event is necessary for enabling altmode, the event should follow + * UCSI event, if not after timeout(this notify may be disabled somehow), + * then force to enable altmode. + */ +static void gaokun_ucsi_handle_no_usb_event(struct gaokun_ucsi *uec, int idx) +{ + struct gaokun_ucsi_port *port; + + port = &uec->ports[idx]; + if (!wait_for_completion_timeout(&port->usb_ack, 2 * HZ)) { + dev_warn(uec->dev, "No USB EVENT, triggered by UCSI EVENT"); + gaokun_ucsi_altmode_notify_ind(uec); + } +} + +static int gaokun_ucsi_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + u32 cci; + struct gaokun_ucsi *uec = container_of(nb, struct gaokun_ucsi, nb); + + switch (action) { + case EC_EVENT_USB: + gaokun_ucsi_altmode_notify_ind(uec); + return NOTIFY_OK; + + case EC_EVENT_UCSI: + uec->ucsi->ops->read_cci(uec->ucsi, &cci); + ucsi_notify_common(uec->ucsi, cci); + if (UCSI_CCI_CONNECTOR(cci)) + gaokun_ucsi_handle_no_usb_event(uec, UCSI_CCI_CONNECTOR(cci) - 1); + + return NOTIFY_OK; + + default: + return NOTIFY_DONE; + } +} + +static int gaokun_ucsi_get_port_num(struct gaokun_ucsi *uec) +{ + struct gaokun_ucsi_reg ureg; + int ret; + + ret = gaokun_ec_ucsi_get_reg(uec->ec, (u8 *)&ureg); + + return ret ? 0 : ureg.port_num; +} + +static int gaokun_ucsi_ports_init(struct gaokun_ucsi *uec) +{ + u32 port; + int i, ret, port_num; + struct device *dev = uec->dev; + struct gaokun_ucsi_port *ucsi_port; + struct fwnode_handle *fwnode; + + port_num = gaokun_ucsi_get_port_num(uec); + uec->port_num = port_num; + + uec->ports = devm_kzalloc(dev, port_num * sizeof(*(uec->ports)), + GFP_KERNEL); + if (!uec->ports) + return -ENOMEM; + + for (i = 0; i < port_num; ++i) { + ucsi_port = &uec->ports[i]; + ucsi_port->ccx = USBC_CCX_NONE; + ucsi_port->idx = i; + ucsi_port->ucsi = uec; + init_completion(&ucsi_port->usb_ack); + spin_lock_init(&ucsi_port->lock); + } + + device_for_each_child_node(dev, fwnode) { + ret = fwnode_property_read_u32(fwnode, "reg", &port); + if (ret < 0) { + dev_err(dev, "missing reg property of %pOFn\n", fwnode); + fwnode_handle_put(fwnode); + return ret; + } + + if (port >= port_num) { + dev_warn(dev, "invalid connector number %d, ignoring\n", port); + continue; + } + + ucsi_port = &uec->ports[port]; + ucsi_port->bridge = devm_drm_dp_hpd_bridge_alloc(dev, to_of_node(fwnode)); + if (IS_ERR(ucsi_port->bridge)) { + fwnode_handle_put(fwnode); + return PTR_ERR(ucsi_port->bridge); + } + } + + for (i = 0; i < port_num; i++) { + if (!uec->ports[i].bridge) + continue; + + ret = devm_drm_dp_hpd_bridge_add(dev, uec->ports[i].bridge); + if (ret) + return ret; + } + + return 0; +} + +static void gaokun_ucsi_register_worker(struct work_struct *work) +{ + struct gaokun_ucsi *uec; + struct ucsi *ucsi; + int ret; + + uec = container_of(work, struct gaokun_ucsi, work); + ucsi = uec->ucsi; + + ucsi->quirks = UCSI_NO_PARTNER_PDOS | UCSI_DELAY_DEVICE_PDOS; + + ssleep(3); /* EC can't handle UCSI properly in the early stage */ + + ret = gaokun_ec_register_notify(uec->ec, &uec->nb); + if (ret) { + dev_err_probe(ucsi->dev, ret, "notifier register failed\n"); + return; + } + + ret = ucsi_register(ucsi); + if (ret) + dev_err_probe(ucsi->dev, ret, "ucsi register failed\n"); +} + +static int gaokun_ucsi_register(struct gaokun_ucsi *uec) +{ + schedule_work(&uec->work); + + return 0; +} + +static int gaokun_ucsi_probe(struct auxiliary_device *adev, + const struct auxiliary_device_id *id) +{ + struct gaokun_ec *ec = adev->dev.platform_data; + struct device *dev = &adev->dev; + struct gaokun_ucsi *uec; + int ret; + + uec = devm_kzalloc(dev, sizeof(*uec), GFP_KERNEL); + if (!uec) + return -ENOMEM; + + uec->ec = ec; + uec->dev = dev; + uec->version = 0x0100; + uec->nb.notifier_call = gaokun_ucsi_notify; + + INIT_WORK(&uec->work, gaokun_ucsi_register_worker); + + ret = gaokun_ucsi_ports_init(uec); + if (ret) + return ret; + + uec->ucsi = ucsi_create(dev, &gaokun_ucsi_ops); + if (IS_ERR(uec->ucsi)) + return PTR_ERR(uec->ucsi); + + ucsi_set_drvdata(uec->ucsi, uec); + auxiliary_set_drvdata(adev, uec); + + return gaokun_ucsi_register(uec); +} + +static void gaokun_ucsi_remove(struct auxiliary_device *adev) +{ + struct gaokun_ucsi *uec = auxiliary_get_drvdata(adev); + + gaokun_ec_unregister_notify(uec->ec, &uec->nb); + ucsi_unregister(uec->ucsi); + ucsi_destroy(uec->ucsi); +} + +static const struct auxiliary_device_id gaokun_ucsi_id_table[] = { + { .name = GAOKUN_MOD_NAME "." GAOKUN_DEV_UCSI, }, + {} +}; +MODULE_DEVICE_TABLE(auxiliary, gaokun_ucsi_id_table); + +static struct auxiliary_driver gaokun_ucsi_driver = { + .name = GAOKUN_DEV_UCSI, + .id_table = gaokun_ucsi_id_table, + .probe = gaokun_ucsi_probe, + .remove = gaokun_ucsi_remove, +}; + +module_auxiliary_driver(gaokun_ucsi_driver); + +MODULE_DESCRIPTION("HUAWEI Matebook E Go UCSI driver"); +MODULE_LICENSE("GPL"); From patchwork Fri Dec 27 17:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengyu Luo X-Patchwork-Id: 13922052 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.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 6F1CF1F8EE5; Fri, 27 Dec 2024 17:15:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319747; cv=none; b=LuwOcMyv2zAuGVCeEiWmVTK/IMVc3/76ZTG5pS6iZf48tgyLFoALDlNEtnAd4ugu9qpuwUQ9NAjjApKqUfCnAhfFSuOSqXAvZ1K+FlwDJeug/sALDoHVOrHhB3hSciG1rQDp0Fh+1tXm6T4hBQCz8KtYzRd/ooswJirVz+QiaLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319747; c=relaxed/simple; bh=YvZ1udbrnlOWcIdwccWk3kbVRXaPgho8vin+AH8oEOE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gJFs1TAhaIELVwSGEyzG7GwFCUB/evCPz2EtpdJXKERDMcU+MXmyAbdSN3I5PjN2z2bc8HDKdaR2gQMRU0LdRqsOgV8jPw2FzWHA5DevRhKMLKKc72XCgRyCfdhH/CmZRnzy334K79fAuQhLLKkabdGznjrTUvxutXvzlfXNiwo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CVm9kqmc; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CVm9kqmc" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-21680814d42so80310645ad.2; Fri, 27 Dec 2024 09:15:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735319745; x=1735924545; 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=yIgahqD8dOxceMTBQ2yzR9/z6Uf8j6EmUz8qtqg4rF4=; b=CVm9kqmc2vzP4AX2GOlgqCC5s0Tqr7GH5kbEM7OHlWeUflGMmYKSuVO65gmtlsLIWZ EbPahCxvAuTfnx/BSZcInAk/t3B9M4vzbruhujri2ukzjEF85MTOfP4QgbaXvVRFMPn/ 4G8IGp4YJEUONNnKhncCSZBtK0aY9y+NU9LMMUOqUQ04mxWaRWsvBLYpMbaq87Vekzol I4+QvDgAb2p2fzxDpF9aVkJBHaGUL6i90lW4YXNeXBtT9eXXyiK343cH9t3nnDz97Img 3HpkGyGGJH2zwWadq375LiklAiCu1oJg6XZVY9qNRJtMJTPX0ANi7RPrYb24XJWnOOrV 5qKQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735319745; x=1735924545; 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=yIgahqD8dOxceMTBQ2yzR9/z6Uf8j6EmUz8qtqg4rF4=; b=Kb3Rn1nE5kxVPcjJy6df+vfvY8qILgoAOqB9wDVv7nSfoe5ExUMK6aQLVS4Vg05B// 4Zf6kQoUGxNyJodJCKoonWn6hQSOuLvOZy/U0YQy5Er9F0CYDBdtLgQEhjueyrn4X/3f LMEOA5ZX/O19FTvNzL0swIPYn/guaCt8OPMoFmWoNIVAV0gT4Zd9vbtzdN9N+tIN0Mfv BnHH1BMNMxiPaYqqWIph/AQlut8Z/o8GZHumJWCWIxZQIxXSCDkDtbvkyPIMpmCNomfA ruN2v2aPuASnJGr/VJG9c3LME7Ks3usBROatBm3duOnq0MXE2u8QyE1D8p3nOpt+5gRD 7DDQ== X-Forwarded-Encrypted: i=1; AJvYcCUCw1raHN2tp/YCQIVHJHTcLTF6DICR/Xhx+CnO/uaXnAR186/2K1o4WfyVj7x1k51BEr1/B/Nk9bHd@vger.kernel.org, AJvYcCUEK54kRrzYZPKhZvgr65nMFU09D/FW+L8lxgFNPgCYVT/EuSTWWI7KjLNH0Kc11rt6Bug3qoURxGsRgfYZc3aHSP5Nqw==@vger.kernel.org, AJvYcCUh6sIkih4qLUeQLI/BElFlGTbuXxLCBDKAtqW2KlNrPvGgVjbJGv0eTmZZpurWK7w79EwZtj7E9Ws=@vger.kernel.org, AJvYcCV0FoS2TH/zCq5Z/GXR3Y7qJcEyzaDJKPB+rmxAasIavlbjdn2qR/gyLvfVkRfjErYUAKXa09Qzt8aOv76L@vger.kernel.org, AJvYcCXwhcElniihQw7fPghl2K2BnHYCuo8h9xi7YfS2MXL5UmaiuSTMnOIrwZeBSLrY5ryyxL9LMFgU0SJK83Lg@vger.kernel.org X-Gm-Message-State: AOJu0YxUYANOema/zYmvDwJxkJSJaxSiMbBpN6Jb/avwmRAlGsL4U7qY gTdjzOTpeSftf4ykGJ/sHdYQBrWcPLiZSW8vQeRt1q5tuVQa1EbU X-Gm-Gg: ASbGncvWLP975ur7FcNBDFu2kycvq5z4t2NsoEwy/lryd4gAmzd4JtDKGiczimOzcr4 P2uh5lHTyzjg5dqi9wLtW8mczJjS3z32338uBmSKWfpuMpENEMEglZRtJeSApO+3LPpR1Wa1KBk XuB90l4BMXchAQ0hvgdfKApwgtvhXNunjanF05R8BoLyUz1BV2M4foOCFkoq8pzAgP0vsYf8x0I aEoWX56NMW/0J8v3dkIAzJ9qqym8ikPJENNF9N3Z54= X-Google-Smtp-Source: AGHT+IEslKCQhnGVqgguMQn4QHUQQkjvu7L+U09f7U0flvlralBjCACdSBh87D6Vnr8VuJCk32SEHg== X-Received: by 2002:a17:902:d502:b0:216:31c2:3db8 with SMTP id d9443c01a7336-219e70c01admr381981125ad.37.1735319744634; Fri, 27 Dec 2024 09:15:44 -0800 (PST) Received: from nuvole.. ([2a09:bac1:76a0:dd10::2e9:62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f5227sm138566925ad.185.2024.12.27.09.15.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 09:15:44 -0800 (PST) From: Pengyu Luo To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Bryan O'Donoghue , Sebastian Reichel , Heikki Krogerus , Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, Dmitry Baryshkov , Nikita Travkin , Pengyu Luo Subject: [PATCH 4/5] power: supply: add Huawei Matebook E Go (sc8280xp) psy driver Date: Sat, 28 Dec 2024 01:13:52 +0800 Message-ID: <20241227171353.404432-5-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241227171353.404432-1-mitltlatltl@gmail.com> References: <20241227171353.404432-1-mitltlatltl@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On the Huawei Matebook E Go (sc8280xp) tablet the EC provides access to the adapter and battery status. Add the driver to read power supply status on the tablet. Signed-off-by: Pengyu Luo --- drivers/power/supply/Kconfig | 9 + drivers/power/supply/Makefile | 1 + drivers/power/supply/huawei-gaokun-battery.c | 446 +++++++++++++++++++ 3 files changed, 456 insertions(+) create mode 100644 drivers/power/supply/huawei-gaokun-battery.c diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index 9f2eef678..e385d0a1f 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -161,6 +161,15 @@ config BATTERY_DS2782 Say Y here to enable support for the DS2782/DS2786 standalone battery gas-gauge. +config BATTERY_HUAWEI_GAOKUN + tristate "Huawei Matebook E Go (sc8280xp) battery" + depends on EC_HUAWEI_GAOKUN + help + This driver enables battery support on the Huawei Matebook E Go. + + To compile the driver as a module, choose M here: the module will be + called huawei-gaokun-battery. + config BATTERY_LEGO_EV3 tristate "LEGO MINDSTORMS EV3 battery" depends on OF && IIO && GPIOLIB && (ARCH_DAVINCI_DA850 || COMPILE_TEST) diff --git a/drivers/power/supply/Makefile b/drivers/power/supply/Makefile index 59c4a9f40..c0941a832 100644 --- a/drivers/power/supply/Makefile +++ b/drivers/power/supply/Makefile @@ -31,6 +31,7 @@ obj-$(CONFIG_BATTERY_DS2781) += ds2781_battery.o obj-$(CONFIG_BATTERY_DS2782) += ds2782_battery.o obj-$(CONFIG_BATTERY_GAUGE_LTC2941) += ltc2941-battery-gauge.o obj-$(CONFIG_BATTERY_GOLDFISH) += goldfish_battery.o +obj-$(CONFIG_BATTERY_HUAWEI_GAOKUN) += huawei-gaokun-battery.o obj-$(CONFIG_BATTERY_LEGO_EV3) += lego_ev3_battery.o obj-$(CONFIG_BATTERY_LENOVO_YOGA_C630) += lenovo_yoga_c630_battery.o obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o diff --git a/drivers/power/supply/huawei-gaokun-battery.c b/drivers/power/supply/huawei-gaokun-battery.c new file mode 100644 index 000000000..40141b59e --- /dev/null +++ b/drivers/power/supply/huawei-gaokun-battery.c @@ -0,0 +1,446 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * gaokun-battery - A power supply driver for HUAWEI Matebook E Go (sc8280xp) + * + * reference: drivers/power/supply/lenovo_yoga_c630_battery.c + * drivers/platform/arm64/acer-aspire1-ec.c + * drivers/acpi/battery.c + * drivers/acpi/ac.c + * + * Copyright (C) 2024 Pengyu Luo + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +/* -------------------------------------------------------------------------- */ +/* String Data Reg */ + +#define EC_BAT_VENDOR 0x01 /* from 0x01 to 0x0F, SUNWODA */ +#define EC_BAT_MODEL 0x11 /* from 0x11 to 0x1F, HB30A8P9ECW-22T */ + +#define EC_ADP_STATUS 0x81 +#define EC_AC_STATUS BIT(0) +#define EC_BAT_PRESENT BIT(1) /* BATC._STA */ + +#define EC_BAT_STATUS 0x82 /* _BST */ +#define EC_BAT_DISCHARGING BIT(0) +#define EC_BAT_CHARGING BIT(1) +#define EC_BAT_CRITICAL BIT(2) /* Low Battery Level */ +#define EC_BAT_FULL BIT(3) + +/* -------------------------------------------------------------------------- */ +/* Word Data Reg */ + +/* 0x5A: ? + * 0x5C: ? + * 0x5E: ? + * 0X60: ? + * 0x84: ? + */ + +#define EC_BAT_STATUS_START 0x90 +#define EC_BAT_PERCENTAGE 0x90 +#define EC_BAT_VOLTAGE 0x92 +#define EC_BAT_CAPACITY 0x94 +#define EC_BAT_FULL_CAPACITY 0x96 +/* 0x98: ? */ +#define EC_BAT_CURRENT 0x9A +/* 0x9C: ? */ + +#define EC_BAT_INFO_START 0xA0 +/* 0xA0: POWER_SUPPLY_PROP_INPUT_VOLTAGE_LIMIT? */ +#define EC_BAT_DESIGN_CAPACITY 0xA2 +#define EC_BAT_DESIGN_VOLTAGE 0xA4 +#define EC_BAT_SERIAL_NUMBER 0xA6 +#define EC_BAT_CYCLE_COUNT 0xAA + +/* -------------------------------------------------------------------------- */ +/* Battery Event ID */ + +#define EC_EVENT_BAT_A0 0xA0 +#define EC_EVENT_BAT_A1 0xA1 +#define EC_EVENT_BAT_A2 0xA2 +#define EC_EVENT_BAT_A3 0xA3 +#define EC_EVENT_BAT_B1 0xB1 +/* EVENT B1 A0 A1 repeat about every 1s 2s 3s respectively */ + +/* ACPI _BIX field, Min sampling time, the duration between two _BST */ +#define CACHE_TIME 5000 /* cache time in milliseconds */ + +#define MILLI_TO_MICRO 1000 + +struct gaokun_psy_bat_status { + __le16 percentage_now; /* 0x90 */ + __le16 voltage_now; + __le16 capacity_now; + __le16 full_capacity; + __le16 unknown1; + __le16 rate_now; + __le16 unknown2; /* 0x9C */ +} __packed; + +struct gaokun_psy_bat_info { + __le16 unknown3; /* 0xA0 */ + __le16 design_capacity; + __le16 design_voltage; + __le16 serial_number; + __le16 padding2; + __le16 cycle_count; /* 0xAA */ +} __packed; + +struct gaokun_psy { + struct gaokun_ec *ec; + struct device *dev; + struct notifier_block nb; + + struct power_supply *bat_psy; + struct power_supply *adp_psy; + + unsigned long update_time; + struct gaokun_psy_bat_status status; + struct gaokun_psy_bat_info info; + + char battery_model[0x10]; /* HB30A8P9ECW-22T, the real one is XXX-22A */ + char battery_serial[0x10]; + char battery_vendor[0x10]; + + int charge_now; + int online; + int bat_present; +}; + +/* -------------------------------------------------------------------------- */ +/* Adapter */ + +static int gaokun_psy_get_adp_status(struct gaokun_psy *ecbat) +{ + /* _PSR */ + int ret; + u8 online = 0; + + ret = gaokun_ec_psy_read_byte(ecbat->ec, EC_ADP_STATUS, &online); + ecbat->online = !!(online & EC_AC_STATUS); + + return ret; +} + +static int gaokun_psy_get_adp_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct gaokun_psy *ecbat = power_supply_get_drvdata(psy); + + if (gaokun_psy_get_adp_status(ecbat)) + return -EIO; + + switch (psp) { + case POWER_SUPPLY_PROP_ONLINE: + val->intval = ecbat->online; + break; + + default: + return -EINVAL; + } + + return 0; +} + +static enum power_supply_property gaokun_psy_adp_props[] = { + POWER_SUPPLY_PROP_ONLINE, +}; + +static const struct power_supply_desc gaokun_psy_adp_desc = { + .name = "gaokun-ec-adapter", + .type = POWER_SUPPLY_TYPE_USB_TYPE_C, + .get_property = gaokun_psy_get_adp_property, + .properties = gaokun_psy_adp_props, + .num_properties = ARRAY_SIZE(gaokun_psy_adp_props), +}; + +/* -------------------------------------------------------------------------- */ +/* Battery */ + +static inline void gaokun_psy_get_bat_present(struct gaokun_psy *ecbat) +{ + int ret; + u8 present; + + /* Some kind of initialization */ + gaokun_ec_write(ecbat->ec, (u8 []){0x02, 0xB2, 1, 0x90}); + + ret = gaokun_ec_psy_read_byte(ecbat->ec, EC_ADP_STATUS, &present); + + ecbat->bat_present = ret ? false : !!(present & EC_BAT_PRESENT); +} + +static inline int gaokun_psy_bat_present(struct gaokun_psy *ecbat) +{ + return ecbat->bat_present; +} + +static int gaokun_psy_get_bat_info(struct gaokun_psy *ecbat) +{ + /* _BIX */ + if (!gaokun_psy_bat_present(ecbat)) + return 0; + + return gaokun_ec_psy_multi_read(ecbat->ec, EC_BAT_INFO_START, + sizeof(ecbat->info), (u8 *)&ecbat->info); +} + +static inline void gaokun_psy_update_bat_charge(struct gaokun_psy *ecbat) +{ + u8 charge = 0; + + gaokun_ec_psy_read_byte(ecbat->ec, EC_BAT_STATUS, &charge); + + charge = (charge == EC_BAT_CHARGING) * POWER_SUPPLY_STATUS_CHARGING + + (charge == EC_BAT_DISCHARGING) * POWER_SUPPLY_STATUS_DISCHARGING + + (charge == EC_BAT_FULL) * POWER_SUPPLY_STATUS_FULL; + + ecbat->charge_now = charge; +} + +static int gaokun_psy_get_bat_status(struct gaokun_psy *ecbat) +{ + /* _BST */ + int ret; + + if (time_before(jiffies, ecbat->update_time + + msecs_to_jiffies(CACHE_TIME))) + return 0; + + gaokun_psy_update_bat_charge(ecbat); + ret = gaokun_ec_psy_multi_read(ecbat->ec, EC_BAT_STATUS_START, + sizeof(ecbat->status), (u8 *)&ecbat->status); + + ecbat->update_time = jiffies; + + return ret; +} + +static inline void gaokun_psy_init(struct gaokun_psy *ecbat) +{ + gaokun_psy_get_bat_present(ecbat); + if (!gaokun_psy_bat_present(ecbat)) + return; + + gaokun_psy_get_bat_info(ecbat); + + snprintf(ecbat->battery_serial, sizeof(ecbat->battery_serial), + "%d", le16_to_cpu(ecbat->info.serial_number)); + + gaokun_ec_psy_multi_read(ecbat->ec, EC_BAT_VENDOR, + sizeof(ecbat->battery_vendor) - 1, + ecbat->battery_vendor); + + gaokun_ec_psy_multi_read(ecbat->ec, EC_BAT_MODEL, + sizeof(ecbat->battery_model) - 1, + ecbat->battery_model); + + ecbat->battery_model[14] = 'A'; /* FIX UP */ +} + +static int gaokun_psy_get_bat_property(struct power_supply *psy, + enum power_supply_property psp, + union power_supply_propval *val) +{ + struct gaokun_psy *ecbat = power_supply_get_drvdata(psy); + + if (gaokun_psy_bat_present(ecbat)) + gaokun_psy_get_bat_status(ecbat); + else if (psp != POWER_SUPPLY_PROP_PRESENT) + return -ENODEV; + + switch (psp) { + case POWER_SUPPLY_PROP_STATUS: + val->intval = ecbat->charge_now; + break; + + case POWER_SUPPLY_PROP_PRESENT: + val->intval = ecbat->bat_present; + break; + + case POWER_SUPPLY_PROP_TECHNOLOGY: + val->intval = POWER_SUPPLY_TECHNOLOGY_LION; + break; + + case POWER_SUPPLY_PROP_CYCLE_COUNT: + val->intval = le16_to_cpu(ecbat->info.cycle_count); + break; + + case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN: + val->intval = le16_to_cpu(ecbat->info.design_voltage) * MILLI_TO_MICRO; + break; + + case POWER_SUPPLY_PROP_VOLTAGE_NOW: + val->intval = le16_to_cpu(ecbat->status.voltage_now) * MILLI_TO_MICRO; + break; + + case POWER_SUPPLY_PROP_CURRENT_NOW: + val->intval = (s16)le16_to_cpu(ecbat->status.rate_now) * MILLI_TO_MICRO; + break; + + case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: + val->intval = le16_to_cpu(ecbat->info.design_capacity) * MILLI_TO_MICRO; + break; + + case POWER_SUPPLY_PROP_CHARGE_FULL: + val->intval = le16_to_cpu(ecbat->status.full_capacity) * MILLI_TO_MICRO; + break; + + case POWER_SUPPLY_PROP_CHARGE_NOW: + val->intval = le16_to_cpu(ecbat->status.capacity_now) * MILLI_TO_MICRO; + break; + + case POWER_SUPPLY_PROP_CAPACITY: + val->intval = le16_to_cpu(ecbat->status.percentage_now); + break; + + case POWER_SUPPLY_PROP_MODEL_NAME: + val->strval = ecbat->battery_model; + break; + + case POWER_SUPPLY_PROP_MANUFACTURER: + val->strval = ecbat->battery_vendor; + break; + + case POWER_SUPPLY_PROP_SERIAL_NUMBER: + val->strval = ecbat->battery_serial; + break; + + default: + return -EINVAL; + } + return 0; +} + +static enum power_supply_property gaokun_psy_bat_props[] = { + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_TECHNOLOGY, + POWER_SUPPLY_PROP_CYCLE_COUNT, + POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN, + POWER_SUPPLY_PROP_VOLTAGE_NOW, + POWER_SUPPLY_PROP_CURRENT_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, + POWER_SUPPLY_PROP_CHARGE_FULL, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_CAPACITY, + POWER_SUPPLY_PROP_MODEL_NAME, + POWER_SUPPLY_PROP_MANUFACTURER, + POWER_SUPPLY_PROP_SERIAL_NUMBER, +}; + +static const struct power_supply_desc gaokun_psy_bat_desc = { + .name = "gaokun-ec-battery", + .type = POWER_SUPPLY_TYPE_BATTERY, + .get_property = gaokun_psy_get_bat_property, + .properties = gaokun_psy_bat_props, + .num_properties = ARRAY_SIZE(gaokun_psy_bat_props), +}; + +static int gaokun_psy_notify(struct notifier_block *nb, + unsigned long action, void *data) +{ + struct gaokun_psy *ecbat = container_of(nb, struct gaokun_psy, nb); + + switch (action) { + case EC_EVENT_BAT_A2: + case EC_EVENT_BAT_B1: + gaokun_psy_get_bat_info(ecbat); + break; + + case EC_EVENT_BAT_A0: + gaokun_psy_get_adp_status(ecbat); + power_supply_changed(ecbat->adp_psy); + msleep(10); + fallthrough; + + case EC_EVENT_BAT_A1: + case EC_EVENT_BAT_A3: + if (action == EC_EVENT_BAT_A3) { + gaokun_psy_get_bat_info(ecbat); + msleep(100); + } + gaokun_psy_get_bat_status(ecbat); + power_supply_changed(ecbat->bat_psy); + break; + } + + return NOTIFY_OK; +} + +static int gaokun_psy_probe(struct auxiliary_device *adev, + const struct auxiliary_device_id *id) +{ + struct gaokun_ec *ec = adev->dev.platform_data; + struct power_supply_config psy_cfg = {}; + struct device *dev = &adev->dev; + struct gaokun_psy *ecbat; + + ecbat = devm_kzalloc(&adev->dev, sizeof(*ecbat), GFP_KERNEL); + if (!ecbat) + return -ENOMEM; + + ecbat->ec = ec; + ecbat->dev = dev; + ecbat->nb.notifier_call = gaokun_psy_notify; + + auxiliary_set_drvdata(adev, ecbat); + + psy_cfg.drv_data = ecbat; + ecbat->adp_psy = devm_power_supply_register(dev, &gaokun_psy_adp_desc, + &psy_cfg); + if (IS_ERR(ecbat->adp_psy)) + return dev_err_probe(dev, PTR_ERR(ecbat->adp_psy), + "Failed to register AC power supply\n"); + + psy_cfg.supplied_to = (char **)&gaokun_psy_bat_desc.name; + psy_cfg.num_supplicants = 1; + psy_cfg.no_wakeup_source = true; + ecbat->bat_psy = devm_power_supply_register(dev, &gaokun_psy_bat_desc, + &psy_cfg); + if (IS_ERR(ecbat->bat_psy)) + return dev_err_probe(dev, PTR_ERR(ecbat->bat_psy), + "Failed to register battery power supply\n"); + + gaokun_psy_init(ecbat); + + return gaokun_ec_register_notify(ec, &ecbat->nb); +} + +static void gaokun_psy_remove(struct auxiliary_device *adev) +{ + struct gaokun_psy *ecbat = auxiliary_get_drvdata(adev); + + gaokun_ec_unregister_notify(ecbat->ec, &ecbat->nb); +} + +static const struct auxiliary_device_id gaokun_psy_id_table[] = { + { .name = GAOKUN_MOD_NAME "." GAOKUN_DEV_PSY, }, + {} +}; +MODULE_DEVICE_TABLE(auxiliary, gaokun_psy_id_table); + +static struct auxiliary_driver gaokun_psy_driver = { + .name = GAOKUN_DEV_PSY, + .id_table = gaokun_psy_id_table, + .probe = gaokun_psy_probe, + .remove = gaokun_psy_remove, +}; + +module_auxiliary_driver(gaokun_psy_driver); + +MODULE_DESCRIPTION("HUAWEI Matebook E Go psy driver"); +MODULE_LICENSE("GPL"); From patchwork Fri Dec 27 17:13:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pengyu Luo X-Patchwork-Id: 13922053 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 93E301F8919; Fri, 27 Dec 2024 17:15:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319752; cv=none; b=dQVNYFt6GskvdXEfNO/3jdQy8BwMk/a67GItOgMdl0SFFbiHwVlEeEmnZXYrf1hfh+txwrwuW6vs3kmeZSTnSgXgMSrp4/X0ZeCopbjNl1xPM168y5JZ36fiGvA4QvpUOSXItyMyakWz4WI09Yjx6W2F1rwt7ZsApcsU2sAebbM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735319752; c=relaxed/simple; bh=VaewzLqkmqFo/f+oJtEz+5NTANhkoqFsICApE8otI84=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qnGd5UmlBpkgUWUffVVOjofvClya3MKQcOtdqYvxBIo07fSE+s/p+w4ZWQkEJK155daW0AANLjwa2mhQOTaxwr2gaVodh1mypTFbeeTuL+RbBtos3o3qLn+nzaZ5u4Y3mCcBHDY3t5tm0AKufIS4jstF8dOyDZfUAonSZsUhN1E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Qf/x9X0b; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Qf/x9X0b" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-21675fd60feso119068515ad.2; Fri, 27 Dec 2024 09:15:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1735319750; x=1735924550; 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=Dk+gmR74J3HsavyfIN7Wsm/Odwamup2HkvCFCW1rfCs=; b=Qf/x9X0bnvRVmqvbZJm8oqUZmg8xjnqfIBewogy54POvBTvc78V3wKDbLnnT8Qtx6d gNuK/GPGj8GEtkyiqXGGHOfUa3KYLeP6i8fEnkF1nYzZG/of8vNjelSz+8v9wN7l9a10 zFpNX8bT34fFfiNLP7fWe+0YIE8gqTkBh2cUT7xGhSv1csqi6yrdtR37OTs8JrjMacfF wxt5uWnNe42jnQ05PJrUnFOm6FXiSaG9BnBTFcrjiHpP/iCN30IAqC7+q0LnoSAfjy4A 1xeuVu4c/f4sSEyKSwXldSYgv7a8xCYc9/TGOIBqh7Ec4GyHYYieqB0l8ONynad7HodI 9KsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735319750; x=1735924550; 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=Dk+gmR74J3HsavyfIN7Wsm/Odwamup2HkvCFCW1rfCs=; b=h1Hf6GyVHUlXCxfKe8m6HOmqF64ffQxu5ksrQD16FTpINLvDxsLs2zKU4ZO4jT1gCP Jsxn3dfpkMDbb+KdkpKw7Onym61ubUIvbSyNtXeHj7NHd7XbaTyBoqBWpiRCfK0g1B6q ShIbdjqVkaDu25wzZjbq1KSCiAeNAXsyl+/+cfTp0sd2Pa8QpY66iIW2zQFVJ7vbsiJQ 7+1LbdrB1Sof94nCyzy+4YsSCAVSGegDkolwymG3sSkTZed5LgzydJqKCc9PO8/0JWaS ojyjp00K5EVYy5xyy5+lYo860/jYW4bthuYs/JMf/qjUjejZxdFrC3fzGgWC8Wi0Vf6c cmpA== X-Forwarded-Encrypted: i=1; AJvYcCV9HdY/lL8w02ucdWAlSmEJE9PDk5AMnhFznyEW+UFK5+rWAcTnqHFHZzbZfZn82PAhW9oL8MI2Amj7QH5n@vger.kernel.org, AJvYcCWFtl9q1gpnfvzd8Vn/COYghZ1VuKnGHmri1n3CVYllXpxFGlDrTEek9arUAfa19OmiK2KLuHUxSQqiXK6s@vger.kernel.org, AJvYcCWdZolycibtX8XihMAQO3wx2qw+oYebNd7IAGdpT2AZD5PyybMLgNOpy4IgWiJwSKPhKHKVQrdlXAm6@vger.kernel.org, AJvYcCX5GjFIwIm+TJcIxMsrpWWD/v63u3BCusqmjQzdiEmx9pVamE8JQZzqG2C9tuQok/NLlxa09WitU1c=@vger.kernel.org, AJvYcCXdMBitplJAvondlahlGeOqeN6LW05z1EBwKpBzZnv0/P+vxIa590CqCrrVdOvekS/9tJhlmcOsNj5ANzx81zwe+CZx7A==@vger.kernel.org X-Gm-Message-State: AOJu0YxR0C3DnLKusu6E7LdjfMJo4sphrbM2QbOHYehq6ixXpgnKTkHv b9945V4T6SUCr3yPhmedDiCNUxayopdxtM5jLS81BE6CEOHS0xQL X-Gm-Gg: ASbGnct5kmXHCkZWT9+2bAuocOImWc4nAeoofMthTzMg1dOYR9bhmddlO0xIN6G1Y2t /3kVHohsAfZISl/MNdEHkpxXwhcrCsqdle1uMszwhzt5rZOBRpSpVuj8WFbFQtNNsiXX00rWnd7 8n8FOrkHEwpiNq5NI7KidhTORpP0Y/IztrShiGBoRaBxsAFuHzoSD9ZpCQx47pSgYd5kFbDT0iI sIRk8b1b82zGuKLT39MQn0yyS/2xSw0bwJhnh0Nqoc= X-Google-Smtp-Source: AGHT+IEq2alO2+I/3NjlfOpSaYnmZW/d5WnDYgErefaWKmQMuLwgCzdhT++/c4Hhx3rC9+CzpSfqQg== X-Received: by 2002:a17:90b:1f85:b0:2ee:7870:8835 with SMTP id 98e67ed59e1d1-2f452f0164cmr42277869a91.33.1735319749931; Fri, 27 Dec 2024 09:15:49 -0800 (PST) Received: from nuvole.. ([2a09:bac1:76a0:dd10::2e9:62]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc9f5227sm138566925ad.185.2024.12.27.09.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Dec 2024 09:15:49 -0800 (PST) From: Pengyu Luo To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Bjorn Andersson , Konrad Dybcio , Hans de Goede , =?utf-8?q?Ilpo_J=C3=A4rvinen?= , Bryan O'Donoghue , Sebastian Reichel , Heikki Krogerus , Greg Kroah-Hartman Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-usb@vger.kernel.org, Dmitry Baryshkov , Nikita Travkin , Pengyu Luo Subject: [PATCH 5/5] arm64: dts: qcom: gaokun3: Add Embedded Controller node Date: Sat, 28 Dec 2024 01:13:53 +0800 Message-ID: <20241227171353.404432-6-mitltlatltl@gmail.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20241227171353.404432-1-mitltlatltl@gmail.com> References: <20241227171353.404432-1-mitltlatltl@gmail.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The Embedded Controller in the Huawei Matebook E Go (s8280xp) is accessible on &i2c15 and provides battery and adapter status, port orientation status, as well as HPD event notifications for two USB Type-C port, etc. Add the EC to the device tree and describe the relationship among the type-c ports, orientation switches and the QMP combo PHY. Signed-off-by: Pengyu Luo --- .../boot/dts/qcom/sc8280xp-huawei-gaokun3.dts | 139 ++++++++++++++++++ 1 file changed, 139 insertions(+) diff --git a/arch/arm64/boot/dts/qcom/sc8280xp-huawei-gaokun3.dts b/arch/arm64/boot/dts/qcom/sc8280xp-huawei-gaokun3.dts index 09b95f89e..09ca9a560 100644 --- a/arch/arm64/boot/dts/qcom/sc8280xp-huawei-gaokun3.dts +++ b/arch/arm64/boot/dts/qcom/sc8280xp-huawei-gaokun3.dts @@ -28,6 +28,7 @@ / { aliases { i2c4 = &i2c4; + i2c15 = &i2c15; serial1 = &uart2; }; @@ -216,6 +217,40 @@ map1 { }; }; + usb0-sbu-mux { + compatible = "pericom,pi3usb102", "gpio-sbu-mux"; + + select-gpios = <&tlmm 164 GPIO_ACTIVE_HIGH>; + + pinctrl-names = "default"; + pinctrl-0 = <&usb0_sbu_default>; + + orientation-switch; + + port { + usb0_sbu_mux: endpoint { + remote-endpoint = <&ucsi0_sbu>; + }; + }; + }; + + usb1-sbu-mux { + compatible = "pericom,pi3usb102", "gpio-sbu-mux"; + + select-gpios = <&tlmm 47 GPIO_ACTIVE_HIGH>; + + pinctrl-names = "default"; + pinctrl-0 = <&usb1_sbu_default>; + + orientation-switch; + + port { + usb1_sbu_mux: endpoint { + remote-endpoint = <&ucsi1_sbu>; + }; + }; + }; + wcn6855-pmu { compatible = "qcom,wcn6855-pmu"; @@ -584,6 +619,81 @@ touchscreen@4f { }; +&i2c15 { + clock-frequency = <400000>; + + pinctrl-0 = <&i2c15_default>; + pinctrl-names = "default"; + + status = "okay"; + + embedded-controller@38 { + compatible = "huawei,sc8280xp-gaokun-ec", "huawei,gaokun-ec"; + reg = <0x38>; + + interrupts-extended = <&tlmm 107 IRQ_TYPE_LEVEL_LOW>; + + #address-cells = <1>; + #size-cells = <0>; + + connector@0 { + compatible = "usb-c-connector"; + reg = <0>; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + ucsi0_ss_in: endpoint { + remote-endpoint = <&usb_0_qmpphy_out>; + }; + }; + + port@1 { + reg = <1>; + + ucsi0_sbu: endpoint { + remote-endpoint = <&usb0_sbu_mux>; + }; + }; + }; + }; + + connector@1 { + compatible = "usb-c-connector"; + reg = <1>; + power-role = "dual"; + data-role = "dual"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + ucsi1_ss_in: endpoint { + remote-endpoint = <&usb_1_qmpphy_out>; + }; + }; + + port@1 { + reg = <1>; + + ucsi1_sbu: endpoint { + remote-endpoint = <&usb1_sbu_mux>; + }; + }; + }; + }; + }; +}; + &mdss0 { status = "okay"; }; @@ -1025,6 +1135,10 @@ &usb_0_qmpphy_dp_in { remote-endpoint = <&mdss0_dp0_out>; }; +&usb_0_qmpphy_out { + remote-endpoint = <&ucsi0_ss_in>; +}; + &usb_1 { status = "okay"; }; @@ -1054,6 +1168,10 @@ &usb_1_qmpphy_dp_in { remote-endpoint = <&mdss0_dp1_out>; }; +&usb_1_qmpphy_out { + remote-endpoint = <&ucsi1_ss_in>; +}; + &usb_2 { status = "okay"; }; @@ -1177,6 +1295,13 @@ i2c4_default: i2c4-default-state { bias-disable; }; + i2c15_default: i2c15-default-state { + pins = "gpio36", "gpio37"; + function = "qup15"; + drive-strength = <2>; + bias-pull-up; + }; + mode_pin_active: mode-pin-state { pins = "gpio26"; function = "gpio"; @@ -1301,6 +1426,20 @@ tx-pins { }; }; + usb0_sbu_default: usb0-sbu-state { + pins = "gpio164"; + function = "gpio"; + bias-disable; + drive-strength = <16>; + }; + + usb1_sbu_default: usb1-sbu-state { + pins = "gpio47"; + function = "gpio"; + bias-disable; + drive-strength = <16>; + }; + wcd_default: wcd-default-state { reset-pins { pins = "gpio106";