linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/1] staging: iio: Add notrigger mode for generic_buffer
@ 2014-11-04 14:29 Karol Wrona
  2014-11-04 14:29 ` [PATCH 1/1] " Karol Wrona
  0 siblings, 1 reply; 3+ messages in thread
From: Karol Wrona @ 2014-11-04 14:29 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, linux-iio
  Cc: Kyungmin Park, Bartlomiej Zolnierkiewicz, Karol Wrona

Hello,

Sometimes it is hard to test IIO device with no triggers at all.
This patch adds "-g" option which allows to use generic_buffer app
without bothering about triggers.

Thanks,
Karol

Karol Wrona (1):
  staging: iio: Add notrigger mode for generic_buffer

 drivers/staging/iio/Documentation/generic_buffer.c |   77 ++++++++++++--------
 1 file changed, 45 insertions(+), 32 deletions(-)

-- 
1.7.9.5


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH 1/1] staging: iio: Add notrigger mode for generic_buffer
  2014-11-04 14:29 [PATCH 0/1] staging: iio: Add notrigger mode for generic_buffer Karol Wrona
@ 2014-11-04 14:29 ` Karol Wrona
  2014-11-05 14:44   ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Karol Wrona @ 2014-11-04 14:29 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, linux-iio
  Cc: Kyungmin Park, Bartlomiej Zolnierkiewicz, Karol Wrona

Some IIO devices do not use the triggers. This patch makes trigger setting
conditional so generic_buffer can be used when triggers are disabled.

Signed-off-by: Karol Wrona <k.wrona@samsung.com>
---
 drivers/staging/iio/Documentation/generic_buffer.c |   77 ++++++++++++--------
 1 file changed, 45 insertions(+), 32 deletions(-)

diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c
index 31dfb21..de4647e 100644
--- a/drivers/staging/iio/Documentation/generic_buffer.c
+++ b/drivers/staging/iio/Documentation/generic_buffer.c
@@ -162,11 +162,12 @@ int main(int argc, char **argv)
 	char *buffer_access;
 	int scan_size;
 	int noevents = 0;
+	int notrigger = 0;
 	char *dummy;
 
 	struct iio_channel_info *channels;
 
-	while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) {
+	while ((c = getopt(argc, argv, "l:w:c:et:n:g")) != -1) {
 		switch (c) {
 		case 'n':
 			device_name = optarg;
@@ -187,6 +188,9 @@ int main(int argc, char **argv)
 		case 'l':
 			buf_len = strtoul(optarg, &dummy, 10);
 			break;
+		case 'g':
+			notrigger = 1;
+			break;
 		case '?':
 			return -1;
 		}
@@ -205,28 +209,32 @@ int main(int argc, char **argv)
 	printf("iio device number being used is %d\n", dev_num);
 
 	asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
-	if (trigger_name == NULL) {
-		/*
-		 * Build the trigger name. If it is device associated its
-		 * name is <device_name>_dev[n] where n matches the device
-		 * number found above
-		 */
-		ret = asprintf(&trigger_name,
-			       "%s-dev%d", device_name, dev_num);
-		if (ret < 0) {
-			ret = -ENOMEM;
-			goto error_ret;
+
+	if (!notrigger) {
+		if (trigger_name == NULL) {
+			/*
+			 * Build the trigger name. If it is device associated
+			 * its name is <device_name>_dev[n] where n matches
+			 * the device number found above.
+			 */
+			ret = asprintf(&trigger_name,
+				       "%s-dev%d", device_name, dev_num);
+			if (ret < 0) {
+				ret = -ENOMEM;
+				goto error_ret;
+			}
 		}
-	}
 
-	/* Verify the trigger exists */
-	trig_num = find_type_by_name(trigger_name, "trigger");
-	if (trig_num < 0) {
-		printf("Failed to find the trigger %s\n", trigger_name);
-		ret = -ENODEV;
-		goto error_free_triggername;
-	}
-	printf("iio trigger number being used is %d\n", trig_num);
+		/* Verify the trigger exists */
+		trig_num = find_type_by_name(trigger_name, "trigger");
+		if (trig_num < 0) {
+			printf("Failed to find the trigger %s\n", trigger_name);
+			ret = -ENODEV;
+			goto error_free_triggername;
+		}
+		printf("iio trigger number being used is %d\n", trig_num);
+	} else
+		printf("trigger-less mode selected\n");
 
 	/*
 	 * Parse the files in scan_elements to identify what channels are
@@ -250,14 +258,18 @@ int main(int argc, char **argv)
 		ret = -ENOMEM;
 		goto error_free_triggername;
 	}
-	printf("%s %s\n", dev_dir_name, trigger_name);
-	/* Set the device trigger to be the data ready trigger found above */
-	ret = write_sysfs_string_and_verify("trigger/current_trigger",
-					dev_dir_name,
-					trigger_name);
-	if (ret < 0) {
-		printf("Failed to write current_trigger file\n");
-		goto error_free_buf_dir_name;
+
+	if (!notrigger) {
+		printf("%s %s\n", dev_dir_name, trigger_name);
+		/* Set the device trigger to be the data ready trigger found
+		 * above */
+		ret = write_sysfs_string_and_verify("trigger/current_trigger",
+						    dev_dir_name,
+						    trigger_name);
+		if (ret < 0) {
+			printf("Failed to write current_trigger file\n");
+			goto error_free_buf_dir_name;
+		}
 	}
 
 	/* Setup ring buffer parameters */
@@ -327,9 +339,10 @@ int main(int argc, char **argv)
 	if (ret < 0)
 		goto error_close_buffer_access;
 
-	/* Disconnect the trigger - just write a dummy name. */
-	write_sysfs_string("trigger/current_trigger",
-			dev_dir_name, "NULL");
+	if (!notrigger)
+		/* Disconnect the trigger - just write a dummy name. */
+		write_sysfs_string("trigger/current_trigger",
+				   dev_dir_name, "NULL");
 
 error_close_buffer_access:
 	close(fp);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] staging: iio: Add notrigger mode for generic_buffer
  2014-11-04 14:29 ` [PATCH 1/1] " Karol Wrona
@ 2014-11-05 14:44   ` Jonathan Cameron
  0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2014-11-05 14:44 UTC (permalink / raw)
  To: Karol Wrona, Hartmut Knaack, linux-iio
  Cc: Kyungmin Park, Bartlomiej Zolnierkiewicz

On 04/11/14 14:29, Karol Wrona wrote:
> Some IIO devices do not use the triggers. This patch makes trigger setting
> conditional so generic_buffer can be used when triggers are disabled.
>
> Signed-off-by: Karol Wrona <k.wrona@samsung.com>
Been meaning to add this for a while!  Thanks for doing it.

Applied to the togreg branch of iio.git - initially pushed out as testing.

Thanks

Jonathan
> ---
>  drivers/staging/iio/Documentation/generic_buffer.c |   77 ++++++++++++--------
>  1 file changed, 45 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/staging/iio/Documentation/generic_buffer.c b/drivers/staging/iio/Documentation/generic_buffer.c
> index 31dfb21..de4647e 100644
> --- a/drivers/staging/iio/Documentation/generic_buffer.c
> +++ b/drivers/staging/iio/Documentation/generic_buffer.c
> @@ -162,11 +162,12 @@ int main(int argc, char **argv)
>  	char *buffer_access;
>  	int scan_size;
>  	int noevents = 0;
> +	int notrigger = 0;
>  	char *dummy;
>
>  	struct iio_channel_info *channels;
>
> -	while ((c = getopt(argc, argv, "l:w:c:et:n:")) != -1) {
> +	while ((c = getopt(argc, argv, "l:w:c:et:n:g")) != -1) {
>  		switch (c) {
>  		case 'n':
>  			device_name = optarg;
> @@ -187,6 +188,9 @@ int main(int argc, char **argv)
>  		case 'l':
>  			buf_len = strtoul(optarg, &dummy, 10);
>  			break;
> +		case 'g':
> +			notrigger = 1;
> +			break;
>  		case '?':
>  			return -1;
>  		}
> @@ -205,28 +209,32 @@ int main(int argc, char **argv)
>  	printf("iio device number being used is %d\n", dev_num);
>
>  	asprintf(&dev_dir_name, "%siio:device%d", iio_dir, dev_num);
> -	if (trigger_name == NULL) {
> -		/*
> -		 * Build the trigger name. If it is device associated its
> -		 * name is <device_name>_dev[n] where n matches the device
> -		 * number found above
> -		 */
> -		ret = asprintf(&trigger_name,
> -			       "%s-dev%d", device_name, dev_num);
> -		if (ret < 0) {
> -			ret = -ENOMEM;
> -			goto error_ret;
> +
> +	if (!notrigger) {
> +		if (trigger_name == NULL) {
> +			/*
> +			 * Build the trigger name. If it is device associated
> +			 * its name is <device_name>_dev[n] where n matches
> +			 * the device number found above.
> +			 */
> +			ret = asprintf(&trigger_name,
> +				       "%s-dev%d", device_name, dev_num);
> +			if (ret < 0) {
> +				ret = -ENOMEM;
> +				goto error_ret;
> +			}
>  		}
> -	}
>
> -	/* Verify the trigger exists */
> -	trig_num = find_type_by_name(trigger_name, "trigger");
> -	if (trig_num < 0) {
> -		printf("Failed to find the trigger %s\n", trigger_name);
> -		ret = -ENODEV;
> -		goto error_free_triggername;
> -	}
> -	printf("iio trigger number being used is %d\n", trig_num);
> +		/* Verify the trigger exists */
> +		trig_num = find_type_by_name(trigger_name, "trigger");
> +		if (trig_num < 0) {
> +			printf("Failed to find the trigger %s\n", trigger_name);
> +			ret = -ENODEV;
> +			goto error_free_triggername;
> +		}
> +		printf("iio trigger number being used is %d\n", trig_num);
> +	} else
> +		printf("trigger-less mode selected\n");
>
>  	/*
>  	 * Parse the files in scan_elements to identify what channels are
> @@ -250,14 +258,18 @@ int main(int argc, char **argv)
>  		ret = -ENOMEM;
>  		goto error_free_triggername;
>  	}
> -	printf("%s %s\n", dev_dir_name, trigger_name);
> -	/* Set the device trigger to be the data ready trigger found above */
> -	ret = write_sysfs_string_and_verify("trigger/current_trigger",
> -					dev_dir_name,
> -					trigger_name);
> -	if (ret < 0) {
> -		printf("Failed to write current_trigger file\n");
> -		goto error_free_buf_dir_name;
> +
> +	if (!notrigger) {
> +		printf("%s %s\n", dev_dir_name, trigger_name);
> +		/* Set the device trigger to be the data ready trigger found
> +		 * above */
> +		ret = write_sysfs_string_and_verify("trigger/current_trigger",
> +						    dev_dir_name,
> +						    trigger_name);
> +		if (ret < 0) {
> +			printf("Failed to write current_trigger file\n");
> +			goto error_free_buf_dir_name;
> +		}
>  	}
>
>  	/* Setup ring buffer parameters */
> @@ -327,9 +339,10 @@ int main(int argc, char **argv)
>  	if (ret < 0)
>  		goto error_close_buffer_access;
>
> -	/* Disconnect the trigger - just write a dummy name. */
> -	write_sysfs_string("trigger/current_trigger",
> -			dev_dir_name, "NULL");
> +	if (!notrigger)
> +		/* Disconnect the trigger - just write a dummy name. */
> +		write_sysfs_string("trigger/current_trigger",
> +				   dev_dir_name, "NULL");
>
>  error_close_buffer_access:
>  	close(fp);
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-11-05 14:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-04 14:29 [PATCH 0/1] staging: iio: Add notrigger mode for generic_buffer Karol Wrona
2014-11-04 14:29 ` [PATCH 1/1] " Karol Wrona
2014-11-05 14:44   ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).