Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp4792235imm; Tue, 7 Aug 2018 07:26:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpfrLcHh4AWNCRryORugxPC6enXwNV01AfWARoNRbCFGNb07fs60wqv21uWlnodgyfmdNvLY X-Received: by 2002:a62:89d8:: with SMTP id n85-v6mr21927837pfk.83.1533651988938; Tue, 07 Aug 2018 07:26:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533651988; cv=none; d=google.com; s=arc-20160816; b=vfMxGefsMNpXlo63eo2X3bAyYgtl6CJo0fVvIzUKnVxiHgwDf/ZHEyEeKXBnoXnZdW oAhWN8Ky9mrBpIACVNCQomlWeTLCZ/Q4J9U2wUDc008P2BrWm5g6RaO8LBlZVp2/TJfB KXtzKxBDYb16orOZd+7gsAZ8J/S6jsMsHfQW0v8+/flVj46ECx3pkasCh3A+jFmf5cxM rOs9jG8WAjEDjT8TAzJ62osfgH4gOszDOFpOeVQrYfNEf/TDw2BFdk9afFgo/a6JeqMs ZlSpJPQvzD79Lnyrb4Ftesv9r2LryAHL9mnYv7Bjfxn17PC3AOZzlGWjzIlIWnYKE/lQ Sn1Q== 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:dkim-signature:arc-authentication-results; bh=faTLIWjlZn/WvDkrw6Po4M2ifxDB0Y4VHjGIHmgf29A=; b=GZgZpY23CnJrRnMz29O4lNfIk5XS3529SZRMX4gpeYgj79glFk25JUIOIZL1BSucJQ kJnQUTSzQKNYdwggbZTbA62fU/xZK2rQyeapuSPz2chPL5nTZHyCWjNAFaZY+l/NwDKU EPtAdoGistoMQsJxuW1i3tYVAN6uw1JBC26OKDwXlvY+mH5joKnEUxvlTxI/gS03gVd0 K9kkwg8kiZ9Y48gqtuBa/Slv3mgTD4wHkbjXGnuovwZmJFNAU8BAJPFZIxAXfe07ZqBW Q+pqLXbiNvjQxAw50aJYne6NdhV/YvvGfN0AcKXqQ961SYE9xN6ARqHtylVqQzKPA4Zk f+vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=xkualwYN; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n8-v6si1167266pgl.101.2018.08.07.07.26.13; Tue, 07 Aug 2018 07:26:28 -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=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=xkualwYN; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389513AbeHGQiw (ORCPT + 99 others); Tue, 7 Aug 2018 12:38:52 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:37290 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732639AbeHGQiv (ORCPT ); Tue, 7 Aug 2018 12:38:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=faTLIWjlZn/WvDkrw6Po4M2ifxDB0Y4VHjGIHmgf29A=; b=xkualwYN8YTNIiRZDMWj2RrIj C1J6LrEYMcb3vLoatUDFmX/q9F8eZP7QddWcPVE9vnRZwPwXwcOQ4opS568/xsU2mank2ARgNN21L tW8N43Xer2wpEjIPrJ62jSksq5+xt6mQnqmC76pfnWiD5IMIE4mt9QrUyMKV/QQHJMK+Y=; Received: from cpc102320-sgyl38-2-0-cust46.18-2.cable.virginm.net ([82.37.168.47] helo=debutante.sirena.org.uk) by heliosphere.sirena.org.uk with esmtpa (Exim 4.89) (envelope-from ) id 1fn2u8-0000mR-SF; Tue, 07 Aug 2018 14:24:08 +0000 Received: by debutante.sirena.org.uk (Postfix, from userid 1000) id 85E4B112433B; Tue, 7 Aug 2018 15:24:08 +0100 (BST) Date: Tue, 7 Aug 2018 15:24:08 +0100 From: Mark Brown To: Baolin Wang Cc: robh+dt@kernel.org, mark.rutland@arm.com, orsonzhai@gmail.com, zhang.lyra@gmail.com, lanqing.liu@spreadtrum.com, linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 2/2] spi: sprd: Add SPI driver for Spreadtrum SC9860 Message-ID: <20180807142408.GB7958@sirena.org.uk> References: <64681bf903104c8a02f118294e616e2a12a5ebe4.1533638405.git.baolin.wang@linaro.org> <99befd2badc4dffb59662fca1e11d79f18b64755.1533638405.git.baolin.wang@linaro.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="CUfgB8w4ZwR/yMy5" Content-Disposition: inline In-Reply-To: <99befd2badc4dffb59662fca1e11d79f18b64755.1533638405.git.baolin.wang@linaro.org> X-Cookie: Danger: do not shake. User-Agent: Mutt/1.10.0 (2018-05-17) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --CUfgB8w4ZwR/yMy5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 07, 2018 at 06:43:38PM +0800, Baolin Wang wrote: > From: Lanqing Liu >=20 > This patch adds the SPI controller driver for Spreadtrum SC9860 platform. This all looks pretty clean, a few comments below but nothing too major: > +static void sprd_spi_chipselect(struct spi_device *sdev, bool cs) > +{ > + struct spi_controller *sctlr =3D sdev->controller; > + struct sprd_spi *ss =3D spi_controller_get_devdata(sctlr); > + u32 val; > + int ret; > + > + ret =3D pm_runtime_get_sync(ss->dev); > + if (ret < 0) { > + dev_err(ss->dev, "failed to resume SPI controller\n"); > + return; > + } Something else further up the stack should probably have runtime PM enabled already - we should only be changing chip select as part of a bigger operation. If you use the core auto_runtime_pm feature this will definitely happen. > + bits_per_word =3D bits_per_word > 16 ? round_up(bits_per_word, 16) : > + round_up(bits_per_word, 8); Please > + switch (bits_per_word) { > + case 8: > + case 16: > + case 32: It'd be nice to have a default case, the core should check for you but it's nice to have defensive programming here. > +static int sprd_spi_transfer_one(struct spi_controller *sctlr, > + struct spi_device *sdev, > + struct spi_transfer *t) > +{ > + struct sprd_spi *ss =3D spi_controller_get_devdata(sctlr); > + int ret; > + > + ret =3D pm_runtime_get_sync(ss->dev); > + if (ret < 0) { > + dev_err(ss->dev, "failed to resume SPI controller\n"); > + goto rpm_err; > + } Same thing with runtime PM here - the core can do this for you. > +static int sprd_spi_setup(struct spi_device *spi_dev) > +{ > + struct spi_controller *sctlr =3D spi_dev->controller; > + struct sprd_spi *ss =3D spi_controller_get_devdata(sctlr); > + int ret; > + > + ret =3D pm_runtime_get_sync(ss->dev); > + if (ret < 0) { > + dev_err(ss->dev, "failed to resume SPI controller\n"); > + return ret; > + } > + > + ss->hw_mode =3D spi_dev->mode; > + sprd_spi_init_hw(ss); This can be called for one chip select while another is in progress so it's not good to actually configure the hardware here unless the configuration is in a chip select specific set of registers. Instead you should defer to when the transfer is being set up. > +static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_s= pi *ss) > +{ > + struct clk *clk_spi, *clk_parent; > + > + clk_spi =3D devm_clk_get(&pdev->dev, "spi"); > + if (IS_ERR(clk_spi)) { > + dev_warn(&pdev->dev, "can't get the spi clock\n"); > + clk_spi =3D NULL; > + } I suspect some of these clocks are essential and you should probably return an error if you can't get them (especially if probe deferral becomes a factor). > + if (!clk_set_parent(clk_spi, clk_parent)) > + ss->src_clk =3D clk_get_rate(clk_spi); > + else > + ss->src_clk =3D SPRD_SPI_DEFAULT_SOURCE; Are upstream DTs going to be missing the clock setup needed here? --CUfgB8w4ZwR/yMy5 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQEzBAABCgAdFiEEreZoqmdXGLWf4p/qJNaLcl1Uh9AFAltpq4cACgkQJNaLcl1U h9AVcgf+NxxRSsAAJNVZOh81hcSC5CB7sYJnt2eniKxe6PLdIM4NXBncN13jTSUf B9wU7JvRS02VGMZiFUi5RA50jN3a5gby3mb9UmjjVZzyQSPNpzeeDUEv67jreyXo zTSy758kPJxqKwCG7fsHSBIJoT5/zx9sLESNX+3IxgJ1cMco6tZET9qo/gQqxsdH Zw9SE4DDrAcIrYoc0Q1gBYIyeJ88ljJoytdHyCRPdjzaWColce5TKv6VvfOp8kZP 6JBKb8FPF6XdAHA8qvHobNyub85E836EIaoNSO97QAFi4JLXR8Zekx6y5kxBT84J Pf2FbnHBP1XRQQX1deSuKEtxt8MYOA== =UadY -----END PGP SIGNATURE----- --CUfgB8w4ZwR/yMy5--