Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5125994imu; Tue, 29 Jan 2019 13:16:33 -0800 (PST) X-Google-Smtp-Source: ALg8bN4W4T6ObSIbHbXKSPFJPUhCcglogfa/T2dCIL9E7XBkJcgiMSgIJWbECnWz/l+DavN+chuN X-Received: by 2002:a17:902:784d:: with SMTP id e13mr28083948pln.188.1548796593649; Tue, 29 Jan 2019 13:16:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548796593; cv=none; d=google.com; s=arc-20160816; b=q14mcvczTGTesHh1wwT9MTIVgcRu2DNe+HnoUZhqjW70Bp1PRb1pQZiimXBjxdUS6Y GG8/Eh5v5bMoBIWp3YMfnhwEEO0Hx6yDONQCm6MqRJ1gnb5YS6Lf8ptYztPiS16UUXly hkHm6rt/UhVG1iLg/DFFFmKOnsDVNdPj5LyQAEeQlAF15euDD0E9DfYn+dBev4cJLpxS ZlGEHLPcLk7oj8M8yMkHi7LKFf4NuDpGgU0eU8jPz7gHFGhpr8/Ev4xDj1ZBUi932+U1 DyJX0TH+83FpwkXTSkcit951n7vzkjIr452CPdxCjtHEp5XKOdGrrDlLj7rx0WrO77U8 RnSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:to:message-id:in-reply-to:from:cc :user-agent:references:subject:content-transfer-encoding :mime-version:dkim-signature; bh=Kb2BAXteXzdCjKYOTZ54ORvysDSW8GHgHBPHj9Xkc1k=; b=O8gXXPnL5Wx816loycvWxUAjT3T+5NWAFvH9IRY8lmI/N9eSzO7Eay6iA5p8ByT5dS +iWYSQD/ViqDdurfuWDozT+JRQ4WUdQBw/pw+O9Kq711DiPE9ExXWOKvAGOkXKeilvD3 LCcEm0FE1uZssM7Re8bTK1NFEnWHEdMgUXKfeXUIRuNKz6AYzbLPm/GESnony1ItHv3r tdLriB0nB7gn6C7zur3WZCkvZRWD0sppO2CGhS7WrFK/WRR+h0mzFHv+gGSSfMdTSoVq phd0+Cd9SOPgeeATKfALfVKh78LlOWRXhOI10OuToX1BvUCkHSUAfwE9kXKv1jBATs2A fuHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=f1PhKEbN; 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=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id be9si7181421plb.143.2019.01.29.13.16.17; Tue, 29 Jan 2019 13:16:33 -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=@kernel.org header.s=default header.b=f1PhKEbN; 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=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729497AbfA2VPr (ORCPT + 99 others); Tue, 29 Jan 2019 16:15:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:55058 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727488AbfA2VPq (ORCPT ); Tue, 29 Jan 2019 16:15:46 -0500 Received: from localhost (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2BC0120881; Tue, 29 Jan 2019 21:15:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1548796545; bh=OzERr/HuAbo9/0J3smto0XPrPizi57aChpdG0oRQ000=; h=Subject:References:Cc:From:In-Reply-To:To:Date:From; b=f1PhKEbNu7ZiZ4ckO9XeQ+5UUxpd5P9UtzvXvrsOeFophlPtBMFG2cur24LVMrkku boieqnci0NGBWlG/G/fRF/WnK2AkN/ZxnvMhYndPyDZYgOHft6FBqVFuEGz9mpX085 SXTuOOW+PkIwLfnLNaNXLF8giRszDY3sB7nGIMpc= Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH 2/9] clk: Introduce get_parent_hw clk op References: <20190129061021.94775-1-sboyd@kernel.org> <20190129061021.94775-3-sboyd@kernel.org> User-Agent: alot/0.8 Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Miquel Raynal , Russell King From: Stephen Boyd In-Reply-To: Message-ID: <154879654428.136743.10048771201181501034@swboyd.mtv.corp.google.com> To: Jerome Brunet , Michael Turquette Date: Tue, 29 Jan 2019 13:15:44 -0800 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Quoting Jerome Brunet (2019-01-29 01:34:38) > On Mon, 2019-01-28 at 22:10 -0800, Stephen Boyd wrote: > > --- > > drivers/clk/clk.c | 117 ++++++++++++++++++++++++++--------- > > include/linux/clk-provider.h | 9 +++ > > 2 files changed, 96 insertions(+), 30 deletions(-) > >=20 > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > > index 01b36f0851bd..5d82cf25bb29 100644 > > --- a/drivers/clk/clk.c > > +++ b/drivers/clk/clk.c > > @@ -2242,14 +2242,84 @@ struct clk *clk_get_parent(struct clk *clk) > > } > > EXPORT_SYMBOL_GPL(clk_get_parent); > > =20 > > -static struct clk_core *__clk_init_parent(struct clk_core *core) > > +static struct clk_core * > > +__clk_init_parent(struct clk_core *core, bool update_orphan) > > { > > u8 index =3D 0; > > + struct clk_hw *parent_hw =3D NULL; > > =20 > > - if (core->num_parents > 1 && core->ops->get_parent) > > - index =3D core->ops->get_parent(core->hw); > > + if (core->ops->get_parent_hw) { > > + parent_hw =3D core->ops->get_parent_hw(core->hw); > > + /* > > + * The provider driver doesn't know what the parent is, > > + * but it's at least something valid, so it's not an > > + * orphan, just a clk with some unknown parent. > > + */ >=20 > I suppose this is the answer the discussion we had last year. I'm not sur= e it > answer the problem. In the case I presented, we have no idea wether the > setting is valid or not. >=20 > We can't assume it is `at least something valid`, the value in the mux is= just > something we can't map. So if you can't map the value in the mux how is that valid? I would think the mux knows what indexes it has strings for, and if the index isn't in there it's invalid. Is that not the case here? >=20 > Aslo, could you provide an example of what such callback would be, with c= lk- > mux maybe ? Sounds fair. I can convert the clk-mux API to this op. It may be that we need to make clk_hw_get_parent_by_index() return an error pointer instead of NULL if it can't find the clk so that we can move the error codes through this new API. >=20 > I don't get how a clock driver will keep track of the clk_hw pointers it = is > connected to. Is there an API for this ? clk-mux must access to clk_core = to > explore his own parent ... which already does not scale well, expect if we > plan to expose clk_core at some point ? No we don't want to expose clk_core to provider drivers. It is only for the use of the clk framework and it's not exposed even as an opaque pointer. We have that core member of clk_hw but that's just to traverse from clk_hw to clk_core, and not for anything else. >=20 > > + if (!parent_hw && update_orphan) > > + core->orphan =3D false; > > + } else { > > + if (core->num_parents > 1 && core->ops->get_parent) >=20 > I still get why, when num_parents =3D=3D 1, it is OK to call get_parent_h= w() and > no get_parent(). It does not seems coherent. I'd rather not change behavior of existing code in this patch, so I took the route of adding another callback with semantics that we can define now because there aren't any users. The difference between the two is made intentionally. >=20 > > + index =3D core->ops->get_parent(core->hw); > > + > > + parent_hw =3D clk_hw_get_parent_by_index(core->hw, index); > > + } > > + > > diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h > > index 60c51871b04b..8b84dee942bf 100644 > > --- a/include/linux/clk-provider.h > > +++ b/include/linux/clk-provider.h > > @@ -155,6 +155,14 @@ struct clk_duty { > > * multiple parents. It is optional (and unnecessary) for c= locks > > * with 0 or 1 parents. > > * > > + * @get_parent_hw: Queries the hardware to determine the parent of a > > clock. The > > + * return value is a clk_hw pointer corresponding to > > + * the parent clock. In short, this function translates the > > parent > > + * value read from hardware into a pointer to the clk_hw for= that > > clk. > > + * Currently only called when the clock is initialized by > > + * __clk_init. This callback is mandatory for clocks with > > + * multiple parents. It is optional for clocks with 0 or 1 > > parents. > > + * >=20 > The comments above could imply that get_parent() and get_parent_hw() are = both > mandatory if num_parent > 1. (I don't think so but) Is this your intent ? It is not the intent. I'll update the docs. Thanks.