spi: clps711x: Simplify handling of RX & TX buffers
PATCH 1/3 spi: clps711x: Simplify handling of RX & TX buffers
Signed-off-by Alexander Shiyan <shc_work-JGs/[email protected]>
--- drivers/spi/spi-clps711x.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-)
drivers/spi/spi-clps711x.c +7 -10
@@ -31,7 +31,6 @@ struct spi_clps711x_data {u8 *tx_buf;u8 *rx_buf; -int count;int len;int chipselect[0 ];
@@ -92,11 +91,12 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,struct spi_clps711x_data *hw =spi_master_get_devdata (master);struct spi_transfer *xfer;int status =0 , cs = hw->chipselect[msg->spi->chip_select]; -u32 data;spi_clps711x_setup_mode (msg->spi);list_for_each_entry (xfer, &msg->transfers, transfer_list) { +u8 data; +if (spi_clps711x_setup_xfer (msg->spi, xfer)) { status = -EINVAL ; goto out_xfr;
@@ -106,13 +106,12 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,reinit_completion (&hw->done); - hw->count =0 ; hw->len = xfer->len; hw->tx_buf = (u8 *)xfer->tx_buf; hw->rx_buf = (u8 *)xfer->rx_buf;/* Initiate transfer */ - data = hw->tx_buf ? hw->tx_buf[hw->count] :0 ; + data = hw->tx_buf ? *hw->tx_buf++ :0 ;clps_writel (data |SYNCIO_FRMLEN (8 ) |SYNCIO_TXFRMEN ,SYNCIO );wait_for_completion (&hw->done);
@@ -137,18 +136,16 @@ out_xfr:static irqreturn_t spi_clps711x_isr (int irq,void *dev_id) {struct spi_clps711x_data *hw = (struct spi_clps711x_data *)dev_id; -u32 data; +u8 data;/* Handle RX */ data =clps_readb (SYNCIO );if (hw->rx_buf) - hw->rx_buf[hw->count] = (u8 )data; - - hw->count++; + *hw->rx_buf++ = data;/* Handle TX */ -if (hw->count < hw->len) { - data = hw->tx_buf ? hw->tx_buf[hw->count] :0 ; +if (--hw->len >0 ) { + data = hw->tx_buf ? *hw->tx_buf++ :0 ;clps_writel (data |SYNCIO_FRMLEN (8 ) |SYNCIO_TXFRMEN ,SYNCIO ); }else complete (&hw->done);
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 1391324390-17547-1-git-send-email-shc_work-JGs/[email protected]
PATCH 2/3 spi: clps711x: Add support for 1-8 BPW transfers
This patch adds support for 1 to 8 BPW to driver and removes excess BPW validation since this is already checked by SPI core.
Signed-off-by Alexander Shiyan <shc_work-JGs/[email protected]>
--- drivers/spi/spi-clps711x.c | 39 ++++++++++++++++----------------------- 1 file changed, 16 insertions(+), 23 deletions(-)
drivers/spi/spi-clps711x.c +16 -23
@@ -31,6 +31,7 @@ struct spi_clps711x_data {u8 *tx_buf;u8 *rx_buf; +unsigned int bpw;int len;int chipselect[0 ];
@@ -56,18 +57,12 @@ static void spi_clps711x_setup_mode(struct spi_device *spi)clps_writew (clps_readw (SYSCON3 ) & ~SYSCON3_ADCCKNSEN ,SYSCON3 ); } -static int spi_clps711x_setup_xfer (struct spi_device *spi, -struct spi_transfer *xfer) +static void spi_clps711x_setup_xfer (struct spi_device *spi, +struct spi_transfer *xfer) {u32 speed = xfer->speed_hz ? : spi->max_speed_hz; -u8 bpw = xfer->bits_per_word;struct spi_clps711x_data *hw =spi_master_get_devdata (spi->master); -if (bpw !=8 ) { -dev_err (&spi->dev,"Unsupported master bus width %i\n" , bpw); -return -EINVAL ; - } -/* Setup SPI frequency divider */ if (!speed || (speed >= hw->max_speed_hz)) clps_writel((clps_readl(SYSCON1) & ~SYSCON1_ADCKSEL_MASK) |
@@ -81,38 +76,36 @@ static int spi_clps711x_setup_xfer(struct spi_device *spi,else clps_writel ((clps_readl (SYSCON1 ) & ~SYSCON1_ADCKSEL_MASK ) |SYSCON1_ADCKSEL (0 ),SYSCON1 ); - -return 0 ; }static int spi_clps711x_transfer_one_message (struct spi_master *master,struct spi_message *msg) {struct spi_clps711x_data *hw =spi_master_get_devdata (master); +struct spi_device *spi = msg->spi;struct spi_transfer *xfer; -int status =0 , cs = hw->chipselect[msg->spi->chip_select]; +int cs = hw->chipselect[spi->chip_select]; -spi_clps711x_setup_mode (msg->spi); +spi_clps711x_setup_mode (spi);list_for_each_entry (xfer, &msg->transfers, transfer_list) {u8 data; -if (spi_clps711x_setup_xfer (msg->spi, xfer)) { - status = -EINVAL ; - goto out_xfr; - } +spi_clps711x_setup_xfer (spi, xfer); -gpio_set_value (cs, !!(msg->spi->mode &SPI_CS_HIGH )); +gpio_set_value (cs, !!(spi->mode &SPI_CS_HIGH ));reinit_completion (&hw->done); hw->len = xfer->len; + hw->bpw = xfer->bits_per_word ? : spi->bits_per_word; hw->tx_buf = (u8 *)xfer->tx_buf; hw->rx_buf = (u8 *)xfer->rx_buf;/* Initiate transfer */ data = hw->tx_buf ? *hw->tx_buf++ :0 ; -clps_writel (data |SYNCIO_FRMLEN (8 ) |SYNCIO_TXFRMEN ,SYNCIO ); +clps_writel (data |SYNCIO_FRMLEN (hw->bpw) |SYNCIO_TXFRMEN , +SYNCIO );wait_for_completion (&hw->done);
@@ -121,13 +114,12 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,if (xfer->cs_change ||list_is_last (&xfer->transfer_list, &msg->transfers)) -gpio_set_value (cs, !(msg->spi->mode &SPI_CS_HIGH )); +gpio_set_value (cs, !(spi->mode &SPI_CS_HIGH )); msg->actual_length += xfer->len; } -out_xfr: - msg->status = status; + msg->status =0 ;spi_finalize_current_message (master);return 0 ;
@@ -146,7 +138,8 @@ static irqreturn_t spi_clps711x_isr(int irq, void *dev_id)/* Handle TX */ if (--hw->len >0 ) { data = hw->tx_buf ? *hw->tx_buf++ :0 ; -clps_writel (data |SYNCIO_FRMLEN (8 ) |SYNCIO_TXFRMEN ,SYNCIO ); +clps_writel (data |SYNCIO_FRMLEN (hw->bpw) |SYNCIO_TXFRMEN , +SYNCIO ); }else complete (&hw->done);
@@ -180,7 +173,7 @@ static int spi_clps711x_probe(struct platform_device *pdev) master->bus_num = pdev->id; master->mode_bits =SPI_CPHA |SPI_CS_HIGH ; - master->bits_per_word_mask =SPI_BPW_MASK (8 ); + master->bits_per_word_mask =SPI_BPW_RANGE_MASK (1 ,8 ); master->num_chipselect = pdata->num_chipselect; master->setup = spi_clps711x_setup; master->transfer_one_message = spi_clps711x_transfer_one_message;
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 spi: clps711x: Use SPI-core "cs_gpios" property for storing GPIOs
In reply to a message not in the archiveSigned-off-by Alexander Shiyan <shc_work-JGs/[email protected]>
--- drivers/spi/spi-clps711x.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-)
drivers/spi/spi-clps711x.c +14 -17
@@ -33,17 +33,12 @@ struct spi_clps711x_data {u8 *rx_buf;unsigned int bpw;int len; - -int chipselect[0 ]; };static int spi_clps711x_setup (struct spi_device *spi) { -struct spi_clps711x_data *hw =spi_master_get_devdata (spi->master); -/* We are expect that SPI-device is not selected */ -gpio_direction_output (hw->chipselect[spi->chip_select], - !(spi->mode &SPI_CS_HIGH )); +gpio_direction_output (spi->cs_gpio, !(spi->mode &SPI_CS_HIGH ));return 0 ; }
@@ -84,7 +79,6 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,struct spi_clps711x_data *hw =spi_master_get_devdata (master);struct spi_device *spi = msg->spi;struct spi_transfer *xfer; -int cs = hw->chipselect[spi->chip_select];spi_clps711x_setup_mode (spi);
@@ -93,7 +87,7 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,spi_clps711x_setup_xfer (spi, xfer); -gpio_set_value (cs, !!(spi->mode &SPI_CS_HIGH )); +gpio_set_value (spi->cs_gpio, !!(spi->mode &SPI_CS_HIGH ));reinit_completion (&hw->done);
@@ -114,7 +108,7 @@ static int spi_clps711x_transfer_one_message(struct spi_master *master,if (xfer->cs_change ||list_is_last (&xfer->transfer_list, &msg->transfers)) -gpio_set_value (cs, !(spi->mode &SPI_CS_HIGH )); +gpio_set_value (spi->cs_gpio, !(spi->mode &SPI_CS_HIGH )); msg->actual_length += xfer->len; }
@@ -163,12 +157,15 @@ static int spi_clps711x_probe(struct platform_device *pdev)return -EINVAL ; } - master =spi_alloc_master (&pdev->dev, -sizeof (struct spi_clps711x_data ) + -sizeof (int ) * pdata->num_chipselect); -if (!master) { -dev_err (&pdev->dev,"SPI allocating memory error\n" ); + master =spi_alloc_master (&pdev->dev,sizeof (*hw)); +if (!master)return -ENOMEM ; + + master->cs_gpios =devm_kzalloc (&pdev->dev,sizeof (int ) * + pdata->num_chipselect,GFP_KERNEL ); +if (!master->cs_gpios) { + ret = -ENOMEM ; + goto err_out; } master->bus_num = pdev->id;
@@ -181,13 +178,13 @@ static int spi_clps711x_probe(struct platform_device *pdev) hw =spi_master_get_devdata (master);for (i =0 ; i < master->num_chipselect; i++) { - hw->chipselect[i] = pdata->chipselect[i]; -if (!gpio_is_valid (hw->chipselect[i])) { + master->cs_gpios[i] = pdata->chipselect[i]; +if (!gpio_is_valid (master->cs_gpios[i])) {dev_err (&pdev->dev,"Invalid CS GPIO %i\n" , i); ret = -EINVAL ; goto err_out; } -if (devm_gpio_request (&pdev->dev, hw->chipselect[i],NULL )) { +if (devm_gpio_request (&pdev->dev, master->cs_gpios[i],NULL )) {dev_err (&pdev->dev,"Can't get CS GPIO %i\n" , i); ret = -EINVAL ; goto err_out;
Signature · 6 lines
1.8.3.2 -- To unsubscribe from this list: send the line "unsubscribe linux-spi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Mark Brown
AppliedQuoted 1 line · Alexander Shiyan
Signed-off-by Alexander Shiyan <shc_work-JGs/[email protected]>
Applied all, thanks.