-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 317419 b: refs/heads/master c: 23f2d73 h: refs/heads/master i: 317417: 5348803 317415: e8d004e v: v3
- Loading branch information
Lars-Peter Clausen
authored and
Greg Kroah-Hartman
committed
Jun 19, 2012
1 parent
9d5547a
commit 7f6ea4e
Showing
5 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: f5b81ddd12da71bd00b2963203c23ff929e0c182 | ||
refs/heads/master: 23f2d735a932c7833d2d00da5e3ecdf4a6836210 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* | ||
* Copyright (c) 2012 Analog Devices, Inc. | ||
* Author: Lars-Peter Clausen <lars@metafoo.de> | ||
* | ||
* 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 <linux/kernel.h> | ||
#include <linux/export.h> | ||
#include <linux/module.h> | ||
#include <linux/iio/iio.h> | ||
#include <linux/iio/buffer.h> | ||
#include <linux/iio/kfifo_buf.h> | ||
#include <linux/iio/triggered_buffer.h> | ||
#include <linux/iio/trigger_consumer.h> | ||
|
||
static const struct iio_buffer_setup_ops iio_triggered_buffer_setup_ops = { | ||
.preenable = &iio_sw_buffer_preenable, | ||
.postenable = &iio_triggered_buffer_postenable, | ||
.predisable = &iio_triggered_buffer_predisable, | ||
}; | ||
|
||
/** | ||
* iio_triggered_buffer_setup() - Setup triggered buffer and pollfunc | ||
* @indio_dev: IIO device structure | ||
* @pollfunc_bh: Function which will be used as pollfunc bottom half | ||
* @pollfunc_th: Function which will be used as pollfunc top half | ||
* @setup_ops: Buffer setup functions to use for this device. | ||
* If NULL the default setup functions for triggered | ||
* buffers will be used. | ||
* | ||
* This function combines some common tasks which will normally be performed | ||
* when setting up a triggered buffer. It will allocate the buffer and the | ||
* pollfunc, as well as register the buffer with the IIO core. | ||
* | ||
* Before calling this function the indio_dev structure should already be | ||
* completely initialized, but not yet registered. In practice this means that | ||
* this function should be called right before iio_device_register(). | ||
* | ||
* To free the resources allocated by this function call | ||
* iio_triggered_buffer_cleanup(). | ||
*/ | ||
int iio_triggered_buffer_setup(struct iio_dev *indio_dev, | ||
irqreturn_t (*pollfunc_bh)(int irq, void *p), | ||
irqreturn_t (*pollfunc_th)(int irq, void *p), | ||
const struct iio_buffer_setup_ops *setup_ops) | ||
{ | ||
int ret; | ||
|
||
indio_dev->buffer = iio_kfifo_allocate(indio_dev); | ||
if (!indio_dev->buffer) { | ||
ret = -ENOMEM; | ||
goto error_ret; | ||
} | ||
|
||
indio_dev->pollfunc = iio_alloc_pollfunc(pollfunc_bh, | ||
pollfunc_th, | ||
IRQF_ONESHOT, | ||
indio_dev, | ||
"%s_consumer%d", | ||
indio_dev->name, | ||
indio_dev->id); | ||
if (indio_dev->pollfunc == NULL) { | ||
ret = -ENOMEM; | ||
goto error_kfifo_free; | ||
} | ||
|
||
/* Ring buffer functions - here trigger setup related */ | ||
if (setup_ops) | ||
indio_dev->setup_ops = setup_ops; | ||
else | ||
indio_dev->setup_ops = &iio_triggered_buffer_setup_ops; | ||
|
||
/* Flag that polled ring buffering is possible */ | ||
indio_dev->modes |= INDIO_BUFFER_TRIGGERED; | ||
|
||
ret = iio_buffer_register(indio_dev, | ||
indio_dev->channels, | ||
indio_dev->num_channels); | ||
if (ret) | ||
goto error_dealloc_pollfunc; | ||
|
||
return 0; | ||
|
||
error_dealloc_pollfunc: | ||
iio_dealloc_pollfunc(indio_dev->pollfunc); | ||
error_kfifo_free: | ||
iio_kfifo_free(indio_dev->buffer); | ||
error_ret: | ||
return ret; | ||
} | ||
EXPORT_SYMBOL(iio_triggered_buffer_setup); | ||
|
||
/** | ||
* iio_triggered_buffer_cleanup() - Free resources allocated by iio_triggered_buffer_setup() | ||
* @indio_dev: IIO device structure | ||
*/ | ||
void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev) | ||
{ | ||
iio_buffer_unregister(indio_dev); | ||
iio_dealloc_pollfunc(indio_dev->pollfunc); | ||
iio_kfifo_free(indio_dev->buffer); | ||
} | ||
EXPORT_SYMBOL(iio_triggered_buffer_cleanup); | ||
|
||
MODULE_AUTHOR("Lars-Peter Clausen <lars@metafoo.de>"); | ||
MODULE_DESCRIPTION("IIO helper functions for setting up triggered buffers"); | ||
MODULE_LICENSE("GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef _LINUX_IIO_TRIGGERED_BUFFER_H_ | ||
#define _LINUX_IIO_TRIGGERED_BUFFER_H_ | ||
|
||
#include <linux/interrupt.h> | ||
|
||
struct iio_dev; | ||
struct iio_buffer_setup_ops; | ||
|
||
int iio_triggered_buffer_setup(struct iio_dev *indio_dev, | ||
irqreturn_t (*pollfunc_bh)(int irq, void *p), | ||
irqreturn_t (*pollfunc_th)(int irq, void *p), | ||
const struct iio_buffer_setup_ops *setup_ops); | ||
void iio_triggered_buffer_cleanup(struct iio_dev *indio_dev); | ||
|
||
#endif |