mirror of
git://nv-tegra.nvidia.com/linux-nv-oot.git
synced 2025-12-22 17:25:35 +03:00
CAN: program prod setting for tdcr register
Using this patch we are programming tdcr register of can controllers based on the data speed. Bug 4165928 Change-Id: I4d3f9426695b4ac19bef144f242dcf74371c00b7 Signed-off-by: Manish Bhardwaj <mbhardwaj@nvidia.com> Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/2924921 Reviewed-by: Suresh Venkatachalam <skathirampat@nvidia.com> Reviewed-by: Krishna Yarlagadda <kyarlagadda@nvidia.com> Reviewed-by: Laxman Dewangan <ldewangan@nvidia.com> GVS: Gerrit_Virtual_Submit <buildbot_gerritrpt@nvidia.com>
This commit is contained in:
committed by
mobile promotions
parent
821e738ecc
commit
df0489a1e0
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* 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"
|
#include "../include/m_ttcan.h"
|
||||||
@@ -9,6 +9,11 @@
|
|||||||
|
|
||||||
#define MTTCAN_INIT_TIMEOUT 1000
|
#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)
|
void ttcan_print_version(struct ttcan_controller *ttcan)
|
||||||
{
|
{
|
||||||
u32 crel, endn;
|
u32 crel, endn;
|
||||||
@@ -288,8 +293,35 @@ inline u32 ttcan_read_ecr(struct ttcan_controller *ttcan)
|
|||||||
return ttcan_read32(ttcan, ADR_MTTCAN_ECR);
|
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;
|
unsigned int temp_reg;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
u32 cccr_reg;
|
u32 cccr_reg;
|
||||||
@@ -308,12 +340,12 @@ int ttcan_set_bitrate(struct ttcan_controller *ttcan)
|
|||||||
nbtp_reg |= (ttcan->bt_config.nominal.brp - 1) <<
|
nbtp_reg |= (ttcan->bt_config.nominal.brp - 1) <<
|
||||||
MTT_NBTP_NBRP_SHIFT & MTT_NBTP_NBRP_MASK;
|
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);
|
nbtp_reg);
|
||||||
ret = ttcan_write32_check(ttcan, ADR_MTTCAN_NBTP, nbtp_reg,
|
ret = ttcan_write32_check(ttcan, ADR_MTTCAN_NBTP, nbtp_reg,
|
||||||
MTTCAN_NBTP_MSK);
|
MTTCAN_NBTP_MSK);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("%s: Normal bitrate configuration failed\n", __func__);
|
dev_err(priv->device, "%s: Normal bitrate configuration failed\n", __func__);
|
||||||
return ret;
|
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) &
|
dbtp_reg |= (ttcan->bt_config.data.tdc << MTT_DBTP_TDC_SHIFT) &
|
||||||
MTT_DBTP_TDC_MASK;
|
MTT_DBTP_TDC_MASK;
|
||||||
|
|
||||||
|
#if KERNEL_VERSION(5, 16, 0) < LINUX_VERSION_CODE
|
||||||
tdcr_reg = (ttcan->bt_config.data.tdc_offset <<
|
tdcr_reg = (ttcan->bt_config.data.tdc_offset <<
|
||||||
MTT_TDCR_TDCO_SHIFT) & MTT_TDCR_TDCO_MASK;
|
MTT_TDCR_TDCO_SHIFT) & MTT_TDCR_TDCO_MASK;
|
||||||
|
|
||||||
tdcr_reg |= ttcan->tdc_offset;
|
tdcr_reg |= ttcan->tdc_offset;
|
||||||
|
#endif
|
||||||
pr_debug("%s DBTP(0x%x) value (0x%x)\n", __func__,
|
dev_dbg(priv->device, "%s DBTP(0x%x) value (0x%x)\n", __func__,
|
||||||
ADR_MTTCAN_DBTP, dbtp_reg);
|
ADR_MTTCAN_DBTP, dbtp_reg);
|
||||||
ret = ttcan_write32_check(ttcan, ADR_MTTCAN_DBTP,
|
ret = ttcan_write32_check(ttcan, ADR_MTTCAN_DBTP,
|
||||||
dbtp_reg, MTTCAN_DBTP_MSK);
|
dbtp_reg, MTTCAN_DBTP_MSK);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("%s: Fast bitrate configuration failed\n",
|
dev_err(priv->device, "%s: Fast bitrate configuration failed\n", __func__);
|
||||||
__func__);
|
|
||||||
return ret;
|
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,
|
ret = ttcan_write32_check(ttcan, ADR_MTTCAN_TDCR,
|
||||||
tdcr_reg, MTTCAN_TDCR_MSK);
|
tdcr_reg, MTTCAN_TDCR_MSK);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("%s: Fast bitrate configuration failed\n",
|
dev_err(priv->device, "%s: Fast bitrate configuration failed\n",
|
||||||
__func__);
|
__func__);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
temp_reg = cccr_reg = ttcan_read32(ttcan, ADR_MTTCAN_CCCR);
|
temp_reg = cccr_reg = ttcan_read32(ttcan, ADR_MTTCAN_CCCR);
|
||||||
if (ttcan->bt_config.fd_flags & CAN_FD_FLAG)
|
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,
|
ret = ttcan_write32_check(ttcan, ADR_MTTCAN_CCCR,
|
||||||
cccr_reg, MTTCAN_CCCR_MSK);
|
cccr_reg, MTTCAN_CCCR_MSK);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pr_err("%s: Error in enabling FD\n", __func__);
|
dev_err(priv->device, "%s: Error in enabling FD\n", __func__);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* 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
|
#ifndef __M_TTCAN_DEF
|
||||||
@@ -287,6 +287,9 @@ struct ttcan_controller {
|
|||||||
struct list_head rx_q1;
|
struct list_head rx_q1;
|
||||||
struct list_head rx_b;
|
struct list_head rx_b;
|
||||||
struct list_head tx_evt;
|
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 *base; /* controller regs space should be remapped. */
|
||||||
void __iomem *xbase; /* extra registers are mapped */
|
void __iomem *xbase; /* extra registers are mapped */
|
||||||
void __iomem *mram_vbase;
|
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_tx_cancelled_reg(struct ttcan_controller *ttcan);
|
||||||
u32 ttcan_read_psr(struct ttcan_controller *ttcan);
|
u32 ttcan_read_psr(struct ttcan_controller *ttcan);
|
||||||
int ttcan_read_rx_buffer(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_req_pending(struct ttcan_controller *ttcan);
|
||||||
int ttcan_tx_buff_req_pending(struct ttcan_controller *ttcan, u8 index);
|
int ttcan_tx_buff_req_pending(struct ttcan_controller *ttcan, u8 index);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
/* 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
|
#ifndef _M_TTCAN_LINUX_H
|
||||||
@@ -31,6 +31,9 @@
|
|||||||
#include <linux/net_tstamp.h>
|
#include <linux/net_tstamp.h>
|
||||||
#include <linux/spinlock.h>
|
#include <linux/spinlock.h>
|
||||||
#include <linux/clocksource.h>
|
#include <linux/clocksource.h>
|
||||||
|
#if KERNEL_VERSION(5, 16, 0) >= LINUX_VERSION_CODE
|
||||||
|
#include <linux/tegra_prod.h>
|
||||||
|
#endif
|
||||||
#include <linux/platform/tegra/ptp-notifier.h>
|
#include <linux/platform/tegra/ptp-notifier.h>
|
||||||
#include <linux/mailbox_client.h>
|
#include <linux/mailbox_client.h>
|
||||||
#ifdef CONFIG_CLK_SRC_TEGRA18_US_TIMER
|
#ifdef CONFIG_CLK_SRC_TEGRA18_US_TIMER
|
||||||
|
|||||||
@@ -988,7 +988,7 @@ static int mttcan_do_set_bittiming(struct net_device *dev)
|
|||||||
if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
|
if (priv->can.ctrlmode & CAN_CTRLMODE_FD_NON_ISO)
|
||||||
priv->ttcan->bt_config.fd_flags |= CAN_FD_NON_ISO_FLAG;
|
priv->ttcan->bt_config.fd_flags |= CAN_FD_NON_ISO_FLAG;
|
||||||
|
|
||||||
err = ttcan_set_bitrate(priv->ttcan);
|
err = ttcan_set_bitrate(priv);
|
||||||
if (err) {
|
if (err) {
|
||||||
netdev_err(priv->dev, "Unable to set bitrate\n");
|
netdev_err(priv->dev, "Unable to set bitrate\n");
|
||||||
return err;
|
return err;
|
||||||
@@ -1906,6 +1906,14 @@ static int mttcan_probe(struct platform_device *pdev)
|
|||||||
if (ret)
|
if (ret)
|
||||||
goto exit_free_device;
|
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);
|
ret = register_mttcan_dev(dev);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
|
dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user