19e288cefSKuninori Morimoto // SPDX-License-Identifier: GPL-2.0 2b3a33077SSimon Horman /* 3b3a33077SSimon Horman * EMMA Mobile EV2 common clock framework support 4b3a33077SSimon Horman * 5b3a33077SSimon Horman * Copyright (C) 2013 Takashi Yoshii <takashi.yoshii.ze@renesas.com> 6b3a33077SSimon Horman * Copyright (C) 2012 Magnus Damm 7b3a33077SSimon Horman */ 8b3a33077SSimon Horman #include <linux/clk-provider.h> 9b3a33077SSimon Horman #include <linux/clkdev.h> 10b3a33077SSimon Horman #include <linux/io.h> 11b3a33077SSimon Horman #include <linux/of.h> 12b3a33077SSimon Horman #include <linux/of_address.h> 13b3a33077SSimon Horman 14b3a33077SSimon Horman /* EMEV2 SMU registers */ 15b3a33077SSimon Horman #define USIAU0_RSTCTRL 0x094 16b3a33077SSimon Horman #define USIBU1_RSTCTRL 0x0ac 17b3a33077SSimon Horman #define USIBU2_RSTCTRL 0x0b0 18b3a33077SSimon Horman #define USIBU3_RSTCTRL 0x0b4 19b3a33077SSimon Horman #define IIC0_RSTCTRL 0x0dc 20b3a33077SSimon Horman #define IIC1_RSTCTRL 0x0e0 21b3a33077SSimon Horman #define STI_RSTCTRL 0x124 22b3a33077SSimon Horman #define STI_CLKSEL 0x688 23b3a33077SSimon Horman 24b3a33077SSimon Horman static DEFINE_SPINLOCK(lock); 25b3a33077SSimon Horman 26b3a33077SSimon Horman /* not pretty, but hey */ 27b3a33077SSimon Horman static void __iomem *smu_base; 28b3a33077SSimon Horman 29b3a33077SSimon Horman static void __init emev2_smu_write(unsigned long value, int offs) 30b3a33077SSimon Horman { 31b3a33077SSimon Horman BUG_ON(!smu_base || (offs >= PAGE_SIZE)); 32b3a33077SSimon Horman writel_relaxed(value, smu_base + offs); 33b3a33077SSimon Horman } 34b3a33077SSimon Horman 35b3a33077SSimon Horman static const struct of_device_id smu_id[] __initconst = { 36b3a33077SSimon Horman { .compatible = "renesas,emev2-smu", }, 37b3a33077SSimon Horman {}, 38b3a33077SSimon Horman }; 39b3a33077SSimon Horman 40b3a33077SSimon Horman static void __init emev2_smu_init(void) 41b3a33077SSimon Horman { 42b3a33077SSimon Horman struct device_node *np; 43b3a33077SSimon Horman 44b3a33077SSimon Horman np = of_find_matching_node(NULL, smu_id); 45b3a33077SSimon Horman BUG_ON(!np); 46b3a33077SSimon Horman smu_base = of_iomap(np, 0); 47b3a33077SSimon Horman BUG_ON(!smu_base); 48b3a33077SSimon Horman of_node_put(np); 49b3a33077SSimon Horman 50b3a33077SSimon Horman /* setup STI timer to run on 32.768 kHz and deassert reset */ 51b3a33077SSimon Horman emev2_smu_write(0, STI_CLKSEL); 52b3a33077SSimon Horman emev2_smu_write(1, STI_RSTCTRL); 53b3a33077SSimon Horman 54b3a33077SSimon Horman /* deassert reset for UART0->UART3 */ 55b3a33077SSimon Horman emev2_smu_write(2, USIAU0_RSTCTRL); 56b3a33077SSimon Horman emev2_smu_write(2, USIBU1_RSTCTRL); 57b3a33077SSimon Horman emev2_smu_write(2, USIBU2_RSTCTRL); 58b3a33077SSimon Horman emev2_smu_write(2, USIBU3_RSTCTRL); 59b3a33077SSimon Horman 60b3a33077SSimon Horman /* deassert reset for IIC0->IIC1 */ 61b3a33077SSimon Horman emev2_smu_write(1, IIC0_RSTCTRL); 62b3a33077SSimon Horman emev2_smu_write(1, IIC1_RSTCTRL); 63b3a33077SSimon Horman } 64b3a33077SSimon Horman 65b3a33077SSimon Horman static void __init emev2_smu_clkdiv_init(struct device_node *np) 66b3a33077SSimon Horman { 67b3a33077SSimon Horman u32 reg[2]; 68b3a33077SSimon Horman struct clk *clk; 69b3a33077SSimon Horman const char *parent_name = of_clk_get_parent_name(np, 0); 70b3a33077SSimon Horman if (WARN_ON(of_property_read_u32_array(np, "reg", reg, 2))) 71b3a33077SSimon Horman return; 72b3a33077SSimon Horman if (!smu_base) 73b3a33077SSimon Horman emev2_smu_init(); 74b3a33077SSimon Horman clk = clk_register_divider(NULL, np->name, parent_name, 0, 75b3a33077SSimon Horman smu_base + reg[0], reg[1], 8, 0, &lock); 76b3a33077SSimon Horman of_clk_add_provider(np, of_clk_src_simple_get, clk); 77b3a33077SSimon Horman clk_register_clkdev(clk, np->name, NULL); 78b3a33077SSimon Horman pr_debug("## %s %s %p\n", __func__, np->name, clk); 79b3a33077SSimon Horman } 80b3a33077SSimon Horman CLK_OF_DECLARE(emev2_smu_clkdiv, "renesas,emev2-smu-clkdiv", 81b3a33077SSimon Horman emev2_smu_clkdiv_init); 82b3a33077SSimon Horman 83b3a33077SSimon Horman static void __init emev2_smu_gclk_init(struct device_node *np) 84b3a33077SSimon Horman { 85b3a33077SSimon Horman u32 reg[2]; 86b3a33077SSimon Horman struct clk *clk; 87b3a33077SSimon Horman const char *parent_name = of_clk_get_parent_name(np, 0); 88b3a33077SSimon Horman if (WARN_ON(of_property_read_u32_array(np, "reg", reg, 2))) 89b3a33077SSimon Horman return; 90b3a33077SSimon Horman if (!smu_base) 91b3a33077SSimon Horman emev2_smu_init(); 92b3a33077SSimon Horman clk = clk_register_gate(NULL, np->name, parent_name, 0, 93b3a33077SSimon Horman smu_base + reg[0], reg[1], 0, &lock); 94b3a33077SSimon Horman of_clk_add_provider(np, of_clk_src_simple_get, clk); 95b3a33077SSimon Horman clk_register_clkdev(clk, np->name, NULL); 96b3a33077SSimon Horman pr_debug("## %s %s %p\n", __func__, np->name, clk); 97b3a33077SSimon Horman } 98b3a33077SSimon Horman CLK_OF_DECLARE(emev2_smu_gclk, "renesas,emev2-smu-gclk", emev2_smu_gclk_init); 99