RE: [PATCH v6 2/8] clk: clock-wizard: Add the clockwizard to clk directory

2020-11-03 Thread Shubhrajyoti Datta
Hi Stephen,

Thanks for the review.

> -Original Message-
> From: Stephen Boyd 
> Sent: Tuesday, September 22, 2020 2:52 AM
> To: Shubhrajyoti Datta ; linux-...@vger.kernel.org
> Cc: devicet...@vger.kernel.org; linux-kernel@vger.kernel.org;
> de...@driverdev.osuosl.org; robh...@kernel.org;
> gre...@linuxfoundation.org; mturque...@baylibre.com; Shubhrajyoti
> Datta 
> Subject: Re: [PATCH v6 2/8] clk: clock-wizard: Add the clockwizard to clk
> directory
> 
> Quoting Stephen Boyd (2020-09-21 14:19:59)
> > Quoting Shubhrajyoti Datta (2020-08-28 06:39:50)
> > > Add clocking wizard driver to clk.
> > >
> > > Signed-off-by: Shubhrajyoti Datta 
> > > ---
> >
> > Can this be combined with patch #6?
> 
> Sorry, I meant patch #8.
Did not get the comment.
Do you want to split the makefile and the driver parts of the patch.
Or the whole of the patch to be merged.

Or do you want the staging patch merged with  here?

[PATCH v6 8/8] staging: clocking-wizard: Delete the driver from the staging




Re: [PATCH v6 2/8] clk: clock-wizard: Add the clockwizard to clk directory

2020-09-21 Thread Stephen Boyd
Quoting Stephen Boyd (2020-09-21 14:19:59)
> Quoting Shubhrajyoti Datta (2020-08-28 06:39:50)
> > Add clocking wizard driver to clk.
> > 
> > Signed-off-by: Shubhrajyoti Datta 
> > ---
> 
> Can this be combined with patch #6?

Sorry, I meant patch #8.


Re: [PATCH v6 2/8] clk: clock-wizard: Add the clockwizard to clk directory

2020-09-21 Thread Stephen Boyd
Quoting Shubhrajyoti Datta (2020-08-28 06:39:50)
> Add clocking wizard driver to clk.
> 
> Signed-off-by: Shubhrajyoti Datta 
> ---

Can this be combined with patch #6? And then use git format-patch -C -M
when generating patches? I'm trying to see if anything changed from the
file in the staging tree or if this is just a copy from staging to clk
directory. Would also be useful if that was stated in the commit text.


[PATCH v6 2/8] clk: clock-wizard: Add the clockwizard to clk directory

2020-08-28 Thread Shubhrajyoti Datta
Add clocking wizard driver to clk.

Signed-off-by: Shubhrajyoti Datta 
---
 drivers/clk/Kconfig |   9 +
 drivers/clk/Makefile|   1 +
 drivers/clk/clk-xlnx-clock-wizard.c | 338 
 3 files changed, 348 insertions(+)
 create mode 100644 drivers/clk/clk-xlnx-clock-wizard.c

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 4026fac..a0e29dd 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -359,6 +359,15 @@ config COMMON_CLK_FIXED_MMIO
help
  Support for Memory Mapped IO Fixed clocks
 
+config COMMON_CLK_XLNX_CLKWZRD
+   tristate "Xilinx Clocking Wizard"
+   depends on COMMON_CLK && OF
+   help
+ Support for the Xilinx Clocking Wizard IP core clock generator.
+ Adds support for clocking wizard and compatible.
+ This driver supports the Xilinx clocking wizard programmable clock
+ synthesizer. The number of output is configurable in the design.
+
 source "drivers/clk/actions/Kconfig"
 source "drivers/clk/analogbits/Kconfig"
 source "drivers/clk/baikal-t1/Kconfig"
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index da8fcf1..1ad6414 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_ARCH_VT8500) += clk-vt8500.o
 obj-$(CONFIG_COMMON_CLK_VC5)   += clk-versaclock5.o
 obj-$(CONFIG_COMMON_CLK_WM831X)+= clk-wm831x.o
 obj-$(CONFIG_COMMON_CLK_XGENE) += clk-xgene.o
+obj-$(CONFIG_COMMON_CLK_XLNX_CLKWZRD)  += clk-xlnx-clock-wizard.o
 
 # please keep this section sorted lexicographically by directory path name
 obj-y  += actions/
diff --git a/drivers/clk/clk-xlnx-clock-wizard.c 
b/drivers/clk/clk-xlnx-clock-wizard.c
new file mode 100644
index 000..b31524a
--- /dev/null
+++ b/drivers/clk/clk-xlnx-clock-wizard.c
@@ -0,0 +1,338 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Xilinx 'Clocking Wizard' driver
+ *
+ *  Copyright (C) 2013 - 2020 Xilinx
+ *
+ *  Sören Brinkmann 
+ *  Shubhrajyoti Datta 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define WZRD_NUM_OUTPUTS   7
+#define WZRD_ACLK_MAX_FREQ 25000UL
+
+#define WZRD_CLK_CFG_REG(n)(0x200 + 4 * (n))
+
+#define WZRD_CLKOUT0_FRAC_EN   BIT(18)
+#define WZRD_CLKFBOUT_FRAC_EN  BIT(26)
+
+#define WZRD_CLKFBOUT_MULT_SHIFT   8
+#define WZRD_CLKFBOUT_MULT_MASK(0xff << 
WZRD_CLKFBOUT_MULT_SHIFT)
+#define WZRD_DIVCLK_DIVIDE_SHIFT   0
+#define WZRD_DIVCLK_DIVIDE_MASK(0xff << 
WZRD_DIVCLK_DIVIDE_SHIFT)
+#define WZRD_CLKOUT_DIVIDE_SHIFT   0
+#define WZRD_CLKOUT_DIVIDE_MASK(0xff << 
WZRD_DIVCLK_DIVIDE_SHIFT)
+
+enum clk_wzrd_int_clks {
+   wzrd_clk_mul,
+   wzrd_clk_mul_div,
+   wzrd_clk_int_max
+};
+
+/**
+ * struct clk_wzrd:
+ * @clk_data:  Clock data
+ * @nb:Notifier block
+ * @base:  Memory base
+ * @clk_in1:   Handle to input clock 'clk_in1'
+ * @axi_clk:   Handle to input clock 's_axi_aclk'
+ * @clks_internal: Internal clocks
+ * @clkout:Output clocks
+ * @speed_grade:   Speed grade of the device
+ * @suspended: Flag indicating power state of the device
+ */
+struct clk_wzrd {
+   struct clk_onecell_data clk_data;
+   struct notifier_block nb;
+   void __iomem *base;
+   struct clk *clk_in1;
+   struct clk *axi_clk;
+   struct clk *clks_internal[wzrd_clk_int_max];
+   struct clk *clkout[WZRD_NUM_OUTPUTS];
+   unsigned int speed_grade;
+   bool suspended;
+};
+
+#define to_clk_wzrd(_nb) container_of(_nb, struct clk_wzrd, nb)
+
+/* maximum frequencies for input/output clocks per speed grade */
+static const unsigned long clk_wzrd_max_freq[] = {
+   8UL,
+   93300UL,
+   106600UL
+};
+
+static int clk_wzrd_clk_notifier(struct notifier_block *nb, unsigned long 
event,
+void *data)
+{
+   unsigned long max;
+   struct clk_notifier_data *ndata = data;
+   struct clk_wzrd *clk_wzrd = to_clk_wzrd(nb);
+
+   if (clk_wzrd->suspended)
+   return NOTIFY_OK;
+
+   if (ndata->clk == clk_wzrd->clk_in1)
+   max = clk_wzrd_max_freq[clk_wzrd->speed_grade - 1];
+   else if (ndata->clk == clk_wzrd->axi_clk)
+   max = WZRD_ACLK_MAX_FREQ;
+   else
+   return NOTIFY_DONE; /* should never happen */
+
+   switch (event) {
+   case PRE_RATE_CHANGE:
+   if (ndata->new_rate > max)
+   return NOTIFY_BAD;
+   return NOTIFY_OK;
+   case POST_RATE_CHANGE:
+   case ABORT_RATE_CHANGE:
+   default:
+   return NOTIFY_DONE;
+   }
+}
+
+static int __maybe_unused clk_wzrd_suspend(struct device *dev)
+{
+   struct clk_wzrd *clk_wzrd = dev_get_drvdata(dev);
+
+