1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
/*
* Copyright (C) 2021 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#define _GNU_SOURCE /* For asprintf */
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "compatible_devices.h"
#include "exynos4412_gpios.h"
#include "exynos4412_gpios_data.h"
#include "tests.h"
static int test_output_value(int debug, char *devmem, int fd, size_t page_size,
char *bank, int gpio_offset)
{
char *gpioset_high_command;
char *gpioset_low_command;
int rc;
rc = asprintf(&gpioset_high_command, "gpioset %s %d=1 > /dev/null", bank, gpio_offset);
if (rc == -1) {
rc = errno;
printf("%s: asprintf failed with error %d: %s\n",
__func__, rc, strerror(rc));
assert(false);
}
rc = system(gpioset_high_command);
assert(rc == 0);
free(gpioset_high_command);
rc = gpio_get_direction(devmem, fd, page_size, bank, gpio_offset);
assert (rc == GPIO_OUTPUT);
rc = gpio_get_output_value(devmem, fd, page_size, bank, gpio_offset);
assert (rc == GPIO_VALUE_HIGH);
rc = asprintf(&gpioset_low_command, "gpioset %s %d=0 > /dev/null", bank, gpio_offset);
if (rc == -1) {
rc = errno;
printf("%s: asprintf failed with error %d: %s\n",
__func__, rc, strerror(rc));
assert(false);
}
rc = system(gpioset_low_command);
assert(rc == 0);
rc = gpio_get_direction(devmem, fd, page_size, bank, gpio_offset);
assert (rc == GPIO_OUTPUT);
rc = gpio_get_output_value(devmem, fd, page_size, bank, gpio_offset);
assert (rc == GPIO_VALUE_LOW);
free(gpioset_low_command);
return 0;
}
static int test_direction(int debug, char *devmem, int fd, size_t page_size,
char *bank, int gpio_offset)
{
char *gpioget_command;
char *gpioset_command;
int rc;
rc = asprintf(&gpioget_command, "gpioget %s %d > /dev/null", bank, gpio_offset);
if (rc == -1) {
rc = errno;
printf("%s: asprintf failed with error %d: %s\n",
__func__, rc, strerror(rc));
assert(false);
}
rc = system(gpioget_command);
assert(rc == 0);
free(gpioget_command);
rc = gpio_get_direction(devmem, fd, page_size, bank, gpio_offset);
assert (rc == GPIO_INPUT);
rc = asprintf(&gpioset_command, "gpioset %s %d=1 > /dev/null", bank, gpio_offset);
if (rc == -1) {
rc = errno;
printf("%s: asprintf failed with error %d: %s\n",
__func__, rc, strerror(rc));
assert(false);
}
rc = system(gpioset_command);
assert(rc == 0);
rc = gpio_get_direction(devmem, fd, page_size, bank, gpio_offset);
assert (rc == GPIO_OUTPUT);
free(gpioset_command);
return 0;
}
int run_tests(int debug, char *devmem, int fd, size_t page_size)
{
bool has_gpioget;
bool has_gpioset;
has_gpioget = device_has_gpioget(debug);
if (!has_gpioget) {
printf("[ !! ] gpioget not found: skipping tests\n");
}
has_gpioset = device_has_gpioset(debug);
if (!has_gpioset) {
printf("[ !! ] gpioset not found: skipping tests\n");
}
if (!has_gpioget || !has_gpioset)
return -1;
test_direction(debug, devmem, fd, page_size, "gpj1", 1);
printf("[ OK ] GPIO direction\n");
test_output_value(debug, devmem, fd, page_size, "gpj1", 1);
printf("[ OK ] GPIO output value\n");
return 0;
}
|