@@ -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.
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2015 - 2023 Beijing WangXun Technology Co., Ltd. */
+#include <linux/platform_device.h>
#include <linux/gpio/property.h>
#include <linux/iopoll.h>
#include <linux/i2c.h>
@@ -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);
@@ -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_ */
Register SFP platform device to get modules information. Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com> --- 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(+)