From patchwork Mon Jan 1 21:01:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10139591 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 AE31E603B4 for ; Mon, 1 Jan 2018 21:02:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9F2D428639 for ; Mon, 1 Jan 2018 21:02:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 93C4928647; Mon, 1 Jan 2018 21:02:21 +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=-4.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, DKIM_VALID, FREEMAIL_FROM, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0F0EE28639 for ; Mon, 1 Jan 2018 21:02:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=UpoKQ498ug4Yu6uF1KrmehBY+waIIlBaVhxSTbcxa30=; b=TT7BAxdwgfs+5MV28xNKexJ5QQ kM38dCN92uj7KodhcMy2FDWREldjES7NV9bIVzcban8K+o5BxAyKWJlGo/Ruzxl61N4iIhj2L0sms CQCBRbHjHIWy1Y5iqtKQdl1G+WGQ2v3Gb0YJaN5SC88fKtuu+J/U1AL5plq2mRBS4VbITyQb/HOFf iqBcnnvYY41dI7cW+499/vZDh7uR4GCsKoU1RflT6Q1AYBWxNPa9+sOWHsFAMMH3LefiTvoas61Bu tRpvP7I2TMjDSvbjQeUk9rryabrPGSITlko8uJgwUYzdoy6Jw9m+DSYUFC9Jn5c4ElNlnFCD9jrSs akVmLOZQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1eW7Dl-0002SZ-Q4; Mon, 01 Jan 2018 21:02:09 +0000 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eW7Dg-0002Qj-I1 for linux-amlogic@lists.infradead.org; Mon, 01 Jan 2018 21:02:06 +0000 Received: by mail-wm0-x244.google.com with SMTP id n138so58430692wmg.2 for ; Mon, 01 Jan 2018 13:01:55 -0800 (PST) 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=XSwntE/xkb7jj2BNbIYxime8ncv8o+oxz/esTMS1aj4=; b=AfJvE/PAw7B14kXRbSZrAx/qgvg3WtwXSW2deNoEgOpTpSM/EFm1cJ7IUL63YjL5nJ HCShbd6FM2Nu1mVH3U/BckEGNUC1F8A7zya7+0A7RVbNueDyVZ4Haob1C+tUWH4IqsKr lpSugwS+ovzk9xSUluZCRKWzbTRfdlzGymL97N4a65tIKeWm+7Nli37nZYsV8i0/0POY AY0UDt2GY68sAqpIDqIvzHorHq8ANo/mmhSol5Zuq0xrE3bZmpSEoNmv3G66kABDyGpY Vdm2e9dDu0LhBMjxRJBzWTOm/4a9bA+hibrhwC1F8/jQfbK9KUYnq1HQ9dakncJHvWaz Tu1g== 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=XSwntE/xkb7jj2BNbIYxime8ncv8o+oxz/esTMS1aj4=; b=of/j2WhOdtyUXy+8km+2rpjIkB8iJLs/frmCJUZAzBKTDgpwgD8+qOmRUGnxcSJmla Gb9nkoPtEZGn3mnqhTMm3TweOgHTGfagKYqaoaZlOzPSGGzsRYfSuVunAwNOvb8cH3ph F+aI5ZDbB3gj+YIB9bf+WPFVEg7cFsSkJd3RVeePjG5vCDDI/zYjErRck/d9MS6wLFCD XXrHOOGbQQ22SrQ0fppA/huCB/tCUL+o7b/XU2juNgPXWaSMiDyAwCNtQqoH10dDDgqs O1QzcPtWUsbDjAdhzpdonIYckhylI0PSL8eX+6xhnY25CzlHujtOHv5HGuiOwV0Y0x6o p4ng== X-Gm-Message-State: AKGB3mIdlVkH3iUdWdUA58M4rhU3fJqsCnIoPZRyJjkApNqvoIXmUwA4 i1fQg9cRLQkPcW5Vfpw6X56EutDh X-Google-Smtp-Source: ACJfBoteAWcJ1MXvKxKdHCj0oL/ToSVHcVlkMFD5RtC6Wf3fpgMmyzzX3tCVU4j68Z9JlfZdaz1nkg== X-Received: by 10.28.29.207 with SMTP id d198mr33683255wmd.106.1514840513796; Mon, 01 Jan 2018 13:01:53 -0800 (PST) Received: from blackbox.darklights.net (p5DE386EE.dip0.t-ipconnect.de. [93.227.134.238]) by smtp.googlemail.com with ESMTPSA id l14sm16874890wre.25.2018.01.01.13.01.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 01 Jan 2018 13:01:53 -0800 (PST) From: Martin Blumenstingl To: narmstrong@baylibre.com, jbrunet@baylibre.com, linux-amlogic@lists.infradead.org Subject: [PATCH v2 1/1] clk: meson: meson8b: add support for the NAND clocks Date: Mon, 1 Jan 2018 22:01:39 +0100 Message-Id: <20180101210139.29808-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180101210139.29808-1-martin.blumenstingl@googlemail.com> References: <20180101210139.29808-1-martin.blumenstingl@googlemail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180101_130204_669742_494AB427 X-CRM114-Status: GOOD ( 15.63 ) X-BeenThere: linux-amlogic@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: carlo@caione.org, khilman@baylibre.com, Martin Blumenstingl , linux-clk@vger.kernel.org MIME-Version: 1.0 Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.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 | 51 ++++++++++++++++++++++++++++++++ drivers/clk/meson/meson8b.h | 3 +- include/dt-bindings/clock/meson8b-clkc.h | 3 ++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c index 20ab7190d328..929f6947e679 100644 --- a/drivers/clk/meson/meson8b.c +++ b/drivers/clk/meson/meson8b.c @@ -418,6 +418,51 @@ struct clk_gate meson8b_clk81 = { }, }; +struct clk_mux meson8b_nand_clk_sel = { + .reg = (void *)HHI_NAND_CLK_CNTL, + .mask = 0x7, + .shift = 9, + .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_PARENT, + }, +}; + +struct clk_divider meson8b_nand_clk_div = { + .reg = (void *)HHI_NAND_CLK_CNTL, + .shift = 0, + .width = 7, + .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, + .flags = CLK_SET_RATE_PARENT, + }, +}; + +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); @@ -599,6 +644,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, [CLK_NR_CLKS] = NULL, }, .num = CLK_NR_CLKS, @@ -695,14 +743,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 const struct meson8b_clk_reset_line { diff --git a/drivers/clk/meson/meson8b.h b/drivers/clk/meson/meson8b.h index 2eaf8a52e7dd..87731d3c7e55 100644 --- a/drivers/clk/meson/meson8b.h +++ b/drivers/clk/meson/meson8b.h @@ -40,6 +40,7 @@ #define HHI_VID_CLK_CNTL 0x17c /* 0x5f offset in data sheet */ #define HHI_VID_DIVIDER_CNTL 0x198 /* 0x66 offset in data sheet */ #define HHI_SYS_CPU_CLK_CNTL0 0x19c /* 0x67 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 */ @@ -69,7 +70,7 @@ * will remain defined here. */ -#define CLK_NR_CLKS 96 +#define CLK_NR_CLKS 99 /* * include the CLKID and RESETID that have diff --git a/include/dt-bindings/clock/meson8b-clkc.h b/include/dt-bindings/clock/meson8b-clkc.h index dea9d46d4fa7..aa1a8148c785 100644 --- a/include/dt-bindings/clock/meson8b-clkc.h +++ b/include/dt-bindings/clock/meson8b-clkc.h @@ -102,5 +102,8 @@ #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 #endif /* __MESON8B_CLKC_H */