From patchwork Mon Jul 30 10:01:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 10548847 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AAC63A754 for ; Mon, 30 Jul 2018 10:15:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99EBB2940D for ; Mon, 30 Jul 2018 10:15:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C17B299E8; Mon, 30 Jul 2018 10:15:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 323682940D for ; Mon, 30 Jul 2018 10:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=IPvMtAVulqdCA7jope/FLSh93e2XCR0FDw0OdyT5Kmc=; b=j9F YTbglTM9hmqggS2lyJTxWYdUUPevBKDAv905FXKTkc0MI6PqENeKKJw5N+cJRKhfe+47pDx9fcAZS wo/SMabZ91VS1Ss/fXNxQVx+0f06OUOIv1rrO0kCBbW6dVG1guMHcVDKxIio5+UFwyTehNYRTM0Qr y0iY8ZDKLPP1yb+6evF5j2x1hO3AK6hfshd2O7OxHwKiWTf5QdYXYVK2bAjv9wIq/jZKud1dpU06J /ysG33BGzfiLw79YYgVEpp0rNz9fwnK9wiLswyl0TFuaHp/yGUDVvIJjImi3SIViaFXkNE4elRdvb KILGlMKWw6NYqy/8lnqtpQ/Fm96/Gvw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk5Cg-0003x7-A1; Mon, 30 Jul 2018 10:15:02 +0000 Received: from inva020.nxp.com ([92.121.34.13]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk5Cd-0003ti-5C for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2018 10:15:00 +0000 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id CCE0A1A003B; Mon, 30 Jul 2018 12:14:44 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 105091A0013; Mon, 30 Jul 2018 12:14:39 +0200 (CEST) Received: from Tank.ap.freescale.net (tank.ap.freescale.net [10.193.20.104]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id A6CD2402D7; Mon, 30 Jul 2018 18:14:31 +0800 (SGT) From: Yangbo Lu To: netdev@vger.kernel.org, madalin.bucur@nxp.com, Richard Cochran , Rob Herring , Shawn Guo , "David S . Miller" Subject: [PATCH 1/3] arm64: dts: fsl: add clocks property for fman ptp timer node Date: Mon, 30 Jul 2018 18:01:52 +0800 Message-Id: <20180730100154.27906-1-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.14.1 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180730_031459_344758_B080C183 X-CRM114-Status: UNSURE ( 7.95 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Yangbo Lu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is to add clocks property for fman ptp timer node. Signed-off-by: Yangbo Lu --- arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi b/arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi index a56a408..4664c33 100644 --- a/arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi +++ b/arch/arm64/boot/dts/freescale/qoriq-fman3-0.dtsi @@ -80,4 +80,5 @@ ptp_timer0: ptp-timer@1afe000 { compatible = "fsl,fman-ptp-timer"; reg = <0x0 0x1afe000 0x0 0x1000>; interrupts = ; + clocks = <&clockgen 3 0>; }; From patchwork Mon Jul 30 10:01:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 10548849 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DC6814BC for ; Mon, 30 Jul 2018 10:15:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2BF2C2940D for ; Mon, 30 Jul 2018 10:15:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1FE2D299E8; Mon, 30 Jul 2018 10:15:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C062D2940D for ; Mon, 30 Jul 2018 10:15:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vYyUiaT3WRgXBSjt1ZrRMtyfHgIwC/5EDnzUcV6pEA0=; b=kLJmbGlo51lX3SoHW3UNzCrW9J lJAJtQWjPxKxz4p7+KH+UDoYuz7zoS2909HXaWRTD8oXs+uJhcPcvXahZtIziaAxBnUglhjmCMyPT tXidkvMGdsf0iyDnM80o0615eDDiwLQ2K0GKUysNBckENs8eIiibjXj7BhgPyGGVArcCc0EmAHxHF v0KWToqy24CkzINu8Rwt3/ADUUy+nBh0OeTVu/GMTvpDjeINL7teAhFN4LhTp9vTPC1JndGvTHFgs pITYTj2FoioNKiC8A/Vv3GVxJ54s7lopybjlEO7JS0vVlH406VgG2yDxkYnxaJocZc3UdNQbuIkH2 loR9oTUg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk5D0-00054k-8H; Mon, 30 Jul 2018 10:15:22 +0000 Received: from inva021.nxp.com ([92.121.34.21]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk5Ce-0003tl-1g for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2018 10:15:01 +0000 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 0788F200031; Mon, 30 Jul 2018 12:14:46 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 3F0ED200002; Mon, 30 Jul 2018 12:14:40 +0200 (CEST) Received: from Tank.ap.freescale.net (tank.ap.freescale.net [10.193.20.104]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id E2BC4402E1; Mon, 30 Jul 2018 18:14:32 +0800 (SGT) From: Yangbo Lu To: netdev@vger.kernel.org, madalin.bucur@nxp.com, Richard Cochran , Rob Herring , Shawn Guo , "David S . Miller" Subject: [PATCH 2/3] powerpc/mpc85xx: add clocks property for fman ptp timer node Date: Mon, 30 Jul 2018 18:01:53 +0800 Message-Id: <20180730100154.27906-2-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180730100154.27906-1-yangbo.lu@nxp.com> References: <20180730100154.27906-1-yangbo.lu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180730_031500_223544_840CF6D9 X-CRM114-Status: UNSURE ( 7.69 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Yangbo Lu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is to add clocks property for fman ptp timer node. Signed-off-by: Yangbo Lu --- arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi | 1 + arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi | 1 + arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi | 1 + arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi | 1 + arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi | 1 + 5 files changed, 5 insertions(+), 0 deletions(-) diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi b/arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi index 6b124f7..9b6cf91 100644 --- a/arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi +++ b/arch/powerpc/boot/dts/fsl/qoriq-fman-0.dtsi @@ -100,4 +100,5 @@ ptp_timer0: ptp-timer@4fe000 { compatible = "fsl,fman-ptp-timer"; reg = <0x4fe000 0x1000>; interrupts = <96 2 0 0>; + clocks = <&clockgen 3 0>; }; diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi b/arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi index b80aaf5..e95c11f 100644 --- a/arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi +++ b/arch/powerpc/boot/dts/fsl/qoriq-fman-1.dtsi @@ -100,4 +100,5 @@ ptp_timer1: ptp-timer@5fe000 { compatible = "fsl,fman-ptp-timer"; reg = <0x5fe000 0x1000>; interrupts = <97 2 0 0>; + clocks = <&clockgen 3 1>; }; diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi b/arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi index d3720fd..d62b36c 100644 --- a/arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi +++ b/arch/powerpc/boot/dts/fsl/qoriq-fman3-0.dtsi @@ -105,4 +105,5 @@ ptp_timer0: ptp-timer@4fe000 { compatible = "fsl,fman-ptp-timer"; reg = <0x4fe000 0x1000>; interrupts = <96 2 0 0>; + clocks = <&clockgen 3 0>; }; diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi b/arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi index ae34c20..3102324 100644 --- a/arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi +++ b/arch/powerpc/boot/dts/fsl/qoriq-fman3-1.dtsi @@ -105,4 +105,5 @@ ptp_timer1: ptp-timer@5fe000 { compatible = "fsl,fman-ptp-timer"; reg = <0x5fe000 0x1000>; interrupts = <97 2 0 0>; + clocks = <&clockgen 3 1>; }; diff --git a/arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi b/arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi index 02f2755..c90702b 100644 --- a/arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi +++ b/arch/powerpc/boot/dts/fsl/qoriq-fman3l-0.dtsi @@ -93,4 +93,5 @@ ptp_timer0: ptp-timer@4fe000 { compatible = "fsl,fman-ptp-timer"; reg = <0x4fe000 0x1000>; interrupts = <96 2 0 0>; + clocks = <&clockgen 3 0>; }; From patchwork Mon Jul 30 10:01:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 10548851 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F133D14BC for ; Mon, 30 Jul 2018 10:15:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E01DD2940D for ; Mon, 30 Jul 2018 10:15:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D3C25299E8; Mon, 30 Jul 2018 10:15:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 586182940D for ; Mon, 30 Jul 2018 10:15:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0AB+4joqU7JhvNLk4/ILi0bQbJK9yFYuCOHyBPyRd50=; b=obss4XpucpGkJdvnIAXNtqUAeb b3qkHe139nztmwYepatCPSROU8JNa7/9aX5Tt0dhdtQ1sS74UoWpIX6ugdeJlxjTK01lCBtwzrme7 IfEq9wPnwgNo8sYqkOxZDKZnnP3/mkUBb4Yiiaqlasyib0GMgiofOr4raGX+6A5FlgpmQ2bfijR0B VkVOkW6CJZieuMOR7IyXarmVBSyiecd4dFRxXszXYBvInw3aV1PGispxbv2oxDFFaZ9Pxe1kxzZEv kDyr51caVbCYAz3/jK9MstLhpbMF4HnrhobszSxdosXYzVlH1z05UULb84IJheyEQXfQyvtpeOZ+Q VCfJihqQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk5DA-0005RI-GI; Mon, 30 Jul 2018 10:15:32 +0000 Received: from inva021.nxp.com ([92.121.34.21]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fk5Ce-0003tn-1f for linux-arm-kernel@lists.infradead.org; Mon, 30 Jul 2018 10:15:01 +0000 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 6B1EC200059; Mon, 30 Jul 2018 12:14:47 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 6C15A20004B; Mon, 30 Jul 2018 12:14:41 +0200 (CEST) Received: from Tank.ap.freescale.net (tank.ap.freescale.net [10.193.20.104]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 1D040402FC; Mon, 30 Jul 2018 18:14:34 +0800 (SGT) From: Yangbo Lu To: netdev@vger.kernel.org, madalin.bucur@nxp.com, Richard Cochran , Rob Herring , Shawn Guo , "David S . Miller" Subject: [PATCH 3/3] ptp_qoriq: convert to use module parameters for initialization Date: Mon, 30 Jul 2018 18:01:54 +0800 Message-Id: <20180730100154.27906-3-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180730100154.27906-1-yangbo.lu@nxp.com> References: <20180730100154.27906-1-yangbo.lu@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180730_031500_363080_E9022542 X-CRM114-Status: GOOD ( 18.84 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Yangbo Lu MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The ptp_qoriq driver initialized the 1588 timer with the configurations provided by the properties of device tree node. For example, fsl,tclk-period = <5>; fsl,tmr-prsc = <2>; fsl,tmr-add = <0xaaaaaaab>; fsl,tmr-fiper1 = <999999995>; fsl,tmr-fiper2 = <99990>; fsl,max-adj = <499999999>; These things actually were runtime configurations which were not proper to be put into dts. This patch is to convert to use module parameters for 1588 timer initialization, and to support initial register values calculation. If the parameters are not provided, the driver will calculate register values with a set of default parameters. With this patch, those dts properties are no longer needed for new platform to support 1588 timer, and many QorIQ DPAA platforms (some P series and T series platforms of PowerPC, and some LS series platforms of ARM64) could use this driver for their fman ptp timer with default module parameters. However, this patch didn't remove the dts method. Because there were still many old platforms using the dts method. We need to clean up their dts files, verify module parameters on them, and convert them to the new method gradually in case of breaking any function. Signed-off-by: Yangbo Lu --- drivers/ptp/ptp_qoriq.c | 117 +++++++++++++++++++++++++++++++++++++++- include/linux/fsl/ptp_qoriq.h | 1 + 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/drivers/ptp/ptp_qoriq.c b/drivers/ptp/ptp_qoriq.c index a14c317..22baf83 100644 --- a/drivers/ptp/ptp_qoriq.c +++ b/drivers/ptp/ptp_qoriq.c @@ -29,9 +29,30 @@ #include #include #include +#include #include +static unsigned int cksel = DEFAULT_CKSEL; +module_param(cksel, uint, 0644); +MODULE_PARM_DESC(cksel, "Select reference clock"); + +static unsigned int clk_src; +module_param(clk_src, uint, 0644); +MODULE_PARM_DESC(clk_src, "Reference clock frequency (if clocks property not provided in dts)"); + +static unsigned int tmr_prsc = 2; +module_param(tmr_prsc, uint, 0644); +MODULE_PARM_DESC(tmr_prsc, "Output clock division/prescale factor"); + +static unsigned int tmr_fiper1 = 1000000000; +module_param(tmr_fiper1, uint, 0644); +MODULE_PARM_DESC(tmr_fiper1, "Desired fixed interval pulse period (ns)"); + +static unsigned int tmr_fiper2 = 100000; +module_param(tmr_fiper2, uint, 0644); +MODULE_PARM_DESC(tmr_fiper2, "Desired fixed interval pulse period (ns)"); + /* * Register access functions */ @@ -317,6 +338,91 @@ static int ptp_qoriq_enable(struct ptp_clock_info *ptp, .enable = ptp_qoriq_enable, }; +/** + * qoriq_ptp_nominal_freq - calculate nominal frequency by reference clock + * frequency + * + * @clk_src: reference clock frequency + * + * The nominal frequency is the desired clock frequency. + * It should be less than the reference clock frequency. + * It should be a factor of 1000MHz. + * + * Return the nominal frequency + */ +static u32 qoriq_ptp_nominal_freq(u32 clk_src) +{ + u32 remainder = 0; + + clk_src /= 1000000; + remainder = clk_src % 100; + if (remainder) { + clk_src -= remainder; + clk_src += 100; + } + + do { + clk_src -= 100; + + } while (1000 % clk_src); + + return clk_src * 1000000; +} + +static int qoriq_ptp_config(struct qoriq_ptp *qoriq_ptp, + struct device_node *node) +{ + struct clk *clk; + u64 freq_comp; + u64 max_adj; + u32 nominal_freq; + + qoriq_ptp->cksel = cksel; + + if (clk_src) { + qoriq_ptp->clk_src = clk_src; + } else { + clk = of_clk_get(node, 0); + if (!IS_ERR(clk)) { + qoriq_ptp->clk_src = clk_get_rate(clk); + clk_put(clk); + } + } + + if (qoriq_ptp->clk_src <= 100000000UL) { + pr_err("error reference clock value, or lower than 100MHz\n"); + return -EINVAL; + } + + nominal_freq = qoriq_ptp_nominal_freq(qoriq_ptp->clk_src); + if (!nominal_freq) + return -EINVAL; + + qoriq_ptp->tclk_period = 1000000000UL / nominal_freq; + qoriq_ptp->tmr_prsc = tmr_prsc; + + /* Calculate initial frequency compensation value for TMR_ADD register. + * freq_comp = ceil(2^32 / freq_ratio) + * freq_ratio = reference_clock_freq / nominal_freq + */ + freq_comp = ((u64)1 << 32) * nominal_freq; + if (do_div(freq_comp, qoriq_ptp->clk_src)) + freq_comp++; + + qoriq_ptp->tmr_add = freq_comp; + qoriq_ptp->tmr_fiper1 = tmr_fiper1 - qoriq_ptp->tclk_period; + qoriq_ptp->tmr_fiper2 = tmr_fiper2 - qoriq_ptp->tclk_period; + + /* max_adj = 1000000000 * (freq_ratio - 1.0) - 1 + * freq_ratio = reference_clock_freq / nominal_freq + */ + max_adj = 1000000000ULL * (qoriq_ptp->clk_src - nominal_freq); + max_adj = max_adj / nominal_freq - 1; + qoriq_ptp->caps.max_adj = max_adj; + + return 0; +} + static int qoriq_ptp_probe(struct platform_device *dev) { struct device_node *node = dev->dev.of_node; @@ -332,7 +438,7 @@ static int qoriq_ptp_probe(struct platform_device *dev) if (!qoriq_ptp) goto no_memory; - err = -ENODEV; + err = -EINVAL; qoriq_ptp->caps = ptp_qoriq_caps; @@ -351,10 +457,14 @@ static int qoriq_ptp_probe(struct platform_device *dev) "fsl,tmr-fiper2", &qoriq_ptp->tmr_fiper2) || of_property_read_u32(node, "fsl,max-adj", &qoriq_ptp->caps.max_adj)) { - pr_err("device tree node missing required elements\n"); - goto no_node; + pr_warn("device tree node missing required elements, try module param\n"); + + if (qoriq_ptp_config(qoriq_ptp, node)) + goto no_param; } + err = -ENODEV; + qoriq_ptp->irq = platform_get_irq(dev, 0); if (qoriq_ptp->irq < 0) { @@ -436,6 +546,7 @@ static int qoriq_ptp_probe(struct platform_device *dev) release_resource(qoriq_ptp->rsrc); no_resource: free_irq(qoriq_ptp->irq, qoriq_ptp); +no_param: no_node: kfree(qoriq_ptp); no_memory: diff --git a/include/linux/fsl/ptp_qoriq.h b/include/linux/fsl/ptp_qoriq.h index dc3dac4..586d430 100644 --- a/include/linux/fsl/ptp_qoriq.h +++ b/include/linux/fsl/ptp_qoriq.h @@ -147,6 +147,7 @@ struct qoriq_ptp { u32 cksel; u32 tmr_fiper1; u32 tmr_fiper2; + u32 clk_src; }; static inline u32 qoriq_read(unsigned __iomem *addr)