[PATCH 02/28] mfd: zl3073x: Register itself as devlink device

Ivan Vecera
2025-04-07T17:29:05Z

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.

Reviewed-by: Michal Schmidt <mschmidt@redhat.com>
Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
drivers/mfd/Kconfig | 3 +++
drivers/mfd/zl3073x-core.c | 27 +++++++++++++++++++++++++--
2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
index 30b36e3ee8f7f..a838d5dca4579 100644
--- a/drivers/mfd/Kconfig
+++ b/drivers/mfd/Kconfig
@@ -2424,11 +2424,13 @@ config MFD_UPBOARD_FPGA

config MFD_ZL3073X_CORE
tristate
+ select NET_DEVLINK
select MFD_CORE

config MFD_ZL3073X_I2C
tristate "Microchip Azurite DPLL/PTP/SyncE with I2C"
depends on I2C
+ depends on NET
select MFD_ZL3073X_CORE
select REGMAP_I2C
help
@@ -2441,6 +2443,7 @@ config MFD_ZL3073X_I2C

config MFD_ZL3073X_SPI
tristate "Microchip Azurite DPLL/PTP/SyncE with SPI"
+ depends on NET
depends on SPI
select MFD_ZL3073X_CORE
select REGMAP_SPI
diff --git a/drivers/mfd/zl3073x-core.c b/drivers/mfd/zl3073x-core.c
index 67a9d5a0e2d8c..71454f683eab0 100644
--- a/drivers/mfd/zl3073x-core.c
+++ b/drivers/mfd/zl3073x-core.c
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: GPL-2.0-only

#include <linux/module.h>
+#include <net/devlink.h>
#include "zl3073x.h"

/*
@@ -44,24 +45,46 @@ 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);
+}
+
struct zl3073x_dev *zl3073x_dev_alloc(struct device *dev)
{
- struct zl3073x_dev *zldev;
+ struct devlink *devlink;

- return devm_kzalloc(dev, sizeof(*zldev), GFP_KERNEL);
+ 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 devlink_priv(devlink);
}
EXPORT_SYMBOL_NS_GPL(zl3073x_dev_alloc, "ZL3073X");

int zl3073x_dev_init(struct zl3073x_dev *zldev)
{
+ struct devlink *devlink;
+
devm_mutex_init(zldev->dev, &zldev->lock);

+ devlink = priv_to_devlink(zldev);
+ devlink_register(devlink);
+
return 0;
}
EXPORT_SYMBOL_NS_GPL(zl3073x_dev_init, "ZL3073X");

void zl3073x_dev_exit(struct zl3073x_dev *zldev)
{
+ devlink_unregister(priv_to_devlink(zldev));
}
EXPORT_SYMBOL_NS_GPL(zl3073x_dev_exit, "ZL3073X");

--
2.48.1