Received: by 10.223.176.5 with SMTP id f5csp3144911wra; Thu, 1 Feb 2018 11:29:29 -0800 (PST) X-Google-Smtp-Source: AH8x227dyU+kJnRViPBSLfAFGMJ3+mSZ16W5TYvvBwrM1UXR8oX0lpXTzu/a5p6R8t6pPHqpOSBb X-Received: by 10.101.64.67 with SMTP id h3mr29832541pgp.168.1517513368890; Thu, 01 Feb 2018 11:29:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517513368; cv=none; d=google.com; s=arc-20160816; b=zAoTGdcJ7h+3gKASAUZXLHq9i1x3GiLl9hnZ37OWhgbA+886rb8wLggj/MzcyUFbIN I6fvjl0R3hLO40G8YXNp7w09fpPMqWtY3x+mx02eY4MQJ3lMyXp53heWk9LTLpT5v4vG qP+HkSWKK37MlZIv2F3YqyE/TKbstN5Gyl5bUSbv1MQNjWfG4v1/aoYjgzpwdHw5L2NB ywMb6uVBnrQAMdrbnojEkAXQ09q+AMt/XEjfZ4ErWBCI+q+EvgPlv960jXREHLkaY+3s biiK8VJjg9jDCXove3IZa3rlZH1h7qDj0P5KCuRPgYvl4ThudN4Zf3sVJVu/arlGaTkw J/mw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature :arc-authentication-results; bh=FCkrDCOCNAE0XI8I2cgIE4HId7P7gRhUdIwt6O7+ZWE=; b=poCFy1A0lUxwQgJPrFMq9lrzNdHDCAPSTNJOETggPfNkJ/WZYx8PIyEo2B9qglzqGG 3DWMnSagPkqwIKxFtzlNI8fRL5KMEzp2YQYgLFJYV7NsycQfUh0f2PjsSRjonUjG5F6K SNphakXSdDr5cbfeq7bFdaVCoEaCWZO6S5trIQbKG7qvfWMMXF6zPT6FwL9KE4aiFt9e pMK7NOJcIosI0b81nmjvMXtrycTcf5eiRjmsqJzjb36r4wzHlToniwPCjtJVFuMsidiW EB9cIQ9QwTR/8I4/efbgzfcZOrGk73JiUkrf9ouDPjiCYI41eu/HfHrvzp+MYpDbue37 Ivug== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=YNRiNzSz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i9si174749pgq.0.2018.02.01.11.29.13; Thu, 01 Feb 2018 11:29:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@lechnology.com header.s=default header.b=YNRiNzSz; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754497AbeBAS6E (ORCPT + 99 others); Thu, 1 Feb 2018 13:58:04 -0500 Received: from vern.gendns.com ([206.190.152.46]:52588 "EHLO vern.gendns.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754575AbeBAS5x (ORCPT ); Thu, 1 Feb 2018 13:57:53 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lechnology.com; s=default; h=Content-Transfer-Encoding:Content-Type: In-Reply-To:MIME-Version:Date:Message-ID:From:References:Cc:To:Subject:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=FCkrDCOCNAE0XI8I2cgIE4HId7P7gRhUdIwt6O7+ZWE=; b=YNRiNzSzNy6/HUAyhNX71hKJgc GNREQ+kD00OPDuFFyGu/Bn+hkBNF4gsgGVqI6jrRhLb2Pm3Up/KJrvk2KAKDzKpui81fpAnIXgdB4 cOKMRcKlp5q3aWQcjL2HzNbaeRKQ1SRVOhRw1cMX6E6S0nIkNRaRDV+IK6ryYi2Tv7EMuIS5+yUcb QeKr6tQfE99Fgo96IkEhPWl6LPOsb4/HwmKSf5mG0q5V/pEyMps8YxDkSW2F81LwJ8cHIJlTIY3SC EQcW6zIjcWLw2P7Q2m965nLnoJkipo9sKbM9nyOaCA23mn7ws8wKeXqQK7KfV3cGg2r5Z6aF34MWM NN8C9u3g==; Received: from 108-198-5-147.lightspeed.okcbok.sbcglobal.net ([108.198.5.147]:46232 helo=[192.168.0.134]) by vern.gendns.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.89_1) (envelope-from ) id 1ehK2f-002FLh-KT; Thu, 01 Feb 2018 13:57:02 -0500 Subject: Re: [PATCH v6 02/41] clk: davinci: New driver for davinci PLL clocks To: Sekhar Nori , linux-clk@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: Michael Turquette , Stephen Boyd , Rob Herring , Mark Rutland , Kevin Hilman , Bartosz Golaszewski , Adam Ford , linux-kernel@vger.kernel.org References: <1516468460-4908-1-git-send-email-david@lechnology.com> <1516468460-4908-3-git-send-email-david@lechnology.com> From: David Lechner Message-ID: <3ed91881-8753-a541-31aa-c835329141b3@lechnology.com> Date: Thu, 1 Feb 2018 12:57:52 -0600 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - vern.gendns.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lechnology.com X-Get-Message-Sender-Via: vern.gendns.com: authenticated_id: davidmain+lechnology.com/only user confirmed/virtual account not confirmed X-Authenticated-Sender: vern.gendns.com: davidmain@lechnology.com X-Source: X-Source-Args: X-Source-Dir: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/01/2018 02:01 AM, Sekhar Nori wrote: > On Saturday 20 January 2018 10:43 PM, David Lechner wrote: >> This adds a new driver for mach-davinci PLL clocks. This is porting the >> code from arch/arm/mach-davinci/clock.c to the common clock framework. >> Additionally, it adds device tree support for these clocks. >> >> The ifeq ($(CONFIG_COMMON_CLK), y) in the Makefile is needed to prevent >> compile errors until the clock code in arch/arm/mach-davinci is removed. >> >> Note: although there are similar clocks for TI Keystone we are not able >> to share the code for a few reasons. The keystone clocks are device tree >> only and use legacy one-node-per-clock bindings. Also the register >> layouts are a bit different, which would add even more if/else mess >> to the keystone clocks. And the keystone PLL driver doesn't support >> setting clock rates. >> >> Signed-off-by: David Lechner > > Looks nice and clean to me. There is still some feedback though. > > One thing missing is DIV4.5 clock. It will be nice to add that too, > mostly just because it will make the binding complete. > >> +void of_davinci_pll_init(struct device_node *node, >> + const struct davinci_pll_clk_info *info, >> + const struct davinci_pll_obsclk_info *obsclk_info, >> + const struct davinci_pll_sysclk_info *div_info, >> + u8 max_sysclk_id) >> +{ >> + struct device_node *child; >> + const char *parent_name; >> + void __iomem *base; >> + struct clk *clk; >> + >> + base = of_iomap(node, 0); >> + if (!base) { >> + pr_err("ioremap failed"); >> + return; >> + } >> + >> + if (info->flags & PLL_HAS_OSCIN) >> + parent_name = of_clk_get_parent_name(node, 0); >> + else >> + parent_name = OSCIN_CLK_NAME; > > I don't think the reference clock input handling is fully correct/flexible. > > There are two ways to provide input clock (ref_clk) to PLL. Either use > the internal oscillator with a crystal connected between OSCIN and > OSCOUT (CLKMODE = 0) or a clean clock input (CLKMODE = 1) connected to > OSCIN (OSCOUT disconnected). > > This is a board specific decision. On the LogicPD EVM, the former option > is used, on the LCDK board, the later. > > So, I think what we need is a DT property like > "ti,davinci-use-internal-osc" for the PLL. Boards can set or ignore it > and you can switch CLKMODE on or off based on that. > > Setting CLKMODE = 1 will switch off the internal oscillator (and > presumably save power), but it does not act as a mux. This explains why > not worrying about setting this correctly in current mainline still works. > > I am also not sure if we really need PLL_HAS_OSCIN since all DaVinci > SoCs set it anyway. I realize this is a bit confusing. I think that part of this comes from the fact that OSCIN is not used consistently in the TRMs. It is used as the name of the actual pin on the SoC for connecting an external clock signal or crystal. It is also used as an input to CLKMODE where it means the output of the internal oscillator rather than the external pin (some SoCs show CLKMODE as a mux with OSCIN and CLKIN, but I agree that it is not really a mux since OSCIN and CLKIN are the same external pin on the SoC - then other SoCs show OSCIN meaning only the external pin here). Furthermore, OSCIN is listed as one of the inputs of EXTCLKSRC also as one of the inputs of OBSCLK on da850-type SoCs. So, the option I went with here is that "ref_clk" is the external clock connected to the OSCIN pin and that the "oscin" clock is the clock domain _after_ CLKMODE. This matches the use of OSCIN in the TRMs where "OSCIN" is used as an input for EXTCLKSRC and OBSCLK. Also the fact that the external reference clock is sometimes called CLKSRC instead of OSCIN influenced the decision go with "oscin" being the internal (to the PLL) clock domain. I think what I should have done, though, is named PLL_HAS_OSCIN as PLL_HAS_CLKMODE instead. I think what you are missing here is that PLL_HAS_OSCIN (or PLL_HAS_CLKMODE) only means that the PLL _has_ PLLCTL[CLKMODE]. It does _not_ mean that we set (or clear) PLLCTL[CLKMODE]. On SoCs with two PLLs, only one of them has the PLLCTL[CLKMODE] bit (and therefore the PLL_HAS_OSCIN flag) and the output of this is shared by both PLLs, e.g. Figure 7-1. PLLC Structure in the AM1808 TRM (spruh82c). So, the clock tree in Linux ends up looking like this: ref_clk - the external clock - aka CLKSRC +-oscin - internal clock domain after CLKMODE - shared by both PLLs +-pll0_extclksrc +-pll0_prediv +-pll0_auxclk +-pll0_obsclk - via the OSCSRC mux +-pll1_pllen +-pll1_pllout +-pll1_obsclk - via the OSCSRC mux Clocks beyond two levels deep are omitted for brevity. It should be easy to see the correlation here Figure 7-1 with the exception that in Figure 7-1 "OSCIN" has the meaning of "the physical pin on the chip" (which Linux calls "ref_clk") and there is no clear label in Figure 7-1 of what the clock domain after PLLCTL[CLKMODE] is called (which Linux calls "oscin"). Sure, it would work just fine if we left "oscin" out of the picture, but it simplifies the driver implementation by having a known "oscin" clock that is fully controlled by the clock driver code instead of having to pass the user-supplied "ref_clk" around a bunch of places. And, we could try to call it something other than "oscin" to try to avoid confusion, but then you will just cause confusion in other places (which could be less total confusion, so I am open to change here). --- Switching topics to CLKMODE and DT... There is a "ti,clkmode-square-wave" property in the proposed DT bindings that does exactly what you have suggested, except the logic is reversed. When omitted, it assumes the use of a crystal oscillator. I believe this is the most common configuration, which is why I made it the default instead of the other way around.