Lines Matching refs:spidev
106 spidev_sync(struct spidev_data *spidev, struct spi_message *message) in spidev_sync() argument
111 mutex_lock(&spidev->spi_lock); in spidev_sync()
112 spi = spidev->spi; in spidev_sync()
119 mutex_unlock(&spidev->spi_lock); in spidev_sync()
124 spidev_sync_write(struct spidev_data *spidev, size_t len) in spidev_sync_write() argument
127 .tx_buf = spidev->tx_buffer, in spidev_sync_write()
129 .speed_hz = spidev->speed_hz, in spidev_sync_write()
135 return spidev_sync(spidev, &m); in spidev_sync_write()
139 spidev_sync_read(struct spidev_data *spidev, size_t len) in spidev_sync_read() argument
142 .rx_buf = spidev->rx_buffer, in spidev_sync_read()
144 .speed_hz = spidev->speed_hz, in spidev_sync_read()
150 return spidev_sync(spidev, &m); in spidev_sync_read()
159 struct spidev_data *spidev; in spidev_read() local
166 spidev = filp->private_data; in spidev_read()
168 mutex_lock(&spidev->buf_lock); in spidev_read()
169 status = spidev_sync_read(spidev, count); in spidev_read()
173 missing = copy_to_user(buf, spidev->rx_buffer, status); in spidev_read()
179 mutex_unlock(&spidev->buf_lock); in spidev_read()
189 struct spidev_data *spidev; in spidev_write() local
197 spidev = filp->private_data; in spidev_write()
199 mutex_lock(&spidev->buf_lock); in spidev_write()
200 missing = copy_from_user(spidev->tx_buffer, buf, count); in spidev_write()
202 status = spidev_sync_write(spidev, count); in spidev_write()
205 mutex_unlock(&spidev->buf_lock); in spidev_write()
210 static int spidev_message(struct spidev_data *spidev, in spidev_message() argument
230 tx_buf = spidev->tx_buffer; in spidev_message()
231 rx_buf = spidev->rx_buffer; in spidev_message()
291 k_tmp->speed_hz = spidev->speed_hz; in spidev_message()
293 dev_dbg(&spidev->spi->dev, in spidev_message()
299 k_tmp->bits_per_word ? : spidev->spi->bits_per_word, in spidev_message()
302 k_tmp->speed_hz ? : spidev->spi->max_speed_hz); in spidev_message()
307 status = spidev_sync_unlocked(spidev->spi, &msg); in spidev_message()
358 struct spidev_data *spidev; in spidev_ioctl() local
372 spidev = filp->private_data; in spidev_ioctl()
373 mutex_lock(&spidev->spi_lock); in spidev_ioctl()
374 spi = spi_dev_get(spidev->spi); in spidev_ioctl()
376 mutex_unlock(&spidev->spi_lock); in spidev_ioctl()
388 mutex_lock(&spidev->buf_lock); in spidev_ioctl()
412 retval = put_user(spidev->speed_hz, (__u32 __user *)arg); in spidev_ioctl()
488 spidev->speed_hz = tmp; in spidev_ioctl()
489 dev_dbg(&spi->dev, "%d Hz (max)\n", spidev->speed_hz); in spidev_ioctl()
508 retval = spidev_message(spidev, ioc, n_ioc); in spidev_ioctl()
513 mutex_unlock(&spidev->buf_lock); in spidev_ioctl()
515 mutex_unlock(&spidev->spi_lock); in spidev_ioctl()
526 struct spidev_data *spidev; in spidev_compat_ioc_message() local
536 spidev = filp->private_data; in spidev_compat_ioc_message()
537 mutex_lock(&spidev->spi_lock); in spidev_compat_ioc_message()
538 spi = spi_dev_get(spidev->spi); in spidev_compat_ioc_message()
540 mutex_unlock(&spidev->spi_lock); in spidev_compat_ioc_message()
545 mutex_lock(&spidev->buf_lock); in spidev_compat_ioc_message()
563 retval = spidev_message(spidev, ioc, n_ioc); in spidev_compat_ioc_message()
567 mutex_unlock(&spidev->buf_lock); in spidev_compat_ioc_message()
569 mutex_unlock(&spidev->spi_lock); in spidev_compat_ioc_message()
589 struct spidev_data *spidev = NULL, *iter; in spidev_open() local
597 spidev = iter; in spidev_open()
602 if (!spidev) { in spidev_open()
607 if (!spidev->tx_buffer) { in spidev_open()
608 spidev->tx_buffer = kmalloc(bufsiz, GFP_KERNEL); in spidev_open()
609 if (!spidev->tx_buffer) { in spidev_open()
615 if (!spidev->rx_buffer) { in spidev_open()
616 spidev->rx_buffer = kmalloc(bufsiz, GFP_KERNEL); in spidev_open()
617 if (!spidev->rx_buffer) { in spidev_open()
623 spidev->users++; in spidev_open()
624 filp->private_data = spidev; in spidev_open()
631 kfree(spidev->tx_buffer); in spidev_open()
632 spidev->tx_buffer = NULL; in spidev_open()
640 struct spidev_data *spidev; in spidev_release() local
644 spidev = filp->private_data; in spidev_release()
647 mutex_lock(&spidev->spi_lock); in spidev_release()
649 dofree = (spidev->spi == NULL); in spidev_release()
650 mutex_unlock(&spidev->spi_lock); in spidev_release()
653 spidev->users--; in spidev_release()
654 if (!spidev->users) { in spidev_release()
656 kfree(spidev->tx_buffer); in spidev_release()
657 spidev->tx_buffer = NULL; in spidev_release()
659 kfree(spidev->rx_buffer); in spidev_release()
660 spidev->rx_buffer = NULL; in spidev_release()
663 kfree(spidev); in spidev_release()
665 spidev->speed_hz = spidev->spi->max_speed_hz; in spidev_release()
669 spi_target_abort(spidev->spi); in spidev_release()
774 struct spidev_data *spidev; in spidev_probe() local
786 spidev = kzalloc(sizeof(*spidev), GFP_KERNEL); in spidev_probe()
787 if (!spidev) in spidev_probe()
791 spidev->spi = spi; in spidev_probe()
792 mutex_init(&spidev->spi_lock); in spidev_probe()
793 mutex_init(&spidev->buf_lock); in spidev_probe()
795 INIT_LIST_HEAD(&spidev->device_entry); in spidev_probe()
805 spidev->devt = MKDEV(SPIDEV_MAJOR, minor); in spidev_probe()
806 dev = device_create(&spidev_class, &spi->dev, spidev->devt, in spidev_probe()
807 spidev, "spidev%d.%d", in spidev_probe()
816 list_add(&spidev->device_entry, &device_list); in spidev_probe()
820 spidev->speed_hz = spi->max_speed_hz; in spidev_probe()
823 spi_set_drvdata(spi, spidev); in spidev_probe()
825 kfree(spidev); in spidev_probe()
832 struct spidev_data *spidev = spi_get_drvdata(spi); in spidev_remove() local
837 mutex_lock(&spidev->spi_lock); in spidev_remove()
838 spidev->spi = NULL; in spidev_remove()
839 mutex_unlock(&spidev->spi_lock); in spidev_remove()
841 list_del(&spidev->device_entry); in spidev_remove()
842 device_destroy(&spidev_class, spidev->devt); in spidev_remove()
843 clear_bit(MINOR(spidev->devt), minors); in spidev_remove()
844 if (spidev->users == 0) in spidev_remove()
845 kfree(spidev); in spidev_remove()