Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4393357pxb; Tue, 26 Jan 2021 22:08:02 -0800 (PST) X-Google-Smtp-Source: ABdhPJz2NR5xIHK3JbzTsJjrz+0ANeDXmczfj9FaQRpx7WGb15H6UhKEKNN6PNahGHwcJ0LGy3gh X-Received: by 2002:aa7:d905:: with SMTP id a5mr7751156edr.78.1611727682265; Tue, 26 Jan 2021 22:08:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611727682; cv=none; d=google.com; s=arc-20160816; b=Rqyb3eDBAL3L50bQkmnK2JsdTHUyYJZG5V7s1U9NT6GqcQlM/ANcm7irB1VHZmzvwg itryKDf4vAEgAglAliO8BX/22+SdkL1LO7jb+6UzbTMWZMpgb2v7pl1fl6OxL4cdR9Ug bLPVbxkQourr5s/ShSVjWI379Sdjq5jRYMvfufB6iJ/Aapcaf2U3nZ3q9+8Q4tvEDrJp OwbRPsoMkA7x1UCCpBNr9Z9no4/M6zRcSVVkGZ+oXb38ET/SzIa7h5pSwsfgS8yo5SMT 6B26gtGjs/3hNL8nAMwTvnPMi/T9U8AvR1gvzRGP2vyRjmH5RF6UrEqIRWRaBE5dWa3e wPLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=vD3EHGbLxSS3YdjyiN4P/XEtIcwWhHbeghamkCuYDFE=; b=lQjTm4wHFFiKrOr9tA6gJhCP9p3j2+Klob/eigTkU+SZXbk4t4Vh8Z+6U7XDf+ZbDZ O7hkSaVSAttVj5DYvxSbF1oiaHDSRPxMOk0Rcfl8N7aXQb4bWpO0h1oTWmBWgbIFw0Fw Jo8tZtPGRI7nVdrjm+ryKgba9hUdQazdURl2y3zyCnqwvSq/aiwapdoAE/5EsLU5gXbf 9CHA0aFY1W+RVik7SmNZkLG6UQzyU4cOC7Eav/7F+a/GZuBgURNlNMb3dAs0ba8z45ut o4NB3+bb/5gsTv7jLyTBZLP7qq8xMpjt06vqw60MO3IEmpTPBRtIp9QwEIJRv4SeB+7g KZ6Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b=WkTG3san; 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=NONE sp=NONE dis=NONE) header.from=foss.st.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b7si417103ejj.332.2021.01.26.22.07.38; Tue, 26 Jan 2021 22:08:02 -0800 (PST) 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=@foss.st.com header.s=selector1 header.b=WkTG3san; 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=NONE sp=NONE dis=NONE) header.from=foss.st.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393846AbhAZSAJ (ORCPT + 99 others); Tue, 26 Jan 2021 13:00:09 -0500 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:43893 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390855AbhAZJF3 (ORCPT ); Tue, 26 Jan 2021 04:05:29 -0500 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 10Q8vTwp001512; Tue, 26 Jan 2021 10:04:29 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=selector1; bh=vD3EHGbLxSS3YdjyiN4P/XEtIcwWhHbeghamkCuYDFE=; b=WkTG3sanqphvMTblqvEba0srKO0/T6j0VCMZURco8IkshvoR1fNtqwU/HPeB3hO2cUYy 56GaqRhd/5fzni4vERt403fNyTg9I05AAZ7DjY7nzMLJyBnoHSCtD5Xfr24G9JRBC5bA G4TPOVkDrC+ynQYFG3KpXUOXV49Gmi6cWDSHR7AOlvwLECblIQzSTYopyXrwUMc1tc6f UPSC0GYK6YeJqshg6f9yOdw+AdaWLTEsWzZY+QUTjugAwHXpVq3sXKrprc3leCf7ftY7 hcafZ2IzGY805VnmcVL82HWMWkUyJF5miIioS40ukrqD3jr/gzsdtaTq1ydKylaEpyRr fQ== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 368a56fvgf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 26 Jan 2021 10:04:29 +0100 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 7994710002A; Tue, 26 Jan 2021 10:04:29 +0100 (CET) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 621F022A4A4; Tue, 26 Jan 2021 10:04:29 +0100 (CET) Received: from localhost (10.75.127.47) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Tue, 26 Jan 2021 10:04:29 +0100 From: To: Michael Turquette , Stephen Boyd , Rob Herring , Maxime Coquelin , Alexandre Torgue , Philipp Zabel , Etienne Carriere , Gabriel Fernandez , CC: , , , , Subject: [PATCH v2 02/14] clk: stm32mp1: merge 'ck_hse_rtc' and 'ck_rtc' into one clock Date: Tue, 26 Jan 2021 10:01:08 +0100 Message-ID: <20210126090120.19900-3-gabriel.fernandez@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210126090120.19900-1-gabriel.fernandez@foss.st.com> References: <20210126090120.19900-1-gabriel.fernandez@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG1NODE3.st.com (10.75.127.3) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343,18.0.737 definitions=2021-01-26_06:2021-01-25,2021-01-26 signatures=0 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Gabriel Fernandez 'ck_rtc' has multiple clocks as input (ck_hsi, ck_lsi, and ck_hse). A divider is available only on the specific rtc input for ck_hse. This Merge will facilitate to have a more coherent clock tree in no trusted / trusted world. Signed-off-by: Gabriel Fernandez --- drivers/clk/clk-stm32mp1.c | 49 +++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk-stm32mp1.c b/drivers/clk/clk-stm32mp1.c index 35d5aee8f9b0..0e1d4427a8df 100644 --- a/drivers/clk/clk-stm32mp1.c +++ b/drivers/clk/clk-stm32mp1.c @@ -245,7 +245,7 @@ static const char * const dsi_src[] = { }; static const char * const rtc_src[] = { - "off", "ck_lse", "ck_lsi", "ck_hse_rtc" + "off", "ck_lse", "ck_lsi", "ck_hse" }; static const char * const mco1_src[] = { @@ -1031,6 +1031,42 @@ static struct clk_hw *clk_register_cktim(struct device *dev, const char *name, return hw; } +/* The divider of RTC clock concerns only ck_hse clock */ +#define HSE_RTC 3 + +static unsigned long clk_divider_rtc_recalc_rate(struct clk_hw *hw, + unsigned long parent_rate) +{ + if (clk_hw_get_parent(hw) == clk_hw_get_parent_by_index(hw, HSE_RTC)) + return clk_divider_ops.recalc_rate(hw, parent_rate); + + return parent_rate; +} + +static long clk_divider_rtc_round_rate(struct clk_hw *hw, unsigned long rate, + unsigned long *prate) +{ + if (clk_hw_get_parent(hw) == clk_hw_get_parent_by_index(hw, HSE_RTC)) + return clk_divider_ops.round_rate(hw, rate, prate); + + return *prate; +} + +static int clk_divider_rtc_set_rate(struct clk_hw *hw, unsigned long rate, + unsigned long parent_rate) +{ + if (clk_hw_get_parent(hw) == clk_hw_get_parent_by_index(hw, HSE_RTC)) + return clk_divider_ops.set_rate(hw, rate, parent_rate); + + return parent_rate; +} + +static const struct clk_ops rtc_div_clk_ops = { + .recalc_rate = clk_divider_rtc_recalc_rate, + .round_rate = clk_divider_rtc_round_rate, + .set_rate = clk_divider_rtc_set_rate, +}; + struct stm32_pll_cfg { u32 offset; }; @@ -1243,6 +1279,10 @@ _clk_stm32_register_composite(struct device *dev, _STM32_DIV(_div_offset, _div_shift, _div_width,\ _div_flags, _div_table, NULL)\ +#define _DIV_RTC(_div_offset, _div_shift, _div_width, _div_flags, _div_table)\ + _STM32_DIV(_div_offset, _div_shift, _div_width,\ + _div_flags, _div_table, &rtc_div_clk_ops) + #define _STM32_MUX(_offset, _shift, _width, _mux_flags, _mmux, _ops)\ .mux = &(struct stm32_mux_cfg) {\ &(struct mux_cfg) {\ @@ -1965,13 +2005,10 @@ static const struct clock_config stm32mp1_clock_cfg[] = { _DIV(RCC_ETHCKSELR, 4, 4, 0, NULL)), /* RTC clock */ - DIV(NO_ID, "ck_hse_rtc", "ck_hse", 0, RCC_RTCDIVR, 0, 6, 0), - - COMPOSITE(RTC, "ck_rtc", rtc_src, CLK_OPS_PARENT_ENABLE | - CLK_SET_RATE_PARENT, + COMPOSITE(RTC, "ck_rtc", rtc_src, CLK_OPS_PARENT_ENABLE, _GATE(RCC_BDCR, 20, 0), _MUX(RCC_BDCR, 16, 2, 0), - _NO_DIV), + _DIV_RTC(RCC_RTCDIVR, 0, 6, 0, NULL)), /* MCO clocks */ COMPOSITE(CK_MCO1, "ck_mco1", mco1_src, CLK_OPS_PARENT_ENABLE | -- 2.17.1