···11+Device tree Clock bindings for Renesas EMMA Mobile EV222+33+This binding uses the common clock binding.44+55+* SMU66+System Management Unit described in user's manual R19UH0037EJ1000_SMU.77+This is not a clock provider, but clocks under SMU depend on it.88+99+Required properties:1010+- compatible: Should be "renesas,emev2-smu"1111+- reg: Address and Size of SMU registers1212+1313+* SMU_CLKDIV1414+Function block with an input mux and a divider, which corresponds to1515+"Serial clock generator" in fig."Clock System Overview" of the manual,1616+and "xxx frequency division setting register" (XXXCLKDIV) registers.1717+This makes internal (neither input nor output) clock that is provided1818+to input of xxxGCLK block.1919+2020+Required properties:2121+- compatible: Should be "renesas,emev2-smu-clkdiv"2222+- reg: Byte offset from SMU base and Bit position in the register2323+- clocks: Parent clocks. Input clocks as described in clock-bindings.txt2424+- #clock-cells: Should be <0>2525+2626+* SMU_GCLK2727+Clock gating node shown as "Clock stop processing block" in the2828+fig."Clock System Overview" of the manual.2929+Registers are "xxx clock gate control register" (XXXGCLKCTRL).3030+3131+Required properties:3232+- compatible: Should be "renesas,emev2-smu-gclk"3333+- reg: Byte offset from SMU base and Bit position in the register3434+- clocks: Input clock as described in clock-bindings.txt3535+- #clock-cells: Should be <0>3636+3737+Example of provider:3838+3939+usia_u0_sclkdiv: usia_u0_sclkdiv {4040+ compatible = "renesas,emev2-smu-clkdiv";4141+ reg = <0x610 0>;4242+ clocks = <&pll3_fo>, <&pll4_fo>, <&pll1_fo>, <&osc1_fo>;4343+ #clock-cells = <0>;4444+};4545+4646+usia_u0_sclk: usia_u0_sclk {4747+ compatible = "renesas,emev2-smu-gclk";4848+ reg = <0x4a0 1>;4949+ clocks = <&usia_u0_sclkdiv>;5050+ #clock-cells = <0>;5151+};5252+5353+Example of consumer:5454+5555+uart@e1020000 {5656+ compatible = "renesas,em-uart";5757+ reg = <0xe1020000 0x38>;5858+ interrupts = <0 8 0>;5959+ clocks = <&usia_u0_sclk>;6060+ clock-names = "sclk";6161+};6262+6363+Example of clock-tree description:6464+6565+ This describes a clock path in the clock tree6666+ c32ki -> pll3_fo -> usia_u0_sclkdiv -> usia_u0_sclk6767+6868+smu@e0110000 {6969+ compatible = "renesas,emev2-smu";7070+ reg = <0xe0110000 0x10000>;7171+ #address-cells = <2>;7272+ #size-cells = <0>;7373+7474+ c32ki: c32ki {7575+ compatible = "fixed-clock";7676+ clock-frequency = <32768>;7777+ #clock-cells = <0>;7878+ };7979+ pll3_fo: pll3_fo {8080+ compatible = "fixed-factor-clock";8181+ clocks = <&c32ki>;8282+ clock-div = <1>;8383+ clock-mult = <7000>;8484+ #clock-cells = <0>;8585+ };8686+ usia_u0_sclkdiv: usia_u0_sclkdiv {8787+ compatible = "renesas,emev2-smu-clkdiv";8888+ reg = <0x610 0>;8989+ clocks = <&pll3_fo>;9090+ #clock-cells = <0>;9191+ };9292+ usia_u0_sclk: usia_u0_sclk {9393+ compatible = "renesas,emev2-smu-gclk";9494+ reg = <0x4a0 1>;9595+ clocks = <&usia_u0_sclkdiv>;9696+ #clock-cells = <0>;9797+ };9898+};
···11+/*22+ * EMMA Mobile EV2 common clock framework support33+ *44+ * Copyright (C) 2013 Takashi Yoshii <takashi.yoshii.ze@renesas.com>55+ * Copyright (C) 2012 Magnus Damm66+ *77+ * This program is free software; you can redistribute it and/or modify88+ * it under the terms of the GNU General Public License as published by99+ * the Free Software Foundation; version 2 of the License.1010+ *1111+ * This program is distributed in the hope that it will be useful,1212+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1313+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1414+ * GNU General Public License for more details.1515+ *1616+ * You should have received a copy of the GNU General Public License1717+ * along with this program; if not, write to the Free Software1818+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA1919+ */2020+#include <linux/clk-provider.h>2121+#include <linux/clkdev.h>2222+#include <linux/io.h>2323+#include <linux/of.h>2424+#include <linux/of_address.h>2525+2626+/* EMEV2 SMU registers */2727+#define USIAU0_RSTCTRL 0x0942828+#define USIBU1_RSTCTRL 0x0ac2929+#define USIBU2_RSTCTRL 0x0b03030+#define USIBU3_RSTCTRL 0x0b43131+#define STI_RSTCTRL 0x1243232+#define STI_CLKSEL 0x6883333+3434+static DEFINE_SPINLOCK(lock);3535+3636+/* not pretty, but hey */3737+void __iomem *smu_base;3838+3939+static void __init emev2_smu_write(unsigned long value, int offs)4040+{4141+ BUG_ON(!smu_base || (offs >= PAGE_SIZE));4242+ writel_relaxed(value, smu_base + offs);4343+}4444+4545+static const struct of_device_id smu_id[] __initconst = {4646+ { .compatible = "renesas,emev2-smu", },4747+ {},4848+};4949+5050+static void __init emev2_smu_init(void)5151+{5252+ struct device_node *np;5353+5454+ np = of_find_matching_node(NULL, smu_id);5555+ BUG_ON(!np);5656+ smu_base = of_iomap(np, 0);5757+ BUG_ON(!smu_base);5858+ of_node_put(np);5959+6060+ /* setup STI timer to run on 32.768 kHz and deassert reset */6161+ emev2_smu_write(0, STI_CLKSEL);6262+ emev2_smu_write(1, STI_RSTCTRL);6363+6464+ /* deassert reset for UART0->UART3 */6565+ emev2_smu_write(2, USIAU0_RSTCTRL);6666+ emev2_smu_write(2, USIBU1_RSTCTRL);6767+ emev2_smu_write(2, USIBU2_RSTCTRL);6868+ emev2_smu_write(2, USIBU3_RSTCTRL);6969+}7070+7171+static void __init emev2_smu_clkdiv_init(struct device_node *np)7272+{7373+ u32 reg[2];7474+ struct clk *clk;7575+ const char *parent_name = of_clk_get_parent_name(np, 0);7676+ if (WARN_ON(of_property_read_u32_array(np, "reg", reg, 2)))7777+ return;7878+ if (!smu_base)7979+ emev2_smu_init();8080+ clk = clk_register_divider(NULL, np->name, parent_name, 0,8181+ smu_base + reg[0], reg[1], 8, 0, &lock);8282+ of_clk_add_provider(np, of_clk_src_simple_get, clk);8383+ clk_register_clkdev(clk, np->name, NULL);8484+ pr_debug("## %s %s %p\n", __func__, np->name, clk);8585+}8686+CLK_OF_DECLARE(emev2_smu_clkdiv, "renesas,emev2-smu-clkdiv",8787+ emev2_smu_clkdiv_init);8888+8989+static void __init emev2_smu_gclk_init(struct device_node *np)9090+{9191+ u32 reg[2];9292+ struct clk *clk;9393+ const char *parent_name = of_clk_get_parent_name(np, 0);9494+ if (WARN_ON(of_property_read_u32_array(np, "reg", reg, 2)))9595+ return;9696+ if (!smu_base)9797+ emev2_smu_init();9898+ clk = clk_register_gate(NULL, np->name, parent_name, 0,9999+ smu_base + reg[0], reg[1], 0, &lock);100100+ of_clk_add_provider(np, of_clk_src_simple_get, clk);101101+ clk_register_clkdev(clk, np->name, NULL);102102+ pr_debug("## %s %s %p\n", __func__, np->name, clk);103103+}104104+CLK_OF_DECLARE(emev2_smu_gclk, "renesas,emev2-smu-gclk", emev2_smu_gclk_init);