Commit d1f4a38c authored by Haikun Wang's avatar Haikun Wang Committed by Mark Brown

spi: spi-fsl-dspi: Enable TCF interrupt mode support

DSPI module has two optional interrupts when complete data transfer.
One is EOQ interrupt, the other one is TCF interrupt.
EOQ indicates a queue of data frame has been transmitted.
TCF indicates a frame has been transmitted.
This patch enable support TCF mode.
Driver binds a correct interrupt mode to every compatible string.
User should use the correct compatible string in the dts node.
Signed-off-by: default avatarHaikun Wang <haikun.wang@freescale.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 6724af48
...@@ -67,9 +67,11 @@ ...@@ -67,9 +67,11 @@
#define SPI_SR 0x2c #define SPI_SR 0x2c
#define SPI_SR_EOQF 0x10000000 #define SPI_SR_EOQF 0x10000000
#define SPI_SR_TCFQF 0x80000000
#define SPI_RSER 0x30 #define SPI_RSER 0x30
#define SPI_RSER_EOQFE 0x10000000 #define SPI_RSER_EOQFE 0x10000000
#define SPI_RSER_TCFQE 0x80000000
#define SPI_PUSHR 0x34 #define SPI_PUSHR 0x34
#define SPI_PUSHR_CONT (1 << 31) #define SPI_PUSHR_CONT (1 << 31)
...@@ -108,6 +110,27 @@ struct chip_data { ...@@ -108,6 +110,27 @@ struct chip_data {
u16 void_write_data; u16 void_write_data;
}; };
enum dspi_trans_mode {
DSPI_EOQ_MODE = 0,
DSPI_TCFQ_MODE,
};
struct fsl_dspi_devtype_data {
enum dspi_trans_mode trans_mode;
};
static const struct fsl_dspi_devtype_data vf610_data = {
.trans_mode = DSPI_EOQ_MODE,
};
static const struct fsl_dspi_devtype_data ls1021a_v1_data = {
.trans_mode = DSPI_TCFQ_MODE,
};
static const struct fsl_dspi_devtype_data ls2085a_data = {
.trans_mode = DSPI_TCFQ_MODE,
};
struct fsl_dspi { struct fsl_dspi {
struct spi_master *master; struct spi_master *master;
struct platform_device *pdev; struct platform_device *pdev;
...@@ -128,6 +151,7 @@ struct fsl_dspi { ...@@ -128,6 +151,7 @@ struct fsl_dspi {
u8 cs; u8 cs;
u16 void_write_data; u16 void_write_data;
u32 cs_change; u32 cs_change;
struct fsl_dspi_devtype_data *devtype_data;
wait_queue_head_t waitq; wait_queue_head_t waitq;
u32 waitflags; u32 waitflags;
...@@ -213,63 +237,61 @@ static void ns_delay_scale(char *psc, char *sc, int delay_ns, ...@@ -213,63 +237,61 @@ static void ns_delay_scale(char *psc, char *sc, int delay_ns,
} }
} }
static int dspi_transfer_write(struct fsl_dspi *dspi) static u32 dspi_data_to_pushr(struct fsl_dspi *dspi, int tx_word)
{ {
int tx_count = 0;
int tx_word;
u16 d16; u16 d16;
u8 d8;
u32 dspi_pushr = 0;
int first = 1;
tx_word = is_double_byte_mode(dspi); if (!(dspi->dataflags & TRAN_STATE_TX_VOID))
d16 = tx_word ? *(u16 *)dspi->tx : *(u8 *)dspi->tx;
else
d16 = dspi->void_write_data;
/* If we are in word mode, but only have a single byte to transfer dspi->tx += tx_word + 1;
* then switch to byte mode temporarily. Will switch back at the dspi->len -= tx_word + 1;
* end of the transfer.
*/
if (tx_word && (dspi->len == 1)) {
dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM;
regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs),
SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8));
tx_word = 0;
}
while (dspi->len && (tx_count < DSPI_FIFO_SIZE)) { return SPI_PUSHR_TXDATA(d16) |
if (tx_word) { SPI_PUSHR_PCS(dspi->cs) |
if (dspi->len == 1) SPI_PUSHR_CTAS(dspi->cs) |
break; SPI_PUSHR_CONT;
}
if (!(dspi->dataflags & TRAN_STATE_TX_VOID)) { static void dspi_data_from_popr(struct fsl_dspi *dspi, int rx_word)
d16 = *(u16 *)dspi->tx; {
dspi->tx += 2; u16 d;
} else { unsigned int val;
d16 = dspi->void_write_data;
}
dspi_pushr = SPI_PUSHR_TXDATA(d16) | regmap_read(dspi->regmap, SPI_POPR, &val);
SPI_PUSHR_PCS(dspi->cs) | d = SPI_POPR_RXDATA(val);
SPI_PUSHR_CTAS(dspi->cs) |
SPI_PUSHR_CONT;
dspi->len -= 2; if (!(dspi->dataflags & TRAN_STATE_RX_VOID))
} else { rx_word ? (*(u16 *)dspi->rx = d) : (*(u8 *)dspi->rx = d);
if (!(dspi->dataflags & TRAN_STATE_TX_VOID)) {
d8 = *(u8 *)dspi->tx; dspi->rx += rx_word + 1;
dspi->tx++; }
} else {
d8 = (u8)dspi->void_write_data;
}
dspi_pushr = SPI_PUSHR_TXDATA(d8) | static int dspi_eoq_write(struct fsl_dspi *dspi)
SPI_PUSHR_PCS(dspi->cs) | {
SPI_PUSHR_CTAS(dspi->cs) | int tx_count = 0;
SPI_PUSHR_CONT; int tx_word;
u32 dspi_pushr = 0;
int first = 1;
dspi->len--; tx_word = is_double_byte_mode(dspi);
while (dspi->len && (tx_count < DSPI_FIFO_SIZE)) {
/* If we are in word mode, only have a single byte to transfer
* switch to byte mode temporarily. Will switch back at the
* end of the transfer.
*/
if (tx_word && (dspi->len == 1)) {
dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM;
regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs),
SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8));
tx_word = 0;
} }
dspi_pushr = dspi_data_to_pushr(dspi, tx_word);
if (dspi->len == 0 || tx_count == DSPI_FIFO_SIZE - 1) { if (dspi->len == 0 || tx_count == DSPI_FIFO_SIZE - 1) {
/* last transfer in the transfer */ /* last transfer in the transfer */
dspi_pushr |= SPI_PUSHR_EOQ; dspi_pushr |= SPI_PUSHR_EOQ;
...@@ -291,40 +313,55 @@ static int dspi_transfer_write(struct fsl_dspi *dspi) ...@@ -291,40 +313,55 @@ static int dspi_transfer_write(struct fsl_dspi *dspi)
return tx_count * (tx_word + 1); return tx_count * (tx_word + 1);
} }
static int dspi_transfer_read(struct fsl_dspi *dspi) static int dspi_eoq_read(struct fsl_dspi *dspi)
{ {
int rx_count = 0; int rx_count = 0;
int rx_word = is_double_byte_mode(dspi); int rx_word = is_double_byte_mode(dspi);
u16 d;
while ((dspi->rx < dspi->rx_end) while ((dspi->rx < dspi->rx_end)
&& (rx_count < DSPI_FIFO_SIZE)) { && (rx_count < DSPI_FIFO_SIZE)) {
if (rx_word) { if (rx_word && (dspi->rx_end - dspi->rx) == 1)
unsigned int val; rx_word = 0;
if ((dspi->rx_end - dspi->rx) == 1) dspi_data_from_popr(dspi, rx_word);
break; rx_count++;
}
regmap_read(dspi->regmap, SPI_POPR, &val); return rx_count;
d = SPI_POPR_RXDATA(val); }
if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) static int dspi_tcfq_write(struct fsl_dspi *dspi)
*(u16 *)dspi->rx = d; {
dspi->rx += 2; int tx_word;
u32 dspi_pushr = 0;
} else { tx_word = is_double_byte_mode(dspi);
unsigned int val;
regmap_read(dspi->regmap, SPI_POPR, &val); if (tx_word && (dspi->len == 1)) {
d = SPI_POPR_RXDATA(val); dspi->dataflags |= TRAN_STATE_WORD_ODD_NUM;
if (!(dspi->dataflags & TRAN_STATE_RX_VOID)) regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs),
*(u8 *)dspi->rx = d; SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(8));
dspi->rx++; tx_word = 0;
}
rx_count++;
} }
return rx_count; dspi_pushr = dspi_data_to_pushr(dspi, tx_word);
if ((dspi->cs_change) && (!dspi->len))
dspi_pushr &= ~SPI_PUSHR_CONT;
regmap_write(dspi->regmap, SPI_PUSHR, dspi_pushr);
return tx_word + 1;
}
static void dspi_tcfq_read(struct fsl_dspi *dspi)
{
int rx_word = is_double_byte_mode(dspi);
if (rx_word && (dspi->rx_end - dspi->rx) == 1)
rx_word = 0;
dspi_data_from_popr(dspi, rx_word);
} }
static int dspi_transfer_one_message(struct spi_master *master, static int dspi_transfer_one_message(struct spi_master *master,
...@@ -334,6 +371,8 @@ static int dspi_transfer_one_message(struct spi_master *master, ...@@ -334,6 +371,8 @@ static int dspi_transfer_one_message(struct spi_master *master,
struct spi_device *spi = message->spi; struct spi_device *spi = message->spi;
struct spi_transfer *transfer; struct spi_transfer *transfer;
int status = 0; int status = 0;
enum dspi_trans_mode trans_mode;
message->actual_length = 0; message->actual_length = 0;
list_for_each_entry(transfer, &message->transfers, transfer_list) { list_for_each_entry(transfer, &message->transfers, transfer_list) {
...@@ -370,8 +409,22 @@ static int dspi_transfer_one_message(struct spi_master *master, ...@@ -370,8 +409,22 @@ static int dspi_transfer_one_message(struct spi_master *master,
regmap_write(dspi->regmap, SPI_CTAR(dspi->cs), regmap_write(dspi->regmap, SPI_CTAR(dspi->cs),
dspi->cur_chip->ctar_val); dspi->cur_chip->ctar_val);
regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_EOQFE); trans_mode = dspi->devtype_data->trans_mode;
message->actual_length += dspi_transfer_write(dspi); switch (trans_mode) {
case DSPI_EOQ_MODE:
regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_EOQFE);
message->actual_length += dspi_eoq_write(dspi);
break;
case DSPI_TCFQ_MODE:
regmap_write(dspi->regmap, SPI_RSER, SPI_RSER_TCFQE);
message->actual_length += dspi_tcfq_write(dspi);
break;
default:
dev_err(&dspi->pdev->dev, "unsupported trans_mode %u\n",
trans_mode);
status = -EINVAL;
goto out;
}
if (wait_event_interruptible(dspi->waitq, dspi->waitflags)) if (wait_event_interruptible(dspi->waitq, dspi->waitflags))
dev_err(&dspi->pdev->dev, "wait transfer complete fail!\n"); dev_err(&dspi->pdev->dev, "wait transfer complete fail!\n");
...@@ -381,6 +434,7 @@ static int dspi_transfer_one_message(struct spi_master *master, ...@@ -381,6 +434,7 @@ static int dspi_transfer_one_message(struct spi_master *master,
udelay(transfer->delay_usecs); udelay(transfer->delay_usecs);
} }
out:
message->status = status; message->status = status;
spi_finalize_current_message(master); spi_finalize_current_message(master);
...@@ -460,27 +514,57 @@ static void dspi_cleanup(struct spi_device *spi) ...@@ -460,27 +514,57 @@ static void dspi_cleanup(struct spi_device *spi)
static irqreturn_t dspi_interrupt(int irq, void *dev_id) static irqreturn_t dspi_interrupt(int irq, void *dev_id)
{ {
struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id; struct fsl_dspi *dspi = (struct fsl_dspi *)dev_id;
struct spi_message *msg = dspi->cur_msg; struct spi_message *msg = dspi->cur_msg;
enum dspi_trans_mode trans_mode;
regmap_write(dspi->regmap, SPI_SR, SPI_SR_EOQF); u32 spi_sr;
dspi_transfer_read(dspi);
regmap_read(dspi->regmap, SPI_SR, &spi_sr);
regmap_write(dspi->regmap, SPI_SR, spi_sr);
trans_mode = dspi->devtype_data->trans_mode;
switch (trans_mode) {
case DSPI_EOQ_MODE:
dspi_eoq_read(dspi);
break;
case DSPI_TCFQ_MODE:
dspi_tcfq_read(dspi);
break;
default:
dev_err(&dspi->pdev->dev, "unsupported trans_mode %u\n",
trans_mode);
return IRQ_HANDLED;
}
if (!dspi->len) { if (!dspi->len) {
if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) if (dspi->dataflags & TRAN_STATE_WORD_ODD_NUM) {
regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs), regmap_update_bits(dspi->regmap, SPI_CTAR(dspi->cs),
SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(16)); SPI_FRAME_BITS_MASK, SPI_FRAME_BITS(16));
dspi->dataflags &= ~TRAN_STATE_WORD_ODD_NUM;
}
dspi->waitflags = 1; dspi->waitflags = 1;
wake_up_interruptible(&dspi->waitq); wake_up_interruptible(&dspi->waitq);
} else } else {
msg->actual_length += dspi_transfer_write(dspi); switch (trans_mode) {
case DSPI_EOQ_MODE:
msg->actual_length += dspi_eoq_write(dspi);
break;
case DSPI_TCFQ_MODE:
msg->actual_length += dspi_tcfq_write(dspi);
break;
default:
dev_err(&dspi->pdev->dev, "unsupported trans_mode %u\n",
trans_mode);
}
}
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static const struct of_device_id fsl_dspi_dt_ids[] = { static const struct of_device_id fsl_dspi_dt_ids[] = {
{ .compatible = "fsl,vf610-dspi", .data = NULL, }, { .compatible = "fsl,vf610-dspi", .data = (void *)&vf610_data, },
{ .compatible = "fsl,ls1021a-v1.0-dspi",
.data = (void *)&ls1021a_v1_data, },
{ .compatible = "fsl,ls2085a-dspi", .data = (void *)&ls2085a_data, },
{ /* sentinel */ } { /* sentinel */ }
}; };
MODULE_DEVICE_TABLE(of, fsl_dspi_dt_ids); MODULE_DEVICE_TABLE(of, fsl_dspi_dt_ids);
...@@ -526,6 +610,8 @@ static int dspi_probe(struct platform_device *pdev) ...@@ -526,6 +610,8 @@ static int dspi_probe(struct platform_device *pdev)
struct resource *res; struct resource *res;
void __iomem *base; void __iomem *base;
int ret = 0, cs_num, bus_num; int ret = 0, cs_num, bus_num;
const struct of_device_id *of_id =
of_match_device(fsl_dspi_dt_ids, &pdev->dev);
master = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi)); master = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi));
if (!master) if (!master)
...@@ -559,6 +645,13 @@ static int dspi_probe(struct platform_device *pdev) ...@@ -559,6 +645,13 @@ static int dspi_probe(struct platform_device *pdev)
} }
master->bus_num = bus_num; master->bus_num = bus_num;
dspi->devtype_data = (struct fsl_dspi_devtype_data *)of_id->data;
if (!dspi->devtype_data) {
dev_err(&pdev->dev, "can't get devtype_data\n");
ret = -EFAULT;
goto out_master_put;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
base = devm_ioremap_resource(&pdev->dev, res); base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(base)) { if (IS_ERR(base)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment