.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* CAN bus driver for Holt HI3110 CAN Controller with SPI Interface |
---|
2 | 3 | * |
---|
3 | 4 | * Copyright(C) Timesys Corporation 2016 |
---|
.. | .. |
---|
11 | 12 | * - Sascha Hauer, Marc Kleine-Budde, Pengutronix |
---|
12 | 13 | * - Simon Kallweit, intefo AG |
---|
13 | 14 | * 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. |
---|
18 | 15 | */ |
---|
19 | 16 | |
---|
20 | 17 | #include <linux/can/core.h> |
---|
.. | .. |
---|
24 | 21 | #include <linux/completion.h> |
---|
25 | 22 | #include <linux/delay.h> |
---|
26 | 23 | #include <linux/device.h> |
---|
27 | | -#include <linux/dma-mapping.h> |
---|
28 | 24 | #include <linux/freezer.h> |
---|
29 | 25 | #include <linux/interrupt.h> |
---|
30 | 26 | #include <linux/io.h> |
---|
.. | .. |
---|
129 | 125 | |
---|
130 | 126 | #define DEVICE_NAME "hi3110" |
---|
131 | 127 | |
---|
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 | | - |
---|
136 | 128 | static const struct can_bittiming_const hi3110_bittiming_const = { |
---|
137 | 129 | .name = DEVICE_NAME, |
---|
138 | 130 | .tseg1_min = 2, |
---|
.. | .. |
---|
159 | 151 | |
---|
160 | 152 | u8 *spi_tx_buf; |
---|
161 | 153 | u8 *spi_rx_buf; |
---|
162 | | - dma_addr_t spi_tx_dma; |
---|
163 | | - dma_addr_t spi_rx_dma; |
---|
164 | 154 | |
---|
165 | 155 | struct sk_buff *tx_skb; |
---|
166 | 156 | int tx_len; |
---|
.. | .. |
---|
187 | 177 | |
---|
188 | 178 | if (priv->tx_skb || priv->tx_len) |
---|
189 | 179 | net->stats.tx_errors++; |
---|
190 | | - if (priv->tx_skb) |
---|
191 | | - dev_kfree_skb(priv->tx_skb); |
---|
| 180 | + dev_kfree_skb(priv->tx_skb); |
---|
192 | 181 | if (priv->tx_len) |
---|
193 | 182 | can_free_echo_skb(priv->net, 0); |
---|
194 | 183 | priv->tx_skb = NULL; |
---|
.. | .. |
---|
220 | 209 | int ret; |
---|
221 | 210 | |
---|
222 | 211 | 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 | | - |
---|
230 | 212 | spi_message_add_tail(&t, &m); |
---|
231 | 213 | |
---|
232 | 214 | ret = spi_sync(spi, &m); |
---|
.. | .. |
---|
688 | 670 | |
---|
689 | 671 | txerr = hi3110_read(spi, HI3110_READ_TEC); |
---|
690 | 672 | rxerr = hi3110_read(spi, HI3110_READ_REC); |
---|
691 | | - cf->data[6] = txerr; |
---|
692 | | - cf->data[7] = rxerr; |
---|
693 | 673 | tx_state = txerr >= rxerr ? new_state : 0; |
---|
694 | 674 | rx_state = txerr <= rxerr ? new_state : 0; |
---|
695 | 675 | can_change_state(net, cf, tx_state, rx_state); |
---|
.. | .. |
---|
702 | 682 | hi3110_hw_sleep(spi); |
---|
703 | 683 | break; |
---|
704 | 684 | } |
---|
| 685 | + } else { |
---|
| 686 | + cf->data[6] = txerr; |
---|
| 687 | + cf->data[7] = rxerr; |
---|
705 | 688 | } |
---|
706 | 689 | } |
---|
707 | 690 | |
---|
.. | .. |
---|
918 | 901 | priv->spi = spi; |
---|
919 | 902 | mutex_init(&priv->hi3110_lock); |
---|
920 | 903 | |
---|
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; |
---|
941 | 909 | } |
---|
| 910 | + priv->spi_rx_buf = devm_kzalloc(&spi->dev, HI3110_RX_BUF_LEN, |
---|
| 911 | + GFP_KERNEL); |
---|
942 | 912 | |
---|
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; |
---|
958 | 916 | } |
---|
959 | 917 | |
---|
960 | 918 | SET_NETDEV_DEV(net, &spi->dev); |
---|