Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp1194263img; Tue, 19 Mar 2019 02:28:19 -0700 (PDT) X-Google-Smtp-Source: APXvYqxVH3/a/SSrXvMgGqpClZh6VuOAFgBlThIwANjge1/mC9OJOuRh4lT5qEEAhKKPo2jCqvuy X-Received: by 2002:a62:b618:: with SMTP id j24mr1203886pff.120.1552987698969; Tue, 19 Mar 2019 02:28:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552987698; cv=none; d=google.com; s=arc-20160816; b=CELdneIxw8sh47BIlOCVVUult6xbZZM5lwO/8Jtw4Tvn/yopFrqrVX9qwmJiL7ZuMt Rcux6fadKG+svixG0EN6tybE9NjMDqk/l8FJSLlz8e0msexXC5he5k39oq08V014b7PD 5iXRzZYyRZ9mJWx0XSbdZZ62sZ7ea1ZsNlNb3ES+E1P2LQagX27pUDwW7y8pGhmPCUjK lEJHhs7cQSa9Jy1qNNwOEFwbleHCN2nPNSbO64fxGEgdTE68ixBwwHX6EcuAw3Ezneic y+GQ9dDdiCDjJ/fvZirWdP8pParJI5d3NYENFU3HSzRFwnDNQoc0UvHYZSzZ5yfbLZWU nC9w== 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:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=Jra424Dp373u9egLT7cs3suTHlRQTxWaaAhBRmIn2rk=; b=hU4uDg6yVHTdQA4PG/LSbfSwMx7tM8sASQCoCVA5oGbnlST2W26R+vLUDo6k0bzSo9 lrkHbJ9jCPggLThTK9Nwkl0NzCeb8AqSB1LlbjDE+ZxRixqonk5x9Nm5DeYs4pT75nct 7hS1MdkwmcWjUZGu/vg3oJ/BP4BkW1rU9BZL2VbVGWszJ+Y4n0SP02ICyyEB44mjWNyD gT0CViG/GhuC0F/xSf5fr296T8g3ptB58bzNPrws5hAAQpK/52euOC1YS7ZJmqZ+qDpW FAKIavSjEU9hoS53FW5/pHuDxADnavjUpUf3q5XUbUzhAqKQjokjpF6XpNr6gy4AxbFD WTFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=K4uKRz91; 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 n9si11212037pgc.472.2019.03.19.02.28.03; Tue, 19 Mar 2019 02:28:18 -0700 (PDT) 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=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=K4uKRz91; 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 S1727442AbfCSJZx (ORCPT + 99 others); Tue, 19 Mar 2019 05:25:53 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53610 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725906AbfCSJZx (ORCPT ); Tue, 19 Mar 2019 05:25:53 -0400 Received: by mail-wm1-f66.google.com with SMTP id e74so15774326wmg.3 for ; Tue, 19 Mar 2019 02:25:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=message-id:subject:from:to:cc:date:in-reply-to:references :user-agent:mime-version:content-transfer-encoding; bh=Jra424Dp373u9egLT7cs3suTHlRQTxWaaAhBRmIn2rk=; b=K4uKRz91md6r9JeM9rv1sYesvETA80w9gQoUtNS5y4wE8bUakbAtHPgPSf9MuSLmbx VNmNAzx83GvvJQWVxm8EEt76rkEmYhwIa+eRfUYI89xiYQAtuHeOZYG9qv5Z87yP9Pyt LNYqxx40Jtov1Az4Pv+ReQL8OCC/nM535J4FYQX4+vUtvYDB5/DlLG6YYNize8r5Ym3j dnoArgRhycF8IW9oBbuqDmfCKGKaWOsKYIv/D3GgMQ7wlVulyleAI5NhH/kQX2Py8J1E JzUhvCuKqFbnPiNVc3ejbcEQeN/dhO8KpsuDAffiqAdfAgH5G0+6ca+sZKBnnXZB8a/C 5d/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:in-reply-to :references:user-agent:mime-version:content-transfer-encoding; bh=Jra424Dp373u9egLT7cs3suTHlRQTxWaaAhBRmIn2rk=; b=CurZbdr8HiB+9h3BQ4Je5jkOouTuoiBPN+AOsVqvs7O6E89pY9C/QEjANL7re4Npvd w1E2nKXLbNbSnNaIdqK49Teb1t6U0fSwJPsiJgnuZ52Lp9lNB864vaau7xMy3Xx2Cq9j HzjqO2JF+1WahcpzaXJ/lM5MPh2hgsFMkqPwUDSh0VRD255WHNvccu52JyjzHKfJe88a WwF0UWtB6iiVzpY5KQoXBaK+GC/2T8xCGSBGS5+MQXkcDojJWuJ/RR+/OOJzv8sNDv35 k1rmw7HxNY+GqPTvu5eVTsH4KzRkNgV2R26+K55mX+VWl4lvHi6kNpoMjrgiURVMelfr jTrA== X-Gm-Message-State: APjAAAXeaHuOZfN5J87Bt77IxLQkDQiRN//FpywL3geiW7YDT64XAKez LOHIBZj7/v07DSTvpOjYKyYrUA== X-Received: by 2002:a7b:c008:: with SMTP id c8mr2583698wmb.98.1552987551203; Tue, 19 Mar 2019 02:25:51 -0700 (PDT) Received: from boomer.baylibre.com ([2a01:e34:eeb6:4690:106b:bae3:31ed:7561]) by smtp.gmail.com with ESMTPSA id f10sm1758721wml.23.2019.03.19.02.25.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Tue, 19 Mar 2019 02:25:50 -0700 (PDT) Message-ID: Subject: Re: [PATCH v2 6/8] clk: Allow parents to be specified without string names From: Jerome Brunet To: Stephen Boyd , Michael Turquette Cc: linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, Miquel Raynal , Russell King , Jeffrey Hugo , Chen-Yu Tsai Date: Tue, 19 Mar 2019 10:25:48 +0100 In-Reply-To: <155267021941.20095.16439182841724325601@swboyd.mtv.corp.google.com> References: <20190226223429.193873-1-sboyd@kernel.org> <20190226223429.193873-7-sboyd@kernel.org> <3e6aa4c392ccdd3bac76b556645139536e61e5e6.camel@baylibre.com> <155267021941.20095.16439182841724325601@swboyd.mtv.corp.google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.30.5 (3.30.5-1.fc29) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2019-03-15 at 10:16 -0700, Stephen Boyd wrote: > Quoting Jerome Brunet (2019-03-15 03:01:53) > > On Tue, 2019-02-26 at 14:34 -0800, Stephen Boyd wrote: > > > --- > > > drivers/clk/clk.c | 260 ++++++++++++++++++++++++++--------- > > > include/linux/clk-provider.h | 19 +++ > > > 2 files changed, 217 insertions(+), 62 deletions(-) > > > > Sorry for the delay. > > > > With the fix you sent to Jeffrey > > Tested by porting the aoclk controller of Amlogic g12a SoC. > > This allowed to test > > * hws only table > > * parent_data with a mix of hw pointers and fw_name (with different input > > controllers and also an input that is optional and never provided) > > > > Tested-by: Jerome Brunet > > > > With the small comment below > > > > Reviewed-by Jerome Brunet > > > > Awesome. Thanks! I need to Cc Rob H to hopefully get an ack on the > concept of relying on DT so I'll resend this series again next week. It > would also be nice if I can throw in a couple more patches to let > drivers specify a DT node when registering a clk if they don't have a > struct device on hand and let drivers lookup with clk_lookups somehow. > > > > diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c > > > index 937b8d092d17..3d01e8c56400 100644 > > > --- a/drivers/clk/clk.c > > > +++ b/drivers/clk/clk.c > > > @@ -39,6 +39,13 @@ static LIST_HEAD(clk_notifier_list); > > > > > > > [...] > > > > > > > > +static int clk_cpy_name(const char *dst, const char *src, bool must_exist) > > > +{ > > > + if (!src) { > > > + if (must_exist) > > > + return -EINVAL; > > > + return 0; > > > + } > > > + > > > + dst = kstrdup_const(src, GFP_KERNEL); > > > + if (!dst) > > > + return -ENOMEM; > > > + > > > + return 0; > > > +} > > > + > > > +static int clk_core_populate_parent_map(struct clk_core *core) > > > +{ > > > + const struct clk_init_data *init = core->hw->init; > > > + u8 num_parents = init->num_parents; > > > + const char * const *parent_names = init->parent_names; > > > + const struct clk_hw **parent_hws = init->parent_hws; > > > + const struct clk_parent_data *parent_data = init->parent_data; > > > + int i, ret = 0; > > > + struct clk_parent_map *parents, *parent; > > > + > > > + if (!num_parents) > > > + return 0; > > > + > > > + /* > > > + * Avoid unnecessary string look-ups of clk_core's possible parents by > > > + * having a cache of names/clk_hw pointers to clk_core pointers. > > > + */ > > > + parents = kcalloc(num_parents, sizeof(*parents), GFP_KERNEL); > > > + core->parents = parents; > > > + if (!parents) > > > + return -ENOMEM; > > > + > > > + /* Copy everything over because it might be __initdata */ > > > + for (i = 0, parent = parents; i < num_parents; i++, parent++) { > > > + if (parent_names) { > > > + /* throw a WARN if any entries are NULL */ > > > + WARN(!parent_names[i], > > > + "%s: invalid NULL in %s's .parent_names\n", > > > + __func__, core->name); > > > + ret = clk_cpy_name(parent->name, parent_names[i], > > > + true); > > > + } else if (parent_data) { > > > > While testing, I mistakenly left both parent_names and parent_data. I was > > surprised that parent_data did not take precedence of parent_names. > > > > Maybe it should ? (... but I understand we are not supposed to provide both) > > I don't think we can. We have a problem where drivers don't initialize > the init structure properly, opting to just throw it on the stack and > leave junk in there that they overwrite. We'd have to go through all the > init structures and initialize them. I suppose we could make a macro for > that: > > DECLARE_CLK_INIT_DATA(init); > > or something like that that does this. We could bury a magic number in > there under some debug option too so that we can make sure drivers are > doing this properly. Otherwise we're left to doing these weird tricks > like I've done here. > > Regardless. I'll have to add a comment to this fact in the code. Thanks. > > > > + parent->hw = parent_data[i].hw; > > > + ret = clk_cpy_name(parent->fw_name, > > > + parent_data[i].fw_name, false); > > > + if (!ret) > > > + ret = clk_cpy_name(parent->name, > > > + parent_data[i].name, > > > + false); > > > + } else if (parent_hws) { > > > + parent->hw = parent_hws[i]; > > > + } else { > > > > Maybe there should also some kinda of check to verify if more than one option > > (among hws, parent_data and parent_names) was provided and throw a warn ? > > > > Could be useful with drivers move away from parent_names ? > > Same thing. It would be nice but we're sort of unable to do so unless we > do what I suggest above. Should we do it? > I was not thinking about anything complicated: * Among the 3 pointers, just throw a warn if more than one is not NULL * In the if/elseif/else, I would have put parent_data before parent_names Nothing critical about that comment though