summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-06-09 19:05:24 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-06-09 19:08:58 +0200
commite2d9ab665fc7b1414a9708a3b267a5facae814f5 (patch)
treec990cc9a0ece1dee6cf4d2aa4213f761d05c958c
parent4648f4cf28f3313a9c82c265e951b74472fd0f62 (diff)
downloadexynos-gpio-tool-e2d9ab665fc7b1414a9708a3b267a5facae814f5.tar.gz
exynos-gpio-tool-e2d9ab665fc7b1414a9708a3b267a5facae814f5.tar.bz2
exynos-gpio-tool-e2d9ab665fc7b1414a9708a3b267a5facae814f5.zip
Add working devmem2 direction test
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--tests.c156
1 files changed, 76 insertions, 80 deletions
diff --git a/tests.c b/tests.c
index 5ec9fed..7de909d 100644
--- a/tests.c
+++ b/tests.c
@@ -32,8 +32,6 @@
#include "memory.h"
#include "tests.h"
-#define DEVMEM2_TESTS 0 /* Broken tests ? */
-
static int run_command(int debug, char *command)
{
char *silent_command;
@@ -70,6 +68,17 @@ static int test_output_value_with_libgpiod(int debug,
char *gpioset_low_command;
int rc;
+ rc = asprintf(&gpioset_high_command, "gpioset %s %d=1", bank,
+ gpio_offset);
+ if (rc == -1) {
+ rc = errno;
+ printf("%s: asprintf failed with error %d: %s\n",
+ __func__, rc, strerror(rc));
+ assert(false);
+ }
+
+ rc = run_command(debug, gpioset_high_command);
+ assert(rc == 0);
rc = asprintf(&gpioset_high_command, "gpioset %s %d=1", bank,
gpio_offset);
@@ -113,77 +122,6 @@ static int test_output_value_with_libgpiod(int debug,
return 0;
}
-#if DEVMEM2_TESTS
-static int test_flash_with_devmem2(int debug,
- struct memory_mapping *memory_mapping)
-{
- int rc;
-
- /* Default values at boot:
- * +--------------+------------+----------+
- * | Distribution | Address | Value[1] |
- * +--------------+------------+----------+
- * | Parabola | 0x11400260 | 0x2000 |
- * | Parabola | 0x11400264 | 0x0000 |
- * +--------------+------------+----------+
- * [1]obtained with devmem2 <address> w
- */
-
- /* Set the GPIO to input */
- if (debug)
- printf(" Starting devmem2 GPIO input test\n");
- /* GPJ1CON[4:7] with bit 4 to 7 at 0 => 0xnn0n (n == don't care) */
- rc = run_command(debug, "devmem2 0x11400260 w 0x2000");
- assert(rc == 0);
- rc = gpio_get_direction(debug, memory_mapping, "gpj1", 1);
- assert (rc == GPIO_INPUT);
- printf("[ OK ] devmem2 GPIO input test\n");
-
- /* Set the GPIO to output */
- if (debug)
- printf(" Starting devmem2 GPIO output test\n");
- /* GPJ1CON[4:7] with bit 1 @ 1 and the rest at 0 => 1<<5 == 0x20 */
- rc = run_command(debug, "devmem2 0x11400260 w 0x2020");
- assert(rc == 0);
- rc = gpio_get_direction(debug, memory_mapping, "gpj1", 1);
- assert (rc == GPIO_OUTPUT);
- printf("[ OK ] devmem2 GPIO output test\n");
-
- /* Set the pin LOW */
- /* GPJ1DAT[1] == 0 */
- if (debug)
- printf(" Starting devmem2 GPIO output low test\n");
- rc = run_command(debug, "devmem2 0x11400264 w 0");
- assert(rc == 0);
- rc = gpio_get_output_value(debug, memory_mapping, "gpj1", 1);
- assert (rc == GPIO_VALUE_LOW);
- printf("[ OK ] devmem2 GPIO output low test\n");
-
- /* Set the pin HIGH */
- /* GPJ1DAT[1] == 1 => 1<<1 == 2 */
- if (debug)
- printf(" Starting devmem2 GPIO output high test\n");
- rc = run_command(debug, "devmem2 0x11400264 w 2");
- assert(rc == 0);
- rc = gpio_get_output_value(debug, memory_mapping, "gpj1", 1);
- assert (rc == GPIO_VALUE_HIGH);
- printf("[ OK ] devmem2 GPIO output high test\n");
-
- /* Set it to low again */
- /* GPJ1DAT[1] == 0 */
- if (debug)
- printf(" Starting devmem2 GPIO output low test\n");
- rc = run_command(debug, "devmem2 0x11400264 w 0");
- assert(rc == 0);
- rc = gpio_get_output_value(debug, memory_mapping, "gpj1", 1);
- assert (rc == GPIO_VALUE_LOW);
- printf("[ OK ] devmem2 GPIO output low test\n");
-
- return 0;
-
-}
-#endif /* DEVMEM2_TESTS */
-
static int test_direction_with_libgpiod(int debug,
struct memory_mapping *memory_mapping,
char *bank, int gpio_offset)
@@ -229,17 +167,76 @@ static int test_direction_with_libgpiod(int debug,
return 0;
}
+static int test_direction_with_devmem2(int debug,
+ struct memory_mapping *memory_mapping)
+{
+ char *gpio_input_command;
+ char *gpio_output_command;
+
+ off_t gpj1_con_addr = 0x11400260;
+ unsigned long register_value;
+ int rc = 0;
+
+ /* Test input for GPJ1 1 */
+ rc = read_word(debug, memory_mapping, gpj1_con_addr, &register_value);
+ assert(rc == 0);
+
+ register_value &= 0xffffff0f;
+
+ rc = asprintf(&gpio_input_command,
+ "devmem2 0x%lx w 0x%lx",
+ gpj1_con_addr, register_value);
+ if (rc == -1) {
+ rc = errno;
+ printf("%s: asprintf failed with error %d: %s\n",
+ __func__, rc, strerror(rc));
+ assert(false);
+ }
+
+ rc = run_command(debug, gpio_input_command);
+ assert(rc == 0);
+
+ rc = gpio_get_direction(debug, memory_mapping, "gpj1", 1);
+ assert (rc == GPIO_INPUT);
+
+ /* Test output for GPJ1 1 */
+ rc = read_word(debug, memory_mapping, gpj1_con_addr, &register_value);
+ assert(rc == 0);
+
+ register_value &= 0xffffff0f;
+ register_value |= (1<<4);
+
+ rc = asprintf(&gpio_output_command,
+ "devmem2 0x%lx w 0x%lx",
+ gpj1_con_addr, register_value);
+ if (rc == -1) {
+ rc = errno;
+ printf("%s: asprintf failed with error %d: %s\n",
+ __func__, rc, strerror(rc));
+ assert(false);
+ }
+
+ rc = run_command(debug, gpio_output_command);
+ assert(rc == 0);
+
+ rc = gpio_get_direction(debug, memory_mapping, "gpj1", 1);
+ assert (rc == GPIO_OUTPUT);
+
+ /* Free resources */
+ free(gpio_input_command);
+ free(gpio_output_command);
+
+ return 0;
+
+}
+
int run_tests(int debug, struct memory_mapping *memory_mapping)
{
-#if DEVMEM2_TESTS
bool has_devmem2;
-#endif /* DEVMEM2_TESTS */
bool has_gpioget;
bool has_gpioset;
-#if DEVMEM2_TESTS
has_devmem2 = device_has_devmem2(debug);
-#endif /* DEVMEM2_TESTS */
has_gpioget = device_has_gpioget(debug);
has_gpioset = device_has_gpioset(debug);
@@ -259,14 +256,13 @@ int run_tests(int debug, struct memory_mapping *memory_mapping)
" libgpiod direction and output tests\n");
}
-#if DEVMEM2_TESTS
if (has_devmem2) {
- test_flash_with_devmem2(debug, memory_mapping);
+ test_direction_with_devmem2(debug, memory_mapping);
+ printf("[ OK ] devmem2 GPIO direction test\n");
} else {
printf("[ !! ] devmem2 not found: skipping"
" devmem2 direction and output tests\n");
}
-#endif /* DEVMEM2_TESTS */
return 0;
}