[net-next,7/7] net: lan743x: Register the platform device for sfp pluggable module

Message ID 20230721060019.2737-8-Raju.Lakkaraju@microchip.com
State New
Headers
Series Add support to PHYLINK and SFP for PCI11x1x chips |

Commit Message

Raju Lakkaraju July 21, 2023, 6 a.m. UTC
  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@microchip.com>
---
 drivers/net/ethernet/microchip/lan743x_main.c | 39 +++++++++++++++++++
 drivers/net/ethernet/microchip/lan743x_main.h |  1 +
 2 files changed, 40 insertions(+)
  

Patch

diff --git a/drivers/net/ethernet/microchip/lan743x_main.c b/drivers/net/ethernet/microchip/lan743x_main.c
index 9b6326d035a8..2dd0965982fb 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.c
+++ b/drivers/net/ethernet/microchip/lan743x_main.c
@@ -17,6 +17,7 @@ 
 #include <linux/crc16.h>
 #include <linux/gpio/machine.h>
 #include <linux/i2c.h>
+#include <linux/platform_device.h>
 #include "../../../misc/mchp_pci1xxxx/mchp_pci1xxxx_gp.h"
 #include "lan743x_main.h"
 #include "lan743x_ethtool.h"
@@ -3228,6 +3229,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 void lan743x_mac_cfg_update(struct lan743x_adapter *adapter, bool link,
 				   int speed, const unsigned long *advertise)
 {
@@ -3715,6 +3741,9 @@  static void lan743x_hardware_cleanup(struct lan743x_adapter *adapter)
 	if (adapter->phylink)
 		phylink_destroy(adapter->phylink);
 
+	if (adapter->sfp_dev)
+		platform_device_unregister(adapter->sfp_dev);
+
 	if (adapter->nodes)
 		software_node_unregister_node_group(adapter->nodes->group);
 
@@ -3942,6 +3971,16 @@  static int lan743x_pcidev_probe(struct pci_dev *pdev,
 	adapter->sgmii_lsd = LINK_2500_MASTER;
 
 	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 sfp register (%d)\n", ret);
+			goto cleanup_hardware;
+		}
+
 		ret = lan743x_phylink_create(adapter->netdev);
 		if (ret) {
 			netif_err(adapter, probe, netdev,
diff --git a/drivers/net/ethernet/microchip/lan743x_main.h b/drivers/net/ethernet/microchip/lan743x_main.h
index 6b94d0e93cbb..d23cf1ca888c 100644
--- a/drivers/net/ethernet/microchip/lan743x_main.h
+++ b/drivers/net/ethernet/microchip/lan743x_main.h
@@ -1083,6 +1083,7 @@  struct lan743x_adapter {
 	struct i2c_adapter	*i2c_adap;
 	struct phylink		*phylink;
 	struct phylink_config	phylink_config;
+	struct platform_device	*sfp_dev;
 };
 
 #define LAN743X_COMPONENT_FLAG_RX(channel)  BIT(20 + (channel))