Skip to content

Commit d6911cf

Browse files
ambarusbroonie
authored andcommitted
spi: s3c64xx: allow full FIFO masks
The driver is wrong because is using partial register field masks for the SPI_STATUS.{RX, TX}_FIFO_LVL register fields. We see s3c64xx_spi_port_config.fifo_lvl_mask with different values for different instances of the same IP. Take s5pv210_spi_port_config for example, it defines: .fifo_lvl_mask = { 0x1ff, 0x7F }, fifo_lvl_mask is used to determine the FIFO depth of the instance of the IP. In this case, the integrator uses a 256 bytes FIFO for the first SPI instance of the IP, and a 64 bytes FIFO for the second instance. While the first mask reflects the SPI_STATUS.{RX, TX}_FIFO_LVL register fields, the second one is two bits short. Using partial field masks is misleading and can hide problems of the driver's logic. Allow platforms to specify the full FIFO mask, regardless of the FIFO depth. Introduce {rx, tx}_fifomask to represent the SPI_STATUS.{RX, TX}_FIFO_LVL register fields. It's a shifted mask defining the field's length and position. We'll be able to deprecate the use of @rx_lvl_offset, as the shift value can be determined from the mask. The existing compatibles shall start using {rx, tx}_fifomask so that they use the full field mask and to avoid shifting the mask to position, and then shifting it back to zero in the {TX, RX}_FIFO_LVL macros. @rx_lvl_offset will be deprecated in a further patch, after we have the infrastructure to deprecate @fifo_lvl_mask as well. No functional change intended. Signed-off-by: Tudor Ambarus <[email protected]> Link: https://msgid.link/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent ff8faa8 commit d6911cf

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

drivers/spi/spi-s3c64xx.c

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// Copyright (c) 2009 Samsung Electronics Co., Ltd.
44
// Jaswinder Singh <[email protected]>
55

6+
#include <linux/bitops.h>
67
#include <linux/bits.h>
78
#include <linux/clk.h>
89
#include <linux/delay.h>
@@ -109,10 +110,10 @@
109110
#define FIFO_LVL_MASK(i) ((i)->port_conf->fifo_lvl_mask[i->port_id])
110111
#define S3C64XX_SPI_ST_TX_DONE(v, i) (((v) & \
111112
(1 << (i)->port_conf->tx_st_done)) ? 1 : 0)
112-
#define TX_FIFO_LVL(v, i) (((v) >> S3C64XX_SPI_ST_TX_FIFO_LVL_SHIFT) & \
113-
FIFO_LVL_MASK(i))
114-
#define RX_FIFO_LVL(v, i) (((v) >> (i)->port_conf->rx_lvl_offset) & \
115-
FIFO_LVL_MASK(i))
113+
#define TX_FIFO_LVL(v, sdd) (((v) & (sdd)->tx_fifomask) >> \
114+
__ffs((sdd)->tx_fifomask))
115+
#define RX_FIFO_LVL(v, sdd) (((v) & (sdd)->rx_fifomask) >> \
116+
__ffs((sdd)->rx_fifomask))
116117
#define FIFO_DEPTH(i) ((FIFO_LVL_MASK(i) >> 1) + 1)
117118

118119
#define S3C64XX_SPI_MAX_TRAILCNT 0x3ff
@@ -136,6 +137,10 @@ struct s3c64xx_spi_dma_data {
136137
* struct s3c64xx_spi_port_config - SPI Controller hardware info
137138
* @fifo_lvl_mask: Bit-mask for {TX|RX}_FIFO_LVL bits in SPI_STATUS register.
138139
* @rx_lvl_offset: Bit offset of RX_FIFO_LVL bits in SPI_STATUS regiter.
140+
* @rx_fifomask: SPI_STATUS.RX_FIFO_LVL mask. Shifted mask defining the field's
141+
* length and position.
142+
* @tx_fifomask: SPI_STATUS.TX_FIFO_LVL mask. Shifted mask defining the field's
143+
* length and position.
139144
* @tx_st_done: Bit offset of TX_DONE bit in SPI_STATUS regiter.
140145
* @clk_div: Internal clock divider
141146
* @quirks: Bitmask of known quirks
@@ -154,6 +159,8 @@ struct s3c64xx_spi_dma_data {
154159
struct s3c64xx_spi_port_config {
155160
int fifo_lvl_mask[MAX_SPI_PORTS];
156161
int rx_lvl_offset;
162+
u32 rx_fifomask;
163+
u32 tx_fifomask;
157164
int tx_st_done;
158165
int quirks;
159166
int clk_div;
@@ -184,6 +191,10 @@ struct s3c64xx_spi_port_config {
184191
* @tx_dma: Local transmit DMA data (e.g. chan and direction)
185192
* @port_conf: Local SPI port configuration data
186193
* @port_id: Port identification number
194+
* @rx_fifomask: SPI_STATUS.RX_FIFO_LVL mask. Shifted mask defining the field's
195+
* length and position.
196+
* @tx_fifomask: SPI_STATUS.TX_FIFO_LVL mask. Shifted mask defining the field's
197+
* length and position.
187198
*/
188199
struct s3c64xx_spi_driver_data {
189200
void __iomem *regs;
@@ -203,6 +214,8 @@ struct s3c64xx_spi_driver_data {
203214
struct s3c64xx_spi_dma_data tx_dma;
204215
const struct s3c64xx_spi_port_config *port_conf;
205216
unsigned int port_id;
217+
u32 rx_fifomask;
218+
u32 tx_fifomask;
206219
};
207220

208221
static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)
@@ -1183,6 +1196,23 @@ static inline const struct s3c64xx_spi_port_config *s3c64xx_spi_get_port_config(
11831196
return (const struct s3c64xx_spi_port_config *)platform_get_device_id(pdev)->driver_data;
11841197
}
11851198

1199+
static void s3c64xx_spi_set_fifomask(struct s3c64xx_spi_driver_data *sdd)
1200+
{
1201+
const struct s3c64xx_spi_port_config *port_conf = sdd->port_conf;
1202+
1203+
if (port_conf->rx_fifomask)
1204+
sdd->rx_fifomask = port_conf->rx_fifomask;
1205+
else
1206+
sdd->rx_fifomask = FIFO_LVL_MASK(sdd) <<
1207+
port_conf->rx_lvl_offset;
1208+
1209+
if (port_conf->tx_fifomask)
1210+
sdd->tx_fifomask = port_conf->tx_fifomask;
1211+
else
1212+
sdd->tx_fifomask = FIFO_LVL_MASK(sdd) <<
1213+
S3C64XX_SPI_ST_TX_FIFO_LVL_SHIFT;
1214+
}
1215+
11861216
static int s3c64xx_spi_probe(struct platform_device *pdev)
11871217
{
11881218
struct resource *mem_res;
@@ -1231,6 +1261,8 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
12311261
sdd->port_id = pdev->id;
12321262
}
12331263

1264+
s3c64xx_spi_set_fifomask(sdd);
1265+
12341266
sdd->cur_bpw = 8;
12351267

12361268
sdd->tx_dma.direction = DMA_MEM_TO_DEV;

0 commit comments

Comments
 (0)