linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Emil Renner Berthing <kernel@esmil.dk>
Cc: Mark Rutland <mark.rutland@arm.com>,
	devicetree@vger.kernel.org, Palmer Dabbelt <palmer@sifive.com>,
	linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org,
	Rob Herring <robh+dt@kernel.org>,
	linux-riscv@lists.infradead.org
Subject: Re: [RFC PATCH] spi: add driver for the SiFive SPI controller
Date: Tue, 13 Nov 2018 10:35:27 -0800	[thread overview]
Message-ID: <20181113183527.GG2089@sirena.org.uk> (raw)
Message-ID: <20181113183527.1qcH7tBQCdACjkzbtqZz0CovTkSxY13pqDP939v9F3Y@z> (raw)
In-Reply-To: <20181112142736.15009-1-kernel@esmil.dk>


[-- Attachment #1.1: Type: text/plain, Size: 3044 bytes --]

On Mon, Nov 12, 2018 at 03:27:36PM +0100, Emil Renner Berthing wrote:

> I know the discussions about the sifive devicetree compatible
> strings haven't come to a conclusion, so I'm sending this as
> an RFC to get some feedback on the rest of the code.

I've not seen any of these discussions or earlier versions of this
driver so I've no idea what's going on here :(

> +Optional properties:
> +- sifive,fifo-depth		: Depth of hardware queues; defaults to 8
> +- sifive,max-bits-per-word	: Maximum bits per word; defaults to 8
> +

If the hardware isn't fixed yet making these enumerable from the
hardware would be good...

> @@ -0,0 +1,442 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * SiFive SPI controller driver (master mode only)
> + *

Please make the entire comment a C++ one to make this look more
intentinal.

> +/* for consistency we need this symbol */
> +#ifdef REG_FMT
> +#undef REG_FMT
> +#endif

We do?  For consistency with what?

> +static void sifive_spi_init(struct sifive_spi *spi)
> +{

> +	/* Set CS/SCK Delays and Inactive Time to defaults */
> +
> +	/* Exit specialized memory-mapped SPI flash mode */

...or not?

> +	/* Set frame format */
> +	cr = FMT_LEN(t->bits_per_word);
> +	switch (mode) {
> +	case SPI_NBITS_QUAD:
> +		cr |= FMT_PROTO_QUAD;
> +		break;

Some namespacing on the driver #defines would be a bit safer against the
possibility of collision with future changes in headers.

> +static void sifive_spi_wait(struct sifive_spi *spi, u32 bit, int poll)
> +{
> +	if (poll) {
> +		u32 cr;
> +		do cr = sifive_spi_read(spi, REG_IP);
> +		while (!(cr & bit));

Please add some braces, indentation or something to make it more clear
that the read is part of a do/while loop - right now it's not
immediately obvious that this is correct.

> +static int sifive_spi_transfer_one(struct spi_master *master,
> +		struct spi_device *device, struct spi_transfer *t)
> +{
> +	struct sifive_spi *spi = spi_master_get_devdata(master);
> +	int poll = sifive_spi_prep_transfer(spi, device, t);
> +
> +	sifive_spi_execute(spi, t, poll);
> +

Why not just inline the execute function here?  It's the only caller
AFAICT.

> +static void sifive_spi_set_cs(struct spi_device *device, bool is_high)
> +{
> +	struct sifive_spi *spi = spi_master_get_devdata(device->master);
> +
> +	/* Reverse polarity is handled by SCMR/CPOL. Not inverted CS. */
> +	if (device->mode & SPI_CS_HIGH)
> +		is_high = !is_high;

spi_set_cs() will handle CS_HIGH for you.

> +	master->bits_per_word_mask = SPI_BPW_MASK(8);

I thought the device supported other bits per word values?

> +	/* If mmc_spi sees a dma_mask, it starts using dma mapped buffers.
> +	 * Probably it should rely on the SPI core auto mapping instead.
> +	 */
> +	pdev->dev.dma_mask = NULL;

If this is a problem please fix it in the MMC core, don't bodge it like
this.

> +static const struct of_device_id sifive_spi_of_match[] = {
> +	{ .compatible = "sifive,spi0", },
> +	{}
> +};
> +MODULE_DEVICE_TABLE(of, sifive_spi_of_match);

spi0 is a *weird* compatible name.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 161 bytes --]

_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

  parent reply	other threads:[~2018-11-13 18:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-12 14:27 [RFC PATCH] spi: add driver for the SiFive SPI controller Emil Renner Berthing
2018-11-12 14:27 ` Emil Renner Berthing
2018-11-13 18:35 ` Mark Brown [this message]
2018-11-13 18:35   ` Mark Brown
2018-11-13 19:48   ` Emil Renner Berthing
2018-11-13 19:48     ` Emil Renner Berthing
2018-11-13 22:38     ` Mark Brown
2018-11-13 22:38       ` Mark Brown
2019-02-13 10:03 ` Yash Shah
2019-02-13 13:10   ` Emil Renner Berthing

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181113183527.GG2089@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kernel@esmil.dk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=palmer@sifive.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).