Lines Matching refs:spidev
2 * spidev.c -- simple synchronous userspace interface to SPI devices
35 #include <linux/spi/spidev.h>
106 spidev_sync(struct spidev_data *spidev, struct spi_message *message)
114 spin_lock_irq(&spidev->spi_lock);
115 if (spidev->spi == NULL)
118 status = spi_async(spidev->spi, message);
119 spin_unlock_irq(&spidev->spi_lock);
131 spidev_sync_write(struct spidev_data *spidev, size_t len)
134 .tx_buf = spidev->buffer,
141 return spidev_sync(spidev, &m);
145 spidev_sync_read(struct spidev_data *spidev, size_t len)
148 .rx_buf = spidev->buffer,
155 return spidev_sync(spidev, &m);
164 struct spidev_data *spidev;
171 spidev = filp->private_data;
173 mutex_lock(&spidev->buf_lock);
174 status = spidev_sync_read(spidev, count);
178 missing = copy_to_user(buf, spidev->buffer, status);
184 mutex_unlock(&spidev->buf_lock);
194 struct spidev_data *spidev;
202 spidev = filp->private_data;
204 mutex_lock(&spidev->buf_lock);
205 missing = copy_from_user(spidev->buffer, buf, count);
207 status = spidev_sync_write(spidev, count);
210 mutex_unlock(&spidev->buf_lock);
215 static int spidev_message(struct spidev_data *spidev,
235 buf = spidev->buffer;
269 dev_dbg(&spidev->spi->dev,
275 u_tmp->bits_per_word ? : spidev->spi->bits_per_word,
277 u_tmp->speed_hz ? : spidev->spi->max_speed_hz);
282 status = spidev_sync(spidev, &msg);
287 buf = spidev->buffer;
311 struct spidev_data *spidev;
337 spidev = filp->private_data;
338 spin_lock_irq(&spidev->spi_lock);
339 spi = spi_dev_get(spidev->spi);
340 spin_unlock_irq(&spidev->spi_lock);
351 mutex_lock(&spidev->buf_lock);
464 retval = spidev_message(spidev, ioc, n_ioc);
469 mutex_unlock(&spidev->buf_lock);
476 struct spidev_data *spidev;
481 list_for_each_entry(spidev, &device_list, device_entry) {
482 if (spidev->devt == inode->i_rdev) {
488 if (!spidev->buffer) {
489 spidev->buffer = kmalloc(bufsiz, GFP_KERNEL);
490 if (!spidev->buffer) {
491 dev_dbg(&spidev->spi->dev, "open/ENOMEM\n");
496 spidev->users++;
497 filp->private_data = spidev;
501 pr_debug("spidev: nothing for minor %d\n", iminor(inode));
509 struct spidev_data *spidev;
513 spidev = filp->private_data;
517 spidev->users--;
518 if (!spidev->users) {
521 kfree(spidev->buffer);
522 spidev->buffer = NULL;
525 spin_lock_irq(&spidev->spi_lock);
526 dofree = (spidev->spi == NULL);
527 spin_unlock_irq(&spidev->spi_lock);
530 kfree(spidev);
563 struct spidev_data *spidev;
568 spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
569 if (!spidev)
573 spidev->spi = spi;
574 spin_lock_init(&spidev->spi_lock);
575 mutex_init(&spidev->buf_lock);
577 INIT_LIST_HEAD(&spidev->device_entry);
587 spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
588 dev = device_create(spidev_class, &spi->dev, spidev->devt,
589 spidev, "spidev%d.%d",
598 list_add(&spidev->device_entry, &device_list);
603 spi_set_drvdata(spi, spidev);
605 kfree(spidev);
612 struct spidev_data *spidev = spi_get_drvdata(spi);
615 spin_lock_irq(&spidev->spi_lock);
616 spidev->spi = NULL;
618 spin_unlock_irq(&spidev->spi_lock);
622 list_del(&spidev->device_entry);
623 device_destroy(spidev_class, spidev->devt);
624 clear_bit(MINOR(spidev->devt), minors);
625 if (spidev->users == 0)
626 kfree(spidev);
634 .name = "spidev",
662 spidev_class = class_create(THIS_MODULE, "spidev");
688 MODULE_ALIAS("spi:spidev");