Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2199453imm; Thu, 11 Oct 2018 06:44:06 -0700 (PDT) X-Google-Smtp-Source: ACcGV61C1NRwbe2vW8S+UQKkhuFmBur5q+RTmrU0h6v4DxGBJaQ21+JQcDVO5vptyYa4oKU8bEfI X-Received: by 2002:a63:5949:: with SMTP id j9-v6mr1530829pgm.210.1539265446638; Thu, 11 Oct 2018 06:44:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539265446; cv=none; d=google.com; s=arc-20160816; b=EuiCgqn2I6qVagiZSNgnjk58U01DEyOWPiGRlV2f0km0w9vD+Z7fIGShLNCZxpp24G Nf3CZX8g3l3163qh1elUjRI7lL7sE4j6X8K0x+4XJ/9ZpZHtNBE3MFhmLcDCPaRk7ZpC lhdxEDrqVy4Ay7AdKk8zVGVzzyjUx5xXV6YMY6Tx4y6c5UfIAn2roKEpsh+TAkbfvOP6 Jz9VE7rbZODvF+kJF6XuDFVFcaX3casMTYuhdLZLieSCYy/MubE1eTI2mxojn7uBke8r iZdptkP4SRgqHXfIhyUvhQjKJ2JijROHUQamc1GYaVHR1jXmtTiVrwFc4MFJ+5r3pyoF /tSQ== 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=ZvB2A6pupDfByB5+ELX5pppJXrddq9Ii7VSogRzrFMc=; b=I3Ge16lg+V3ACzzriZ5q7n8ISst1yfzaun1yH0h9Af6FUbj5QV3sq7zI0flMrQTS2q ycMCG4Dh2OFp+vkk83Pg1xdAu3DVbj2/tXc3BxGJHtcnS/Kicqp7jadF3Tb72OezH0M3 j53Q9fNpdvWT3e7K1TtGb+GWT0//Ek0H5y85L7n04bZGa2x++IKaEzikK7GZ68wAGvp0 xWRJN/B5YlyOvvwf8B//U2dKZgyPv6XonHVYjo9T0/HKLVSNmfSxqML+ZUYqcT6W22HL NIW+XLU9xrKwIHgRnvQ9exiIElArE/j6BhAvMoWykozyeOohmxLOMLtUv8lA8COOdevA 0N9w== 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=cirrus.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u4-v6si6941309pgi.554.2018.10.11.06.43.51; Thu, 11 Oct 2018 06:44:06 -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=cirrus.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbeJKUxY (ORCPT + 99 others); Thu, 11 Oct 2018 16:53:24 -0400 Received: from mx0a-001ae601.pphosted.com ([67.231.149.25]:60838 "EHLO mx0b-001ae601.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726071AbeJKUxY (ORCPT ); Thu, 11 Oct 2018 16:53:24 -0400 Received: from pps.filterd (m0077473.ppops.net [127.0.0.1]) by mx0a-001ae601.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w9BDOZWF008516; Thu, 11 Oct 2018 08:26:04 -0500 Authentication-Results: ppops.net; spf=none smtp.mailfrom=ckeepax@opensource.cirrus.com Received: from mail3.cirrus.com ([87.246.76.56]) by mx0a-001ae601.pphosted.com with ESMTP id 2mxwhefttp-1; Thu, 11 Oct 2018 08:26:04 -0500 Received: from EX17.ad.cirrus.com (ex17.ad.cirrus.com [172.20.9.81]) by mail3.cirrus.com (Postfix) with ESMTP id A5F73611C8B3; Thu, 11 Oct 2018 08:28:16 -0500 (CDT) Received: from imbe.wolfsonmicro.main (198.61.95.81) by EX17.ad.cirrus.com (172.20.9.81) with Microsoft SMTP Server id 14.3.408.0; Thu, 11 Oct 2018 14:26:02 +0100 Received: from imbe.wolfsonmicro.main (imbe.wolfsonmicro.main [198.61.95.81]) by imbe.wolfsonmicro.main (8.14.4/8.14.4) with ESMTP id w9BDQ2Ew002789; Thu, 11 Oct 2018 14:26:02 +0100 Date: Thu, 11 Oct 2018 14:26:02 +0100 From: Charles Keepax To: Stephen Boyd CC: , , , , , , , , , , , Subject: Re: [PATCH v2 3/5] clk: lochnagar: Add support for the Cirrus Logic Lochnagar Message-ID: <20181011132602.GD1653@imbe.wolfsonmicro.main> References: <20181008132542.19775-1-ckeepax@opensource.cirrus.com> <20181008132542.19775-3-ckeepax@opensource.cirrus.com> <153924124658.207691.10370075148426001371@swboyd.mtv.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <153924124658.207691.10370075148426001371@swboyd.mtv.corp.google.com> User-Agent: Mutt/1.5.20 (2009-12-10) X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1810110131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 11, 2018 at 12:00:46AM -0700, Stephen Boyd wrote: > Quoting Charles Keepax (2018-10-08 06:25:40) > > +#include > > Is this used? > > > +#include > > +#include > > Is this used? > > > +#include > > +#include > > +#include > > +#include > > Used? Apparently not, will remove the three of them. > > +struct lochnagar_regmap_clk { > > + unsigned int cfg_reg; > > + unsigned int ena_mask; > > + unsigned int dir_mask; > > + > > + unsigned int src_reg; > > + unsigned int src_mask; > > Are these 32 bits or 16 bits or 8 bits? Please use a u32/u16/u8 so we > know the register width. > Can do. > > +struct lochnagar_clk_priv { > > + struct device *dev; > > + struct lochnagar *lochnagar; > > Is this used for anything besides getting the regmap? Can you get the > pointer to the parent in probe and use that to get the regmap pointer > from dev_get_remap() and also use the of_node of the parent to register > a clk provider? It would be nice to avoid including the mfd header file > unless it's providing something useful. > It is also used to find out which type of Lochnagar we have connected, which determines which clocks we should register. I could perhaps pass that using another mechanism but we would still want to include the MFD stuff to get the register definitions. So this approach seems simplest. > > +#define LN_CLK_FIXED(ID, NAME, RATE) \ > > + [LOCHNAGAR_##ID] = { \ > > + .name = NAME, .type = LOCHNAGAR_CLK_TYPE_FIXED, \ > > + { .fixed.rate = RATE, }, \ > > + } > > Can all these fixed clks come from DT instead of being populated by this > driver? Unless they're being generated by this hardware block and not > actually a crystal or some other on-board clock that goes into this > hardware block and then right out of it? > Technically they are supplied by a clock generator chip (bunch of PLLs) which is controlled by the board controller chip. That said I don't really ever see them changing so will move them in DT. > > +static int lochnagar_regmap_prepare(struct clk_hw *hw) > > +{ > > + struct lochnagar_clk *lclk = lochnagar_hw_to_lclk(hw); > > + struct lochnagar_clk_priv *priv = lclk->priv; > > + struct regmap *regmap = priv->lochnagar->regmap; > > + int ret; > > + > > + dev_dbg(priv->dev, "Prepare %s\n", lclk->name); > > Nitpick: Can you just rely on the clk tracepoints? > Can do they are hardly essential. > > + > > + if (!lclk->regmap.ena_mask) > > Why did we assign the ops to the clk if it can't be enabled? Please make > different ops for different types of clks so we don't have to check > something else and bail out early when the op is called. > This is a bit of a leak from earlier versions of the code I can just remove them. > > +static int lochnagar_regmap_set_parent(struct clk_hw *hw, u8 index) > > +{ > > + struct lochnagar_clk *lclk = lochnagar_hw_to_lclk(hw); > > + struct lochnagar_clk_priv *priv = lclk->priv; > > + struct regmap *regmap = priv->lochnagar->regmap; > > + int ret; > > + > > + dev_dbg(priv->dev, "Reparent %s to %s\n", > > + lclk->name, priv->parents[index]); > > + > > + if (lclk->regmap.dir_mask) { > > + ret = regmap_update_bits(regmap, lclk->regmap.cfg_reg, > > + lclk->regmap.dir_mask, > > + lclk->regmap.dir_mask); > > + if (ret < 0) { > > + dev_err(priv->dev, "Failed to set %s direction: %d\n", > > What does direction mean? > Some of the clocks can both generate and receive a clock. For example the PSIA (external audio interface) MCLKs, the attached device could be expecting or providing a master audio clock. If the user assigns a parent to the clock we assume the attached device is providing a clock to us, otherwise we assume we are providing the clock. > > + ret = regmap_read(regmap, lclk->regmap.src_reg, &val); > > + if (ret < 0) { > > + dev_err(priv->dev, "Failed to read parent of %s: %d\n", > > + lclk->name, ret); > > + return 0; > > Return a number greater than all possible parents of this clk? > Can do. > > + for (i = 0; i < ARRAY_SIZE(priv->lclks); i++) { > > + lclk = &priv->lclks[i]; > > + > > + lclk->priv = priv; > > + > > + switch (lclk->type) { > > + case LOCHNAGAR_CLK_TYPE_FIXED: > > + clk = clk_register_fixed_rate(priv->dev, lclk->name, > > + NULL, 0, > > + lclk->fixed.rate); > > + break; > > + case LOCHNAGAR_CLK_TYPE_REGMAP: > > + clk_init.name = lclk->name; > > + lclk->hw.init = &clk_init; > > + > > + clk = devm_clk_register(priv->dev, &lclk->hw); > > Please use the clk_hw based registration APIs. > Can do. > > +static int lochnagar_clk_remove(struct platform_device *pdev) > > +{ > > + struct lochnagar_clk_priv *priv = platform_get_drvdata(pdev); > > + int i; > > + > > + of_clk_del_provider(priv->lochnagar->dev->of_node); > > Use devm variant of clk provider registration? > This isn't using the devm version as it makes the assumption that the device that contains the DT is the same one we want to devm against which isn't the case here. I could update probe to copy the of_node over from the parent, if you prefer? I think that would also work. > > +static struct platform_driver lochnagar_clk_driver = { > > + .driver = { > > + .name = "lochnagar-clk", > > + }, > > Any id_table? > Doesn't really need one since the driver will only ever be bound in by the MFD, so matching on the driver name is fine. Thanks, Charles