mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-11-11 12:28:41 +08:00
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 <tudor.ambarus@linaro.org> Link: https://msgid.link/r/20240216070555.2483977-4-tudor.ambarus@linaro.org Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
ff8faa8a5c
commit
d6911cf27e
@ -3,6 +3,7 @@
|
|||||||
// Copyright (c) 2009 Samsung Electronics Co., Ltd.
|
// Copyright (c) 2009 Samsung Electronics Co., Ltd.
|
||||||
// Jaswinder Singh <jassi.brar@samsung.com>
|
// Jaswinder Singh <jassi.brar@samsung.com>
|
||||||
|
|
||||||
|
#include <linux/bitops.h>
|
||||||
#include <linux/bits.h>
|
#include <linux/bits.h>
|
||||||
#include <linux/clk.h>
|
#include <linux/clk.h>
|
||||||
#include <linux/delay.h>
|
#include <linux/delay.h>
|
||||||
@ -109,10 +110,10 @@
|
|||||||
#define FIFO_LVL_MASK(i) ((i)->port_conf->fifo_lvl_mask[i->port_id])
|
#define FIFO_LVL_MASK(i) ((i)->port_conf->fifo_lvl_mask[i->port_id])
|
||||||
#define S3C64XX_SPI_ST_TX_DONE(v, i) (((v) & \
|
#define S3C64XX_SPI_ST_TX_DONE(v, i) (((v) & \
|
||||||
(1 << (i)->port_conf->tx_st_done)) ? 1 : 0)
|
(1 << (i)->port_conf->tx_st_done)) ? 1 : 0)
|
||||||
#define TX_FIFO_LVL(v, i) (((v) >> S3C64XX_SPI_ST_TX_FIFO_LVL_SHIFT) & \
|
#define TX_FIFO_LVL(v, sdd) (((v) & (sdd)->tx_fifomask) >> \
|
||||||
FIFO_LVL_MASK(i))
|
__ffs((sdd)->tx_fifomask))
|
||||||
#define RX_FIFO_LVL(v, i) (((v) >> (i)->port_conf->rx_lvl_offset) & \
|
#define RX_FIFO_LVL(v, sdd) (((v) & (sdd)->rx_fifomask) >> \
|
||||||
FIFO_LVL_MASK(i))
|
__ffs((sdd)->rx_fifomask))
|
||||||
#define FIFO_DEPTH(i) ((FIFO_LVL_MASK(i) >> 1) + 1)
|
#define FIFO_DEPTH(i) ((FIFO_LVL_MASK(i) >> 1) + 1)
|
||||||
|
|
||||||
#define S3C64XX_SPI_MAX_TRAILCNT 0x3ff
|
#define S3C64XX_SPI_MAX_TRAILCNT 0x3ff
|
||||||
@ -136,6 +137,10 @@ struct s3c64xx_spi_dma_data {
|
|||||||
* struct s3c64xx_spi_port_config - SPI Controller hardware info
|
* struct s3c64xx_spi_port_config - SPI Controller hardware info
|
||||||
* @fifo_lvl_mask: Bit-mask for {TX|RX}_FIFO_LVL bits in SPI_STATUS register.
|
* @fifo_lvl_mask: Bit-mask for {TX|RX}_FIFO_LVL bits in SPI_STATUS register.
|
||||||
* @rx_lvl_offset: Bit offset of RX_FIFO_LVL bits in SPI_STATUS regiter.
|
* @rx_lvl_offset: Bit offset of RX_FIFO_LVL bits in SPI_STATUS regiter.
|
||||||
|
* @rx_fifomask: SPI_STATUS.RX_FIFO_LVL mask. Shifted mask defining the field's
|
||||||
|
* length and position.
|
||||||
|
* @tx_fifomask: SPI_STATUS.TX_FIFO_LVL mask. Shifted mask defining the field's
|
||||||
|
* length and position.
|
||||||
* @tx_st_done: Bit offset of TX_DONE bit in SPI_STATUS regiter.
|
* @tx_st_done: Bit offset of TX_DONE bit in SPI_STATUS regiter.
|
||||||
* @clk_div: Internal clock divider
|
* @clk_div: Internal clock divider
|
||||||
* @quirks: Bitmask of known quirks
|
* @quirks: Bitmask of known quirks
|
||||||
@ -154,6 +159,8 @@ struct s3c64xx_spi_dma_data {
|
|||||||
struct s3c64xx_spi_port_config {
|
struct s3c64xx_spi_port_config {
|
||||||
int fifo_lvl_mask[MAX_SPI_PORTS];
|
int fifo_lvl_mask[MAX_SPI_PORTS];
|
||||||
int rx_lvl_offset;
|
int rx_lvl_offset;
|
||||||
|
u32 rx_fifomask;
|
||||||
|
u32 tx_fifomask;
|
||||||
int tx_st_done;
|
int tx_st_done;
|
||||||
int quirks;
|
int quirks;
|
||||||
int clk_div;
|
int clk_div;
|
||||||
@ -184,6 +191,10 @@ struct s3c64xx_spi_port_config {
|
|||||||
* @tx_dma: Local transmit DMA data (e.g. chan and direction)
|
* @tx_dma: Local transmit DMA data (e.g. chan and direction)
|
||||||
* @port_conf: Local SPI port configuration data
|
* @port_conf: Local SPI port configuration data
|
||||||
* @port_id: Port identification number
|
* @port_id: Port identification number
|
||||||
|
* @rx_fifomask: SPI_STATUS.RX_FIFO_LVL mask. Shifted mask defining the field's
|
||||||
|
* length and position.
|
||||||
|
* @tx_fifomask: SPI_STATUS.TX_FIFO_LVL mask. Shifted mask defining the field's
|
||||||
|
* length and position.
|
||||||
*/
|
*/
|
||||||
struct s3c64xx_spi_driver_data {
|
struct s3c64xx_spi_driver_data {
|
||||||
void __iomem *regs;
|
void __iomem *regs;
|
||||||
@ -203,6 +214,8 @@ struct s3c64xx_spi_driver_data {
|
|||||||
struct s3c64xx_spi_dma_data tx_dma;
|
struct s3c64xx_spi_dma_data tx_dma;
|
||||||
const struct s3c64xx_spi_port_config *port_conf;
|
const struct s3c64xx_spi_port_config *port_conf;
|
||||||
unsigned int port_id;
|
unsigned int port_id;
|
||||||
|
u32 rx_fifomask;
|
||||||
|
u32 tx_fifomask;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)
|
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(
|
|||||||
return (const struct s3c64xx_spi_port_config *)platform_get_device_id(pdev)->driver_data;
|
return (const struct s3c64xx_spi_port_config *)platform_get_device_id(pdev)->driver_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void s3c64xx_spi_set_fifomask(struct s3c64xx_spi_driver_data *sdd)
|
||||||
|
{
|
||||||
|
const struct s3c64xx_spi_port_config *port_conf = sdd->port_conf;
|
||||||
|
|
||||||
|
if (port_conf->rx_fifomask)
|
||||||
|
sdd->rx_fifomask = port_conf->rx_fifomask;
|
||||||
|
else
|
||||||
|
sdd->rx_fifomask = FIFO_LVL_MASK(sdd) <<
|
||||||
|
port_conf->rx_lvl_offset;
|
||||||
|
|
||||||
|
if (port_conf->tx_fifomask)
|
||||||
|
sdd->tx_fifomask = port_conf->tx_fifomask;
|
||||||
|
else
|
||||||
|
sdd->tx_fifomask = FIFO_LVL_MASK(sdd) <<
|
||||||
|
S3C64XX_SPI_ST_TX_FIFO_LVL_SHIFT;
|
||||||
|
}
|
||||||
|
|
||||||
static int s3c64xx_spi_probe(struct platform_device *pdev)
|
static int s3c64xx_spi_probe(struct platform_device *pdev)
|
||||||
{
|
{
|
||||||
struct resource *mem_res;
|
struct resource *mem_res;
|
||||||
@ -1231,6 +1261,8 @@ static int s3c64xx_spi_probe(struct platform_device *pdev)
|
|||||||
sdd->port_id = pdev->id;
|
sdd->port_id = pdev->id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s3c64xx_spi_set_fifomask(sdd);
|
||||||
|
|
||||||
sdd->cur_bpw = 8;
|
sdd->cur_bpw = 8;
|
||||||
|
|
||||||
sdd->tx_dma.direction = DMA_MEM_TO_DEV;
|
sdd->tx_dma.direction = DMA_MEM_TO_DEV;
|
||||||
|
Loading…
Reference in New Issue
Block a user