Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update rockchip CAN bus driver #374

Open
wants to merge 7 commits into
base: linux-6.1-stan-rkr1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions drivers/net/can/rockchip/rockchip_can.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#include <linux/can.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
#include <linux/can/led.h>
#include <linux/clk.h>
#include <linux/netdevice.h>
#include <linux/interrupt.h>
Expand Down Expand Up @@ -309,7 +308,7 @@ static int rockchip_can_start_xmit(struct sk_buff *skb, struct net_device *ndev)
}

writel(fi, rcan->base + CAN_TX_FRM_INFO);
can_put_echo_skb(skb, ndev, 0);
can_put_echo_skb(skb, ndev, 0, 0);

rockchip_can_write_cmdreg(rcan, TX_REQ);
netdev_dbg(ndev, "TX: can_id:0x%08x dlc: %d mode: 0x%08x data: 0x%08x 0x%08x\n",
Expand All @@ -334,7 +333,7 @@ static void rockchip_can_rx(struct net_device *ndev)
return;

fi = readl(rcan->base + CAN_RX_FRM_INFO);
cf->can_dlc = get_can_dlc(fi & CAN_DLC_MASK);
cf->can_dlc = can_cc_dlc2len(fi & CAN_DLC_MASK);
id = readl(rcan->base + CAN_RX_ID);
if (fi & CAN_EFF)
id |= CAN_EFF_FLAG;
Expand All @@ -355,8 +354,6 @@ static void rockchip_can_rx(struct net_device *ndev)
stats->rx_bytes += cf->can_dlc;
netif_rx(skb);

can_led_event(ndev, CAN_LED_EVENT_RX);

netdev_dbg(ndev, "%s can_id:0x%08x fi: 0x%08x dlc: %d data: 0x%08x 0x%08x\n",
__func__, cf->can_id, fi, cf->can_dlc,
data1, data2);
Expand Down Expand Up @@ -504,6 +501,7 @@ static irqreturn_t rockchip_can_interrupt(int irq, void *dev_id)
u8 err_int = ERR_WARN_INT | RX_BUF_OV | PASSIVE_ERR |
TX_LOSTARB | BUS_ERR_INT;
u8 isr;
unsigned int ign;

isr = readl(rcan->base + CAN_INT);
if (isr & TX_FINISH) {
Expand All @@ -512,9 +510,8 @@ static irqreturn_t rockchip_can_interrupt(int irq, void *dev_id)
CAN_DLC_MASK;
stats->tx_packets++;
rockchip_can_write_cmdreg(rcan, 0);
can_get_echo_skb(ndev, 0);
ign = can_get_echo_skb(ndev, 0, NULL);
netif_wake_queue(ndev);
can_led_event(ndev, CAN_LED_EVENT_TX);
}

if (isr & RX_FINISH)
Expand Down Expand Up @@ -555,7 +552,6 @@ static int rockchip_can_open(struct net_device *ndev)
goto exit_can_start;
}

can_led_event(ndev, CAN_LED_EVENT_OPEN);
netif_start_queue(ndev);

netdev_dbg(ndev, "%s\n", __func__);
Expand All @@ -575,7 +571,6 @@ static int rockchip_can_close(struct net_device *ndev)
netif_stop_queue(ndev);
rockchip_can_stop(ndev);
close_candev(ndev);
can_led_event(ndev, CAN_LED_EVENT_STOP);
pm_runtime_put(rcan->dev);

netdev_dbg(ndev, "%s\n", __func__);
Expand Down Expand Up @@ -771,8 +766,6 @@ static int rockchip_can_probe(struct platform_device *pdev)
goto err_disableclks;
}

devm_can_led_init(ndev);

pm_runtime_put(&pdev->dev);

return 0;
Expand Down
33 changes: 12 additions & 21 deletions drivers/net/can/rockchip/rockchip_canfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include <linux/types.h>
#include <linux/can/dev.h>
#include <linux/can/error.h>
#include <linux/can/led.h>
#include <linux/reset.h>
#include <linux/pm_runtime.h>
#include <linux/rockchip/cpu.h>
Expand Down Expand Up @@ -550,7 +549,7 @@ static int rockchip_canfd_start_xmit(struct sk_buff *skb,
if (cf->can_id & CAN_EFF_FLAG) {
/* Extended CAN ID format */
id = cf->can_id & CAN_EFF_MASK;
dlc = can_len2dlc(cf->len) & DLC_MASK;
dlc = can_fd_len2dlc(cf->len) & DLC_MASK;
dlc |= FORMAT_MASK;

/* Extended frames remote TX request */
Expand All @@ -559,7 +558,7 @@ static int rockchip_canfd_start_xmit(struct sk_buff *skb,
} else {
/* Standard CAN ID format */
id = cf->can_id & CAN_SFF_MASK;
dlc = can_len2dlc(cf->len) & DLC_MASK;
dlc = can_fd_len2dlc(cf->len) & DLC_MASK;

/* Standard frames remote TX request */
if (cf->can_id & CAN_RTR_FLAG)
Expand Down Expand Up @@ -596,7 +595,7 @@ static int rockchip_canfd_start_xmit(struct sk_buff *skb,
for (i = 0; i < cf->len; i += 4)
rockchip_canfd_write(rcan, CAN_TXDAT0 + i,
*(u32 *)(cf->data + i));
can_put_echo_skb(skb, ndev, 0);
can_put_echo_skb(skb, ndev, 0, 0);
rockchip_canfd_write(rcan, CAN_CMD, CAN_TX1_REQ);
local_irq_restore(flags);
return NETDEV_TX_OK;
Expand All @@ -609,7 +608,7 @@ static int rockchip_canfd_start_xmit(struct sk_buff *skb,
rockchip_canfd_write(rcan, CAN_TXDAT0 + i,
*(u32 *)(cf->data + i));

can_put_echo_skb(skb, ndev, 0);
can_put_echo_skb(skb, ndev, 0, 0);
rockchip_canfd_write(rcan, CAN_MODE,
rockchip_canfd_read(rcan, CAN_MODE) | MODE_SPACE_RX);
rockchip_canfd_write(rcan, CAN_CMD, cmd);
Expand Down Expand Up @@ -664,9 +663,9 @@ static int rockchip_canfd_rx(struct net_device *ndev)

/* Change CAN data length format to socketCAN data format */
if (dlc & FDF_MASK)
cf->len = can_dlc2len(dlc & DLC_MASK);
cf->len = can_fd_dlc2len(dlc & DLC_MASK);
else
cf->len = get_can_dlc(dlc & DLC_MASK);
cf->len = can_cc_dlc2len(dlc & DLC_MASK);

/* Change CAN ID format to socketCAN ID format */
if (dlc & FORMAT_MASK) {
Expand Down Expand Up @@ -695,8 +694,6 @@ static int rockchip_canfd_rx(struct net_device *ndev)
stats->rx_bytes += cf->len;
netif_rx(skb);

can_led_event(ndev, CAN_LED_EVENT_RX);

return 1;
}

Expand Down Expand Up @@ -736,9 +733,6 @@ static int rockchip_canfd_rx_poll(struct napi_struct *napi, int quota)
work_done += rockchip_canfd_rx(ndev);
}

if (work_done)
can_led_event(ndev, CAN_LED_EVENT_RX);

if (work_done < 6) {
napi_complete_done(napi, work_done);
rockchip_canfd_write(rcan, CAN_INT_MASK, 0);
Expand Down Expand Up @@ -800,7 +794,7 @@ static int rockchip_canfd_err(struct net_device *ndev, u32 isr)
cancel_delayed_work(&rcan->tx_err_work);
netif_stop_queue(ndev);
rockchip_canfd_stop(ndev);
can_free_echo_skb(ndev, 0);
can_free_echo_skb(ndev, 0, NULL);
rockchip_canfd_start(ndev);
netif_start_queue(ndev);
}
Expand All @@ -823,13 +817,15 @@ static irqreturn_t rockchip_canfd_interrupt(int irq, void *dev_id)
u32 dlc = 0;
u32 quota, work_done = 0;

unsigned int ign;

isr = rockchip_canfd_read(rcan, CAN_INT);
if (isr & TX_FINISH_INT) {
cancel_delayed_work(&rcan->tx_err_work);
dlc = rockchip_canfd_read(rcan, CAN_TXFIC);
/* transmission complete interrupt */
if (dlc & FDF_MASK)
stats->tx_bytes += can_dlc2len(dlc & DLC_MASK);
stats->tx_bytes += can_fd_dlc2len(dlc & DLC_MASK);
else
stats->tx_bytes += (dlc & DLC_MASK);
stats->tx_packets++;
Expand All @@ -849,9 +845,8 @@ static irqreturn_t rockchip_canfd_interrupt(int irq, void *dev_id)
0, 5000000, false, rcan, CAN_CMD))
netdev_err(ndev, "Warning: wait tx req timeout!\n");
rockchip_canfd_write(rcan, CAN_CMD, 0);
can_get_echo_skb(ndev, 0);
ign = can_get_echo_skb(ndev, 0, NULL);
netif_wake_queue(ndev);
can_led_event(ndev, CAN_LED_EVENT_TX);
}

if (isr & RX_FINISH_INT) {
Expand Down Expand Up @@ -903,7 +898,6 @@ static int rockchip_canfd_open(struct net_device *ndev)
goto exit_can_start;
}

can_led_event(ndev, CAN_LED_EVENT_OPEN);
if (rcan->mode == ROCKCHIP_RK3568_CAN_MODE_V2)
napi_enable(&rcan->napi);
netif_start_queue(ndev);
Expand All @@ -927,7 +921,6 @@ static int rockchip_canfd_close(struct net_device *ndev)
napi_disable(&rcan->napi);
rockchip_canfd_stop(ndev);
close_candev(ndev);
can_led_event(ndev, CAN_LED_EVENT_STOP);
pm_runtime_put(rcan->dev);
cancel_delayed_work_sync(&rcan->tx_err_work);

Expand Down Expand Up @@ -1153,7 +1146,7 @@ static int rockchip_canfd_probe(struct platform_device *pdev)

if (rcan->mode == ROCKCHIP_RK3568_CAN_MODE_V2) {
rcan->txtorx = 0;
netif_napi_add(ndev, &rcan->napi, rockchip_canfd_rx_poll, 6);
netif_napi_add_weight(ndev, &rcan->napi, rockchip_canfd_rx_poll, 6);
}

ndev->netdev_ops = &rockchip_canfd_netdev_ops;
Expand Down Expand Up @@ -1183,8 +1176,6 @@ static int rockchip_canfd_probe(struct platform_device *pdev)
goto err_disableclks;
}

devm_can_led_init(ndev);

return 0;

err_disableclks:
Expand Down