[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20250717171100.2245998-3-ivecera@redhat.com>
Date: Thu, 17 Jul 2025 19:11:00 +0200
From: Ivan Vecera <ivecera@...hat.com>
To: netdev@...r.kernel.org
Cc: Prathosh Satish <prathosh.satish@...rochip.com>,
Vadim Fedorenko <vadim.fedorenko@...ux.dev>,
Arkadiusz Kubalewski <arkadiusz.kubalewski@...el.com>,
Jiri Pirko <jiri@...nulli.us>,
Rob Herring <robh@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>,
Prathosh Satish <Prathosh.Satish@...rochip.com>,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
Michal Schmidt <mschmidt@...hat.com>,
Petr Oros <poros@...hat.com>
Subject: [PATCH net-next 2/2] dpll: zl3073x: Initialize clock ID from device property
The clock ID value can be specified by the platform via 'clock-id'
property. Use this property value to initialize clock ID and if it
is not specified generate random one as fallback.
Tested-by: Prathosh Satish <prathosh.satish@...rochip.com>
Signed-off-by: Ivan Vecera <ivecera@...hat.com>
---
drivers/dpll/zl3073x/core.c | 32 +++++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/drivers/dpll/zl3073x/core.c b/drivers/dpll/zl3073x/core.c
index 7ebcfc5ec1f09..f5245225f1d3b 100644
--- a/drivers/dpll/zl3073x/core.c
+++ b/drivers/dpll/zl3073x/core.c
@@ -9,6 +9,8 @@
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/netlink.h>
+#include <linux/property.h>
+#include <linux/random.h>
#include <linux/regmap.h>
#include <linux/sprintf.h>
#include <linux/string_choices.h>
@@ -932,6 +934,29 @@ zl3073x_dev_phase_meas_setup(struct zl3073x_dev *zldev, int num_channels)
return zl3073x_write_u8(zldev, ZL_REG_DPLL_PHASE_ERR_READ_MASK, mask);
}
+/**
+ * zl3073x_dev_clock_id_init - initialize clock ID
+ * @zldev: pointer to zl3073x device
+ *
+ * Initializes clock ID using device property if it is provided or
+ * generates random one.
+ */
+static void
+zl3073x_dev_clock_id_init(struct zl3073x_dev *zldev)
+{
+ u64 clock_id;
+ int rc;
+
+ /* Try to read clock ID from device property */
+ rc = device_property_read_u64(zldev->dev, "clock-id", &clock_id);
+
+ /* Generate random id if the property does not exist or value is zero */
+ if (rc || !clock_id)
+ clock_id = get_random_u64();
+
+ zldev->clock_id = clock_id;
+}
+
/**
* zl3073x_dev_probe - initialize zl3073x device
* @zldev: pointer to zl3073x device
@@ -985,11 +1010,8 @@ int zl3073x_dev_probe(struct zl3073x_dev *zldev,
FIELD_GET(GENMASK(15, 8), cfg_ver),
FIELD_GET(GENMASK(7, 0), cfg_ver));
- /* Generate random clock ID as the device has not such property that
- * could be used for this purpose. A user can later change this value
- * using devlink.
- */
- zldev->clock_id = get_random_u64();
+ /* Initialize clock ID */
+ zl3073x_dev_clock_id_init(zldev);
/* Initialize mutex for operations where multiple reads, writes
* and/or polls are required to be done atomically.
--
2.49.1
Powered by blists - more mailing lists