From patchwork Wed Nov 14 22:57:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10683343 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 08F8614DB for ; Wed, 14 Nov 2018 22:59:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDCC82BFF3 for ; Wed, 14 Nov 2018 22:59:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E21692BFF8; Wed, 14 Nov 2018 22:59:02 +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 6CCC92BFF3 for ; Wed, 14 Nov 2018 22:59:02 +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=D3nU8j96KmD2/n5p59AwvjkBXAGd1iqk9xxC9HbNMZI=; b=Wgu5oZfoCvbQwz reePdIlXTiUn4u2S0Pxrd67z4qRHNKP4Mvj6p8z5UeOonaA7KkEi/GWmSA/DKlqjZW/ZRN+6HZX6H TkUpYETuBPRhxf2E4zIl0xDwZArawZMdmrB2TjyEmRgJXHH/T8bu8ORi8G8CvKPLFpF5qy9BFXgdf VW7GK1GqMxOnppfK4pKGYXkLXuP4wInXhuzG2XUJdcMokpqJMLCGhHDFPNP0ZtoSERIvjm4e7MP0B gaCltS59SrrDhfrb++Me+neDSt4aLBGTLRLkEAFM25VL2Hz7u2KgUPJqQ4S6a2eyMdhcgCJ2fVQSW hYZJ9Gd1lmkQ1FpGGGFA==; 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 1gN47e-0000lG-Ob; Wed, 14 Nov 2018 22:58:58 +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 1gN46l-00087p-Nj; Wed, 14 Nov 2018 22:58:06 +0000 Received: by mail-wr1-x443.google.com with SMTP id z13-v6so19105736wrs.3; Wed, 14 Nov 2018 14:57:53 -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=mqeqV0l+4ciF5RTVW9joEtdlIbRSvfaFdjva14ByRQM=; b=IbCQFyyVdMVMgwlkpg4LyGdG9lmHPNKlQgYIcye4QYFBer6s2lRBkfJvs6qwqZppJj 62Qik7Lp8EqPJWqlpMEVzISczyfQbEuoNn7Bzhw7qjFD+7nk5K9BtJGG5po/O90z/Bep jZB0inDrIGa2tfHvXFruKc5rv339jmI2LMRV6W/QOrJ5L+pgAFe1RIYlK0uD/UZOd0xw kzrMCdye9eL0Ou1Y0XIM5Q//FZuUVWG41wuCpBrZwW8Sg87sfjKmpfwBqqzJiPSd9lt4 4krMyKYLfODfnlGmj1vptcVe7x7MGEsKlRKIcnMfslVzqK7Zj5WVvn7u/6bllF191Egx 1n5Q== 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=mqeqV0l+4ciF5RTVW9joEtdlIbRSvfaFdjva14ByRQM=; b=W8kEHsCLbj5QOhFK6hHLWmXBaP9havqb4RRzvnkqOaG7/PUyC6y4s3ebng27ZW6/Ww FdAjzt+w+7u0AIIICWlMKWCok6tJVD+JBRMrYUuGfvzY5/8/jzPW/StjCfux5p0wVQgF OXbJR2m/juQp4evxz+/MKf8RdfVh71e7YZrd68O1cUv7Vi6k9hSOgcVKogvCpmP0w90N 9gzmhZJPw/LCuTOvZ8gC4iRDTHFUeBp9l+sYYJTB1ghRn1vOdZmOnlb59KVyT3AnYxfQ blesLGzknh0vy7mLEcRhtpNDAqyC0a2ULzwtjdTfryQxIPzBR1sfMroLm82oCu4eNZ+O vSag== X-Gm-Message-State: AGRZ1gKE0YI+ab5DBIcre22nnV23MWKi0qjbvhiL8tD8u/qLQGopD74J 3W3oIwn450m1fdJL2JJ2oYOwixQs X-Google-Smtp-Source: AJdET5djTpjBY0KV3FDCcu2Viy0gYHjlh01ToHzIDSeMfzz24L1fdUVBnwr1RLhfhYimgYG7mh+3tQ== X-Received: by 2002:a5d:48cc:: with SMTP id p12-v6mr3773836wrs.122.1542236271637; Wed, 14 Nov 2018 14:57:51 -0800 (PST) Received: from blackbox.darklights.net (p200300DCD717A100301AB549B11D5ACB.dip0.t-ipconnect.de. [2003:dc:d717:a100:301a:b549:b11d:5acb]) by smtp.googlemail.com with ESMTPSA id n7-v6sm18987784wrt.60.2018.11.14.14.57.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 14:57:51 -0800 (PST) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org, jbrunet@baylibre.com, narmstrong@baylibre.com Subject: [RFC v1 1/7] clk: meson: meson8b: run from the XTAL when changing the CPU frequency Date: Wed, 14 Nov 2018 23:57:19 +0100 Message-Id: <20181114225725.2821-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181114225725.2821-1-martin.blumenstingl@googlemail.com> References: <20181114225725.2821-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-20181114_145803_772325_7EE55923 X-CRM114-Status: GOOD ( 15.00 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=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 9bd5920da0ff..40e77fe4ba7c 100644 --- a/drivers/clk/meson/meson8b.c +++ b/drivers/clk/meson/meson8b.c @@ -1103,6 +1103,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, @@ -1112,6 +1159,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; @@ -1166,6 +1215,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)