Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp575516pxb; Fri, 22 Apr 2022 07:10:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4okj7yyYNF4b5NcWIQvH+fBm4xPVqZUt8TfbLh1mBm9yPfQr5w5AJu/yXgtG+eznHAFIv X-Received: by 2002:a17:907:7ea3:b0:6e8:92eb:3dcc with SMTP id qb35-20020a1709077ea300b006e892eb3dccmr4395568ejc.75.1650636659199; Fri, 22 Apr 2022 07:10:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650636659; cv=none; d=google.com; s=arc-20160816; b=gDNG3HFogBmTh8iiKjGboPzPnoxvVSOVY4c96wm4EvPNA+xtuEKAiOd9Hc9xqCp6Nl NCe+PYUGY9uNvqXXKfmRAN50ovp5TEampmgAUmHV/ZoDGxeJJBX9Dz5lJEtcmvOTmeSO fwP4xNr47LYtc6NZnkfnCq/24Rw2pSJJT+XrmH0HUWQhELSiz3V87NiebE6yeYh7ECix OPwMuHDipKFxklr5g/cvlh1MR3gZUsf66TKfYYPbTcmQhbIcZzPOpSluVStEEtW1HeyS AltsisP6ytdFz8bQa92ITNYybYDaYrS6hK1XQNZHeQnfLEwEU79sm3aLrz/lvZjeJ+nD pEsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=R7jGqyYJMUVo08fKH+szIIQUXUxBVoUo95cPDD/inJ4=; b=SY8cDR3Hr/zfbOFEykVg4WRbKqMSYl4Uu14QjRLHHvlrxCQ9pBAZC7u6Uym8uu82qb 68BYYdyLwXPHqTvPtSordY2SC7V+xRGqTyXGKzCEkqUBSkIgA+GSpY90GyRg1IBgAxCJ 9DKkNguASocD5SmtllWHwqhtFMi+35iLj4sfUxP4zwqVoUAbzmVGFp9G4y11rqVyf9uJ GUx+wOs0zvY0365mJzOGqeWmf3pIdg5JoXVvNVhTLGYDaH4cdgXarspVZt0H31U/MRLs 59zyCUOx/dqzfA4suR6B2a4Ja0GJ5yS3OyBVvzXMh7wJjhKNcxFCQCRRRcq6s9CKF1wl +OcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I9zUiMzd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ho10-20020a1709070e8a00b006f361f9f173si1216330ejc.164.2022.04.22.07.10.35; Fri, 22 Apr 2022 07:10:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=I9zUiMzd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443862AbiDVERp (ORCPT + 99 others); Fri, 22 Apr 2022 00:17:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230232AbiDVERj (ORCPT ); Fri, 22 Apr 2022 00:17:39 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC4494EA0F for ; Thu, 21 Apr 2022 21:14:47 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-2edbd522c21so72847597b3.13 for ; Thu, 21 Apr 2022 21:14:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=R7jGqyYJMUVo08fKH+szIIQUXUxBVoUo95cPDD/inJ4=; b=I9zUiMzdx0x2AlBPle+xfx0YbHSjxYYQzMOxKnLzS5AN60wHrUGdTUNXRzRKZNWmRB 9/3o8X4D7FM5xD5BeHyIcf8ZQ9PSZkS6eg6Sku3+6xyQH3NVx54VTYCYGsVZsyq3yAZz vrLRrZwZGIuU8vS6PrH96FzJkh+IepxJW45pY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=R7jGqyYJMUVo08fKH+szIIQUXUxBVoUo95cPDD/inJ4=; b=utaqEMvv4KYV6For2gZnpews5Iuq+e9eV+M/yDCzLERbxkz22XkSbwrLIDm4J3i24d Fyx3AV9HrOCThcJA9/6Rg0Tv9xH3UNZ++N5G/cNh3VL8YlYiehFLSdux+d/EL2gHfwas Y/JmBYP5HKFzOlcaj7vtHEkRUG+3bkyOQrS2sRzGrnaND9QiZ5gQcPXGwYldmqRirnca g1RVWizBO1tSgykyTUdx4Pc9+hB4xJMoSMdEe0lpYW3Hid7dw5AArOVjbqowNzo8Smjr utIiPqMSTOh75qJJGMGOE7e2Cko5hvEaDNLK6lEnAfzmQZwTEeoxtRO7kEfwHsbnJt5k yEHA== X-Gm-Message-State: AOAM530GQFO9THdGtIEAmdw4KMrQ5dmLiuDkpgPJ7wrZxX4S2OU8H7LJ JQ1G7niPGhZBEXl4MjlqQWZdJKdKpwQY2BzIFI1b/g== X-Received: by 2002:a81:ad1f:0:b0:2f4:da5b:5133 with SMTP id l31-20020a81ad1f000000b002f4da5b5133mr3074648ywh.105.1650600887150; Thu, 21 Apr 2022 21:14:47 -0700 (PDT) MIME-Version: 1.0 References: <20220419081246.2546159-1-wenst@chromium.org> <3591fcc1-d34a-b40a-4e78-edcf9d2ddf08@collabora.com> <20220422014044.16530C385A7@smtp.kernel.org> In-Reply-To: <20220422014044.16530C385A7@smtp.kernel.org> From: Chen-Yu Tsai Date: Fri, 22 Apr 2022 12:14:36 +0800 Message-ID: Subject: Re: [RFC PATCH 0/7] clk: mediatek: Move to struct clk_hw provider APIs To: Stephen Boyd Cc: AngeloGioacchino Del Regno , Michael Turquette , Chun-Jie Chen , Miles Chen , Rex-BC Chen , Matthias Brugger , linux-clk@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Apr 22, 2022 at 9:40 AM Stephen Boyd wrote: > > Quoting Chen-Yu Tsai (2022-04-20 23:05:10) > > > > Not exactly. All the clocks in the MTK drivers are allocated at runtime, > > so we can't use clk_parent_data to point to not-yet-allocated clk_hw-s. > > Instead we'll need to have > > > > struct mtk_clk_parent_data { > > unsigned int clk_id; /* Match CLK_XXX_YYY from dt-binding headers */ > > ... /* remaining fields same as mtk_clk_parent_data */ > > }; > > > > and create the actual clk_parent_data at runtime by looking up clk_id in > > the set of already registered clks: > > > > int mtk_clk_register_XXX(..., struct mtk_clk_parent_data *pdata, > > struct clk_hw_onecell_data *clk_data) { > > struct clk_parent_data data = { > > .hw = clk_data[pdata->clk_id], > > /* copy other fields verbatim */ > > }; > > ... > > } > > > > Obviously this forces some ordering of how the clks are registered. > > I believe the order is already correct, and if it isn't, it would be > > easy to detect, and we can reorder things to fix it. > > If this is a common problem, we may need to come up with a generic > solution that either adds a new clk registration API that fills in the > clk_parent_data hw pointer or add another member to struct > clk_parent_data that says "index into this other array of clk_hw > pointers". Looking through the large clk drivers, at least Rockchip and MediaTek drivers would benefit from this. And maybe the Tegra ones as well, though I'm not familiar with them. Meson, Qcom, and sunxi-ng all use the static clk_hw scheme, so they're unaffected. I can think of a couple ways to tackle this: A. Add a new data structure as I showed above, and a helper to fill in |struct clk_parent_data| from said data structure. This basically moves what I planned to do for the MediaTek clk driver to the clk provider API. This is the least intrusive option. B. Add the |clk_id| field to |struct clk_parent_data|, and a |struct clk_hw *| field to |struct clk_init_data| for the array. Lookup would be done at clk registration time in clk_core_populate_parent_map(). This still forces checking of the clk_hw pointer and proper ordering of clk registration though. And it also bloats the data structures for folks not using the feature. C. Same as B, but keep the pointer to the array around (in clk_core?), and move the lookup into clk_core_fill_parent_index(). This provides similar behavior to using global clk name or static |struct clk_hw *| values in that clk registration order is not restricted. All the above options are designed around the desire to be able to make either the new data structure or |struct clk_parent_data| constant. Thoughts? Regards ChenYu