From patchwork Wed Sep 27 06:26:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 114349 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp4673733qgf; Tue, 26 Sep 2017 23:27:49 -0700 (PDT) X-Received: by 10.99.6.210 with SMTP id 201mr379300pgg.416.1506493669888; Tue, 26 Sep 2017 23:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506493669; cv=none; d=google.com; s=arc-20160816; b=AadDjB+6jTIDtZAlPr15k6SJHYY7czp726TfyDKKyYvYorzdqsy9Y441etXMe6uJAR sbbKSf4714/8oYpyeKEZZQPjxlJL3YnwPEOfJfpkywqlSqg7nshLUDzK8IkCCMGwi5nW DKqlhdGq5/m30mu5wDV4G+TCGgzb7X/Rc1oYgiy0sET3zQil3VTcfDLZBWrT7jJC+kbr xE2y5T0AVpJOmEx72pNPk8QewN/T0rOUfAYE3eNpm1uLMbyBSPlb82VkhBm8qUCh9oN9 NC0LaoNc8hdDaPEYClsOLlUF8Tb/8yX8fzkjLzBWDW0OqdjFehsbZcWRkWQAW1M5/UUp wuDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=7E/V83b8Xtyr0Zzys3yxvbZfJd5zamnBK7X22z3EPls=; b=UbxPloNeyhGOQ1PV9s3m1H9SNgmd1F6J/pSRTgoBL0lxN4264x75Mzaf/czNNNnvim z8DOfeW5bO/UWLV1GAT1E4BfEYf3THb3RlRZVxeJIMbgT0IjVFvSyOponpnLt/CJEvsy FJV/3FjiuJwnKsWGqykRG6riHBjHy7AQIVsEb3r5823SWRJ7GtqiYCwzFoNOAv17kzR6 46CNLwARIHVha6t62GyeV4EW84VixbDnTqaKCpbflmdu+4HiPVr9YWH8Zru+o4jXBF6d mYZf49muXrvTATHNhvDttp85/rR/Yw8wEEo0KHh8cix3qj+1N2btK5D19G5EeKD2cbmd BvJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YFIi9+O+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p33si6971536pld.231.2017.09.26.23.27.49; Tue, 26 Sep 2017 23:27:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=YFIi9+O+; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752088AbdI0G1s (ORCPT + 26 others); Wed, 27 Sep 2017 02:27:48 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:38366 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750805AbdI0G1p (ORCPT ); Wed, 27 Sep 2017 02:27:45 -0400 Received: by mail-pf0-f193.google.com with SMTP id a7so6001544pfj.5; Tue, 26 Sep 2017 23:27:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=7E/V83b8Xtyr0Zzys3yxvbZfJd5zamnBK7X22z3EPls=; b=YFIi9+O+4IN6U/xdbrRN9kILzWtvpz0VIXXf9YFS1J+SuOKCyIVdsMdkvMGUK3TGqY noaIGc0S3ouRU/4Tjgz8XlJkZLj4fMje5ETAtVM28u1tfRxq1FUtopTZrd2NNnYSR/Yc TrWn0FR0w90dFBw6bdUgba/wcoYWO241aUxQ5K+Kpoi5FFX4/KcVdCL3HYXLxWwdDxBE ImqDGAF6oZ+ZfNeGMAywkT2DLnO0EE+r8AYtsbHfGuANVyvv6lYH6EK/vuP/NmjCcSAL DQQvkWHiEGI+Fdpez5rwVUYwo2l05XbjXX7ehIP21WXUY/vgqo6eEtjSNFWitbN96v1F /PKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=7E/V83b8Xtyr0Zzys3yxvbZfJd5zamnBK7X22z3EPls=; b=kYIl1OarS9+JNhGFlqX5WMPL+E0kDAz9bvX31/B+Mkz1677Mw+CiZcd5VypVyz9tFO UiUHX8LdtIYoxDI6VJ07lI7cYxMkGvHSJd3+RboRqNmTPxB0jauC1pKPNwVvWC/ap0f4 shGQAiRMF8dZ1+L0slVhVhJbiKPkPLLg9WKhUNfQU5WoymqQN0h4Yhpsc65NmuX4XbLl XAHpfhvvvB7tcXiPU/mNprEVLl9cDR3WnNc6BEVUm9g/gQ9R2fmW4K0GSKbY9hWLS6EB qKeJEwu41hHWuVgu/xKlTbZ6JgTwTr+JZsFYED5xPlqT4oymk4Db8DXR5qhP3LOOLvYu 4sfg== X-Gm-Message-State: AHPjjUgaLbogwEDetDATuJN/rKjYF7Vq3398WRgLmguGBsfnt9XECPTV 7gm1b6MrYJpPYwQHkf0XGW8= X-Google-Smtp-Source: AOwi7QC+QUu95zX1hSZA/l9Ey5spLJ4bLTKBE1Bu04EB8TFnCOxm3MO5D2WGPdl/1CprtLUWbV3qug== X-Received: by 10.99.121.129 with SMTP id u123mr389020pgc.246.1506493664380; Tue, 26 Sep 2017 23:27:44 -0700 (PDT) Received: from aurora.jms.id.au ([203.0.153.9]) by smtp.gmail.com with ESMTPSA id q23sm18880446pfk.182.2017.09.26.23.27.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 26 Sep 2017 23:27:43 -0700 (PDT) Received: by aurora.jms.id.au (sSMTP sendmail emulation); Wed, 27 Sep 2017 15:57:35 +0930 From: Joel Stanley To: Lee Jones , Michael Turquette , Stephen Boyd Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Andrew Jeffery , Benjamin Herrenschmidt , Jeremy Kerr , Rick Altherr , Ryan Chen , Arnd Bergmann Subject: [PATCH v3 2/5] clk: aspeed: Register core clocks Date: Wed, 27 Sep 2017 15:56:59 +0930 Message-Id: <20170927062702.11350-3-joel@jms.id.au> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170927062702.11350-1-joel@jms.id.au> References: <20170927062702.11350-1-joel@jms.id.au> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This registers the core clocks; those which are required to calculate the rate of the timer peripheral so the system can load a clocksource driver. Signed-off-by: Joel Stanley --- v3: - Fix ast2400 ahb calculation - Remove incorrect 'this is wrong' comment - Separate out clkin calc to be per platform - Support 48MHz clkin on ast2400 --- drivers/clk/clk-aspeed.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 164 insertions(+) -- 2.14.1 diff --git a/drivers/clk/clk-aspeed.c b/drivers/clk/clk-aspeed.c index 36b79a378f73..14387055554f 100644 --- a/drivers/clk/clk-aspeed.c +++ b/drivers/clk/clk-aspeed.c @@ -29,6 +29,9 @@ #define ASPEED_STRAP 0x70 #define ASPEED_CLK_SELECTION_2 0xd8 +/* Globally visible clocks */ +static DEFINE_SPINLOCK(aspeed_clk_lock); + /* Keeps track of all clocks */ static struct clk_hw_onecell_data *aspeed_clk_data; @@ -105,6 +108,160 @@ static const struct aspeed_gate_data aspeed_gates[] __initconst = { [ASPEED_CLK_GATE_LHCCLK] = { 28, -1, "lhclk-gate", "lhclk", 0 }, /* LPC master/LPC+ */ }; +static const struct clk_div_table ast2400_div_table[] = { + { 0x0, 2 }, + { 0x1, 4 }, + { 0x2, 6 }, + { 0x3, 8 }, + { 0x4, 10 }, + { 0x5, 12 }, + { 0x6, 14 }, + { 0x7, 16 }, + { 0 } +}; + +static const struct clk_div_table ast2500_div_table[] = { + { 0x0, 4 }, + { 0x1, 8 }, + { 0x2, 12 }, + { 0x3, 16 }, + { 0x4, 20 }, + { 0x5, 24 }, + { 0x6, 28 }, + { 0x7, 32 }, + { 0 } +}; + +static struct clk_hw *aspeed_ast2400_calc_pll(const char *name, u32 val) +{ + unsigned int mult, div; + + if (val & BIT(17)) { + /* Pass through mode */ + mult = div = 1; + } else { + /* F = 24Mhz * (2-OD) * [(N + 2) / (D + 1)] */ + u32 n = (val >> 5) & 0x3f; + u32 od = (val >> 4) & 0x1; + u32 d = val & 0xf; + + mult = (2 - od) * (n + 2); + div = d + 1; + } + return clk_hw_register_fixed_factor(NULL, name, "clkin", 0, + mult, div); +}; + +static struct clk_hw *aspeed_ast2500_calc_pll(const char *name, u32 val) +{ + unsigned int mult, div; + + if (val & BIT(20)) { + /* Pass through mode */ + mult = div = 1; + } else { + /* F = clkin * [(M+1) / (N+1)] / (P + 1) */ + u32 p = (val >> 13) & 0x3f; + u32 m = (val >> 5) & 0xff; + u32 n = val & 0x1f; + + mult = (m + 1) / (n + 1); + div = p + 1; + } + + return clk_hw_register_fixed_factor(NULL, name, "clkin", 0, + mult, div); +} + +static void __init aspeed_ast2400_cc(struct regmap *map) +{ + struct clk_hw *hw; + u32 val, freq, div; + + /* + * CLKIN is the crystal oscillator, 24, 48 or 25MHz selected by + * strapping + */ + regmap_read(map, ASPEED_STRAP, &val); + if (val & BIT(23)) + freq = 25000000; + else if (val & BIT(18)) + freq = 48000000; + else + freq = 24000000; + hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq); + pr_debug("clkin @%u MHz\n", freq / 1000000); + + /* + * High-speed PLL clock derived from the crystal. This the CPU clock, + * and we assume that it is enabled + */ + regmap_read(map, ASPEED_HPLL_PARAM, &val); + WARN(val & BIT(18), "hpll is strapped not configured"); + aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2400_calc_pll("hpll", val); + + /* + * Strap bits 11:10 define the CPU/AHB clock frequency ratio (aka HCLK) + * 00: Select CPU:AHB = 1:1 + * 01: Select CPU:AHB = 2:1 + * 10: Select CPU:AHB = 4:1 + * 11: Select CPU:AHB = 3:1 + */ + regmap_read(map, ASPEED_STRAP, &val); + val = (val >> 10) & 0x3; + div = val + 1; + if (div == 3) + div = 4; + else if (div == 4) + div = 3; + hw = clk_hw_register_fixed_factor(NULL, "ahb", "hpll", 0, 1, div); + aspeed_clk_data->hws[ASPEED_CLK_AHB] = hw; + + /* APB clock clock selection register SCU08 (aka PCLK) */ + hw = clk_hw_register_divider_table(NULL, "apb", "hpll", 0, + scu_base + ASPEED_CLK_SELECTION, 23, 3, 0, + ast2400_div_table, + &aspeed_clk_lock); + aspeed_clk_data->hws[ASPEED_CLK_APB] = hw; +} + +static void __init aspeed_ast2500_cc(struct regmap *map) +{ + struct clk_hw *hw; + u32 val, freq, div; + + /* CLKIN is the crystal oscillator, 24 or 25MHz selected by strapping */ + regmap_read(map, ASPEED_STRAP, &val); + if (val & BIT(23)) + freq = 25000000; + else + freq = 24000000; + hw = clk_hw_register_fixed_rate(NULL, "clkin", NULL, 0, freq); + pr_debug("clkin @%u MHz\n", freq / 1000000); + + /* + * High-speed PLL clock derived from the crystal. This the CPU clock, + * and we assume that it is enabled + */ + regmap_read(map, ASPEED_HPLL_PARAM, &val); + aspeed_clk_data->hws[ASPEED_CLK_HPLL] = aspeed_ast2500_calc_pll("hpll", val); + + /* Strap bits 11:9 define the AXI/AHB clock frequency ratio (aka HCLK)*/ + regmap_read(map, ASPEED_STRAP, &val); + val = (val >> 9) & 0x7; + WARN(val == 0, "strapping is zero: cannot determine ahb clock"); + div = 2 * (val + 1); + hw = clk_hw_register_fixed_factor(NULL, "ahb", "hpll", 0, 1, div); + aspeed_clk_data->hws[ASPEED_CLK_AHB] = hw; + + /* APB clock clock selection register SCU08 (aka PCLK) */ + regmap_read(map, ASPEED_CLK_SELECTION, &val); + val = (val >> 23) & 0x7; + div = 4 * (val + 1); + hw = clk_hw_register_fixed_factor(NULL, "apb", "hpll", 0, 1, div); + aspeed_clk_data->hws[ASPEED_CLK_APB] = hw; +}; + static void __init aspeed_cc_init(struct device_node *np) { struct regmap *map; @@ -146,6 +303,13 @@ static void __init aspeed_cc_init(struct device_node *np) return; } + if (of_device_is_compatible(np, "aspeed,ast2400-scu")) + aspeed_ast2400_cc(map); + else if (of_device_is_compatible(np, "aspeed,ast2500-scu")) + aspeed_ast2500_cc(map); + else + pr_err("unknown platform, failed to add clocks\n"); + aspeed_clk_data->num = ASPEED_NUM_CLKS; ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, aspeed_clk_data); if (ret)