Re: [PATCH v4 03/10] clk: renesas: add R906G032 driver

2023-04-17 Thread Ralph Siemsen

On Mon, Apr 17, 2023 at 07:07:57PM +0200, Marek Vasut wrote:


R-Car , not RCAR .


Ack, will fix in next version (including in some commit msg)


+static int r9a06g032_clk_probe(struct udevice *dev)
+{
+   struct r9a06g032_priv *priv = dev_get_priv(dev);
+   int err;
+
+   priv->regmap = syscon_regmap_lookup_by_phandle(dev, "regmap");
+   if (IS_ERR(priv->regmap)) {
+   dev_dbg(dev, "unable to find regmap\n");
+   return PTR_ERR(priv->regmap);
+   }
+
+   /* Enable S/W reset */
+   regmap_write(priv->regmap, 0x120, 0x41);
+
+   /* Get master clock */
+   err = clk_get_by_name(dev, "mclk", >mclk);
+   if (err)
+   return err;
+
+   return 0;


You can use 'return clk_get_by_name(...)' here directly instead of the


Will do.

Ralph


Re: [PATCH v4 03/10] clk: renesas: add R906G032 driver

2023-04-17 Thread Marek Vasut

On 3/8/23 21:26, Ralph Siemsen wrote:

Clock driver for the Renesas RZ/N1 SoC family. This is based on
Linux kernel 6.2.y drivers/clk/renesas/r9a06g032-clocks.c as found in
commit 02693e11611e ("clk: renesas: r9a06g032: Repair grave increment error"),
with the following additional patch series applied:
https://lore.kernel.org/linux-renesas-soc/20230301215520.828455-1-ralph.siem...@linaro.org/

Notable difference: this version avoids allocating a 'struct clk'
for each clock source, as this is problematic before relocation.
Instead, it uses the same approach as existing Renesas RCAR2/3


R-Car , not RCAR .

[...]


+static int r9a06g032_clk_probe(struct udevice *dev)
+{
+   struct r9a06g032_priv *priv = dev_get_priv(dev);
+   int err;
+
+   priv->regmap = syscon_regmap_lookup_by_phandle(dev, "regmap");
+   if (IS_ERR(priv->regmap)) {
+   dev_dbg(dev, "unable to find regmap\n");
+   return PTR_ERR(priv->regmap);
+   }
+
+   /* Enable S/W reset */
+   regmap_write(priv->regmap, 0x120, 0x41);
+
+   /* Get master clock */
+   err = clk_get_by_name(dev, "mclk", >mclk);
+   if (err)
+   return err;
+
+   return 0;


You can use 'return clk_get_by_name(...)' here directly instead of the
'
err = ...
if (err)
 return err;
return 0;
'


[PATCH v4 03/10] clk: renesas: add R906G032 driver

2023-03-08 Thread Ralph Siemsen
Clock driver for the Renesas RZ/N1 SoC family. This is based on
Linux kernel 6.2.y drivers/clk/renesas/r9a06g032-clocks.c as found in
commit 02693e11611e ("clk: renesas: r9a06g032: Repair grave increment error"),
with the following additional patch series applied:
https://lore.kernel.org/linux-renesas-soc/20230301215520.828455-1-ralph.siem...@linaro.org/

Notable difference: this version avoids allocating a 'struct clk'
for each clock source, as this is problematic before relocation.
Instead, it uses the same approach as existing Renesas RCAR2/3
clock drivers, using a temporary structure filled on-the-fly.

Signed-off-by: Ralph Siemsen 
---

Changes in v4:
- commit message now includes hash of Linux upon which this is based
  as well as the additional patches (clock table cleanups)
- sync changes from review on linux patches, including
  - move RB macro higher up and document it, matching Linux driver
  - use multiply/divide instead of shifts for computing reg address
  - improve comments for clock gate, descriptor structures

Changes in v3:
- convert data table to explicit reg/bit numbers
- drop the unused scon, mirack, mirstat fields
- added some kernel docs to structures
- use enum for type field of struct r9a06g032_clkdesc
- cleanup macros for one assignment per line
- add a macro for top-most clock ID value ~0
- use dev_dbg() instead of debug/print
- minor reformatting, declarations before code, etc
- !foo instead of foo == 0
- IS_ERR / PTR_ERR where appropriate
- implement div_table handling
- remove some #if 0 old test code

 drivers/clk/renesas/Kconfig|6 +
 drivers/clk/renesas/Makefile   |1 +
 drivers/clk/renesas/r9a06g032-clocks.c | 1096 
 3 files changed, 1103 insertions(+)
 create mode 100644 drivers/clk/renesas/r9a06g032-clocks.c

diff --git a/drivers/clk/renesas/Kconfig b/drivers/clk/renesas/Kconfig
index 6788415eed..bbc618f464 100644
--- a/drivers/clk/renesas/Kconfig
+++ b/drivers/clk/renesas/Kconfig
@@ -130,3 +130,9 @@ config CLK_R8A779A0
depends on CLK_RCAR_GEN3
help
  Enable this to support the clocks on Renesas R8A779A0 SoC.
+
+config CLK_R9A06G032
+   bool "Renesas R9A06G032 clock driver"
+   depends on CLK_RENESAS
+   help
+ Enable this to support the clocks on Renesas R9A06G032 SoC.
diff --git a/drivers/clk/renesas/Makefile b/drivers/clk/renesas/Makefile
index a0d8c10bdb..7f0ef28367 100644
--- a/drivers/clk/renesas/Makefile
+++ b/drivers/clk/renesas/Makefile
@@ -19,3 +19,4 @@ obj-$(CONFIG_CLK_R8A77980) += r8a77980-cpg-mssr.o
 obj-$(CONFIG_CLK_R8A77990) += r8a77990-cpg-mssr.o
 obj-$(CONFIG_CLK_R8A77995) += r8a77995-cpg-mssr.o
 obj-$(CONFIG_CLK_R8A779A0) += r8a779a0-cpg-mssr.o
+obj-$(CONFIG_CLK_R9A06G032) += r9a06g032-clocks.o
diff --git a/drivers/clk/renesas/r9a06g032-clocks.c 
b/drivers/clk/renesas/r9a06g032-clocks.c
new file mode 100644
index 00..a2adefc9bb
--- /dev/null
+++ b/drivers/clk/renesas/r9a06g032-clocks.c
@@ -0,0 +1,1096 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * R9A06G032 clock driver
+ *
+ * Copyright (C) 2018 Renesas Electronics Europe Limited
+ *
+ * Michel Pollet , 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+
+/**
+ * struct regbit - describe one bit in a register
+ * @reg: offset of register relative to base address,
+ *  expressed in units of 32-bit words (not bytes),
+ * @bit: which bit (0 to 31) in the register
+ *
+ * This structure is used to compactly encode the location
+ * of a single bit in a register. Five bits are needed to
+ * encode the bit number. With uint16_t data type, this
+ * leaves 11 bits to encode a register offset up to 2047.
+ *
+ * Since registers are aligned on 32-bit boundaries, the
+ * offset will be specified in 32-bit words rather than bytes.
+ * This allows encoding an offset up to 0x1FFC (8188) bytes.
+ *
+ * Helper macro RB() takes care of converting the register
+ * offset from bytes to 32-bit words.
+ */
+struct regbit {
+   u16 reg:11;
+   u16 bit:5;
+};
+
+#define RB(_reg, _bit) ((struct regbit) { \
+   .reg = (_reg) / 4, \
+   .bit = (_bit) \
+})
+
+/**
+ * struct r9a06g032_gate - clock-related control bits
+ * @gate:   clock enable/disable
+ * @reset:  clock module reset (active low)
+ * @ready:  enables NoC forwarding of read/write requests to device,
+ *  (eg. device is ready to handle read/write requests)
+ * @midle:  request to idle the NoC interconnect
+ *
+ * Each of these fields describes a single bit in a register,
+ * which controls some aspect of clock gating. The @gate field
+ * is mandatory, this one enables/disables the clock. The
+ * other fields are optional, with zero indicating "not used".
+ *
+ * In most cases there is a @reset bit which needs to be
+ * de-asserted to bring the module out of reset.
+ *
+ * Modules may also need to signal when the are @ready to
+ * handle requests