Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2584327ybh; Mon, 5 Aug 2019 03:28:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqzOi+hHh+E2mpjM4u01BBGVu6q9fYcZ5QgV5wNHyX8P0ph4wJIKBqKBMPKXX4U0LIyNuZnR X-Received: by 2002:aa7:93a8:: with SMTP id x8mr74637389pff.49.1565000894794; Mon, 05 Aug 2019 03:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565000894; cv=none; d=google.com; s=arc-20160816; b=DiW/NBoDstwFZXW0MxnUueaOBnKseWCqKNI0NRkEvMZc5h4UE2FhI4lW68TnOH9eZs 7/FMvZxMw9NS44QNZgY0oKFyAUnFl76RQZSWJqw8PWQRaAHwvEbURlqAA05cDi+wmRo0 lNwnQELw51mwN6PnEUtnzAHEix6YeR6rhCs8x6tZ9kvRh6BG9zlPMXse4s7E+hEGCwP2 d2sJBgfff1CbqtAERHkGC2YFotdIiCc3TT2wSmPXAJCp+QjhaCbedV206EImqR3H9N8Z kYGqXhnrsAwCSXpyGWOy+xbmxgL163sspl6QqTy68WjMHrSFRuAOyL1YfRAYe5WDqifj gOKg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=zeo3dO4srmOI+/HtOSINx976zCCA12faIbxVlPOyEcg=; b=L+Ab1EDyJSL2ztXt+QVKlywK1mhu7ZToIJ9H1sYtQ732OJLP/lx3PVAuVxIULQvVrF mzwKkSgSJ/48u7SMJlAK+rqzm90ejznJZeBkJI1fJmC91bxxG0Wp0h+RYvZEtIURd6MZ zmcxSsq9LZ0tOBpxMzJRPrMe2h5xjI6r0shKhJOR6V+KQKh9ow2yjhNeEahzY2uC3uv5 RQZNU+Yf3srM9srhui2418jJX7uutbI6TnqEhxK6xkM2pd+H3zcbo+mb0lUHit4d6pgh iLiwgKP4vN5BjdnZ7X6mag4jr18wW05Cey/IagqlEx98Odn9Gic0OC2rEf8Liyxn8Io+ vNAQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si22343216pgq.154.2019.08.05.03.27.58; Mon, 05 Aug 2019 03:28:14 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728306AbfHEK0j (ORCPT + 99 others); Mon, 5 Aug 2019 06:26:39 -0400 Received: from mga17.intel.com ([192.55.52.151]:7819 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728281AbfHEK0j (ORCPT ); Mon, 5 Aug 2019 06:26:39 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Aug 2019 03:26:38 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,349,1559545200"; d="scan'208";a="192386489" Received: from buildpc-hp-z230.iind.intel.com (HELO buildpc-HP-Z230) ([10.223.89.34]) by fmsmga001.fm.intel.com with ESMTP; 05 Aug 2019 03:26:35 -0700 Date: Mon, 5 Aug 2019 15:58:28 +0530 From: Sanyog Kale To: Pierre-Louis Bossart Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, tiwai@suse.de, broonie@kernel.org, vkoul@kernel.org, gregkh@linuxfoundation.org, jank@cadence.com, srinivas.kandagatla@linaro.org, slawomir.blauciak@intel.com Subject: Re: [RFC PATCH 25/40] soundwire: intel: use BIOS information to set clock dividers Message-ID: <20190805102828.GF22437@buildpc-HP-Z230> References: <20190725234032.21152-1-pierre-louis.bossart@linux.intel.com> <20190725234032.21152-26-pierre-louis.bossart@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190725234032.21152-26-pierre-louis.bossart@linux.intel.com> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 25, 2019 at 06:40:17PM -0500, Pierre-Louis Bossart wrote: > The BIOS provides an Intel-specific property, let's use it to avoid > hard-coded clock dividers. > > Signed-off-by: Pierre-Louis Bossart > --- > drivers/soundwire/cadence_master.c | 26 ++++++++++++++++++++++---- > drivers/soundwire/intel.c | 26 ++++++++++++++++++++++++++ > include/linux/soundwire/sdw.h | 2 ++ > 3 files changed, 50 insertions(+), 4 deletions(-) > > diff --git a/drivers/soundwire/cadence_master.c b/drivers/soundwire/cadence_master.c > index d84344e29f71..10ebcef2e84e 100644 > --- a/drivers/soundwire/cadence_master.c > +++ b/drivers/soundwire/cadence_master.c > @@ -173,8 +173,6 @@ > #define CDNS_PDI_CONFIG_PORT GENMASK(4, 0) > > /* Driver defaults */ > - > -#define CDNS_DEFAULT_CLK_DIVIDER 0 > #define CDNS_DEFAULT_SSP_INTERVAL 0x18 > #define CDNS_TX_TIMEOUT 2000 > > @@ -973,7 +971,10 @@ static u32 cdns_set_default_frame_shape(int n_rows, int n_cols) > */ > int sdw_cdns_init(struct sdw_cdns *cdns) > { > + struct sdw_bus *bus = &cdns->bus; > + struct sdw_master_prop *prop = &bus->prop; > u32 val; > + int divider; > int ret; > > /* Exit clock stop */ > @@ -985,9 +986,17 @@ int sdw_cdns_init(struct sdw_cdns *cdns) > } > > /* Set clock divider */ > + divider = (prop->mclk_freq / prop->max_clk_freq) - 1; Do you expect mclk_freq and max_clk_freq to be same? > val = cdns_readl(cdns, CDNS_MCP_CLK_CTRL0); > - val |= CDNS_DEFAULT_CLK_DIVIDER; > + val |= divider; > cdns_writel(cdns, CDNS_MCP_CLK_CTRL0, val); > + cdns_writel(cdns, CDNS_MCP_CLK_CTRL1, val); > + > + pr_err("plb: mclk %d max_freq %d divider %d register %x\n", > + prop->mclk_freq, > + prop->max_clk_freq, > + divider, > + val); This can be removed. > > /* Set the default frame shape */ > val = cdns_set_default_frame_shape(prop->default_row, > @@ -1035,6 +1044,7 @@ EXPORT_SYMBOL(sdw_cdns_init); > > int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params) > { > + struct sdw_master_prop *prop = &bus->prop; > struct sdw_cdns *cdns = bus_to_cdns(bus); > int mcp_clkctrl_off, mcp_clkctrl; > int divider; > @@ -1044,7 +1054,9 @@ int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params) > return -EINVAL; > } > > - divider = (params->max_dr_freq / params->curr_dr_freq) - 1; > + divider = prop->mclk_freq * SDW_DOUBLE_RATE_FACTOR / What is the reason for not using max_dr_freq? Its precomputed as prop->max_clk_freq * SDW_DOUBLE_RATE_FACTOR; > + params->curr_dr_freq; > + divider--; /* divider is 1/(N+1) */ > > if (params->next_bank) > mcp_clkctrl_off = CDNS_MCP_CLK_CTRL1; > @@ -1055,6 +1067,12 @@ int cdns_bus_conf(struct sdw_bus *bus, struct sdw_bus_params *params) > mcp_clkctrl |= divider; > cdns_writel(cdns, mcp_clkctrl_off, mcp_clkctrl); > > + pr_err("plb: mclk * 2 %d curr_dr_freq %d divider %d register %x\n", > + prop->mclk_freq * SDW_DOUBLE_RATE_FACTOR, > + params->curr_dr_freq, > + divider, > + mcp_clkctrl); > + > return 0; > } > EXPORT_SYMBOL(cdns_bus_conf); > diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c > index c718c9c67a37..796ac2bc8cea 100644 > --- a/drivers/soundwire/intel.c > +++ b/drivers/soundwire/intel.c > @@ -917,11 +917,37 @@ static int intel_register_dai(struct sdw_intel *sdw) > dais, num_dai); > } > > +static int sdw_master_read_intel_prop(struct sdw_bus *bus) > +{ > + struct sdw_master_prop *prop = &bus->prop; > + struct fwnode_handle *link; > + char name[32]; > + int nval, i; > + > + /* Find master handle */ > + snprintf(name, sizeof(name), > + "mipi-sdw-link-%d-subproperties", bus->link_id); > + > + link = device_get_named_child_node(bus->dev, name); > + if (!link) { > + dev_err(bus->dev, "Master node %s not found\n", name); > + return -EIO; > + } > + > + fwnode_property_read_u32(link, > + "intel-sdw-ip-clock", > + &prop->mclk_freq); > + return 0; > +} > + > static int intel_prop_read(struct sdw_bus *bus) > { > /* Initialize with default handler to read all DisCo properties */ > sdw_master_read_prop(bus); > > + /* read Intel-specific properties */ > + sdw_master_read_intel_prop(bus); > + > return 0; > } > > diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h > index 31d1e8acf25b..b6acc436ac80 100644 > --- a/include/linux/soundwire/sdw.h > +++ b/include/linux/soundwire/sdw.h > @@ -379,6 +379,7 @@ struct sdw_slave_prop { > * @dynamic_frame: Dynamic frame shape supported > * @err_threshold: Number of times that software may retry sending a single > * command > + * @mclk_freq: clock reference passed to SoundWire Master, in Hz. > */ > struct sdw_master_prop { > u32 revision; > @@ -393,6 +394,7 @@ struct sdw_master_prop { > u32 default_col; > bool dynamic_frame; > u32 err_threshold; > + u32 mclk_freq; > }; > > int sdw_master_read_prop(struct sdw_bus *bus); > -- > 2.20.1 > --