From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
To: Anup Kulkarni <quic_anupkulk@quicinc.com>
Cc: <quic_msavaliy@quicinc.com>, <quic_vdadhani@quicinc.com>,
<mkl@pengutronix.de>, <manivannan.sadhasivam@linaro.org>,
<thomas.kopp@microchip.com>, <mailhol.vincent@wanadoo.fr>,
<davem@davemloft.net>, <edumazet@google.com>, <kuba@kernel.org>,
<pabeni@redhat.com>, <linux-can@vger.kernel.org>,
<netdev@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v1] can: mcp251xfd: Enable transceiver using gpio
Date: Tue, 6 Aug 2024 13:03:00 +0200 [thread overview]
Message-ID: <6ac470f9-c918-49d5-8b71-0b7c6ed2c83e@intel.com> (raw)
In-Reply-To: <20240806090339.785712-1-quic_anupkulk@quicinc.com>
On 8/6/24 11:03, Anup Kulkarni wrote:
> Ensure the CAN transceiver is active during mcp251xfd_open() and
> inactive during mcp251xfd_close() by utilizing
> mcp251xfd_transceiver_mode(). Adjust GPIO_0 to switch between
> NORMAL and STANDBY modes of transceiver.
>
> Signed-off-by: Anup Kulkarni <quic_anupkulk@quicinc.com>
> ---
> .../net/can/spi/mcp251xfd/mcp251xfd-core.c | 32 +++++++++++++++++++
> drivers/net/can/spi/mcp251xfd/mcp251xfd.h | 7 ++++
> 2 files changed, 39 insertions(+)
>
> diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
> index 3e7526274e34..3b56dc1721a5 100644
> --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
> +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd-core.c
> @@ -153,6 +153,25 @@ static inline int mcp251xfd_vdd_disable(const struct mcp251xfd_priv *priv)
> return regulator_disable(priv->reg_vdd);
> }
>
> +static int
> +mcp251xfd_transceiver_mode(const struct mcp251xfd_priv *priv,
> + const enum mcp251xfd_xceiver_mode mode)
> +{
> + int val, pmode, latch;
> +
> + if (mode == MCP251XFD_XCVR_NORMAL_MODE) {
> + pmode = MCP251XFD_REG_IOCON_PM0;
> + latch = 0;
> + } else if (mode == MCP251XFD_XCVR_STBY_MODE) {
> + pmode = MCP251XFD_REG_IOCON_PM0;
> + latch = MCP251XFD_REG_IOCON_LAT0;
> + } else {
> + return -EINVAL;
> + }
@pmode is always the same, no need for separate assignment
this if-else chain will be better as an switch statement
> + val = (pmode | latch) << priv->transceiver_pin;
put a newline here
> + return regmap_write(priv->map_reg, MCP251XFD_REG_IOCON, val);
> +}
> +
> static inline int
> mcp251xfd_transceiver_enable(const struct mcp251xfd_priv *priv)
> {
> @@ -1620,6 +1639,10 @@ static int mcp251xfd_open(struct net_device *ndev)
> if (err)
> goto out_transceiver_disable;
>
> + err = mcp251xfd_transceiver_mode(priv, MCP251XFD_XCVR_NORMAL_MODE);
> + if (err)
> + goto out_transceiver_disable;
> +
> clear_bit(MCP251XFD_FLAGS_DOWN, priv->flags);
> can_rx_offload_enable(&priv->offload);
>
> @@ -1668,6 +1691,7 @@ static int mcp251xfd_open(struct net_device *ndev)
>
> static int mcp251xfd_stop(struct net_device *ndev)
> {
> + int err;
> struct mcp251xfd_priv *priv = netdev_priv(ndev);
>
> netif_stop_queue(ndev);
> @@ -1678,6 +1702,9 @@ static int mcp251xfd_stop(struct net_device *ndev)
> free_irq(ndev->irq, priv);
> destroy_workqueue(priv->wq);
> can_rx_offload_disable(&priv->offload);
> + err = mcp251xfd_transceiver_mode(priv, MCP251XFD_XCVR_STBY_MODE);
> + if (err)
> + return err;
perhaps it would be better to continue here anyway?
> mcp251xfd_chip_stop(priv, CAN_STATE_STOPPED);
> mcp251xfd_transceiver_disable(priv);
> mcp251xfd_ring_free(priv);
> @@ -2051,6 +2078,11 @@ static int mcp251xfd_probe(struct spi_device *spi)
> "Failed to get clock-frequency!\n");
> }
>
> + err = device_property_read_u32(&spi->dev, "gpio-transceiver-pin", &priv->transceiver_pin);
> + if (err)
> + return dev_err_probe(&spi->dev, err,
> + "Failed to get gpio transceiver pin!\n");
> +
remember to fix it as Christophe J. has pointed out
> /* Sanity check */
> if (freq < MCP251XFD_SYSCLOCK_HZ_MIN ||
> freq > MCP251XFD_SYSCLOCK_HZ_MAX) {
> diff --git a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
> index dcbbd2b2fae8..14b086814bdb 100644
> --- a/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
> +++ b/drivers/net/can/spi/mcp251xfd/mcp251xfd.h
> @@ -614,6 +614,12 @@ enum mcp251xfd_flags {
> __MCP251XFD_FLAGS_SIZE__
> };
>
> +enum mcp251xfd_xceiver_mode {
> + MCP251XFD_XCVR_NORMAL_MODE,
> + MCP251XFD_XCVR_STBY_MODE,
> + MCP251XFD_XCVR_MODE_NONE
no need to add NONE mode if you don't make any use of it,
also the name is not consistent with the other modes
> +};
> +
> struct mcp251xfd_priv {
> struct can_priv can;
> struct can_rx_offload offload;
> @@ -670,6 +676,7 @@ struct mcp251xfd_priv {
>
> struct mcp251xfd_devtype_data devtype_data;
> struct can_berr_counter bec;
> + u32 transceiver_pin;
> };
>
> #define MCP251XFD_IS(_model) \
next prev parent reply other threads:[~2024-08-06 11:03 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-06 9:03 Anup Kulkarni
2024-08-06 9:20 ` Christophe JAILLET
2024-08-06 11:03 ` Przemek Kitszel [this message]
2024-08-06 20:02 ` Marc Kleine-Budde
2024-09-09 11:20 ` Anup Kulkarni
2024-08-07 7:47 ` kernel test robot
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=6ac470f9-c918-49d5-8b71-0b7c6ed2c83e@intel.com \
--to=przemyslaw.kitszel@intel.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mailhol.vincent@wanadoo.fr \
--cc=manivannan.sadhasivam@linaro.org \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=quic_anupkulk@quicinc.com \
--cc=quic_msavaliy@quicinc.com \
--cc=quic_vdadhani@quicinc.com \
--cc=thomas.kopp@microchip.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 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®