Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7986888imu; Tue, 4 Dec 2018 00:36:31 -0800 (PST) X-Google-Smtp-Source: AFSGD/V8/a/LucqP7sUUl3CL4XUHVspVjqll08TcWg9AcPyKjHjUDuumr0/NrCX8LCNRogyS+wpq X-Received: by 2002:a17:902:b090:: with SMTP id p16mr19203049plr.190.1543912591586; Tue, 04 Dec 2018 00:36:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543912591; cv=none; d=google.com; s=arc-20160816; b=CwnR7ABaHnlyuClmqVsvprEyHt/iqBtZTC9OWOt1tRSJQ+z/W/VBBO+2Z96zOyU81K JdAiTKGdsZe9Fh0GwFdFcjfR2+keWQk4+T0htQKlRI6d0THTd+bqcND43s0Z4RoqI5dz vNhIUgekoScKt73P+zqA4R9h44l33h1P4Eiai1PypqfABlT5MVAHLrO+jVkJlpkd0k+Z 6XVcAv+woojeR8GBxbwQUsj0iclIB8/ybW7txo/CReVf9d3SeY7M1Ckz/QKFEqh89Blm fIJY5mp1uiW7oE0WnvnhuK8pO5mhSolFE7NOWZ5JUytxumBqfRDUyIAD92u4fF4E9Pz0 VTsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=Pvdl9byh6FKkiDnXeMoFMKAXrijl+JroH8S3yML7/NA=; b=ERxljWfPplq7ZwwqTnWo7Yo6fSg+2braLLNQZC/27fTrpM3kbQOouGC2jwq/GBGCJY ZXEz+rc4YPg9cPfxMwgMiTmvk7nlrLlFJCYvQ4WcIOX9e0catYuGx/L/71WbJtHgcGKX rzGUFP7vsycZs3hbtth5BMyNP7HkQSp0BXJ8h7vFLmSHpTKOaAyPzu8afhn7nW3/O6Ua sPnwre+tMmHwAxM1JeXcC/aRhkOXs1hMR7q7CKu55KzQUjFydlUzZlKN14HUVZ16wnDk 3iJCX41N3LvK2YXZ0QMsGdFLAzOfcUxGZbrY/D53EAmmnVCodY3aUmI55r24cmRQXdOq DZIw== ARC-Authentication-Results: i=1; mx.google.com; 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 z5si14809655pgu.19.2018.12.04.00.36.16; Tue, 04 Dec 2018 00:36:31 -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; 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 S1725864AbeLDIfj (ORCPT + 99 others); Tue, 4 Dec 2018 03:35:39 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:39777 "EHLO relay1.mentorg.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725468AbeLDIfi (ORCPT ); Tue, 4 Dec 2018 03:35:38 -0500 Received: from svr-orw-mbx-03.mgc.mentorg.com ([147.34.90.203]) by relay1.mentorg.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-SHA384:256) id 1gU6B6-0007PN-D7 from Jiada_Wang@mentor.com ; Tue, 04 Dec 2018 00:35:36 -0800 Received: from [172.30.112.76] (147.34.91.1) by svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) with Microsoft SMTP Server (TLS) id 15.0.1320.4; Tue, 4 Dec 2018 00:35:32 -0800 Subject: Re: [PATCH linux-next v2 6/6] ASoC: rsnd: add avb clocks To: Kuninori Morimoto CC: "broonie@kernel.org" , "perex@perex.cz" , "tiwai@suse.com" , "vladimir_zapolskiy@mentor.com" , "alsa-devel@alsa-project.org" , "linux-kernel@vger.kernel.org" References: <20181203112427.18324-1-jiada_wang@mentor.com> <87o9a22hjt.wl-kuninori.morimoto.gx@renesas.com> From: Jiada Wang Message-ID: <64d0b9f1-ca23-425e-68d1-31ce9d6ab168@mentor.com> Date: Tue, 4 Dec 2018 17:35:31 +0900 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <87o9a22hjt.wl-kuninori.morimoto.gx@renesas.com> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US X-ClientProxiedBy: svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) To svr-orw-mbx-03.mgc.mentorg.com (147.34.90.203) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Morimoto-san Thanks for your comments, I will address your findings in next version Thanks, Jiada On 2018/12/04 10:52, Kuninori Morimoto wrote: > Hi Jiada > >> There are AVB Counter Clocks in ADG, each clock has 12bits integral >> and 8 bits fractional dividers which operates with S0D1ϕ clock. >> >> This patch registers 8 AVB Counter Clocks when clock-cells of >> rcar_sound node is 2, >> >> Signed-off-by: Jiada Wang >> --- > (snip) >> +struct clk_avb { >> + struct clk_hw hw; >> + unsigned int idx; >> + struct rsnd_mod *mod; >> + /* lock reg access */ >> + spinlock_t *lock; >> +}; >> + >> +#define to_clk_avb(_hw) container_of(_hw, struct clk_avb, hw) > I like "hw_to_avb()" > >> +static struct clk *rsnd_adg_clk_src_twocell_get(struct of_phandle_args *clkspec, >> + void *data) >> +{ >> + unsigned int clkidx = clkspec->args[1]; >> + struct rsnd_adg *adg = data; >> + const char *type; >> + struct clk *clk; >> + >> + switch (clkspec->args[0]) { >> + case ADG_FIX: >> + type = "fixed"; >> + if (clkidx >= CLKOUTMAX) { >> + pr_err("Invalid %s clock index %u\n", type, >> + clkidx); >> + return ERR_PTR(-EINVAL); >> + } >> + clk = adg->clkout[clkidx]; >> + break; >> + case ADG_AVB: >> + type = "avb"; >> + if (clkidx >= AVB_CLK_NUM) { >> + pr_err("Invalid %s clock index %u\n", type, >> + clkidx); >> + return ERR_PTR(-EINVAL); >> + } >> + clk = adg->clkavb[clkidx]; >> + break; >> + default: >> + pr_err("Invalid ADG clock type %u\n", clkspec->args[0]); >> + return ERR_PTR(-EINVAL); >> + } >> + >> + return clk; >> +} > In this function > 1) I don't think you need to use "char *type". > 2) If you use "clkidx = clkspec->args[1]", having same name for "clkspec->args[0]" > is readable. > 3) please use dev_err() instad of pr_err() > I think data can be priv, and you can use rsnd_priv_to_adg(), rsnd_priv_to_dev() > >> +static void clk_avb_div_write(struct rsnd_mod *mod, u32 data, int idx) > (snip) >> +static u32 clk_avb_div_read(struct rsnd_mod *mod, int idx) > To reduce confusion, and be more redable code, > I think these function can be > > clk_avb_div_write(struct rsnd_adg *adg, u32 data); > clk_avb_div_read(struct rsnd_adg *adg); > >> +static int clk_avb_set_rate(struct clk_hw *hw, unsigned long rate, >> + unsigned long parent_rate) >> +{ >> + struct clk_avb *avb = to_clk_avb(hw); >> + unsigned int div = clk_avb_calc_div(rate, parent_rate); >> + u32 val; >> + >> + val = clk_avb_div_read(avb->mod, avb->idx) & ~AVB_DIV_MASK; >> + clk_avb_div_write(avb->mod, val | div, avb->idx); >> + >> + return 0; >> +} > Why do we need to care about ~AVB_DIV_MASK area ? > These are 0 Reserved, I think. > >> +static const struct clk_ops clk_avb_ops = { >> + .enable = clk_avb_enable, >> + .disable = clk_avb_disable, >> + .is_enabled = clk_avb_is_enabled, >> + .recalc_rate = clk_avb_recalc_rate, >> + .round_rate = clk_avb_round_rate, >> + .set_rate = clk_avb_set_rate, >> +}; > This is not a big deal, but I like tab aligned ops > >> +static struct clk *clk_register_avb(struct device *dev, struct rsnd_mod *mod, >> + unsigned int id, spinlock_t *lock) >> +{ >> + struct clk_init_data init; >> + struct clk_avb *avb; >> + struct clk *clk; >> + char name[AVB_CLK_NAME_SIZE]; >> + const char *parent_name = ADG_CLK_NAME; >> + >> + avb = devm_kzalloc(dev, sizeof(*avb), GFP_KERNEL); >> + if (!avb) >> + return ERR_PTR(-ENOMEM); >> + >> + snprintf(name, AVB_CLK_NAME_SIZE, "%s%u", AVB_CLK_NAME, id); >> + >> + avb->idx = id; >> + avb->lock = lock; >> + avb->mod = mod; >> + >> + /* Register the clock. */ >> + init.name = name; >> + init.ops = &clk_avb_ops; >> + init.flags = CLK_IS_BASIC; >> + init.parent_names = &parent_name; >> + init.num_parents = 1; >> + >> + avb->hw.init = &init; >> + >> + /* init DIV to a valid state */ >> + clk_avb_div_write(avb->mod, avb->idx, AVB_MAX_DIV); > Please check parameter, I think you want to do is > > - clk_avb_div_write(avb->mod, avb->idx, AVB_MAX_DIV); > + clk_avb_div_write(avb->mod, AVB_MAX_DIV, avb->idx); > > Best regards > --- > Kuninori Morimoto