Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  * Copyright (c) 2022 Rockchip Electronics Co. Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/ioctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/miscdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <uapi/linux/rk-iomux.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include "../../pinctrl/pinctrl-rockchip.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) struct rk_iomux_device {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	struct miscdevice dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) static long rk_iomux_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 	struct iomux_ioctl_data data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (_IOC_SIZE(cmd) > sizeof(data))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	if (copy_from_user(&data, (void __user *)arg, _IOC_SIZE(cmd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 		return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	if (!(_IOC_DIR(cmd) & _IOC_WRITE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 		memset(&data, 0, sizeof(data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	case IOMUX_IOC_MUX_SET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 		ret = rk_iomux_set(data.bank, data.pin, data.mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	case IOMUX_IOC_MUX_GET:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		ret = rk_iomux_get(data.bank, data.pin, &data.mux);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 		if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 			return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 		return -ENOTTY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	if (_IOC_DIR(cmd) & _IOC_READ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		if (copy_to_user((void __user *)arg, &data, _IOC_SIZE(cmd)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 			return -EFAULT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static const struct file_operations rk_iomux_fops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	.owner          = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	.unlocked_ioctl = rk_iomux_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 	.compat_ioctl	= compat_ptr_ioctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) static __init int rk_iomux_device_create(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 	struct rk_iomux_device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	if (!cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	cdev->dev.minor = MISC_DYNAMIC_MINOR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	cdev->dev.name = "iomux";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	cdev->dev.fops = &rk_iomux_fops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	cdev->dev.parent = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	ret = misc_register(&cdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 		pr_err("failed to register iomux device (%d)\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) late_initcall(rk_iomux_device_create);