Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp2616499pxb; Sun, 17 Oct 2021 20:37:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzttPZucF6UwKtHEolWcE3I4G1bEZohnoAThs04XekhBaC+b26Xh280YrUF+sZmZRCtrs2o X-Received: by 2002:a17:90b:23c8:: with SMTP id md8mr45307134pjb.210.1634528242400; Sun, 17 Oct 2021 20:37:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634528242; cv=none; d=google.com; s=arc-20160816; b=mfK8XoHiHCn4ezWV2NCoJtsZTtalBuvpCBo6Iq8RUz4oIXB7f6ki6lVmjfFAbnUbsu eqOi6WNFfsH8tx2T0DJQPEoSi2hjprdsPFPWFEIMQHmvH+KD2Ddrq7LqC7lsejdUUC0L EW8yiVQjnvO4ST/wc9Fd2gF4rG4JqmPUIPYQX7LDv5l+86eYdLPMgzA9O2ZuHpmbEvIn 4cg2fkCtETPdyrkkrdEv3STfQlZ8u2lYzMBVAgI7K35O9w13Y6zXcJVCgGSwewvCOl+j Gm8GGxizxWLqWMiggdaMAN4eolZLupwgvxFuEirZ5ohu2GTEowzDefL4JaAKYxFcrB4e xh+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=KqnMuFpgSADQq8LPQeZiTx5HVHbVDQMXAFWHZfFF9ZU=; b=iMBUX2EJZNvKxwyI1Y4ciZeE9HTZLicHEKqXEMVvM6HAW23E++jnJqVpGcWTibbwiv 2TJ/phd6V9JvvACJO5PF8rtebcIhIrLZnR+QR6zvLV8LGYaW1aaHgredNdcL//su59Vu HwhVNKxfjewRt5UMW+u5lShUaSAe1FZ/fokHazxY4izUtwjvCIRysq1rwtjLKgQjkV66 G4Oa15K+QVkNyLSDyAnabMC71xd5GFfxJz12kbunbiHta0mXiMs9SUcB5hMbXU9uLKT8 MKOZSEXK+geyddnvMirD92scSIaeF74RNPu/iNk0Sv13efo8ExHcsmDKJ08xLtIxYZSR gcDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@googlemail.com header.s=20210112 header.b="fk6S2/0U"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 2si15783886pll.120.2021.10.17.20.37.10; Sun, 17 Oct 2021 20:37:22 -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; dkim=pass header.i=@googlemail.com header.s=20210112 header.b="fk6S2/0U"; 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; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236959AbhJPPCY (ORCPT + 98 others); Sat, 16 Oct 2021 11:02:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234554AbhJPPCQ (ORCPT ); Sat, 16 Oct 2021 11:02:16 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC85EC061570; Sat, 16 Oct 2021 08:00:07 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id y3so31885051wrl.1; Sat, 16 Oct 2021 08:00:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KqnMuFpgSADQq8LPQeZiTx5HVHbVDQMXAFWHZfFF9ZU=; b=fk6S2/0U84Ed4T3ZK/U92G/9b6uIOmZ9WS6lCYyMAtTq4M0vSHh9GNLEAUbEW7U+ut dmoc70mZ9dAiuHQxKj+Ohy+JyJrvjaCoG5U81nEO0KU4nlovcjYIx84N6gjx3qWS+RK5 cfkulnmvbTqh8Por5CFHoNGRwib+wNlFZAED4KW4hLJUPd6b/Tbd9jmYXbiIdK4viFXp /bOd2d91jI2KKnJT4G3YAmYlMqw/UCooyVr2id8UR+H9fqbCGLm6a8ATt3jt/hu62yDi 9g0gT8LfkchWkMVlLKUWQ2CzzRM+TmiimAxB2ufhzGgTitD/VpINbAwCCz3MD8N69L/O ru8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=KqnMuFpgSADQq8LPQeZiTx5HVHbVDQMXAFWHZfFF9ZU=; b=BV2NJY0gUPdUxmH1mBr5b+CnEh+8Xix3kTyvOFIjcaFVcRn1IXHaYCcN09aRRjHywP xeYiAyhpA3nungPPzMKh2QYUaPSfP0TnuGauHBsANK04NlG6X7H1uK+6yC5zUIVi2mem K6BPO0TFXciBGzVCgmSEOpFK9iFRUWSANxo2WFohKLxZwwsUxHFxxe1INzDNhRmLCvEd H/NVBz0npPMpNZ9zUP9iK/YfOvhxpMRTlWu/oSqqYOovL9V5J3GH3heZvXj3SbLvGib2 FoeUHrdx5qNB6QVVKUSDMnJllfjqj3wHhXLAOVukiAtK9pVp359otYzhACdXax/LPJB+ xEGQ== X-Gm-Message-State: AOAM5328o97n5P8S+E92AD3CKvsGR2Q5g4zb+7IY/tZeGC9X47dPaB8s v2rrMthpUGBYHUIZasHWqt2EZxzzxAY= X-Received: by 2002:a5d:6982:: with SMTP id g2mr22269558wru.51.1634396406342; Sat, 16 Oct 2021 08:00:06 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a01-0c22-7b82-9800-f22f-74ff-fe21-0725.c22.pool.telefonica.de. [2a01:c22:7b82:9800:f22f:74ff:fe21:725]) by smtp.googlemail.com with ESMTPSA id k17sm13543280wmj.0.2021.10.16.08.00.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 16 Oct 2021 08:00:05 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, jbrunet@baylibre.com Cc: narmstrong@baylibre.com, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Martin Blumenstingl , Christian Hewitt Subject: [PATCH] clk: meson: gxbb: Add the spread spectrum bit for MPLL0 on GXBB Date: Sat, 16 Oct 2021 16:59:39 +0200 Message-Id: <20211016145939.15643-1-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christian reports that 48kHz audio does not work on his WeTek Play 2 (which uses a GXBB SoC), while 44.1kHz audio works fine on the same board. He also reports that 48kHz audio works on GXL and GXM SoCs, which are using an (almost) identical AIU (audio controller). Experimenting has shown that MPLL0 is causing this problem. In the .dts we have by default: assigned-clocks = <&clkc CLKID_MPLL0>, <&clkc CLKID_MPLL1>, <&clkc CLKID_MPLL2>; assigned-clock-rates = <294912000>, <270950400>, <393216000>; The MPLL0 rate is divisible by 48kHz without remainder and the MPLL1 rate is divisible by 44.1kHz without remainder. Swapping these two clock rates "fixes" 48kHz audio but breaks 44.1kHz audio. Everything looks normal when looking at the info provided by the common clock framework while playing 48kHz audio (via I2S with mclk-fs = 256): mpll_prediv 1 1 0 2000000000 mpll0_div 1 1 0 294909641 mpll0 1 1 0 294909641 cts_amclk_sel 1 1 0 294909641 cts_amclk_div 1 1 0 12287902 cts_amclk 1 1 0 12287902 meson-clk-msr however shows that the actual MPLL0 clock is off by more than 38MHz: mp0_out 333322917 +/-10416Hz The 3.14 vendor kernel uses the following code to enable SSEN only for MPLL0 (where con_reg2 is HHI_MPLL_CNTL and SSEN_shift is 25): if (strncmp(hw->clk->name, "mpll_clk_out0", 13) == 0) { val = readl(mpll->con_reg2); val |= 1 << mpll->SSEN_shift; writel(val, mpll->con_reg2); } Add the SSEN (spread spectrum enable) bit and add the CLK_MESON_MPLL_SPREAD_SPECTRUM flag to enable this bit for MPLL0. Do this for GXBB *only* since GXL doesn't seem to care if this bit is set or not, meaning that meson-clk-msr always sees (approximately) the same frequency as common clock framework. Fixes: 8925dbd03bb29b ("clk: meson: gxbb: no spread spectrum on mpll") Reported-by: Christian Hewitt Signed-off-by: Martin Blumenstingl --- drivers/clk/meson/gxbb.c | 50 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/drivers/clk/meson/gxbb.c b/drivers/clk/meson/gxbb.c index d6eed760327d..673bc915c7d9 100644 --- a/drivers/clk/meson/gxbb.c +++ b/drivers/clk/meson/gxbb.c @@ -713,6 +713,41 @@ static struct clk_regmap gxbb_mpll_prediv = { }; static struct clk_regmap gxbb_mpll0_div = { + .data = &(struct meson_clk_mpll_data){ + .sdm = { + .reg_off = HHI_MPLL_CNTL7, + .shift = 0, + .width = 14, + }, + .sdm_en = { + .reg_off = HHI_MPLL_CNTL7, + .shift = 15, + .width = 1, + }, + .n2 = { + .reg_off = HHI_MPLL_CNTL7, + .shift = 16, + .width = 9, + }, + .ssen = { + .reg_off = HHI_MPLL_CNTL, + .shift = 25, + .width = 1, + }, + .flags = CLK_MESON_MPLL_SPREAD_SPECTRUM, + .lock = &meson_clk_lock, + }, + .hw.init = &(struct clk_init_data){ + .name = "mpll0_div", + .ops = &meson_clk_mpll_ops, + .parent_hws = (const struct clk_hw *[]) { + &gxbb_mpll_prediv.hw + }, + .num_parents = 1, + }, +}; + +static struct clk_regmap gxl_mpll0_div = { .data = &(struct meson_clk_mpll_data){ .sdm = { .reg_off = HHI_MPLL_CNTL7, @@ -749,7 +784,16 @@ static struct clk_regmap gxbb_mpll0 = { .hw.init = &(struct clk_init_data){ .name = "mpll0", .ops = &clk_regmap_gate_ops, - .parent_hws = (const struct clk_hw *[]) { &gxbb_mpll0_div.hw }, + .parent_data = &(const struct clk_parent_data) { + /* + * Note: + * GXL and GXBB have different SSEN requirements. We + * fallback to the global naming string mechanism so + * mpll0_div picks up the appropriate one. + */ + .name = "mpll0_div", + .index = -1, + }, .num_parents = 1, .flags = CLK_SET_RATE_PARENT, }, @@ -3044,7 +3088,7 @@ static struct clk_hw_onecell_data gxl_hw_onecell_data = { [CLKID_VAPB_1] = &gxbb_vapb_1.hw, [CLKID_VAPB_SEL] = &gxbb_vapb_sel.hw, [CLKID_VAPB] = &gxbb_vapb.hw, - [CLKID_MPLL0_DIV] = &gxbb_mpll0_div.hw, + [CLKID_MPLL0_DIV] = &gxl_mpll0_div.hw, [CLKID_MPLL1_DIV] = &gxbb_mpll1_div.hw, [CLKID_MPLL2_DIV] = &gxbb_mpll2_div.hw, [CLKID_MPLL_PREDIV] = &gxbb_mpll_prediv.hw, @@ -3439,7 +3483,7 @@ static struct clk_regmap *const gxl_clk_regmaps[] = { &gxbb_mpll0, &gxbb_mpll1, &gxbb_mpll2, - &gxbb_mpll0_div, + &gxl_mpll0_div, &gxbb_mpll1_div, &gxbb_mpll2_div, &gxbb_cts_amclk_div, -- 2.33.1