From patchwork Tue Apr 11 09:27:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiawen Wu X-Patchwork-Id: 13207256 X-Patchwork-Delegate: kuba@kernel.org 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 100D3C77B75 for ; Tue, 11 Apr 2023 09:31:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229825AbjDKJa3 (ORCPT ); Tue, 11 Apr 2023 05:30:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbjDKJaY (ORCPT ); Tue, 11 Apr 2023 05:30:24 -0400 Received: from smtpbgau1.qq.com (smtpbgau1.qq.com [54.206.16.166]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F129272B; Tue, 11 Apr 2023 02:30:10 -0700 (PDT) X-QQ-mid: bizesmtp91t1681205301txy7fiff Received: from wxdbg.localdomain.com ( [183.129.236.74]) by bizesmtp.qq.com (ESMTP) with id ; Tue, 11 Apr 2023 17:28:20 +0800 (CST) X-QQ-SSF: 01400000000000H0Z000000A0000000 X-QQ-FEAT: q+yjhizk/eKRQYhLfYqTfb9ijkz37drwdg6S2J/VgfatOfFqAX/vIymqIPSDO pPqYRPLMf9n1vmk9j704XMlbNjzaHOoXHQOfMbHU3d4skhLGeNgkIeC1Lv4ZBoUNnK6kWU5 5HysShCZp3UNV5z+f+GybhTbuiWLLZVQI5h0tTi8/EDqCOSDhizIJE5P80MZT8su1eFDCGg kD0sImh4OnuaN8/gefsG3C3KQFNHkqxLkvRyRR2KENqyJhIWm3e2sG4Q109bG4utBvNyZWe M8KVBghWk0jJ6GDdu1zM5Uh/ftJksGJsN0JHslFJdtyaq4/YlmlXXb937/FBKe2J18PS9AB Frkpv321lVtdZAHdZ6kYSL3plAaFh5DaCVoYxnS5TANzwJvpOq6s/hxGAUEOceWV4kmQS8c 0JibgCbQ61g= X-QQ-GoodBg: 2 X-BIZMAIL-ID: 15729466026710604010 From: Jiawen Wu To: netdev@vger.kernel.org, linux@armlinux.org.uk Cc: linux-i2c@vger.kernel.org, linux-gpio@vger.kernel.org, mengyuanlou@net-swift.com, Jiawen Wu Subject: [PATCH net-next v2 3/6] net: txgbe: Add SFP module identify Date: Tue, 11 Apr 2023 17:27:22 +0800 Message-Id: <20230411092725.104992-4-jiawenwu@trustnetic.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20230411092725.104992-1-jiawenwu@trustnetic.com> References: <20230411092725.104992-1-jiawenwu@trustnetic.com> MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:trustnetic.com:qybglogicsvr:qybglogicsvr5 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Register SFP platform device to get modules information. Signed-off-by: Jiawen Wu Reviewed-by: Andrew Lunn --- drivers/net/ethernet/wangxun/Kconfig | 1 + .../net/ethernet/wangxun/txgbe/txgbe_phy.c | 28 +++++++++++++++++++ .../net/ethernet/wangxun/txgbe/txgbe_type.h | 1 + 3 files changed, 30 insertions(+) diff --git a/drivers/net/ethernet/wangxun/Kconfig b/drivers/net/ethernet/wangxun/Kconfig index 8cbf0dd48a2c..c5b62918db78 100644 --- a/drivers/net/ethernet/wangxun/Kconfig +++ b/drivers/net/ethernet/wangxun/Kconfig @@ -42,6 +42,7 @@ config TXGBE depends on PCI select LIBWX select I2C + select SFP help This driver supports Wangxun(R) 10GbE PCI Express family of adapters. diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c index 2721da1625e0..dd5ecfad56c1 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_phy.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0 /* Copyright (c) 2015 - 2023 Beijing WangXun Technology Co., Ltd. */ +#include #include #include #include @@ -206,6 +207,25 @@ static int txgbe_i2c_adapter_add(struct txgbe *txgbe) return 0; } +static int txgbe_sfp_register(struct txgbe *txgbe) +{ + struct pci_dev *pdev = txgbe->wx->pdev; + struct platform_device_info info = {}; + struct platform_device *sfp_dev; + + info.parent = &pdev->dev; + info.fwnode = software_node_fwnode(txgbe->nodes.group[SWNODE_SFP]); + info.name = "sfp"; + info.id = (pdev->bus->number << 8) | pdev->devfn; + sfp_dev = platform_device_register_full(&info); + if (IS_ERR(sfp_dev)) + return PTR_ERR(sfp_dev); + + txgbe->sfp_dev = sfp_dev; + + return 0; +} + int txgbe_init_phy(struct txgbe *txgbe) { int ret; @@ -222,6 +242,12 @@ int txgbe_init_phy(struct txgbe *txgbe) goto err; } + ret = txgbe_sfp_register(txgbe); + if (ret) { + wx_err(txgbe->wx, "failed to register sfp\n"); + goto err; + } + return 0; err: @@ -232,6 +258,8 @@ int txgbe_init_phy(struct txgbe *txgbe) void txgbe_remove_phy(struct txgbe *txgbe) { + if (txgbe->sfp_dev) + platform_device_unregister(txgbe->sfp_dev); if (txgbe->i2c_adap) i2c_del_adapter(txgbe->i2c_adap); diff --git a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h index 6c02af196157..a7d6f47cbe05 100644 --- a/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h +++ b/drivers/net/ethernet/wangxun/txgbe/txgbe_type.h @@ -162,6 +162,7 @@ struct txgbe { struct wx *wx; struct txgbe_nodes nodes; struct i2c_adapter *i2c_adap; + struct platform_device *sfp_dev; }; #endif /* _TXGBE_TYPE_H_ */