Received: by 10.223.185.116 with SMTP id b49csp2328183wrg; Thu, 15 Feb 2018 09:55:05 -0800 (PST) X-Google-Smtp-Source: AH8x224Go8kmbxyQ7YrvgdwMHZBwqlzUYBV/tss8JXnp1bTCiLsw62x5vK+80hTdwNQpIjSz4KOB X-Received: by 10.167.128.6 with SMTP id j6mr3392907pfi.56.1518717305412; Thu, 15 Feb 2018 09:55:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518717305; cv=none; d=google.com; s=arc-20160816; b=0ZG32KfS1ZUUBMDdGWD+gkXIMSUPvcv5WJReY45wGQkA4MyMNxrOhg2AutsmPXFr4H 5Z27NyWPV5UwE+FXwDhI0B69qB3mqSbYJalDYYa39l59oGrnKRNd50/9NOQOUEk/kT5y GlovYTagRZtmA0OhggE5vqBOLniV0p36UBy7s1IR4fTHJaNtp/WYixjlYPYkUCGZCfMQ BsQbbHfqepd95QYBV5LXGgNT2ES7gHteo5xoO8D4rLopqUe30S24gayjhvMbwRwbMBHg xb9K2JtBzX3ZH5ogvkMlaNVYywZVeGH6kDjIwR4rJt9oA2NN4V19S8mr3TgQyxSgMuTY Sthg== 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=fbgHwc6qxTGfjWZlEIKY4TsabkSuWYsSGWLLxPC089c=; b=PYpCrMknbWoQ2fyTgYCcERZboucaC9tmAowTv3oSwoHPGwGPgvQ0inH3m9fJIO9V6+ nRGk1MHYXcvy+rfoQDV3nQC5VY7QtH/oZ5OCoiLyPPlCFOG9FFlhLD4PZqvmbIdRDjn5 GL8O7XoQt3koPQ/bdQMRQYsRa5M8IiaNiVzvgajC3b8RrVBKBX8jPh37Fq32Hv/4op3x RFjM99iiq7cWvI7CWqivmHrTZ0Rc2WhqblLsJlE2XspH3AT4KnXEzqqjDIt80rzemj4f rELDSFvcni87MSGTPUgj58BvV28H3aW3tkeqX7zxagLQIOMe0DGMIO2k17dfolognhvu rXKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NiN7Fe+H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z123si3055462pgb.280.2018.02.15.09.54.50; Thu, 15 Feb 2018 09:55:05 -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=pass header.i=@gmail.com header.s=20161025 header.b=NiN7Fe+H; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1165895AbeBORxv (ORCPT + 99 others); Thu, 15 Feb 2018 12:53:51 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:55825 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1165772AbeBORxs (ORCPT ); Thu, 15 Feb 2018 12:53:48 -0500 Received: by mail-wm0-f67.google.com with SMTP id h74so2381358wme.5; Thu, 15 Feb 2018 09:53:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=fbgHwc6qxTGfjWZlEIKY4TsabkSuWYsSGWLLxPC089c=; b=NiN7Fe+HHLAlnW4Q3pL/BLrnsgHDi/tEnXbp01fKJAddUL/hO+H3JDNyQup4Wcs4Zo BGC6C/nTyJjEz3Y3ZKVQlhVsqm3UvLjHkPPQNi8dzqJWar9OKvmNH/8cvchHN0t61zzb wDZYv1VEZ3K0zd67NO55BXUtiZL8zO7diFE4vn+QiZDNTD7W4VsbewzjmhuUqdFobJ2/ IokEMOcmCkAyPTYNQ4/W8UftKp9/bIWqjlYBJzCwt4mgODS3HuQUi3uVYLpe3BIoS8UP o74wSrVywKuMtyE0AIiacL32QPtnLZt0mxW25hCR6bBg8hBd3nnJJP3qf4uAPG2Gk3mc 1/uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=fbgHwc6qxTGfjWZlEIKY4TsabkSuWYsSGWLLxPC089c=; b=RoRM0eG3gqNs3EdjDfs3qb6yuOVKOl+Bd1T8+NMxM7kfqAGdaziX9+abCGQZdzZJzI 6uRDG+0iC8ZY/Xv44aAnPqDnWTrX06M1xgXp5Docre0/IgjB4K8ukKgqaX/UjEV+UQn0 uaRQQUxUvXdrWq1AP5Xo+TkGt1BXQbI3obA4UHJEhqL5IfdYZvhgRx3ed/siQjTX1fJC RJ0CDJPXFk/5/hVxekihjppRuVpA5N6az5USikaUgSthRpqm573jV9jO4BkH6QPBHnFc Pzop8t8B2nBNeGug0dXc39BREmM4YdpNjzS1A5v8N1wdsvY/3v+zCslDstFrFhRe+i9G t4oQ== X-Gm-Message-State: APf1xPC8utGQBOliYkAoA9kBvhD3A9y0W0dxSIr6wR9ueLnspNr/lXoM Ng/HNaNsmRZcM7XeHY5AZQCyQ8c1 X-Received: by 10.28.135.142 with SMTP id j136mr2944602wmd.33.1518717227023; Thu, 15 Feb 2018 09:53:47 -0800 (PST) Received: from [192.168.2.73] (p578F04D2.dip0.t-ipconnect.de. [87.143.4.210]) by smtp.gmail.com with ESMTPSA id u3sm4743041wre.39.2018.02.15.09.53.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 09:53:46 -0800 (PST) Subject: Re: [PATCH v3] rtc: ac100: Fix ac100 determine rate bug To: Maxime Ripard Cc: wens@csie.org, a.zummo@towertech.it, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, linux-sunxi@googlegroups.com, linux-rtc@vger.kernel.org References: <20180214135612.21356-1-embed3d@gmail.com> <20180215141154.monvwx25awwetqrc@flea.lan> From: Philipp Rossak Message-ID: <00ece3d8-52ac-c51d-1867-97f7fd84dadf@gmail.com> Date: Thu, 15 Feb 2018 18:53:45 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <20180215141154.monvwx25awwetqrc@flea.lan> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 15.02.2018 15:11, Maxime Ripard wrote: > On Wed, Feb 14, 2018 at 02:56:12PM +0100, Philipp Rossak wrote: >> This patch fixes a bug, that prevents the Allwinner A83T and the A80 >> from a successful boot. >> >> The bug is there since v4.16-rc1 and appeared after the clk branch was >> merged. > > Out of curiosity, which patch has introduced this? I couldn't find any > obvious match. > I wasn't also n >> You can find the shortend trace below: >> >> Unable to handle kernel NULL pointer dereference at virtual address >> 00000000 >> pgd = (ptrval) >> [00000000] *pgd=00000000 >> Internal error: Oops: 5 [#1] SMP ARM >> Modules linked in: >> CPU: 0 PID: 49 Comm: kworker/0:1 Not tainted 4.15.0-10190-gb89e32ccd1be #2 >> Hardware name: Allwinner sun8i Family >> Workqueue: events deferred_probe_work_func >> PC is at clk_hw_get_rate+0x0/0x34 >> LR is at ac100_clkout_determine_rate+0x48/0x19c >> >> [ ... ] >> >> (clk_hw_get_rate) from (ac100_clkout_determine_rate+0x48/0x19c) >> (ac100_clkout_determine_rate) from (clk_core_set_rate_nolock+0x3c/0x1a0) >> (clk_core_set_rate_nolock) from (clk_set_rate+0x30/0x88) >> (clk_set_rate) from (of_clk_set_defaults+0x200/0x364) >> (of_clk_set_defaults) from (platform_drv_probe+0x18/0xb0) >> >> To fix that bug, we first check if the return of the >> clk_hw_get_parent_by_index is non zero. If it is zero we skip that >> clock parent. >> >> The BUG report could be found here: https://lkml.org/lkml/2018/2/10/198 >> >> Fixes: 04940631b8d2 ("rtc: ac100: Add clk output support") >> >> Signed-off-by: Philipp Rossak >> --- >> >> Changes in v3: >> * add information when the bug appeared >> * make the comment more clear >> Changes in v2: >> * add tag Fixes: ... to commit message >> * add comment to if statement why we are doing this check >> >> drivers/rtc/rtc-ac100.c | 19 ++++++++++++++++++- >> 1 file changed, 18 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c >> index 8ff9dc3fe5bf..2412aa2e8399 100644 >> --- a/drivers/rtc/rtc-ac100.c >> +++ b/drivers/rtc/rtc-ac100.c >> @@ -183,7 +183,24 @@ static int ac100_clkout_determine_rate(struct clk_hw *hw, >> >> for (i = 0; i < num_parents; i++) { >> struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i); >> - unsigned long tmp, prate = clk_hw_get_rate(parent); >> + unsigned long tmp, prate; >> + >> + /* >> + * The clock has two parents, one is a fixed clock which is >> + * internally registered by the ac100 driver. The other parent >> + * is a clock from the codec side of the chip, which we >> + * properly declare and reference in the devicetree and is >> + * not implemented in any driver right now. >> + * If the clock core looks for the parent of that second >> + * missing clock, it can't one that is registered and >> + * returns NULL. >> + * Thus we need to check if the parent exists before >> + * we get the parent rate. >> + */ >> + if (!parent) >> + continue; > > I'm sorry, but I still don't get it. When you register that clock, you > will give it two parents. Why would that change during the life of the > clock? > > This really looks like a workaround rather than an actual fix. > > Maxime > I agree this is more a workaround! A proper solution/fix would be to define the devicetree correct like this: diff --git a/arch/arm/boot/dts/sun8i-a83t-bananapi-m3.dts b/arch/arm/boot/dts/sun8i-a83t-bananapi-m3.dts index 6550bf0e594b..6f56d429f17e 100644 --- a/arch/arm/boot/dts/sun8i-a83t-bananapi-m3.dts +++ b/arch/arm/boot/dts/sun8i-a83t-bananapi-m3.dts @@ -175,11 +175,18 @@ compatible = "x-powers,ac100-rtc"; interrupt-parent = <&r_intc>; interrupts = <0 IRQ_TYPE_LEVEL_LOW>; - clocks = <&ac100_codec>; + clocks = <&ac100_rtc_32k>; #clock-cells = <1>; clock-output-names = "cko1_rtc", "cko2_rtc", "cko3_rtc"; + + ac100_rtc_32k: rtc-32k-oscillator { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <32768>; + clock-output-names = "ac100-rtc-32k"; + }; }; }; }; What do you think about that solution? I already tested it and it looks like it is working. Philipp