forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/platform/x86/intel_scu_ipcutil.c
....@@ -1,32 +1,31 @@
1
+// SPDX-License-Identifier: GPL-2.0
12 /*
2
- * intel_scu_ipc.c: Driver for the Intel SCU IPC mechanism
3
+ * Driver for the Intel SCU IPC mechanism
34 *
45 * (C) Copyright 2008-2010 Intel Corporation
56 * Author: Sreedhara DS (sreedhara.ds@intel.com)
67 *
7
- * This program is free software; you can redistribute it and/or
8
- * modify it under the terms of the GNU General Public License
9
- * as published by the Free Software Foundation; version 2
10
- * of the License.
11
- *
12
- * This driver provides ioctl interfaces to call intel scu ipc driver api
8
+ * This driver provides IOCTL interfaces to call Intel SCU IPC driver API.
139 */
1410
15
-#include <linux/module.h>
16
-#include <linux/kernel.h>
1711 #include <linux/errno.h>
18
-#include <linux/types.h>
19
-#include <linux/fs.h>
2012 #include <linux/fcntl.h>
13
+#include <linux/fs.h>
14
+#include <linux/kernel.h>
15
+#include <linux/module.h>
2116 #include <linux/sched.h>
22
-#include <linux/uaccess.h>
2317 #include <linux/slab.h>
24
-#include <linux/init.h>
18
+#include <linux/types.h>
19
+#include <linux/uaccess.h>
20
+
2521 #include <asm/intel_scu_ipc.h>
2622
2723 static int major;
2824
29
-/* ioctl commnds */
25
+struct intel_scu_ipc_dev *scu;
26
+static DEFINE_MUTEX(scu_lock);
27
+
28
+/* IOCTL commands */
3029 #define INTE_SCU_IPC_REGISTER_READ 0
3130 #define INTE_SCU_IPC_REGISTER_WRITE 1
3231 #define INTE_SCU_IPC_REGISTER_UPDATE 2
....@@ -56,12 +55,12 @@
5655
5756 switch (cmd) {
5857 case INTE_SCU_IPC_REGISTER_READ:
59
- return intel_scu_ipc_readv(data->addr, data->data, count);
58
+ return intel_scu_ipc_dev_readv(scu, data->addr, data->data, count);
6059 case INTE_SCU_IPC_REGISTER_WRITE:
61
- return intel_scu_ipc_writev(data->addr, data->data, count);
60
+ return intel_scu_ipc_dev_writev(scu, data->addr, data->data, count);
6261 case INTE_SCU_IPC_REGISTER_UPDATE:
63
- return intel_scu_ipc_update_register(data->addr[0],
64
- data->data[0], data->mask);
62
+ return intel_scu_ipc_dev_update(scu, data->addr[0], data->data[0],
63
+ data->mask);
6564 default:
6665 return -ENOTTY;
6766 }
....@@ -95,8 +94,40 @@
9594 return 0;
9695 }
9796
97
+static int scu_ipc_open(struct inode *inode, struct file *file)
98
+{
99
+ int ret = 0;
100
+
101
+ /* Only single open at the time */
102
+ mutex_lock(&scu_lock);
103
+ if (scu) {
104
+ ret = -EBUSY;
105
+ goto unlock;
106
+ }
107
+
108
+ scu = intel_scu_ipc_dev_get();
109
+ if (!scu)
110
+ ret = -ENODEV;
111
+
112
+unlock:
113
+ mutex_unlock(&scu_lock);
114
+ return ret;
115
+}
116
+
117
+static int scu_ipc_release(struct inode *inode, struct file *file)
118
+{
119
+ mutex_lock(&scu_lock);
120
+ intel_scu_ipc_dev_put(scu);
121
+ scu = NULL;
122
+ mutex_unlock(&scu_lock);
123
+
124
+ return 0;
125
+}
126
+
98127 static const struct file_operations scu_ipc_fops = {
99128 .unlocked_ioctl = scu_ipc_ioctl,
129
+ .open = scu_ipc_open,
130
+ .release = scu_ipc_release,
100131 };
101132
102133 static int __init ipc_module_init(void)