Commit f702dbbb authored by David S. Miller's avatar David S. Miller

Merge tag 'linux-can-next-for-6.6-20230803' of...

Merge tag 'linux-can-next-for-6.6-20230803' of git://git.kernel.org/pub/scm/linux/kernel/git/mkl/linux-can-next

Marc Kleine-Budde says:

====================
pull-request: can-next 2023-08-03

This is a pull request of 9 patches for net-next/master.

The 1st patch is by Ruan Jinjie, targets the flexcan driver, and
cleans up the error handling of platform_get_irq() in the
flexcan_probe() function.

Markus Schneider-Pargmann contributes 6 patches for the tcan4x5x M_CAN
driver, consisting of some cleanups, and adding support for the
tcan4552/4553 chips.

Another patch by Ruan Jinjie, that cleans up the error path of
platform_get_irq() in the c_can_plat_probe() function of the C_CAN
platform driver.

The last patch is by Frank Jungclaus and adds support for the
CAN-USB/3 and CAN FD to the ESD USB CAN driver.
================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 992725ff 806e95ae
...@@ -4,7 +4,10 @@ Texas Instruments TCAN4x5x CAN Controller ...@@ -4,7 +4,10 @@ Texas Instruments TCAN4x5x CAN Controller
This file provides device node information for the TCAN4x5x interface contains. This file provides device node information for the TCAN4x5x interface contains.
Required properties: Required properties:
- compatible: "ti,tcan4x5x" - compatible:
"ti,tcan4552", "ti,tcan4x5x"
"ti,tcan4553", "ti,tcan4x5x" or
"ti,tcan4x5x"
- reg: 0 - reg: 0
- #address-cells: 1 - #address-cells: 1
- #size-cells: 0 - #size-cells: 0
...@@ -21,8 +24,10 @@ Optional properties: ...@@ -21,8 +24,10 @@ Optional properties:
- reset-gpios: Hardwired output GPIO. If not defined then software - reset-gpios: Hardwired output GPIO. If not defined then software
reset. reset.
- device-state-gpios: Input GPIO that indicates if the device is in - device-state-gpios: Input GPIO that indicates if the device is in
a sleep state or if the device is active. a sleep state or if the device is active. Not
- device-wake-gpios: Wake up GPIO to wake up the TCAN device. available with tcan4552/4553.
- device-wake-gpios: Wake up GPIO to wake up the TCAN device. Not
available with tcan4552/4553.
Example: Example:
tcan4x5x: tcan4x5x@0 { tcan4x5x: tcan4x5x@0 {
......
...@@ -285,8 +285,8 @@ static int c_can_plat_probe(struct platform_device *pdev) ...@@ -285,8 +285,8 @@ static int c_can_plat_probe(struct platform_device *pdev)
/* get the platform data */ /* get the platform data */
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq <= 0) { if (irq < 0) {
ret = -ENODEV; ret = irq;
goto exit; goto exit;
} }
......
...@@ -2089,8 +2089,8 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -2089,8 +2089,8 @@ static int flexcan_probe(struct platform_device *pdev)
} }
irq = platform_get_irq(pdev, 0); irq = platform_get_irq(pdev, 0);
if (irq <= 0) if (irq < 0)
return -ENODEV; return irq;
regs = devm_platform_ioremap_resource(pdev, 0); regs = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(regs)) if (IS_ERR(regs))
...@@ -2167,13 +2167,13 @@ static int flexcan_probe(struct platform_device *pdev) ...@@ -2167,13 +2167,13 @@ static int flexcan_probe(struct platform_device *pdev)
if (priv->devtype_data.quirks & FLEXCAN_QUIRK_NR_IRQ_3) { if (priv->devtype_data.quirks & FLEXCAN_QUIRK_NR_IRQ_3) {
priv->irq_boff = platform_get_irq(pdev, 1); priv->irq_boff = platform_get_irq(pdev, 1);
if (priv->irq_boff <= 0) { if (priv->irq_boff < 0) {
err = -ENODEV; err = priv->irq_boff;
goto failed_platform_get_irq; goto failed_platform_get_irq;
} }
priv->irq_err = platform_get_irq(pdev, 2); priv->irq_err = platform_get_irq(pdev, 2);
if (priv->irq_err <= 0) { if (priv->irq_err < 0) {
err = -ENODEV; err = priv->irq_err;
goto failed_platform_get_irq; goto failed_platform_get_irq;
} }
} }
......
...@@ -1913,6 +1913,22 @@ static int register_m_can_dev(struct net_device *dev) ...@@ -1913,6 +1913,22 @@ static int register_m_can_dev(struct net_device *dev)
return register_candev(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, static void m_can_of_parse_mram(struct m_can_classdev *cdev,
const u32 *mram_config_vals) const u32 *mram_config_vals)
{ {
......
...@@ -103,6 +103,7 @@ int m_can_class_register(struct m_can_classdev *cdev); ...@@ -103,6 +103,7 @@ int m_can_class_register(struct m_can_classdev *cdev);
void m_can_class_unregister(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_class_get_clocks(struct m_can_classdev *cdev);
int m_can_init_ram(struct m_can_classdev *priv); 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_suspend(struct device *dev);
int m_can_class_resume(struct device *dev); int m_can_class_resume(struct device *dev);
......
...@@ -6,8 +6,9 @@ ...@@ -6,8 +6,9 @@
#define TCAN4X5X_EXT_CLK_DEF 40000000 #define TCAN4X5X_EXT_CLK_DEF 40000000
#define TCAN4X5X_DEV_ID0 0x00 #define TCAN4X5X_DEV_ID1 0x00
#define TCAN4X5X_DEV_ID1 0x04 #define TCAN4X5X_DEV_ID1_TCAN 0x4e414354 /* ASCII TCAN */
#define TCAN4X5X_DEV_ID2 0x04
#define TCAN4X5X_REV 0x08 #define TCAN4X5X_REV 0x08
#define TCAN4X5X_STATUS 0x0C #define TCAN4X5X_STATUS 0x0C
#define TCAN4X5X_ERROR_STATUS_MASK 0x10 #define TCAN4X5X_ERROR_STATUS_MASK 0x10
...@@ -80,6 +81,7 @@ ...@@ -80,6 +81,7 @@
TCAN4X5X_MCAN_IR_RF1F) TCAN4X5X_MCAN_IR_RF1F)
#define TCAN4X5X_MRAM_START 0x8000 #define TCAN4X5X_MRAM_START 0x8000
#define TCAN4X5X_MRAM_SIZE 0x800
#define TCAN4X5X_MCAN_OFFSET 0x1000 #define TCAN4X5X_MCAN_OFFSET 0x1000
#define TCAN4X5X_CLEAR_ALL_INT 0xffffffff #define TCAN4X5X_CLEAR_ALL_INT 0xffffffff
...@@ -102,6 +104,37 @@ ...@@ -102,6 +104,37 @@
#define TCAN4X5X_WD_3_S_TIMER BIT(29) #define TCAN4X5X_WD_3_S_TIMER BIT(29)
#define TCAN4X5X_WD_6_S_TIMER (BIT(28) | BIT(29)) #define TCAN4X5X_WD_6_S_TIMER (BIT(28) | BIT(29))
struct tcan4x5x_version_info {
const char *name;
u32 id2_register;
bool has_wake_pin;
bool has_state_pin;
};
enum {
TCAN4552 = 0,
TCAN4553,
TCAN4X5X,
};
static const struct tcan4x5x_version_info tcan4x5x_versions[] = {
[TCAN4552] = {
.name = "4552",
.id2_register = 0x32353534,
},
[TCAN4553] = {
.name = "4553",
.id2_register = 0x32353534,
},
/* generic version with no id2_register at the end */
[TCAN4X5X] = {
.name = "generic",
.has_wake_pin = true,
.has_state_pin = true,
},
};
static inline struct tcan4x5x_priv *cdev_to_priv(struct m_can_classdev *cdev) static inline struct tcan4x5x_priv *cdev_to_priv(struct m_can_classdev *cdev)
{ {
return container_of(cdev, struct tcan4x5x_priv, cdev); return container_of(cdev, struct tcan4x5x_priv, cdev);
...@@ -253,11 +286,45 @@ static int tcan4x5x_disable_state(struct m_can_classdev *cdev) ...@@ -253,11 +286,45 @@ static int tcan4x5x_disable_state(struct m_can_classdev *cdev)
TCAN4X5X_DISABLE_INH_MSK, 0x01); TCAN4X5X_DISABLE_INH_MSK, 0x01);
} }
static int tcan4x5x_get_gpios(struct m_can_classdev *cdev) static const struct tcan4x5x_version_info
*tcan4x5x_find_version(struct tcan4x5x_priv *priv)
{
u32 val;
int ret;
ret = regmap_read(priv->regmap, TCAN4X5X_DEV_ID1, &val);
if (ret)
return ERR_PTR(ret);
if (val != TCAN4X5X_DEV_ID1_TCAN) {
dev_err(&priv->spi->dev, "Not a tcan device %x\n", val);
return ERR_PTR(-ENODEV);
}
ret = regmap_read(priv->regmap, TCAN4X5X_DEV_ID2, &val);
if (ret)
return ERR_PTR(ret);
for (int i = 0; i != ARRAY_SIZE(tcan4x5x_versions); ++i) {
const struct tcan4x5x_version_info *vinfo = &tcan4x5x_versions[i];
if (!vinfo->id2_register || val == vinfo->id2_register) {
dev_info(&priv->spi->dev, "Detected TCAN device version %s\n",
vinfo->name);
return vinfo;
}
}
return &tcan4x5x_versions[TCAN4X5X];
}
static int tcan4x5x_get_gpios(struct m_can_classdev *cdev,
const struct tcan4x5x_version_info *version_info)
{ {
struct tcan4x5x_priv *tcan4x5x = cdev_to_priv(cdev); struct tcan4x5x_priv *tcan4x5x = cdev_to_priv(cdev);
int ret; int ret;
if (version_info->has_wake_pin) {
tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake", tcan4x5x->device_wake_gpio = devm_gpiod_get(cdev->dev, "device-wake",
GPIOD_OUT_HIGH); GPIOD_OUT_HIGH);
if (IS_ERR(tcan4x5x->device_wake_gpio)) { if (IS_ERR(tcan4x5x->device_wake_gpio)) {
...@@ -266,6 +333,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev) ...@@ -266,6 +333,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev)
tcan4x5x_disable_wake(cdev); tcan4x5x_disable_wake(cdev);
} }
}
tcan4x5x->reset_gpio = devm_gpiod_get_optional(cdev->dev, "reset", tcan4x5x->reset_gpio = devm_gpiod_get_optional(cdev->dev, "reset",
GPIOD_OUT_LOW); GPIOD_OUT_LOW);
...@@ -276,6 +344,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev) ...@@ -276,6 +344,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev)
if (ret) if (ret)
return ret; return ret;
if (version_info->has_state_pin) {
tcan4x5x->device_state_gpio = devm_gpiod_get_optional(cdev->dev, tcan4x5x->device_state_gpio = devm_gpiod_get_optional(cdev->dev,
"device-state", "device-state",
GPIOD_IN); GPIOD_IN);
...@@ -283,6 +352,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev) ...@@ -283,6 +352,7 @@ static int tcan4x5x_get_gpios(struct m_can_classdev *cdev)
tcan4x5x->device_state_gpio = NULL; tcan4x5x->device_state_gpio = NULL;
tcan4x5x_disable_state(cdev); tcan4x5x_disable_state(cdev);
} }
}
return 0; return 0;
} }
...@@ -298,6 +368,7 @@ static struct m_can_ops tcan4x5x_ops = { ...@@ -298,6 +368,7 @@ static struct m_can_ops tcan4x5x_ops = {
static int tcan4x5x_can_probe(struct spi_device *spi) static int tcan4x5x_can_probe(struct spi_device *spi)
{ {
const struct tcan4x5x_version_info *version_info;
struct tcan4x5x_priv *priv; struct tcan4x5x_priv *priv;
struct m_can_classdev *mcan_class; struct m_can_classdev *mcan_class;
int freq, ret; int freq, ret;
...@@ -307,6 +378,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -307,6 +378,10 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
if (!mcan_class) if (!mcan_class)
return -ENOMEM; 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 = cdev_to_priv(mcan_class);
priv->power = devm_regulator_get_optional(&spi->dev, "vsup"); priv->power = devm_regulator_get_optional(&spi->dev, "vsup");
...@@ -327,6 +402,8 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -327,6 +402,8 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
/* Sanity check */ /* Sanity check */
if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF) { if (freq < 20000000 || freq > TCAN4X5X_EXT_CLK_DEF) {
dev_err(&spi->dev, "Clock frequency is out of supported range %d\n",
freq);
ret = -ERANGE; ret = -ERANGE;
goto out_m_can_class_free_dev; goto out_m_can_class_free_dev;
} }
...@@ -345,28 +422,49 @@ static int tcan4x5x_can_probe(struct spi_device *spi) ...@@ -345,28 +422,49 @@ static int tcan4x5x_can_probe(struct spi_device *spi)
/* Configure the SPI bus */ /* Configure the SPI bus */
spi->bits_per_word = 8; spi->bits_per_word = 8;
ret = spi_setup(spi); ret = spi_setup(spi);
if (ret) if (ret) {
dev_err(&spi->dev, "SPI setup failed %pe\n", ERR_PTR(ret));
goto out_m_can_class_free_dev; goto out_m_can_class_free_dev;
}
ret = tcan4x5x_regmap_init(priv); ret = tcan4x5x_regmap_init(priv);
if (ret) if (ret) {
dev_err(&spi->dev, "regmap init failed %pe\n", ERR_PTR(ret));
goto out_m_can_class_free_dev; goto out_m_can_class_free_dev;
}
ret = tcan4x5x_power_enable(priv->power, 1); ret = tcan4x5x_power_enable(priv->power, 1);
if (ret) if (ret) {
dev_err(&spi->dev, "Enabling regulator failed %pe\n",
ERR_PTR(ret));
goto out_m_can_class_free_dev; goto out_m_can_class_free_dev;
}
ret = tcan4x5x_get_gpios(mcan_class); version_info = tcan4x5x_find_version(priv);
if (ret) if (IS_ERR(version_info)) {
ret = PTR_ERR(version_info);
goto out_power; goto out_power;
}
ret = tcan4x5x_get_gpios(mcan_class, version_info);
if (ret) {
dev_err(&spi->dev, "Getting gpios failed %pe\n", ERR_PTR(ret));
goto out_power;
}
ret = tcan4x5x_init(mcan_class); ret = tcan4x5x_init(mcan_class);
if (ret) if (ret) {
dev_err(&spi->dev, "tcan initialization failed %pe\n",
ERR_PTR(ret));
goto out_power; goto out_power;
}
ret = m_can_class_register(mcan_class); ret = m_can_class_register(mcan_class);
if (ret) if (ret) {
dev_err(&spi->dev, "Failed registering m_can device %pe\n",
ERR_PTR(ret));
goto out_power; goto out_power;
}
netdev_info(mcan_class->net, "TCAN4X5X successfully initialized.\n"); netdev_info(mcan_class->net, "TCAN4X5X successfully initialized.\n");
return 0; return 0;
......
...@@ -95,7 +95,6 @@ static const struct regmap_range tcan4x5x_reg_table_wr_range[] = { ...@@ -95,7 +95,6 @@ static const struct regmap_range tcan4x5x_reg_table_wr_range[] = {
regmap_reg_range(0x000c, 0x0010), regmap_reg_range(0x000c, 0x0010),
/* Device configuration registers and Interrupt Flags*/ /* Device configuration registers and Interrupt Flags*/
regmap_reg_range(0x0800, 0x080c), regmap_reg_range(0x0800, 0x080c),
regmap_reg_range(0x0814, 0x0814),
regmap_reg_range(0x0820, 0x0820), regmap_reg_range(0x0820, 0x0820),
regmap_reg_range(0x0830, 0x0830), regmap_reg_range(0x0830, 0x0830),
/* M_CAN */ /* M_CAN */
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment