Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iio: Add buffer enable/disable callbacks

This patch adds a enable and disable callback that is called when the
buffer is enabled/disabled. This can be used by buffer implementations that
need to do some setup or teardown work. E.g. a DMA based buffer can use
this to start/stop the DMA transfer.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Lars-Peter Clausen and committed by
Jonathan Cameron
e18a2ad4 b440655b

+43 -1
+35 -1
drivers/iio/industrialio-buffer.c
··· 568 568 iio_buffer_deactivate(buffer); 569 569 } 570 570 571 + static int iio_buffer_enable(struct iio_buffer *buffer, 572 + struct iio_dev *indio_dev) 573 + { 574 + if (!buffer->access->enable) 575 + return 0; 576 + return buffer->access->enable(buffer, indio_dev); 577 + } 578 + 579 + static int iio_buffer_disable(struct iio_buffer *buffer, 580 + struct iio_dev *indio_dev) 581 + { 582 + if (!buffer->access->disable) 583 + return 0; 584 + return buffer->access->disable(buffer, indio_dev); 585 + } 586 + 571 587 static void iio_buffer_update_bytes_per_datum(struct iio_dev *indio_dev, 572 588 struct iio_buffer *buffer) 573 589 { ··· 735 719 static int iio_enable_buffers(struct iio_dev *indio_dev, 736 720 struct iio_device_config *config) 737 721 { 722 + struct iio_buffer *buffer; 738 723 int ret; 739 724 740 725 indio_dev->active_scan_mask = config->scan_mask; ··· 770 753 indio_dev->info->hwfifo_set_watermark(indio_dev, 771 754 config->watermark); 772 755 756 + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) { 757 + ret = iio_buffer_enable(buffer, indio_dev); 758 + if (ret) 759 + goto err_disable_buffers; 760 + } 761 + 773 762 indio_dev->currentmode = config->mode; 774 763 775 764 if (indio_dev->setup_ops->postenable) { ··· 783 760 if (ret) { 784 761 dev_dbg(&indio_dev->dev, 785 762 "Buffer not started: postenable failed (%d)\n", ret); 786 - goto err_run_postdisable; 763 + goto err_disable_buffers; 787 764 } 788 765 } 789 766 790 767 return 0; 791 768 769 + err_disable_buffers: 770 + list_for_each_entry_continue_reverse(buffer, &indio_dev->buffer_list, 771 + buffer_list) 772 + iio_buffer_disable(buffer, indio_dev); 792 773 err_run_postdisable: 793 774 indio_dev->currentmode = INDIO_DIRECT_MODE; 794 775 if (indio_dev->setup_ops->postdisable) ··· 805 778 806 779 static int iio_disable_buffers(struct iio_dev *indio_dev) 807 780 { 781 + struct iio_buffer *buffer; 808 782 int ret = 0; 809 783 int ret2; 810 784 ··· 822 794 823 795 if (indio_dev->setup_ops->predisable) { 824 796 ret2 = indio_dev->setup_ops->predisable(indio_dev); 797 + if (ret2 && !ret) 798 + ret = ret2; 799 + } 800 + 801 + list_for_each_entry(buffer, &indio_dev->buffer_list, buffer_list) { 802 + ret2 = iio_buffer_disable(buffer, indio_dev); 825 803 if (ret2 && !ret) 826 804 ret = ret2; 827 805 }
+8
include/linux/iio/buffer.h
··· 33 33 * storage. 34 34 * @set_bytes_per_datum:set number of bytes per datum 35 35 * @set_length: set number of datums in buffer 36 + * @enable: called if the buffer is attached to a device and the 37 + * device starts sampling. Calls are balanced with 38 + * @disable. 39 + * @disable: called if the buffer is attached to a device and the 40 + * device stops sampling. Calles are balanced with @enable. 36 41 * @release: called when the last reference to the buffer is dropped, 37 42 * should free all resources allocated by the buffer. 38 43 * @modes: Supported operating modes by this buffer type ··· 62 57 63 58 int (*set_bytes_per_datum)(struct iio_buffer *buffer, size_t bpd); 64 59 int (*set_length)(struct iio_buffer *buffer, int length); 60 + 61 + int (*enable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); 62 + int (*disable)(struct iio_buffer *buffer, struct iio_dev *indio_dev); 65 63 66 64 void (*release)(struct iio_buffer *buffer); 67 65