tools/testing/selftests/gpio/gpio-mockup-cdev.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/gpio/gpio-mockup-cdev.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/gpio/gpio-mockup-cdev.c
Extension
.c
Size
4444 bytes
Lines
199
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

switch (opt) {
		case 'l':
			flags_v1 |= GPIOHANDLE_REQUEST_ACTIVE_LOW;
			flags_v2 |= GPIO_V2_LINE_FLAG_ACTIVE_LOW;
			break;
		case 'b':
			if (strcmp("pull-up", optarg) == 0) {
				flags_v1 |= GPIOHANDLE_REQUEST_BIAS_PULL_UP;
				flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_PULL_UP;
			} else if (strcmp("pull-down", optarg) == 0) {
				flags_v1 |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN;
				flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN;
			} else if (strcmp("disabled", optarg) == 0) {
				flags_v1 |= GPIOHANDLE_REQUEST_BIAS_DISABLE;
				flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_DISABLED;
			}
			break;
		case 's':
			val = atoi(optarg);
			flags_v1 &= ~GPIOHANDLE_REQUEST_INPUT;
			flags_v1 |= GPIOHANDLE_REQUEST_OUTPUT;
			flags_v2 &= ~GPIO_V2_LINE_FLAG_INPUT;
			flags_v2 |= GPIO_V2_LINE_FLAG_OUTPUT;
			break;
		case 'u':
			abiv = atoi(optarg);
			break;
		default:
			usage(argv[0]);
		}
	}

	if (argc < optind + 2)
		usage(argv[0]);

	chip = argv[optind];
	offset = atoi(argv[optind + 1]);

	cfd = open(chip, 0);
	if (cfd == -1) {
		fprintf(stderr, "Failed to open %s: %s\n", chip, strerror(errno));
		return -errno;
	}

	if (abiv == 1)
		lfd = request_line_v1(cfd, offset, flags_v1, val);
	else
		lfd = request_line_v2(cfd, offset, flags_v2, val);

	close(cfd);

	if (lfd < 0) {
		fprintf(stderr, "Failed to request %s:%d: %s\n", chip, offset, strerror(-lfd));
		return lfd;
	}

	if (flags_v2 & GPIO_V2_LINE_FLAG_OUTPUT) {
		wait_signal();
	} else {
		if (abiv == 1)
			ret = get_value_v1(lfd);
		else
			ret = get_value_v2(lfd);
	}

	close(lfd);

	return ret;
}

Annotation

Implementation Notes