mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vignesh Raghavendra <vigneshr@ti.com>
To: Naga Sureshkumar Relli <naga.sureshkumar.relli@xilinx.com>,
	<broonie@kernel.org>, <bbrezillon@kernel.org>
Cc: <linux-spi@vger.kernel.org>, <dwmw2@infradead.org>,
	<marek.vasut@gmail.com>, <richard@nod.at>,
	<linux-mtd@lists.infradead.org>, <linux-kernel@vger.kernel.org>,
	<michal.simek@xilinx.com>, <nagasuresh12@gmail.com>
Subject: Re: [LINUX PATCH v2 3/3] spi: spi-mem: Add support for Zynq QSPI controller
Date: Fri, 5 Apr 2019 10:13:39 +0530	[thread overview]
Message-ID: <c8f73eab-99eb-ddbc-9776-ea6b3a3ecf0f@ti.com> (raw)
In-Reply-To: <1554105553-20207-1-git-send-email-naga.sureshkumar.relli@xilinx.com>



On 01/04/19 1:29 PM, Naga Sureshkumar Relli wrote:
> +/**
> + * zynq_qspi_config_op - Configure QSPI controller for specified transfer
> + * @xqspi:	Pointer to the zynq_qspi structure
> + * @qspi:	Pointer to the spi_device structure
> + *
> + * Sets the operational mode of QSPI controller for the next QSPI transfer and
> + * sets the requested clock frequency.
> + *
> + * Return:	0 on success and -EINVAL on invalid input parameter
> + *
> + * Note: If the requested frequency is not an exact match with what can be
> + * obtained using the prescalar value, the driver sets the clock frequency which
> + * is lower than the requested frequency (maximum lower) for the transfer. If
> + * the requested frequency is higher or lower than that is supported by the QSPI
> + * controller the driver will set the highest or lowest frequency supported by
> + * controller.
> + */
> +static int zynq_qspi_config_op(struct zynq_qspi *xqspi, struct spi_device *spi)
> +{
> +	u32 config_reg, baud_rate_val = 0;
> +
> +	/*
> +	 * Set the clock frequency
> +	 * The baud rate divisor is not a direct mapping to the value written
> +	 * into the configuration register (config_reg[5:3])
> +	 * i.e. 000 - divide by 2
> +	 *      001 - divide by 4
> +	 *      ----------------
> +	 *      111 - divide by 256
> +	 */
> +	while ((baud_rate_val < ZYNQ_QSPI_BAUD_DIV_MAX)  &&
> +	       (clk_get_rate(xqspi->refclk) / (2 << baud_rate_val)) >
> +		spi->max_speed_hz)
> +		baud_rate_val++;
> +

Instead use DIV_ROUND_UP, something like below should work(untested):

	unsigned long refclk_rate = clk_get_rate(xqspi->refclk);
	u32 baud_rate_val = DIV_ROUND_UP(refclk_rate, spi->max_speed_hz) - 1;

	if (baud_rate_val > ZYNQ_QSPI_BAUD_DIV_MAX)
		baud_rate_val = ZYNQ_QSPI_BAUD_DIV_MAX;

> +	config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET);
> +
> +	/* Set the QSPI clock phase and clock polarity */
> +	config_reg &= (~ZYNQ_QSPI_CONFIG_CPHA_MASK) &
> +		      (~ZYNQ_QSPI_CONFIG_CPOL_MASK);
> +	if (spi->mode & SPI_CPHA)
> +		config_reg |= ZYNQ_QSPI_CONFIG_CPHA_MASK;
> +	if (spi->mode & SPI_CPOL)
> +		config_reg |= ZYNQ_QSPI_CONFIG_CPOL_MASK;
> +
> +	config_reg &= ~ZYNQ_QSPI_CONFIG_BDRATE_MASK;
> +	config_reg |= (baud_rate_val << ZYNQ_QSPI_BAUD_DIV_SHIFT);
> +	zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg);
> +
> +	return 0;
> +}
> +

-- 
Regards
Vignesh

  parent reply	other threads:[~2019-04-05  4:43 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-01  7:59 Naga Sureshkumar Relli
2019-04-05  3:26 ` Applied "spi: spi-mem: Add support for Zynq QSPI controller" to the spi tree Mark Brown
2019-04-05  4:43 ` Vignesh Raghavendra [this message]
2019-04-05  5:25   ` [LINUX PATCH v2 3/3] spi: spi-mem: Add support for Zynq QSPI controller Naga Sureshkumar Relli
2019-04-05  6:15     ` Vignesh Raghavendra
2019-04-08 17:51 ` Guenter Roeck

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=c8f73eab-99eb-ddbc-9776-ea6b3a3ecf0f@ti.com \
    --to=vigneshr@ti.com \
    --cc=bbrezillon@kernel.org \
    --cc=broonie@kernel.org \
    --cc=dwmw2@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=marek.vasut@gmail.com \
    --cc=michal.simek@xilinx.com \
    --cc=naga.sureshkumar.relli@xilinx.com \
    --cc=nagasuresh12@gmail.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®