mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-06 02:50:49 +09:00
tools: testing: selftests: add iomux instance
Add a new instance for rockchip pinctrl to do selftest, and the userland
can set or get the iomux to one pin directly.
Build the iomux by gcc:
xx-gcc tools/testing/selftests/rkpinctrl/iomux.c -o iomux
Tested on rk3588-evb1:
[root@RK3588:/]# iomux 1 15 1
[root@RK3588:/]# iomux 1 15
mux get (GPIO1-15) = 1
[root@RK3588:/]# iomux 1 15 2
[root@RK3588:/]# iomux 1 15
mux get (GPIO1-15) = 2
Signed-off-by: Jianqun Xu <jay.xu@rock-chips.com>
Change-Id: Ic5271b25e55e1023caa5580346ffb82fe7a4cb65
This commit is contained in:
6
tools/testing/selftests/rkpinctrl/Makefile
Normal file
6
tools/testing/selftests/rkpinctrl/Makefile
Normal file
@@ -0,0 +1,6 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
CFLAGS += -static -O3 -Wl,-no-as-needed -Wall
|
||||
|
||||
TEST_GEN_PROGS = iomux
|
||||
|
||||
include ../lib.mk
|
||||
107
tools/testing/selftests/rkpinctrl/iomux.c
Normal file
107
tools/testing/selftests/rkpinctrl/iomux.c
Normal file
@@ -0,0 +1,107 @@
|
||||
// SPDX-License-Identifier: GPL-2.0
|
||||
/*
|
||||
* Copyright (c) 2022 Rockchip Electronics Co. Ltd.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "../../../../include/uapi/linux/rk-iomux.h"
|
||||
|
||||
static int rk_iomux_ioctl_set(int fd, int bank, int pin, int mux)
|
||||
{
|
||||
struct iomux_ioctl_data data = {
|
||||
.bank = bank,
|
||||
.pin = pin,
|
||||
.mux = mux,
|
||||
};
|
||||
int ret;
|
||||
|
||||
if (!fd)
|
||||
return -EINVAL;
|
||||
|
||||
ret = ioctl(fd, IOMUX_IOC_MUX_SET, &data);
|
||||
if (ret < 0) {
|
||||
perror("fail to ioctl");
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rk_iomux_ioctl_get(int fd, int bank, int pin, int *mux)
|
||||
{
|
||||
struct iomux_ioctl_data data = {
|
||||
.bank = bank,
|
||||
.pin = pin,
|
||||
};
|
||||
int ret;
|
||||
|
||||
if (!fd)
|
||||
return -EINVAL;
|
||||
|
||||
ret = ioctl(fd, IOMUX_IOC_MUX_GET, &data);
|
||||
if (ret < 0) {
|
||||
perror("fail to ioctl");
|
||||
return ret;
|
||||
}
|
||||
*mux = data.mux;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void usage(void)
|
||||
{
|
||||
printf("%s:\n"
|
||||
"set iomux:\n"
|
||||
"iomux [bank index] [pin index] [mux value]\n"
|
||||
"get iomux:\n"
|
||||
"iomux [bank index] [pin index]\n",
|
||||
__func__);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
const char *name = "/dev/iomux";
|
||||
int fd;
|
||||
int bank, pin, mux;
|
||||
int ret;
|
||||
|
||||
if ((argc != 3) && (argc != 4)) {
|
||||
usage();
|
||||
return -1;
|
||||
}
|
||||
|
||||
bank = atoi(argv[1]);
|
||||
pin = atoi(argv[2]);
|
||||
|
||||
fd = open(name, O_RDWR);
|
||||
if (fd < 0) {
|
||||
printf("open %s failed!\n", name);
|
||||
return fd;
|
||||
}
|
||||
|
||||
if (argc == 4) {
|
||||
mux = atoi(argv[3]);
|
||||
ret = rk_iomux_ioctl_set(fd, bank, pin, mux);
|
||||
if (ret)
|
||||
goto err;
|
||||
} else if (argc == 3) {
|
||||
ret = rk_iomux_ioctl_get(fd, bank, pin, &mux);
|
||||
if (ret)
|
||||
goto err;
|
||||
printf("mux get (GPIO%d-%d) = %d\n", bank, pin, mux);
|
||||
}
|
||||
|
||||
err:
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user