Subject: [PATCH v3 0/6] can: tcan4x5x: Introduce tcan4552/4553

Hi everyone,

This series introduces two new chips tcan-4552 and tcan-4553. The
generic driver works in general but needs a few small changes. These are
caused by the removal of wake and state pins.

v3 removes the check of the devicetree compatible and completely relies
on the ID2 register.

Based on v6.5-rc1.

Best,
Markus

Changes in v3:
- Rebased to v6.5-rc1
- Removed devicetree compatible check in tcan driver. The device version
is now unconditionally detected using the ID2 register

Changes in v2:
- Update the binding documentation to specify tcan4552 and tcan4553 with
the tcan4x5x as fallback
- Update the driver to use auto detection as well. If compatible differs
from the ID2 register, use the ID2 register and print a warning.
- Small style changes

Previous versions:
v2 - https://lore.kernel.org/lkml/[email protected]/
v1 - https://lore.kernel.org/lkml/[email protected]

Markus Schneider-Pargmann (6):
dt-bindings: can: tcan4x5x: Add tcan4552 and tcan4553 variants
can: tcan4x5x: Remove reserved register 0x814 from writable table
can: tcan4x5x: Check size of mram configuration
can: tcan4x5x: Rename ID registers to match datasheet
can: tcan4x5x: Add support for tcan4552/4553
can: tcan4x5x: Add error messages in probe

.../devicetree/bindings/net/can/tcan4x5x.txt | 11 +-
drivers/net/can/m_can/m_can.c | 16 ++
drivers/net/can/m_can/m_can.h | 1 +
drivers/net/can/m_can/tcan4x5x-core.c | 139 +++++++++++++++---
drivers/net/can/m_can/tcan4x5x-regmap.c | 1 -
5 files changed, 142 insertions(+), 26 deletions(-)


base-commit: 06c2afb862f9da8dc5efa4b6076a0e48c3fbaaa5
--
2.40.1



Subject: [PATCH v3 3/6] can: tcan4x5x: Check size of mram configuration

To reduce debugging effort in case the mram is misconfigured, add this
size check of the DT configuration. Currently if the mram configuration
doesn't fit into the available MRAM it just overwrites other areas of
the MRAM.

Signed-off-by: Markus Schneider-Pargmann <[email protected]>
Reviewed-by: Michal Kubiak <[email protected]>
---
drivers/net/can/m_can/m_can.c | 16 ++++++++++++++++
drivers/net/can/m_can/m_can.h | 1 +
drivers/net/can/m_can/tcan4x5x-core.c | 5 +++++
3 files changed, 22 insertions(+)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index c5af92bcc9c9..9210cf0705a1 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -1887,6 +1887,22 @@ static int register_m_can_dev(struct net_device *dev)
return register_candev(dev);
}

+int m_can_check_mram_cfg(struct m_can_classdev *cdev, u32 mram_max_size)
+{
+ u32 total_size;
+
+ total_size = cdev->mcfg[MRAM_TXB].off - cdev->mcfg[MRAM_SIDF].off +
+ cdev->mcfg[MRAM_TXB].num * TXB_ELEMENT_SIZE;
+ if (total_size > mram_max_size) {
+ dev_err(cdev->dev, "Total size of mram config(%u) exceeds mram(%u)\n",
+ total_size, mram_max_size);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(m_can_check_mram_cfg);
+
static void m_can_of_parse_mram(struct m_can_classdev *cdev,
const u32 *mram_config_vals)
{
diff --git a/drivers/net/can/m_can/m_can.h b/drivers/net/can/m_can/m_can.h
index a839dc71dc9b..d8150d8128e7 100644
--- a/drivers/net/can/m_can/m_can.h
+++ b/drivers/net/can/m_can/m_can.h
@@ -101,6 +101,7 @@ int m_can_class_register(struct m_can_classdev *cdev);
void m_can_class_unregister(struct m_can_classdev *cdev);
int m_can_class_get_clocks(struct m_can_classdev *cdev);
int m_can_init_ram(struct m_can_classdev *priv);
+int m_can_check_mram_cfg(struct m_can_classdev *cdev, u32 mram_max_size);

int m_can_class_suspend(struct device *dev);
int m_can_class_resume(struct device *dev);
diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
index 2342aa011647..e706518176e4 100644
--- a/drivers/net/can/m_can/tcan4x5x-core.c
+++ b/drivers/net/can/m_can/tcan4x5x-core.c
@@ -80,6 +80,7 @@
TCAN4X5X_MCAN_IR_RF1F)

#define TCAN4X5X_MRAM_START 0x8000
+#define TCAN4X5X_MRAM_SIZE 0x800
#define TCAN4X5X_MCAN_OFFSET 0x1000

#define TCAN4X5X_CLEAR_ALL_INT 0xffffffff
@@ -307,6 +308,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
if (!mcan_class)
return -ENOMEM;

+ ret = m_can_check_mram_cfg(mcan_class, TCAN4X5X_MRAM_SIZE);
+ if (ret)
+ goto out_m_can_class_free_dev;
+
priv = cdev_to_priv(mcan_class);

priv->power = devm_regulator_get_optional(&spi->dev, "vsup");
--
2.40.1


Subject: [PATCH v3 6/6] can: tcan4x5x: Add error messages in probe

To be able to understand issues during probe easier, add error messages
if something fails.

Signed-off-by: Markus Schneider-Pargmann <[email protected]>
---
drivers/net/can/m_can/tcan4x5x-core.c | 26 ++++++++++++++++++++------
1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/net/can/m_can/tcan4x5x-core.c b/drivers/net/can/m_can/tcan4x5x-core.c
index 2d329b4e4f52..60380b50e553 100644
--- a/drivers/net/can/m_can/tcan4x5x-core.c
+++ b/drivers/net/can/m_can/tcan4x5x-core.c
@@ -402,6 +402,8 @@ static int tcan4x5x_can_probe(struct spi_device *spi)

/* Sanity check */
if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF) {
+ dev_err(&spi->dev, "Clock frequency is out of supported range %d\n",
+ freq);
ret = -ERANGE;
goto out_m_can_class_free_dev;
}
@@ -420,16 +422,22 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
/* Configure the SPI bus */
spi->bits_per_word = 8;
ret = spi_setup(spi);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "SPI setup failed %d\n", ret);
goto out_m_can_class_free_dev;
+ }

ret = tcan4x5x_regmap_init(priv);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "regmap init failed %d\n", ret);
goto out_m_can_class_free_dev;
+ }

ret = tcan4x5x_power_enable(priv->power, 1);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "Enabling regulator failed %d\n", ret);
goto out_m_can_class_free_dev;
+ }

version_info = tcan4x5x_find_version(priv);
if (IS_ERR(version_info)) {
@@ -438,16 +446,22 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
}

ret = tcan4x5x_get_gpios(mcan_class, version_info);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "Getting gpios failed %d\n", ret);
goto out_power;
+ }

ret = tcan4x5x_init(mcan_class);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "tcan initialization failed %d\n", ret);
goto out_power;
+ }

ret = m_can_class_register(mcan_class);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "Failed registering m_can device %d\n", ret);
goto out_power;
+ }

netdev_info(mcan_class->net, "TCAN4X5X successfully initialized.\n");
return 0;
--
2.40.1


Subject: [PATCH v3 1/6] dt-bindings: can: tcan4x5x: Add tcan4552 and tcan4553 variants

These two new chips do not have state or wake pins.

Signed-off-by: Markus Schneider-Pargmann <[email protected]>
Acked-by: Krzysztof Kozlowski <[email protected]>
---
.../devicetree/bindings/net/can/tcan4x5x.txt | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/Documentation/devicetree/bindings/net/can/tcan4x5x.txt b/Documentation/devicetree/bindings/net/can/tcan4x5x.txt
index e3501bfa22e9..170e23f0610d 100644
--- a/Documentation/devicetree/bindings/net/can/tcan4x5x.txt
+++ b/Documentation/devicetree/bindings/net/can/tcan4x5x.txt
@@ -4,7 +4,10 @@ Texas Instruments TCAN4x5x CAN Controller
This file provides device node information for the TCAN4x5x interface contains.

Required properties:
- - compatible: "ti,tcan4x5x"
+ - compatible:
+ "ti,tcan4552", "ti,tcan4x5x"
+ "ti,tcan4553", "ti,tcan4x5x" or
+ "ti,tcan4x5x"
- reg: 0
- #address-cells: 1
- #size-cells: 0
@@ -21,8 +24,10 @@ Optional properties:
- reset-gpios: Hardwired output GPIO. If not defined then software
reset.
- device-state-gpios: Input GPIO that indicates if the device is in
- a sleep state or if the device is active.
- - device-wake-gpios: Wake up GPIO to wake up the TCAN device.
+ a sleep state or if the device is active. Not
+ available with tcan4552/4553.
+ - device-wake-gpios: Wake up GPIO to wake up the TCAN device. Not
+ available with tcan4552/4553.

Example:
tcan4x5x: tcan4x5x@0 {
--
2.40.1


2023-07-24 09:14:41

by Marc Kleine-Budde

[permalink] [raw]
Subject: Re: [PATCH v3 6/6] can: tcan4x5x: Add error messages in probe

On 21.07.2023 15:50:09, Markus Schneider-Pargmann wrote:
> To be able to understand issues during probe easier, add error messages
> if something fails.

Can you print the error codes as "%pe", ERR_PTR(err)?

Marc

--
Pengutronix e.K. | Marc Kleine-Budde |
Embedded Linux | https://www.pengutronix.de |
Vertretung Nürnberg | Phone: +49-5121-206917-129 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |


Attachments:
(No filename) (489.00 B)
signature.asc (499.00 B)
Download all attachments
Subject: Re: [PATCH v3 6/6] can: tcan4x5x: Add error messages in probe

On Mon, Jul 24, 2023 at 10:37:51AM +0200, Marc Kleine-Budde wrote:
> On 21.07.2023 15:50:09, Markus Schneider-Pargmann wrote:
> > To be able to understand issues during probe easier, add error messages
> > if something fails.
>
> Can you print the error codes as "%pe", ERR_PTR(err)?

Yes, thank you, I will use that instead.

Best,
Markus

>
> Marc
>
> --
> Pengutronix e.K. | Marc Kleine-Budde |
> Embedded Linux | https://www.pengutronix.de |
> Vertretung Nürnberg | Phone: +49-5121-206917-129 |
> Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-9 |