[PATCH v3 net-next 6/8] mfd: zl3073x: Add clock_id field

Ivan Vecera
2025-04-16T16:22:30Z

Add .clock_id to zl3073x_dev structure that will be used by later
commits introducing DPLL driver. The clock ID is necessary for DPLL
device registration. To generate such ID use chip ID read during
device initialization for this. For the case where are multiple
zl3073x based chips the chip ID is shifted and lower bits are filled
by an unique value. For I2C case it is I2C device address and for SPI
case it is chip-select value.

Signed-off-by: Ivan Vecera <ivecera@redhat.com>
---
drivers/mfd/zl3073x-core.c | 6 +++++-
drivers/mfd/zl3073x-i2c.c | 4 +++-
drivers/mfd/zl3073x-spi.c | 4 +++-
drivers/mfd/zl3073x.h | 2 +-
include/linux/mfd/zl3073x.h | 2 ++
5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/mfd/zl3073x-core.c b/drivers/mfd/zl3073x-core.c
index 3d18786c769d2..5a0e2bb1a969f 100644
--- a/drivers/mfd/zl3073x-core.c
+++ b/drivers/mfd/zl3073x-core.c
@@ -485,13 +485,14 @@ static void zl3073x_devlink_unregister(void *ptr)
* zl3073x_dev_probe - initialize zl3073x device
* @zldev: pointer to zl3073x device
* @chip_info: chip info based on compatible
+ * @dev_id: device ID to be used as part of clock ID
*
* Common initialization of zl3073x device structure.
*
* Returns: 0 on success, <0 on error
*/
int zl3073x_dev_probe(struct zl3073x_dev *zldev,
- const struct zl3073x_chip_info *chip_info)
+ const struct zl3073x_chip_info *chip_info, u8 dev_id)
{
u16 id, revision, fw_ver;
struct devlink *devlink;
@@ -533,6 +534,9 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,
FIELD_GET(GENMASK(15, 8), cfg_ver),
FIELD_GET(GENMASK(7, 0), cfg_ver));

+ /* Use chip ID and given dev ID as clock ID */
+ zldev->clock_id = ((u64)id << 8) | dev_id;
+
/* Register the device as devlink device */
devlink = priv_to_devlink(zldev);
devlink_register(devlink);
diff --git a/drivers/mfd/zl3073x-i2c.c b/drivers/mfd/zl3073x-i2c.c
index 76bc9a0463180..ae0ad6b7b0129 100644
--- a/drivers/mfd/zl3073x-i2c.c
+++ b/drivers/mfd/zl3073x-i2c.c
@@ -29,7 +29,9 @@ static int zl3073x_i2c_probe(struct i2c_client *client)
return PTR_ERR(zldev->regmap);
}

- return zl3073x_dev_probe(zldev, i2c_get_match_data(client));
+ /* Initialize device and use I2C address as dev ID */
+ return zl3073x_dev_probe(zldev, i2c_get_match_data(client),
+ client->addr);
}

static const struct i2c_device_id zl3073x_i2c_id[] = {
diff --git a/drivers/mfd/zl3073x-spi.c b/drivers/mfd/zl3073x-spi.c
index d0fc2d2221c0d..6e6ec88b40d72 100644
--- a/drivers/mfd/zl3073x-spi.c
+++ b/drivers/mfd/zl3073x-spi.c
@@ -29,7 +29,9 @@ static int zl3073x_spi_probe(struct spi_device *spi)
return PTR_ERR(zldev->regmap);
}

- return zl3073x_dev_probe(zldev, spi_get_device_match_data(spi));
+ /* Initialize device and use SPI chip select value as dev ID */
+ return zl3073x_dev_probe(zldev, spi_get_device_match_data(spi),
+ spi_get_chipselect(spi, 0));
}

static const struct spi_device_id zl3073x_spi_id[] = {
diff --git a/drivers/mfd/zl3073x.h b/drivers/mfd/zl3073x.h
index 3a2fea61cf579..abd1ab9a56ded 100644
--- a/drivers/mfd/zl3073x.h
+++ b/drivers/mfd/zl3073x.h
@@ -26,6 +26,6 @@ extern const struct zl3073x_chip_info zl3073x_chip_info[];
struct zl3073x_dev *zl3073x_devm_alloc(struct device *dev);
void zl3073x_dev_init_regmap_config(struct regmap_config *regmap_cfg);
int zl3073x_dev_probe(struct zl3073x_dev *zldev,
- const struct zl3073x_chip_info *chip_info);
+ const struct zl3073x_chip_info *chip_info, u8 dev_id);

#endif /* __ZL3073X_CORE_H */
diff --git a/include/linux/mfd/zl3073x.h b/include/linux/mfd/zl3073x.h
index 53813a8c39660..5074f64a70137 100644
--- a/include/linux/mfd/zl3073x.h
+++ b/include/linux/mfd/zl3073x.h
@@ -13,11 +13,13 @@ struct regmap;
* @dev: pointer to device
* @regmap: regmap to access device registers
* @mailbox_lock: mutex protecting an access to mailbox registers
+ * @clock_id: clock id of the device
*/
struct zl3073x_dev {
struct device *dev;
struct regmap *regmap;
struct mutex mailbox_lock;
+ u64 clock_id;
};

/**
--
2.48.1