Commit 7a4feff7 authored by Mark Brown's avatar Mark Brown

spidev: A few cleanups

Merge series from Andy Shevchenko <andriy.shevchenko@linux.intel.com>:

A few cleanups to the spidev.c to utilize existing APIs and make it
use less amount of Lines of Code. No functional change intended.
parents 0578a6db 764246c7
...@@ -357,6 +357,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -357,6 +357,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
int retval = 0; int retval = 0;
struct spidev_data *spidev; struct spidev_data *spidev;
struct spi_device *spi; struct spi_device *spi;
struct spi_controller *ctlr;
u32 tmp; u32 tmp;
unsigned n_ioc; unsigned n_ioc;
struct spi_ioc_transfer *ioc; struct spi_ioc_transfer *ioc;
...@@ -376,6 +377,8 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -376,6 +377,8 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return -ESHUTDOWN; return -ESHUTDOWN;
} }
ctlr = spi->controller;
/* use the buffer lock here for triple duty: /* use the buffer lock here for triple duty:
* - prevent I/O (from us) so calling spi_setup() is safe; * - prevent I/O (from us) so calling spi_setup() is safe;
* - prevent concurrent SPI_IOC_WR_* from morphing * - prevent concurrent SPI_IOC_WR_* from morphing
...@@ -388,22 +391,15 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -388,22 +391,15 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
/* read requests */ /* read requests */
case SPI_IOC_RD_MODE: case SPI_IOC_RD_MODE:
case SPI_IOC_RD_MODE32: case SPI_IOC_RD_MODE32:
tmp = spi->mode; tmp = spi->mode & SPI_MODE_MASK;
{
struct spi_controller *ctlr = spi->controller;
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
ctlr->cs_gpiods[spi_get_chipselect(spi, 0)]) tmp &= ~SPI_CS_HIGH;
tmp &= ~SPI_CS_HIGH;
}
if (cmd == SPI_IOC_RD_MODE) if (cmd == SPI_IOC_RD_MODE)
retval = put_user(tmp & SPI_MODE_MASK, retval = put_user(tmp, (__u8 __user *)arg);
(__u8 __user *)arg);
else else
retval = put_user(tmp & SPI_MODE_MASK, retval = put_user(tmp, (__u32 __user *)arg);
(__u32 __user *)arg);
break; break;
case SPI_IOC_RD_LSB_FIRST: case SPI_IOC_RD_LSB_FIRST:
retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0, retval = put_user((spi->mode & SPI_LSB_FIRST) ? 1 : 0,
...@@ -424,7 +420,6 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -424,7 +420,6 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
else else
retval = get_user(tmp, (u32 __user *)arg); retval = get_user(tmp, (u32 __user *)arg);
if (retval == 0) { if (retval == 0) {
struct spi_controller *ctlr = spi->controller;
u32 save = spi->mode; u32 save = spi->mode;
if (tmp & ~SPI_MODE_MASK) { if (tmp & ~SPI_MODE_MASK) {
...@@ -432,8 +427,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) ...@@ -432,8 +427,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
break; break;
} }
if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods && if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
tmp |= SPI_CS_HIGH; tmp |= SPI_CS_HIGH;
tmp |= spi->mode & ~SPI_MODE_MASK; tmp |= spi->mode & ~SPI_MODE_MASK;
......
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