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;
371 spidev = filp->private_data;
372 mutex_lock(&spidev->spi_lock);
373 spi = spi_dev_get(spidev->spi);
375 mutex_unlock(&spidev->spi_lock);
385 mutex_lock(&spidev->buf_lock);
416 retval = put_user(spidev->speed_hz, (__u32 __user *)arg);
494 spidev->speed_hz = tmp;
495 dev_dbg(&spi->dev, "%d Hz (max)\n", spidev->speed_hz);
514 retval = spidev_message(spidev, ioc, n_ioc);
519 mutex_unlock(&spidev->buf_lock);
521 mutex_unlock(&spidev->spi_lock);
532 struct spidev_data *spidev;
542 spidev = filp->private_data;
543 mutex_lock(&spidev->spi_lock);
544 spi = spi_dev_get(spidev->spi);
546 mutex_unlock(&spidev->spi_lock);
551 mutex_lock(&spidev->buf_lock);
569 retval = spidev_message(spidev, ioc, n_ioc);
573 mutex_unlock(&spidev->buf_lock);
575 mutex_unlock(&spidev->spi_lock);
595 struct spidev_data *spidev = NULL, *iter;
603 spidev = iter;
608 if (!spidev) {
609 pr_debug("spidev: nothing for minor %d\n", iminor(inode));
613 if (!spidev->tx_buffer) {
614 spidev->tx_buffer = kmalloc(bufsiz, GFP_KERNEL);
615 if (!spidev->tx_buffer) {
621 if (!spidev->rx_buffer) {
622 spidev->rx_buffer = kmalloc(bufsiz, GFP_KERNEL);
623 if (!spidev->rx_buffer) {
629 spidev->users++;
630 filp->private_data = spidev;
637 kfree(spidev->tx_buffer);
638 spidev->tx_buffer = NULL;
646 struct spidev_data *spidev;
650 spidev = filp->private_data;
653 mutex_lock(&spidev->spi_lock);
655 dofree = (spidev->spi == NULL);
656 mutex_unlock(&spidev->spi_lock);
659 spidev->users--;
660 if (!spidev->users) {
662 kfree(spidev->tx_buffer);
663 spidev->tx_buffer = NULL;
665 kfree(spidev->rx_buffer);
666 spidev->rx_buffer = NULL;
669 kfree(spidev);
671 spidev->speed_hz = spidev->spi->max_speed_hz;
675 spi_slave_abort(spidev->spi);
722 * spidev should never be referenced in DT without a specific compatible string,
727 if (device_property_match_string(dev, "compatible", "spidev") < 0)
730 dev_err(dev, "spidev listed directly in DT is not supported\n");
775 struct spidev_data *spidev;
787 spidev = kzalloc(sizeof(*spidev), GFP_KERNEL);
788 if (!spidev)
792 spidev->spi = spi;
793 mutex_init(&spidev->spi_lock);
794 mutex_init(&spidev->buf_lock);
796 INIT_LIST_HEAD(&spidev->device_entry);
806 spidev->devt = MKDEV(SPIDEV_MAJOR, minor);
807 dev = device_create(spidev_class, &spi->dev, spidev->devt,
808 spidev, "spidev%d.%d",
817 list_add(&spidev->device_entry, &device_list);
821 spidev->speed_hz = spi->max_speed_hz;
824 spi_set_drvdata(spi, spidev);
826 kfree(spidev);
833 struct spidev_data *spidev = spi_get_drvdata(spi);
838 mutex_lock(&spidev->spi_lock);
839 spidev->spi = NULL;
840 mutex_unlock(&spidev->spi_lock);
842 list_del(&spidev->device_entry);
843 device_destroy(spidev_class, spidev->devt);
844 clear_bit(MINOR(spidev->devt), minors);
845 if (spidev->users == 0)
846 kfree(spidev);
852 .name = "spidev",
881 spidev_class = class_create("spidev");
907 MODULE_ALIAS("spi:spidev");