Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp128448pxj; Wed, 16 Jun 2021 22:19:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLMaCYQTI9uktCriFOZJ4lNgbdzIhBDfcc/549++Eb2IxMc1/pxhlokchC3kH0V1dxoSms X-Received: by 2002:a92:cf0a:: with SMTP id c10mr2182798ilo.97.1623907182977; Wed, 16 Jun 2021 22:19:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623907182; cv=none; d=google.com; s=arc-20160816; b=c4ZZhZtj/xkNfl7a0pBOAiFHEJbFlrYJgRVZwGUFJTiyZ7RwmtEK4Mnt1D1fXdtoEN iX0r+pi934W30ItmwwJYmBa39RPAnWqBHEK55Vd3ZjDZQlJjRj0Ub6VrsvqL5RrpgTDq zSuY3VR5J8H9WY50eAS4AfqXEL214iA6DGOcUWPh8lh4D+vaipStlp5/C9eDsAMhfBOy 3gZSys6gPWQkoKEZB3TYz571bRD93W9HQ979yh/C3qum0sSnzptZFlzNoIGaeuS6GDpC mgJboXNSGhcNMXuCjxFv9FkMYfi50TcZCAgddmAkgCKafU0ocZT9YC7Wp8emg/3kH5Xd JRXw== 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=MQFahwvfutC3FxBs/hqCSrvMqO46K/tUe+kmA3pJK74=; b=YtpVvHC3SBP7EcTVM44AOE6JWywjZ2ZD4AhBA1T6QcSSizGLg5WHM4uQRGIlZ5WgeQ Nm9GRenwA5/eo6eDb7wV7yRzL8sa5qMe+f05yk6SomDQazzln1AKpMS68mDkKthFdvuH I+abmH9rPLGBIXgIBHZJxuZdNi8GI4acWmQXASOYHP5XadMv6nUFkzYdD5jNC0cY+0Gy VeyfRW5+e2WahDT5BR+oLU7ACQLyjEwUm/EEthdzJ8VcyllTeUnDaFZmKdzhNVSeocIh 1fj6rkqBWWowdfnr/92g9W00Wgt7o8ouYJuALndQ9byrhltJiB/44PmhCVSy83ENiCdO cPhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@foss.st.com header.s=selector1 header.b="vGb/6lrY"; 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 b6si4763045ilv.8.2021.06.16.22.19.30; Wed, 16 Jun 2021 22:19:42 -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=@foss.st.com header.s=selector1 header.b="vGb/6lrY"; 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 S230455AbhFQFU5 (ORCPT + 99 others); Thu, 17 Jun 2021 01:20:57 -0400 Received: from mx08-00178001.pphosted.com ([91.207.212.93]:36748 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230001AbhFQFUv (ORCPT ); Thu, 17 Jun 2021 01:20:51 -0400 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 15H5Go4F023982; Thu, 17 Jun 2021 07:18:22 +0200 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=MQFahwvfutC3FxBs/hqCSrvMqO46K/tUe+kmA3pJK74=; b=vGb/6lrY4cdO1oxnH5MYhNVidJ+MA6ndbrHEp4ZuqG7PMqpXqmMInNQpiY96jMFID9ea 2m16G92V90bTrgYUMElkoiyR+uF9wa+Q715ThDxuJntMbSl8y4bIZyBMTnLjxuIPuaOa UXg9mb0T+W54JEmFYCXear7zb5WNRT23BF6ihGmr6up35+PAErG0RjkRNws6JNX8go2E EfSM9w4iFfaoHIX8315if1frfJUC/aR2VqwURrTEljHuWvOkcJ/G70A829WMXhlr9whj HCrrUQ745ZRnst28DoluFZRlJ6pr29RHPkXKykBHXSdZy0m1OZ/K19VJ+pfZAmUWFgx0 bA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 397p55arr5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 17 Jun 2021 07:18:22 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A2DD9100038; Thu, 17 Jun 2021 07:18:21 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node3.st.com [10.75.127.6]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 8AC0021127A; Thu, 17 Jun 2021 07:18:21 +0200 (CEST) Received: from localhost (10.75.127.47) by SFHDAG2NODE3.st.com (10.75.127.6) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 17 Jun 2021 07:18:21 +0200 From: To: Michael Turquette , Stephen Boyd , Rob Herring , Maxime Coquelin , Alexandre Torgue , Philipp Zabel , Etienne Carriere , Gabriel Fernandez , CC: , , , , Subject: [RESEND PATCH v3 02/11] clk: stm32mp1: merge 'ck_hse_rtc' and 'ck_rtc' into one clock Date: Thu, 17 Jun 2021 07:18:05 +0200 Message-ID: <20210617051814.12018-3-gabriel.fernandez@foss.st.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210617051814.12018-1-gabriel.fernandez@foss.st.com> References: <20210617051814.12018-1-gabriel.fernandez@foss.st.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG1NODE1.st.com (10.75.127.1) To SFHDAG2NODE3.st.com (10.75.127.6) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-06-17_01:2021-06-15,2021-06-17 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 | 54 +++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/drivers/clk/clk-stm32mp1.c b/drivers/clk/clk-stm32mp1.c index 35d5aee8f9b0..a7c244fd0b03 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,47 @@ 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 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 int clk_divider_rtc_determine_rate(struct clk_hw *hw, struct clk_rate_request *req) +{ + unsigned long best_parent_rate = req->best_parent_rate; + + if (req->best_parent_hw == clk_hw_get_parent_by_index(hw, HSE_RTC)) { + req->rate = clk_divider_ops.round_rate(hw, req->rate, &best_parent_rate); + req->best_parent_rate = best_parent_rate; + } else { + req->rate = best_parent_rate; + } + + return 0; +} + +static const struct clk_ops rtc_div_clk_ops = { + .recalc_rate = clk_divider_rtc_recalc_rate, + .set_rate = clk_divider_rtc_set_rate, + .determine_rate = clk_divider_rtc_determine_rate +}; + struct stm32_pll_cfg { u32 offset; }; @@ -1243,6 +1284,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 +2010,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