[PATCH v2 04/14] mfd: zl3073x: Register itself as devlink device

Ivan Vecera
2025-04-09T14:43:22Z

Use devlink_alloc() to alloc zl3073x_dev structure and register
the device as a devlink device. Follow-up patches add support for
devlink device info reporting and devlink flash interface will
be later used for flashing firmware and configuration.

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
v1->v2:
- dependency on NET moved to MFD_ZL3073X_CORE in Kconfig
- devlink register managed way
---
drivers/mfd/Kconfig | 2 ++
drivers/mfd/zl3073x-core.c | 35 +++++++++++++++++++++++++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 30b36e3ee8f7f..3c54b9e2b8003 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2424,6 +2424,8 @@ config MFD_UPBOARD_FPGA

config MFD_ZL3073X_CORE
tristate
+ depends on NET
+ select NET_DEVLINK
select MFD_CORE

config MFD_ZL3073X_I2C
diff --git a/drivers/mfd/zl3073x-core.c b/drivers/mfd/zl3073x-core.c
index ccb6987d04a20..116c6dd9eebc7 100644
--- a/drivers/mfd/zl3073x-core.c
+++ b/drivers/mfd/zl3073x-core.c
@@ -8,6 +8,7 @@
#include <linux/mfd/zl3073x.h>
#include <linux/module.h>
#include <linux/regmap.h>
+#include <net/devlink.h>
#include "zl3073x.h"

/*
@@ -58,6 +59,14 @@ const struct regmap_config *zl3073x_get_regmap_config(void)
}
EXPORT_SYMBOL_NS_GPL(zl3073x_get_regmap_config, "ZL3073X");

+static const struct devlink_ops zl3073x_devlink_ops = {
+};
+
+static void zl3073x_devlink_free(void *ptr)
+{
+ devlink_free(ptr);
+}
+
/**
* zl3073x_devm_alloc - allocates zl3073x device structure
* @dev: pointer to device structure
@@ -68,12 +77,25 @@ EXPORT_SYMBOL_NS_GPL(zl3073x_get_regmap_config, "ZL3073X");
*/
struct zl3073x_dev *zl3073x_devm_alloc(struct device *dev)
{
- struct zl3073x_dev *zldev;
+ struct devlink *devlink;
+
+ devlink = devlink_alloc(&zl3073x_devlink_ops,
+ sizeof(struct zl3073x_dev), dev);
+ if (!devlink)
+ return NULL;
+
+ if (devm_add_action_or_reset(dev, zl3073x_devlink_free, devlink))
+ return NULL;

- return devm_kzalloc(dev, sizeof(*zldev), GFP_KERNEL);
+ return devlink_priv(devlink);
}
EXPORT_SYMBOL_NS_GPL(zl3073x_devm_alloc, "ZL3073X");

+static void zl3073x_devlink_unregister(void *ptr)
+{
+ devlink_unregister(ptr);
+}
+
/**
* zl3073x_dev_init - initialize zl3073x device
* @zldev: pointer to zl3073x device
@@ -84,6 +106,7 @@ EXPORT_SYMBOL_NS_GPL(zl3073x_devm_alloc, "ZL3073X");
*/
int zl3073x_dev_init(struct zl3073x_dev *zldev)
{
+ struct devlink *devlink;
int rc;

rc = devm_mutex_init(zldev->dev, &zldev->lock);
@@ -92,6 +115,14 @@ int zl3073x_dev_init(struct zl3073x_dev *zldev)
return rc;
}

+ devlink = priv_to_devlink(zldev);
+ devlink_register(devlink);
+
+ rc = devm_add_action_or_reset(zldev->dev, zl3073x_devlink_unregister,
+ devlink);
+ if (rc)
+ return rc;
+
return 0;
}
EXPORT_SYMBOL_NS_GPL(zl3073x_dev_init, "ZL3073X");
--
2.48.1