From patchwork Sat Apr 1 13:10:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 9657843 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E0CC360349 for ; Sat, 1 Apr 2017 13:10:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C30372852B for ; Sat, 1 Apr 2017 13:10:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B7B712857C; Sat, 1 Apr 2017 13:10:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3936B2852B for ; Sat, 1 Apr 2017 13:10:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751395AbdDANKL (ORCPT ); Sat, 1 Apr 2017 09:10:11 -0400 Received: from mail-wr0-f195.google.com ([209.85.128.195]:35546 "EHLO mail-wr0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751359AbdDANKK (ORCPT ); Sat, 1 Apr 2017 09:10:10 -0400 Received: by mail-wr0-f195.google.com with SMTP id p52so23989901wrc.2 for ; Sat, 01 Apr 2017 06:10:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JoTHcKk2KJ2OJw2CDKPrORDvDbirOlse3ozWk4JrUyk=; b=ZbNOIn5kW0gRHUeCQHcZOE8To3Md6+cX46ZLRAJbUpkoCzQ4d7hH2tUh/foe0HeZfz B95FBfQEYRET70R1Lh139zU6BUU+Z01q0vx5BWjhiLYFNIA5gXzHHEfbCqJLokw/Qk5e 9RWleGb+Nafm5tpv6zZRZqYn5NY567hb/f4kwEyh2kqv6HEa2yEjZH/CPruqGz+eQ31S amF6dZLGbsCLAdPjDU26HWxcno9DbF6GADbnSNP7IiTAT+Iw2qKfG8vYY9CTKWIcddBf /AUBWIyETa0O7RHSCqmcbxYhbSvgrEB10qUxAfHsDqsK9JhLDGGHq0XQlRUanKsk/Yeo /pNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JoTHcKk2KJ2OJw2CDKPrORDvDbirOlse3ozWk4JrUyk=; b=Ym0bmP0BLdSazD+pyfKPUuD7bmtx4Ujm5xlh9nK0FXfInXtaMmEBbYE4qOtp4wFBYE bgNOoLseA+a9PgmXfVFc2HdtTg3yM6eFeONIyKrGdAviyAfLo2rLdUQnT3AM2AYHSpxu wx2DjosA8HfeRttjdqz/YRDuulkWdN6RuzJBRj5XkL+sDXh3AKabtMM9riHFF76IT+oO xfJT3WhgQGfk9gnp+4MV/q4TEXYOegN0/GWG4PvaanbuGuKmQpjlOfenlPSuC8KLswxG S1ukB+EvdqmqUJ9QVcts+8B8QKY0pDMWtkOYZzAhYHrIgp+LqPtVnUpfbXlUyjOL2IT1 HkwQ== X-Gm-Message-State: AFeK/H3UZO7yHUz2lg5/puJLwwYD7vmF6pt5WZE5fB7rtCAy5XZFKst1Ny3la/8HNVQwMw== X-Received: by 10.223.133.204 with SMTP id 12mr7943436wru.0.1491052208727; Sat, 01 Apr 2017 06:10:08 -0700 (PDT) Received: from blackbox.darklights.net (p5DE38642.dip0.t-ipconnect.de. [93.227.134.66]) by smtp.googlemail.com with ESMTPSA id x133sm6697745wme.22.2017.04.01.06.10.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Apr 2017 06:10:07 -0700 (PDT) From: Martin Blumenstingl To: mturquette@baylibre.com, sboyd@codeaurora.org, jbrunet@baylibre.com, linux-clk@vger.kernel.org, linux-amlogic@lists.infradead.org, narmstrong@baylibre.com Cc: carlo@caione.org, khilman@baylibre.com, linux-arm-kernel@lists.infradead.org, Martin Blumenstingl Subject: [PATCH 1/1] clk: meson: meson8b: add support for the NAND clocks Date: Sat, 1 Apr 2017 15:10:01 +0200 Message-Id: <20170401131001.9988-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.12.1 In-Reply-To: <20170401131001.9988-1-martin.blumenstingl@googlemail.com> References: <20170401131001.9988-1-martin.blumenstingl@googlemail.com> Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This adds the NAND clocks (from the HHI_NAND_CLK_CNTL register) to the Meson8b clock driver. There are three NAND clocks: a gate which enables or disables the NAND clock, a mux and a divider (which divides the mux output). Unfortunately the public S805 datasheet does not document the mux parents. However, the vendor kernel has a few hints for us which allows us to make an educated guess about the clock parents. To do this we need to have a look at set_nand_core_clk() from the vendor's NAND driver (see [0]): - XTAL = (4<<9) | (1<<8) | 0 - 160MHz = (0<<9) | (1<<8) | 3) - 182MHz = (3<<9) | (1<<8) | 1) - 212MHz = (1<<9) | (1<<8) | 3) - 255MHz = (2<<9) | (1<<8) | 1) While there is a comment for the XTAL parent (which indicates that it should only be used for debugging) we have to do a bit of math for the other parents: target_freq * divider = rate of parent clock Bit 8 above is the enable bit, so we can ignore it here. Bits 11:9 are the mux index and bits 6:0 are the 0-based divider (so we need to add 1). This gives us: - mux 0 (160MHz * 4) = fclk_div4 (actual rate = 637.5MHz, off by 2.5MHz) - mux 1 (212MHz * 4) = fclk_div3 (actual rate = 850MHz, off by 2MHz) - mux 2 (255MHz * 2) = fclk_div5 (matches exactly 510MHz) - mux 3 (182MHz * 2) = fclk_div7 (actual rate = 346.3MHz, off by 0.3MHz) [0] https://github.com/khadas/linux/blob/9587681285cb/drivers/amlogic/amlnf/dev/amlnf_ctrl.c#L314 Signed-off-by: Martin Blumenstingl --- drivers/clk/meson/meson8b.c | 53 +++++++++++++++++++++++++++++++++++++++++++++ drivers/clk/meson/meson8b.h | 6 ++++- 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c index e9985503165c..b7f3cf8ed386 100644 --- a/drivers/clk/meson/meson8b.c +++ b/drivers/clk/meson/meson8b.c @@ -403,6 +403,53 @@ struct clk_gate meson8b_clk81 = { }, }; +static u32 mux_table_nand[] = { 0, 1, 2, 3, 4 }; + +struct clk_mux meson8b_nand_clk_sel = { + .reg = (void *)HHI_NAND_CLK_CNTL, + .mask = 0x7, + .shift = 9, + .table = mux_table_nand, + .flags = CLK_MUX_ROUND_CLOSEST, + .lock = &clk_lock, + .hw.init = &(struct clk_init_data){ + .name = "nand_clk_sel", + .ops = &clk_mux_ops, + /* FIXME all other parents are unknown: */ + .parent_names = (const char *[]){ "fclk_div4", "fclk_div3", + "fclk_div5", "fclk_div7", "xtal" }, + .num_parents = 5, + .flags = CLK_SET_RATE_NO_REPARENT, + }, +}; + +struct clk_divider meson8b_nand_clk_div = { + .reg = (void *)HHI_NAND_CLK_CNTL, + .shift = 0, + .width = 6, + .flags = CLK_DIVIDER_ROUND_CLOSEST, + .lock = &clk_lock, + .hw.init = &(struct clk_init_data){ + .name = "nand_clk_div", + .ops = &clk_divider_ops, + .parent_names = (const char *[]){ "nand_clk_sel" }, + .num_parents = 1, + }, +}; + +struct clk_gate meson8b_nand_clk_gate = { + .reg = (void *)HHI_NAND_CLK_CNTL, + .bit_idx = 8, + .lock = &clk_lock, + .hw.init = &(struct clk_init_data){ + .name = "nand_clk_gate", + .ops = &clk_gate_ops, + .parent_names = (const char *[]){ "nand_clk_div" }, + .num_parents = 1, + .flags = CLK_SET_RATE_PARENT, + }, +}; + /* Everything Else (EE) domain gates */ static MESON_GATE(meson8b_ddr, HHI_GCLK_MPEG0, 0); @@ -584,6 +631,9 @@ static struct clk_hw_onecell_data meson8b_hw_onecell_data = { [CLKID_MPLL0] = &meson8b_mpll0.hw, [CLKID_MPLL1] = &meson8b_mpll1.hw, [CLKID_MPLL2] = &meson8b_mpll2.hw, + [CLKID_NAND_SEL] = &meson8b_nand_clk_sel.hw, + [CLKID_NAND_DIV] = &meson8b_nand_clk_div.hw, + [CLKID_NAND_CLK] = &meson8b_nand_clk_gate.hw, }, .num = CLK_NR_CLKS, }; @@ -679,14 +729,17 @@ static struct clk_gate *const meson8b_clk_gates[] = { &meson8b_ao_ahb_sram, &meson8b_ao_ahb_bus, &meson8b_ao_iface, + &meson8b_nand_clk_gate, }; static struct clk_mux *const meson8b_clk_muxes[] = { &meson8b_mpeg_clk_sel, + &meson8b_nand_clk_sel, }; static struct clk_divider *const meson8b_clk_dividers[] = { &meson8b_mpeg_clk_div, + &meson8b_nand_clk_div, }; static int meson8b_clkc_probe(struct platform_device *pdev) diff --git a/drivers/clk/meson/meson8b.h b/drivers/clk/meson/meson8b.h index 3881defc8644..cbb8001b5fe8 100644 --- a/drivers/clk/meson/meson8b.h +++ b/drivers/clk/meson/meson8b.h @@ -37,6 +37,7 @@ #define HHI_GCLK_AO 0x154 /* 0x55 offset in data sheet */ #define HHI_SYS_CPU_CLK_CNTL1 0x15c /* 0x57 offset in data sheet */ #define HHI_MPEG_CLK_CNTL 0x174 /* 0x5d offset in data sheet */ +#define HHI_NAND_CLK_CNTL 0x25c /* 0x97 offset in data sheet */ #define HHI_MPLL_CNTL 0x280 /* 0xa0 offset in data sheet */ #define HHI_SYS_PLL_CNTL 0x300 /* 0xc0 offset in data sheet */ #define HHI_VID_PLL_CNTL 0x320 /* 0xc8 offset in data sheet */ @@ -160,8 +161,11 @@ #define CLKID_MPLL0 93 #define CLKID_MPLL1 94 #define CLKID_MPLL2 95 +#define CLKID_NAND_SEL 96 +#define CLKID_NAND_DIV 97 +#define CLKID_NAND_CLK 98 -#define CLK_NR_CLKS 96 +#define CLK_NR_CLKS 99 /* include the CLKIDs that have been made part of the stable DT binding */ #include