mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Marek Vasut <marek.vasut@gmail.com>
To: Mika Westerberg <mika.westerberg@linux.intel.com>,
	linux-mtd@lists.infradead.org
Cc: Cyrille Pitchen <cyrille.pitchen@atmel.com>,
	Boris Brezillon <boris.brezillon@free-electrons.com>,
	Richard Weinberger <richard@nod.at>,
	Brian Norris <computersforpeace@gmail.com>,
	David Woodhouse <dwmw2@infradead.org>,
	Lee Jones <lee.jones@linaro.org>,
	Peter Tyser <ptyser@xes-inc.com>,
	key.seong.lim@intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v5 1/3] spi-nor: Add support for Intel SPI serial flash controller
Date: Fri, 25 Nov 2016 18:26:10 +0100	[thread overview]
Message-ID: <75195621-aeec-3d83-46ed-74ab1660fd5f@gmail.com> (raw)
In-Reply-To: <20161114102447.131602-2-mika.westerberg@linux.intel.com>

On 11/14/2016 11:24 AM, Mika Westerberg wrote:
> Add support for the SPI serial flash host controller found on many Intel
> CPUs including Baytrail and Braswell. The SPI serial flash controller is
> used to access BIOS and other platform specific information. By default the
> driver exposes a single read-only MTD device but with a module parameter
> "writeable=1" the MTD device can be made read-write which makes it possible
> to upgrade BIOS directly from Linux.
> 
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>

Only minor nits below. Sorry I took so long with the review.

[...]

> +static int intel_spi_wait_hw_busy(struct intel_spi *ispi)
> +{
> +	unsigned long timeout = jiffies + msecs_to_jiffies(INTEL_SPI_TIMEOUT);
> +	u32 hwstat;

Won't some include/linux/iopoll.h macro help here ?

> +	while (!time_after(jiffies, timeout)) {
> +		hwstat = readl(ispi->base + HSFSTS_CTL);
> +		if (!(hwstat & HSFSTS_CTL_SCIP))
> +			return 0;
> +		cond_resched();
> +	}
> +
> +	return -ETIMEDOUT;
> +}
> +
> +static int intel_spi_wait_sw_busy(struct intel_spi *ispi)
> +{
> +	unsigned long timeout = jiffies + msecs_to_jiffies(INTEL_SPI_TIMEOUT);
> +	u32 swstat;
> +
> +	while (!time_after(jiffies, timeout)) {

DTTO

> +		swstat = readl(ispi->sregs + SSFSTS_CTL);
> +		if (!(swstat & SSFSTS_CTL_SCIP))
> +			return 0;
> +		cond_resched();
> +	}
> +
> +	return -ETIMEDOUT;
> +}

[...]

> +static ssize_t intel_spi_read(struct spi_nor *nor, loff_t from, size_t len,
> +			      u_char *read_buf)
> +{
> +	struct intel_spi *ispi = nor->priv;
> +	size_t block_size, retlen = 0;
> +	u32 val, status;
> +	ssize_t ret;
> +
> +	switch (nor->read_opcode) {
> +	case SPINOR_OP_READ:
> +	case SPINOR_OP_READ_FAST:
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	while (len > 0) {
> +		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
> +
> +		writel(from, ispi->base + FADDR);
> +
> +		val = readl(ispi->base + HSFSTS_CTL);
> +		val |= HSFSTS_CTL_AEL | HSFSTS_CTL_FCERR | HSFSTS_CTL_FDONE;
> +		val &= ~HSFSTS_CTL_FDBC_MASK;
> +		val |= (block_size - 1) << HSFSTS_CTL_FDBC_SHIFT;
> +		val &= ~HSFSTS_CTL_FCYCLE_MASK;
> +		val |= HSFSTS_CTL_FCYCLE_READ;
> +		val |= HSFSTS_CTL_FGO;

Sort those bit clears and bit sets so you first clear and then set bits.

> +		writel(val, ispi->base + HSFSTS_CTL);
> +
> +		ret = intel_spi_wait_hw_busy(ispi);
> +		if (ret)
> +			return ret;
> +
> +		status = readl(ispi->base + HSFSTS_CTL);
> +		if (status & HSFSTS_CTL_FCERR)
> +			ret = -EIO;
> +		else if (status & HSFSTS_CTL_AEL)
> +			ret = -EACCES;
> +
> +		if (ret < 0) {
> +			dev_err(ispi->dev, "read error: %llx: %#x\n", from,
> +				status);
> +			return ret;
> +		}
> +
> +		ret = intel_spi_read_block(ispi, read_buf, block_size);
> +		if (ret)
> +			return ret;
> +
> +		len -= block_size;
> +		from += block_size;
> +		retlen += block_size;
> +		read_buf += block_size;
> +	}
> +
> +	return retlen;
> +}
> +
> +static ssize_t intel_spi_write(struct spi_nor *nor, loff_t to, size_t len,
> +			       const u_char *write_buf)
> +{
> +	struct intel_spi *ispi = nor->priv;
> +	size_t block_size, retlen = 0;
> +	u32 val, status;
> +	ssize_t ret;
> +
> +	while (len > 0) {
> +		block_size = min_t(size_t, len, INTEL_SPI_FIFO_SZ);
> +
> +		writel(to, ispi->base + FADDR);
> +
> +		val = readl(ispi->base + HSFSTS_CTL);
> +		val |= HSFSTS_CTL_AEL | HSFSTS_CTL_FCERR | HSFSTS_CTL_FDONE;
> +		val &= ~HSFSTS_CTL_FDBC_MASK;
> +		val |= (block_size - 1) << HSFSTS_CTL_FDBC_SHIFT;
> +		val &= ~HSFSTS_CTL_FCYCLE_MASK;
> +		val |= HSFSTS_CTL_FCYCLE_WRITE;

DTTO here.

> +		/* Write enable */
> +		if (ispi->preopcodes[1] == SPINOR_OP_WREN)
> +			val |= SSFSTS_CTL_SPOP;
> +		val |= SSFSTS_CTL_ACS;
> +		writel(val, ispi->base + HSFSTS_CTL);
> +
> +		ret = intel_spi_write_block(ispi, write_buf, block_size);
> +		if (ret) {
> +			dev_err(ispi->dev, "failed to write block\n");
> +			return ret;
> +		}
> +
> +		/* Start the write now */
> +		val = readl(ispi->base + HSFSTS_CTL);
> +		writel(val | HSFSTS_CTL_FGO, ispi->base + HSFSTS_CTL);
> +
> +		ret = intel_spi_wait_hw_busy(ispi);
> +		if (ret) {
> +			dev_err(ispi->dev, "timeout\n");
> +			return ret;
> +		}
> +
> +		status = readl(ispi->base + HSFSTS_CTL);
> +		if (status & HSFSTS_CTL_FCERR)
> +			ret = -EIO;
> +		else if (status & HSFSTS_CTL_AEL)
> +			ret = -EACCES;
> +
> +		if (ret < 0) {
> +			dev_err(ispi->dev, "write error: %llx: %#x\n", to,
> +				status);
> +			return ret;
> +		}
> +
> +		len -= block_size;
> +		to += block_size;
> +		retlen += block_size;
> +		write_buf += block_size;
> +	}
> +
> +	return retlen;
> +}

[...]

-- 
Best regards,
Marek Vasut

  parent reply	other threads:[~2016-11-25 17:38 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-14 10:24 [PATCH v5 0/3] " Mika Westerberg
2016-11-14 10:24 ` [PATCH v5 1/3] " Mika Westerberg
2016-11-21 14:26   ` Cyrille Pitchen
2016-11-25 17:26   ` Marek Vasut [this message]
2016-11-14 10:24 ` [PATCH v5 2/3] mfd: lpc_ich: Add support for SPI serial flash host controller Mika Westerberg
2016-11-25 17:28   ` Marek Vasut
2016-11-14 10:24 ` [PATCH v5 3/3] mfd: lpc_ich: Add support for Intel Apollo Lake SoC Mika Westerberg
2016-11-25 17:29   ` Marek Vasut
2016-11-18 19:04 ` [PATCH v5 0/3] spi-nor: Add support for Intel SPI serial flash controller Lee Jones
2016-11-19  7:35   ` Mika Westerberg
2016-11-19  8:03     ` Boris Brezillon
2016-11-21 10:51       ` Lee Jones
2016-11-22 10:20         ` Cyrille Pitchen

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=75195621-aeec-3d83-46ed-74ab1660fd5f@gmail.com \
    --to=marek.vasut@gmail.com \
    --cc=boris.brezillon@free-electrons.com \
    --cc=computersforpeace@gmail.com \
    --cc=cyrille.pitchen@atmel.com \
    --cc=dwmw2@infradead.org \
    --cc=key.seong.lim@intel.com \
    --cc=lee.jones@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mika.westerberg@linux.intel.com \
    --cc=ptyser@xes-inc.com \
    --cc=richard@nod.at \
    /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

all inboxes | Powered by JetHome®