diff --git a/drivers/net/can/mttcan/hal/m_ttcan.c b/drivers/net/can/mttcan/hal/m_ttcan.c index 39b256b2..c2988efb 100644 --- a/drivers/net/can/mttcan/hal/m_ttcan.c +++ b/drivers/net/can/mttcan/hal/m_ttcan.c @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ #include "../include/m_ttcan.h" @@ -9,6 +9,11 @@ #define MTTCAN_INIT_TIMEOUT 1000 +#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE +#define MTTCAN_SPEED_5MBPS 5000000 +#define MTTCAN_SPEED_8MBPS 8333333 +#endif + void ttcan_print_version(struct ttcan_controller *ttcan) { u32 crel, endn; @@ -288,8 +293,35 @@ inline u32 ttcan_read_ecr(struct ttcan_controller *ttcan) return ttcan_read32(ttcan, ADR_MTTCAN_ECR); } -int ttcan_set_bitrate(struct ttcan_controller *ttcan) +#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE +static void tegra_mttcan_config_prod_settings(struct mttcan_priv *priv) { + struct ttcan_controller *ttcan = priv->ttcan; + char *prod_name; + int ret; + + switch (ttcan->bt_config.data.bitrate) { + case MTTCAN_SPEED_5MBPS: + prod_name = "prod_c_can_5m"; + break; + case MTTCAN_SPEED_8MBPS: + prod_name = "prod_c_can_8m"; + break; + default: + prod_name = "prod_c_can_2m_1m"; + break; + } + + ret = tegra_prod_set_by_name(&ttcan->base, prod_name, + ttcan->prod_list); + if (ret == 0) + dev_dbg(priv->device, "setting prod: %s\n", prod_name); +} +#endif + +int ttcan_set_bitrate(struct mttcan_priv *priv) +{ + struct ttcan_controller *ttcan = priv->ttcan; unsigned int temp_reg; int ret = 0; u32 cccr_reg; @@ -308,12 +340,12 @@ int ttcan_set_bitrate(struct ttcan_controller *ttcan) nbtp_reg |= (ttcan->bt_config.nominal.brp - 1) << MTT_NBTP_NBRP_SHIFT & MTT_NBTP_NBRP_MASK; - pr_debug("%s NBTP(0x%x) value (0x%x)\n", __func__, ADR_MTTCAN_NBTP, + dev_dbg(priv->device, "%s NBTP(0x%x) value (0x%x)\n", __func__, ADR_MTTCAN_NBTP, nbtp_reg); ret = ttcan_write32_check(ttcan, ADR_MTTCAN_NBTP, nbtp_reg, MTTCAN_NBTP_MSK); if (ret) { - pr_err("%s: Normal bitrate configuration failed\n", __func__); + dev_err(priv->device, "%s: Normal bitrate configuration failed\n", __func__); return ret; } @@ -332,28 +364,33 @@ int ttcan_set_bitrate(struct ttcan_controller *ttcan) dbtp_reg |= (ttcan->bt_config.data.tdc << MTT_DBTP_TDC_SHIFT) & MTT_DBTP_TDC_MASK; +#if KERNEL_VERSION(5, 16, 0) < LINUX_VERSION_CODE tdcr_reg = (ttcan->bt_config.data.tdc_offset << MTT_TDCR_TDCO_SHIFT) & MTT_TDCR_TDCO_MASK; tdcr_reg |= ttcan->tdc_offset; - - pr_debug("%s DBTP(0x%x) value (0x%x)\n", __func__, +#endif + dev_dbg(priv->device, "%s DBTP(0x%x) value (0x%x)\n", __func__, ADR_MTTCAN_DBTP, dbtp_reg); ret = ttcan_write32_check(ttcan, ADR_MTTCAN_DBTP, dbtp_reg, MTTCAN_DBTP_MSK); if (ret) { - pr_err("%s: Fast bitrate configuration failed\n", - __func__); + dev_err(priv->device, "%s: Fast bitrate configuration failed\n", __func__); return ret; } +#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE + if (ttcan->prod_list) + tegra_mttcan_config_prod_settings(priv); +#else ret = ttcan_write32_check(ttcan, ADR_MTTCAN_TDCR, tdcr_reg, MTTCAN_TDCR_MSK); if (ret) { - pr_err("%s: Fast bitrate configuration failed\n", + dev_err(priv->device, "%s: Fast bitrate configuration failed\n", __func__); return ret; } +#endif temp_reg = cccr_reg = ttcan_read32(ttcan, ADR_MTTCAN_CCCR); if (ttcan->bt_config.fd_flags & CAN_FD_FLAG) @@ -375,7 +412,7 @@ int ttcan_set_bitrate(struct ttcan_controller *ttcan) ret = ttcan_write32_check(ttcan, ADR_MTTCAN_CCCR, cccr_reg, MTTCAN_CCCR_MSK); if (ret) { - pr_err("%s: Error in enabling FD\n", __func__); + dev_err(priv->device, "%s: Error in enabling FD\n", __func__); return ret; } } diff --git a/drivers/net/can/mttcan/include/m_ttcan.h b/drivers/net/can/mttcan/include/m_ttcan.h index ab878a17..f6ebec3f 100644 --- a/drivers/net/can/mttcan/include/m_ttcan.h +++ b/drivers/net/can/mttcan/include/m_ttcan.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ #ifndef __M_TTCAN_DEF @@ -287,6 +287,9 @@ struct ttcan_controller { struct list_head rx_q1; struct list_head rx_b; struct list_head tx_evt; +#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE + struct tegra_prod *prod_list; +#endif void __iomem *base; /* controller regs space should be remapped. */ void __iomem *xbase; /* extra registers are mapped */ void __iomem *mram_vbase; @@ -494,7 +497,7 @@ void ttcan_set_tx_cancel_request(struct ttcan_controller *ttcan, u32 txbcr); u32 ttcan_read_tx_cancelled_reg(struct ttcan_controller *ttcan); u32 ttcan_read_psr(struct ttcan_controller *ttcan); int ttcan_read_rx_buffer(struct ttcan_controller *ttcan); -int ttcan_set_bitrate(struct ttcan_controller *ttcan); +int ttcan_set_bitrate(struct mttcan_priv *priv); int ttcan_tx_req_pending(struct ttcan_controller *ttcan); int ttcan_tx_buff_req_pending(struct ttcan_controller *ttcan, u8 index); diff --git a/drivers/net/can/mttcan/include/m_ttcan_linux.h b/drivers/net/can/mttcan/include/m_ttcan_linux.h index 0e76c49a..9fa451e0 100644 --- a/drivers/net/can/mttcan/include/m_ttcan_linux.h +++ b/drivers/net/can/mttcan/include/m_ttcan_linux.h @@ -1,6 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ /* - * Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + * Copyright (c) 2022-2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ #ifndef _M_TTCAN_LINUX_H @@ -31,6 +31,9 @@ #include #include #include +#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE +#include +#endif #include #include #ifdef CONFIG_CLK_SRC_TEGRA18_US_TIMER diff --git a/drivers/net/can/mttcan/native/m_ttcan_linux.c b/drivers/net/can/mttcan/native/m_ttcan_linux.c index 68728c72..9742c205 100644 --- a/drivers/net/can/mttcan/native/m_ttcan_linux.c +++ b/drivers/net/can/mttcan/native/m_ttcan_linux.c @@ -988,7 +988,7 @@ static int mttcan_do_set_bittiming(struct net_device *dev) if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO) priv->ttcan->bt_config.fd_flags |= CAN_FD_NON_ISO_FLAG; - err = ttcan_set_bitrate(priv->ttcan); + err = ttcan_set_bitrate(priv); if (err) { netdev_err(priv->dev, "Unable to set bitrate\n"); return err; @@ -1906,6 +1906,14 @@ static int mttcan_probe(struct platform_device *pdev) if (ret) goto exit_free_device; +#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE + priv->ttcan->prod_list = devm_tegra_prod_get(&pdev->dev); + if (IS_ERR_OR_NULL(priv->ttcan->prod_list)) { + dev_dbg(&pdev->dev, "Prod-setting not available\n"); + priv->ttcan->prod_list = NULL; + } +#endif + ret = register_mttcan_dev(dev); if (ret) { dev_err(&pdev->dev, "registering %s failed (err=%d)\n",