From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A9C38CCF9E9 for ; Thu, 26 Sep 2024 07:52:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Content-Transfer-Encoding:Content-Type:In-Reply-To:From:References:To:Subject :MIME-Version:Date:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=QQkR69sKp8Yewhrmn8jwB2Hc/tFxgtKhEZk1YzyJXlA=; b=rUVW+IXOiOHE7T lsQOCDank/TR37oOMPTDF+BkoNbEpwC/P8wCGhTCw1seqTBQ3WUBLgLGmHl4L/uSIHOF8/kGrUcpm jSc27g/ToJGzTz48QjoDR1gYEEu6EoYm4m63bI/QEZPxnVU/4++cu6LP0IabFSF2TeicyolFI7m5B TN29+0ozgPkRtpGrcsmZ0wusw6weNQjtuvrB/EWebs3kKSKYu31eSCHcFioO0p1mxFY4pCXMjU0zI I4NyRY4WJbRTOn+8udMRmUMkjfGJqWLiFxeWTEphPvjLQUbdf+px8d/149e0nzjttB5/dyWp1tQ9M pBFNc/vXenYkDm/SzXig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1stjIh-00000007ahV-3fLD; Thu, 26 Sep 2024 07:52:35 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1stj9T-00000007Y9M-390I for linux-arm-kernel@lists.infradead.org; Thu, 26 Sep 2024 07:43:05 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-42cbface8d6so7712695e9.3 for ; Thu, 26 Sep 2024 00:43:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tuxon.dev; s=google; t=1727336582; x=1727941382; darn=lists.infradead.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=QQkR69sKp8Yewhrmn8jwB2Hc/tFxgtKhEZk1YzyJXlA=; b=f+L24OF374nQc6+xBSeqMwCUMW+u3ZCIX6SWIEjJmRQEBnd3bU9LKJDu2Bh+I2D6Mu SolofQpQpKM/hCG4t9IAlubajHAyC669A0VSXssM+K0qySmfcZoEdQTKR2yKYe7oINJb EIbgJFIjNsRhgDBaSaNJ6LPkitFebygjvR0oEXuroO4dndbI33UwICqQsnvAT/VNpWth zoxeSQAFx/mC1f0IEetdA4h4TBueDq++BFH3jQy9cVAuVt/4pN+dY3zY/PPhXLfehnaX PRZHEgyVXMYI9i1Xi7IPuJPVDALDEyoQK8oXqgjxSfNHdzZJWqoU5w6lMGqM+kpILMST /egg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727336582; x=1727941382; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QQkR69sKp8Yewhrmn8jwB2Hc/tFxgtKhEZk1YzyJXlA=; b=ZVZjxgVfiUrvr63M4qR9Hi8aitq3WIg2AsToxr3f6M58bRXDwbgA5xMTe1kxsLqPXn O7dH1gugnN5D8xoCHR0q4MXe7lh2jBt7/uNs4SdcxIFyS+MRCwibIW6uTcz8G5U21Bnw lS+s9j0Dgs21ROuhjN7h2PzJhLrOuVTsVH+UxFuAxHUvv355YzM0YYCjzXbbN/VwVQQX SKBg/GfFP1kYz67TqB164KcAO+mnDV3jE1B6dECzoLqEGMLpmDZkdOt5PiiEwmkKPQN8 OJirs+IfcGYWhu6cF5WNDhjEAo/EMukB3TwR2uTsaRHL6Z8bGLAGxhggDo6cKgB9HmA+ qv0w== X-Forwarded-Encrypted: i=1; AJvYcCXdUXhPdt05+ZwnRqvnXuUhJo60tw70HC0H31or+5BrLUeotnca/VIhevc+9/8fqEbPeJSfUu3lU7/GanQmuY8e@lists.infradead.org X-Gm-Message-State: AOJu0YxHlc1FEpUevWBKjrdUZeLqw9N2HuKaczXkfsLrHw7RkZVSy3XG plyOkIebIVtwLixAk1wkKnL3B++s6IbA1UuRmCBwlAx3LNfLdxk6qXqcjjeWekaWbYTwZ/g4T8U o X-Google-Smtp-Source: AGHT+IHBv+8cCJ4P//uZgQU9mGKQlD7W6/9RP/K5Q7QoHFn/s97lU6vtCpnQ8hrmoZ5KSMACjGqOMw== X-Received: by 2002:adf:fbcc:0:b0:374:c44e:ef27 with SMTP id ffacd0b85a97d-37cc245dd30mr4407870f8f.8.1727336581837; Thu, 26 Sep 2024 00:43:01 -0700 (PDT) Received: from [192.168.50.4] ([82.78.167.115]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-37ccd370ab7sm1819223f8f.25.2024.09.26.00.43.00 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 26 Sep 2024 00:43:01 -0700 (PDT) Message-ID: Date: Thu, 26 Sep 2024 10:42:59 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v1 09/12] clk: at91: sam9x60: Allow enabling main_rc_osc through DT Content-Language: en-US To: Ryan Wanner , ada@thorsis.com References: <20240821105943.230281-1-ada@thorsis.com> <20240821105943.230281-10-ada@thorsis.com> <20240919-outsider-extending-e0a926bd23fa@thorsis.com> <464f599a-7f0b-4e4e-901a-8f88a25428d6@microchip.com> From: claudiu beznea In-Reply-To: <464f599a-7f0b-4e4e-901a-8f88a25428d6@microchip.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240926_004304_015560_C7D83506 X-CRM114-Status: GOOD ( 44.67 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Rob Herring , Conor Dooley , "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , Stephen Boyd , Christian Melki , Alexandre Belloni , open list , Michael Turquette , Krzysztof Kozlowski , "open list:COMMON CLK FRAMEWORK" , "moderated list:ARM/Microchip \(AT91\) SoC support" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi, Ryan, Alexander, Sorry for returning late, I took some time to think about it... On 24.09.2024 18:52, Ryan Wanner wrote: > Hello Alex, > > I think a possible solution is to put the DT binding ID for main rc oc > after PMC_MCK and then add 1 to all the other IDs that are not dependent > on PMC_MAIN, the IDs that are before the branch for the sama7g54. If I understand correctly, wouldn't this shift also the rest of the IDs and break the DT ABI? > > One issue I see with this solution is with SoCs that do not want the > main rc os exported to the DT the driver array might be allocating too > much memory, this can be solved by removing the +1 that is in the clock > drivers next to the device tree binding macro, since this macro is now > increased by 1 with this change. > > Doing a quick test on the sam9x60 and sama7g54 I did not see any glaring > issues with this potential solution. > > Best, > > Ryan > > > On 9/19/24 05:39, Alexander Dahl wrote: >> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe >> >> Hello Claudiu, >> >> after being busy with other things, I'm back looking at this series. >> As Nicolas pointed out [1], we need three clocks for the OTPC to work, >> quote: >> >> "for all the products, the main RC oscillator, the OTPC peripheral >> clock and the MCKx clocks associated to OTP must be enabled." >> >> I have a problem with making the main_rc_osc accessible for both >> SAM9X60 and SAMA7G5 here, see below. >> >> Am Wed, Aug 21, 2024 at 12:59:40PM +0200 schrieb Alexander Dahl: >>> SAM9X60 Datasheet (DS60001579G) Section "23.4 Product Dependencies" >>> says: >>> >>> "The OTPC is clocked through the Power Management Controller (PMC). >>> The user must power on the main RC oscillator and enable the >>> peripheral clock of the OTPC prior to reading or writing the OTP >>> memory." >>> >>> The code for enabling/disabling that clock is already present, it was >>> just not possible to hook into DT anymore, after at91 clk devicetree >>> binding rework back in 2018 for kernel v4.19. >>> >>> Signed-off-by: Alexander Dahl >>> --- >>> drivers/clk/at91/sam9x60.c | 3 ++- >>> include/dt-bindings/clock/at91.h | 1 + >>> 2 files changed, 3 insertions(+), 1 deletion(-) >>> >>> diff --git a/drivers/clk/at91/sam9x60.c b/drivers/clk/at91/sam9x60.c >>> index e309cbf3cb9a..4d5ee20b8fc4 100644 >>> --- a/drivers/clk/at91/sam9x60.c >>> +++ b/drivers/clk/at91/sam9x60.c >>> @@ -207,7 +207,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np) >>> if (IS_ERR(regmap)) >>> return; >>> >>> - sam9x60_pmc = pmc_data_allocate(PMC_PLLACK + 1, >>> + sam9x60_pmc = pmc_data_allocate(PMC_MAIN_RC + 1, >>> nck(sam9x60_systemck), >>> nck(sam9x60_periphck), >>> nck(sam9x60_gck), 8); >>> @@ -218,6 +218,7 @@ static void __init sam9x60_pmc_setup(struct device_node *np) >>> 50000000); >>> if (IS_ERR(hw)) >>> goto err_free; >>> + sam9x60_pmc->chws[PMC_MAIN_RC] = hw; >>> >>> hw = at91_clk_register_main_osc(regmap, "main_osc", mainxtal_name, NULL, 0); >>> if (IS_ERR(hw)) >>> diff --git a/include/dt-bindings/clock/at91.h b/include/dt-bindings/clock/at91.h >>> index 3e3972a814c1..f957625cb3ac 100644 >>> --- a/include/dt-bindings/clock/at91.h >>> +++ b/include/dt-bindings/clock/at91.h >>> @@ -25,6 +25,7 @@ >>> #define PMC_PLLBCK 8 >>> #define PMC_AUDIOPLLCK 9 >>> #define PMC_AUDIOPINCK 10 >>> +#define PMC_MAIN_RC 11 >>> >>> /* SAMA7G5 */ >>> #define PMC_CPUPLL (PMC_MAIN + 1) >> >> There are IDs defined in the devicetree bindings here, which are used >> both in dts and in driver code as array indexes. In v1 of the patch >> series I just added a new last element in the end of the generic list >> and used that for SAM9X60. >> >> For SAMA7G5 those IDs are branched of from PMC_MAIN in between, making >> SAMA7G5 using a different last element, and different values after >> PMC_MAIN. Looking at it now, I think it was a bad decision to do this branch. Thinking at it maybe it would be better to have per SoC specific bindings to avoid this kind of issue in future. The PMC IP b/w different SAM SoCs is anyway different and, as it happens now, we may reach to a point where, due to issues in datasheet, or whatever human errors, we may reach this problem again. So, what do you think about having separate binding files for each SoC? Another option would be to xlate the clocks not by directly indexing in struct pmc_data::chws but by matching the driver clock ID and DT provided id. This will increase the lookup time, from O(1) to O(N), N being 13 for SAMA7G5, 15 for SAM9X7 and SAMA7D55. And will need adjustment at least for SAM9X{60, 7} and SAMA7{G5, D55}. With this the of_clk_hw_pmc_get() will be something like: diff --git a/drivers/clk/at91/pmc.c b/drivers/clk/at91/pmc.c index 5aa9c1f1c886..22191d1ca78b 100644 --- a/drivers/clk/at91/pmc.c +++ b/drivers/clk/at91/pmc.c @@ -52,8 +52,10 @@ struct clk_hw *of_clk_hw_pmc_get(struct of_phandle_args *clkspec, void *data) switch (type) { case PMC_TYPE_CORE: - if (idx < pmc_data->ncore) - return pmc_data->chws[idx]; + for (int i = 0; i < pmc_data->ncore; i++) { + if (pmc_data->chws.idx[i] == i) + return pmc_data->chws.hws[i]; + } break; diff --git a/drivers/clk/at91/pmc.h b/drivers/clk/at91/pmc.h index 4fb29ca111f7..f7e88f9872dc 100644 --- a/drivers/clk/at91/pmc.h +++ b/drivers/clk/at91/pmc.h @@ -19,7 +19,10 @@ extern spinlock_t pmc_pcr_lock; struct pmc_data { unsigned int ncore; - struct clk_hw **chws; + struct { + struct clk_hw **hws; + int *idx; + } chws; Thank you, Claudiu Beznea >> >> Now we need a new ID for main rc osc, but not only for SAM9X60, but >> also for SAMA7G5. I'm not sure what the implications would be, if the >> new ID would be added in between before PMC_MAIN, so all values would >> change? Adding it to the end of the lists would probably be safe, but >> then you would need a diffently named variant for SAMA7G5's different >> IDs. I find the current status somewhat unfortunate for future >> extensions. How should this new ID be added here? What would be the >> way forward? >> >> Greets >> Alex >> >> [1] https://lore.kernel.org/linux-clk/ec34efc2-2051-4b8a-b5d8-6e2fd5e08c28@microchip.com/T/#u >> >>> -- >>> 2.39.2 >>> >>> >> >