Skip to content

Commit af603b3

Browse files
asrini4rhemanth9
andauthored
Main LNL PV release (#7)
* acquire & release sensor fixes (#49) (#55) * 1).acq & rel sensor fix for HSD 15015753611 2).release_firmware fix for HSD 14022301639 3).vid/pid mismatch fix for HSD 15015491881 * Revert testapp to use external acq/rel. --------- Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * PR for Pmain PV (#65) * Remove watchdog support (#52) Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * Fix shared I2C parameter (#53) Read IICS method and assign shared I2C value. Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * Add DKMS (#56) * Add DKMS support Signed-off-by: Hemanth Rachakonda <hemanth.rachakonda@intel.com> * Updated with README with dkms Signed-off-by: Hemanth Rachakonda <hemanth.rachakonda@intel.com> --------- Signed-off-by: Hemanth Rachakonda <hemanth.rachakonda@intel.com> * [Delay release sensor during FW update] (#57) During FW update release the sensor just before CV reset. Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * [Fix for FW update in suspend] (#58) Using wait() in suspend is not letting device to go suspend. Use right API for device to enter suspend. Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * [New IPU-Vision interface] (#60) 1).Removal of cvs_acquire_camera_sensor & cvs_release_camera_sensor API's 2).Grant sensor ownership to IPU by default Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * [Remove redundant host wake] (#62) Remove hostwake before fw d/l. Fix some debug message logs. Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> * [Fix coverity issue for PV] (#63) Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> --------- Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> Signed-off-by: Hemanth Rachakonda <hemanth.rachakonda@intel.com> Co-authored-by: rhemanth9 <hemanth.rachakonda@intel.com> --------- Signed-off-by: Srinivas Alla <alla.srinivas@intel.com> Signed-off-by: Hemanth Rachakonda <hemanth.rachakonda@intel.com> Co-authored-by: rhemanth9 <hemanth.rachakonda@intel.com>
1 parent d330767 commit af603b3

File tree

5 files changed

+121
-268
lines changed

5 files changed

+121
-268
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ This repository supports Intel Vision Driver on Intel Lunar Lake (LNL) CVS-enabl
1111
## Build instructions
1212
Ways to build the USBIO drivers
1313
1. build out of kernel source tree
14-
2. build with kernel source tree and build with dkms aren't supported yet
14+
2. build with dkms
15+
3. build with kernel source tree aren't supported yet
1516

1617
Build was tested on Ubuntu 22.04 LNL CVS platform running kernel v6.7-rc8
1718

@@ -43,4 +44,8 @@ $ sudo insmod intel_cvs.ko
4344
$ sudo rmmod intel_cvs
4445
```
4546

47+
### Build with dkms
48+
a dkms.conf file is also provided as an example for building with dkms which can be used by ```dkms add, build and install```.
49+
50+
4651

dkms.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
PACKAGE_NAME="vision-driver"
2+
PACKAGE_VERSION="1.0.0"
3+
4+
MAKE="make KERNELRELEASE=$kernelver KERNEL_SRC=$kernel_source_dir"
5+
CLEAN="make KERNELRELEASE=$kernelver KERNEL_SRC=$kernel_source_dir clean"
6+
7+
BUILT_MODULE_NAME[0]="intel_cvs"
8+
DEST_MODULE_LOCATION[0]="/updates"
9+
10+
AUTOINSTALL="yes"

drivers/misc/icvs/intel_cvs.c

Lines changed: 27 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,8 @@ static irqreturn_t cvs_irq_handler(int irq, void *devid)
2525
if (!icvs || !icvs->dev)
2626
goto exit;
2727

28-
icvs->rst_retry = RST_RETRY;
2928
icvs->hostwake_event_arg = 1;
3029
wake_up_interruptible(&icvs->hostwake_event);
31-
32-
if (icvs->fw_dl_task_finished == true)
33-
hrtimer_start(&icvs->wdt, ms_to_ktime(WDT_TIMEOUT),
34-
HRTIMER_MODE_REL);
3530
ret = true;
3631
exit:
3732
return IRQ_RETVAL(ret);
@@ -54,49 +49,10 @@ static int cvs_init(struct intel_cvs *icvs)
5449
goto exit;
5550
}
5651

57-
icvs->rst_retry = RST_RETRY;
58-
5952
exit:
6053
return ret;
6154
}
6255

63-
static void cvs_wdt_reset_thread(struct work_struct *work)
64-
{
65-
struct intel_cvs *icvs = container_of(work, struct intel_cvs, rst_task);
66-
67-
if (!icvs)
68-
return;
69-
70-
dev_info(icvs->dev, "%s\n", __func__);
71-
gpiod_set_value_cansleep(icvs->rst, 0);
72-
73-
if (icvs->rst_retry--) {
74-
icvs->owner = CVS_CAMERA_NONE;
75-
icvs->ref_count = 0;
76-
icvs->int_ref_count = 0;
77-
78-
msleep(RST_TIME);
79-
gpiod_set_value_cansleep(icvs->rst, 1);
80-
hrtimer_start(&icvs->wdt, ms_to_ktime(WDT_TIMEOUT),
81-
HRTIMER_MODE_REL);
82-
} else
83-
dev_err(icvs->dev, "%s:Device unresponsive!\n", __func__);
84-
}
85-
86-
static enum hrtimer_restart cvs_wdt_reset(struct hrtimer *t)
87-
{
88-
struct intel_cvs *icvs = container_of(t, struct intel_cvs, wdt);
89-
90-
if (!icvs)
91-
goto exit;
92-
93-
dev_warn(icvs->dev, "%s\n", __func__);
94-
schedule_work(&icvs->rst_task);
95-
96-
exit:
97-
return HRTIMER_NORESTART;
98-
}
99-
10056
static int find_oem_prod_id(acpi_handle handle, const char* method_name, unsigned long long* value)
10157
{
10258
acpi_status status;
@@ -116,23 +72,24 @@ static int find_oem_prod_id(acpi_handle handle, const char* method_name, unsigne
11672
return 0;
11773
}
11874

119-
static int find_shared_i2c(acpi_handle handle, const char *method_name)
75+
static void find_shared_i2c(acpi_handle handle, const char *method_name, int *i2c_shared)
12076
{
121-
struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
12277
acpi_status status;
78+
unsigned long long value = 0;
79+
status = acpi_evaluate_integer(handle, (acpi_string)method_name,
80+
NULL, &value);
12381

124-
status = acpi_evaluate_object(handle, (acpi_string)method_name, NULL,
125-
&buffer);
126-
if (ACPI_FAILURE(status))
127-
return -ENODEV;
128-
129-
if (!buffer.pointer)
130-
return -ENODEV;
131-
132-
ACPI_FREE(buffer.pointer);
133-
pr_info("%s:ACPI method %s found for i2c_shared\n", __func__,
134-
method_name);
135-
return 0;
82+
if (ACPI_FAILURE(status)) {
83+
dev_err(cvs->dev, "%s: ACPI method %s not found",
84+
__func__, method_name);
85+
*i2c_shared = 0;
86+
}
87+
88+
dev_info(cvs->dev,
89+
"%s: ACPI method %s returned:0x%llx",
90+
__func__, method_name, value);
91+
92+
*i2c_shared = (value == 0) ? 0 : 1;
13693
}
13794

13895
static int cvs_i2c_probe(struct i2c_client *i2c)
@@ -215,15 +172,11 @@ static int cvs_i2c_probe(struct i2c_client *i2c)
215172
goto exit;
216173
}
217174

218-
INIT_WORK(&icvs->rst_task, cvs_wdt_reset_thread);
219175
INIT_WORK(&icvs->fw_dl_task, cvs_fw_dl_thread);
220176
init_waitqueue_head(&icvs->hostwake_event);
221177
init_waitqueue_head(&icvs->update_complete_event);
222178
icvs->fw_dl_task_finished = false;
223179

224-
hrtimer_init(&icvs->wdt, CLOCK_REALTIME, HRTIMER_MODE_REL);
225-
icvs->wdt.function = cvs_wdt_reset;
226-
227180
ret = cvs_init(icvs);
228181
if (ret)
229182
dev_err(icvs->dev, "Failed to initialize\n");
@@ -234,7 +187,7 @@ static int cvs_i2c_probe(struct i2c_client *i2c)
234187
dev_err(icvs->dev, "Failed to get ACPI handle\n");
235188
goto exit;
236189
}
237-
icvs->i2c_shared = (find_shared_i2c(handle, "IICS") < 0) ? 0 : 1;
190+
find_shared_i2c(handle, "IICS", &icvs->i2c_shared);
238191

239192
if (icvs->cap == ICVS_FULLCAP) {
240193
find_oem_prod_id(handle, "OPID", &(icvs->oem_prod_id));
@@ -256,7 +209,6 @@ static int cvs_i2c_probe(struct i2c_client *i2c)
256209
static void cvs_exit(struct intel_cvs *icvs)
257210
{
258211
if (icvs && icvs->dev && icvs->rst) {
259-
hrtimer_cancel(&icvs->wdt);
260212
devm_free_irq(icvs->dev, icvs->irq, icvs);
261213
gpiod_set_value_cansleep(icvs->rst, 0);
262214
}
@@ -272,12 +224,6 @@ static void cvs_i2c_remove(struct i2c_client *i2c)
272224
if (icvs) {
273225
cvs->close_fw_dl_task = true;
274226

275-
while (cvs->ref_count) {
276-
pr_info("%s:Camera is used by IPU. check again after %dms",
277-
__func__, WAIT_HOST_RELEASE_MS);
278-
mdelay(WAIT_HOST_RELEASE_MS);
279-
}
280-
281227
if (icvs->cap == ICVS_FULLCAP) {
282228
if (!cvs->fw_dl_task_finished) {
283229
pr_info("%s:signal cvs_fw_dl_thread() to stop",
@@ -387,44 +333,6 @@ int cvs_release_camera_sensor_internal(void)
387333
return -EIO;
388334
}
389335

390-
int cvs_acquire_camera_sensor(struct cvs_mipi_config *config,
391-
cvs_privacy_callback_t callback, void *handle,
392-
struct cvs_camera_status *status)
393-
{
394-
int ret;
395-
396-
if (!cvs)
397-
return -EINVAL;
398-
399-
ret = cvs_acquire_camera_sensor_internal();
400-
if (!ret) {
401-
spin_lock(&cvs->lock);
402-
cvs->ref_count++;
403-
spin_unlock(&cvs->lock);
404-
}
405-
return (ret) ? ret : 0;
406-
}
407-
EXPORT_SYMBOL_GPL(cvs_acquire_camera_sensor);
408-
409-
int cvs_release_camera_sensor(struct cvs_camera_status *status)
410-
{
411-
int ret;
412-
413-
if (!cvs)
414-
return -EINVAL;
415-
416-
ret = cvs_release_camera_sensor_internal();
417-
if (!ret) {
418-
spin_lock(&cvs->lock);
419-
cvs->ref_count = (cvs->ref_count > 0) ? (cvs->ref_count - 1) : 0;
420-
cvs->owner = (cvs->ref_count == 0) ? CVS_CAMERA_CVS :
421-
CVS_CAMERA_IPU;
422-
spin_unlock(&cvs->lock);
423-
}
424-
return (ret) ? ret : 0;
425-
}
426-
EXPORT_SYMBOL_GPL(cvs_release_camera_sensor);
427-
428336
#ifdef DEBUG_CVS
429337
int cvs_exec_cmd(enum cvs_command command)
430338
{
@@ -529,29 +437,24 @@ static ssize_t coredump_show(struct device *dev, struct device_attribute *attr,
529437
"CVS VID/PID : 0x%x 0x%x\n"
530438
"CVS Firmware Ver: %d.%d.%d.%d (0x%x.0x%x.0x%x.0x%x)\n"
531439
"CVS Device State: 0x%x (%s)\n"
532-
"Reference Count : %d (internal %d)\n"
440+
"Reference Count : %d\n"
533441
"CVS Owner : %s\n"
534442
"I2C Shared : %d\n",
535443
cvs->id.vid, cvs->id.pid, cvs->ver.major, cvs->ver.minor,
536444
cvs->ver.hotfix, cvs->ver.build, cvs->ver.major, cvs->ver.minor,
537445
cvs->ver.hotfix, cvs->ver.build, cvs->cvs_state, stat_name,
538-
cvs->ref_count, cvs->int_ref_count,
446+
cvs->int_ref_count,
539447
((cvs->owner == CVS_CAMERA_NONE) ? "NONE" :
540448
(cvs->owner == CVS_CAMERA_CVS) ? "CVS" :
541-
(cvs->owner == CVS_CAMERA_IPU && cvs->ref_count) ? "IPU" :
542-
(cvs->owner == CVS_CAMERA_IPU && cvs->int_ref_count) ? "VDRV" : "UNKNOWN"),
449+
(cvs->owner == CVS_CAMERA_IPU) ? "HOST" : "UNKNOWN"),
543450
cvs->i2c_shared);
544451
}
545452
static DEVICE_ATTR_RO(coredump);
546453

547454
static ssize_t cmd_store(struct device *dev, struct device_attribute *attr,
548455
const char *buf, size_t count)
549456
{
550-
if (sysfs_streq(buf, "acquire"))
551-
cvs_acquire_camera_sensor(NULL, NULL, NULL, NULL);
552-
else if (sysfs_streq(buf, "release"))
553-
cvs_release_camera_sensor(NULL);
554-
else if (sysfs_streq(buf, "state"))
457+
if (sysfs_streq(buf, "state"))
555458
cvs_exec_cmd(GET_DEVICE_STATE);
556459
else if (sysfs_streq(buf, "version"))
557460
cvs_exec_cmd(GET_FW_VERSION);
@@ -568,7 +471,7 @@ static ssize_t cmd_show(struct device *dev, struct device_attribute *attr,
568471
{
569472
return sysfs_emit(
570473
buf, "command: %s\n",
571-
"[coredump, acquire, release, state, version, id]");
474+
"[coredump, state, version, id]");
572475
}
573476
static DEVICE_ATTR_RW(cmd);
574477

@@ -586,27 +489,20 @@ static int cvs_suspend(struct device *dev)
586489
struct i2c_client *i2c = container_of(dev, struct i2c_client, dev);
587490
struct intel_cvs *icvs = i2c_get_clientdata(i2c);
588491
int ret = 0;
589-
u64 timeout;
590492

591493
dev_info(icvs->dev, "%s entered\n", __func__);
592-
/* Wait for FW update complete */
593494
if (icvs->cap == ICVS_FULLCAP && cvs->fw_dl_task_finished != true) {
594495
cvs->close_fw_dl_task = true;
595496
cvs->hostwake_event_arg = 1;
596497
wake_up_interruptible(&cvs->hostwake_event);
597-
timeout = msecs_to_jiffies(WAIT_HOST_WAKE_FLASH_LONG_MS * FW_MAX_RETRY);
598-
ret = wait_event_interruptible_timeout(cvs->update_complete_event,
599-
cvs->update_complete_event_arg == 1,
600-
timeout);
601-
if (ret <= 0) {
602-
dev_err(icvs->dev, "%s: Failed to wait FW update complete\n", __func__);
603-
ret = -EAGAIN;
604-
}
498+
/* Wait for fw update to cancel */
499+
dev_info(icvs->dev, "%s: wait for fw update cancel", __func__);
500+
flush_work(&icvs->fw_dl_task);
501+
dev_info(icvs->dev, "%s: fw update cancelled", __func__);
605502
}
606503

607504
if (icvs->cap == ICVS_FULLCAP) {
608-
/* Disable wdt & IRQ */
609-
hrtimer_cancel(&icvs->wdt);
505+
/* Disable IRQ */
610506
disable_irq(icvs->irq);
611507
}
612508

@@ -634,7 +530,7 @@ static int cvs_resume(struct device *dev)
634530
icvs->fw_dl_task_finished = false;
635531
icvs->close_fw_dl_task = false;
636532

637-
/* Restart IRQ and wdt, hrtimer_start would start by fw_dl_task */
533+
/* Restart IRQ & fw_dl thread */
638534
enable_irq(icvs->irq);
639535
schedule_work(&icvs->fw_dl_task);
640536
}

0 commit comments

Comments
 (0)