1 内核支持
1.1 内核配置CONFIG_ROCKCHIP_IOMUX,令iomux.c参与编译,生成/dev/iomux节点
drivers/soc/rockchip/iomux.c
#include <linux/device.h>
#include <linux/err.h>
#include <linux/file.h>
#include <linux/fs.h>
#include <linux/list.h>
#include <linux/uaccess.h>
#include <linux/ioctl.h>
#include <linux/types.h>
#include <linux/miscdevice.h>
#include <linux/slab.h>
#include <uapi/linux/rk-iomux.h>
#include "../../pinctrl/pinctrl-rockchip.h"
struct rk_iomux_device {
struct miscdevice dev;
};
static long rk_iomux_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
struct iomux_ioctl_data data;
int ret = 0;
if (_IOC_DIR(cmd) & _IOC_READ) {
if (copy_to_user((void __user *)arg, &data, _IOC_SIZE(cmd)))
return -EFAULT;
}
return ret;
}
static const struct file_operations rk_iomux_fops = {
.owner = THIS_MODULE,
.unlocked_ioctl = rk_iomux_ioctl,
.compat_ioctl = compat_ptr_ioctl,
};
static __init int rk_iomux_device_create(void)
{
struct rk_iomux_device *cdev;
int ret;
cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
if (!cdev)
return -ENOMEM;
cdev->dev.minor = MISC_DYNAMIC_MINOR;
cdev->dev.name = "iomux";
cdev->dev.fops = &rk_iomux_fops;
cdev->dev.parent = NULL;
ret = misc_register(&cdev->dev);
if (ret) {
pr_err("failed to register iomux device (%d)\n", ret);
return ret;
}
return 0;
}
late_initcall(rk_iomux_device_create);
2 工具编译
工具位置:tools/testing/selftests/rkpinctrl/iomux.c
用交叉工具链编译成iomux可执行文件
gcc tools/testing/selftests/rkpinctrl/iomux.c -o iomux
3 使用
gpio4a4_sel
//设置 GPIO1_A1 为 func1
iomux 1 1 1
//获取 GPIO1_B0 当前iomux值
iomux 1 8