Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-23 Thread hl

Hi MyungJoo,

On 23/11/15 16:09, MyungJoo Ham wrote:

+static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
+  unsigned long parent_rate)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   /*
+* Get parent rate since it changed in this clks set_rate op. The parent
+* rate passed into this function is cached before set_rate is called in
+* the common clk code, so we have to get it here.
+*/
+   parent_rate = clk_get_rate(clk_get_parent(hw->clk));
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+   val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
+
+   return parent_rate / (val + 1);
+}
+
+/*
+ * TODO: set ddr frequcney in dcf which run in ATF
+ */
+static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+   return 0;
+}

Is it correct that you didn't fill this up because your
Trustzone driver (SMC) is not ready yet?

Yep, the SMC is not ready yet.


Then, why don't you fill that function assuming that TrustZone is not activated
and add SMC call functions with if or #if after its TrustZone driver is ready?

Or does your SoC mandate the usage ot TrustZone, restricting the usage
of CRU_CLKSEL6_CON write? (I don't see why SoC vendors will do this..)


I'll be ready to merge the RK3399 devfreq driver if you
fill this up (assuming that TZ is not enabled) or
add TZ driver and SMC calls.
Thank you for your reply,  it is good idea use if or #if to 
distinguish the TrustZone whether ready,
i will handle it in next version. I may follow Heiko advice to do 
some modify in dmc clock and rk3399 devfreq driver,

I will upload new version when it's ready.


Cheers,
MyungJoo
ps. according to rk339_dmcclk_recalc_rate(), filling rk339_dmcclk_set_rate
assuming that TZ is not enabled seems trivial.


--
Lin Huang


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-23 Thread hl

Hi Heiko,

On 22/11/15 02:30, Heiko Stuebner wrote:

Hi Lin,

Am Freitag, 20. November 2015, 09:37:15 schrieb hl:

On 20/11/15 05:47, Heiko Stuebner wrote:

Hi Lin,

Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:

support rk3399 dmc clock driver. Note, ddr set rate function will
use dcf controller which run in ATF, it need to fishish it when rk3399
arm trust firmware ready.

this unfinalized state is slightly unfortunate and I think this code will
need to wait until CRU and DDRC specs are available.

Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
so shouldn't be a separate driver at all and also what your driver currently
only does can still simply be described in the regular scheme as part of
a full clock driver like

PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
3,
DFLAGS | CLK_DIVIDER_POWER_OF_TWO),

So the code needs to actually demonstrate why a separate clock type is
really necessary.

I do understand that we will probably need a special way to talk to this
dcf controller but seeing how this interaction will work is really a
prequisite to finding a correct solution.

  if we can use common clock driver, i can put the dfi controller as
a  independent driver
  into devfreq,  this is the best way. But how do we separate the ddr
clk_set_rate() ,
  so we can manipulate dcf controller(actually, we use SMC handle dcf
controller in arm trust firmware ),
  i check clock driver code, it seem there is not way to do that for now.

the core problem I have right now is, that I don't understand how the
interaction with the dfi controller works at all :-) .

One thing that might work, is that your dfi-driver takes the ddrc-clock
from the clock controller and then registers a clock notifier to get
notified before and after the clock-rate changes. But that depends as
stated above on how the dfi-controller needs to be handled.

For example the current armclk-handling uses a clock notifier around the
actual rate change ... so you could use that as inspiration.
Thank you for your inspiration. I think i can handle ddrc clk like 
the armclk.
About the dfi, it will monitor ddr utilization, according this 
result to do
ddr frequency scaling. I think i can implement a dfi drvier, and 
register it to devfreq,
then call the dmc_set_rate fucntion in the dfi drvier, meanwhile i 
will implement a ddrc clk driver
like the armclk, implement set rate funciton, and call the 
dcf(implement in ATF) in this function.



Heiko






--
Lin Huang


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-23 Thread MyungJoo Ham
> +static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
> +unsigned long parent_rate)
> +{
> + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
> + u32 val;
> +
> + /*
> +  * Get parent rate since it changed in this clks set_rate op. The parent
> +  * rate passed into this function is cached before set_rate is called in
> +  * the common clk code, so we have to get it here.
> +  */
> + parent_rate = clk_get_rate(clk_get_parent(hw->clk));
> +
> + val = readl(dmc->cru + CRU_CLKSEL6_CON);
> + val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
> +
> + return parent_rate / (val + 1);
> +}
> +
> +/*
> + * TODO: set ddr frequcney in dcf which run in ATF
> + */
> +static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
> +   unsigned long parent_rate)
> +{
> + return 0;
> +}

Is it correct that you didn't fill this up because your
Trustzone driver (SMC) is not ready yet?

Then, why don't you fill that function assuming that TrustZone is not activated
and add SMC call functions with if or #if after its TrustZone driver is ready?

Or does your SoC mandate the usage ot TrustZone, restricting the usage
of CRU_CLKSEL6_CON write? (I don't see why SoC vendors will do this..)


I'll be ready to merge the RK3399 devfreq driver if you
fill this up (assuming that TZ is not enabled) or
add TZ driver and SMC calls.


Cheers,
MyungJoo
ps. according to rk339_dmcclk_recalc_rate(), filling rk339_dmcclk_set_rate
assuming that TZ is not enabled seems trivial.

Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-23 Thread MyungJoo Ham
> +static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
> +unsigned long parent_rate)
> +{
> + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
> + u32 val;
> +
> + /*
> +  * Get parent rate since it changed in this clks set_rate op. The parent
> +  * rate passed into this function is cached before set_rate is called in
> +  * the common clk code, so we have to get it here.
> +  */
> + parent_rate = clk_get_rate(clk_get_parent(hw->clk));
> +
> + val = readl(dmc->cru + CRU_CLKSEL6_CON);
> + val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
> +
> + return parent_rate / (val + 1);
> +}
> +
> +/*
> + * TODO: set ddr frequcney in dcf which run in ATF
> + */
> +static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
> +   unsigned long parent_rate)
> +{
> + return 0;
> +}

Is it correct that you didn't fill this up because your
Trustzone driver (SMC) is not ready yet?

Then, why don't you fill that function assuming that TrustZone is not activated
and add SMC call functions with if or #if after its TrustZone driver is ready?

Or does your SoC mandate the usage ot TrustZone, restricting the usage
of CRU_CLKSEL6_CON write? (I don't see why SoC vendors will do this..)


I'll be ready to merge the RK3399 devfreq driver if you
fill this up (assuming that TZ is not enabled) or
add TZ driver and SMC calls.


Cheers,
MyungJoo
ps. according to rk339_dmcclk_recalc_rate(), filling rk339_dmcclk_set_rate
assuming that TZ is not enabled seems trivial.

Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-23 Thread hl

Hi Heiko,

On 22/11/15 02:30, Heiko Stuebner wrote:

Hi Lin,

Am Freitag, 20. November 2015, 09:37:15 schrieb hl:

On 20/11/15 05:47, Heiko Stuebner wrote:

Hi Lin,

Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:

support rk3399 dmc clock driver. Note, ddr set rate function will
use dcf controller which run in ATF, it need to fishish it when rk3399
arm trust firmware ready.

this unfinalized state is slightly unfortunate and I think this code will
need to wait until CRU and DDRC specs are available.

Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
so shouldn't be a separate driver at all and also what your driver currently
only does can still simply be described in the regular scheme as part of
a full clock driver like

PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
3,
DFLAGS | CLK_DIVIDER_POWER_OF_TWO),

So the code needs to actually demonstrate why a separate clock type is
really necessary.

I do understand that we will probably need a special way to talk to this
dcf controller but seeing how this interaction will work is really a
prequisite to finding a correct solution.

  if we can use common clock driver, i can put the dfi controller as
a  independent driver
  into devfreq,  this is the best way. But how do we separate the ddr
clk_set_rate() ,
  so we can manipulate dcf controller(actually, we use SMC handle dcf
controller in arm trust firmware ),
  i check clock driver code, it seem there is not way to do that for now.

the core problem I have right now is, that I don't understand how the
interaction with the dfi controller works at all :-) .

One thing that might work, is that your dfi-driver takes the ddrc-clock
from the clock controller and then registers a clock notifier to get
notified before and after the clock-rate changes. But that depends as
stated above on how the dfi-controller needs to be handled.

For example the current armclk-handling uses a clock notifier around the
actual rate change ... so you could use that as inspiration.
Thank you for your inspiration. I think i can handle ddrc clk like 
the armclk.
About the dfi, it will monitor ddr utilization, according this 
result to do
ddr frequency scaling. I think i can implement a dfi drvier, and 
register it to devfreq,
then call the dmc_set_rate fucntion in the dfi drvier, meanwhile i 
will implement a ddrc clk driver
like the armclk, implement set rate funciton, and call the 
dcf(implement in ATF) in this function.



Heiko






--
Lin Huang


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-23 Thread hl

Hi MyungJoo,

On 23/11/15 16:09, MyungJoo Ham wrote:

+static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
+  unsigned long parent_rate)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   /*
+* Get parent rate since it changed in this clks set_rate op. The parent
+* rate passed into this function is cached before set_rate is called in
+* the common clk code, so we have to get it here.
+*/
+   parent_rate = clk_get_rate(clk_get_parent(hw->clk));
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+   val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
+
+   return parent_rate / (val + 1);
+}
+
+/*
+ * TODO: set ddr frequcney in dcf which run in ATF
+ */
+static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+   return 0;
+}

Is it correct that you didn't fill this up because your
Trustzone driver (SMC) is not ready yet?

Yep, the SMC is not ready yet.


Then, why don't you fill that function assuming that TrustZone is not activated
and add SMC call functions with if or #if after its TrustZone driver is ready?

Or does your SoC mandate the usage ot TrustZone, restricting the usage
of CRU_CLKSEL6_CON write? (I don't see why SoC vendors will do this..)


I'll be ready to merge the RK3399 devfreq driver if you
fill this up (assuming that TZ is not enabled) or
add TZ driver and SMC calls.
Thank you for your reply,  it is good idea use if or #if to 
distinguish the TrustZone whether ready,
i will handle it in next version. I may follow Heiko advice to do 
some modify in dmc clock and rk3399 devfreq driver,

I will upload new version when it's ready.


Cheers,
MyungJoo
ps. according to rk339_dmcclk_recalc_rate(), filling rk339_dmcclk_set_rate
assuming that TZ is not enabled seems trivial.


--
Lin Huang


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-21 Thread Heiko Stuebner
Hi Lin,

Am Freitag, 20. November 2015, 09:37:15 schrieb hl:
> On 20/11/15 05:47, Heiko Stuebner wrote:
> > Hi Lin,
> >
> > Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:
> >> support rk3399 dmc clock driver. Note, ddr set rate function will
> >> use dcf controller which run in ATF, it need to fishish it when rk3399
> >> arm trust firmware ready.
> > this unfinalized state is slightly unfortunate and I think this code will
> > need to wait until CRU and DDRC specs are available.
> >
> > Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
> > so shouldn't be a separate driver at all and also what your driver currently
> > only does can still simply be described in the regular scheme as part of
> > a full clock driver like
> >
> > PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
> > COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
> > RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
> > 3,
> > DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
> >
> > So the code needs to actually demonstrate why a separate clock type is
> > really necessary.
> >
> > I do understand that we will probably need a special way to talk to this
> > dcf controller but seeing how this interaction will work is really a
> > prequisite to finding a correct solution.
>
>  if we can use common clock driver, i can put the dfi controller as 
> a  independent driver
>  into devfreq,  this is the best way. But how do we separate the ddr 
> clk_set_rate() ,
>  so we can manipulate dcf controller(actually, we use SMC handle dcf 
> controller in arm trust firmware ),
>  i check clock driver code, it seem there is not way to do that for now.

the core problem I have right now is, that I don't understand how the
interaction with the dfi controller works at all :-) .

One thing that might work, is that your dfi-driver takes the ddrc-clock
from the clock controller and then registers a clock notifier to get
notified before and after the clock-rate changes. But that depends as
stated above on how the dfi-controller needs to be handled.

For example the current armclk-handling uses a clock notifier around the
actual rate change ... so you could use that as inspiration.


Heiko

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-21 Thread Heiko Stuebner
Hi Lin,

Am Freitag, 20. November 2015, 09:37:15 schrieb hl:
> On 20/11/15 05:47, Heiko Stuebner wrote:
> > Hi Lin,
> >
> > Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:
> >> support rk3399 dmc clock driver. Note, ddr set rate function will
> >> use dcf controller which run in ATF, it need to fishish it when rk3399
> >> arm trust firmware ready.
> > this unfinalized state is slightly unfortunate and I think this code will
> > need to wait until CRU and DDRC specs are available.
> >
> > Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
> > so shouldn't be a separate driver at all and also what your driver currently
> > only does can still simply be described in the regular scheme as part of
> > a full clock driver like
> >
> > PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
> > COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
> > RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
> > 3,
> > DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
> >
> > So the code needs to actually demonstrate why a separate clock type is
> > really necessary.
> >
> > I do understand that we will probably need a special way to talk to this
> > dcf controller but seeing how this interaction will work is really a
> > prequisite to finding a correct solution.
>
>  if we can use common clock driver, i can put the dfi controller as 
> a  independent driver
>  into devfreq,  this is the best way. But how do we separate the ddr 
> clk_set_rate() ,
>  so we can manipulate dcf controller(actually, we use SMC handle dcf 
> controller in arm trust firmware ),
>  i check clock driver code, it seem there is not way to do that for now.

the core problem I have right now is, that I don't understand how the
interaction with the dfi controller works at all :-) .

One thing that might work, is that your dfi-driver takes the ddrc-clock
from the clock controller and then registers a clock notifier to get
notified before and after the clock-rate changes. But that depends as
stated above on how the dfi-controller needs to be handled.

For example the current armclk-handling uses a clock notifier around the
actual rate change ... so you could use that as inspiration.


Heiko

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-19 Thread hl

Hi Heiko,

On 20/11/15 05:47, Heiko Stuebner wrote:

Hi Lin,

Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:

support rk3399 dmc clock driver. Note, ddr set rate function will
use dcf controller which run in ATF, it need to fishish it when rk3399
arm trust firmware ready.

this unfinalized state is slightly unfortunate and I think this code will
need to wait until CRU and DDRC specs are available.

Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
so shouldn't be a separate driver at all and also what your driver currently
only does can still simply be described in the regular scheme as part of
a full clock driver like

PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
3,
DFLAGS | CLK_DIVIDER_POWER_OF_TWO),

So the code needs to actually demonstrate why a separate clock type is
really necessary.

I do understand that we will probably need a special way to talk to this
dcf controller but seeing how this interaction will work is really a
prequisite to finding a correct solution.
if we can use common clock driver, i can put the dfi controller as 
a  independent driver
into devfreq,  this is the best way. But how do we separate the ddr 
clk_set_rate() ,
so we can manipulate dcf controller(actually, we use SMC handle dcf 
controller in arm trust firmware ),

i check clock driver code, it seem there is not way to do that for now.


Heiko


---
  drivers/clk/rockchip/Makefile |   1 +
  drivers/clk/rockchip/clk-rk3399-dmc.c | 196 ++
  include/soc/rockchip/rk3399-dmc-clk.h |  36 +++
  3 files changed, 233 insertions(+)
  create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c
  create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h

diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
index b27edd6..98bd955 100644
--- a/drivers/clk/rockchip/Makefile
+++ b/drivers/clk/rockchip/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER)+= softrst.o
  obj-y += clk-rk3188.o
  obj-y += clk-rk3288.o
  obj-y += clk-rk3368.o
+obj-y  += clk-rk3399-dmc.o
diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c 
b/drivers/clk/rockchip/clk-rk3399-dmc.c
new file mode 100644
index 000..03cc044
--- /dev/null
+++ b/drivers/clk/rockchip/clk-rk3399-dmc.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define to_rk3399_dmcclk(obj)  container_of(obj, struct rk3399_dmcclk, hw)
+
+/* CRU_CLKSEL6_CON*/
+#define CRU_CLKSEL6_CON0x118
+#define CLK_DDRC_PLL_SEL_SHIFT 0x4
+#define CLK_DDRC_PLL_SEL_MASK  0x3
+#define CLK_DDRC_DIV_CON_SHIFT 0
+#define CLK_DDRC_DIV_CON_MASK  0x07
+
+static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
+  unsigned long parent_rate)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   /*
+* Get parent rate since it changed in this clks set_rate op. The parent
+* rate passed into this function is cached before set_rate is called in
+* the common clk code, so we have to get it here.
+*/
+   parent_rate = clk_get_rate(clk_get_parent(hw->clk));
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+   val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
+
+   return parent_rate / (val + 1);
+}
+
+/*
+ * TODO: set ddr frequcney in dcf which run in ATF
+ */
+static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+   return 0;
+}
+
+static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+
+   return (val >> CLK_DDRC_PLL_SEL_SHIFT) &
+   CLK_DDRC_PLL_SEL_MASK;
+}
+
+static const struct clk_ops rk3399_dmcclk_ops = {
+   .recalc_rate = rk3399_dmcclk_recalc_rate,
+   .set_rate = rk3399_dmcclk_set_rate,
+   .get_parent = rk3399_dmcclk_get_parent,
+};
+
+static const char *parent_clk_names[] = {
+   "pll_dpll",
+   "pll_gpll",
+   "pll_alpll",
+   "pll_abpll",
+};
+
+static int 

Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-19 Thread Heiko Stuebner
Hi Lin,

Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:
> support rk3399 dmc clock driver. Note, ddr set rate function will
> use dcf controller which run in ATF, it need to fishish it when rk3399
> arm trust firmware ready.

this unfinalized state is slightly unfortunate and I think this code will
need to wait until CRU and DDRC specs are available.

Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
so shouldn't be a separate driver at all and also what your driver currently
only does can still simply be described in the regular scheme as part of
a full clock driver like

PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
3,
DFLAGS | CLK_DIVIDER_POWER_OF_TWO),

So the code needs to actually demonstrate why a separate clock type is
really necessary.

I do understand that we will probably need a special way to talk to this
dcf controller but seeing how this interaction will work is really a
prequisite to finding a correct solution.


Heiko

> ---
>  drivers/clk/rockchip/Makefile |   1 +
>  drivers/clk/rockchip/clk-rk3399-dmc.c | 196 
> ++
>  include/soc/rockchip/rk3399-dmc-clk.h |  36 +++
>  3 files changed, 233 insertions(+)
>  create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c
>  create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h
> 
> diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
> index b27edd6..98bd955 100644
> --- a/drivers/clk/rockchip/Makefile
> +++ b/drivers/clk/rockchip/Makefile
> @@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER)  += softrst.o
>  obj-y+= clk-rk3188.o
>  obj-y+= clk-rk3288.o
>  obj-y+= clk-rk3368.o
> +obj-y+= clk-rk3399-dmc.o
> diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c 
> b/drivers/clk/rockchip/clk-rk3399-dmc.c
> new file mode 100644
> index 000..03cc044
> --- /dev/null
> +++ b/drivers/clk/rockchip/clk-rk3399-dmc.c
> @@ -0,0 +1,196 @@
> +/*
> + * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define to_rk3399_dmcclk(obj)container_of(obj, struct rk3399_dmcclk, 
> hw)
> +
> +/* CRU_CLKSEL6_CON*/
> +#define CRU_CLKSEL6_CON  0x118
> +#define CLK_DDRC_PLL_SEL_SHIFT   0x4
> +#define CLK_DDRC_PLL_SEL_MASK0x3
> +#define CLK_DDRC_DIV_CON_SHIFT   0
> +#define CLK_DDRC_DIV_CON_MASK0x07
> +
> +static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
> +unsigned long parent_rate)
> +{
> + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
> + u32 val;
> +
> + /*
> +  * Get parent rate since it changed in this clks set_rate op. The parent
> +  * rate passed into this function is cached before set_rate is called in
> +  * the common clk code, so we have to get it here.
> +  */
> + parent_rate = clk_get_rate(clk_get_parent(hw->clk));
> +
> + val = readl(dmc->cru + CRU_CLKSEL6_CON);
> + val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
> +
> + return parent_rate / (val + 1);
> +}
> +
> +/*
> + * TODO: set ddr frequcney in dcf which run in ATF
> + */
> +static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
> +   unsigned long parent_rate)
> +{
> + return 0;
> +}
> +
> +static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw)
> +{
> + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
> + u32 val;
> +
> + val = readl(dmc->cru + CRU_CLKSEL6_CON);
> +
> + return (val >> CLK_DDRC_PLL_SEL_SHIFT) &
> + CLK_DDRC_PLL_SEL_MASK;
> +}
> +
> +static const struct clk_ops rk3399_dmcclk_ops = {
> + .recalc_rate = rk3399_dmcclk_recalc_rate,
> + .set_rate = rk3399_dmcclk_set_rate,
> + .get_parent = rk3399_dmcclk_get_parent,
> +};
> +
> +static const char *parent_clk_names[] = {
> + "pll_dpll",
> + "pll_gpll",
> + "pll_alpll",
> + "pll_abpll",
> +};
> +
> +static int rk3399_register_dmcclk(struct rk3399_dmcclk *dmc)
> +{
> + struct clk_init_data init;
> + struct clk *clk;
> +
> + init.name = "dmc_clk";
> + init.parent_names = parent_clk_names;
> + 

[PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-19 Thread Lin Huang
support rk3399 dmc clock driver. Note, ddr set rate function will
use dcf controller which run in ATF, it need to fishish it when rk3399
arm trust firmware ready.

Signed-off-by: Lin Huang 
---
 drivers/clk/rockchip/Makefile |   1 +
 drivers/clk/rockchip/clk-rk3399-dmc.c | 196 ++
 include/soc/rockchip/rk3399-dmc-clk.h |  36 +++
 3 files changed, 233 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c
 create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h

diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
index b27edd6..98bd955 100644
--- a/drivers/clk/rockchip/Makefile
+++ b/drivers/clk/rockchip/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER)+= softrst.o
 obj-y  += clk-rk3188.o
 obj-y  += clk-rk3288.o
 obj-y  += clk-rk3368.o
+obj-y  += clk-rk3399-dmc.o
diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c 
b/drivers/clk/rockchip/clk-rk3399-dmc.c
new file mode 100644
index 000..03cc044
--- /dev/null
+++ b/drivers/clk/rockchip/clk-rk3399-dmc.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define to_rk3399_dmcclk(obj)  container_of(obj, struct rk3399_dmcclk, hw)
+
+/* CRU_CLKSEL6_CON*/
+#define CRU_CLKSEL6_CON0x118
+#define CLK_DDRC_PLL_SEL_SHIFT 0x4
+#define CLK_DDRC_PLL_SEL_MASK  0x3
+#define CLK_DDRC_DIV_CON_SHIFT 0
+#define CLK_DDRC_DIV_CON_MASK  0x07
+
+static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
+  unsigned long parent_rate)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   /*
+* Get parent rate since it changed in this clks set_rate op. The parent
+* rate passed into this function is cached before set_rate is called in
+* the common clk code, so we have to get it here.
+*/
+   parent_rate = clk_get_rate(clk_get_parent(hw->clk));
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+   val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
+
+   return parent_rate / (val + 1);
+}
+
+/*
+ * TODO: set ddr frequcney in dcf which run in ATF
+ */
+static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+   return 0;
+}
+
+static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+
+   return (val >> CLK_DDRC_PLL_SEL_SHIFT) &
+   CLK_DDRC_PLL_SEL_MASK;
+}
+
+static const struct clk_ops rk3399_dmcclk_ops = {
+   .recalc_rate = rk3399_dmcclk_recalc_rate,
+   .set_rate = rk3399_dmcclk_set_rate,
+   .get_parent = rk3399_dmcclk_get_parent,
+};
+
+static const char *parent_clk_names[] = {
+   "pll_dpll",
+   "pll_gpll",
+   "pll_alpll",
+   "pll_abpll",
+};
+
+static int rk3399_register_dmcclk(struct rk3399_dmcclk *dmc)
+{
+   struct clk_init_data init;
+   struct clk *clk;
+
+   init.name = "dmc_clk";
+   init.parent_names = parent_clk_names;
+   init.num_parents = ARRAY_SIZE(parent_clk_names);
+   init.ops = _dmcclk_ops;
+   init.flags = 0;
+   dmc->hw->init = 
+
+   clk = devm_clk_register(dmc->dev, dmc->hw);
+   if (IS_ERR(clk)) {
+   dev_err(dmc->dev, "could not register cpuclk dmc_clk\n");
+   return PTR_ERR(clk);
+   }
+   clk_register_clkdev(clk, "dmc_clk", NULL);
+   of_clk_add_provider(dmc->dev->of_node, of_clk_src_simple_get, clk);
+
+   return 0;
+}
+
+static int rk3399_dmcclk_probe(struct platform_device *pdev)
+{
+   struct rk3399_dmcclk *dmc;
+   struct resource *res;
+   struct device_node *node;
+   int ret;
+
+   dmc = devm_kzalloc(>dev, sizeof(*dmc), GFP_KERNEL);
+   if (!dmc)
+   return -ENOMEM;
+
+   dmc->hw = devm_kzalloc(>dev, sizeof(*dmc->hw), GFP_KERNEL);
+   if (!dmc->hw)
+   return -ENOMEM;
+
+   dmc->dev = >dev;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   dmc->ctrl_regs = devm_ioremap_resource(>dev, res);
+   if (IS_ERR(dmc->ctrl_regs))
+   return PTR_ERR(dmc->ctrl_regs);
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+   dmc->dfi_regs = 

Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-19 Thread hl

Hi Heiko,

On 20/11/15 05:47, Heiko Stuebner wrote:

Hi Lin,

Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:

support rk3399 dmc clock driver. Note, ddr set rate function will
use dcf controller which run in ATF, it need to fishish it when rk3399
arm trust firmware ready.

this unfinalized state is slightly unfortunate and I think this code will
need to wait until CRU and DDRC specs are available.

Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
so shouldn't be a separate driver at all and also what your driver currently
only does can still simply be described in the regular scheme as part of
a full clock driver like

PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
3,
DFLAGS | CLK_DIVIDER_POWER_OF_TWO),

So the code needs to actually demonstrate why a separate clock type is
really necessary.

I do understand that we will probably need a special way to talk to this
dcf controller but seeing how this interaction will work is really a
prequisite to finding a correct solution.
if we can use common clock driver, i can put the dfi controller as 
a  independent driver
into devfreq,  this is the best way. But how do we separate the ddr 
clk_set_rate() ,
so we can manipulate dcf controller(actually, we use SMC handle dcf 
controller in arm trust firmware ),

i check clock driver code, it seem there is not way to do that for now.


Heiko


---
  drivers/clk/rockchip/Makefile |   1 +
  drivers/clk/rockchip/clk-rk3399-dmc.c | 196 ++
  include/soc/rockchip/rk3399-dmc-clk.h |  36 +++
  3 files changed, 233 insertions(+)
  create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c
  create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h

diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
index b27edd6..98bd955 100644
--- a/drivers/clk/rockchip/Makefile
+++ b/drivers/clk/rockchip/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER)+= softrst.o
  obj-y += clk-rk3188.o
  obj-y += clk-rk3288.o
  obj-y += clk-rk3368.o
+obj-y  += clk-rk3399-dmc.o
diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c 
b/drivers/clk/rockchip/clk-rk3399-dmc.c
new file mode 100644
index 000..03cc044
--- /dev/null
+++ b/drivers/clk/rockchip/clk-rk3399-dmc.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define to_rk3399_dmcclk(obj)  container_of(obj, struct rk3399_dmcclk, hw)
+
+/* CRU_CLKSEL6_CON*/
+#define CRU_CLKSEL6_CON0x118
+#define CLK_DDRC_PLL_SEL_SHIFT 0x4
+#define CLK_DDRC_PLL_SEL_MASK  0x3
+#define CLK_DDRC_DIV_CON_SHIFT 0
+#define CLK_DDRC_DIV_CON_MASK  0x07
+
+static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
+  unsigned long parent_rate)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   /*
+* Get parent rate since it changed in this clks set_rate op. The parent
+* rate passed into this function is cached before set_rate is called in
+* the common clk code, so we have to get it here.
+*/
+   parent_rate = clk_get_rate(clk_get_parent(hw->clk));
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+   val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
+
+   return parent_rate / (val + 1);
+}
+
+/*
+ * TODO: set ddr frequcney in dcf which run in ATF
+ */
+static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+   return 0;
+}
+
+static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+
+   return (val >> CLK_DDRC_PLL_SEL_SHIFT) &
+   CLK_DDRC_PLL_SEL_MASK;
+}
+
+static const struct clk_ops rk3399_dmcclk_ops = {
+   .recalc_rate = rk3399_dmcclk_recalc_rate,
+   .set_rate = rk3399_dmcclk_set_rate,
+   .get_parent = rk3399_dmcclk_get_parent,
+};
+
+static const char *parent_clk_names[] = {
+   "pll_dpll",
+   "pll_gpll",
+   "pll_alpll",
+   "pll_abpll",
+};
+
+static int 

Re: [PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-19 Thread Heiko Stuebner
Hi Lin,

Am Donnerstag, 19. November 2015, 18:21:10 schrieb Lin Huang:
> support rk3399 dmc clock driver. Note, ddr set rate function will
> use dcf controller which run in ATF, it need to fishish it when rk3399
> arm trust firmware ready.

this unfinalized state is slightly unfortunate and I think this code will
need to wait until CRU and DDRC specs are available.

Because this is clearly part of the CRU (labeled CRU_CLKSEL6_CON etc)
so shouldn't be a separate driver at all and also what your driver currently
only does can still simply be described in the regular scheme as part of
a full clock driver like

PNAME(mux_ddrc_p) = { "pll_dpll", "pll_gpll", "pll_alpll", "pll_abpll" };
COMPOSITE_NOGATE(0, "ddrc", mux_ddrc_p, 0,
RK3399_CLKSEL_CON(6), 4, 2, MFLAGS, 0, 
3,
DFLAGS | CLK_DIVIDER_POWER_OF_TWO),

So the code needs to actually demonstrate why a separate clock type is
really necessary.

I do understand that we will probably need a special way to talk to this
dcf controller but seeing how this interaction will work is really a
prequisite to finding a correct solution.


Heiko

> ---
>  drivers/clk/rockchip/Makefile |   1 +
>  drivers/clk/rockchip/clk-rk3399-dmc.c | 196 
> ++
>  include/soc/rockchip/rk3399-dmc-clk.h |  36 +++
>  3 files changed, 233 insertions(+)
>  create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c
>  create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h
> 
> diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
> index b27edd6..98bd955 100644
> --- a/drivers/clk/rockchip/Makefile
> +++ b/drivers/clk/rockchip/Makefile
> @@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER)  += softrst.o
>  obj-y+= clk-rk3188.o
>  obj-y+= clk-rk3288.o
>  obj-y+= clk-rk3368.o
> +obj-y+= clk-rk3399-dmc.o
> diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c 
> b/drivers/clk/rockchip/clk-rk3399-dmc.c
> new file mode 100644
> index 000..03cc044
> --- /dev/null
> +++ b/drivers/clk/rockchip/clk-rk3399-dmc.c
> @@ -0,0 +1,196 @@
> +/*
> + * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define to_rk3399_dmcclk(obj)container_of(obj, struct rk3399_dmcclk, 
> hw)
> +
> +/* CRU_CLKSEL6_CON*/
> +#define CRU_CLKSEL6_CON  0x118
> +#define CLK_DDRC_PLL_SEL_SHIFT   0x4
> +#define CLK_DDRC_PLL_SEL_MASK0x3
> +#define CLK_DDRC_DIV_CON_SHIFT   0
> +#define CLK_DDRC_DIV_CON_MASK0x07
> +
> +static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
> +unsigned long parent_rate)
> +{
> + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
> + u32 val;
> +
> + /*
> +  * Get parent rate since it changed in this clks set_rate op. The parent
> +  * rate passed into this function is cached before set_rate is called in
> +  * the common clk code, so we have to get it here.
> +  */
> + parent_rate = clk_get_rate(clk_get_parent(hw->clk));
> +
> + val = readl(dmc->cru + CRU_CLKSEL6_CON);
> + val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
> +
> + return parent_rate / (val + 1);
> +}
> +
> +/*
> + * TODO: set ddr frequcney in dcf which run in ATF
> + */
> +static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
> +   unsigned long parent_rate)
> +{
> + return 0;
> +}
> +
> +static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw)
> +{
> + struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
> + u32 val;
> +
> + val = readl(dmc->cru + CRU_CLKSEL6_CON);
> +
> + return (val >> CLK_DDRC_PLL_SEL_SHIFT) &
> + CLK_DDRC_PLL_SEL_MASK;
> +}
> +
> +static const struct clk_ops rk3399_dmcclk_ops = {
> + .recalc_rate = rk3399_dmcclk_recalc_rate,
> + .set_rate = rk3399_dmcclk_set_rate,
> + .get_parent = rk3399_dmcclk_get_parent,
> +};
> +
> +static const char *parent_clk_names[] = {
> + "pll_dpll",
> + "pll_gpll",
> + "pll_alpll",
> + "pll_abpll",
> +};
> +
> +static int rk3399_register_dmcclk(struct rk3399_dmcclk *dmc)
> +{
> + struct clk_init_data init;
> + struct clk *clk;
> +
> + init.name = "dmc_clk";
> + init.parent_names = parent_clk_names;
> + 

[PATCH 1/2] clk: rockchip: dmc: support rk3399 dmc clock driver

2015-11-19 Thread Lin Huang
support rk3399 dmc clock driver. Note, ddr set rate function will
use dcf controller which run in ATF, it need to fishish it when rk3399
arm trust firmware ready.

Signed-off-by: Lin Huang 
---
 drivers/clk/rockchip/Makefile |   1 +
 drivers/clk/rockchip/clk-rk3399-dmc.c | 196 ++
 include/soc/rockchip/rk3399-dmc-clk.h |  36 +++
 3 files changed, 233 insertions(+)
 create mode 100644 drivers/clk/rockchip/clk-rk3399-dmc.c
 create mode 100644 include/soc/rockchip/rk3399-dmc-clk.h

diff --git a/drivers/clk/rockchip/Makefile b/drivers/clk/rockchip/Makefile
index b27edd6..98bd955 100644
--- a/drivers/clk/rockchip/Makefile
+++ b/drivers/clk/rockchip/Makefile
@@ -13,3 +13,4 @@ obj-$(CONFIG_RESET_CONTROLLER)+= softrst.o
 obj-y  += clk-rk3188.o
 obj-y  += clk-rk3288.o
 obj-y  += clk-rk3368.o
+obj-y  += clk-rk3399-dmc.o
diff --git a/drivers/clk/rockchip/clk-rk3399-dmc.c 
b/drivers/clk/rockchip/clk-rk3399-dmc.c
new file mode 100644
index 000..03cc044
--- /dev/null
+++ b/drivers/clk/rockchip/clk-rk3399-dmc.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define to_rk3399_dmcclk(obj)  container_of(obj, struct rk3399_dmcclk, hw)
+
+/* CRU_CLKSEL6_CON*/
+#define CRU_CLKSEL6_CON0x118
+#define CLK_DDRC_PLL_SEL_SHIFT 0x4
+#define CLK_DDRC_PLL_SEL_MASK  0x3
+#define CLK_DDRC_DIV_CON_SHIFT 0
+#define CLK_DDRC_DIV_CON_MASK  0x07
+
+static unsigned long rk3399_dmcclk_recalc_rate(struct clk_hw *hw,
+  unsigned long parent_rate)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   /*
+* Get parent rate since it changed in this clks set_rate op. The parent
+* rate passed into this function is cached before set_rate is called in
+* the common clk code, so we have to get it here.
+*/
+   parent_rate = clk_get_rate(clk_get_parent(hw->clk));
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+   val = (val >> CLK_DDRC_DIV_CON_SHIFT) & CLK_DDRC_DIV_CON_MASK;
+
+   return parent_rate / (val + 1);
+}
+
+/*
+ * TODO: set ddr frequcney in dcf which run in ATF
+ */
+static int rk3399_dmcclk_set_rate(struct clk_hw *hw, unsigned long rate,
+ unsigned long parent_rate)
+{
+   return 0;
+}
+
+static u8 rk3399_dmcclk_get_parent(struct clk_hw *hw)
+{
+   struct rk3399_dmcclk *dmc = to_rk3399_dmcclk();
+   u32 val;
+
+   val = readl(dmc->cru + CRU_CLKSEL6_CON);
+
+   return (val >> CLK_DDRC_PLL_SEL_SHIFT) &
+   CLK_DDRC_PLL_SEL_MASK;
+}
+
+static const struct clk_ops rk3399_dmcclk_ops = {
+   .recalc_rate = rk3399_dmcclk_recalc_rate,
+   .set_rate = rk3399_dmcclk_set_rate,
+   .get_parent = rk3399_dmcclk_get_parent,
+};
+
+static const char *parent_clk_names[] = {
+   "pll_dpll",
+   "pll_gpll",
+   "pll_alpll",
+   "pll_abpll",
+};
+
+static int rk3399_register_dmcclk(struct rk3399_dmcclk *dmc)
+{
+   struct clk_init_data init;
+   struct clk *clk;
+
+   init.name = "dmc_clk";
+   init.parent_names = parent_clk_names;
+   init.num_parents = ARRAY_SIZE(parent_clk_names);
+   init.ops = _dmcclk_ops;
+   init.flags = 0;
+   dmc->hw->init = 
+
+   clk = devm_clk_register(dmc->dev, dmc->hw);
+   if (IS_ERR(clk)) {
+   dev_err(dmc->dev, "could not register cpuclk dmc_clk\n");
+   return PTR_ERR(clk);
+   }
+   clk_register_clkdev(clk, "dmc_clk", NULL);
+   of_clk_add_provider(dmc->dev->of_node, of_clk_src_simple_get, clk);
+
+   return 0;
+}
+
+static int rk3399_dmcclk_probe(struct platform_device *pdev)
+{
+   struct rk3399_dmcclk *dmc;
+   struct resource *res;
+   struct device_node *node;
+   int ret;
+
+   dmc = devm_kzalloc(>dev, sizeof(*dmc), GFP_KERNEL);
+   if (!dmc)
+   return -ENOMEM;
+
+   dmc->hw = devm_kzalloc(>dev, sizeof(*dmc->hw), GFP_KERNEL);
+   if (!dmc->hw)
+   return -ENOMEM;
+
+   dmc->dev = >dev;
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+   dmc->ctrl_regs = devm_ioremap_resource(>dev, res);
+   if (IS_ERR(dmc->ctrl_regs))
+   return PTR_ERR(dmc->ctrl_regs);
+
+   res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+