From: Lars-Peter Clausen Date: Fri, 14 Aug 2015 14:54:54 +0000 (+0200) Subject: iio: Move callback buffer to its own module X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=050ee2f16e245b42c9ba30640bb91b309b424c48;p=GitHub%2Fmoto-9609%2Fandroid_kernel_motorola_exynos9610.git iio: Move callback buffer to its own module Currently the IIO callback buffer implementation is directly built into the IIO core module when enabled. Given that the callback buffer module is standalone functionallity there is really no reason to do this. So move it to its own module. Also rename the source to follow the standard IIO module naming convention as well as add a license notice to the file. Signed-off-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig index 4011effe4c05..b52c8a3b1360 100644 --- a/drivers/iio/Kconfig +++ b/drivers/iio/Kconfig @@ -21,7 +21,7 @@ config IIO_BUFFER if IIO_BUFFER config IIO_BUFFER_CB - bool "IIO callback buffer used for push in-kernel interfaces" + tristate "IIO callback buffer used for push in-kernel interfaces" help Should be selected by any drivers that do in-kernel push usage. That is, those where the data is pushed to the consumer. diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile index 698afc2d17ce..09d8ec5d57d8 100644 --- a/drivers/iio/Makefile +++ b/drivers/iio/Makefile @@ -6,8 +6,8 @@ obj-$(CONFIG_IIO) += industrialio.o industrialio-y := industrialio-core.o industrialio-event.o inkern.o industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o -industrialio-$(CONFIG_IIO_BUFFER_CB) += buffer_cb.o +obj-$(CONFIG_IIO_BUFFER_CB) += industrialio-buffer-cb.o obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o diff --git a/drivers/iio/buffer_cb.c b/drivers/iio/buffer_cb.c deleted file mode 100644 index 1648e6e5a848..000000000000 --- a/drivers/iio/buffer_cb.c +++ /dev/null @@ -1,126 +0,0 @@ -#include -#include -#include -#include -#include -#include - -struct iio_cb_buffer { - struct iio_buffer buffer; - int (*cb)(const void *data, void *private); - void *private; - struct iio_channel *channels; -}; - -static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer) -{ - return container_of(buffer, struct iio_cb_buffer, buffer); -} - -static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data) -{ - struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); - return cb_buff->cb(data, cb_buff->private); -} - -static void iio_buffer_cb_release(struct iio_buffer *buffer) -{ - struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); - kfree(cb_buff->buffer.scan_mask); - kfree(cb_buff); -} - -static const struct iio_buffer_access_funcs iio_cb_access = { - .store_to = &iio_buffer_cb_store_to, - .release = &iio_buffer_cb_release, - - .modes = INDIO_BUFFER_SOFTWARE | INDIO_BUFFER_TRIGGERED, -}; - -struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, - int (*cb)(const void *data, - void *private), - void *private) -{ - int ret; - struct iio_cb_buffer *cb_buff; - struct iio_dev *indio_dev; - struct iio_channel *chan; - - cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL); - if (cb_buff == NULL) - return ERR_PTR(-ENOMEM); - - iio_buffer_init(&cb_buff->buffer); - - cb_buff->private = private; - cb_buff->cb = cb; - cb_buff->buffer.access = &iio_cb_access; - INIT_LIST_HEAD(&cb_buff->buffer.demux_list); - - cb_buff->channels = iio_channel_get_all(dev); - if (IS_ERR(cb_buff->channels)) { - ret = PTR_ERR(cb_buff->channels); - goto error_free_cb_buff; - } - - indio_dev = cb_buff->channels[0].indio_dev; - cb_buff->buffer.scan_mask - = kcalloc(BITS_TO_LONGS(indio_dev->masklength), sizeof(long), - GFP_KERNEL); - if (cb_buff->buffer.scan_mask == NULL) { - ret = -ENOMEM; - goto error_release_channels; - } - chan = &cb_buff->channels[0]; - while (chan->indio_dev) { - if (chan->indio_dev != indio_dev) { - ret = -EINVAL; - goto error_free_scan_mask; - } - set_bit(chan->channel->scan_index, - cb_buff->buffer.scan_mask); - chan++; - } - - return cb_buff; - -error_free_scan_mask: - kfree(cb_buff->buffer.scan_mask); -error_release_channels: - iio_channel_release_all(cb_buff->channels); -error_free_cb_buff: - kfree(cb_buff); - return ERR_PTR(ret); -} -EXPORT_SYMBOL_GPL(iio_channel_get_all_cb); - -int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff) -{ - return iio_update_buffers(cb_buff->channels[0].indio_dev, - &cb_buff->buffer, - NULL); -} -EXPORT_SYMBOL_GPL(iio_channel_start_all_cb); - -void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff) -{ - iio_update_buffers(cb_buff->channels[0].indio_dev, - NULL, - &cb_buff->buffer); -} -EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb); - -void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buff) -{ - iio_channel_release_all(cb_buff->channels); - iio_buffer_put(&cb_buff->buffer); -} -EXPORT_SYMBOL_GPL(iio_channel_release_all_cb); - -struct iio_channel -*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer) -{ - return cb_buffer->channels; -} -EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels); diff --git a/drivers/iio/industrialio-buffer-cb.c b/drivers/iio/industrialio-buffer-cb.c new file mode 100644 index 000000000000..323079c3ccce --- /dev/null +++ b/drivers/iio/industrialio-buffer-cb.c @@ -0,0 +1,138 @@ +/* The industrial I/O callback buffer + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 as published by + * the Free Software Foundation. + */ + +#include +#include +#include +#include +#include +#include +#include + +struct iio_cb_buffer { + struct iio_buffer buffer; + int (*cb)(const void *data, void *private); + void *private; + struct iio_channel *channels; +}; + +static struct iio_cb_buffer *buffer_to_cb_buffer(struct iio_buffer *buffer) +{ + return container_of(buffer, struct iio_cb_buffer, buffer); +} + +static int iio_buffer_cb_store_to(struct iio_buffer *buffer, const void *data) +{ + struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); + return cb_buff->cb(data, cb_buff->private); +} + +static void iio_buffer_cb_release(struct iio_buffer *buffer) +{ + struct iio_cb_buffer *cb_buff = buffer_to_cb_buffer(buffer); + kfree(cb_buff->buffer.scan_mask); + kfree(cb_buff); +} + +static const struct iio_buffer_access_funcs iio_cb_access = { + .store_to = &iio_buffer_cb_store_to, + .release = &iio_buffer_cb_release, + + .modes = INDIO_BUFFER_SOFTWARE | INDIO_BUFFER_TRIGGERED, +}; + +struct iio_cb_buffer *iio_channel_get_all_cb(struct device *dev, + int (*cb)(const void *data, + void *private), + void *private) +{ + int ret; + struct iio_cb_buffer *cb_buff; + struct iio_dev *indio_dev; + struct iio_channel *chan; + + cb_buff = kzalloc(sizeof(*cb_buff), GFP_KERNEL); + if (cb_buff == NULL) + return ERR_PTR(-ENOMEM); + + iio_buffer_init(&cb_buff->buffer); + + cb_buff->private = private; + cb_buff->cb = cb; + cb_buff->buffer.access = &iio_cb_access; + INIT_LIST_HEAD(&cb_buff->buffer.demux_list); + + cb_buff->channels = iio_channel_get_all(dev); + if (IS_ERR(cb_buff->channels)) { + ret = PTR_ERR(cb_buff->channels); + goto error_free_cb_buff; + } + + indio_dev = cb_buff->channels[0].indio_dev; + cb_buff->buffer.scan_mask + = kcalloc(BITS_TO_LONGS(indio_dev->masklength), sizeof(long), + GFP_KERNEL); + if (cb_buff->buffer.scan_mask == NULL) { + ret = -ENOMEM; + goto error_release_channels; + } + chan = &cb_buff->channels[0]; + while (chan->indio_dev) { + if (chan->indio_dev != indio_dev) { + ret = -EINVAL; + goto error_free_scan_mask; + } + set_bit(chan->channel->scan_index, + cb_buff->buffer.scan_mask); + chan++; + } + + return cb_buff; + +error_free_scan_mask: + kfree(cb_buff->buffer.scan_mask); +error_release_channels: + iio_channel_release_all(cb_buff->channels); +error_free_cb_buff: + kfree(cb_buff); + return ERR_PTR(ret); +} +EXPORT_SYMBOL_GPL(iio_channel_get_all_cb); + +int iio_channel_start_all_cb(struct iio_cb_buffer *cb_buff) +{ + return iio_update_buffers(cb_buff->channels[0].indio_dev, + &cb_buff->buffer, + NULL); +} +EXPORT_SYMBOL_GPL(iio_channel_start_all_cb); + +void iio_channel_stop_all_cb(struct iio_cb_buffer *cb_buff) +{ + iio_update_buffers(cb_buff->channels[0].indio_dev, + NULL, + &cb_buff->buffer); +} +EXPORT_SYMBOL_GPL(iio_channel_stop_all_cb); + +void iio_channel_release_all_cb(struct iio_cb_buffer *cb_buff) +{ + iio_channel_release_all(cb_buff->channels); + iio_buffer_put(&cb_buff->buffer); +} +EXPORT_SYMBOL_GPL(iio_channel_release_all_cb); + +struct iio_channel +*iio_channel_cb_get_channels(const struct iio_cb_buffer *cb_buffer) +{ + return cb_buffer->channels; +} +EXPORT_SYMBOL_GPL(iio_channel_cb_get_channels); + +MODULE_AUTHOR("Jonathan Cameron "); +MODULE_DESCRIPTION("Industrial I/O callback buffer"); +MODULE_LICENSE("GPL");