aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-core.c
diff options
context:
space:
mode:
authorAlison Schofield <amsfield22@gmail.com>2016-03-09 14:30:12 -0500
committerJonathan Cameron <jic23@kernel.org>2016-03-12 06:17:19 -0500
commit08a33805518e7845486f88287e8aace6f8439391 (patch)
treeb1eccda86f0d406bcd95f24c7c234220ee5d408d /drivers/iio/industrialio-core.c
parente8731180fbf6fd45351b587d67cdc0685ce99a7a (diff)
iio: core: implement iio_device_{claim|release}_direct_mode()
It is often the case that the driver wants to be sure a device stays in direct mode while it is executing a task or series of tasks. To accomplish this today, the driver performs this sequence: 1) take the device state lock, 2) verify it is not in a buffered mode, 3) execute some tasks, and 4) release that lock. This patch introduces a pair of helper functions that simplify these steps and make it more semantically expressive. iio_device_claim_direct_mode() If the device is not in any buffered mode it is guaranteed to stay that way until iio_release_direct_mode() is called. iio_device_release_direct_mode() Release the claim. Device is no longer guaranteed to stay in direct mode. Signed-off-by: Alison Schofield <amsfield22@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/industrialio-core.c')
-rw-r--r--drivers/iio/industrialio-core.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index 70cb7eb0a75c..2e768bc99f05 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -25,6 +25,7 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/anon_inodes.h> 26#include <linux/anon_inodes.h>
27#include <linux/debugfs.h> 27#include <linux/debugfs.h>
28#include <linux/mutex.h>
28#include <linux/iio/iio.h> 29#include <linux/iio/iio.h>
29#include "iio_core.h" 30#include "iio_core.h"
30#include "iio_core_trigger.h" 31#include "iio_core_trigger.h"
@@ -1375,6 +1376,44 @@ void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
1375} 1376}
1376EXPORT_SYMBOL_GPL(devm_iio_device_unregister); 1377EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
1377 1378
1379/**
1380 * iio_device_claim_direct_mode - Keep device in direct mode
1381 * @indio_dev: the iio_dev associated with the device
1382 *
1383 * If the device is in direct mode it is guaranteed to stay
1384 * that way until iio_device_release_direct_mode() is called.
1385 *
1386 * Use with iio_device_release_direct_mode()
1387 *
1388 * Returns: 0 on success, -EBUSY on failure
1389 */
1390int iio_device_claim_direct_mode(struct iio_dev *indio_dev)
1391{
1392 mutex_lock(&indio_dev->mlock);
1393
1394 if (iio_buffer_enabled(indio_dev)) {
1395 mutex_unlock(&indio_dev->mlock);
1396 return -EBUSY;
1397 }
1398 return 0;
1399}
1400EXPORT_SYMBOL_GPL(iio_device_claim_direct_mode);
1401
1402/**
1403 * iio_device_release_direct_mode - releases claim on direct mode
1404 * @indio_dev: the iio_dev associated with the device
1405 *
1406 * Release the claim. Device is no longer guaranteed to stay
1407 * in direct mode.
1408 *
1409 * Use with iio_device_claim_direct_mode()
1410 */
1411void iio_device_release_direct_mode(struct iio_dev *indio_dev)
1412{
1413 mutex_unlock(&indio_dev->mlock);
1414}
1415EXPORT_SYMBOL_GPL(iio_device_release_direct_mode);
1416
1378subsys_initcall(iio_init); 1417subsys_initcall(iio_init);
1379module_exit(iio_exit); 1418module_exit(iio_exit);
1380 1419