summaryrefslogtreecommitdiffstats
path: root/drivers/spi/spidev.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/spi/spidev.c')
-rw-r--r--drivers/spi/spidev.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index d13dc15cc1..655f2c959c 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -357,6 +357,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
int retval = 0;
struct spidev_data *spidev;
struct spi_device *spi;
+ struct spi_controller *ctlr;
u32 tmp;
unsigned n_ioc;
struct spi_ioc_transfer *ioc;
@@ -376,6 +377,8 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
return -ESHUTDOWN;
}
+ ctlr = spi->controller;
+
/* use the buffer lock here for triple duty:
* - prevent I/O (from us) so calling spi_setup() is safe;
* - prevent concurrent SPI_IOC_WR_* from morphing
@@ -388,22 +391,15 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
/* read requests */
case SPI_IOC_RD_MODE:
case SPI_IOC_RD_MODE32:
- tmp = spi->mode;
-
- {
- struct spi_controller *ctlr = spi->controller;
+ tmp = spi->mode & SPI_MODE_MASK;
- if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
- ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
- tmp &= ~SPI_CS_HIGH;
- }
+ if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
+ tmp &= ~SPI_CS_HIGH;
if (cmd == SPI_IOC_RD_MODE)
- retval = put_user(tmp & SPI_MODE_MASK,
- (__u8 __user *)arg);
+ retval = put_user(tmp, (__u8 __user *)arg);
else
- retval = put_user(tmp & SPI_MODE_MASK,
- (__u32 __user *)arg);
+ retval = put_user(tmp, (__u32 __user *)arg);
break;
case SPI_IOC_RD_LSB_FIRST:
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)
else
retval = get_user(tmp, (u32 __user *)arg);
if (retval == 0) {
- struct spi_controller *ctlr = spi->controller;
u32 save = spi->mode;
if (tmp & ~SPI_MODE_MASK) {
@@ -432,8 +427,7 @@ spidev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
break;
}
- if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
- ctlr->cs_gpiods[spi_get_chipselect(spi, 0)])
+ if (ctlr->use_gpio_descriptors && spi_get_csgpiod(spi, 0))
tmp |= SPI_CS_HIGH;
tmp |= spi->mode & ~SPI_MODE_MASK;
@@ -701,7 +695,9 @@ static const struct file_operations spidev_fops = {
* It also simplifies memory management.
*/
-static struct class *spidev_class;
+static const struct class spidev_class = {
+ .name = "spidev",
+};
static const struct spi_device_id spidev_spi_ids[] = {
{ .name = "dh2228fv" },
@@ -804,7 +800,7 @@ static int spidev_probe(struct spi_device *spi)
struct device *dev;
spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
- dev = device_create(spidev_class, &spi->dev, spidev->devt,
+ dev = device_create(&spidev_class, &spi->dev, spidev->devt,
spidev, "spidev%d.%d",
spi->master->bus_num, spi_get_chipselect(spi, 0));
status = PTR_ERR_OR_ZERO(dev);
@@ -840,7 +836,7 @@ static void spidev_remove(struct spi_device *spi)
mutex_unlock(&spidev->spi_lock);
list_del(&spidev->device_entry);
- device_destroy(spidev_class, spidev->devt);
+ device_destroy(&spidev_class, spidev->devt);
clear_bit(MINOR(spidev->devt), minors);
if (spidev->users == 0)
kfree(spidev);
@@ -878,15 +874,15 @@ static int __init spidev_init(void)
if (status < 0)
return status;
- spidev_class = class_create("spidev");
- if (IS_ERR(spidev_class)) {
+ status = class_register(&spidev_class);
+ if (status) {
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
- return PTR_ERR(spidev_class);
+ return status;
}
status = spi_register_driver(&spidev_spi_driver);
if (status < 0) {
- class_destroy(spidev_class);
+ class_unregister(&spidev_class);
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
}
return status;
@@ -896,7 +892,7 @@ module_init(spidev_init);
static void __exit spidev_exit(void)
{
spi_unregister_driver(&spidev_spi_driver);
- class_destroy(spidev_class);
+ class_unregister(&spidev_class);
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
}
module_exit(spidev_exit);