From patchwork Wed Dec 4 07:24:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13893293 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F1ECE7716D for ; Wed, 4 Dec 2024 07:27:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lM0mNCtHjT+hsg9qAEDa4xZpSra1ZeG4WjgSFO0QQkI=; b=dxukcIBAJARSeSG86vC4ty3fvi ZlPWxgLLGnyy85B1ncPlEbtXm0KoXXeJvxB2kbc1BThdzslWoXAXbXYCVPUO/xaeFzQzUqJ76ZCyn n6GXu6K0mm5xDBbE4+lEVXeVR7z5nY9nA+ArvKOHG6COYFAgFQIqLFWY/GzkQU6yzXexsEmQ1Ig85 QwE+3QA6LQn1TPWkaojNI1NJDwJgsimpgXHNl4tuCC1JmBSkSOKfRnbiD+7qfawkZsfwph0//JhDP vGHHeAuZxenD43RUYDZgUlC7GGfhqkeJMhZ3pnSPe923zaIiV9t3OAvx3q1klkiidpEtfJJSbfPFI k3vy27Ww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIjn7-0000000BiIu-3fpD; Wed, 04 Dec 2024 07:27:21 +0000 Received: from mail-wm1-x331.google.com ([2a00:1450:4864:20::331]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIjl8-0000000BhqU-43Nb; Wed, 04 Dec 2024 07:25:20 +0000 Received: by mail-wm1-x331.google.com with SMTP id 5b1f17b1804b1-434a766b475so58844865e9.1; Tue, 03 Dec 2024 23:25:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733297117; x=1733901917; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=lM0mNCtHjT+hsg9qAEDa4xZpSra1ZeG4WjgSFO0QQkI=; b=UOFl743tlqFN+JeXSVjhVF5MNJEwfzewoAp/z3AJQPZMtceIhmYdfxnfW3fnM/UB5N k++E41LOvgMfs5b/F92mHehehgSnHTIzj64gavELOpuOSBjuHREWDVxYshZc/13xfwkM yjX1mTxzpO2EQXXTTCTpo+ATY70iPrgrOwv2S40g1w16vwwChzd0QN5OvEdrsUcN3GNo ED1WL7VBevi+XGFHFcQlOBxFrWBcEkKcmMHsdqt+eN1O+GYiSpv1jUnZbms/7pyITzP6 5jtomxxWgZC4n0AmzAqkZ//aqMG+/hhaAzGMB7uJT1x+HzBNgSqcMv3wjuXFXU+3u4fP Lc/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733297117; x=1733901917; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=lM0mNCtHjT+hsg9qAEDa4xZpSra1ZeG4WjgSFO0QQkI=; b=uJKAZpdzeHLufjSA4lH02nwCt7g1npu6K+qUBwwOo/1dOxLDEL3P+Itnzw5d+xyeFu l2rgA9OVAdsaC6LAA5JPKN8tkg82s7wEmdv0kQppyN1zUByO/8eHvRiYoeq3OcE5SRvx dblCYH2GPxwRe2FBvd0Dh3duI3t3iCc7K2YbvLvVKf+owr7BR5QRqxZdUrcVLVh7T7iT YpC3PrpRCEEZuC+KI1adhCAew0yS8Ue+erqeIwebXrLgP/PwQ+tIAxAJwEHnARnwywTC 9xRs9y3LBNaeucLLnJSvAWIaSjrzvhWQzcLrnwOMp2Mpc1Axm6PIf9XolphE+Hc5irdS s1vQ== X-Forwarded-Encrypted: i=1; AJvYcCVZlQYmMd4swmmidO/wCkrNoxZiMmWulDdqCatGvGepp+mI0d/PDJ+7+xRJhWDjC9B6Fq/JZ8qFNQQQQmB5f5Po@lists.infradead.org, AJvYcCWlTI6LWo074v6sKw0ceQxaVb/AJrY3MK9L0JgN3zystBp5oHHDUmnZOZ0gWH6WaX4va1oEImehhSpHDFfR/hk=@lists.infradead.org X-Gm-Message-State: AOJu0Yx0S3ZDBvqavEaGZ836nlfSwhRDTTZwVZowwsoErI+5tRyQX67z 7fDmO8l2NEYGUWQg/jkW8onKSRuLYjyQekpfUaf7+18PRInjpfut X-Gm-Gg: ASbGncuFSarqJto2oFE2ruj6TYcegh1nKoDb1orMeuHZsjooTE9BP/KhN6VwQO7qcmf R8G/0sIr+aNgt2BWi9Z0wN5FGNodpEnrVFLF6JnQZCOXdh3ksVz9rr4fFL5uaCUNZqfnnRCVrN6 dIPL/G3VPBpw59pWh7j5FbY0WGyPDzs+rJ4h9Sfz89jYPFpFotkp+89+q0ff6HyA7+ADlwKC1YF Prc6J4V8Iy9d7UPrAKzFkReGy7erx9d+QDB46Ara+zCo0RuUg6Fw7XarPn57TZEJX6urlhBlsVW OjHLYR7EybntTWzH304= X-Google-Smtp-Source: AGHT+IEhtL7LsG4DAXwbNqLf3tFfGzBkkKQkzEXZrrUsxaZJeipMuj9IjLDyKTikR4xXJlJjRYRVNg== X-Received: by 2002:a5d:5849:0:b0:385:fbb4:7d51 with SMTP id ffacd0b85a97d-385fd42d261mr4633208f8f.56.1733297117038; Tue, 03 Dec 2024 23:25:17 -0800 (PST) Received: from localhost.localdomain (93-34-91-161.ip49.fastwebnet.it. [93.34.91.161]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434d527257dsm14396655e9.1.2024.12.03.23.25.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 23:25:16 -0800 (PST) From: Christian Marangi To: Christian Marangi , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiner Kallweit , Russell King , Matthias Brugger , AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, upstream@airoha.com Subject: [net-next PATCH v8 1/4] net: dsa: add devm_dsa_register_switch() Date: Wed, 4 Dec 2024 08:24:08 +0100 Message-ID: <20241204072427.17778-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241204072427.17778-1-ansuelsmth@gmail.com> References: <20241204072427.17778-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241203_232519_002828_330B55F8 X-CRM114-Status: GOOD ( 13.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Some DSA driver can be simplified if devres takes care of unregistering the DSA switch. This permits to effectively drop the remove OP from driver that just execute the dsa_unregister_switch() and nothing else. Signed-off-by: Christian Marangi --- include/net/dsa.h | 1 + net/dsa/dsa.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 72ae65e7246a..c703d5dc3fb0 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1355,6 +1355,7 @@ static inline void dsa_tag_generic_flow_dissect(const struct sk_buff *skb, void dsa_unregister_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds); +int devm_dsa_register_switch(struct device *dev, struct dsa_switch *ds); void dsa_switch_shutdown(struct dsa_switch *ds); struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); void dsa_flush_workqueue(void); diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 5a7c0e565a89..aca6aee68248 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -1544,6 +1544,25 @@ int dsa_register_switch(struct dsa_switch *ds) } EXPORT_SYMBOL_GPL(dsa_register_switch); +static void devm_dsa_unregister_switch(void *data) +{ + struct dsa_switch *ds = data; + + dsa_unregister_switch(ds); +} + +int devm_dsa_register_switch(struct device *dev, struct dsa_switch *ds) +{ + int err; + + err = dsa_register_switch(ds); + if (err) + return err; + + return devm_add_action_or_reset(dev, devm_dsa_unregister_switch, ds); +} +EXPORT_SYMBOL_GPL(devm_dsa_register_switch); + static void dsa_switch_remove(struct dsa_switch *ds) { struct dsa_switch_tree *dst = ds->dst; From patchwork Wed Dec 4 07:24:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13893294 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 35E85E7716D for ; Wed, 4 Dec 2024 07:28:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=UObQQxVp3PNi/U3LeYQmo0T4c/idtN7E2PfgKAA5yAg=; b=rd2nG0tMGac0UPzZLUFF2O+/Zx cOZ4/V1U8p03eiTyXmgefG3l+Ns1HStOxwjIKCF/A/eZJLBawHXEsWBPBfv/A7zVfPooV9gIz+lJH KHxSzUdXciSYvV1J1LNpNcquOkDDwthXZAwMnCPzJBNlQucv0pNfv7itP1uUeoIy8V7sbrqVDNPyd aumfu87B740QwWWhu4rHvInji7IRzXnfs0a/ndQh+rCFPQ/IsAp8ENAcTUzkWY54LPCncEBwCfH7G pWSNMsb+15BM/JoKjw/EgPJIEBWUDmlh6INlGsEzEI+VfAtxMIVdxac/Zt9Qp0nqomf4lH5648Prm HPvG0j/w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIjo6-0000000BiTb-0ap1; Wed, 04 Dec 2024 07:28:22 +0000 Received: from mail-wm1-x32d.google.com ([2a00:1450:4864:20::32d]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIjlB-0000000BhrP-1MeJ; Wed, 04 Dec 2024 07:25:22 +0000 Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-434a2033562so52972155e9.1; Tue, 03 Dec 2024 23:25:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733297120; x=1733901920; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=UObQQxVp3PNi/U3LeYQmo0T4c/idtN7E2PfgKAA5yAg=; b=YbGauGajUQs7L03mCRjRlEa+h/wwAmmpkqhttJCJ4MlwJVRiQPbqw5EEfcejybN686 qcPrU8ep2SaQJ1USuPMg4ztnpvo8/mrSG0Mag1qU0sSOPRuy2gBmMAHYd2g5HXBFub5r s0nDZAB39eXwEBti/dUQyJV8joTGX8auiTci5fhT3IkRsBRd8T2QmT9uKbCP+aEtYwEx PHovv/2j8wGlctkfRhjWKXN3CKAs+vwM2srMlXVEF4gBXRMqG3Aaf7XpkwPdmD/Rxm75 GqDTizXkFSWx6Va6MjjN5ZFpST13yxhfadHJDxaVR0m8YcEmqgiMPkTk8rVHj9Ma74fI D/uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733297120; x=1733901920; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=UObQQxVp3PNi/U3LeYQmo0T4c/idtN7E2PfgKAA5yAg=; b=gKfA639bEDOWo80q0WNKYxP+zzLHSMKf+e/MQw5wKgcqE76gtTjHjYpvmbUC0ISbxB RmyNBNfA77OCUrxX7yoJQSK9Dyl4I1St08IW6fFOJ19cGab/xhKkVMro4I/4sZFwR2Kr QGSRlyr1ba8K45B4Au4r67DWJdsHNuiZoct1GvYIIMuSrRXmL0APZESFZ+jCaDKuXF4y MStCy07PL97KwZtFS2YEWBv98lEH0gvpgZsNajlJURLwLfXQ+8NSuYbZ55rg1JpY3oeP ZULbFPnnpA7/GQiVYKybMcIRLt2Vqe28a4yp7MWhtdpcOSNITsWiHxSavnq+vfTmy6t4 znqQ== X-Forwarded-Encrypted: i=1; AJvYcCVC29dO3rasCqENGlKTufJlSTtiPD7NvAX1ORDbAv8uikfH9JHC43vdnVtW6TIjyx9Q8Ubtu5F/M9I6r719e4NE@lists.infradead.org, AJvYcCXkjo8lfqzaYMXCH9cbLvTv/6j5lX9e4lucTdRiexaXC3q/+r3POhoYqVlySP7AsO4cHwCJvSWaVUTLqPR7Ajk=@lists.infradead.org X-Gm-Message-State: AOJu0Yw3bTsgBosBVZuQPdVkfNqlsZoJhF0o+BugLwz3VAdxXobbIUbL d4TJKPIW6+hE6LIb3uieiWqmynxIfp6rjno1kPBpeKcImXxuBiNs X-Gm-Gg: ASbGncs5vp7qkn+nRhgDgURHxZsy1sOPqxvYW4D4OkzKCOe/WjEmyke6Spo+blJxNX8 YSBL/+W4+JNZGVyv+0yb+psfCfMSN7dQBa0NcL0hUNI5fKmvkLdsVzd0J9L6YArV+jwZP/Be0LY GCBRHKxuuGquBH44jcxw8P2cB8qGWBTPlHgNuN/re4vp8tS1SIERIyumpobW1kIUxijAPYsl9QC xh+lG5gPl/wL3wRaEbO9MmehGL0DdBVtASmYRs65gm/RSDJG38NsNZ2gBlP1nTIGnHNA8soAj+h /kjAw1wQOdx3GbjVwSs= X-Google-Smtp-Source: AGHT+IG6GiOU8xXTwVBff1NMq8Zq0Y8B2/QsfVDLRgbuHim2FUJK1hmA+W5ob0jF5AAiiOWuiHlEzg== X-Received: by 2002:a05:600c:4f12:b0:434:a962:2a8c with SMTP id 5b1f17b1804b1-434d0a03abfmr44310995e9.22.1733297119576; Tue, 03 Dec 2024 23:25:19 -0800 (PST) Received: from localhost.localdomain (93-34-91-161.ip49.fastwebnet.it. [93.34.91.161]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434d527257dsm14396655e9.1.2024.12.03.23.25.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 23:25:18 -0800 (PST) From: Christian Marangi To: Christian Marangi , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiner Kallweit , Russell King , Matthias Brugger , AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, upstream@airoha.com Subject: [net-next PATCH v8 2/4] dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation Date: Wed, 4 Dec 2024 08:24:09 +0100 Message-ID: <20241204072427.17778-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241204072427.17778-1-ansuelsmth@gmail.com> References: <20241204072427.17778-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241203_232521_408902_E6F0AE64 X-CRM114-Status: GOOD ( 18.10 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add Airoha AN8855 5 port Gigabit Switch documentation. The switch node requires an additional mdio node to describe each internal PHY absolute address on the bus. Calibration values might be stored in switch EFUSE and internal PHY might need to be calibrated, in such case, airoha,ext-surge needs to be enabled and relative NVMEM cells needs to be defined in nvmem-layout node. Signed-off-by: Christian Marangi Reviewed-by: Rob Herring (Arm) --- .../bindings/net/dsa/airoha,an8855.yaml | 242 ++++++++++++++++++ 1 file changed, 242 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml diff --git a/Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml b/Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file mode 100644 index 000000000000..8ea2fadbab85 --- /dev/null +++ b/Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml @@ -0,0 +1,242 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/dsa/airoha,an8855.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Airoha AN8855 Gigabit switch + +maintainers: + - Christian Marangi + +description: > + Airoha AN8855 is a 5-port Gigabit Switch. + + The switch node requires an additional mdio node to describe each internal + PHY relative offset as the PHY address for the switch match the one for + the PHY ports. On top of internal PHY address, the switch base PHY address + is added. + + Also the switch base PHY address can be configured and changed after the + first initialization. On reset, the switch PHY address is ALWAYS 1. + +properties: + compatible: + const: airoha,an8855 + + reg: + maxItems: 1 + + reset-gpios: + description: + GPIO to be used to reset the whole device + maxItems: 1 + + airoha,ext-surge: + $ref: /schemas/types.yaml#/definitions/flag + description: + Calibrate the internal PHY with the calibration values stored in EFUSE + for the r50Ohm values. + + '#nvmem-cell-cells': + const: 0 + + nvmem-layout: + $ref: /schemas/nvmem/layouts/nvmem-layout.yaml + description: + NVMEM Layout for exposed EFUSE. (for example to propagate calibration + value for r50Ohm for internal PHYs) + + mdio: + $ref: /schemas/net/mdio.yaml# + unevaluatedProperties: false + description: + Define the absolute address of the internal PHY for each port. + +$ref: dsa.yaml# + +required: + - compatible + - reg + +unevaluatedProperties: false + +examples: + - | + #include + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + switch@1 { + compatible = "airoha,an8855"; + reg = <1>; + reset-gpios = <&pio 39 0>; + + airoha,ext-surge; + + #nvmem-cell-cells = <0>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + shift_sel_port0_tx_a: shift-sel-port0-tx-a@c { + reg = <0xc 0x4>; + }; + + shift_sel_port0_tx_b: shift-sel-port0-tx-b@10 { + reg = <0x10 0x4>; + }; + + shift_sel_port0_tx_c: shift-sel-port0-tx-c@14 { + reg = <0x14 0x4>; + }; + + shift_sel_port0_tx_d: shift-sel-port0-tx-d@18 { + reg = <0x18 0x4>; + }; + + shift_sel_port1_tx_a: shift-sel-port1-tx-a@1c { + reg = <0x1c 0x4>; + }; + + shift_sel_port1_tx_b: shift-sel-port1-tx-b@20 { + reg = <0x20 0x4>; + }; + + shift_sel_port1_tx_c: shift-sel-port1-tx-c@24 { + reg = <0x24 0x4>; + }; + + shift_sel_port1_tx_d: shift-sel-port1-tx-d@28 { + reg = <0x28 0x4>; + }; + + shift_sel_port2_tx_a: shift-sel-port2-tx-a@2c { + reg = <0x2c 0x4>; + }; + + shift_sel_port2_tx_b: shift-sel-port2-tx-b@30 { + reg = <0x30 0x4>; + }; + + shift_sel_port2_tx_c: shift-sel-port2-tx-c@34 { + reg = <0x34 0x4>; + }; + + shift_sel_port2_tx_d: shift-sel-port2-tx-d@38 { + reg = <0x38 0x4>; + }; + + shift_sel_port3_tx_a: shift-sel-port3-tx-a@4c { + reg = <0x4c 0x4>; + }; + + shift_sel_port3_tx_b: shift-sel-port3-tx-b@50 { + reg = <0x50 0x4>; + }; + + shift_sel_port3_tx_c: shift-sel-port3-tx-c@54 { + reg = <0x54 0x4>; + }; + + shift_sel_port3_tx_d: shift-sel-port3-tx-d@58 { + reg = <0x58 0x4>; + }; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + label = "lan1"; + phy-mode = "internal"; + phy-handle = <&internal_phy1>; + }; + + port@1 { + reg = <1>; + label = "lan2"; + phy-mode = "internal"; + phy-handle = <&internal_phy2>; + }; + + port@2 { + reg = <2>; + label = "lan3"; + phy-mode = "internal"; + phy-handle = <&internal_phy3>; + }; + + port@3 { + reg = <3>; + label = "lan4"; + phy-mode = "internal"; + phy-handle = <&internal_phy4>; + }; + + port@5 { + reg = <5>; + label = "cpu"; + ethernet = <&gmac0>; + phy-mode = "2500base-x"; + + fixed-link { + speed = <2500>; + full-duplex; + pause; + }; + }; + }; + + mdio { + #address-cells = <1>; + #size-cells = <0>; + + internal_phy1: phy@1 { + reg = <1>; + + nvmem-cells = <&shift_sel_port0_tx_a>, + <&shift_sel_port0_tx_b>, + <&shift_sel_port0_tx_c>, + <&shift_sel_port0_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + + internal_phy2: phy@2 { + reg = <2>; + + nvmem-cells = <&shift_sel_port1_tx_a>, + <&shift_sel_port1_tx_b>, + <&shift_sel_port1_tx_c>, + <&shift_sel_port1_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + + internal_phy3: phy@3 { + reg = <3>; + + nvmem-cells = <&shift_sel_port2_tx_a>, + <&shift_sel_port2_tx_b>, + <&shift_sel_port2_tx_c>, + <&shift_sel_port2_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + + internal_phy4: phy@4 { + reg = <4>; + + nvmem-cells = <&shift_sel_port3_tx_a>, + <&shift_sel_port3_tx_b>, + <&shift_sel_port3_tx_c>, + <&shift_sel_port3_tx_d>; + nvmem-cell-names = "tx_a", "tx_b", "tx_c", "tx_d"; + }; + }; + }; + }; From patchwork Wed Dec 4 07:24:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13893297 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D75A9E7716D for ; Wed, 4 Dec 2024 07:29:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:To:From:Reply-To: Cc:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Svrsg3mmKKAv3YlnGrb0UzTznAqTSntGHCBI+3zPRtg=; b=VCdFFDlSVTcc7mHozDyLWHKLCn Qnnopp8NDCS+NypmgXb5yzutlKZR3YtYCCfvvZSi8nO+ZuOO4toxGrztNj73uA9xUBxeYiw+kU8vS tfxf7XKpl+/yyVMvjBqNTvEQ7UGPCTyS1n0pMZFiN2GLRhBD7AGKoOVlqDv7yydS9y28+GTMCG/jq eWI/cNtaWyBqkrwkhHlQ/9xpXQ9VRZj6VI+bMuyool33xLob8EgavS6M9lRzsB9KcYzoRCGVX/dMp t7nG0AK3DPWL3CJrcmpIwZwpyexAkl6TQjdKxJWIP/BaGPp3c0UB+K94vToQFpxKP63Nw+hjRvnYt rS6rOe7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tIjp5-0000000BieR-0GQW; Wed, 04 Dec 2024 07:29:23 +0000 Received: from mail-wm1-x32f.google.com ([2a00:1450:4864:20::32f]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tIjlF-0000000BhsX-0xC3; Wed, 04 Dec 2024 07:25:26 +0000 Received: by mail-wm1-x32f.google.com with SMTP id 5b1f17b1804b1-434ab114753so54537445e9.0; Tue, 03 Dec 2024 23:25:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1733297123; x=1733901923; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Svrsg3mmKKAv3YlnGrb0UzTznAqTSntGHCBI+3zPRtg=; b=d4d5+q1///WBLIPeybnuQm2KxKxIB96xaLeFuaqYh2zfIsrpWL7bdi6UjOiWQKQRYk 33UpzRO+PdbeEIp1Dfv6NYbKs9XZKho+9/0xBp6lfj9MArODnVTs1rN3rHi4O1xOCii9 jOKZtkD6/tFQH3ChItHrM8u2sGtmZh/uGhforOqsn2JEBfLNJoO8E0W3Y5m089rLZf6w zqgbM+Dlx7CPOUgAVUEE0u55PBq/7zsVTvrE3ov3qgK/cd8O8HQxT05oOBNfFVg3a+a4 ZE8QqlK6O9E9eNVfjoqQHx577cAq7CAxMne7JOxb4Yuue7FTaUfuo4hlPXGT54/tSrFK 9EAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1733297123; x=1733901923; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Svrsg3mmKKAv3YlnGrb0UzTznAqTSntGHCBI+3zPRtg=; b=B3Jexa4TwFz+5X4SvUy4dECjEdNVoIOtPcNEcrzNThDqjBlXAfU/Phvi2HekC3KW9A vk8WCK/62cnUyutroVmFpIwE3i7Go4gFd4yHcpNMjIH72D8qgFg8EYjY8sU9Bo+QonUN 3MFs7GebvlhwG8tm5lviyFQYRAbv2xNqv7C32tcxWkmSp6eOzD9ekIIt1d4vrFzwko1t Eo/ch2t+5u4fpAGVd5bH/nyIdgK7ICWJtwVCqJofW6X6UI39s5VS/PZQGePfodaBp8Zf GKEIWHAGCZiUJcehjs8W/QVz3d3xUsHvoc5BPtroF2vhuLHlMWldSSW42jGP8DZY4NKt GfyA== X-Forwarded-Encrypted: i=1; AJvYcCVcy+PUDmSB1LlIDfw7P19p6Bg/n+3Weoq8k8m9VM8d2XjgCd4ZxlKBO/fpqm1eejsv6cVRZmcBEwZdghazU/HB@lists.infradead.org, AJvYcCXCUa4L7UsvHs+WNY6QWWChGsIz2B0rBAB+9FXBDtY6LTVJ+V5BeFjmonVMsbnd5OVbQ8mh2k/CP1qgKJprXC4=@lists.infradead.org X-Gm-Message-State: AOJu0YxTraVuz2bBUi8+Ls95sV7E5wL/JZt7n2vx6tq7i0Y4QA4/XwbN kaGeTOyXpRUGdPRq0BHS0iOHMpYWoMEPLnq2tfbpm2QaoandGI+E X-Gm-Gg: ASbGncu+tP4ps4NJ5+OEJx8rV5Zuk8pkZgzFoIpkCTBqjqCy3q/bruQbaWwoJ99jJbJ UGCtdOpFk3Nwhtdq06T7MjmNo1SxqztfTfFdTPNkM4Fe0STV3LRbo5/4Yvzof1KceozIwG02HrL uDLZNOt8rhrKEAoGL+nWXHIabkBSHSfHAKpxoMOyeXmyf3E/qWL9KqvQTLWQYGXWn5cLlGEs3la SY6ejNYTKrWFkgPMO3NzG2mayDlBo4H4DVb7tWNfsS5LYT5vJwMn9GyhQdh3v9FV4ssF28JC5sg VUt038CiPZizmIbE1fg= X-Google-Smtp-Source: AGHT+IHs+H+xOKCLyIaYESZ+Zid3s9AZ9B7/IzL1DkG7+6BqVYPp8yphBjWfDoSDsRUvVmFct/n1PA== X-Received: by 2002:a05:600c:3554:b0:431:6083:cd38 with SMTP id 5b1f17b1804b1-434d09b0020mr45524075e9.6.1733297123184; Tue, 03 Dec 2024 23:25:23 -0800 (PST) Received: from localhost.localdomain (93-34-91-161.ip49.fastwebnet.it. [93.34.91.161]) by smtp.googlemail.com with ESMTPSA id 5b1f17b1804b1-434d527257dsm14396655e9.1.2024.12.03.23.25.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Dec 2024 23:25:22 -0800 (PST) From: Christian Marangi To: Christian Marangi , Andrew Lunn , Florian Fainelli , Vladimir Oltean , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Heiner Kallweit , Russell King , Matthias Brugger , AngeloGioacchino Del Regno , linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, upstream@airoha.com Subject: [net-next PATCH v8 4/4] net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY Date: Wed, 4 Dec 2024 08:24:11 +0100 Message-ID: <20241204072427.17778-5-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241204072427.17778-1-ansuelsmth@gmail.com> References: <20241204072427.17778-1-ansuelsmth@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241203_232525_268375_1A8329A4 X-CRM114-Status: GOOD ( 25.68 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add support for Airoha AN8855 Internal Switch Gigabit PHY. This is a simple PHY driver to configure and calibrate the PHY for the AN8855 Switch with the use of NVMEM cells. Signed-off-by: Christian Marangi --- MAINTAINERS | 1 + drivers/net/phy/Kconfig | 5 + drivers/net/phy/Makefile | 1 + drivers/net/phy/air_an8855.c | 267 +++++++++++++++++++++++++++++++++++ 4 files changed, 274 insertions(+) create mode 100644 drivers/net/phy/air_an8855.c diff --git a/MAINTAINERS b/MAINTAINERS index e3077d9feee2..cf34add2a0bb 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -726,6 +726,7 @@ S: Maintained F: Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml F: drivers/net/dsa/an8855.c F: drivers/net/dsa/an8855.h +F: drivers/net/phy/air_an8855.c AIROHA ETHERNET DRIVER M: Lorenzo Bianconi diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index ee3ea0b56d48..1d474038ea7f 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -79,6 +79,11 @@ config SFP comment "MII PHY device drivers" +config AIR_AN8855_PHY + tristate "Airoha AN8855 Internal Gigabit PHY" + help + Currently supports the internal Airoha AN8855 Switch PHY. + config AIR_EN8811H_PHY tristate "Airoha EN8811H 2.5 Gigabit PHY" help diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index 90f886844381..baba7894785b 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -35,6 +35,7 @@ obj-y += $(sfp-obj-y) $(sfp-obj-m) obj-$(CONFIG_ADIN_PHY) += adin.o obj-$(CONFIG_ADIN1100_PHY) += adin1100.o +obj-$(CONFIG_AIR_AN8855_PHY) += air_an8855.o obj-$(CONFIG_AIR_EN8811H_PHY) += air_en8811h.o obj-$(CONFIG_AMD_PHY) += amd.o obj-$(CONFIG_AMCC_QT2025_PHY) += qt2025.o diff --git a/drivers/net/phy/air_an8855.c b/drivers/net/phy/air_an8855.c new file mode 100644 index 000000000000..7ede6674994f --- /dev/null +++ b/drivers/net/phy/air_an8855.c @@ -0,0 +1,267 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2024 Christian Marangi + */ + +#include +#include +#include +#include + +#define AN8855_PHY_SELECT_PAGE 0x1f +#define AN8855_PHY_PAGE GENMASK(2, 0) +#define AN8855_PHY_PAGE_STANDARD FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x0) +#define AN8855_PHY_PAGE_EXTENDED_1 FIELD_PREP_CONST(AN8855_PHY_PAGE, 0x1) + +/* MII Registers Page 1 */ +#define AN8855_PHY_EXT_REG_14 0x14 +#define AN8855_PHY_EN_DOWN_SHIFT BIT(4) + +/* R50 Calibration regs in MDIO_MMD_VEND1 */ +#define AN8855_PHY_R500HM_RSEL_TX_AB 0x174 +#define AN8855_PHY_R50OHM_RSEL_TX_A_EN BIT(15) +#define AN8855_PHY_R50OHM_RSEL_TX_A GENMASK(14, 8) +#define AN8855_PHY_R50OHM_RSEL_TX_B_EN BIT(7) +#define AN8855_PHY_R50OHM_RSEL_TX_B GENMASK(6, 0) +#define AN8855_PHY_R500HM_RSEL_TX_CD 0x175 +#define AN8855_PHY_R50OHM_RSEL_TX_C_EN BIT(15) +#define AN8855_PHY_R50OHM_RSEL_TX_C GENMASK(14, 8) +#define AN8855_PHY_R50OHM_RSEL_TX_D_EN BIT(7) +#define AN8855_PHY_R50OHM_RSEL_TX_D GENMASK(6, 0) + +#define AN8855_SWITCH_EFUSE_R50O GENMASK(30, 24) + +/* PHY TX PAIR DELAY SELECT Register */ +#define AN8855_PHY_TX_PAIR_DLY_SEL_GBE 0x013 +#define AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_A_GBE GENMASK(14, 12) +#define AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_B_GBE GENMASK(10, 8) +#define AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_C_GBE GENMASK(6, 4) +#define AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_D_GBE GENMASK(2, 0) +/* PHY ADC Register */ +#define AN8855_PHY_RXADC_CTRL 0x0d8 +#define AN8855_PHY_RG_AD_SAMNPLE_PHSEL_A BIT(12) +#define AN8855_PHY_RG_AD_SAMNPLE_PHSEL_B BIT(8) +#define AN8855_PHY_RG_AD_SAMNPLE_PHSEL_C BIT(4) +#define AN8855_PHY_RG_AD_SAMNPLE_PHSEL_D BIT(0) +#define AN8855_PHY_RXADC_REV_0 0x0d9 +#define AN8855_PHY_RG_AD_RESERVE0_A GENMASK(15, 8) +#define AN8855_PHY_RG_AD_RESERVE0_B GENMASK(7, 0) +#define AN8855_PHY_RXADC_REV_1 0x0da +#define AN8855_PHY_RG_AD_RESERVE0_C GENMASK(15, 8) +#define AN8855_PHY_RG_AD_RESERVE0_D GENMASK(7, 0) + +#define AN8855_PHY_ID 0xc0ff0410 + +#define AN8855_PHY_FLAGS_EN_CALIBRATION BIT(0) + +struct air_an8855_priv { + u8 calibration_data[4]; +}; + +static const u8 dsa_r50ohm_table[] = { + 127, 127, 127, 127, 127, 127, 127, 127, 127, 127, + 127, 127, 127, 127, 127, 127, 127, 126, 122, 117, + 112, 109, 104, 101, 97, 94, 90, 88, 84, 80, + 78, 74, 72, 68, 66, 64, 61, 58, 56, 53, + 51, 48, 47, 44, 42, 40, 38, 36, 34, 32, + 31, 28, 27, 24, 24, 22, 20, 18, 16, 16, + 14, 12, 11, 9 +}; + +static int en8855_get_r50ohm_val(struct device *dev, const char *calib_name, + u8 *dest) +{ + u32 shift_sel, val; + int ret; + int i; + + ret = nvmem_cell_read_u32(dev, calib_name, &val); + if (ret) + return ret; + + shift_sel = FIELD_GET(AN8855_SWITCH_EFUSE_R50O, val); + for (i = 0; i < ARRAY_SIZE(dsa_r50ohm_table); i++) + if (dsa_r50ohm_table[i] == shift_sel) + break; + + if (i < 8 || i >= ARRAY_SIZE(dsa_r50ohm_table)) + *dest = dsa_r50ohm_table[25]; + else + *dest = dsa_r50ohm_table[i - 8]; + + return 0; +} + +static int an8855_probe(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + struct device_node *node = dev->of_node; + struct air_an8855_priv *priv; + int ret; + + /* If we don't have a node, skip get calib */ + if (!node) + return 0; + + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); + if (!priv) + return -ENOMEM; + + ret = en8855_get_r50ohm_val(dev, "tx_a", &priv->calibration_data[0]); + if (ret) + return ret; + + ret = en8855_get_r50ohm_val(dev, "tx_b", &priv->calibration_data[1]); + if (ret) + return ret; + + ret = en8855_get_r50ohm_val(dev, "tx_c", &priv->calibration_data[2]); + if (ret) + return ret; + + ret = en8855_get_r50ohm_val(dev, "tx_d", &priv->calibration_data[3]); + if (ret) + return ret; + + phydev->priv = priv; + + return 0; +} + +static int an8855_get_downshift(struct phy_device *phydev, u8 *data) +{ + int val; + + val = phy_read_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1, AN8855_PHY_EXT_REG_14); + if (val < 0) + return val; + + *data = val & AN8855_PHY_EN_DOWN_SHIFT ? DOWNSHIFT_DEV_DEFAULT_COUNT : + DOWNSHIFT_DEV_DISABLE; + + return 0; +} + +static int an8855_set_downshift(struct phy_device *phydev, u8 cnt) +{ + u16 ds = cnt != DOWNSHIFT_DEV_DISABLE ? AN8855_PHY_EN_DOWN_SHIFT : 0; + + return phy_modify_paged(phydev, AN8855_PHY_PAGE_EXTENDED_1, + AN8855_PHY_EXT_REG_14, AN8855_PHY_EN_DOWN_SHIFT, + ds); +} + +static int an8855_config_init(struct phy_device *phydev) +{ + struct air_an8855_priv *priv = phydev->priv; + int ret; + + /* Enable HW auto downshift */ + ret = an8855_set_downshift(phydev, DOWNSHIFT_DEV_DEFAULT_COUNT); + if (ret) + return ret; + + /* Apply calibration values, if needed. + * AN8855_PHY_FLAGS_EN_CALIBRATION signal this. + */ + if (priv && phydev->dev_flags & AN8855_PHY_FLAGS_EN_CALIBRATION) { + u8 *calibration_data = priv->calibration_data; + + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_R500HM_RSEL_TX_AB, + AN8855_PHY_R50OHM_RSEL_TX_A | AN8855_PHY_R50OHM_RSEL_TX_B, + FIELD_PREP(AN8855_PHY_R50OHM_RSEL_TX_A, calibration_data[0]) | + FIELD_PREP(AN8855_PHY_R50OHM_RSEL_TX_B, calibration_data[1])); + if (ret) + return ret; + ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_R500HM_RSEL_TX_CD, + AN8855_PHY_R50OHM_RSEL_TX_C | AN8855_PHY_R50OHM_RSEL_TX_D, + FIELD_PREP(AN8855_PHY_R50OHM_RSEL_TX_C, calibration_data[2]) | + FIELD_PREP(AN8855_PHY_R50OHM_RSEL_TX_D, calibration_data[3])); + if (ret) + return ret; + } + + /* Apply values to reduce signal noise */ + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_TX_PAIR_DLY_SEL_GBE, + FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_A_GBE, 0x4) | + FIELD_PREP(AN8855_PHY_CR_DA_TX_PAIR_DELKAY_SEL_C_GBE, 0x4)); + if (ret) + return ret; + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_CTRL, + AN8855_PHY_RG_AD_SAMNPLE_PHSEL_A | + AN8855_PHY_RG_AD_SAMNPLE_PHSEL_C); + if (ret) + return ret; + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_0, + FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_A, 0x1)); + if (ret) + return ret; + ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, AN8855_PHY_RXADC_REV_1, + FIELD_PREP(AN8855_PHY_RG_AD_RESERVE0_C, 0x1)); + if (ret) + return ret; + + return 0; +} + +static int an8855_get_tunable(struct phy_device *phydev, + struct ethtool_tunable *tuna, void *data) +{ + switch (tuna->id) { + case ETHTOOL_PHY_DOWNSHIFT: + return an8855_get_downshift(phydev, data); + default: + return -EOPNOTSUPP; + } +} + +static int an8855_set_tunable(struct phy_device *phydev, + struct ethtool_tunable *tuna, const void *data) +{ + switch (tuna->id) { + case ETHTOOL_PHY_DOWNSHIFT: + return an8855_set_downshift(phydev, *(const u8 *)data); + default: + return -EOPNOTSUPP; + } +} + +static int an8855_read_page(struct phy_device *phydev) +{ + return __phy_read(phydev, AN8855_PHY_SELECT_PAGE); +} + +static int an8855_write_page(struct phy_device *phydev, int page) +{ + return __phy_write(phydev, AN8855_PHY_SELECT_PAGE, page); +} + +static struct phy_driver an8855_driver[] = { +{ + PHY_ID_MATCH_EXACT(AN8855_PHY_ID), + .name = "Airoha AN8855 internal PHY", + /* PHY_GBIT_FEATURES */ + .flags = PHY_IS_INTERNAL, + .probe = an8855_probe, + .config_init = an8855_config_init, + .soft_reset = genphy_soft_reset, + .get_tunable = an8855_get_tunable, + .set_tunable = an8855_set_tunable, + .suspend = genphy_suspend, + .resume = genphy_resume, + .read_page = an8855_read_page, + .write_page = an8855_write_page, +}, }; + +module_phy_driver(an8855_driver); + +static struct mdio_device_id __maybe_unused an8855_tbl[] = { + { PHY_ID_MATCH_EXACT(AN8855_PHY_ID) }, + { } +}; + +MODULE_DEVICE_TABLE(mdio, an8855_tbl); + +MODULE_DESCRIPTION("Airoha AN8855 PHY driver"); +MODULE_AUTHOR("Christian Marangi "); +MODULE_LICENSE("GPL");