forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/net/can/spi/hi311x.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* CAN bus driver for Holt HI3110 CAN Controller with SPI Interface
23 *
34 * Copyright(C) Timesys Corporation 2016
....@@ -11,10 +12,6 @@
1112 * - Sascha Hauer, Marc Kleine-Budde, Pengutronix
1213 * - Simon Kallweit, intefo AG
1314 * Copyright 2007
14
- *
15
- * This program is free software; you can redistribute it and/or modify
16
- * it under the terms of the GNU General Public License version 2 as
17
- * published by the Free Software Foundation.
1815 */
1916
2017 #include <linux/can/core.h>
....@@ -24,7 +21,6 @@
2421 #include <linux/completion.h>
2522 #include <linux/delay.h>
2623 #include <linux/device.h>
27
-#include <linux/dma-mapping.h>
2824 #include <linux/freezer.h>
2925 #include <linux/interrupt.h>
3026 #include <linux/io.h>
....@@ -129,10 +125,6 @@
129125
130126 #define DEVICE_NAME "hi3110"
131127
132
-static int hi3110_enable_dma = 1; /* Enable SPI DMA. Default: 1 (On) */
133
-module_param(hi3110_enable_dma, int, 0444);
134
-MODULE_PARM_DESC(hi3110_enable_dma, "Enable SPI DMA. Default: 1 (On)");
135
-
136128 static const struct can_bittiming_const hi3110_bittiming_const = {
137129 .name = DEVICE_NAME,
138130 .tseg1_min = 2,
....@@ -159,8 +151,6 @@
159151
160152 u8 *spi_tx_buf;
161153 u8 *spi_rx_buf;
162
- dma_addr_t spi_tx_dma;
163
- dma_addr_t spi_rx_dma;
164154
165155 struct sk_buff *tx_skb;
166156 int tx_len;
....@@ -187,8 +177,7 @@
187177
188178 if (priv->tx_skb || priv->tx_len)
189179 net->stats.tx_errors++;
190
- if (priv->tx_skb)
191
- dev_kfree_skb(priv->tx_skb);
180
+ dev_kfree_skb(priv->tx_skb);
192181 if (priv->tx_len)
193182 can_free_echo_skb(priv->net, 0);
194183 priv->tx_skb = NULL;
....@@ -220,13 +209,6 @@
220209 int ret;
221210
222211 spi_message_init(&m);
223
-
224
- if (hi3110_enable_dma) {
225
- t.tx_dma = priv->spi_tx_dma;
226
- t.rx_dma = priv->spi_rx_dma;
227
- m.is_dma_mapped = 1;
228
- }
229
-
230212 spi_message_add_tail(&t, &m);
231213
232214 ret = spi_sync(spi, &m);
....@@ -688,8 +670,6 @@
688670
689671 txerr = hi3110_read(spi, HI3110_READ_TEC);
690672 rxerr = hi3110_read(spi, HI3110_READ_REC);
691
- cf->data[6] = txerr;
692
- cf->data[7] = rxerr;
693673 tx_state = txerr >= rxerr ? new_state : 0;
694674 rx_state = txerr <= rxerr ? new_state : 0;
695675 can_change_state(net, cf, tx_state, rx_state);
....@@ -702,6 +682,9 @@
702682 hi3110_hw_sleep(spi);
703683 break;
704684 }
685
+ } else {
686
+ cf->data[6] = txerr;
687
+ cf->data[7] = rxerr;
705688 }
706689 }
707690
....@@ -918,43 +901,18 @@
918901 priv->spi = spi;
919902 mutex_init(&priv->hi3110_lock);
920903
921
- /* If requested, allocate DMA buffers */
922
- if (hi3110_enable_dma) {
923
- spi->dev.coherent_dma_mask = ~0;
924
-
925
- /* Minimum coherent DMA allocation is PAGE_SIZE, so allocate
926
- * that much and share it between Tx and Rx DMA buffers.
927
- */
928
- priv->spi_tx_buf = dmam_alloc_coherent(&spi->dev,
929
- PAGE_SIZE,
930
- &priv->spi_tx_dma,
931
- GFP_DMA);
932
-
933
- if (priv->spi_tx_buf) {
934
- priv->spi_rx_buf = (priv->spi_tx_buf + (PAGE_SIZE / 2));
935
- priv->spi_rx_dma = (dma_addr_t)(priv->spi_tx_dma +
936
- (PAGE_SIZE / 2));
937
- } else {
938
- /* Fall back to non-DMA */
939
- hi3110_enable_dma = 0;
940
- }
904
+ priv->spi_tx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN,
905
+ GFP_KERNEL);
906
+ if (!priv->spi_tx_buf) {
907
+ ret = -ENOMEM;
908
+ goto error_probe;
941909 }
910
+ priv->spi_rx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN,
911
+ GFP_KERNEL);
942912
943
- /* Allocate non-DMA buffers */
944
- if (!hi3110_enable_dma) {
945
- priv->spi_tx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN,
946
- GFP_KERNEL);
947
- if (!priv->spi_tx_buf) {
948
- ret = -ENOMEM;
949
- goto error_probe;
950
- }
951
- priv->spi_rx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN,
952
- GFP_KERNEL);
953
-
954
- if (!priv->spi_rx_buf) {
955
- ret = -ENOMEM;
956
- goto error_probe;
957
- }
913
+ if (!priv->spi_rx_buf) {
914
+ ret = -ENOMEM;
915
+ goto error_probe;
958916 }
959917
960918 SET_NETDEV_DEV(net, &spi->dev);