From: Markus Schneider-Pargmann <msp@baylibre.com>
To: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Cc: Wolfgang Grandegger <wg@grandegger.com>,
Marc Kleine-Budde <mkl@pengutronix.de>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
"David S . Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
Conor Dooley <conor+dt@kernel.org>,
Chandrasekar Ramakrishnan <rcsekar@samsung.com>,
Michal Kubiak <michal.kubiak@intel.com>,
Vivek Yadav <vivek.2311@samsung.com>,
linux-can@vger.kernel.org, netdev@vger.kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
Simon Horman <simon.horman@corigine.com>
Subject: Re: [PATCH v2 5/6] can: tcan4x5x: Add support for tcan4552/4553
Date: Thu, 22 Jun 2023 14:23:39 +0200 [thread overview]
Message-ID: <20230622122339.6tkajdcenj5r3vdm@blmsp> (raw)
In-Reply-To: <21f12495-ffa9-a0bf-190a-11b6ae30ca45@linaro.org>
Hi Krzysztof,
On Wed, Jun 21, 2023 at 03:00:39PM +0200, Krzysztof Kozlowski wrote:
> On 21/06/2023 14:31, Markus Schneider-Pargmann wrote:
> > Hi Krzysztof,
> >
> > On Wed, Jun 21, 2023 at 12:28:34PM +0200, Krzysztof Kozlowski wrote:
> >> On 21/06/2023 11:31, Markus Schneider-Pargmann wrote:
> >>> tcan4552 and tcan4553 do not have wake or state pins, so they are
> >>> currently not compatible with the generic driver. The generic driver
> >>> uses tcan4x5x_disable_state() and tcan4x5x_disable_wake() if the gpios
> >>> are not defined. These functions use register bits that are not
> >>> available in tcan4552/4553.
> >>>
> >>> This patch adds support by introducing version information to reflect if
> >>> the chip has wake and state pins. Also the version is now checked.
> >>>
> >>> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
> >>> ---
> >>> drivers/net/can/m_can/tcan4x5x-core.c | 128 +++++++++++++++++++++-----
> >>> 1 file changed, 104 insertions(+), 24 deletions(-)
> >>>
> >>> diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
> >>> index fb9375fa20ec..756acd122075 100644
> >>> --- a/drivers/net/can/m_can/tcan4x5x-core.c
> >>> +++ b/drivers/net/can/m_can/tcan4x5x-core.c
> >>> @@ -7,6 +7,7 @@
> >>> #define TCAN4X5X_EXT_CLK_DEF 40000000
> >>>
> >>> #define TCAN4X5X_DEV_ID1 0x00
> >>> +#define TCAN4X5X_DEV_ID1_TCAN 0x4e414354 /* ASCII TCAN */
> >>> #define TCAN4X5X_DEV_ID2 0x04
> >>> #define TCAN4X5X_REV 0x08
> >>> #define TCAN4X5X_STATUS 0x0C
> >>> @@ -103,6 +104,13 @@
> >>> #define TCAN4X5X_WD_3_S_TIMER BIT(29)
> >>> #define TCAN4X5X_WD_6_S_TIMER (BIT(28) | BIT(29))
> >>>
> >>> +struct tcan4x5x_version_info {
> >>> + u32 id2_register;
> >>> +
> >>> + bool has_wake_pin;
> >>> + bool has_state_pin;
> >>> +};
> >>> +
> >>> static inline struct tcan4x5x_priv *cdev_to_priv(struct m_can_classdev *cdev)
> >>> {
> >>> return container_of(cdev, struct tcan4x5x_priv, cdev);
> >>> @@ -254,18 +262,68 @@ static int tcan4x5x_disable_state(struct m_can_classdev *cdev)
> >>> TCAN4X5X_DISABLE_INH_MSK, 0x01);
> >>> }
> >>>
> >>> -static int tcan4x5x_get_gpios(struct m_can_classdev *cdev)
> >>> +static const struct tcan4x5x_version_info tcan4x5x_generic;
> >>> +static const struct of_device_id tcan4x5x_of_match[];
> >>> +
> >>> +static const struct tcan4x5x_version_info
> >>> +*tcan4x5x_find_version_info(struct tcan4x5x_priv *priv, u32 id2_value)
> >>> +{
> >>> + for (int i = 0; tcan4x5x_of_match[i].data; ++i) {
> >>> + const struct tcan4x5x_version_info *vinfo =
> >>> + tcan4x5x_of_match[i].data;
> >>> + if (!vinfo->id2_register || id2_value == vinfo->id2_register) {
> >>> + dev_warn(&priv->spi->dev, "TCAN device is %s, please use it in DT\n",
> >>> + tcan4x5x_of_match[i].compatible);
> >>> + return vinfo;
> >>> + }
> >>> + }
> >>> +
> >>> + return &tcan4x5x_generic;
> >>
> >> I don't understand what do you want to achieve here. Kernel job is not
> >> to validate DTB, so if DTB says you have 4552, there is no need to
> >> double check. On the other hand, you have Id register so entire idea of
> >> custom compatibles can be dropped and instead you should detect the
> >> variant based on the ID.
> >
> > I can read the ID register but tcan4552 and 4553 do not have two
> > devicetree properties that tcan4550 has, namely state and wake gpios.
>
> Does not matter, you don't use OF matching to then differentiate
> handling of GPIOs to then read the register. You first read registers,
> so everything is auto-detectable.
>
> > See v1 discussion about that [1].
>
> Yeah, but your code is different, although maybe we just misunderstood
> each other. You wrote that you cannot use the GPIOs, so I assumed you
> need to know the variant before using the GPIOs. Then you need
> compatibles. It's not the case here. You can read the variant and based
> on this skip entirely GPIOs as they are entirely missing.
The version information is always readable for that chip, regardless of
state and wake GPIOs as far as I know. So yes it is possible to setup
the GPIOs based on the content of the ID register.
I personally would prefer separate compatibles. The binding
documentation needs to address that wake and state GPIOs are not
available for tcan4552/4553. I think having compatibles that are for
these chips would make sense then. However this is my opinion, you are
the maintainer.
Best,
Markus
>
> >
> > In v1 Marc pointed out that mcp251xfd is using an autodetection and warn
> > mechanism which I implemented here as well. [2]
>
> But why? Just read the ID and detect the variant based on this. Your DT
> still can have separate compatibles followed by fallback, that's not a
> problem.
>
>
> Best regards,
> Krzysztof
>
next prev parent reply other threads:[~2023-06-22 12:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-21 9:30 [PATCH v2 0/6] can: tcan4x5x: Introduce tcan4552/4553 Markus Schneider-Pargmann
2023-06-21 9:30 ` [PATCH v2 1/6] dt-bindings: can: tcan4x5x: Add tcan4552 and tcan4553 variants Markus Schneider-Pargmann
2023-06-21 10:26 ` Krzysztof Kozlowski
2023-06-21 10:29 ` Krzysztof Kozlowski
2023-06-21 12:20 ` Markus Schneider-Pargmann
2023-06-21 9:30 ` [PATCH v2 2/6] can: tcan4x5x: Remove reserved register 0x814 from writable table Markus Schneider-Pargmann
2023-06-21 9:31 ` [PATCH v2 3/6] can: tcan4x5x: Check size of mram configuration Markus Schneider-Pargmann
2023-06-21 9:31 ` [PATCH v2 4/6] can: tcan4x5x: Rename ID registers to match datasheet Markus Schneider-Pargmann
2023-06-21 9:31 ` [PATCH v2 5/6] can: tcan4x5x: Add support for tcan4552/4553 Markus Schneider-Pargmann
2023-06-21 10:28 ` Krzysztof Kozlowski
2023-06-21 12:31 ` Markus Schneider-Pargmann
2023-06-21 13:00 ` Krzysztof Kozlowski
2023-06-22 12:23 ` Markus Schneider-Pargmann [this message]
2023-06-22 12:52 ` Krzysztof Kozlowski
2023-06-27 14:23 ` Markus Schneider-Pargmann
2023-07-01 8:34 ` Krzysztof Kozlowski
2023-07-18 7:57 ` Marc Kleine-Budde
2023-06-21 9:31 ` [PATCH v2 6/6] can: tcan4x5x: Add error messages in probe Markus Schneider-Pargmann
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=20230622122339.6tkajdcenj5r3vdm@blmsp \
--to=msp@baylibre.com \
--cc=conor+dt@kernel.org \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=krzysztof.kozlowski@linaro.org \
--cc=kuba@kernel.org \
--cc=linux-can@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=michal.kubiak@intel.com \
--cc=mkl@pengutronix.de \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rcsekar@samsung.com \
--cc=robh+dt@kernel.org \
--cc=simon.horman@corigine.com \
--cc=vivek.2311@samsung.com \
--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 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).