Lines Matching refs:spidev

92 spidev_sync(struct spidev_data *spidev, struct spi_message *message)  in spidev_sync()  argument
97 spin_lock_irq(&spidev->spi_lock); in spidev_sync()
98 spi = spidev->spi; in spidev_sync()
99 spin_unlock_irq(&spidev->spi_lock); in spidev_sync()
113 spidev_sync_write(struct spidev_data *spidev, size_t len) in spidev_sync_write() argument
116 .tx_buf = spidev->tx_buffer, in spidev_sync_write()
118 .speed_hz = spidev->speed_hz, in spidev_sync_write()
124 return spidev_sync(spidev, &m); in spidev_sync_write()
128 spidev_sync_read(struct spidev_data *spidev, size_t len) in spidev_sync_read() argument
131 .rx_buf = spidev->rx_buffer, in spidev_sync_read()
133 .speed_hz = spidev->speed_hz, in spidev_sync_read()
139 return spidev_sync(spidev, &m); in spidev_sync_read()
148 struct spidev_data *spidev; in spidev_read() local
155 spidev = filp->private_data; in spidev_read()
157 mutex_lock(&spidev->buf_lock); in spidev_read()
158 status = spidev_sync_read(spidev, count); in spidev_read()
162 missing = copy_to_user(buf, spidev->rx_buffer, status); in spidev_read()
168 mutex_unlock(&spidev->buf_lock); in spidev_read()
178 struct spidev_data *spidev; in spidev_write() local
186 spidev = filp->private_data; in spidev_write()
188 mutex_lock(&spidev->buf_lock); in spidev_write()
189 missing = copy_from_user(spidev->tx_buffer, buf, count); in spidev_write()
191 status = spidev_sync_write(spidev, count); in spidev_write()
194 mutex_unlock(&spidev->buf_lock); in spidev_write()
199 static int spidev_message(struct spidev_data *spidev, in spidev_message() argument
219 tx_buf = spidev->tx_buffer; in spidev_message()
220 rx_buf = spidev->rx_buffer; in spidev_message()
280 k_tmp->speed_hz = spidev->speed_hz; in spidev_message()
282 dev_dbg(&spidev->spi->dev, in spidev_message()
288 k_tmp->bits_per_word ? : spidev->spi->bits_per_word, in spidev_message()
291 k_tmp->speed_hz ? : spidev->spi->max_speed_hz); in spidev_message()
296 status = spidev_sync(spidev, &msg); in spidev_message()
347 struct spidev_data *spidev; in spidev_ioctl() local
360 spidev = filp->private_data; in spidev_ioctl()
361 spin_lock_irq(&spidev->spi_lock); in spidev_ioctl()
362 spi = spi_dev_get(spidev->spi); in spidev_ioctl()
363 spin_unlock_irq(&spidev->spi_lock); in spidev_ioctl()
374 mutex_lock(&spidev->buf_lock); in spidev_ioctl()
394 retval = put_user(spidev->speed_hz, (__u32 __user *)arg); in spidev_ioctl()
464 spidev->speed_hz = tmp; in spidev_ioctl()
466 spidev->speed_hz); in spidev_ioctl()
485 retval = spidev_message(spidev, ioc, n_ioc); in spidev_ioctl()
490 mutex_unlock(&spidev->buf_lock); in spidev_ioctl()
502 struct spidev_data *spidev; in spidev_compat_ioc_message() local
512 spidev = filp->private_data; in spidev_compat_ioc_message()
513 spin_lock_irq(&spidev->spi_lock); in spidev_compat_ioc_message()
514 spi = spi_dev_get(spidev->spi); in spidev_compat_ioc_message()
515 spin_unlock_irq(&spidev->spi_lock); in spidev_compat_ioc_message()
521 mutex_lock(&spidev->buf_lock); in spidev_compat_ioc_message()
539 retval = spidev_message(spidev, ioc, n_ioc); in spidev_compat_ioc_message()
543 mutex_unlock(&spidev->buf_lock); in spidev_compat_ioc_message()
564 struct spidev_data *spidev; in spidev_open() local
569 list_for_each_entry(spidev, &device_list, device_entry) { in spidev_open()
570 if (spidev->devt == inode->i_rdev) { in spidev_open()
581 if (!spidev->tx_buffer) { in spidev_open()
582 spidev->tx_buffer = kmalloc(bufsiz, GFP_KERNEL); in spidev_open()
583 if (!spidev->tx_buffer) { in spidev_open()
584 dev_dbg(&spidev->spi->dev, "open/ENOMEM\n"); in spidev_open()
590 if (!spidev->rx_buffer) { in spidev_open()
591 spidev->rx_buffer = kmalloc(bufsiz, GFP_KERNEL); in spidev_open()
592 if (!spidev->rx_buffer) { in spidev_open()
593 dev_dbg(&spidev->spi->dev, "open/ENOMEM\n"); in spidev_open()
599 spidev->users++; in spidev_open()
600 filp->private_data = spidev; in spidev_open()
607 kfree(spidev->tx_buffer); in spidev_open()
608 spidev->tx_buffer = NULL; in spidev_open()
616 struct spidev_data *spidev; in spidev_release() local
620 spidev = filp->private_data; in spidev_release()
623 spin_lock_irq(&spidev->spi_lock); in spidev_release()
625 dofree = (spidev->spi == NULL); in spidev_release()
626 spin_unlock_irq(&spidev->spi_lock); in spidev_release()
629 spidev->users--; in spidev_release()
630 if (!spidev->users) { in spidev_release()
632 kfree(spidev->tx_buffer); in spidev_release()
633 spidev->tx_buffer = NULL; in spidev_release()
635 kfree(spidev->rx_buffer); in spidev_release()
636 spidev->rx_buffer = NULL; in spidev_release()
639 kfree(spidev); in spidev_release()
641 spidev->speed_hz = spidev->spi->max_speed_hz; in spidev_release()
645 spi_slave_abort(spidev->spi); in spidev_release()
731 struct spidev_data *spidev; in spidev_probe() local
747 spidev = kzalloc(sizeof(*spidev), GFP_KERNEL); in spidev_probe()
748 if (!spidev) in spidev_probe()
752 spidev->spi = spi; in spidev_probe()
753 spin_lock_init(&spidev->spi_lock); in spidev_probe()
754 mutex_init(&spidev->buf_lock); in spidev_probe()
756 INIT_LIST_HEAD(&spidev->device_entry); in spidev_probe()
766 spidev->devt = MKDEV(SPIDEV_MAJOR, minor); in spidev_probe()
767 dev = device_create(spidev_class, &spi->dev, spidev->devt, in spidev_probe()
768 spidev, "spidev%d.%d", in spidev_probe()
777 list_add(&spidev->device_entry, &device_list); in spidev_probe()
781 spidev->speed_hz = spi->max_speed_hz; in spidev_probe()
784 spi_set_drvdata(spi, spidev); in spidev_probe()
786 kfree(spidev); in spidev_probe()
793 struct spidev_data *spidev = spi_get_drvdata(spi); in spidev_remove() local
798 spin_lock_irq(&spidev->spi_lock); in spidev_remove()
799 spidev->spi = NULL; in spidev_remove()
800 spin_unlock_irq(&spidev->spi_lock); in spidev_remove()
802 list_del(&spidev->device_entry); in spidev_remove()
803 device_destroy(spidev_class, spidev->devt); in spidev_remove()
804 clear_bit(MINOR(spidev->devt), minors); in spidev_remove()
805 if (spidev->users == 0) in spidev_remove()
806 kfree(spidev); in spidev_remove()