Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp1177044pxb; Sat, 9 Jan 2021 10:04:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwDn3R9bTihNQ66TDx+hV1UkG9DjzjV/dGRip2QWowJ/jdgISj9IOJC57vGzYIVnxiWx2IP X-Received: by 2002:a50:becf:: with SMTP id e15mr9458012edk.138.1610215497007; Sat, 09 Jan 2021 10:04:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610215496; cv=none; d=google.com; s=arc-20160816; b=Ff7m2jVTOC5j/K/OdpLGhJzpufCeIRF+pC7EaN+TQFe6aeaJa0sW/CrAh5Ck8/Xgnc OHwsYbFrvqU4NSD+3Ua86kAgtQ/BYdKFwcgenlM93Fh2vNF9vnu9WZsScpg5oxCDifSl kLOk3tl0EWsPZgSVBFPG0W4PkmdTD20b7dmwV3UTvHtckUuq1fGDlMjqmSmqsfprtR3C vU0v0UG1ToUCBBSeOETJXPokTLcV+gLuBjeDSbk1+1akXhRqCWH3jGUe9b18sNaWV1CN 2z/FgX/n+2Hfkv+e6QaRerSFNsJCPayZ/LV5eN4cJymAnWHSwQIg/eKXpgYeVI7caY/I tLoQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=wRM6oG1hu8RGqKD2eM88G1tjBNP/wErLlNbuymFtCD8=; b=L6RY716jzzlDrb83YjSkOzDolDHCF63NKQNtA34f054wikpxICsWsNvBf+3s8E62g2 pwF6qLCO9jOw2maAPdpMO3Kfk6vckFX4KpVywFAdDwbzrx6ry6X0gW/1a/xk49+KL7lb r5xLDGG6uJXbB/m/uNeuPuWku+uExoH0xtkNCfOjop7JtGWcVTxOsWfWZ0y5n66DVjU0 O3j4ksAXO8EmK7ygcGg9XbLPUiMJ5+cpHQOZHfop6UqE/aGeabpX6sDCyFp1PshS0a+d gmx+kaVP9DK/ffVx0c6cYRNs5Mv0/ZsmZIPJ4kMj3MqpDjt/Cp7jGYSIkrr1cZAIrVMo /q3A== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y12si5164322edp.127.2021.01.09.10.04.19; Sat, 09 Jan 2021 10:04:56 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726020AbhAISCy (ORCPT + 99 others); Sat, 9 Jan 2021 13:02:54 -0500 Received: from hostingweb31-40.netsons.net ([89.40.174.40]:45068 "EHLO hostingweb31-40.netsons.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725951AbhAISCx (ORCPT ); Sat, 9 Jan 2021 13:02:53 -0500 Received: from [77.244.183.192] (port=62314 helo=[192.168.178.24]) by hostingweb31.netsons.net with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.93) (envelope-from ) id 1kyIZ0-005zFT-1I; Sat, 09 Jan 2021 19:02:10 +0100 Subject: Re: [RFC 2/2] clk: vc5: Add support for optional load capacitance To: Adam Ford Cc: linux-clk , Adam Ford-BE , Michael Turquette , Stephen Boyd , Rob Herring , devicetree , Linux Kernel Mailing List References: <20210106173900.388758-1-aford173@gmail.com> <20210106173900.388758-2-aford173@gmail.com> From: Luca Ceresoli Message-ID: Date: Sat, 9 Jan 2021 19:02:09 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 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 - hostingweb31.netsons.net X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - lucaceresoli.net X-Get-Message-Sender-Via: hostingweb31.netsons.net: authenticated_id: luca@lucaceresoli.net X-Authenticated-Sender: hostingweb31.netsons.net: luca@lucaceresoli.net X-Source: X-Source-Args: X-Source-Dir: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Adam, On 09/01/21 04:00, Adam Ford wrote: > On Fri, Jan 8, 2021 at 4:49 PM Luca Ceresoli wrote: >> >> Hi Adam, >> >> On 06/01/21 18:39, Adam Ford wrote: >>> There are two registers which can set the load capacitance for >>> XTAL1 and XTAL2. These are optional registers when using an >>> external crystal. Parse the device tree and set the >>> corresponding registers accordingly. >> >> No need to repeat the first 2 sentences, they are already in patch 1. > > The reason I did that was because if someone does a git log on the > individual file, they'd see the comment. While it's redundant not, it > might not be as obvious in the future when looking back. Not > everyone reviews the history of the binding, but the source files' git > logs usually have some value. However, if you want me to drop it or > rephrase it, I can do that. Makes sense, I had never considered that before. >>> +static int vc5_map_cap_value(u32 femtofarads) >>> +{ >>> + int mapped_value; >>> + >>> + /* The datasheet explicitly states 9000 - 25000 */ >>> + if ((femtofarads < 9000) || (femtofarads > 25000)) >>> + return -EINVAL; >>> + >>> + /* The lowest target we can hit is 9430, so exit if it's less */ >>> + if (femtofarads < 9430) >>> + return 0; >>> + >>> + /* >>> + * According to VersaClock 6E Programming Guide, there are 6 >>> + * bits which translate to 64 entries in XTAL registers 12 and >>> + * 13. Because bits 0 and 1 increase the capacitance the >>> + * same, some of the values can be repeated. Plugging this >>> + * into a spreadsheet and generating a trendline, the output >>> + * equation becomes x = (y-9098.29) / 216.44, where 'y' is >>> + * the desired capacitance in femtofarads, and x is the value >>> + * of XTAL[5:0]. >>> + * To help with rounding, do fixed point math >>> + */ >>> + femtofarads *= 100; >>> + mapped_value = (femtofarads - 909829) / 21644; >> >> Thanks for the extensive comment, but I am confused. Not by your code >> which is very clean and readable, but by the chip documentation >> (disclaimer: I haven't read it in full depth). > > I was confused too since the datasheet and programmers manual differ a bit. >> >> The 5P49V6965 datasheet at page 17 clearly states capacitance can be >> increased in 0.5 pF steps. The "VersaClock 6E Family Register >> Descriptions and Programming Guide" at page 18 shows a table that allows >> 0.43 pF. Can you clarify how the thing works? > > I used the Versaclock 6E doc which is based on the following: > > BIT 5 - Add 6.92pF > BIT 4 - Add 3.46pF > BIT 3 - Add 1.73pF > BIT 2 - Add 0.86pF > Bit 1 - Add 0.43pF > Bit 0 - Add 0.43pF > > Because the Datasheet starts at 9pF, the math I used, assumes these > numbers are added to 9pF. > Because the datasheet shows the increments are in .5pF increments, the > 430nF seems close. The datasheet shows 9pF - 25pF and based on the > programmer table, we could get close to 25pF by enabling all bits and > adding 9pF, however the math doesn't quite hit 25pF. > > For what it's worth I needed around 11.5pF, and with this patch, the > hardware engineer said our ppm went from around 70 ppm to around 4ppm. Did he measure what happens if you set the register according to the 0.5 pF interpretation? Does it improve? I understand the difference is probably olwer than the noise, but who knows. >>> + >>> + /* >>> + * The datasheet states, the maximum capacitance is 25000, >>> + * but the programmer guide shows a max value is 22832, >>> + * so values higher values could overflow, so cap it. >>> + */ >> >> The 22832 limit is if you assume 0.43 pF steps. Assuming 0.5 pF steps >> leads to 25000. Now I am more confused than before. > > I agree. It would be nice to get some clarification from Renesas. Definitely. Do you have access to some support from them? I don't think I have, but I can ask next week. Regards. -- Luca