From patchwork Thu Nov 15 22:40:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10685209 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D79B14DB for ; Thu, 15 Nov 2018 22:43:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F5C92D591 for ; Thu, 15 Nov 2018 22:43:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 239602D583; Thu, 15 Nov 2018 22:43:07 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 9B3782D578 for ; Thu, 15 Nov 2018 22:43:06 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=5jSSiga2ukv+9WxwM08oRxsdPf4jdy0N3/gsb+6GM3o=; b=bD0zhdSR/X4+g/ /coh76CQUBWlBQM/OJJz+uOlehrZ9PoNunSadqvY4SqC9fwsjrSUfwM7bLrSa+v4MK5zkL13AcqIm 6QBtxvT8/I0geYfF8dBXuD32k4zaMRnqoR6jZd5Q4o4y/XEC5TRRNZoQeAtd3VhKPBfkL5c6GTpCQ lRUwouHd+yE5kfmlKs/7/FNlG2g9h7gKfTzsSgBol9ct1QGdVtWoOMxiMBRUR6IuzY0OaSvoE5l41 1/oVH4/jXKU6iCf71jZhVRwHWeWvhaJk6FAXDL5FWcrApOttA5DR7JradCn+IIp/swQFAG3xsaJUh KP0DxmbK3VS/cp7Cu7RA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNQLn-0002x0-6M; Thu, 15 Nov 2018 22:43:03 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gNQKL-0001Os-Gb; Thu, 15 Nov 2018 22:41:35 +0000 Received: by mail-wr1-x443.google.com with SMTP id r10so5373913wrs.10; Thu, 15 Nov 2018 14:41:23 -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 :mime-version:content-transfer-encoding; bh=Ocpvr4v/IalymL6Cfmgpy4xn0IPt/TDny70HjBkIVnQ=; b=getxhgJC6hg+ji7gWowQYLqG6ApfFgAi5irT4hgOttWDJ2K5Ue43mcY6Q4+G4Mn0Gz dNqRkvnKtHZLfN67jsl4daQMygYdeuJNohCyMd+vTKUwaWkahzV+PXoHQd7qcN22P3uz 4rgdFgcYmqL3FRBd+HqWgFSojTa8Ldkp+Ec4kNXIJiP8HY3Oc5OXmnDgL7YGAcXCQygO i081ts666V//8taGxtWTWjElOlF0eGUkcSwpnk8mc3NAmtoMHkqyC2yEEKzuAbefHt28 hVRyvdasfqbqPmczYQPZ3SCAHufoaDMN95IYMEVk80MHs7UIvhWyWlcR8UWIul+v9kWa 10VA== 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:mime-version:content-transfer-encoding; bh=Ocpvr4v/IalymL6Cfmgpy4xn0IPt/TDny70HjBkIVnQ=; b=YDpLobw0Ja+MZerRN91Lj9fsyDsYk1D+aiN0vfXoOOcHtuC6KYzYo9giAFc7vDWH/j yDv8PHr4//vbPGskc0pmm6LaC3Tpor70Dl/LRSFUL/90yX4NM3QA9ksWz7qtgDdzYQCT nveZzgfTjlAGUrWv4X3j0OMe/YSkFchPxDORyXoxi3sHhNxnh2YWUwC9CosXZBr56Nyn fce54ku9mG0qZAKg1FzYyB8KYcpEpSuihLOeSarrmDGwg+T1j3hGHmbkZbmWd5P3nNHy wMELyLfQAfzARei+svgi86fmX+Fzoj7t+bWwcE9zdDiq4MLUQhL7LKwkW7JiID1wPVXZ itEw== X-Gm-Message-State: AGRZ1gK+1H5k2LTBUO2YCA0k/drnSBSSlmb4zQ5pgKo7avJ0ukWE31JO 1ZLr2dZJjp1G74YF3wS6PbTysXqT X-Google-Smtp-Source: AJdET5eIxNcbjlEsDJBwlBm8xGH49dS6nqNXq9wH7vfwUtUr9BuKp18Y1KLrN0CrQmMIX3O5E8P1Lg== X-Received: by 2002:a5d:5745:: with SMTP id q5-v6mr7165566wrw.161.1542321681386; Thu, 15 Nov 2018 14:41:21 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD717A100B85ACE585A885C51.dip0.t-ipconnect.de. [2003:dc:d717:a100:b85a:ce58:5a88:5c51]) by smtp.googlemail.com with ESMTPSA id x12sm2076388wmc.37.2018.11.15.14.41.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Nov 2018 14:41:20 -0800 (PST) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, jbrunet@baylibre.com, narmstrong@baylibre.com Subject: [PATCH v2 5/6] clk: meson: meson8b: run from the XTAL when changing the CPU frequency Date: Thu, 15 Nov 2018 23:40:47 +0100 Message-Id: <20181115224048.13511-6-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181115224048.13511-1-martin.blumenstingl@googlemail.com> References: <20181115224048.13511-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181115_144133_551947_AB2ADE79 X-CRM114-Status: GOOD ( 15.65 ) 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: sboyd@kernel.org, Martin Blumenstingl , mturquette@baylibre.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-amlogic" Errors-To: linux-amlogic-bounces+patchwork-linux-amlogic=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Changing the CPU clock requires changing various clocks including the SYS PLL. The existing meson clk-pll and clk-regmap drivers can change all of the relevant clocks already. However, changing for exampe the SYS PLL is problematic because as long as the CPU is running off a clock derived from SYS PLL changing the latter results in a full system lockup. Fix this system lockup by switching the CPU clock to run off the XTAL while we are changing the any of the clocks in the CPU clock tree. Signed-off-by: Martin Blumenstingl Reviewed-by: Jerome Brunet --- drivers/clk/meson/meson8b.c | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c index b07a92ed7de3..c06a1a7faa4c 100644 --- a/drivers/clk/meson/meson8b.c +++ b/drivers/clk/meson/meson8b.c @@ -1116,6 +1116,53 @@ static const struct reset_control_ops meson8b_clk_reset_ops = { .deassert = meson8b_clk_reset_deassert, }; +struct meson8b_nb_data { + struct notifier_block nb; + struct clk_hw_onecell_data *onecell_data; +}; + +static int meson8b_cpu_clk_notifier_cb(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct meson8b_nb_data *nb_data = + container_of(nb, struct meson8b_nb_data, nb); + struct clk_hw **hws = nb_data->onecell_data->hws; + struct clk_hw *cpu_clk_hw, *parent_clk_hw; + struct clk *cpu_clk, *parent_clk; + int ret; + + switch (event) { + case PRE_RATE_CHANGE: + parent_clk_hw = hws[CLKID_XTAL]; + break; + + case POST_RATE_CHANGE: + parent_clk_hw = hws[CLKID_CPU_SCALE_OUT_SEL]; + break; + + default: + return NOTIFY_DONE; + } + + cpu_clk_hw = hws[CLKID_CPUCLK]; + cpu_clk = __clk_lookup(clk_hw_get_name(cpu_clk_hw)); + + parent_clk = __clk_lookup(clk_hw_get_name(parent_clk_hw)); + + ret = clk_set_parent(cpu_clk, parent_clk); + if (ret) + return notifier_from_errno(ret); + + udelay(100); + + return NOTIFY_OK; +} + +static struct meson8b_nb_data meson8b_cpu_nb_data = { + .nb.notifier_call = meson8b_cpu_clk_notifier_cb, + .onecell_data = &meson8b_hw_onecell_data, +}; + static const struct regmap_config clkc_regmap_config = { .reg_bits = 32, .val_bits = 32, @@ -1125,6 +1172,8 @@ static const struct regmap_config clkc_regmap_config = { static void __init meson8b_clkc_init(struct device_node *np) { struct meson8b_clk_reset *rstc; + const char *notifier_clk_name; + struct clk *notifier_clk; void __iomem *clk_base; struct regmap *map; int i, ret; @@ -1179,6 +1228,20 @@ static void __init meson8b_clkc_init(struct device_node *np) return; } + /* + * FIXME we shouldn't program the muxes in notifier handlers. The + * tricky programming sequence will be handled by the forthcoming + * coordinated clock rates mechanism once that feature is released. + */ + notifier_clk_name = clk_hw_get_name(&meson8b_cpu_scale_out_sel.hw); + notifier_clk = __clk_lookup(notifier_clk_name); + ret = clk_notifier_register(notifier_clk, &meson8b_cpu_nb_data.nb); + if (ret) { + pr_err("%s: failed to register the CPU clock notifier\n", + __func__); + return; + } + ret = of_clk_add_hw_provider(np, of_clk_hw_onecell_get, &meson8b_hw_onecell_data); if (ret)