Lines Matching refs:spidev

25 #include <linux/spi/spidev.h>
106 spidev_sync(struct spidev_data *spidev, struct spi_message *message)
111 mutex_lock(&spidev->spi_lock);
112 spi = spidev->spi;
119 mutex_unlock(&spidev->spi_lock);
124 spidev_sync_write(struct spidev_data *spidev, size_t len)
127 .tx_buf = spidev->tx_buffer,
129 .speed_hz = spidev->speed_hz,
135 return spidev_sync(spidev, &m);
139 spidev_sync_read(struct spidev_data *spidev, size_t len)
142 .rx_buf = spidev->rx_buffer,
144 .speed_hz = spidev->speed_hz,
150 return spidev_sync(spidev, &m);
159 struct spidev_data *spidev;
166 spidev = filp->private_data;
168 mutex_lock(&spidev->buf_lock);
169 status = spidev_sync_read(spidev, count);
173 missing = copy_to_user(buf, spidev->rx_buffer, status);
179 mutex_unlock(&spidev->buf_lock);
189 struct spidev_data *spidev;
197 spidev = filp->private_data;
199 mutex_lock(&spidev->buf_lock);
200 missing = copy_from_user(spidev->tx_buffer, buf, count);
202 status = spidev_sync_write(spidev, count);
205 mutex_unlock(&spidev->buf_lock);
210 static int spidev_message(struct spidev_data *spidev,
230 tx_buf = spidev->tx_buffer;
231 rx_buf = spidev->rx_buffer;
291 k_tmp->speed_hz = spidev->speed_hz;
293 dev_dbg(&spidev->spi->dev,
299 k_tmp->bits_per_word ? : spidev->spi->bits_per_word,
302 k_tmp->speed_hz ? : spidev->spi->max_speed_hz);
307 status = spidev_sync_unlocked(spidev->spi, &msg);
358 struct spidev_data *spidev;
372 spidev = filp->private_data;
373 mutex_lock(&spidev->spi_lock);
374 spi = spi_dev_get(spidev->spi);
376 mutex_unlock(&spidev->spi_lock);
388 mutex_lock(&spidev->buf_lock);
412 retval = put_user(spidev->speed_hz, (__u32 __user *)arg);
488 spidev->speed_hz = tmp;
489 dev_dbg(&spi->dev, "%d Hz (max)\n", spidev->speed_hz);
508 retval = spidev_message(spidev, ioc, n_ioc);
513 mutex_unlock(&spidev->buf_lock);
515 mutex_unlock(&spidev->spi_lock);
526 struct spidev_data *spidev;
536 spidev = filp->private_data;
537 mutex_lock(&spidev->spi_lock);
538 spi = spi_dev_get(spidev->spi);
540 mutex_unlock(&spidev->spi_lock);
545 mutex_lock(&spidev->buf_lock);
563 retval = spidev_message(spidev, ioc, n_ioc);
567 mutex_unlock(&spidev->buf_lock);
569 mutex_unlock(&spidev->spi_lock);
589 struct spidev_data *spidev = NULL, *iter;
597 spidev = iter;
602 if (!spidev) {
603 pr_debug("spidev: nothing for minor %d\n", iminor(inode));
607 if (!spidev->tx_buffer) {
608 spidev->tx_buffer = kmalloc(bufsiz, GFP_KERNEL);
609 if (!spidev->tx_buffer) {
615 if (!spidev->rx_buffer) {
616 spidev->rx_buffer = kmalloc(bufsiz, GFP_KERNEL);
617 if (!spidev->rx_buffer) {
623 spidev->users++;
624 filp->private_data = spidev;
631 kfree(spidev->tx_buffer);
632 spidev->tx_buffer = NULL;
640 struct spidev_data *spidev;
644 spidev = filp->private_data;
647 mutex_lock(&spidev->spi_lock);
649 dofree = (spidev->spi == NULL);
650 mutex_unlock(&spidev->spi_lock);
653 spidev->users--;
654 if (!spidev->users) {
656 kfree(spidev->tx_buffer);
657 spidev->tx_buffer = NULL;
659 kfree(spidev->rx_buffer);
660 spidev->rx_buffer = NULL;
663 kfree(spidev);
665 spidev->speed_hz = spidev->spi->max_speed_hz;
669 spi_slave_abort(spidev->spi);
699 .name = "spidev",
718 * spidev should never be referenced in DT without a specific compatible string,
723 if (device_property_match_string(dev, "compatible", "spidev") < 0)
726 dev_err(dev, "spidev listed directly in DT is not supported\n");
771 struct spidev_data *spidev;
783 spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
784 if (!spidev)
788 spidev->spi = spi;
789 mutex_init(&spidev->spi_lock);
790 mutex_init(&spidev->buf_lock);
792 INIT_LIST_HEAD(&spidev->device_entry);
802 spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
803 dev = device_create(&spidev_class, &spi->dev, spidev->devt,
804 spidev, "spidev%d.%d",
813 list_add(&spidev->device_entry, &device_list);
817 spidev->speed_hz = spi->max_speed_hz;
820 spi_set_drvdata(spi, spidev);
822 kfree(spidev);
829 struct spidev_data *spidev = spi_get_drvdata(spi);
834 mutex_lock(&spidev->spi_lock);
835 spidev->spi = NULL;
836 mutex_unlock(&spidev->spi_lock);
838 list_del(&spidev->device_entry);
839 device_destroy(&spidev_class, spidev->devt);
840 clear_bit(MINOR(spidev->devt), minors);
841 if (spidev->users == 0)
842 kfree(spidev);
848 .name = "spidev",
903 MODULE_ALIAS("spi:spidev");