[net-next,7/7] net: lan743x: Register the platform device for sfp pluggable module
Commit Message
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(+)
@@ -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,
@@ -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))