From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Alexander Shiyan <shc_work@mail.ru>, linux-can@vger.kernel.org
Cc: Wolfgang Grandegger <wg@grandegger.com>
Subject: Re: [PATCH 2/4] can: mcp251x: Improve mcp251x_hw_reset()
Date: Tue, 01 Apr 2014 22:47:19 +0200 [thread overview]
Message-ID: <533B25D7.8000701@pengutronix.de> (raw)
In-Reply-To: <1396001687-7092-2-git-send-email-shc_work@mail.ru>
[-- Attachment #1: Type: text/plain, Size: 2653 bytes --]
On 03/28/2014 11:14 AM, Alexander Shiyan wrote:
> The MCP251x utilizes an oscillator startup timer (OST), which holds the
> chip in reset, to insure that the oscillator has stabilized before the
> internal state machine begins to operate. The OST maintains reset for
> the first 128 OSC clock cycles after power up or reset.
> So, this patch removes unnecessary loops and reduce delay for power on
> and reset to the safe value.
>
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
> ---
> drivers/net/can/mcp251x.c | 33 +++++++++++++--------------------
> 1 file changed, 13 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/net/can/mcp251x.c b/drivers/net/can/mcp251x.c
> index 26879c7..fea41b4 100644
> --- a/drivers/net/can/mcp251x.c
> +++ b/drivers/net/can/mcp251x.c
> @@ -214,6 +214,8 @@
>
> #define TX_ECHO_SKB_MAX 1
>
> +#define MCP251X_OST_DELAY_MS (5)
> +
> #define DEVICE_NAME "mcp251x"
>
> static int mcp251x_enable_dma; /* Enable SPI DMA. Default: 0 (Off) */
> @@ -625,28 +627,20 @@ static int mcp251x_hw_reset(struct spi_device *spi)
> {
> struct mcp251x_priv *priv = spi_get_drvdata(spi);
> int ret;
> - unsigned long timeout;
> +
> + /* Wait for oscillator startup timer after power up */
> + mdelay(MCP251X_OST_DELAY_MS);
>
> priv->spi_tx_buf[0] = INSTRUCTION_RESET;
> - ret = spi_write(spi, priv->spi_tx_buf, 1);
> - if (ret) {
> - dev_err(&spi->dev, "reset failed: ret = %d\n", ret);
> - return -EIO;
> - }
> + ret = mcp251x_spi_trans(spi, 1);
> + if (ret)
> + return ret;
>
> - /* Wait for reset to finish */
> - timeout = jiffies + HZ;
> - mdelay(10);
> - while ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK)
> - != CANCTRL_REQOP_CONF) {
> - schedule();
> - if (time_after(jiffies, timeout)) {
> - dev_err(&spi->dev, "MCP251x didn't"
> - " enter in conf mode after reset\n");
> - return -EBUSY;
> - }
> - }
> - return 0;
> + /* Wait for oscillator startup timer after reset */
> + mdelay(MCP251X_OST_DELAY_MS);
> +
> + return ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK) ==
> + CANCTRL_REQOP_CONF) ? 0 : -ENODEV;
I've converted this into a more standard/readable:
+ reg = mcp251x_read_reg(spi, CANSTAT);
+ if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF)
+ return -ENODEV;
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 242 bytes --]
next prev parent reply other threads:[~2014-04-01 20:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-03-28 10:14 [PATCH 1/4] can: mcp251x: Check return value of spi_setup() Alexander Shiyan
2014-03-28 10:14 ` [PATCH 2/4] can: mcp251x: Improve mcp251x_hw_reset() Alexander Shiyan
2014-04-01 20:47 ` Marc Kleine-Budde [this message]
2014-03-28 10:14 ` [PATCH 3/4] can: mcp251x: Improve mcp251x_hw_probe() Alexander Shiyan
2014-04-01 20:46 ` Marc Kleine-Budde
2014-03-28 10:14 ` [PATCH 4/4] can: mcp251x: Remove unnecessary power disabling Alexander Shiyan
2014-04-01 20:36 ` Marc Kleine-Budde
2014-04-02 6:17 ` Alexander Shiyan
2014-04-02 7:05 ` Marc Kleine-Budde
2014-04-01 11:56 ` [PATCH 1/4] can: mcp251x: Check return value of spi_setup() Marc Kleine-Budde
2014-04-01 12:47 ` Alexander Shiyan
2014-04-01 12:49 ` Marc Kleine-Budde
2014-04-01 12:54 ` Alexander Shiyan
2014-04-01 20:40 ` Marc Kleine-Budde
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=533B25D7.8000701@pengutronix.de \
--to=mkl@pengutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=shc_work@mail.ru \
--cc=wg@grandegger.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.