1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2021 Intel Corporation */
4 #include <linux/module.h>
5 #include <linux/mutex.h>
6 #include <linux/sched.h>
7 #include <linux/spinlock.h>
10 #include "intel_vsc.h"
12 #define ACE_PRIVACY_ON 2
19 struct vsc_csi_ops
*csi_ops
;
20 uint16_t csi_registerred
;
23 struct vsc_ace_ops
*ace_ops
;
24 uint16_t ace_registerred
;
27 static struct intel_vsc vsc
;
29 static int check_component_ready(void)
34 spin_lock_irqsave(&vsc
.lock
, flags
);
36 if (vsc
.ace_registerred
&& vsc
.csi_registerred
)
39 spin_unlock_irqrestore(&vsc
.lock
, flags
);
44 static void update_camera_status(struct vsc_camera_status
*status
,
45 struct camera_status
*s
)
48 status
->owner
= s
->camera_owner
;
49 status
->exposure_level
= s
->exposure_level
;
50 status
->status
= VSC_PRIVACY_OFF
;
52 if (s
->privacy_stat
== ACE_PRIVACY_ON
)
53 status
->status
= VSC_PRIVACY_ON
;
57 int vsc_register_ace(void *ace
, struct vsc_ace_ops
*ops
)
62 if (ops
->ipu_own_camera
&& ops
->ace_own_camera
) {
63 spin_lock_irqsave(&vsc
.lock
, flags
);
67 vsc
.ace_registerred
= true;
69 spin_unlock_irqrestore(&vsc
.lock
, flags
);
75 pr_err("register ace failed\n");
78 EXPORT_SYMBOL_GPL(vsc_register_ace
);
80 void vsc_unregister_ace(void)
84 spin_lock_irqsave(&vsc
.lock
, flags
);
86 vsc
.ace_registerred
= false;
88 spin_unlock_irqrestore(&vsc
.lock
, flags
);
90 EXPORT_SYMBOL_GPL(vsc_unregister_ace
);
92 int vsc_register_csi(void *csi
, struct vsc_csi_ops
*ops
)
97 if (ops
->set_privacy_callback
&&
98 ops
->set_owner
&& ops
->set_mipi_conf
) {
99 spin_lock_irqsave(&vsc
.lock
, flags
);
103 vsc
.csi_registerred
= true;
105 spin_unlock_irqrestore(&vsc
.lock
, flags
);
111 pr_err("register csi failed\n");
114 EXPORT_SYMBOL_GPL(vsc_register_csi
);
116 void vsc_unregister_csi(void)
120 spin_lock_irqsave(&vsc
.lock
, flags
);
122 vsc
.csi_registerred
= false;
124 spin_unlock_irqrestore(&vsc
.lock
, flags
);
126 EXPORT_SYMBOL_GPL(vsc_unregister_csi
);
128 int vsc_acquire_camera_sensor(struct vsc_mipi_config
*config
,
129 vsc_privacy_callback_t callback
,
131 struct vsc_camera_status
*status
)
134 struct camera_status s
;
135 struct mipi_conf conf
= { 0 };
137 struct vsc_csi_ops
*csi_ops
;
138 struct vsc_ace_ops
*ace_ops
;
143 ret
= check_component_ready();
145 pr_info("intel vsc not ready\n");
149 mutex_lock(&vsc
.mutex
);
150 /* no need check component again here */
152 csi_ops
= vsc
.csi_ops
;
153 ace_ops
= vsc
.ace_ops
;
155 csi_ops
->set_privacy_callback(vsc
.csi
, callback
, handle
);
157 ret
= ace_ops
->ipu_own_camera(vsc
.ace
, &s
);
159 pr_err("ipu own camera failed\n");
162 update_camera_status(status
, &s
);
164 ret
= csi_ops
->set_owner(vsc
.csi
, CSI_IPU
);
166 pr_err("ipu own csi failed\n");
170 conf
.lane_num
= config
->lane_num
;
171 conf
.freq
= config
->freq
;
172 ret
= csi_ops
->set_mipi_conf(vsc
.csi
, &conf
);
174 pr_err("config mipi failed\n");
179 mutex_unlock(&vsc
.mutex
);
182 EXPORT_SYMBOL_GPL(vsc_acquire_camera_sensor
);
184 int vsc_release_camera_sensor(struct vsc_camera_status
*status
)
187 struct camera_status s
;
189 struct vsc_csi_ops
*csi_ops
;
190 struct vsc_ace_ops
*ace_ops
;
192 ret
= check_component_ready();
194 pr_info("intel vsc not ready\n");
198 mutex_lock(&vsc
.mutex
);
199 /* no need check component again here */
201 csi_ops
= vsc
.csi_ops
;
202 ace_ops
= vsc
.ace_ops
;
204 csi_ops
->set_privacy_callback(vsc
.csi
, NULL
, NULL
);
206 ret
= csi_ops
->set_owner(vsc
.csi
, CSI_FW
);
208 pr_err("vsc own csi failed\n");
212 ret
= ace_ops
->ace_own_camera(vsc
.ace
, &s
);
214 pr_err("vsc own camera failed\n");
217 update_camera_status(status
, &s
);
220 mutex_unlock(&vsc
.mutex
);
223 EXPORT_SYMBOL_GPL(vsc_release_camera_sensor
);
225 static int __init
intel_vsc_init(void)
227 memset(&vsc
, 0, sizeof(struct intel_vsc
));
229 spin_lock_init(&vsc
.lock
);
230 mutex_init(&vsc
.mutex
);
232 vsc
.csi_registerred
= false;
233 vsc
.ace_registerred
= false;
238 static void __exit
intel_vsc_exit(void)
242 module_init(intel_vsc_init
);
243 module_exit(intel_vsc_exit
);
245 MODULE_AUTHOR("Intel Corporation");
246 MODULE_LICENSE("GPL v2");
247 MODULE_SOFTDEP("post: mei_csi mei_ace");
248 MODULE_DESCRIPTION("Device driver for Intel VSC");