Commit b6d5be57 authored by Karol Wrona's avatar Karol Wrona Committed by Jonathan Cameron
Browse files

staging: iio: Add notrigger mode for generic_buffer



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: default avatarKarol Wrona <k.wrona@samsung.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 455f0049
Loading
Loading
Loading
Loading
+45 −32
Original line number Diff line number Diff line
@@ -158,11 +158,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;
@@ -183,6 +184,9 @@ int main(int argc, char **argv)
		case 'l':
			buf_len = strtoul(optarg, &dummy, 10);
			break;
		case 'g':
			notrigger = 1;
			break;
		case '?':
			return -1;
		}
@@ -201,11 +205,13 @@ 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 (!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
			 * 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);
@@ -223,6 +229,8 @@ int main(int argc, char **argv)
			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
@@ -246,8 +254,11 @@ int main(int argc, char **argv)
		ret = -ENOMEM;
		goto error_free_triggername;
	}

	if (!notrigger) {
		printf("%s %s\n", dev_dir_name, trigger_name);
	/* Set the device trigger to be the data ready trigger found above */
		/* 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);
@@ -255,6 +266,7 @@ int main(int argc, char **argv)
			printf("Failed to write current_trigger file\n");
			goto error_free_buf_dir_name;
		}
	}

	/* Setup ring buffer parameters */
	ret = write_sysfs_int("length", buf_dir_name, buf_len);
@@ -323,6 +335,7 @@ int main(int argc, char **argv)
	if (ret < 0)
		goto error_close_buffer_access;

	if (!notrigger)
		/* Disconnect the trigger - just write a dummy name. */
		write_sysfs_string("trigger/current_trigger",
				   dev_dir_name, "NULL");