2017-12-14 06:28:27 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009 Samsung Electronics Co., Ltd.
|
|
|
|
// Jaswinder Singh <jassi.brar@samsung.com>
|
2009-11-30 07:39:42 +00: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>
2024-02-16 07:05:46 +00:00
|
|
|
#include <linux/bitops.h>
|
2024-02-07 12:04:17 +00:00
|
|
|
#include <linux/bits.h>
|
2009-11-30 07:39:42 +00:00
|
|
|
#include <linux/clk.h>
|
2024-02-07 12:04:15 +00:00
|
|
|
#include <linux/delay.h>
|
2009-11-30 07:39:42 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2013-04-11 20:42:03 +00:00
|
|
|
#include <linux/dmaengine.h>
|
2024-02-07 12:04:15 +00:00
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
2024-02-07 12:04:16 +00:00
|
|
|
#include <linux/io.h>
|
2024-02-07 12:04:15 +00:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/platform_data/spi-s3c64xx.h>
|
2009-11-30 07:39:42 +00:00
|
|
|
#include <linux/platform_device.h>
|
2011-12-04 00:58:06 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2009-11-30 07:39:42 +00:00
|
|
|
#include <linux/spi/spi.h>
|
2024-02-07 12:04:18 +00:00
|
|
|
#include <linux/types.h>
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2024-02-16 07:05:54 +00:00
|
|
|
#define MAX_SPI_PORTS 12
|
2014-11-06 09:51:49 +00:00
|
|
|
#define S3C64XX_SPI_QUIRK_CS_AUTO (1 << 1)
|
2015-09-03 20:39:36 +00:00
|
|
|
#define AUTOSUSPEND_TIMEOUT 2000
|
2012-07-12 22:15:14 +00:00
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
/* Registers and bit-fields */
|
|
|
|
|
|
|
|
#define S3C64XX_SPI_CH_CFG 0x00
|
|
|
|
#define S3C64XX_SPI_CLK_CFG 0x04
|
2018-04-16 15:40:20 +00:00
|
|
|
#define S3C64XX_SPI_MODE_CFG 0x08
|
2020-10-02 12:22:39 +00:00
|
|
|
#define S3C64XX_SPI_CS_REG 0x0C
|
2009-11-30 07:39:42 +00:00
|
|
|
#define S3C64XX_SPI_INT_EN 0x10
|
|
|
|
#define S3C64XX_SPI_STATUS 0x14
|
|
|
|
#define S3C64XX_SPI_TX_DATA 0x18
|
|
|
|
#define S3C64XX_SPI_RX_DATA 0x1C
|
2018-04-16 15:40:20 +00:00
|
|
|
#define S3C64XX_SPI_PACKET_CNT 0x20
|
|
|
|
#define S3C64XX_SPI_PENDING_CLR 0x24
|
|
|
|
#define S3C64XX_SPI_SWAP_CFG 0x28
|
2009-11-30 07:39:42 +00:00
|
|
|
#define S3C64XX_SPI_FB_CLK 0x2C
|
|
|
|
|
|
|
|
#define S3C64XX_SPI_CH_HS_EN (1<<6) /* High Speed Enable */
|
|
|
|
#define S3C64XX_SPI_CH_SW_RST (1<<5)
|
|
|
|
#define S3C64XX_SPI_CH_SLAVE (1<<4)
|
|
|
|
#define S3C64XX_SPI_CPOL_L (1<<3)
|
|
|
|
#define S3C64XX_SPI_CPHA_B (1<<2)
|
|
|
|
#define S3C64XX_SPI_CH_RXCH_ON (1<<1)
|
|
|
|
#define S3C64XX_SPI_CH_TXCH_ON (1<<0)
|
|
|
|
|
|
|
|
#define S3C64XX_SPI_CLKSEL_SRCMSK (3<<9)
|
|
|
|
#define S3C64XX_SPI_CLKSEL_SRCSHFT 9
|
|
|
|
#define S3C64XX_SPI_ENCLK_ENABLE (1<<8)
|
2013-01-31 06:25:01 +00:00
|
|
|
#define S3C64XX_SPI_PSR_MASK 0xff
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
#define S3C64XX_SPI_MODE_CH_TSZ_BYTE (0<<29)
|
|
|
|
#define S3C64XX_SPI_MODE_CH_TSZ_HALFWORD (1<<29)
|
|
|
|
#define S3C64XX_SPI_MODE_CH_TSZ_WORD (2<<29)
|
|
|
|
#define S3C64XX_SPI_MODE_CH_TSZ_MASK (3<<29)
|
|
|
|
#define S3C64XX_SPI_MODE_BUS_TSZ_BYTE (0<<17)
|
|
|
|
#define S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD (1<<17)
|
|
|
|
#define S3C64XX_SPI_MODE_BUS_TSZ_WORD (2<<17)
|
|
|
|
#define S3C64XX_SPI_MODE_BUS_TSZ_MASK (3<<17)
|
2023-05-02 06:28:13 +00:00
|
|
|
#define S3C64XX_SPI_MODE_RX_RDY_LVL GENMASK(16, 11)
|
|
|
|
#define S3C64XX_SPI_MODE_RX_RDY_LVL_SHIFT 11
|
2022-06-29 10:23:01 +00:00
|
|
|
#define S3C64XX_SPI_MODE_SELF_LOOPBACK (1<<3)
|
2009-11-30 07:39:42 +00:00
|
|
|
#define S3C64XX_SPI_MODE_RXDMA_ON (1<<2)
|
|
|
|
#define S3C64XX_SPI_MODE_TXDMA_ON (1<<1)
|
|
|
|
#define S3C64XX_SPI_MODE_4BURST (1<<0)
|
|
|
|
|
2020-10-02 12:22:39 +00:00
|
|
|
#define S3C64XX_SPI_CS_NSC_CNT_2 (2<<4)
|
|
|
|
#define S3C64XX_SPI_CS_AUTO (1<<1)
|
|
|
|
#define S3C64XX_SPI_CS_SIG_INACT (1<<0)
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
#define S3C64XX_SPI_INT_TRAILING_EN (1<<6)
|
|
|
|
#define S3C64XX_SPI_INT_RX_OVERRUN_EN (1<<5)
|
|
|
|
#define S3C64XX_SPI_INT_RX_UNDERRUN_EN (1<<4)
|
|
|
|
#define S3C64XX_SPI_INT_TX_OVERRUN_EN (1<<3)
|
|
|
|
#define S3C64XX_SPI_INT_TX_UNDERRUN_EN (1<<2)
|
|
|
|
#define S3C64XX_SPI_INT_RX_FIFORDY_EN (1<<1)
|
|
|
|
#define S3C64XX_SPI_INT_TX_FIFORDY_EN (1<<0)
|
|
|
|
|
2024-02-16 07:05:54 +00:00
|
|
|
#define S3C64XX_SPI_ST_RX_FIFO_RDY_V2 GENMASK(23, 15)
|
|
|
|
#define S3C64XX_SPI_ST_TX_FIFO_RDY_V2 GENMASK(14, 6)
|
2024-02-16 07:05:45 +00:00
|
|
|
#define S3C64XX_SPI_ST_TX_FIFO_LVL_SHIFT 6
|
2009-11-30 07:39:42 +00:00
|
|
|
#define S3C64XX_SPI_ST_RX_OVERRUN_ERR (1<<5)
|
2018-04-16 15:40:20 +00:00
|
|
|
#define S3C64XX_SPI_ST_RX_UNDERRUN_ERR (1<<4)
|
2009-11-30 07:39:42 +00:00
|
|
|
#define S3C64XX_SPI_ST_TX_OVERRUN_ERR (1<<3)
|
2018-04-16 15:40:20 +00:00
|
|
|
#define S3C64XX_SPI_ST_TX_UNDERRUN_ERR (1<<2)
|
2009-11-30 07:39:42 +00:00
|
|
|
#define S3C64XX_SPI_ST_RX_FIFORDY (1<<1)
|
|
|
|
#define S3C64XX_SPI_ST_TX_FIFORDY (1<<0)
|
|
|
|
|
|
|
|
#define S3C64XX_SPI_PACKET_CNT_EN (1<<16)
|
2022-09-27 11:21:17 +00:00
|
|
|
#define S3C64XX_SPI_PACKET_CNT_MASK GENMASK(15, 0)
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
#define S3C64XX_SPI_PND_TX_UNDERRUN_CLR (1<<4)
|
|
|
|
#define S3C64XX_SPI_PND_TX_OVERRUN_CLR (1<<3)
|
|
|
|
#define S3C64XX_SPI_PND_RX_UNDERRUN_CLR (1<<2)
|
|
|
|
#define S3C64XX_SPI_PND_RX_OVERRUN_CLR (1<<1)
|
|
|
|
#define S3C64XX_SPI_PND_TRAILING_CLR (1<<0)
|
|
|
|
|
|
|
|
#define S3C64XX_SPI_SWAP_RX_HALF_WORD (1<<7)
|
|
|
|
#define S3C64XX_SPI_SWAP_RX_BYTE (1<<6)
|
|
|
|
#define S3C64XX_SPI_SWAP_RX_BIT (1<<5)
|
|
|
|
#define S3C64XX_SPI_SWAP_RX_EN (1<<4)
|
|
|
|
#define S3C64XX_SPI_SWAP_TX_HALF_WORD (1<<3)
|
|
|
|
#define S3C64XX_SPI_SWAP_TX_BYTE (1<<2)
|
|
|
|
#define S3C64XX_SPI_SWAP_TX_BIT (1<<1)
|
|
|
|
#define S3C64XX_SPI_SWAP_TX_EN (1<<0)
|
|
|
|
|
2018-04-16 15:40:20 +00:00
|
|
|
#define S3C64XX_SPI_FBCLK_MSK (3<<0)
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
#define FIFO_LVL_MASK(i) ((i)->port_conf->fifo_lvl_mask[i->port_id])
|
|
|
|
#define S3C64XX_SPI_ST_TX_DONE(v, i) (((v) & \
|
|
|
|
(1 << (i)->port_conf->tx_st_done)) ? 1 : 0)
|
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>
2024-02-16 07:05:46 +00:00
|
|
|
#define TX_FIFO_LVL(v, sdd) (((v) & (sdd)->tx_fifomask) >> \
|
|
|
|
__ffs((sdd)->tx_fifomask))
|
|
|
|
#define RX_FIFO_LVL(v, sdd) (((v) & (sdd)->rx_fifomask) >> \
|
|
|
|
__ffs((sdd)->rx_fifomask))
|
2024-01-20 17:00:01 +00:00
|
|
|
#define FIFO_DEPTH(i) ((FIFO_LVL_MASK(i) >> 1) + 1)
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
#define S3C64XX_SPI_MAX_TRAILCNT 0x3ff
|
|
|
|
#define S3C64XX_SPI_TRAILCNT_OFF 19
|
|
|
|
|
2023-05-02 06:28:13 +00:00
|
|
|
#define S3C64XX_SPI_POLLING_SIZE 32
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
#define msecs_to_loops(t) (loops_per_jiffy / 1000 * HZ * t)
|
2023-05-02 06:28:11 +00:00
|
|
|
#define is_polling(x) (x->cntrlr_info->polling)
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
#define RXBUSY (1<<2)
|
|
|
|
#define TXBUSY (1<<3)
|
|
|
|
|
2011-09-02 00:44:42 +00:00
|
|
|
struct s3c64xx_spi_dma_data {
|
2013-04-11 20:42:03 +00:00
|
|
|
struct dma_chan *ch;
|
2020-10-02 12:22:37 +00:00
|
|
|
dma_cookie_t cookie;
|
2012-04-30 16:31:27 +00:00
|
|
|
enum dma_transfer_direction direction;
|
2011-09-02 00:44:42 +00:00
|
|
|
};
|
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
/**
|
2021-04-14 20:33:42 +00:00
|
|
|
* struct s3c64xx_spi_port_config - SPI Controller hardware info
|
2024-02-16 07:05:53 +00:00
|
|
|
* @fifo_lvl_mask: [DEPRECATED] use @{rx, tx}_fifomask instead.
|
|
|
|
* @rx_lvl_offset: [DEPRECATED] use @{rx,tx}_fifomask instead.
|
spi: s3c64xx: allow FIFO depth to be determined from the compatible
There are SoCs that use the same FIFO depth for all the instances of the
SPI IP. See the fifo_lvl_mask defined for gs101 for example:
.fifo_lvl_mask = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f},
Instead of specifying the FIFO depth with the same value for all 16
nodes in this case, allow such SoCs to infer the FIFO depth from the
compatible. There are other SoCs than can benefit of this, see:
{gs101, fsd, exynos850, s3c641, s3c2443}_spi_port_config.
The FIFO depth inferred from the compatible has a higher precedence than
the one that might be specified via device tree, the driver shall know
better.
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Link: https://msgid.link/r/20240216070555.2483977-7-tudor.ambarus@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2024-02-16 07:05:49 +00:00
|
|
|
* @fifo_depth: depth of the FIFO.
|
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>
2024-02-16 07:05:46 +00:00
|
|
|
* @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.
|
2012-07-12 22:15:14 +00:00
|
|
|
* @tx_st_done: Bit offset of TX_DONE bit in SPI_STATUS regiter.
|
2022-06-29 10:23:02 +00:00
|
|
|
* @clk_div: Internal clock divider
|
2020-07-17 13:54:17 +00:00
|
|
|
* @quirks: Bitmask of known quirks
|
2012-07-12 22:15:14 +00:00
|
|
|
* @high_speed: True, if the controller supports HIGH_SPEED_EN bit.
|
|
|
|
* @clk_from_cmu: True, if the controller does not include a clock mux and
|
|
|
|
* prescaler unit.
|
2020-07-17 13:54:17 +00:00
|
|
|
* @clk_ioclk: True if clock is present on this device
|
2022-06-29 10:23:01 +00:00
|
|
|
* @has_loopback: True if loopback mode can be supported
|
2024-02-07 11:15:15 +00:00
|
|
|
* @use_32bit_io: True if the SoC allows only 32-bit register accesses.
|
2012-07-12 22:15:14 +00:00
|
|
|
*
|
|
|
|
* The Samsung s3c64xx SPI controller are used on various Samsung SoC's but
|
|
|
|
* differ in some aspects such as the size of the fifo and spi bus clock
|
|
|
|
* setup. Such differences are specified to the driver using this structure
|
|
|
|
* which is provided as driver data to the driver.
|
|
|
|
*/
|
|
|
|
struct s3c64xx_spi_port_config {
|
|
|
|
int fifo_lvl_mask[MAX_SPI_PORTS];
|
|
|
|
int rx_lvl_offset;
|
spi: s3c64xx: allow FIFO depth to be determined from the compatible
There are SoCs that use the same FIFO depth for all the instances of the
SPI IP. See the fifo_lvl_mask defined for gs101 for example:
.fifo_lvl_mask = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f},
Instead of specifying the FIFO depth with the same value for all 16
nodes in this case, allow such SoCs to infer the FIFO depth from the
compatible. There are other SoCs than can benefit of this, see:
{gs101, fsd, exynos850, s3c641, s3c2443}_spi_port_config.
The FIFO depth inferred from the compatible has a higher precedence than
the one that might be specified via device tree, the driver shall know
better.
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Link: https://msgid.link/r/20240216070555.2483977-7-tudor.ambarus@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2024-02-16 07:05:49 +00:00
|
|
|
unsigned int fifo_depth;
|
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>
2024-02-16 07:05:46 +00:00
|
|
|
u32 rx_fifomask;
|
|
|
|
u32 tx_fifomask;
|
2012-07-12 22:15:14 +00:00
|
|
|
int tx_st_done;
|
2013-05-20 06:51:32 +00:00
|
|
|
int quirks;
|
2022-06-29 10:23:02 +00:00
|
|
|
int clk_div;
|
2012-07-12 22:15:14 +00:00
|
|
|
bool high_speed;
|
|
|
|
bool clk_from_cmu;
|
2016-07-12 10:02:14 +00:00
|
|
|
bool clk_ioclk;
|
2022-06-29 10:23:01 +00:00
|
|
|
bool has_loopback;
|
2024-02-07 11:15:15 +00:00
|
|
|
bool use_32bit_io;
|
2012-07-12 22:15:14 +00:00
|
|
|
};
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
/**
|
|
|
|
* struct s3c64xx_spi_driver_data - Runtime info holder for SPI driver.
|
|
|
|
* @clk: Pointer to the spi clock.
|
2010-01-20 20:49:44 +00:00
|
|
|
* @src_clk: Pointer to the clock used to generate SPI signals.
|
2023-08-18 09:31:47 +00:00
|
|
|
* @ioclk: Pointer to the i/o clock between host and target
|
2020-07-17 13:54:17 +00:00
|
|
|
* @pdev: Pointer to device's platform device data
|
2023-08-18 09:31:47 +00:00
|
|
|
* @host: Pointer to the SPI Protocol host.
|
2009-11-30 07:39:42 +00:00
|
|
|
* @cntrlr_info: Platform specific data for the controller this driver manages.
|
|
|
|
* @lock: Controller specific lock.
|
|
|
|
* @state: Set of FLAGS to indicate status.
|
|
|
|
* @sfr_start: BUS address of SPI controller regs.
|
|
|
|
* @regs: Pointer to ioremap'ed controller registers.
|
|
|
|
* @xfer_completion: To indicate completion of xfer task.
|
|
|
|
* @cur_mode: Stores the active configuration of the controller.
|
|
|
|
* @cur_bpw: Stores the active bits per word settings.
|
2020-07-17 13:54:17 +00:00
|
|
|
* @cur_speed: Current clock speed
|
|
|
|
* @rx_dma: Local receive DMA data (e.g. chan and direction)
|
|
|
|
* @tx_dma: Local transmit DMA data (e.g. chan and direction)
|
2024-02-07 12:04:20 +00:00
|
|
|
* @port_conf: Local SPI port configuration data
|
2024-02-16 07:05:53 +00:00
|
|
|
* @port_id: [DEPRECATED] use @{rx,tx}_fifomask instead.
|
2024-02-16 07:05:47 +00:00
|
|
|
* @fifo_depth: depth of the FIFO.
|
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>
2024-02-16 07:05:46 +00:00
|
|
|
* @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.
|
2009-11-30 07:39:42 +00:00
|
|
|
*/
|
|
|
|
struct s3c64xx_spi_driver_data {
|
|
|
|
void __iomem *regs;
|
|
|
|
struct clk *clk;
|
2010-01-20 20:49:44 +00:00
|
|
|
struct clk *src_clk;
|
2016-07-12 10:02:14 +00:00
|
|
|
struct clk *ioclk;
|
2009-11-30 07:39:42 +00:00
|
|
|
struct platform_device *pdev;
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host;
|
2020-10-02 12:22:40 +00:00
|
|
|
struct s3c64xx_spi_info *cntrlr_info;
|
2009-11-30 07:39:42 +00:00
|
|
|
spinlock_t lock;
|
|
|
|
unsigned long sfr_start;
|
|
|
|
struct completion xfer_completion;
|
|
|
|
unsigned state;
|
|
|
|
unsigned cur_mode, cur_bpw;
|
|
|
|
unsigned cur_speed;
|
2011-09-02 00:44:42 +00:00
|
|
|
struct s3c64xx_spi_dma_data rx_dma;
|
|
|
|
struct s3c64xx_spi_dma_data tx_dma;
|
2021-04-14 20:33:43 +00:00
|
|
|
const struct s3c64xx_spi_port_config *port_conf;
|
2012-07-12 22:15:14 +00:00
|
|
|
unsigned int port_id;
|
2024-02-16 07:05:47 +00:00
|
|
|
unsigned int fifo_depth;
|
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>
2024-02-16 07:05:46 +00:00
|
|
|
u32 rx_fifomask;
|
|
|
|
u32 tx_fifomask;
|
2009-11-30 07:39:42 +00:00
|
|
|
};
|
|
|
|
|
2018-04-17 14:29:51 +00:00
|
|
|
static void s3c64xx_flush_fifo(struct s3c64xx_spi_driver_data *sdd)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
|
|
|
void __iomem *regs = sdd->regs;
|
|
|
|
unsigned long loops;
|
|
|
|
u32 val;
|
|
|
|
|
|
|
|
writel(0, regs + S3C64XX_SPI_PACKET_CNT);
|
|
|
|
|
2012-05-23 12:29:51 +00:00
|
|
|
val = readl(regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
val &= ~(S3C64XX_SPI_CH_RXCH_ON | S3C64XX_SPI_CH_TXCH_ON);
|
|
|
|
writel(val, regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
val = readl(regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
val |= S3C64XX_SPI_CH_SW_RST;
|
|
|
|
val &= ~S3C64XX_SPI_CH_HS_EN;
|
|
|
|
writel(val, regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
|
|
|
|
/* Flush TxFIFO*/
|
|
|
|
loops = msecs_to_loops(1);
|
|
|
|
do {
|
|
|
|
val = readl(regs + S3C64XX_SPI_STATUS);
|
2012-07-12 22:15:14 +00:00
|
|
|
} while (TX_FIFO_LVL(val, sdd) && loops--);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2010-08-23 16:40:56 +00:00
|
|
|
if (loops == 0)
|
|
|
|
dev_warn(&sdd->pdev->dev, "Timed out flushing TX FIFO\n");
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
/* Flush RxFIFO*/
|
|
|
|
loops = msecs_to_loops(1);
|
|
|
|
do {
|
|
|
|
val = readl(regs + S3C64XX_SPI_STATUS);
|
2012-07-12 22:15:14 +00:00
|
|
|
if (RX_FIFO_LVL(val, sdd))
|
2009-11-30 07:39:42 +00:00
|
|
|
readl(regs + S3C64XX_SPI_RX_DATA);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
} while (loops--);
|
|
|
|
|
2010-08-23 16:40:56 +00:00
|
|
|
if (loops == 0)
|
|
|
|
dev_warn(&sdd->pdev->dev, "Timed out flushing RX FIFO\n");
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
val = readl(regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
val &= ~S3C64XX_SPI_CH_SW_RST;
|
|
|
|
writel(val, regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
|
|
|
|
val = readl(regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
val &= ~(S3C64XX_SPI_MODE_TXDMA_ON | S3C64XX_SPI_MODE_RXDMA_ON);
|
|
|
|
writel(val, regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
}
|
|
|
|
|
2011-09-02 00:44:42 +00:00
|
|
|
static void s3c64xx_spi_dmacb(void *data)
|
2011-09-02 00:44:41 +00:00
|
|
|
{
|
2011-09-02 00:44:42 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd;
|
|
|
|
struct s3c64xx_spi_dma_data *dma = data;
|
2011-09-02 00:44:41 +00:00
|
|
|
unsigned long flags;
|
|
|
|
|
2012-03-10 00:48:46 +00:00
|
|
|
if (dma->direction == DMA_DEV_TO_MEM)
|
2011-09-02 00:44:42 +00:00
|
|
|
sdd = container_of(data,
|
|
|
|
struct s3c64xx_spi_driver_data, rx_dma);
|
|
|
|
else
|
|
|
|
sdd = container_of(data,
|
|
|
|
struct s3c64xx_spi_driver_data, tx_dma);
|
|
|
|
|
2011-09-02 00:44:41 +00:00
|
|
|
spin_lock_irqsave(&sdd->lock, flags);
|
|
|
|
|
2012-03-10 00:48:46 +00:00
|
|
|
if (dma->direction == DMA_DEV_TO_MEM) {
|
2011-09-02 00:44:42 +00:00
|
|
|
sdd->state &= ~RXBUSY;
|
|
|
|
if (!(sdd->state & TXBUSY))
|
|
|
|
complete(&sdd->xfer_completion);
|
|
|
|
} else {
|
|
|
|
sdd->state &= ~TXBUSY;
|
|
|
|
if (!(sdd->state & RXBUSY))
|
|
|
|
complete(&sdd->xfer_completion);
|
|
|
|
}
|
2011-09-02 00:44:41 +00:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sdd->lock, flags);
|
|
|
|
}
|
|
|
|
|
2024-02-07 12:04:26 +00:00
|
|
|
static int s3c64xx_prepare_dma(struct s3c64xx_spi_dma_data *dma,
|
|
|
|
struct sg_table *sgt)
|
2013-04-11 20:42:03 +00:00
|
|
|
{
|
|
|
|
struct s3c64xx_spi_driver_data *sdd;
|
|
|
|
struct dma_slave_config config;
|
|
|
|
struct dma_async_tx_descriptor *desc;
|
2020-10-02 12:22:37 +00:00
|
|
|
int ret;
|
2013-04-11 20:42:03 +00:00
|
|
|
|
2013-08-11 00:33:28 +00:00
|
|
|
memset(&config, 0, sizeof(config));
|
|
|
|
|
2013-04-11 20:42:03 +00:00
|
|
|
if (dma->direction == DMA_DEV_TO_MEM) {
|
|
|
|
sdd = container_of((void *)dma,
|
|
|
|
struct s3c64xx_spi_driver_data, rx_dma);
|
|
|
|
config.src_addr = sdd->sfr_start + S3C64XX_SPI_RX_DATA;
|
|
|
|
config.src_addr_width = sdd->cur_bpw / 8;
|
|
|
|
config.src_maxburst = 1;
|
|
|
|
} else {
|
|
|
|
sdd = container_of((void *)dma,
|
|
|
|
struct s3c64xx_spi_driver_data, tx_dma);
|
|
|
|
config.dst_addr = sdd->sfr_start + S3C64XX_SPI_TX_DATA;
|
|
|
|
config.dst_addr_width = sdd->cur_bpw / 8;
|
|
|
|
config.dst_maxburst = 1;
|
|
|
|
}
|
2024-02-07 12:04:23 +00:00
|
|
|
config.direction = dma->direction;
|
2024-02-07 12:04:24 +00:00
|
|
|
ret = dmaengine_slave_config(dma->ch, &config);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-04-11 20:42:03 +00:00
|
|
|
|
2014-02-02 13:47:47 +00:00
|
|
|
desc = dmaengine_prep_slave_sg(dma->ch, sgt->sgl, sgt->nents,
|
|
|
|
dma->direction, DMA_PREP_INTERRUPT);
|
2020-10-02 12:22:37 +00:00
|
|
|
if (!desc) {
|
|
|
|
dev_err(&sdd->pdev->dev, "unable to prepare %s scatterlist",
|
|
|
|
dma->direction == DMA_DEV_TO_MEM ? "rx" : "tx");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2013-04-11 20:42:03 +00:00
|
|
|
|
|
|
|
desc->callback = s3c64xx_spi_dmacb;
|
|
|
|
desc->callback_param = dma;
|
|
|
|
|
2020-10-02 12:22:37 +00:00
|
|
|
dma->cookie = dmaengine_submit(desc);
|
|
|
|
ret = dma_submit_error(dma->cookie);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&sdd->pdev->dev, "DMA submission failed");
|
2024-02-07 12:04:25 +00:00
|
|
|
return ret;
|
2020-10-02 12:22:37 +00:00
|
|
|
}
|
|
|
|
|
2013-04-11 20:42:03 +00:00
|
|
|
dma_async_issue_pending(dma->ch);
|
2020-10-02 12:22:37 +00:00
|
|
|
return 0;
|
2013-04-11 20:42:03 +00:00
|
|
|
}
|
|
|
|
|
2016-06-28 02:41:11 +00:00
|
|
|
static void s3c64xx_spi_set_cs(struct spi_device *spi, bool enable)
|
|
|
|
{
|
|
|
|
struct s3c64xx_spi_driver_data *sdd =
|
2023-08-18 09:31:47 +00:00
|
|
|
spi_controller_get_devdata(spi->controller);
|
2016-06-28 02:41:11 +00:00
|
|
|
|
2016-06-28 02:41:12 +00:00
|
|
|
if (sdd->cntrlr_info->no_cs)
|
|
|
|
return;
|
|
|
|
|
2016-06-28 02:41:11 +00:00
|
|
|
if (enable) {
|
|
|
|
if (!(sdd->port_conf->quirks & S3C64XX_SPI_QUIRK_CS_AUTO)) {
|
2020-10-02 12:22:39 +00:00
|
|
|
writel(0, sdd->regs + S3C64XX_SPI_CS_REG);
|
2016-06-28 02:41:11 +00:00
|
|
|
} else {
|
2020-10-02 12:22:39 +00:00
|
|
|
u32 ssel = readl(sdd->regs + S3C64XX_SPI_CS_REG);
|
2016-06-28 02:41:11 +00:00
|
|
|
|
2020-10-02 12:22:39 +00:00
|
|
|
ssel |= (S3C64XX_SPI_CS_AUTO |
|
|
|
|
S3C64XX_SPI_CS_NSC_CNT_2);
|
|
|
|
writel(ssel, sdd->regs + S3C64XX_SPI_CS_REG);
|
2016-06-28 02:41:11 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!(sdd->port_conf->quirks & S3C64XX_SPI_QUIRK_CS_AUTO))
|
2020-10-02 12:22:39 +00:00
|
|
|
writel(S3C64XX_SPI_CS_SIG_INACT,
|
|
|
|
sdd->regs + S3C64XX_SPI_CS_REG);
|
2016-06-28 02:41:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
static int s3c64xx_spi_prepare_transfer(struct spi_controller *spi)
|
2013-04-11 20:42:03 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(spi);
|
2013-04-11 20:42:03 +00:00
|
|
|
|
2016-06-28 02:41:14 +00:00
|
|
|
if (is_polling(sdd))
|
|
|
|
return 0;
|
|
|
|
|
2022-05-24 14:01:32 +00:00
|
|
|
/* Requests DMA channels */
|
|
|
|
sdd->rx_dma.ch = dma_request_chan(&sdd->pdev->dev, "rx");
|
|
|
|
if (IS_ERR(sdd->rx_dma.ch)) {
|
|
|
|
dev_err(&sdd->pdev->dev, "Failed to get RX DMA channel\n");
|
2022-06-12 20:34:28 +00:00
|
|
|
sdd->rx_dma.ch = NULL;
|
2022-05-24 14:01:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
sdd->tx_dma.ch = dma_request_chan(&sdd->pdev->dev, "tx");
|
|
|
|
if (IS_ERR(sdd->tx_dma.ch)) {
|
2022-06-08 08:19:12 +00:00
|
|
|
dev_err(&sdd->pdev->dev, "Failed to get TX DMA channel\n");
|
2022-05-24 14:01:32 +00:00
|
|
|
dma_release_channel(sdd->rx_dma.ch);
|
2022-06-12 20:34:28 +00:00
|
|
|
sdd->tx_dma.ch = NULL;
|
|
|
|
sdd->rx_dma.ch = NULL;
|
2022-05-24 14:01:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-28 02:41:14 +00:00
|
|
|
spi->dma_rx = sdd->rx_dma.ch;
|
|
|
|
spi->dma_tx = sdd->tx_dma.ch;
|
2013-04-18 17:12:00 +00:00
|
|
|
|
2016-06-28 02:41:14 +00:00
|
|
|
return 0;
|
2013-04-11 20:42:03 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
static int s3c64xx_spi_unprepare_transfer(struct spi_controller *spi)
|
2022-06-27 01:38:45 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(spi);
|
2022-06-27 01:38:45 +00:00
|
|
|
|
|
|
|
if (is_polling(sdd))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Releases DMA channels if they are allocated */
|
|
|
|
if (sdd->rx_dma.ch && sdd->tx_dma.ch) {
|
|
|
|
dma_release_channel(sdd->rx_dma.ch);
|
|
|
|
dma_release_channel(sdd->tx_dma.ch);
|
2022-08-08 00:48:51 +00:00
|
|
|
sdd->rx_dma.ch = NULL;
|
|
|
|
sdd->tx_dma.ch = NULL;
|
2022-06-27 01:38:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
static bool s3c64xx_spi_can_dma(struct spi_controller *host,
|
2014-01-16 12:25:46 +00:00
|
|
|
struct spi_device *spi,
|
|
|
|
struct spi_transfer *xfer)
|
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2014-01-16 12:25:46 +00:00
|
|
|
|
2024-02-07 12:04:22 +00:00
|
|
|
if (sdd->rx_dma.ch && sdd->tx_dma.ch)
|
2024-03-29 08:58:40 +00:00
|
|
|
return xfer->len >= sdd->fifo_depth;
|
2022-05-24 14:01:32 +00:00
|
|
|
|
2024-02-07 12:04:22 +00:00
|
|
|
return false;
|
2014-01-16 12:25:46 +00:00
|
|
|
}
|
|
|
|
|
2024-02-07 11:15:15 +00:00
|
|
|
static void s3c64xx_iowrite8_32_rep(volatile void __iomem *addr,
|
|
|
|
const void *buffer, unsigned int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
const u8 *buf = buffer;
|
|
|
|
|
|
|
|
do {
|
|
|
|
__raw_writel(*buf++, addr);
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void s3c64xx_iowrite16_32_rep(volatile void __iomem *addr,
|
|
|
|
const void *buffer, unsigned int count)
|
|
|
|
{
|
|
|
|
if (count) {
|
|
|
|
const u16 *buf = buffer;
|
|
|
|
|
|
|
|
do {
|
|
|
|
__raw_writel(*buf++, addr);
|
|
|
|
} while (--count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-07 11:15:14 +00:00
|
|
|
static void s3c64xx_iowrite_rep(const struct s3c64xx_spi_driver_data *sdd,
|
|
|
|
struct spi_transfer *xfer)
|
|
|
|
{
|
|
|
|
void __iomem *addr = sdd->regs + S3C64XX_SPI_TX_DATA;
|
|
|
|
const void *buf = xfer->tx_buf;
|
|
|
|
unsigned int len = xfer->len;
|
|
|
|
|
|
|
|
switch (sdd->cur_bpw) {
|
|
|
|
case 32:
|
|
|
|
iowrite32_rep(addr, buf, len / 4);
|
|
|
|
break;
|
|
|
|
case 16:
|
2024-02-07 11:15:15 +00:00
|
|
|
if (sdd->port_conf->use_32bit_io)
|
|
|
|
s3c64xx_iowrite16_32_rep(addr, buf, len / 2);
|
|
|
|
else
|
|
|
|
iowrite16_rep(addr, buf, len / 2);
|
2024-02-07 11:15:14 +00:00
|
|
|
break;
|
|
|
|
default:
|
2024-02-07 11:15:15 +00:00
|
|
|
if (sdd->port_conf->use_32bit_io)
|
|
|
|
s3c64xx_iowrite8_32_rep(addr, buf, len);
|
|
|
|
else
|
|
|
|
iowrite8_rep(addr, buf, len);
|
2024-02-07 11:15:14 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 12:22:37 +00:00
|
|
|
static int s3c64xx_enable_datapath(struct s3c64xx_spi_driver_data *sdd,
|
2018-04-17 14:29:51 +00:00
|
|
|
struct spi_transfer *xfer, int dma_mode)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
|
|
|
void __iomem *regs = sdd->regs;
|
|
|
|
u32 modecfg, chcfg;
|
2020-10-02 12:22:37 +00:00
|
|
|
int ret = 0;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
modecfg = readl(regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
modecfg &= ~(S3C64XX_SPI_MODE_TXDMA_ON | S3C64XX_SPI_MODE_RXDMA_ON);
|
|
|
|
|
|
|
|
chcfg = readl(regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
chcfg &= ~S3C64XX_SPI_CH_TXCH_ON;
|
|
|
|
|
|
|
|
if (dma_mode) {
|
|
|
|
chcfg &= ~S3C64XX_SPI_CH_RXCH_ON;
|
|
|
|
} else {
|
|
|
|
/* Always shift in data in FIFO, even if xfer is Tx only,
|
|
|
|
* this helps setting PCKT_CNT value for generating clocks
|
|
|
|
* as exactly needed.
|
|
|
|
*/
|
|
|
|
chcfg |= S3C64XX_SPI_CH_RXCH_ON;
|
|
|
|
writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
|
|
|
|
| S3C64XX_SPI_PACKET_CNT_EN,
|
|
|
|
regs + S3C64XX_SPI_PACKET_CNT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfer->tx_buf != NULL) {
|
|
|
|
sdd->state |= TXBUSY;
|
|
|
|
chcfg |= S3C64XX_SPI_CH_TXCH_ON;
|
|
|
|
if (dma_mode) {
|
|
|
|
modecfg |= S3C64XX_SPI_MODE_TXDMA_ON;
|
2024-02-07 12:04:26 +00:00
|
|
|
ret = s3c64xx_prepare_dma(&sdd->tx_dma, &xfer->tx_sg);
|
2009-11-30 07:39:42 +00:00
|
|
|
} else {
|
2024-02-07 11:15:14 +00:00
|
|
|
s3c64xx_iowrite_rep(sdd, xfer);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xfer->rx_buf != NULL) {
|
|
|
|
sdd->state |= RXBUSY;
|
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
if (sdd->port_conf->high_speed && sdd->cur_speed >= 30000000UL
|
2009-11-30 07:39:42 +00:00
|
|
|
&& !(sdd->cur_mode & SPI_CPHA))
|
|
|
|
chcfg |= S3C64XX_SPI_CH_HS_EN;
|
|
|
|
|
|
|
|
if (dma_mode) {
|
|
|
|
modecfg |= S3C64XX_SPI_MODE_RXDMA_ON;
|
|
|
|
chcfg |= S3C64XX_SPI_CH_RXCH_ON;
|
|
|
|
writel(((xfer->len * 8 / sdd->cur_bpw) & 0xffff)
|
|
|
|
| S3C64XX_SPI_PACKET_CNT_EN,
|
|
|
|
regs + S3C64XX_SPI_PACKET_CNT);
|
2024-02-07 12:04:26 +00:00
|
|
|
ret = s3c64xx_prepare_dma(&sdd->rx_dma, &xfer->rx_sg);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-02 12:22:37 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
writel(modecfg, regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
writel(chcfg, regs + S3C64XX_SPI_CH_CFG);
|
2020-10-02 12:22:37 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:12:39 +00:00
|
|
|
static u32 s3c64xx_spi_wait_for_timeout(struct s3c64xx_spi_driver_data *sdd,
|
2013-05-20 06:51:32 +00:00
|
|
|
int timeout_ms)
|
|
|
|
{
|
|
|
|
void __iomem *regs = sdd->regs;
|
|
|
|
unsigned long val = 1;
|
|
|
|
u32 status;
|
2024-02-16 07:05:47 +00:00
|
|
|
u32 max_fifo = sdd->fifo_depth;
|
2013-05-20 06:51:32 +00:00
|
|
|
|
|
|
|
if (timeout_ms)
|
|
|
|
val = msecs_to_loops(timeout_ms);
|
|
|
|
|
|
|
|
do {
|
|
|
|
status = readl(regs + S3C64XX_SPI_STATUS);
|
|
|
|
} while (RX_FIFO_LVL(status, sdd) < max_fifo && --val);
|
|
|
|
|
|
|
|
/* return the actual received data length */
|
|
|
|
return RX_FIFO_LVL(status, sdd);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2018-04-17 14:29:51 +00:00
|
|
|
static int s3c64xx_wait_for_dma(struct s3c64xx_spi_driver_data *sdd,
|
|
|
|
struct spi_transfer *xfer)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
|
|
|
void __iomem *regs = sdd->regs;
|
|
|
|
unsigned long val;
|
2014-01-24 20:05:43 +00:00
|
|
|
u32 status;
|
2009-11-30 07:39:42 +00:00
|
|
|
int ms;
|
|
|
|
|
|
|
|
/* millisecs to xfer 'len' bytes @ 'cur_speed' */
|
|
|
|
ms = xfer->len * 8 * 1000 / sdd->cur_speed;
|
2020-10-02 12:22:42 +00:00
|
|
|
ms += 30; /* some tolerance */
|
|
|
|
ms = max(ms, 100); /* minimum timeout */
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2014-01-24 20:05:43 +00:00
|
|
|
val = msecs_to_jiffies(ms) + 10;
|
|
|
|
val = wait_for_completion_timeout(&sdd->xfer_completion, val);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the previous xfer was completed within timeout, then
|
2024-02-07 12:04:27 +00:00
|
|
|
* proceed further else return -ETIMEDOUT.
|
2014-01-24 20:05:43 +00:00
|
|
|
* DmaTx returns after simply writing data in the FIFO,
|
|
|
|
* w/o waiting for real transmission on the bus to finish.
|
|
|
|
* DmaRx returns only after Dma read data from FIFO which
|
|
|
|
* needs bus transmission to finish, so we don't worry if
|
|
|
|
* Xfer involved Rx(with or without Tx).
|
|
|
|
*/
|
|
|
|
if (val && !xfer->rx_buf) {
|
|
|
|
val = msecs_to_loops(10);
|
|
|
|
status = readl(regs + S3C64XX_SPI_STATUS);
|
|
|
|
while ((TX_FIFO_LVL(status, sdd)
|
|
|
|
|| !S3C64XX_SPI_ST_TX_DONE(status, sdd))
|
|
|
|
&& --val) {
|
|
|
|
cpu_relax();
|
2010-09-03 01:36:46 +00:00
|
|
|
status = readl(regs + S3C64XX_SPI_STATUS);
|
2014-01-24 20:05:43 +00:00
|
|
|
}
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 20:05:43 +00:00
|
|
|
/* If timed out while checking rx/tx status return error */
|
|
|
|
if (!val)
|
2024-02-07 12:04:27 +00:00
|
|
|
return -ETIMEDOUT;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2014-01-24 20:05:43 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-05-20 06:51:32 +00:00
|
|
|
|
2018-04-17 14:29:51 +00:00
|
|
|
static int s3c64xx_wait_for_pio(struct s3c64xx_spi_driver_data *sdd,
|
2023-05-02 06:28:13 +00:00
|
|
|
struct spi_transfer *xfer, bool use_irq)
|
2014-01-24 20:05:43 +00:00
|
|
|
{
|
|
|
|
void __iomem *regs = sdd->regs;
|
|
|
|
unsigned long val;
|
|
|
|
u32 status;
|
|
|
|
int loops;
|
|
|
|
u32 cpy_len;
|
|
|
|
u8 *buf;
|
|
|
|
int ms;
|
2023-05-02 06:28:12 +00:00
|
|
|
unsigned long time_us;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-05-02 06:28:12 +00:00
|
|
|
/* microsecs to xfer 'len' bytes @ 'cur_speed' */
|
|
|
|
time_us = (xfer->len * 8 * 1000 * 1000) / sdd->cur_speed;
|
|
|
|
ms = (time_us / 1000);
|
2014-01-24 20:05:43 +00:00
|
|
|
ms += 10; /* some tolerance */
|
2013-05-20 06:51:32 +00:00
|
|
|
|
2023-05-02 06:28:12 +00:00
|
|
|
/* sleep during signal transfer time */
|
|
|
|
status = readl(regs + S3C64XX_SPI_STATUS);
|
|
|
|
if (RX_FIFO_LVL(status, sdd) < xfer->len)
|
|
|
|
usleep_range(time_us / 2, time_us);
|
|
|
|
|
2023-05-02 06:28:13 +00:00
|
|
|
if (use_irq) {
|
|
|
|
val = msecs_to_jiffies(ms);
|
|
|
|
if (!wait_for_completion_timeout(&sdd->xfer_completion, val))
|
2024-02-07 12:04:27 +00:00
|
|
|
return -ETIMEDOUT;
|
2023-05-02 06:28:13 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 20:05:43 +00:00
|
|
|
val = msecs_to_loops(ms);
|
|
|
|
do {
|
|
|
|
status = readl(regs + S3C64XX_SPI_STATUS);
|
|
|
|
} while (RX_FIFO_LVL(status, sdd) < xfer->len && --val);
|
2013-05-20 06:51:32 +00:00
|
|
|
|
2018-04-16 15:40:19 +00:00
|
|
|
if (!val)
|
|
|
|
return -EIO;
|
2014-01-24 20:05:43 +00:00
|
|
|
|
|
|
|
/* If it was only Tx */
|
|
|
|
if (!xfer->rx_buf) {
|
|
|
|
sdd->state &= ~TXBUSY;
|
|
|
|
return 0;
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2014-01-24 20:05:43 +00:00
|
|
|
/*
|
|
|
|
* If the receive length is bigger than the controller fifo
|
|
|
|
* size, calculate the loops and read the fifo as many times.
|
|
|
|
* loops = length / max fifo size (calculated by using the
|
|
|
|
* fifo mask).
|
|
|
|
* For any size less than the fifo size the below code is
|
|
|
|
* executed atleast once.
|
|
|
|
*/
|
2024-02-16 07:05:47 +00:00
|
|
|
loops = xfer->len / sdd->fifo_depth;
|
2014-01-24 20:05:43 +00:00
|
|
|
buf = xfer->rx_buf;
|
|
|
|
do {
|
|
|
|
/* wait for data to be received in the fifo */
|
|
|
|
cpy_len = s3c64xx_spi_wait_for_timeout(sdd,
|
|
|
|
(loops ? ms : 0));
|
|
|
|
|
|
|
|
switch (sdd->cur_bpw) {
|
|
|
|
case 32:
|
|
|
|
ioread32_rep(regs + S3C64XX_SPI_RX_DATA,
|
|
|
|
buf, cpy_len / 4);
|
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
ioread16_rep(regs + S3C64XX_SPI_RX_DATA,
|
|
|
|
buf, cpy_len / 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ioread8_rep(regs + S3C64XX_SPI_RX_DATA,
|
|
|
|
buf, cpy_len);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = buf + cpy_len;
|
|
|
|
} while (loops--);
|
|
|
|
sdd->state &= ~RXBUSY;
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-02 12:22:37 +00:00
|
|
|
static int s3c64xx_spi_config(struct s3c64xx_spi_driver_data *sdd)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
|
|
|
void __iomem *regs = sdd->regs;
|
2020-10-02 12:22:37 +00:00
|
|
|
int ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
u32 val;
|
2022-06-29 10:23:02 +00:00
|
|
|
int div = sdd->port_conf->clk_div;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
/* Disable Clock */
|
2016-07-07 07:23:57 +00:00
|
|
|
if (!sdd->port_conf->clk_from_cmu) {
|
2010-09-29 08:31:33 +00:00
|
|
|
val = readl(regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
val &= ~S3C64XX_SPI_ENCLK_ENABLE;
|
|
|
|
writel(val, regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
}
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
/* Set Polarity and Phase */
|
|
|
|
val = readl(regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
val &= ~(S3C64XX_SPI_CH_SLAVE |
|
|
|
|
S3C64XX_SPI_CPOL_L |
|
|
|
|
S3C64XX_SPI_CPHA_B);
|
|
|
|
|
|
|
|
if (sdd->cur_mode & SPI_CPOL)
|
|
|
|
val |= S3C64XX_SPI_CPOL_L;
|
|
|
|
|
|
|
|
if (sdd->cur_mode & SPI_CPHA)
|
|
|
|
val |= S3C64XX_SPI_CPHA_B;
|
|
|
|
|
|
|
|
writel(val, regs + S3C64XX_SPI_CH_CFG);
|
|
|
|
|
|
|
|
/* Set Channel & DMA Mode */
|
|
|
|
val = readl(regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
val &= ~(S3C64XX_SPI_MODE_BUS_TSZ_MASK
|
|
|
|
| S3C64XX_SPI_MODE_CH_TSZ_MASK);
|
|
|
|
|
|
|
|
switch (sdd->cur_bpw) {
|
|
|
|
case 32:
|
|
|
|
val |= S3C64XX_SPI_MODE_BUS_TSZ_WORD;
|
2010-09-29 08:31:33 +00:00
|
|
|
val |= S3C64XX_SPI_MODE_CH_TSZ_WORD;
|
2009-11-30 07:39:42 +00:00
|
|
|
break;
|
|
|
|
case 16:
|
|
|
|
val |= S3C64XX_SPI_MODE_BUS_TSZ_HALFWORD;
|
2010-09-29 08:31:33 +00:00
|
|
|
val |= S3C64XX_SPI_MODE_CH_TSZ_HALFWORD;
|
2009-11-30 07:39:42 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
val |= S3C64XX_SPI_MODE_BUS_TSZ_BYTE;
|
2010-09-29 08:31:33 +00:00
|
|
|
val |= S3C64XX_SPI_MODE_CH_TSZ_BYTE;
|
2009-11-30 07:39:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-29 10:23:01 +00:00
|
|
|
if ((sdd->cur_mode & SPI_LOOP) && sdd->port_conf->has_loopback)
|
|
|
|
val |= S3C64XX_SPI_MODE_SELF_LOOPBACK;
|
2023-07-11 08:20:20 +00:00
|
|
|
else
|
|
|
|
val &= ~S3C64XX_SPI_MODE_SELF_LOOPBACK;
|
2022-06-29 10:23:01 +00:00
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
writel(val, regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
if (sdd->port_conf->clk_from_cmu) {
|
2022-06-29 10:23:02 +00:00
|
|
|
ret = clk_set_rate(sdd->src_clk, sdd->cur_speed * div);
|
2020-10-02 12:22:37 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2022-06-29 10:23:02 +00:00
|
|
|
sdd->cur_speed = clk_get_rate(sdd->src_clk) / div;
|
2010-09-29 08:31:33 +00:00
|
|
|
} else {
|
|
|
|
/* Configure Clock */
|
|
|
|
val = readl(regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
val &= ~S3C64XX_SPI_PSR_MASK;
|
2022-06-29 10:23:02 +00:00
|
|
|
val |= ((clk_get_rate(sdd->src_clk) / sdd->cur_speed / div - 1)
|
2010-09-29 08:31:33 +00:00
|
|
|
& S3C64XX_SPI_PSR_MASK);
|
|
|
|
writel(val, regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
|
|
|
|
/* Enable Clock */
|
|
|
|
val = readl(regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
val |= S3C64XX_SPI_ENCLK_ENABLE;
|
|
|
|
writel(val, regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
}
|
2020-10-02 12:22:37 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define XFER_DMAADDR_INVALID DMA_BIT_MASK(32)
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
static int s3c64xx_spi_prepare_message(struct spi_controller *host,
|
2013-10-04 23:42:58 +00:00
|
|
|
struct spi_message *msg)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2009-11-30 07:39:42 +00:00
|
|
|
struct spi_device *spi = msg->spi;
|
|
|
|
struct s3c64xx_spi_csinfo *cs = spi->controller_data;
|
|
|
|
|
|
|
|
/* Configure feedback delay */
|
2022-01-18 23:09:15 +00:00
|
|
|
if (!cs)
|
|
|
|
/* No delay if not defined */
|
|
|
|
writel(0, sdd->regs + S3C64XX_SPI_FB_CLK);
|
|
|
|
else
|
|
|
|
writel(cs->fb_delay & 0x3, sdd->regs + S3C64XX_SPI_FB_CLK);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2013-10-04 23:42:58 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-09-29 08:31:33 +00:00
|
|
|
|
2022-09-27 11:21:17 +00:00
|
|
|
static size_t s3c64xx_spi_max_transfer_size(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct spi_controller *ctlr = spi->controller;
|
|
|
|
|
|
|
|
return ctlr->can_dma ? S3C64XX_SPI_PACKET_CNT_MASK : SIZE_MAX;
|
|
|
|
}
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
static int s3c64xx_spi_transfer_one(struct spi_controller *host,
|
2013-10-05 10:51:14 +00:00
|
|
|
struct spi_device *spi,
|
|
|
|
struct spi_transfer *xfer)
|
2013-10-04 23:42:58 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2024-02-16 07:05:47 +00:00
|
|
|
const unsigned int fifo_len = sdd->fifo_depth;
|
2018-04-17 14:29:54 +00:00
|
|
|
const void *tx_buf = NULL;
|
|
|
|
void *rx_buf = NULL;
|
|
|
|
int target_len = 0, origin_len = 0;
|
|
|
|
int use_dma = 0;
|
2023-05-02 06:28:13 +00:00
|
|
|
bool use_irq = false;
|
2013-10-05 10:51:14 +00:00
|
|
|
int status;
|
2013-10-04 23:42:58 +00:00
|
|
|
u32 speed;
|
|
|
|
u8 bpw;
|
2013-10-05 10:51:14 +00:00
|
|
|
unsigned long flags;
|
2023-05-02 06:28:13 +00:00
|
|
|
u32 rdy_lv;
|
|
|
|
u32 val;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2014-01-12 13:07:50 +00:00
|
|
|
reinit_completion(&sdd->xfer_completion);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2013-10-05 10:51:14 +00:00
|
|
|
/* Only BPW and Speed may change across transfers */
|
|
|
|
bpw = xfer->bits_per_word;
|
2015-09-15 13:26:14 +00:00
|
|
|
speed = xfer->speed_hz;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2013-10-05 10:51:14 +00:00
|
|
|
if (bpw != sdd->cur_bpw || speed != sdd->cur_speed) {
|
|
|
|
sdd->cur_bpw = bpw;
|
|
|
|
sdd->cur_speed = speed;
|
2016-06-28 02:41:13 +00:00
|
|
|
sdd->cur_mode = spi->mode;
|
2020-10-02 12:22:37 +00:00
|
|
|
status = s3c64xx_spi_config(sdd);
|
|
|
|
if (status)
|
|
|
|
return status;
|
2013-10-05 10:51:14 +00:00
|
|
|
}
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2024-03-29 08:58:40 +00:00
|
|
|
if (!is_polling(sdd) && xfer->len >= fifo_len &&
|
2018-04-17 14:29:54 +00:00
|
|
|
sdd->rx_dma.ch && sdd->tx_dma.ch) {
|
2013-10-05 10:51:14 +00:00
|
|
|
use_dma = 1;
|
2023-05-02 06:28:13 +00:00
|
|
|
} else if (xfer->len >= fifo_len) {
|
2018-04-17 14:29:54 +00:00
|
|
|
tx_buf = xfer->tx_buf;
|
|
|
|
rx_buf = xfer->rx_buf;
|
|
|
|
origin_len = xfer->len;
|
|
|
|
target_len = xfer->len;
|
2023-05-02 06:28:13 +00:00
|
|
|
xfer->len = fifo_len - 1;
|
2018-04-17 14:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2023-05-02 06:28:13 +00:00
|
|
|
/* transfer size is greater than 32, change to IRQ mode */
|
2023-05-10 11:39:42 +00:00
|
|
|
if (!use_dma && xfer->len > S3C64XX_SPI_POLLING_SIZE)
|
2023-05-02 06:28:13 +00:00
|
|
|
use_irq = true;
|
|
|
|
|
|
|
|
if (use_irq) {
|
|
|
|
reinit_completion(&sdd->xfer_completion);
|
|
|
|
|
|
|
|
rdy_lv = xfer->len;
|
|
|
|
/* Setup RDY_FIFO trigger Level
|
|
|
|
* RDY_LVL =
|
|
|
|
* fifo_lvl up to 64 byte -> N bytes
|
|
|
|
* 128 byte -> RDY_LVL * 2 bytes
|
|
|
|
* 256 byte -> RDY_LVL * 4 bytes
|
|
|
|
*/
|
|
|
|
if (fifo_len == 128)
|
|
|
|
rdy_lv /= 2;
|
|
|
|
else if (fifo_len == 256)
|
|
|
|
rdy_lv /= 4;
|
|
|
|
|
|
|
|
val = readl(sdd->regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
val &= ~S3C64XX_SPI_MODE_RX_RDY_LVL;
|
|
|
|
val |= (rdy_lv << S3C64XX_SPI_MODE_RX_RDY_LVL_SHIFT);
|
|
|
|
writel(val, sdd->regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
|
|
|
|
/* Enable FIFO_RDY_EN IRQ */
|
|
|
|
val = readl(sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
writel((val | S3C64XX_SPI_INT_RX_FIFORDY_EN),
|
|
|
|
sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:29:54 +00:00
|
|
|
spin_lock_irqsave(&sdd->lock, flags);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2018-04-17 14:29:54 +00:00
|
|
|
/* Pending only which is to be done */
|
|
|
|
sdd->state &= ~RXBUSY;
|
|
|
|
sdd->state &= ~TXBUSY;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2018-04-17 14:29:54 +00:00
|
|
|
/* Start the signals */
|
|
|
|
s3c64xx_spi_set_cs(spi, true);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2020-10-02 12:22:37 +00:00
|
|
|
status = s3c64xx_enable_datapath(sdd, xfer, use_dma);
|
2020-10-02 12:22:35 +00:00
|
|
|
|
2018-04-17 14:29:54 +00:00
|
|
|
spin_unlock_irqrestore(&sdd->lock, flags);
|
|
|
|
|
2020-10-02 12:22:37 +00:00
|
|
|
if (status) {
|
|
|
|
dev_err(&spi->dev, "failed to enable data path for transfer: %d\n", status);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-17 14:29:54 +00:00
|
|
|
if (use_dma)
|
|
|
|
status = s3c64xx_wait_for_dma(sdd, xfer);
|
|
|
|
else
|
2023-05-02 06:28:13 +00:00
|
|
|
status = s3c64xx_wait_for_pio(sdd, xfer, use_irq);
|
2018-04-17 14:29:54 +00:00
|
|
|
|
|
|
|
if (status) {
|
|
|
|
dev_err(&spi->dev,
|
2020-10-02 12:22:38 +00:00
|
|
|
"I/O Error: rx-%d tx-%d rx-%c tx-%c len-%d dma-%d res-(%d)\n",
|
2018-04-17 14:29:54 +00:00
|
|
|
xfer->rx_buf ? 1 : 0, xfer->tx_buf ? 1 : 0,
|
|
|
|
(sdd->state & RXBUSY) ? 'f' : 'p',
|
|
|
|
(sdd->state & TXBUSY) ? 'f' : 'p',
|
2020-10-02 12:22:38 +00:00
|
|
|
xfer->len, use_dma ? 1 : 0, status);
|
2018-04-17 14:29:54 +00:00
|
|
|
|
|
|
|
if (use_dma) {
|
2020-10-02 12:22:38 +00:00
|
|
|
struct dma_tx_state s;
|
|
|
|
|
|
|
|
if (xfer->tx_buf && (sdd->state & TXBUSY)) {
|
|
|
|
dmaengine_pause(sdd->tx_dma.ch);
|
|
|
|
dmaengine_tx_status(sdd->tx_dma.ch, sdd->tx_dma.cookie, &s);
|
2018-04-17 14:29:54 +00:00
|
|
|
dmaengine_terminate_all(sdd->tx_dma.ch);
|
2020-10-02 12:22:38 +00:00
|
|
|
dev_err(&spi->dev, "TX residue: %d\n", s.residue);
|
|
|
|
|
|
|
|
}
|
|
|
|
if (xfer->rx_buf && (sdd->state & RXBUSY)) {
|
|
|
|
dmaengine_pause(sdd->rx_dma.ch);
|
|
|
|
dmaengine_tx_status(sdd->rx_dma.ch, sdd->rx_dma.cookie, &s);
|
2018-04-17 14:29:54 +00:00
|
|
|
dmaengine_terminate_all(sdd->rx_dma.ch);
|
2020-10-02 12:22:38 +00:00
|
|
|
dev_err(&spi->dev, "RX residue: %d\n", s.residue);
|
|
|
|
}
|
2018-04-17 14:29:54 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
s3c64xx_flush_fifo(sdd);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
2018-04-17 14:29:54 +00:00
|
|
|
if (target_len > 0) {
|
|
|
|
target_len -= xfer->len;
|
|
|
|
|
|
|
|
if (xfer->tx_buf)
|
|
|
|
xfer->tx_buf += xfer->len;
|
|
|
|
|
|
|
|
if (xfer->rx_buf)
|
|
|
|
xfer->rx_buf += xfer->len;
|
|
|
|
|
2023-05-02 06:28:13 +00:00
|
|
|
if (target_len >= fifo_len)
|
|
|
|
xfer->len = fifo_len - 1;
|
2018-04-17 14:29:54 +00:00
|
|
|
else
|
|
|
|
xfer->len = target_len;
|
|
|
|
}
|
|
|
|
} while (target_len > 0);
|
|
|
|
|
|
|
|
if (origin_len) {
|
|
|
|
/* Restore original xfer buffers and length */
|
|
|
|
xfer->tx_buf = tx_buf;
|
|
|
|
xfer->rx_buf = rx_buf;
|
|
|
|
xfer->len = origin_len;
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2013-10-05 10:51:14 +00:00
|
|
|
return status;
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
static struct s3c64xx_spi_csinfo *s3c64xx_get_target_ctrldata(
|
2012-07-12 22:15:15 +00:00
|
|
|
struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct s3c64xx_spi_csinfo *cs;
|
2023-08-18 09:31:47 +00:00
|
|
|
struct device_node *target_np, *data_np = NULL;
|
2012-07-12 22:15:15 +00:00
|
|
|
u32 fb_delay = 0;
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
target_np = spi->dev.of_node;
|
|
|
|
if (!target_np) {
|
2012-07-12 22:15:15 +00:00
|
|
|
dev_err(&spi->dev, "device node not found\n");
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
cs = kzalloc(sizeof(*cs), GFP_KERNEL);
|
2022-01-24 08:23:47 +00:00
|
|
|
if (!cs)
|
2012-07-12 22:15:15 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
2022-01-24 08:23:47 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
data_np = of_get_child_by_name(target_np, "controller-data");
|
2022-01-24 08:23:47 +00:00
|
|
|
if (!data_np) {
|
|
|
|
dev_info(&spi->dev, "feedback delay set to default (0)\n");
|
|
|
|
return cs;
|
2012-07-12 22:15:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
of_property_read_u32(data_np, "samsung,spi-feedback-delay", &fb_delay);
|
|
|
|
cs->fb_delay = fb_delay;
|
2012-09-18 07:10:49 +00:00
|
|
|
of_node_put(data_np);
|
2012-07-12 22:15:15 +00:00
|
|
|
return cs;
|
|
|
|
}
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
/*
|
|
|
|
* Here we only check the validity of requested configuration
|
|
|
|
* and save the configuration in a local data-structure.
|
|
|
|
* The controller is actually configured only just before we
|
|
|
|
* get a message to transfer.
|
|
|
|
*/
|
|
|
|
static int s3c64xx_spi_setup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct s3c64xx_spi_csinfo *cs = spi->controller_data;
|
|
|
|
struct s3c64xx_spi_driver_data *sdd;
|
2012-07-12 22:15:15 +00:00
|
|
|
int err;
|
2022-06-29 10:23:02 +00:00
|
|
|
int div;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
sdd = spi_controller_get_devdata(spi->controller);
|
2014-07-16 15:19:08 +00:00
|
|
|
if (spi->dev.of_node) {
|
2023-08-18 09:31:47 +00:00
|
|
|
cs = s3c64xx_get_target_ctrldata(spi);
|
2012-07-12 22:15:15 +00:00
|
|
|
spi->controller_data = cs;
|
|
|
|
}
|
|
|
|
|
2022-01-18 23:09:15 +00:00
|
|
|
/* NULL is fine, we just avoid using the FB delay (=0) */
|
|
|
|
if (IS_ERR(cs)) {
|
2023-03-10 17:32:03 +00:00
|
|
|
dev_err(&spi->dev, "No CS for SPI(%d)\n", spi_get_chipselect(spi, 0));
|
2009-11-30 07:39:42 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2022-01-18 23:09:15 +00:00
|
|
|
if (!spi_get_ctldata(spi))
|
2013-06-21 05:56:12 +00:00
|
|
|
spi_set_ctldata(spi, cs);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2011-12-04 00:58:06 +00:00
|
|
|
pm_runtime_get_sync(&sdd->pdev->dev);
|
|
|
|
|
2022-06-29 10:23:02 +00:00
|
|
|
div = sdd->port_conf->clk_div;
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
/* Check if we can provide the requested rate */
|
2012-07-12 22:15:14 +00:00
|
|
|
if (!sdd->port_conf->clk_from_cmu) {
|
2010-09-29 08:31:33 +00:00
|
|
|
u32 psr, speed;
|
|
|
|
|
|
|
|
/* Max possible */
|
2022-06-29 10:23:02 +00:00
|
|
|
speed = clk_get_rate(sdd->src_clk) / div / (0 + 1);
|
2010-09-29 08:31:33 +00:00
|
|
|
|
|
|
|
if (spi->max_speed_hz > speed)
|
|
|
|
spi->max_speed_hz = speed;
|
|
|
|
|
2022-06-29 10:23:02 +00:00
|
|
|
psr = clk_get_rate(sdd->src_clk) / div / spi->max_speed_hz - 1;
|
2010-09-29 08:31:33 +00:00
|
|
|
psr &= S3C64XX_SPI_PSR_MASK;
|
|
|
|
if (psr == S3C64XX_SPI_PSR_MASK)
|
|
|
|
psr--;
|
|
|
|
|
2022-06-29 10:23:02 +00:00
|
|
|
speed = clk_get_rate(sdd->src_clk) / div / (psr + 1);
|
2010-09-29 08:31:33 +00:00
|
|
|
if (spi->max_speed_hz < speed) {
|
|
|
|
if (psr+1 < S3C64XX_SPI_PSR_MASK) {
|
|
|
|
psr++;
|
|
|
|
} else {
|
|
|
|
err = -EINVAL;
|
|
|
|
goto setup_exit;
|
|
|
|
}
|
|
|
|
}
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2022-06-29 10:23:02 +00:00
|
|
|
speed = clk_get_rate(sdd->src_clk) / div / (psr + 1);
|
2012-07-12 22:15:15 +00:00
|
|
|
if (spi->max_speed_hz >= speed) {
|
2010-09-29 08:31:33 +00:00
|
|
|
spi->max_speed_hz = speed;
|
2012-07-12 22:15:15 +00:00
|
|
|
} else {
|
2012-12-20 18:27:31 +00:00
|
|
|
dev_err(&spi->dev, "Can't set %dHz transfer speed\n",
|
|
|
|
spi->max_speed_hz);
|
2009-11-30 07:39:42 +00:00
|
|
|
err = -EINVAL;
|
2012-07-12 22:15:15 +00:00
|
|
|
goto setup_exit;
|
|
|
|
}
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:39:36 +00:00
|
|
|
pm_runtime_mark_last_busy(&sdd->pdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(&sdd->pdev->dev);
|
2016-06-28 02:41:11 +00:00
|
|
|
s3c64xx_spi_set_cs(spi, false);
|
|
|
|
|
2012-07-12 22:15:15 +00:00
|
|
|
return 0;
|
2011-12-04 00:58:06 +00:00
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
setup_exit:
|
2015-09-03 20:39:36 +00:00
|
|
|
pm_runtime_mark_last_busy(&sdd->pdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(&sdd->pdev->dev);
|
2009-11-30 07:39:42 +00:00
|
|
|
/* setup() returns with device de-selected */
|
2016-06-28 02:41:11 +00:00
|
|
|
s3c64xx_spi_set_cs(spi, false);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2012-07-12 22:15:15 +00:00
|
|
|
spi_set_ctldata(spi, NULL);
|
|
|
|
|
2022-01-18 23:09:15 +00:00
|
|
|
/* This was dynamically allocated on the DT path */
|
2012-09-13 14:31:30 +00:00
|
|
|
if (spi->dev.of_node)
|
|
|
|
kfree(cs);
|
2012-07-12 22:15:15 +00:00
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
static void s3c64xx_spi_cleanup(struct spi_device *spi)
|
|
|
|
{
|
|
|
|
struct s3c64xx_spi_csinfo *cs = spi_get_ctldata(spi);
|
|
|
|
|
2022-01-18 23:09:15 +00:00
|
|
|
/* This was dynamically allocated on the DT path */
|
|
|
|
if (spi->dev.of_node)
|
|
|
|
kfree(cs);
|
2014-07-16 15:19:08 +00:00
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
spi_set_ctldata(spi, NULL);
|
|
|
|
}
|
|
|
|
|
2011-11-10 10:57:32 +00:00
|
|
|
static irqreturn_t s3c64xx_spi_irq(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct s3c64xx_spi_driver_data *sdd = data;
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *spi = sdd->host;
|
2013-03-13 06:43:30 +00:00
|
|
|
unsigned int val, clr = 0;
|
2011-11-10 10:57:32 +00:00
|
|
|
|
2013-03-13 06:43:30 +00:00
|
|
|
val = readl(sdd->regs + S3C64XX_SPI_STATUS);
|
2011-11-10 10:57:32 +00:00
|
|
|
|
2013-03-13 06:43:30 +00:00
|
|
|
if (val & S3C64XX_SPI_ST_RX_OVERRUN_ERR) {
|
|
|
|
clr = S3C64XX_SPI_PND_RX_OVERRUN_CLR;
|
2011-11-10 10:57:32 +00:00
|
|
|
dev_err(&spi->dev, "RX overrun\n");
|
2013-03-13 06:43:30 +00:00
|
|
|
}
|
|
|
|
if (val & S3C64XX_SPI_ST_RX_UNDERRUN_ERR) {
|
|
|
|
clr |= S3C64XX_SPI_PND_RX_UNDERRUN_CLR;
|
2011-11-10 10:57:32 +00:00
|
|
|
dev_err(&spi->dev, "RX underrun\n");
|
2013-03-13 06:43:30 +00:00
|
|
|
}
|
|
|
|
if (val & S3C64XX_SPI_ST_TX_OVERRUN_ERR) {
|
|
|
|
clr |= S3C64XX_SPI_PND_TX_OVERRUN_CLR;
|
2011-11-10 10:57:32 +00:00
|
|
|
dev_err(&spi->dev, "TX overrun\n");
|
2013-03-13 06:43:30 +00:00
|
|
|
}
|
|
|
|
if (val & S3C64XX_SPI_ST_TX_UNDERRUN_ERR) {
|
|
|
|
clr |= S3C64XX_SPI_PND_TX_UNDERRUN_CLR;
|
2011-11-10 10:57:32 +00:00
|
|
|
dev_err(&spi->dev, "TX underrun\n");
|
2013-03-13 06:43:30 +00:00
|
|
|
}
|
|
|
|
|
2023-05-02 06:28:13 +00:00
|
|
|
if (val & S3C64XX_SPI_ST_RX_FIFORDY) {
|
|
|
|
complete(&sdd->xfer_completion);
|
|
|
|
/* No pending clear irq, turn-off INT_EN_RX_FIFO_RDY */
|
|
|
|
val = readl(sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
writel((val & ~S3C64XX_SPI_INT_RX_FIFORDY_EN),
|
|
|
|
sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
}
|
|
|
|
|
2013-03-13 06:43:30 +00:00
|
|
|
/* Clear the pending irq by setting and then clearing it */
|
|
|
|
writel(clr, sdd->regs + S3C64XX_SPI_PENDING_CLR);
|
|
|
|
writel(0, sdd->regs + S3C64XX_SPI_PENDING_CLR);
|
2011-11-10 10:57:32 +00:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2018-04-16 15:40:17 +00:00
|
|
|
static void s3c64xx_spi_hwinit(struct s3c64xx_spi_driver_data *sdd)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
2010-01-20 20:49:44 +00:00
|
|
|
struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
|
2009-11-30 07:39:42 +00:00
|
|
|
void __iomem *regs = sdd->regs;
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
sdd->cur_speed = 0;
|
|
|
|
|
2016-06-28 02:41:12 +00:00
|
|
|
if (sci->no_cs)
|
2020-10-02 12:22:39 +00:00
|
|
|
writel(0, sdd->regs + S3C64XX_SPI_CS_REG);
|
2016-06-28 02:41:12 +00:00
|
|
|
else if (!(sdd->port_conf->quirks & S3C64XX_SPI_QUIRK_CS_AUTO))
|
2020-10-02 12:22:39 +00:00
|
|
|
writel(S3C64XX_SPI_CS_SIG_INACT, sdd->regs + S3C64XX_SPI_CS_REG);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
/* Disable Interrupts - we use Polling if not DMA mode */
|
|
|
|
writel(0, regs + S3C64XX_SPI_INT_EN);
|
|
|
|
|
2012-07-12 22:15:14 +00:00
|
|
|
if (!sdd->port_conf->clk_from_cmu)
|
2010-09-29 08:31:33 +00:00
|
|
|
writel(sci->src_clk_nr << S3C64XX_SPI_CLKSEL_SRCSHFT,
|
2009-11-30 07:39:42 +00:00
|
|
|
regs + S3C64XX_SPI_CLK_CFG);
|
|
|
|
writel(0, regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
writel(0, regs + S3C64XX_SPI_PACKET_CNT);
|
|
|
|
|
2013-03-13 06:43:30 +00:00
|
|
|
/* Clear any irq pending bits, should set and clear the bits */
|
|
|
|
val = S3C64XX_SPI_PND_RX_OVERRUN_CLR |
|
|
|
|
S3C64XX_SPI_PND_RX_UNDERRUN_CLR |
|
|
|
|
S3C64XX_SPI_PND_TX_OVERRUN_CLR |
|
|
|
|
S3C64XX_SPI_PND_TX_UNDERRUN_CLR;
|
|
|
|
writel(val, regs + S3C64XX_SPI_PENDING_CLR);
|
|
|
|
writel(0, regs + S3C64XX_SPI_PENDING_CLR);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
writel(0, regs + S3C64XX_SPI_SWAP_CFG);
|
|
|
|
|
|
|
|
val = readl(regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
val &= ~S3C64XX_SPI_MODE_4BURST;
|
2024-02-07 12:04:30 +00:00
|
|
|
val |= (S3C64XX_SPI_MAX_TRAILCNT << S3C64XX_SPI_TRAILCNT_OFF);
|
2009-11-30 07:39:42 +00:00
|
|
|
writel(val, regs + S3C64XX_SPI_MODE_CFG);
|
|
|
|
|
2018-04-17 14:29:51 +00:00
|
|
|
s3c64xx_flush_fifo(sdd);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2012-07-12 22:15:15 +00:00
|
|
|
#ifdef CONFIG_OF
|
2013-01-31 06:25:01 +00:00
|
|
|
static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev)
|
2012-07-12 22:15:15 +00:00
|
|
|
{
|
|
|
|
struct s3c64xx_spi_info *sci;
|
|
|
|
u32 temp;
|
|
|
|
|
|
|
|
sci = devm_kzalloc(dev, sizeof(*sci), GFP_KERNEL);
|
2014-04-29 08:20:20 +00:00
|
|
|
if (!sci)
|
2012-07-12 22:15:15 +00:00
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
if (of_property_read_u32(dev->of_node, "samsung,spi-src-clk", &temp)) {
|
2024-02-07 12:04:29 +00:00
|
|
|
dev_dbg(dev, "spi bus clock parent not specified, using clock at index 0 as parent\n");
|
2012-07-12 22:15:15 +00:00
|
|
|
sci->src_clk_nr = 0;
|
|
|
|
} else {
|
|
|
|
sci->src_clk_nr = temp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (of_property_read_u32(dev->of_node, "num-cs", &temp)) {
|
2024-02-07 12:04:29 +00:00
|
|
|
dev_dbg(dev, "number of chip select lines not specified, assuming 1 chip select line\n");
|
2012-07-12 22:15:15 +00:00
|
|
|
sci->num_cs = 1;
|
|
|
|
} else {
|
|
|
|
sci->num_cs = temp;
|
|
|
|
}
|
|
|
|
|
2017-02-10 02:20:19 +00:00
|
|
|
sci->no_cs = of_property_read_bool(dev->of_node, "no-cs-readback");
|
2023-05-02 06:28:11 +00:00
|
|
|
sci->polling = !of_property_present(dev->of_node, "dmas");
|
2016-06-28 02:41:12 +00:00
|
|
|
|
2012-07-12 22:15:15 +00:00
|
|
|
return sci;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static struct s3c64xx_spi_info *s3c64xx_spi_parse_dt(struct device *dev)
|
|
|
|
{
|
2013-07-30 07:58:59 +00:00
|
|
|
return dev_get_platdata(dev);
|
2012-07-12 22:15:15 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static inline const struct s3c64xx_spi_port_config *s3c64xx_spi_get_port_config(
|
2012-07-12 22:15:14 +00:00
|
|
|
struct platform_device *pdev)
|
|
|
|
{
|
2012-07-12 22:15:15 +00:00
|
|
|
#ifdef CONFIG_OF
|
2021-04-14 20:33:41 +00:00
|
|
|
if (pdev->dev.of_node)
|
2021-04-14 20:33:43 +00:00
|
|
|
return of_device_get_match_data(&pdev->dev);
|
2012-07-12 22:15:15 +00:00
|
|
|
#endif
|
2021-04-14 20:33:43 +00:00
|
|
|
return (const struct s3c64xx_spi_port_config *)platform_get_device_id(pdev)->driver_data;
|
2012-07-12 22:15:14 +00:00
|
|
|
}
|
|
|
|
|
2024-02-16 07:05:51 +00:00
|
|
|
static int s3c64xx_spi_set_port_id(struct platform_device *pdev,
|
|
|
|
struct s3c64xx_spi_driver_data *sdd)
|
|
|
|
{
|
2024-02-16 07:05:52 +00:00
|
|
|
const struct s3c64xx_spi_port_config *port_conf = sdd->port_conf;
|
2024-02-16 07:05:51 +00:00
|
|
|
int ret;
|
|
|
|
|
2024-02-16 07:05:52 +00:00
|
|
|
if (port_conf->rx_fifomask && port_conf->tx_fifomask)
|
|
|
|
return 0;
|
|
|
|
|
2024-02-16 07:05:51 +00:00
|
|
|
if (pdev->dev.of_node) {
|
|
|
|
ret = of_alias_get_id(pdev->dev.of_node, "spi");
|
|
|
|
if (ret < 0)
|
|
|
|
return dev_err_probe(&pdev->dev, ret,
|
|
|
|
"Failed to get alias id\n");
|
|
|
|
sdd->port_id = ret;
|
|
|
|
} else {
|
|
|
|
if (pdev->id < 0)
|
|
|
|
return dev_err_probe(&pdev->dev, -EINVAL,
|
|
|
|
"Negative platform ID is not allowed\n");
|
|
|
|
sdd->port_id = pdev->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
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>
2024-02-16 07:05:46 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-02-05 13:27:35 +00:00
|
|
|
static int s3c64xx_spi_probe(struct platform_device *pdev)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
2012-07-12 22:15:15 +00:00
|
|
|
struct resource *mem_res;
|
2009-11-30 07:39:42 +00:00
|
|
|
struct s3c64xx_spi_driver_data *sdd;
|
2013-07-30 07:58:59 +00:00
|
|
|
struct s3c64xx_spi_info *sci = dev_get_platdata(&pdev->dev);
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host;
|
2011-11-10 10:57:32 +00:00
|
|
|
int ret, irq;
|
2011-11-02 11:04:19 +00:00
|
|
|
char clk_name[16];
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2012-07-12 22:15:15 +00:00
|
|
|
if (!sci && pdev->dev.of_node) {
|
|
|
|
sci = s3c64xx_spi_parse_dt(&pdev->dev);
|
|
|
|
if (IS_ERR(sci))
|
|
|
|
return PTR_ERR(sci);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2023-06-06 01:20:51 +00:00
|
|
|
if (!sci)
|
|
|
|
return dev_err_probe(&pdev->dev, -ENODEV,
|
|
|
|
"Platform_data missing!\n");
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2011-11-10 10:57:32 +00:00
|
|
|
irq = platform_get_irq(pdev, 0);
|
2023-06-06 01:20:51 +00:00
|
|
|
if (irq < 0)
|
2023-07-27 13:16:35 +00:00
|
|
|
return irq;
|
2011-11-10 10:57:32 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
host = devm_spi_alloc_host(&pdev->dev, sizeof(*sdd));
|
|
|
|
if (!host)
|
2023-06-06 01:20:51 +00:00
|
|
|
return dev_err_probe(&pdev->dev, -ENOMEM,
|
2023-08-18 09:31:47 +00:00
|
|
|
"Unable to allocate SPI Host\n");
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
platform_set_drvdata(pdev, host);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
sdd = spi_controller_get_devdata(host);
|
2012-07-12 22:15:14 +00:00
|
|
|
sdd->port_conf = s3c64xx_spi_get_port_config(pdev);
|
2023-08-18 09:31:47 +00:00
|
|
|
sdd->host = host;
|
2009-11-30 07:39:42 +00:00
|
|
|
sdd->cntrlr_info = sci;
|
|
|
|
sdd->pdev = pdev;
|
2024-02-16 07:05:51 +00:00
|
|
|
|
|
|
|
ret = s3c64xx_spi_set_port_id(pdev, sdd);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
spi: s3c64xx: allow FIFO depth to be determined from the compatible
There are SoCs that use the same FIFO depth for all the instances of the
SPI IP. See the fifo_lvl_mask defined for gs101 for example:
.fifo_lvl_mask = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f,
0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0x7f},
Instead of specifying the FIFO depth with the same value for all 16
nodes in this case, allow such SoCs to infer the FIFO depth from the
compatible. There are other SoCs than can benefit of this, see:
{gs101, fsd, exynos850, s3c641, s3c2443}_spi_port_config.
The FIFO depth inferred from the compatible has a higher precedence than
the one that might be specified via device tree, the driver shall know
better.
Signed-off-by: Tudor Ambarus <tudor.ambarus@linaro.org>
Link: https://msgid.link/r/20240216070555.2483977-7-tudor.ambarus@linaro.org
Signed-off-by: Mark Brown <broonie@kernel.org>
2024-02-16 07:05:49 +00:00
|
|
|
if (sdd->port_conf->fifo_depth)
|
|
|
|
sdd->fifo_depth = sdd->port_conf->fifo_depth;
|
|
|
|
else if (of_property_read_u32(pdev->dev.of_node, "fifo-depth",
|
|
|
|
&sdd->fifo_depth))
|
2024-02-16 07:05:48 +00:00
|
|
|
sdd->fifo_depth = FIFO_DEPTH(sdd);
|
2024-02-16 07:05:47 +00: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>
2024-02-16 07:05:46 +00:00
|
|
|
s3c64xx_spi_set_fifomask(sdd);
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
sdd->cur_bpw = 8;
|
|
|
|
|
2013-01-18 11:47:03 +00:00
|
|
|
sdd->tx_dma.direction = DMA_MEM_TO_DEV;
|
|
|
|
sdd->rx_dma.direction = DMA_DEV_TO_MEM;
|
2012-07-12 22:15:15 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
host->dev.of_node = pdev->dev.of_node;
|
2024-02-16 07:05:50 +00:00
|
|
|
host->bus_num = -1;
|
2023-08-18 09:31:47 +00:00
|
|
|
host->setup = s3c64xx_spi_setup;
|
|
|
|
host->cleanup = s3c64xx_spi_cleanup;
|
|
|
|
host->prepare_transfer_hardware = s3c64xx_spi_prepare_transfer;
|
|
|
|
host->unprepare_transfer_hardware = s3c64xx_spi_unprepare_transfer;
|
|
|
|
host->prepare_message = s3c64xx_spi_prepare_message;
|
|
|
|
host->transfer_one = s3c64xx_spi_transfer_one;
|
|
|
|
host->max_transfer_size = s3c64xx_spi_max_transfer_size;
|
|
|
|
host->num_chipselect = sci->num_cs;
|
|
|
|
host->use_gpio_descriptors = true;
|
|
|
|
host->dma_alignment = 8;
|
|
|
|
host->bits_per_word_mask = SPI_BPW_MASK(32) | SPI_BPW_MASK(16) |
|
|
|
|
SPI_BPW_MASK(8);
|
2009-11-30 07:39:42 +00:00
|
|
|
/* the spi->mode bits understood by this driver: */
|
2023-08-18 09:31:47 +00:00
|
|
|
host->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH;
|
2022-06-29 10:23:01 +00:00
|
|
|
if (sdd->port_conf->has_loopback)
|
2023-08-18 09:31:47 +00:00
|
|
|
host->mode_bits |= SPI_LOOP;
|
|
|
|
host->auto_runtime_pm = true;
|
2014-01-16 12:25:46 +00:00
|
|
|
if (!is_polling(sdd))
|
2023-08-18 09:31:47 +00:00
|
|
|
host->can_dma = s3c64xx_spi_can_dma;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-07-06 03:27:26 +00:00
|
|
|
sdd->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &mem_res);
|
2023-06-06 01:20:50 +00:00
|
|
|
if (IS_ERR(sdd->regs))
|
|
|
|
return PTR_ERR(sdd->regs);
|
2023-07-06 03:27:26 +00:00
|
|
|
sdd->sfr_start = mem_res->start;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-06-06 01:20:51 +00:00
|
|
|
if (sci->cfg_gpio && sci->cfg_gpio())
|
|
|
|
return dev_err_probe(&pdev->dev, -EBUSY,
|
|
|
|
"Unable to config gpio\n");
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
/* Setup clocks */
|
2023-05-31 20:55:50 +00:00
|
|
|
sdd->clk = devm_clk_get_enabled(&pdev->dev, "spi");
|
2023-06-06 01:20:51 +00:00
|
|
|
if (IS_ERR(sdd->clk))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(sdd->clk),
|
|
|
|
"Unable to acquire clock 'spi'\n");
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2011-11-02 11:04:19 +00:00
|
|
|
sprintf(clk_name, "spi_busclk%d", sci->src_clk_nr);
|
2023-05-31 20:55:50 +00:00
|
|
|
sdd->src_clk = devm_clk_get_enabled(&pdev->dev, clk_name);
|
2023-06-06 01:20:51 +00:00
|
|
|
if (IS_ERR(sdd->src_clk))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(sdd->src_clk),
|
|
|
|
"Unable to acquire clock '%s'\n",
|
|
|
|
clk_name);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2016-07-12 10:02:14 +00:00
|
|
|
if (sdd->port_conf->clk_ioclk) {
|
2023-05-31 20:55:50 +00:00
|
|
|
sdd->ioclk = devm_clk_get_enabled(&pdev->dev, "spi_ioclk");
|
2023-06-06 01:20:51 +00:00
|
|
|
if (IS_ERR(sdd->ioclk))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(sdd->ioclk),
|
|
|
|
"Unable to acquire 'ioclk'\n");
|
2016-07-12 10:02:14 +00:00
|
|
|
}
|
|
|
|
|
2015-09-03 20:39:36 +00:00
|
|
|
pm_runtime_set_autosuspend_delay(&pdev->dev, AUTOSUSPEND_TIMEOUT);
|
|
|
|
pm_runtime_use_autosuspend(&pdev->dev);
|
|
|
|
pm_runtime_set_active(&pdev->dev);
|
|
|
|
pm_runtime_enable(&pdev->dev);
|
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
/* Setup Deufult Mode */
|
2018-04-16 15:40:17 +00:00
|
|
|
s3c64xx_spi_hwinit(sdd);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
spin_lock_init(&sdd->lock);
|
|
|
|
init_completion(&sdd->xfer_completion);
|
|
|
|
|
2013-01-10 02:04:21 +00:00
|
|
|
ret = devm_request_irq(&pdev->dev, irq, s3c64xx_spi_irq, 0,
|
|
|
|
"spi-s3c64xx", sdd);
|
2011-11-10 10:57:32 +00:00
|
|
|
if (ret != 0) {
|
|
|
|
dev_err(&pdev->dev, "Failed to request IRQ %d: %d\n",
|
|
|
|
irq, ret);
|
2016-07-12 10:02:12 +00:00
|
|
|
goto err_pm_put;
|
2011-11-10 10:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
writel(S3C64XX_SPI_INT_RX_OVERRUN_EN | S3C64XX_SPI_INT_RX_UNDERRUN_EN |
|
|
|
|
S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN,
|
|
|
|
sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
ret = devm_spi_register_controller(&pdev->dev, host);
|
2013-08-31 17:55:53 +00:00
|
|
|
if (ret != 0) {
|
2023-08-18 09:31:47 +00:00
|
|
|
dev_err(&pdev->dev, "cannot register SPI host: %d\n", ret);
|
2016-07-12 10:02:12 +00:00
|
|
|
goto err_pm_put;
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
dev_dbg(&pdev->dev, "Samsung SoC SPI Driver loaded for Bus SPI-%d with %d Targets attached\n",
|
2024-02-16 07:05:50 +00:00
|
|
|
host->bus_num, host->num_chipselect);
|
2016-11-10 15:17:51 +00:00
|
|
|
dev_dbg(&pdev->dev, "\tIOmem=[%pR]\tFIFO %dbytes\n",
|
2024-02-16 07:05:47 +00:00
|
|
|
mem_res, sdd->fifo_depth);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2015-09-03 20:39:36 +00:00
|
|
|
pm_runtime_mark_last_busy(&pdev->dev);
|
|
|
|
pm_runtime_put_autosuspend(&pdev->dev);
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
return 0;
|
|
|
|
|
2016-07-12 10:02:12 +00:00
|
|
|
err_pm_put:
|
2015-09-03 20:39:36 +00:00
|
|
|
pm_runtime_put_noidle(&pdev->dev);
|
2015-09-03 20:38:46 +00:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
pm_runtime_set_suspended(&pdev->dev);
|
2015-09-03 20:39:36 +00:00
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-03-03 17:20:16 +00:00
|
|
|
static void s3c64xx_spi_remove(struct platform_device *pdev)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host = platform_get_drvdata(pdev);
|
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2015-09-03 20:40:53 +00:00
|
|
|
pm_runtime_get_sync(&pdev->dev);
|
2011-12-04 00:58:06 +00:00
|
|
|
|
2011-11-10 10:57:32 +00:00
|
|
|
writel(0, sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
|
2017-01-09 10:36:10 +00:00
|
|
|
if (!is_polling(sdd)) {
|
|
|
|
dma_release_channel(sdd->rx_dma.ch);
|
|
|
|
dma_release_channel(sdd->tx_dma.ch);
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:40:53 +00:00
|
|
|
pm_runtime_put_noidle(&pdev->dev);
|
|
|
|
pm_runtime_disable(&pdev->dev);
|
|
|
|
pm_runtime_set_suspended(&pdev->dev);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
|
|
|
|
2013-03-22 02:09:08 +00:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2011-12-04 00:36:18 +00:00
|
|
|
static int s3c64xx_spi_suspend(struct device *dev)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host = dev_get_drvdata(dev);
|
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2024-02-07 12:04:28 +00:00
|
|
|
int ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2024-02-07 12:04:28 +00:00
|
|
|
ret = spi_controller_suspend(host);
|
2013-10-21 13:42:49 +00:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2015-09-03 20:40:11 +00:00
|
|
|
ret = pm_runtime_force_suspend(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
sdd->cur_speed = 0; /* Output Clock is stopped */
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-12-04 00:36:18 +00:00
|
|
|
static int s3c64xx_spi_resume(struct device *dev)
|
2009-11-30 07:39:42 +00:00
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host = dev_get_drvdata(dev);
|
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2010-01-20 20:49:44 +00:00
|
|
|
struct s3c64xx_spi_info *sci = sdd->cntrlr_info;
|
2015-09-03 20:40:11 +00:00
|
|
|
int ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2013-04-16 03:42:57 +00:00
|
|
|
if (sci->cfg_gpio)
|
2012-07-12 22:15:15 +00:00
|
|
|
sci->cfg_gpio();
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2015-09-03 20:40:11 +00:00
|
|
|
ret = pm_runtime_force_resume(dev);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2023-08-18 09:31:47 +00:00
|
|
|
return spi_controller_resume(host);
|
2009-11-30 07:39:42 +00:00
|
|
|
}
|
2013-03-22 02:09:08 +00:00
|
|
|
#endif /* CONFIG_PM_SLEEP */
|
2009-11-30 07:39:42 +00:00
|
|
|
|
2014-12-12 23:41:15 +00:00
|
|
|
#ifdef CONFIG_PM
|
2011-12-04 00:58:06 +00:00
|
|
|
static int s3c64xx_spi_runtime_suspend(struct device *dev)
|
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host = dev_get_drvdata(dev);
|
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2011-12-04 00:58:06 +00:00
|
|
|
|
2012-10-02 23:30:12 +00:00
|
|
|
clk_disable_unprepare(sdd->clk);
|
|
|
|
clk_disable_unprepare(sdd->src_clk);
|
2016-07-12 10:02:14 +00:00
|
|
|
clk_disable_unprepare(sdd->ioclk);
|
2011-12-04 00:58:06 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int s3c64xx_spi_runtime_resume(struct device *dev)
|
|
|
|
{
|
2023-08-18 09:31:47 +00:00
|
|
|
struct spi_controller *host = dev_get_drvdata(dev);
|
|
|
|
struct s3c64xx_spi_driver_data *sdd = spi_controller_get_devdata(host);
|
2013-09-27 17:44:53 +00:00
|
|
|
int ret;
|
2011-12-04 00:58:06 +00:00
|
|
|
|
2016-07-12 10:02:14 +00:00
|
|
|
if (sdd->port_conf->clk_ioclk) {
|
|
|
|
ret = clk_prepare_enable(sdd->ioclk);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-27 17:44:53 +00:00
|
|
|
ret = clk_prepare_enable(sdd->src_clk);
|
|
|
|
if (ret != 0)
|
2016-07-12 10:02:14 +00:00
|
|
|
goto err_disable_ioclk;
|
2013-09-27 17:44:53 +00:00
|
|
|
|
|
|
|
ret = clk_prepare_enable(sdd->clk);
|
2016-07-12 10:02:14 +00:00
|
|
|
if (ret != 0)
|
|
|
|
goto err_disable_src_clk;
|
2011-12-04 00:58:06 +00:00
|
|
|
|
2018-05-16 08:42:39 +00:00
|
|
|
s3c64xx_spi_hwinit(sdd);
|
|
|
|
|
2020-10-02 12:22:43 +00:00
|
|
|
writel(S3C64XX_SPI_INT_RX_OVERRUN_EN | S3C64XX_SPI_INT_RX_UNDERRUN_EN |
|
|
|
|
S3C64XX_SPI_INT_TX_OVERRUN_EN | S3C64XX_SPI_INT_TX_UNDERRUN_EN,
|
|
|
|
sdd->regs + S3C64XX_SPI_INT_EN);
|
|
|
|
|
2011-12-04 00:58:06 +00:00
|
|
|
return 0;
|
2016-07-12 10:02:14 +00:00
|
|
|
|
|
|
|
err_disable_src_clk:
|
|
|
|
clk_disable_unprepare(sdd->src_clk);
|
|
|
|
err_disable_ioclk:
|
|
|
|
clk_disable_unprepare(sdd->ioclk);
|
|
|
|
|
|
|
|
return ret;
|
2011-12-04 00:58:06 +00:00
|
|
|
}
|
2014-12-12 23:41:15 +00:00
|
|
|
#endif /* CONFIG_PM */
|
2011-12-04 00:58:06 +00:00
|
|
|
|
2011-12-04 00:36:18 +00:00
|
|
|
static const struct dev_pm_ops s3c64xx_spi_pm = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(s3c64xx_spi_suspend, s3c64xx_spi_resume)
|
2011-12-04 00:58:06 +00:00
|
|
|
SET_RUNTIME_PM_OPS(s3c64xx_spi_runtime_suspend,
|
|
|
|
s3c64xx_spi_runtime_resume, NULL)
|
2011-12-04 00:36:18 +00:00
|
|
|
};
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static const struct s3c64xx_spi_port_config s3c2443_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.fifo_lvl_mask = { 0x7f },
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.rx_lvl_offset = 13,
|
|
|
|
.tx_st_done = 21,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2012-07-12 22:15:14 +00:00
|
|
|
.high_speed = true,
|
|
|
|
};
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static const struct s3c64xx_spi_port_config s3c6410_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.fifo_lvl_mask = { 0x7f, 0x7F },
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.rx_lvl_offset = 13,
|
|
|
|
.tx_st_done = 21,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2012-07-12 22:15:14 +00:00
|
|
|
};
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static const struct s3c64xx_spi_port_config s5pv210_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.fifo_lvl_mask = { 0x1ff, 0x7F },
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.rx_lvl_offset = 15,
|
|
|
|
.tx_st_done = 25,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2012-07-12 22:15:14 +00:00
|
|
|
.high_speed = true,
|
|
|
|
};
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static const struct s3c64xx_spi_port_config exynos4_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.fifo_lvl_mask = { 0x1ff, 0x7F, 0x7F },
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2012-07-12 22:15:14 +00:00
|
|
|
.rx_lvl_offset = 15,
|
|
|
|
.tx_st_done = 25,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2012-07-12 22:15:14 +00:00
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
2020-10-02 12:22:36 +00:00
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
2012-07-12 22:15:14 +00:00
|
|
|
};
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static const struct s3c64xx_spi_port_config exynos7_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2014-11-06 09:51:49 +00:00
|
|
|
.fifo_lvl_mask = { 0x1ff, 0x7F, 0x7F, 0x7F, 0x7F, 0x1ff},
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2014-11-06 09:51:49 +00:00
|
|
|
.rx_lvl_offset = 15,
|
|
|
|
.tx_st_done = 25,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2014-11-06 09:51:49 +00:00
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
|
|
|
};
|
|
|
|
|
2021-04-14 20:33:43 +00:00
|
|
|
static const struct s3c64xx_spi_port_config exynos5433_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2016-07-12 10:02:14 +00:00
|
|
|
.fifo_lvl_mask = { 0x1ff, 0x7f, 0x7f, 0x7f, 0x7f, 0x1ff},
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2016-07-12 10:02:14 +00:00
|
|
|
.rx_lvl_offset = 15,
|
|
|
|
.tx_st_done = 25,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2016-07-12 10:02:14 +00:00
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
|
|
|
.clk_ioclk = true,
|
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
|
|
|
};
|
|
|
|
|
2024-01-20 01:29:46 +00:00
|
|
|
static const struct s3c64xx_spi_port_config exynos850_spi_port_config = {
|
2024-02-16 07:05:55 +00:00
|
|
|
.fifo_depth = 64,
|
|
|
|
.rx_fifomask = S3C64XX_SPI_ST_RX_FIFO_RDY_V2,
|
|
|
|
.tx_fifomask = S3C64XX_SPI_ST_TX_FIFO_RDY_V2,
|
2024-01-20 01:29:46 +00:00
|
|
|
.tx_st_done = 25,
|
|
|
|
.clk_div = 4,
|
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
|
|
|
.has_loopback = true,
|
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
|
|
|
};
|
|
|
|
|
2022-06-29 10:23:04 +00:00
|
|
|
static const struct s3c64xx_spi_port_config exynosautov9_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2022-06-29 10:23:04 +00:00
|
|
|
.fifo_lvl_mask = { 0x1ff, 0x1ff, 0x7f, 0x7f, 0x7f, 0x7f, 0x1ff, 0x7f,
|
|
|
|
0x7f, 0x7f, 0x7f, 0x7f},
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2022-06-29 10:23:04 +00:00
|
|
|
.rx_lvl_offset = 15,
|
|
|
|
.tx_st_done = 25,
|
|
|
|
.clk_div = 4,
|
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
|
|
|
.clk_ioclk = true,
|
|
|
|
.has_loopback = true,
|
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
|
|
|
};
|
|
|
|
|
2022-06-27 09:45:41 +00:00
|
|
|
static const struct s3c64xx_spi_port_config fsd_spi_port_config = {
|
2024-02-16 07:05:53 +00:00
|
|
|
/* fifo_lvl_mask is deprecated. Use {rx, tx}_fifomask instead. */
|
2022-03-08 12:16:40 +00:00
|
|
|
.fifo_lvl_mask = { 0x7f, 0x7f, 0x7f, 0x7f, 0x7f},
|
2024-02-16 07:05:53 +00:00
|
|
|
/* rx_lvl_offset is deprecated. Use {rx, tx}_fifomask instead. */
|
2022-03-08 12:16:40 +00:00
|
|
|
.rx_lvl_offset = 15,
|
|
|
|
.tx_st_done = 25,
|
2022-06-29 10:23:02 +00:00
|
|
|
.clk_div = 2,
|
2022-03-08 12:16:40 +00:00
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
|
|
|
.clk_ioclk = false,
|
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
|
|
|
};
|
|
|
|
|
2024-02-07 11:15:16 +00:00
|
|
|
static const struct s3c64xx_spi_port_config gs101_spi_port_config = {
|
2024-02-16 07:05:54 +00:00
|
|
|
.fifo_depth = 64,
|
|
|
|
.rx_fifomask = S3C64XX_SPI_ST_RX_FIFO_RDY_V2,
|
|
|
|
.tx_fifomask = S3C64XX_SPI_ST_TX_FIFO_RDY_V2,
|
2024-02-07 11:15:16 +00:00
|
|
|
.tx_st_done = 25,
|
|
|
|
.clk_div = 4,
|
|
|
|
.high_speed = true,
|
|
|
|
.clk_from_cmu = true,
|
|
|
|
.has_loopback = true,
|
|
|
|
.use_32bit_io = true,
|
|
|
|
.quirks = S3C64XX_SPI_QUIRK_CS_AUTO,
|
|
|
|
};
|
|
|
|
|
2015-05-01 15:44:06 +00:00
|
|
|
static const struct platform_device_id s3c64xx_spi_driver_ids[] = {
|
2012-07-12 22:15:14 +00:00
|
|
|
{
|
|
|
|
.name = "s3c2443-spi",
|
|
|
|
.driver_data = (kernel_ulong_t)&s3c2443_spi_port_config,
|
|
|
|
}, {
|
|
|
|
.name = "s3c6410-spi",
|
|
|
|
.driver_data = (kernel_ulong_t)&s3c6410_spi_port_config,
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2012-07-12 22:15:15 +00:00
|
|
|
static const struct of_device_id s3c64xx_spi_dt_match[] = {
|
2024-02-07 11:15:16 +00:00
|
|
|
{ .compatible = "google,gs101-spi",
|
|
|
|
.data = &gs101_spi_port_config,
|
|
|
|
},
|
2013-09-23 09:45:45 +00:00
|
|
|
{ .compatible = "samsung,s3c2443-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &s3c2443_spi_port_config,
|
2013-09-23 09:45:45 +00:00
|
|
|
},
|
|
|
|
{ .compatible = "samsung,s3c6410-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &s3c6410_spi_port_config,
|
2013-09-23 09:45:45 +00:00
|
|
|
},
|
|
|
|
{ .compatible = "samsung,s5pv210-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &s5pv210_spi_port_config,
|
2013-09-23 09:45:45 +00:00
|
|
|
},
|
2012-07-12 22:15:15 +00:00
|
|
|
{ .compatible = "samsung,exynos4210-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &exynos4_spi_port_config,
|
2012-07-12 22:15:15 +00:00
|
|
|
},
|
2014-11-06 09:51:49 +00:00
|
|
|
{ .compatible = "samsung,exynos7-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &exynos7_spi_port_config,
|
2014-11-06 09:51:49 +00:00
|
|
|
},
|
2016-07-12 10:02:14 +00:00
|
|
|
{ .compatible = "samsung,exynos5433-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &exynos5433_spi_port_config,
|
2016-07-12 10:02:14 +00:00
|
|
|
},
|
2024-01-20 01:29:46 +00:00
|
|
|
{ .compatible = "samsung,exynos850-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &exynos850_spi_port_config,
|
2024-01-20 01:29:46 +00:00
|
|
|
},
|
2022-06-29 10:23:04 +00:00
|
|
|
{ .compatible = "samsung,exynosautov9-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &exynosautov9_spi_port_config,
|
2022-06-29 10:23:04 +00:00
|
|
|
},
|
2022-03-08 12:16:40 +00:00
|
|
|
{ .compatible = "tesla,fsd-spi",
|
2024-02-07 12:04:21 +00:00
|
|
|
.data = &fsd_spi_port_config,
|
2022-03-08 12:16:40 +00:00
|
|
|
},
|
2012-07-12 22:15:15 +00:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, s3c64xx_spi_dt_match);
|
|
|
|
|
2009-11-30 07:39:42 +00:00
|
|
|
static struct platform_driver s3c64xx_spi_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "s3c64xx-spi",
|
2011-12-04 00:36:18 +00:00
|
|
|
.pm = &s3c64xx_spi_pm,
|
2012-07-12 22:15:15 +00:00
|
|
|
.of_match_table = of_match_ptr(s3c64xx_spi_dt_match),
|
2009-11-30 07:39:42 +00:00
|
|
|
},
|
2013-09-09 14:09:25 +00:00
|
|
|
.probe = s3c64xx_spi_probe,
|
2023-03-03 17:20:16 +00:00
|
|
|
.remove_new = s3c64xx_spi_remove,
|
2012-07-12 22:15:14 +00:00
|
|
|
.id_table = s3c64xx_spi_driver_ids,
|
2009-11-30 07:39:42 +00:00
|
|
|
};
|
|
|
|
MODULE_ALIAS("platform:s3c64xx-spi");
|
|
|
|
|
2013-09-09 14:09:25 +00:00
|
|
|
module_platform_driver(s3c64xx_spi_driver);
|
2009-11-30 07:39:42 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jaswinder Singh <jassi.brar@samsung.com>");
|
|
|
|
MODULE_DESCRIPTION("S3C64XX SPI Controller Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|