Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp342228pxb; Wed, 22 Sep 2021 03:33:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpCW3ADVWLo+4xW1gq6AbC4RiFj3tI3rznBn4NS6HDHNotart/EKVrDV1mnGFoZ/7Pq/BM X-Received: by 2002:a05:6e02:1aac:: with SMTP id l12mr21303175ilv.318.1632306786263; Wed, 22 Sep 2021 03:33:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632306786; cv=none; d=google.com; s=arc-20160816; b=xkU03InxLpJjIAcgpCl0y1OIwmkJ2VTw68RQuoH3UAmLo9BDzFyzVEQOuSoW8nBLVB 6kIuUCuaFAC2VMIr4A40oheCinMr3Cm3bmREMYTm0/y72jaoCnW7cuyN1WSjxJKG3Xh3 cGtBq6mYcmhHMwpx95UVPpfR8Q3D8ZiH4jW+J1BAG5fx/okiDt0Y8IfqjoVOEb1QsihP 2SohLFGza+jm1sP0H5yxPs+SJ393JRGYRCBIf6p955EH9V0Nd7f7zGYh9u1eFc5y5TN8 zrjON0LWTmsmrVs6KnL+zjoXkApJOqiTkyhJx+/LQnNmXjWxPjpKnpfB3bh1WtyO5qdY nETQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=L3HqADj/Oai1WFfclYxdP0uFzHeUkK7W2RHqlwWGdBM=; b=mA0cOnascBE5DBWV1e4TQ3J0bL9Jdzlrd38hn0+Q8dwpqDNVaP+/JpHw6Fd0HVrRcN JiofPQqDR3m2YKNbPAjN5M2jXAwiaYbU8/KF1h/vA99qohtPENHbBaUn3+rajAFXMVNY X+lPN7elmheu3ZkRNS9DbvIVMtKi6Z9DmqYXaEwxQ5MbBm73wYzaMlqCSGgyHlY7fpZB Ob8KDkNOAJUAOuQEhRugDRotLjhmtjN7sESX/V0kSc7EuauLanF89zrJU8LusmVnDV4z 5hOoTQ0RwoJ2u+L78ctiMilSAsPrxjUULKHbNZRweewW4H7hor/1hy5lZro98Pfa7uST e06A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s14si2451395iln.136.2021.09.22.03.32.55; Wed, 22 Sep 2021 03:33:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234904AbhIVKdI (ORCPT + 99 others); Wed, 22 Sep 2021 06:33:08 -0400 Received: from twspam01.aspeedtech.com ([211.20.114.71]:26571 "EHLO twspam01.aspeedtech.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234786AbhIVKdF (ORCPT ); Wed, 22 Sep 2021 06:33:05 -0400 Received: from mail.aspeedtech.com ([192.168.0.24]) by twspam01.aspeedtech.com with ESMTP id 18MAB7N1012563; Wed, 22 Sep 2021 18:11:07 +0800 (GMT-8) (envelope-from chin-ting_kuo@aspeedtech.com) Received: from localhost.localdomain (192.168.10.9) by TWMBX02.aspeed.com (192.168.0.24) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 22 Sep 2021 18:31:25 +0800 From: Chin-Ting Kuo To: , , , , , , , , , , , , CC: , Subject: [PATCH 01/10] clk: aspeed: ast2600: Porting sdhci clock source Date: Wed, 22 Sep 2021 18:31:07 +0800 Message-ID: <20210922103116.30652-2-chin-ting_kuo@aspeedtech.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210922103116.30652-1-chin-ting_kuo@aspeedtech.com> References: <20210922103116.30652-1-chin-ting_kuo@aspeedtech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.10.9] X-ClientProxiedBy: TWMBX02.aspeed.com (192.168.0.24) To TWMBX02.aspeed.com (192.168.0.24) X-DNSRBL: X-MAIL: twspam01.aspeedtech.com 18MAB7N1012563 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org - There are two clock sources used to generate SD/SDIO clock, APLL clock and HCLK (200MHz). User can select which clock source should be used by configuring SCU310[8]. - The SD/SDIO clock divider selection table SCU310[30:28] is different between AST2600-A1 and AST2600-A2/A3. For AST2600-A1, 200MHz SD/SDIO clock cannot be gotten by the dividers in SCU310[30:28] if APLL is not the multiple of 200MHz and HCLK is 200MHz. For AST2600-A2/A3, a new divider, "1", is added and 200MHz SD/SDIO clock can be obtained by adopting HCLK as clock source and setting SCU310[30:28] to 3b'111. Signed-off-by: Chin-Ting Kuo --- drivers/clk/clk-ast2600.c | 69 ++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/drivers/clk/clk-ast2600.c b/drivers/clk/clk-ast2600.c index bc3be5f3eae1..a6778c18274a 100644 --- a/drivers/clk/clk-ast2600.c +++ b/drivers/clk/clk-ast2600.c @@ -168,6 +168,30 @@ static const struct clk_div_table ast2600_div_table[] = { { 0 } }; +static const struct clk_div_table ast2600_sd_div_a1_table[] = { + { 0x0, 2 }, + { 0x1, 4 }, + { 0x2, 6 }, + { 0x3, 8 }, + { 0x4, 10 }, + { 0x5, 12 }, + { 0x6, 14 }, + { 0x7, 16 }, + { 0 } +}; + +static const struct clk_div_table ast2600_sd_div_a2_table[] = { + { 0x0, 2 }, + { 0x1, 4 }, + { 0x2, 6 }, + { 0x3, 8 }, + { 0x4, 10 }, + { 0x5, 12 }, + { 0x6, 14 }, + { 0x7, 1 }, + { 0 } +}; + /* For hpll/dpll/epll/mpll */ static struct clk_hw *ast2600_calc_pll(const char *name, u32 val) { @@ -424,6 +448,11 @@ static const char *const emmc_extclk_parent_names[] = { "mpll", }; +static const char *const sd_extclk_parent_names[] = { + "hclk", + "apll", +}; + static const char * const vclk_parent_names[] = { "dpll", "d1pll", @@ -523,18 +552,42 @@ static int aspeed_g6_clk_probe(struct platform_device *pdev) return PTR_ERR(hw); aspeed_g6_clk_data->hws[ASPEED_CLK_EMMC] = hw; - /* SD/SDIO clock divider and gate */ - hw = clk_hw_register_gate(dev, "sd_extclk_gate", "hpll", 0, - scu_g6_base + ASPEED_G6_CLK_SELECTION4, 31, 0, - &aspeed_g6_clk_lock); + clk_hw_register_fixed_rate(NULL, "hclk", NULL, 0, 200000000); + + regmap_read(map, 0x310, &val); + hw = clk_hw_register_mux(dev, "sd_extclk_mux", + sd_extclk_parent_names, + ARRAY_SIZE(sd_extclk_parent_names), 0, + scu_g6_base + ASPEED_G6_CLK_SELECTION4, 8, 1, + 0, &aspeed_g6_clk_lock); if (IS_ERR(hw)) return PTR_ERR(hw); - hw = clk_hw_register_divider_table(dev, "sd_extclk", "sd_extclk_gate", - 0, scu_g6_base + ASPEED_G6_CLK_SELECTION4, 28, 3, 0, - ast2600_div_table, - &aspeed_g6_clk_lock); + + hw = clk_hw_register_gate(dev, "sd_extclk_gate", "sd_extclk_mux", + 0, scu_g6_base + ASPEED_G6_CLK_SELECTION4, + 31, 0, &aspeed_g6_clk_lock); if (IS_ERR(hw)) return PTR_ERR(hw); + + regmap_read(map, 0x14, &val); + /* AST2600-A2/A3 clock divisor is different from AST2600-A1 */ + if (((val & GENMASK(23, 16)) >> 16) >= 2) { + /* AST2600-A2/A3 */ + hw = clk_hw_register_divider_table(dev, "sd_extclk", "sd_extclk_gate", + 0, scu_g6_base + ASPEED_G6_CLK_SELECTION4, 28, 3, 0, + ast2600_sd_div_a2_table, + &aspeed_g6_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + } else { + /* AST2600-A1 */ + hw = clk_hw_register_divider_table(dev, "sd_extclk", "sd_extclk_gate", + 0, scu_g6_base + ASPEED_G6_CLK_SELECTION4, 28, 3, 0, + ast2600_sd_div_a1_table, + &aspeed_g6_clk_lock); + if (IS_ERR(hw)) + return PTR_ERR(hw); + } aspeed_g6_clk_data->hws[ASPEED_CLK_SDIO] = hw; /* MAC1/2 RMII 50MHz RCLK */ -- 2.17.1