-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'mike-turquette/clk-next-shmobile' into …
…dt3-base
- Loading branch information
Showing
9 changed files
with
850 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Documentation/devicetree/bindings/clock/renesas,cpg-div6-clocks.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
* Renesas CPG DIV6 Clock | ||
|
||
The CPG DIV6 clocks are variable factor clocks provided by the Clock Pulse | ||
Generator (CPG). They clock input is divided by a configurable factor from 1 | ||
to 64. | ||
|
||
Required Properties: | ||
|
||
- compatible: Must be one of the following | ||
- "renesas,r8a7790-div6-clock" for R8A7790 (R-Car H2) DIV6 clocks | ||
- "renesas,r8a7791-div6-clock" for R8A7791 (R-Car M2) DIV6 clocks | ||
- "renesas,cpg-div6-clock" for generic DIV6 clocks | ||
- reg: Base address and length of the memory resource used by the DIV6 clock | ||
- clocks: Reference to the parent clock | ||
- #clock-cells: Must be 0 | ||
- clock-output-names: The name of the clock as a free-form string | ||
|
||
|
||
Example | ||
------- | ||
|
||
sd2_clk: sd2_clk@e6150078 { | ||
compatible = "renesas,r8a7790-div6-clock", "renesas,cpg-div6-clock"; | ||
reg = <0 0xe6150078 0 4>; | ||
clocks = <&pll1_div2_clk>; | ||
#clock-cells = <0>; | ||
clock-output-names = "sd2"; | ||
}; |
51 changes: 51 additions & 0 deletions
51
Documentation/devicetree/bindings/clock/renesas,cpg-mstp-clocks.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
* Renesas CPG Module Stop (MSTP) Clocks | ||
|
||
The CPG can gate SoC device clocks. The gates are organized in groups of up to | ||
32 gates. | ||
|
||
This device tree binding describes a single 32 gate clocks group per node. | ||
Clocks are referenced by user nodes by the MSTP node phandle and the clock | ||
index in the group, from 0 to 31. | ||
|
||
Required Properties: | ||
|
||
- compatible: Must be one of the following | ||
- "renesas,r8a7790-mstp-clocks" for R8A7790 (R-Car H2) MSTP gate clocks | ||
- "renesas,r8a7791-mstp-clocks" for R8A7791 (R-Car M2) MSTP gate clocks | ||
- "renesas,cpg-mstp-clock" for generic MSTP gate clocks | ||
- reg: Base address and length of the I/O mapped registers used by the MSTP | ||
clocks. The first register is the clock control register and is mandatory. | ||
The second register is the clock status register and is optional when not | ||
implemented in hardware. | ||
- clocks: Reference to the parent clocks, one per output clock. The parents | ||
must appear in the same order as the output clocks. | ||
- #clock-cells: Must be 1 | ||
- clock-output-names: The name of the clocks as free-form strings | ||
- renesas,indices: Indices of the gate clocks into the group (0 to 31) | ||
|
||
The clocks, clock-output-names and renesas,indices properties contain one | ||
entry per gate clock. The MSTP groups are sparsely populated. Unimplemented | ||
gate clocks must not be declared. | ||
|
||
|
||
Example | ||
------- | ||
|
||
#include <dt-bindings/clock/r8a7790-clock.h> | ||
|
||
mstp3_clks: mstp3_clks@e615013c { | ||
compatible = "renesas,r8a7790-mstp-clocks", "renesas,cpg-mstp-clocks"; | ||
reg = <0 0xe615013c 0 4>, <0 0xe6150048 0 4>; | ||
clocks = <&cp_clk>, <&mmc1_clk>, <&sd3_clk>, <&sd2_clk>, | ||
<&cpg_clocks R8A7790_CLK_SD1>, <&cpg_clocks R8A7790_CLK_SD0>, | ||
<&mmc0_clk>; | ||
#clock-cells = <1>; | ||
clock-output-names = | ||
"tpu0", "mmcif1", "sdhi3", "sdhi2", | ||
"sdhi1", "sdhi0", "mmcif0"; | ||
renesas,clock-indices = < | ||
R8A7790_CLK_TPU0 R8A7790_CLK_MMCIF1 R8A7790_CLK_SDHI3 | ||
R8A7790_CLK_SDHI2 R8A7790_CLK_SDHI1 R8A7790_CLK_SDHI0 | ||
R8A7790_CLK_MMCIF0 | ||
>; | ||
}; |
32 changes: 32 additions & 0 deletions
32
Documentation/devicetree/bindings/clock/renesas,rcar-gen2-cpg-clocks.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
* Renesas R-Car Gen2 Clock Pulse Generator (CPG) | ||
|
||
The CPG generates core clocks for the R-Car Gen2 SoCs. It includes three PLLs | ||
and several fixed ratio dividers. | ||
|
||
Required Properties: | ||
|
||
- compatible: Must be one of | ||
- "renesas,r8a7790-cpg-clocks" for the r8a7790 CPG | ||
- "renesas,r8a7791-cpg-clocks" for the r8a7791 CPG | ||
- "renesas,rcar-gen2-cpg-clocks" for the generic R-Car Gen2 CPG | ||
|
||
- reg: Base address and length of the memory resource used by the CPG | ||
|
||
- clocks: Reference to the parent clock | ||
- #clock-cells: Must be 1 | ||
- clock-output-names: The names of the clocks. Supported clocks are "main", | ||
"pll0", "pll1", "pll3", "lb", "qspi", "sdh", "sd0", "sd1" and "z" | ||
|
||
|
||
Example | ||
------- | ||
|
||
cpg_clocks: cpg_clocks@e6150000 { | ||
compatible = "renesas,r8a7790-cpg-clocks", | ||
"renesas,rcar-gen2-cpg-clocks"; | ||
reg = <0 0xe6150000 0 0x1000>; | ||
clocks = <&extal_clk>; | ||
#clock-cells = <1>; | ||
clock-output-names = "main", "pll0, "pll1", "pll3", | ||
"lb", "qspi", "sdh", "sd0", "sd1", "z"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
obj-$(CONFIG_ARCH_R8A7790) += clk-rcar-gen2.o | ||
obj-$(CONFIG_ARCH_R8A7791) += clk-rcar-gen2.o | ||
obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-div6.o | ||
obj-$(CONFIG_ARCH_SHMOBILE_MULTI) += clk-mstp.o | ||
|
||
# for emply built-in.o | ||
obj-n := dummy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
/* | ||
* r8a7790 Common Clock Framework support | ||
* | ||
* Copyright (C) 2013 Renesas Solutions Corp. | ||
* | ||
* Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; version 2 of the License. | ||
*/ | ||
|
||
#include <linux/clk-provider.h> | ||
#include <linux/clkdev.h> | ||
#include <linux/init.h> | ||
#include <linux/io.h> | ||
#include <linux/kernel.h> | ||
#include <linux/of.h> | ||
#include <linux/of_address.h> | ||
|
||
#define CPG_DIV6_CKSTP BIT(8) | ||
#define CPG_DIV6_DIV(d) ((d) & 0x3f) | ||
#define CPG_DIV6_DIV_MASK 0x3f | ||
|
||
/** | ||
* struct div6_clock - MSTP gating clock | ||
* @hw: handle between common and hardware-specific interfaces | ||
* @reg: IO-remapped register | ||
* @div: divisor value (1-64) | ||
*/ | ||
struct div6_clock { | ||
struct clk_hw hw; | ||
void __iomem *reg; | ||
unsigned int div; | ||
}; | ||
|
||
#define to_div6_clock(_hw) container_of(_hw, struct div6_clock, hw) | ||
|
||
static int cpg_div6_clock_enable(struct clk_hw *hw) | ||
{ | ||
struct div6_clock *clock = to_div6_clock(hw); | ||
|
||
clk_writel(CPG_DIV6_DIV(clock->div - 1), clock->reg); | ||
|
||
return 0; | ||
} | ||
|
||
static void cpg_div6_clock_disable(struct clk_hw *hw) | ||
{ | ||
struct div6_clock *clock = to_div6_clock(hw); | ||
|
||
/* DIV6 clocks require the divisor field to be non-zero when stopping | ||
* the clock. | ||
*/ | ||
clk_writel(CPG_DIV6_CKSTP | CPG_DIV6_DIV(CPG_DIV6_DIV_MASK), | ||
clock->reg); | ||
} | ||
|
||
static int cpg_div6_clock_is_enabled(struct clk_hw *hw) | ||
{ | ||
struct div6_clock *clock = to_div6_clock(hw); | ||
|
||
return !(clk_readl(clock->reg) & CPG_DIV6_CKSTP); | ||
} | ||
|
||
static unsigned long cpg_div6_clock_recalc_rate(struct clk_hw *hw, | ||
unsigned long parent_rate) | ||
{ | ||
struct div6_clock *clock = to_div6_clock(hw); | ||
unsigned int div = (clk_readl(clock->reg) & CPG_DIV6_DIV_MASK) + 1; | ||
|
||
return parent_rate / div; | ||
} | ||
|
||
static unsigned int cpg_div6_clock_calc_div(unsigned long rate, | ||
unsigned long parent_rate) | ||
{ | ||
unsigned int div; | ||
|
||
div = DIV_ROUND_CLOSEST(parent_rate, rate); | ||
return clamp_t(unsigned int, div, 1, 64); | ||
} | ||
|
||
static long cpg_div6_clock_round_rate(struct clk_hw *hw, unsigned long rate, | ||
unsigned long *parent_rate) | ||
{ | ||
unsigned int div = cpg_div6_clock_calc_div(rate, *parent_rate); | ||
|
||
return *parent_rate / div; | ||
} | ||
|
||
static int cpg_div6_clock_set_rate(struct clk_hw *hw, unsigned long rate, | ||
unsigned long parent_rate) | ||
{ | ||
struct div6_clock *clock = to_div6_clock(hw); | ||
unsigned int div = cpg_div6_clock_calc_div(rate, parent_rate); | ||
|
||
clock->div = div; | ||
|
||
/* Only program the new divisor if the clock isn't stopped. */ | ||
if (!(clk_readl(clock->reg) & CPG_DIV6_CKSTP)) | ||
clk_writel(CPG_DIV6_DIV(clock->div - 1), clock->reg); | ||
|
||
return 0; | ||
} | ||
|
||
static const struct clk_ops cpg_div6_clock_ops = { | ||
.enable = cpg_div6_clock_enable, | ||
.disable = cpg_div6_clock_disable, | ||
.is_enabled = cpg_div6_clock_is_enabled, | ||
.recalc_rate = cpg_div6_clock_recalc_rate, | ||
.round_rate = cpg_div6_clock_round_rate, | ||
.set_rate = cpg_div6_clock_set_rate, | ||
}; | ||
|
||
static void __init cpg_div6_clock_init(struct device_node *np) | ||
{ | ||
struct clk_init_data init; | ||
struct div6_clock *clock; | ||
const char *parent_name; | ||
const char *name; | ||
struct clk *clk; | ||
int ret; | ||
|
||
clock = kzalloc(sizeof(*clock), GFP_KERNEL); | ||
if (!clock) { | ||
pr_err("%s: failed to allocate %s DIV6 clock\n", | ||
__func__, np->name); | ||
return; | ||
} | ||
|
||
/* Remap the clock register and read the divisor. Disabling the | ||
* clock overwrites the divisor, so we need to cache its value for the | ||
* enable operation. | ||
*/ | ||
clock->reg = of_iomap(np, 0); | ||
if (clock->reg == NULL) { | ||
pr_err("%s: failed to map %s DIV6 clock register\n", | ||
__func__, np->name); | ||
goto error; | ||
} | ||
|
||
clock->div = (clk_readl(clock->reg) & CPG_DIV6_DIV_MASK) + 1; | ||
|
||
/* Parse the DT properties. */ | ||
ret = of_property_read_string(np, "clock-output-names", &name); | ||
if (ret < 0) { | ||
pr_err("%s: failed to get %s DIV6 clock output name\n", | ||
__func__, np->name); | ||
goto error; | ||
} | ||
|
||
parent_name = of_clk_get_parent_name(np, 0); | ||
if (parent_name == NULL) { | ||
pr_err("%s: failed to get %s DIV6 clock parent name\n", | ||
__func__, np->name); | ||
goto error; | ||
} | ||
|
||
/* Register the clock. */ | ||
init.name = name; | ||
init.ops = &cpg_div6_clock_ops; | ||
init.flags = CLK_IS_BASIC; | ||
init.parent_names = &parent_name; | ||
init.num_parents = 1; | ||
|
||
clock->hw.init = &init; | ||
|
||
clk = clk_register(NULL, &clock->hw); | ||
if (IS_ERR(clk)) { | ||
pr_err("%s: failed to register %s DIV6 clock (%ld)\n", | ||
__func__, np->name, PTR_ERR(clk)); | ||
goto error; | ||
} | ||
|
||
of_clk_add_provider(np, of_clk_src_simple_get, clk); | ||
|
||
return; | ||
|
||
error: | ||
if (clock->reg) | ||
iounmap(clock->reg); | ||
kfree(clock); | ||
} | ||
CLK_OF_DECLARE(cpg_div6_clk, "renesas,cpg-div6-clock", cpg_div6_clock_init); |
Oops, something went wrong.