Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: gpio: port to GPIO uAPI v2

Add a port to the GPIO uAPI v2 interface and make it the default.

Signed-off-by: Kent Gibson <warthog618@gmail.com>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>

authored by

Kent Gibson and committed by
Bartosz Golaszewski
10f33652 ef0d6d97

+76 -10
+67 -8
tools/testing/selftests/gpio/gpio-mockup-cdev.c
··· 18 18 19 19 #define CONSUMER "gpio-mockup-cdev" 20 20 21 + static int request_line_v2(int cfd, unsigned int offset, 22 + uint64_t flags, unsigned int val) 23 + { 24 + struct gpio_v2_line_request req; 25 + int ret; 26 + 27 + memset(&req, 0, sizeof(req)); 28 + req.num_lines = 1; 29 + req.offsets[0] = offset; 30 + req.config.flags = flags; 31 + strcpy(req.consumer, CONSUMER); 32 + if (flags & GPIO_V2_LINE_FLAG_OUTPUT) { 33 + req.config.num_attrs = 1; 34 + req.config.attrs[0].mask = 1; 35 + req.config.attrs[0].attr.id = GPIO_V2_LINE_ATTR_ID_OUTPUT_VALUES; 36 + if (val) 37 + req.config.attrs[0].attr.values = 1; 38 + } 39 + ret = ioctl(cfd, GPIO_V2_GET_LINE_IOCTL, &req); 40 + if (ret == -1) 41 + return -errno; 42 + return req.fd; 43 + } 44 + 45 + 46 + static int get_value_v2(int lfd) 47 + { 48 + struct gpio_v2_line_values vals; 49 + int ret; 50 + 51 + memset(&vals, 0, sizeof(vals)); 52 + vals.mask = 1; 53 + ret = ioctl(lfd, GPIO_V2_LINE_GET_VALUES_IOCTL, &vals); 54 + if (ret == -1) 55 + return -errno; 56 + return vals.bits & 0x1; 57 + } 58 + 21 59 static int request_line_v1(int cfd, unsigned int offset, 22 60 uint32_t flags, unsigned int val) 23 61 { ··· 95 57 printf(" (default is to leave bias unchanged):\n"); 96 58 printf(" -l: set line active low (default is active high)\n"); 97 59 printf(" -s: set line value (default is to get line value)\n"); 60 + printf(" -u: uAPI version to use (default is 2)\n"); 98 61 exit(-1); 99 62 } 100 63 ··· 117 78 { 118 79 char *chip; 119 80 int opt, ret, cfd, lfd; 120 - unsigned int offset, val; 81 + unsigned int offset, val, abiv; 121 82 uint32_t flags_v1; 83 + uint64_t flags_v2; 122 84 85 + abiv = 2; 123 86 ret = 0; 124 87 flags_v1 = GPIOHANDLE_REQUEST_INPUT; 88 + flags_v2 = GPIO_V2_LINE_FLAG_INPUT; 125 89 126 90 while ((opt = getopt(argc, argv, "lb:s:u:")) != -1) { 127 91 switch (opt) { 128 92 case 'l': 129 93 flags_v1 |= GPIOHANDLE_REQUEST_ACTIVE_LOW; 94 + flags_v2 |= GPIO_V2_LINE_FLAG_ACTIVE_LOW; 130 95 break; 131 96 case 'b': 132 - if (strcmp("pull-up", optarg) == 0) 97 + if (strcmp("pull-up", optarg) == 0) { 133 98 flags_v1 |= GPIOHANDLE_REQUEST_BIAS_PULL_UP; 134 - else if (strcmp("pull-down", optarg) == 0) 99 + flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_PULL_UP; 100 + } else if (strcmp("pull-down", optarg) == 0) { 135 101 flags_v1 |= GPIOHANDLE_REQUEST_BIAS_PULL_DOWN; 136 - else if (strcmp("disabled", optarg) == 0) 102 + flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN; 103 + } else if (strcmp("disabled", optarg) == 0) { 137 104 flags_v1 |= GPIOHANDLE_REQUEST_BIAS_DISABLE; 105 + flags_v2 |= GPIO_V2_LINE_FLAG_BIAS_DISABLED; 106 + } 138 107 break; 139 108 case 's': 140 109 val = atoi(optarg); 141 110 flags_v1 &= ~GPIOHANDLE_REQUEST_INPUT; 142 111 flags_v1 |= GPIOHANDLE_REQUEST_OUTPUT; 112 + flags_v2 &= ~GPIO_V2_LINE_FLAG_INPUT; 113 + flags_v2 |= GPIO_V2_LINE_FLAG_OUTPUT; 114 + break; 115 + case 'u': 116 + abiv = atoi(optarg); 143 117 break; 144 118 default: 145 119 usage(argv[0]); ··· 171 119 return -errno; 172 120 } 173 121 174 - lfd = request_line_v1(cfd, offset, flags_v1, val); 122 + if (abiv == 1) 123 + lfd = request_line_v1(cfd, offset, flags_v1, val); 124 + else 125 + lfd = request_line_v2(cfd, offset, flags_v2, val); 175 126 176 127 close(cfd); 177 128 ··· 183 128 return lfd; 184 129 } 185 130 186 - if (flags_v1 & GPIOHANDLE_REQUEST_OUTPUT) 131 + if (flags_v2 & GPIO_V2_LINE_FLAG_OUTPUT) { 187 132 wait_signal(); 188 - else 189 - ret = get_value_v1(lfd); 133 + } else { 134 + if (abiv == 1) 135 + ret = get_value_v1(lfd); 136 + else 137 + ret = get_value_v2(lfd); 138 + } 190 139 191 140 close(lfd); 192 141
+9 -2
tools/testing/selftests/gpio/gpio-mockup.sh
··· 14 14 verbose= 15 15 full_test= 16 16 random= 17 + uapi_opt= 17 18 active_opt= 18 19 bias_opt= 19 20 line_set_pid= ··· 31 30 echo "-r: test random lines as well as fence posts" 32 31 echo "-t: interface type:" 33 32 echo " cdev (character device ABI) - default" 33 + echo " cdev_v1 (deprecated character device ABI)" 34 34 echo " sysfs (deprecated SYSFS ABI)" 35 35 echo "-v: verbose progress reporting" 36 36 exit $ksft_fail ··· 102 100 { 103 101 release_line 104 102 105 - $BASE/gpio-mockup-cdev $active_opt /dev/$chip $offset 103 + local cdev_opts=${uapi_opt}${active_opt} 104 + $BASE/gpio-mockup-cdev $cdev_opts /dev/$chip $offset 106 105 echo $? 107 106 } 108 107 ··· 145 142 esac 146 143 done 147 144 148 - local cdev_opts=${active_opt} 145 + local cdev_opts=${uapi_opt}${active_opt} 149 146 if [ "$val" ]; then 150 147 $BASE/gpio-mockup-cdev $cdev_opts -s$val /dev/$chip $offset & 151 148 # failure to set is detected by reading mockup and toggling values ··· 342 339 sysfs) 343 340 source $BASE/gpio-mockup-sysfs.sh 344 341 echo "WARNING: gpio sysfs ABI is deprecated." 342 + ;; 343 + cdev_v1) 344 + echo "WARNING: gpio cdev ABI v1 is deprecated." 345 + uapi_opt="-u1 " 345 346 ;; 346 347 cdev) 347 348 ;;