summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-05-27 14:42:21 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-05-27 17:57:58 +0200
commit91a4b4f4f7f37a7ad84734a01e79a82965201994 (patch)
treef70511d6d54ee2b4179ac67c6444ac095d278ec2
parent69954ce752c5f7e04031b4462aac691e8bcfa754 (diff)
downloadexynos-gpio-tool-91a4b4f4f7f37a7ad84734a01e79a82965201994.tar.gz
exynos-gpio-tool-91a4b4f4f7f37a7ad84734a01e79a82965201994.tar.bz2
exynos-gpio-tool-91a4b4f4f7f37a7ad84734a01e79a82965201994.zip
[WIP] Add devmem2 based tests
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--compatible_devices.c15
-rw-r--r--compatible_devices.h1
-rw-r--r--tests.c98
3 files changed, 97 insertions, 17 deletions
diff --git a/compatible_devices.c b/compatible_devices.c
index dd82b29..d63d6bc 100644
--- a/compatible_devices.c
+++ b/compatible_devices.c
@@ -269,6 +269,21 @@ int device_is_compatible(int debug)
return false;
}
+bool device_has_devmem2(int debug)
+{
+ int rc = 0;
+ int err;
+
+ rc = system("devmem2 2>&1 > /dev/null");
+ if (rc != 256) {
+ err = errno;
+ printf("%s: rc=%d errno=%d\n", __func__, rc, err);
+ return false;
+ }
+
+ return true;
+}
+
bool device_has_gpioget(int debug)
{
int rc = 0;
diff --git a/compatible_devices.h b/compatible_devices.h
index 5c0ea99..4d5c8df 100644
--- a/compatible_devices.h
+++ b/compatible_devices.h
@@ -20,6 +20,7 @@
#include <stdbool.h>
+bool device_has_devmem2(int debug);
bool device_has_gpioget(int debug);
bool device_has_gpioset(int debug);
int device_is_compatible(int debug);
diff --git a/tests.c b/tests.c
index 0279354..1e94dba 100644
--- a/tests.c
+++ b/tests.c
@@ -31,8 +31,9 @@
#include "tests.h"
-static int test_output_value(int debug, char *devmem, int fd, size_t page_size,
- char *bank, int gpio_offset)
+static int test_output_value_with_libgpiod(int debug, char *devmem, int fd,
+ size_t page_size, char *bank,
+ int gpio_offset)
{
char *gpioset_high_command;
char *gpioset_low_command;
@@ -78,8 +79,61 @@ static int test_output_value(int debug, char *devmem, int fd, size_t page_size,
return 0;
}
-static int test_direction(int debug, char *devmem, int fd, size_t page_size,
- char *bank, int gpio_offset)
+static int test_flash_with_devmem2(int debug, char *devmem, int fd,
+ size_t page_size)
+{
+ int rc;
+
+ /* On Parabola with the nonfree u-boot and the Replicant 11 kernel,
+ * the gpio value register is 0x0 after boot, so I hope that it is safe
+ * to set it to 0x0 too on Replicant 6, even if after boot, its value
+ * is 0x1.
+ * We also used the default values after booting Parabola for the gpio
+ * direction register.
+ */
+
+ /* Set the GPIO to input */
+ rc = system("devmem2 0x11400260 w 0x2000");
+ assert(rc == 0);
+
+ rc = gpio_get_direction(devmem, fd, page_size, "gpj1", 1);
+ assert (rc == GPIO_INPUT);
+
+ /* Set the GPIO to output */
+ rc = system("devmem2 0x11400260 w 0x2002");
+ assert(rc == 0);
+
+ rc = gpio_get_direction(devmem, fd, page_size, "gpj1", 1);
+ assert (rc == GPIO_OUTPUT);
+
+ /* Set the pin LOW */
+ rc = system("devmem2 0x11400264 w 0");
+ assert(rc == 0);
+
+ rc = gpio_get_output_value(devmem, fd, page_size, "gpj1", 1);
+ assert (rc == GPIO_VALUE_LOW);
+
+ /* Set the pin HIGH */
+ rc = system("devmem2 0x11400264 w 2");
+ assert(rc == 0);
+
+ rc = gpio_get_output_value(devmem, fd, page_size, "gpj1", 1);
+ assert (rc == GPIO_VALUE_HIGH);
+
+ /* Set it to low again */
+ rc = system("devmem2 0x11400264 w 0");
+ assert(rc == 0);
+
+ rc = gpio_get_output_value(devmem, fd, page_size, "gpj1", 1);
+ assert (rc == GPIO_VALUE_LOW);
+
+ return 0;
+
+}
+
+static int test_direction_with_libgpiod(int debug, char *devmem, int fd,
+ size_t page_size, char *bank,
+ int gpio_offset)
{
char *gpioget_command;
char *gpioset_command;
@@ -122,27 +176,37 @@ static int test_direction(int debug, char *devmem, int fd, size_t page_size,
int run_tests(int debug, char *devmem, int fd, size_t page_size)
{
+ bool has_devmem2;
bool has_gpioget;
bool has_gpioset;
+ has_devmem2 = device_has_devmem2(debug);
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;
+ if (has_gpioget && has_gpioset) {
+ test_direction_with_libgpiod(debug, devmem, fd, page_size, "gpj1", 1);
+ printf("[ OK ] libgpiod GPIO direction test\n");
+
+ test_output_value_with_libgpiod(debug, devmem, fd, page_size, "gpj1", 1);
+ printf("[ OK ] libgpiod GPIO output value test\n");
+ } else {
+ if (!has_gpioget)
+ printf("[ !! ] gpioget not found: skipping"
+ " libgpiod direction and output tests\n");
- test_direction(debug, devmem, fd, page_size, "gpj1", 1);
- printf("[ OK ] GPIO direction\n");
+ if (!has_gpioset)
+ printf("[ !! ] gpioset not found: skipping"
+ " libgpiod direction and output tests\n");
+ }
- test_output_value(debug, devmem, fd, page_size, "gpj1", 1);
- printf("[ OK ] GPIO output value\n");
+ if (has_devmem2) {
+ test_flash_with_devmem2(debug, devmem, fd, page_size);
+ printf("[ OK ] devmem2 GPIO direction and output test\n");
+ } else {
+ printf("[ !! ] devmem2 not found: skipping"
+ " devmem2 direction and output tests\n");
+ }
return 0;
}