From patchwork Fri Jul 5 07:19:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Trimarchi X-Patchwork-Id: 3175 Return-Path: X-Original-To: linux-amarula@patchwork.amarulasolutions.com Delivered-To: linux-amarula@patchwork.amarulasolutions.com Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by ganimede.amarulasolutions.com (Postfix) with ESMTPS id 916353F102 for ; Fri, 5 Jul 2024 09:20:04 +0200 (CEST) Received: by mail-ed1-f70.google.com with SMTP id 4fb4d7f45d1cf-58d6fdee657sf1263461a12.2 for ; Fri, 05 Jul 2024 00:20:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1720164004; cv=pass; d=google.com; s=arc-20160816; b=AaBtP8DRT0mZUMnwi8IH9JEmZzK69m2IV/0X5rj4YtZU7q7nC6TZme4kl1pr6Xc+T2 AFNUdARYeS97FPSuIBP4nrwRVNGZJ7lEzhPHlsjYA+S9XMl4H8a3xmirfHiNXD/q59B7 ZdjEkt1cMDMGrCEpWfBTo+fvmfEM7QaGeDGABgasyzrPkf1uAaCrYHzs8hWZeae8A1ip EuxGI48R0g4BZS24b8w5HrJEML4wxbHM1kiNDfqXcEc0ZHvTmnXSNqxR9y+aqJyIIa66 vSDJLp0XH1EVJu3sXTLOyd5SaRPhMc/D5lyfpKFA3dRc97g+qiQlDng9pQF+UhCg1xgI IWIw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=U+KVOt7g13xcJT+xauFcaAJKCUOq3POwPU9v7S+5HWg=; fh=mOdiJs73+91K06dWpw3dU84tzCYoutx+NBH8gRIBBwU=; b=h3AGgpaWtfLMAd/jFkvTOgQ8ET2h7OCXeQYc3wwJ/QP9v2wF2ioRy0NcylDzdAro1N TTh32XEYY2Q/HbErQJBU6QMd6wYj7g0TYqpg+1YOc40FfigN7UGOmzn8p5nTJ3wOVK4C Tc4RlhphgLaCt5qRhkWQ1MWPqUFjNw3LGH4DX3vktDZUeVIVBjJZR4FHA2hT4S7Hxzp1 XtuGBCyn16h3/rubIRMWa+FcEsDA15YNrVQ4VMRKAQzqHTNW6WUCdZzc80qptfViYhA2 xMJaG1QCPos7TwDntrp2JU3GeXy7A921iFTpVgNCvuHwOkzazd+1eh4odh9FJpRCl8bz ZcVA==; darn=patchwork.amarulasolutions.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ud1utqFW; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amarulasolutions.com; s=google; t=1720164004; x=1720768804; darn=patchwork.amarulasolutions.com; h=list-unsubscribe:list-archive:list-help:list-post:list-id :mailing-list:precedence:x-original-authentication-results :x-original-sender:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=U+KVOt7g13xcJT+xauFcaAJKCUOq3POwPU9v7S+5HWg=; b=k/p+8QQxaPuX7Mfvc1Kv7lMDTCf88Kv0K+uErt6RuCeGpoeyuJkMS28Uw+5Dz7qZQu 1sfTpp6MmnGEZvn7u+dTlkA5br3cjULkG3bM8U8vmuD8mH5oDKCRjzykixI4Zwdhcc+L zdzFGhMDMlLeBW+hDk+plvtRm3r0fuWCKweQ8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720164004; x=1720768804; h=list-unsubscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence :x-original-authentication-results:x-original-sender:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :x-beenthere:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U+KVOt7g13xcJT+xauFcaAJKCUOq3POwPU9v7S+5HWg=; b=usdudzzId/uyqxNOBEgrKu5IYGn0JZ0Xo0nV5aH9f0BM+SPFRIQo3lboq0s810Apmf pImQO2VMkAuL1W+oxRSuAkyxLpNaET/eFa9P/zU6kKPvg7fE13hiIA0XPv7sXa1w/RNE 1Avi95Xhql9gwS2LuTvd/5JygeOBtMkKoy8kPkS3v0+CacfXnROh31Dz/2q5kJ0vrMwT fzeo2dKc7U1VYGkME9UBx66iy4z23MUFtS3JEtp35YLAujrvprhlgwOKdmTEvagElRFz Nr2LmA0ef4LnItvBfB6CCHvaE8NgbP/rdau7sL3uCiE+3mufm4OfhYGHozgEnqYhSdYR H7Hg== X-Forwarded-Encrypted: i=2; AJvYcCU958NygvBz0GYYeWeTpN3Pln09Y8jrslatigUQlwmvcmehwSLI/zfcRn7a1SzhfKu4b9dmh1u2pTZ0POWqCrzoHu4dCjvbSXp63UrWTBKSBhdLe+CbrmtcQvm2TA== X-Gm-Message-State: AOJu0YxmvMBkOIXpkCMTeKheAEqaiPZcMT49A8YM+kkTAtK2sQfLOfkJ xgWN83CLjs+f05/KNGP9gHlJe0eW4Wj2BjX8kjrDuYPynTwDgIPGfCMPEwUIXRrQ3tTH/CnQcg= = X-Google-Smtp-Source: AGHT+IEGOHXyd6KPLWHSWXOC/r6uNpAWXcejEvah6epOyp62yFbBuJBagsoVfmACfz6ly+/zzF3Jbg== X-Received: by 2002:a05:6402:2710:b0:58b:8a20:f553 with SMTP id 4fb4d7f45d1cf-58e5a6ee74emr2960351a12.9.1720164004336; Fri, 05 Jul 2024 00:20:04 -0700 (PDT) X-BeenThere: linux-amarula@amarulasolutions.com Received: by 2002:a05:6402:3589:b0:58b:ce37:ebce with SMTP id 4fb4d7f45d1cf-58e249de8b0ls713337a12.1.-pod-prod-03-eu; Fri, 05 Jul 2024 00:20:02 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCXAzvPzv7uR1iHu6sxguMHOEEvZxZubHcH8HAXeaJxEmckBZiJWeBLgJSqjGNGOmkQYP/1EGeS1EHXUvvApgCXy2mP1x+m7A8oRhfHW0h3lV8eg X-Received: by 2002:a17:906:f896:b0:a77:cdaa:88a9 with SMTP id a640c23a62f3a-a77cdaa8a80mr51670766b.6.1720164002448; Fri, 05 Jul 2024 00:20:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720164002; cv=none; d=google.com; s=arc-20160816; b=YwhlQX5ucEr6T2MBiqva9kr4GrrV9UtaFOISBsPJkG31ztEmNRTHf5NoEvQgEPWJIX olY8ce+Gvs/d3yYMzQiSXU8mV2vh5aUr9b/x56SFWUnDXWVGkyg4vLRCCNQmjgfs2/F0 siCto1Zh6im/28MGwE0RK5xjelU0XA4t9Kfy0GDN61qkMvUB6H2MEKoyxYrHuhY1F1zx u3YbbtJ+D+kSL3Uogy1UjEQN0vUYGt46uskF8PV885UwryEDHeoJhUGA1BCXFbrdcoLy r7OlHk1TvH4fOY0qXAllVHrUShh7E0oiKkchzFibjBHzQYWWnAzoKsLQY595RgRkXgoA +L9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=N85XRfDcPcplvNL7bzPUkL1l2YYn2nyqS5OiAu7J43s=; fh=w6gHUaeX5sLU6fB3a/nRZKAvOFmKcmz4JaEADCroHDs=; b=TUOTMFdlDowny18f11R53mOnFyEjUSzFt6vr8TYyBkmOqNva6mRb/62DS0POMkuboj R4ckgBbt4Z/XyxaKqv1W88To3HJm3tYh+8kFqFifoIfeD1WTx4OK86w68mZ0FeyF+dJk e4CjveQn24Z1Tt0LSI7YYW+VUuCgIeRME4pfRHD3nV6Al0JpZebxr71GKkrYE79n4TOK mX20T9kw+jEJ3EAbWfTS6cx46BOvJzilicZ2odo8+pc8pFKYiVMuWZoiIsQGuV3gTXbV BRFCjrFqzb05XshTUnutTRd6HqMoJ4cQWXcpjP8MUgp+noB4DLDuXZRoZfF68j48JJsu 8K1g==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ud1utqFW; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id a640c23a62f3a-a77cda56610sor16150966b.19.2024.07.05.00.20.02 for (Google Transport Security); Fri, 05 Jul 2024 00:20:02 -0700 (PDT) Received-SPF: pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; X-Forwarded-Encrypted: i=1; AJvYcCVG+YXtagftpJ4SlnC0aeMSoguGBKGth5PsldWEpDe/yjoqRLnc+m4Nci3ckE0lQiRKNybXSJc7k9+aCEee6fQxNLk2uoqemhYMTBfRBKaXK1mI X-Received: by 2002:a17:907:7e89:b0:a72:40e7:c6e1 with SMTP id a640c23a62f3a-a77ba48d504mr283970866b.44.1720164001702; Fri, 05 Jul 2024 00:20:01 -0700 (PDT) Received: from panicking.. ([2001:b07:6474:ebbf:a3e:4288:e106:2eef]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a72ab0b84d5sm655158066b.223.2024.07.05.00.20.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Jul 2024 00:20:01 -0700 (PDT) From: Michael Trimarchi To: Lukasz Majewski , Sean Anderson Cc: Tom Rini , linux-amarula@amarulasolutions.com, u-boot@lists.denx.de, Dario Binacchi , Michael Trimarchi , Peng Fan , Dong Aisheng , Shawn Guo Subject: [PATCH V2] clk: imx: add mux ops for i.MX8M composite clk Date: Fri, 5 Jul 2024 09:19:52 +0200 Message-ID: <20240705071952.12245-3-michael@amarulasolutions.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240705071952.12245-1-michael@amarulasolutions.com> References: <20240705071952.12245-1-michael@amarulasolutions.com> MIME-Version: 1.0 X-Original-Sender: michael@amarulasolutions.com X-Original-Authentication-Results: mx.google.com; dkim=pass header.i=@amarulasolutions.com header.s=google header.b=Ud1utqFW; spf=pass (google.com: domain of michael@amarulasolutions.com designates 209.85.220.41 as permitted sender) smtp.mailfrom=michael@amarulasolutions.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=amarulasolutions.com; dara=pass header.i=@amarulasolutions.com Content-Type: text/plain; charset="UTF-8" Precedence: list Mailing-list: list linux-amarula@amarulasolutions.com; contact linux-amarula+owners@amarulasolutions.com List-ID: X-Spam-Checked-In-Group: linux-amarula@amarulasolutions.com X-Google-Group-Id: 476853432473 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Upstream Linux commit f90b68d6c8b0. The CORE/BUS root slice has following design, simplied graph: The difference is core not have pre_div block. A composite core/bus clk has 8 inputs for mux to select, saying clk[0-7]. It support target(smart) interface and normal interface. Target interface is exported for programmer easy to configure ccm root. Normal interface is also exported, but we not use it in our driver, because it will introduce more complexity compared with target interface. The normal interface simplified as below: SEL_A GA +--+ +-+ | +->+ +------+ CLK[0-7]--->+ | +-+ | | | | +----v---+ +----+ | +--+ |pre_diva+----> | +---------+ | +--------+ |mux +--+post_div | | +--+ |pre_divb+--->+ | +---------+ | | | +----^---+ +----+ +--->+ | +-+ | | +->+ +------+ +--+ +-+ SEL_B GB The mux in the upper pic is not the target interface MUX, target interface MUX is hiding SEL_A and SEL_B. When you choose clk[0-7], you are actually writing SEL_A or SEL_B depends on the internal counter which will also control the internal "mux". The target interface simplified as below which is used by Linux Kernel: CLK[0-7]--->MUX-->Gate-->pre_div-->post_div A requirement of the Target Interface's software is that the target clock source is active, it means when setting SEL_A, the current input clk to SEL_A must be active, same to SEL_B. We touch target interface, but hardware logic actually also need configure normal interface. There will be system hang, when doing the following steps: The initial state: SEL_A/SEL_B are both sourcing from clk0, the internal counter choose SEL_A. 1. switch mux from clk0 to clk1 The hardware logic will choose SEL_B and configure SEL_B to clk1. SEL_A no changed. 2. gate off clk0 Disable clk0, then the input to SEL_A is off. 3. switch from clk1 to clk2 The hardware logic will choose SEL_A and configure SEL_A to clk2, however the current SEL_A input clk0 is off, the system hang. The solution to fix the issue is in step 1, write twice to target interface MUX, it will make SEL_A/SEL_B both sources from clk1, then no need to care about the state of clk0. And finally system performs well. Signed-off-by: Peng Fan Reviewed-by: Dong Aisheng Signed-off-by: Shawn Guo Signed-off-by: Michael Trimarchi --- V1->V2: add original submitter in linux kernel, suggested by Fabio Estevam --- drivers/clk/imx/clk-composite-8m.c | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/clk/imx/clk-composite-8m.c b/drivers/clk/imx/clk-composite-8m.c index 560d74aac80..2cb7d135000 100644 --- a/drivers/clk/imx/clk-composite-8m.c +++ b/drivers/clk/imx/clk-composite-8m.c @@ -117,6 +117,41 @@ static const struct clk_ops imx8m_clk_composite_divider_ops = { .set_rate = imx8m_clk_composite_divider_set_rate, }; +static int imx8m_clk_mux_set_parent(struct clk *clk, struct clk *parent) +{ + struct clk_mux *mux = to_clk_mux(clk); + int index; + u32 val; + u32 reg; + + index = clk_mux_fetch_parent_index(clk, parent); + if (index < 0) { + log_err("Could not fetch index\n"); + return index; + } + + val = clk_mux_index_to_val(mux->table, mux->flags, index); + + reg = readl(mux->reg); + reg &= ~(mux->mask << mux->shift); + val = val << mux->shift; + reg |= val; + + /* + * write twice to make sure non-target interface + * SEL_A/B point the same clk input. + */ + writel(reg, mux->reg); + writel(reg, mux->reg); + + return 0; +} + +const struct clk_ops imx8m_clk_mux_ops = { + .get_rate = clk_generic_get_rate, + .set_parent = imx8m_clk_mux_set_parent, +}; + struct clk *imx8m_clk_composite_flags(const char *name, const char * const *parent_names, int num_parents, void __iomem *reg, @@ -155,7 +190,7 @@ struct clk *imx8m_clk_composite_flags(const char *name, clk = clk_register_composite(NULL, name, parent_names, num_parents, - &mux->clk, &clk_mux_ops, &div->clk, + &mux->clk, &imx8m_clk_mux_ops, &div->clk, &imx8m_clk_composite_divider_ops, &gate->clk, &clk_gate_ops, flags); if (IS_ERR(clk))