[PATCH net-next V2 3/5] net: lan743x: Register the platform device for sfp pluggable module

From: Raju Lakkaraju
Date: Wed Sep 11 2024 - 12:15:35 EST


Add support for sfp pluggable module as platform device handle the gpio
input and output signals and i2c bus access the sfp eeprom data.

Signed-off-by: Raju Lakkaraju <Raju.Lakkaraju@xxxxxxxxxxxxx>
---
Change List:
============
V1 -> V2:
- Add platform_device_unregister( ) when sfp register fail
V0 -> V1:
- No change

drivers/net/ethernet/microchip/Kconfig | 1 +
drivers/net/ethernet/microchip/lan743x_main.c | 43 +++++++++++++++++++
drivers/net/ethernet/microchip/lan743x_main.h | 1 +
3 files changed, 45 insertions(+)

diff --git a/drivers/net/ethernet/microchip/Kconfig b/drivers/net/ethernet/microchip/Kconfig
index 9c08a4af257a..3dacf39b49b4 100644
--- a/drivers/net/ethernet/microchip/Kconfig
+++ b/drivers/net/ethernet/microchip/Kconfig
@@ -52,6 +52,7 @@ config LAN743X
select PHYLINK
select I2C_PCI1XXXX
select GP_PCI1XXXX
+ select SFP
help
Support for the Microchip LAN743x and PCI11x1x families of PCI
Express Ethernet devices
diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index dc571020ae1b..c1061e2972f9 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -16,6 +16,7 @@
#include <linux/iopoll.h>
#include <linux/crc16.h>
#include <linux/phylink.h>
+#include <linux/platform_device.h>
#include "lan743x_main.h"
#include "lan743x_ethtool.h"

@@ -187,6 +188,11 @@ static int pci1xxxx_gpio_dev_get(struct lan743x_adapter *adapter)

static void lan743x_pci_cleanup(struct lan743x_adapter *adapter)
{
+ if (adapter->sfp_dev) {
+ platform_device_unregister(adapter->sfp_dev);
+ adapter->sfp_dev = NULL;
+ }
+
if (adapter->nodes) {
software_node_unregister_node_group(adapter->nodes->group);
kfree(adapter->nodes);
@@ -3062,6 +3068,31 @@ static int lan743x_swnodes_register(struct lan743x_adapter *adapter)
return software_node_register_node_group(nodes->group);
}

+static int lan743x_sfp_register(struct lan743x_adapter *adapter)
+{
+ struct pci_dev *pdev = adapter->pdev;
+ struct platform_device_info sfp_info;
+ struct platform_device *sfp_dev;
+
+ memset(&sfp_info, 0, sizeof(sfp_info));
+ sfp_info.parent = &adapter->pdev->dev;
+ sfp_info.fwnode = software_node_fwnode(adapter->nodes->group[SWNODE_SFP]);
+ sfp_info.name = "sfp";
+ sfp_info.id = (pdev->bus->number << 8) | pdev->devfn;
+ sfp_dev = platform_device_register_full(&sfp_info);
+ if (IS_ERR(sfp_dev)) {
+ netif_err(adapter, drv, adapter->netdev,
+ "Failed to register SFP device\n");
+ return PTR_ERR(sfp_dev);
+ }
+
+ adapter->sfp_dev = sfp_dev;
+ netif_dbg(adapter, drv, adapter->netdev,
+ "SFP platform device registered");
+
+ return 0;
+}
+
static int lan743x_phylink_sgmii_config(struct lan743x_adapter *adapter)
{
u32 sgmii_ctl;
@@ -3851,6 +3882,18 @@ static int lan743x_pcidev_probe(struct pci_dev *pdev,
if (ret)
goto cleanup_pci;

+ if (adapter->is_sfp_support_en) {
+ adapter->i2c_adap->dev.fwnode =
+ software_node_fwnode(adapter->nodes->group[SWNODE_I2C]);
+
+ ret = lan743x_sfp_register(adapter);
+ if (ret < 0) {
+ netif_err(adapter, probe, netdev,
+ "Failed to register sfp (%d)\n", ret);
+ goto cleanup_pci;
+ }
+ }
+
ret = lan743x_mdiobus_init(adapter);
if (ret)
goto cleanup_hardware;
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index bf0d0f285e39..c303a69c3bea 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -1129,6 +1129,7 @@ struct lan743x_adapter {
struct phylink_config phylink_config;
struct lan743x_sw_nodes *nodes;
struct i2c_adapter *i2c_adap;
+ struct platform_device *sfp_dev;
};

#define LAN743X_COMPONENT_FLAG_RX(channel) BIT(20 + (channel))
--
2.34.1