@@ -72,6 +72,9 @@ static void cvs_wdt_reset_thread(struct work_struct *work)
7272
7373 if (icvs -> rst_retry -- ) {
7474 icvs -> owner = CVS_CAMERA_NONE ;
75+ icvs -> ref_count = 0 ;
76+ icvs -> int_ref_count = 0 ;
77+
7578 msleep (RST_TIME );
7679 gpiod_set_value_cansleep (icvs -> rst , 1 );
7780 hrtimer_start (& icvs -> wdt , ms_to_ktime (WDT_TIMEOUT ),
@@ -267,7 +270,6 @@ static void cvs_i2c_remove(struct i2c_client *i2c)
267270 dev_info (& i2c -> dev , "%s\n" , __func__ );
268271 icvs = i2c_get_clientdata (i2c );
269272 if (icvs ) {
270- release_firmware (cvs -> file );
271273 cvs -> close_fw_dl_task = true;
272274
273275 while (cvs -> ref_count ) {
@@ -328,7 +330,7 @@ int cvs_acquire_camera_sensor_internal(void)
328330 if (!cvs )
329331 return - EINVAL ;
330332
331- if (cvs -> icvs_state == CV_FW_DOWNLOADING_STATE )
333+ if (cvs -> icvs_state == CV_FW_DOWNLOADING_STATE || cvs -> icvs_state == CV_FW_FLASHING_STATE )
332334 return - EBUSY ;
333335
334336 if (cvs -> owner != CVS_CAMERA_IPU ) {
@@ -341,6 +343,8 @@ int cvs_acquire_camera_sensor_internal(void)
341343 if (val != 0 )
342344 goto err_out ;
343345 }
346+
347+ cvs -> owner = CVS_CAMERA_IPU ;
344348 cvs -> int_ref_count ++ ;
345349 return 0 ;
346350
@@ -359,7 +363,10 @@ int cvs_release_camera_sensor_internal(void)
359363 if (cvs -> icvs_state == CV_FW_DOWNLOADING_STATE )
360364 return - EBUSY ;
361365
362- if (cvs -> owner != CVS_CAMERA_CVS ) {
366+ if (cvs -> int_ref_count == 0 )
367+ return 0 ;
368+
369+ if (cvs -> owner != CVS_CAMERA_CVS && cvs -> int_ref_count == 1 ) {
363370 do {
364371 gpiod_set_value_cansleep (cvs -> req , 1 );
365372 mdelay (GPIO_READ_DELAY_MS );
@@ -369,8 +376,12 @@ int cvs_release_camera_sensor_internal(void)
369376 if (val != 1 )
370377 goto err_out ;
371378 }
379+
372380 cvs -> int_ref_count -- ;
381+ cvs -> owner = (cvs -> int_ref_count == 0 ) ? CVS_CAMERA_CVS :
382+ CVS_CAMERA_IPU ;
373383 return 0 ;
384+
374385err_out :
375386 dev_err (cvs -> dev , "%s:error! val %d (!=1)\n" , __func__ , val );
376387 return - EIO ;
@@ -388,10 +399,7 @@ int cvs_acquire_camera_sensor(struct cvs_mipi_config *config,
388399 ret = cvs_acquire_camera_sensor_internal ();
389400 if (!ret ) {
390401 spin_lock (& cvs -> lock );
391- cvs -> owner = (cvs -> ref_count <= 0 ) ? CVS_CAMERA_IPU :
392- cvs -> owner ;
393- cvs -> ref_count = (cvs -> ref_count <= 0 ) ? 1 :
394- (cvs -> ref_count + 1 );
402+ cvs -> ref_count ++ ;
395403 spin_unlock (& cvs -> lock );
396404 }
397405 return (ret ) ? ret : 0 ;
@@ -408,33 +416,16 @@ int cvs_release_camera_sensor(struct cvs_camera_status *status)
408416 ret = cvs_release_camera_sensor_internal ();
409417 if (!ret ) {
410418 spin_lock (& cvs -> lock );
411- cvs -> ref_count = (cvs -> ref_count > 0 ) ? (cvs -> ref_count - 1 ) :
412- 0 ;
419+ cvs -> ref_count = (cvs -> ref_count > 0 ) ? (cvs -> ref_count - 1 ) : 0 ;
413420 cvs -> owner = (cvs -> ref_count == 0 ) ? CVS_CAMERA_CVS :
414- cvs -> owner ;
421+ CVS_CAMERA_IPU ;
415422 spin_unlock (& cvs -> lock );
416423 }
417424 return (ret ) ? ret : 0 ;
418425}
419426EXPORT_SYMBOL_GPL (cvs_release_camera_sensor );
420427
421428#ifdef DEBUG_CVS
422- int cvs_get_state ()
423- {
424- if (!cvs )
425- return - EINVAL ;
426-
427- if (cvs_acquire_camera_sensor_internal ())
428- return - EINVAL ;
429-
430- if (cvs_read_i2c (GET_DEVICE_STATE , (char * )& cvs -> cvs_state ,
431- sizeof (char )) <= 0 )
432- return - EIO ;
433-
434- cvs_release_camera_sensor_internal ();
435- return 0 ;
436- }
437-
438429int cvs_exec_cmd (enum cvs_command command )
439430{
440431 int rc ;
@@ -448,20 +439,34 @@ int cvs_exec_cmd(enum cvs_command command)
448439
449440 switch (command ) {
450441 case GET_DEVICE_STATE :
442+ if (cvs -> icvs_state == CV_FW_FLASHING_STATE ) {
443+ dev_dbg (cvs -> dev , "%s: Device Busy. State can't be queried now" , __func__ );
444+ return - EBUSY ;
445+ }
451446 rc = cvs_read_i2c (GET_DEVICE_STATE , (char * )& cvs -> cvs_state ,
452447 sizeof (char ));
453448 if (rc <= 0 )
454449 goto err_out ;
455450 break ;
456451
457452 case GET_FW_VERSION :
453+ if (cvs -> icvs_state == CV_FW_DOWNLOADING_STATE || cvs -> icvs_state == CV_FW_FLASHING_STATE ) {
454+ dev_dbg (cvs -> dev , "%s: Device Busy. Version can't be queried now" , __func__ );
455+ return - EBUSY ;
456+ }
457+
458458 rc = cvs_read_i2c (GET_FW_VERSION , (char * )& cvs -> ver ,
459459 sizeof (struct cvs_fw ));
460460 if (rc <= 0 )
461461 goto err_out ;
462462 break ;
463463
464464 case GET_VID_PID :
465+ if (cvs -> icvs_state == CV_FW_DOWNLOADING_STATE || cvs -> icvs_state == CV_FW_FLASHING_STATE ) {
466+ dev_dbg (cvs -> dev , "%s: Device Busy. ID can't be queried now" , __func__ );
467+ return - EBUSY ;
468+ }
469+
465470 rc = cvs_read_i2c (GET_VID_PID , (char * )& cvs -> id ,
466471 sizeof (struct cvs_id ));
467472 if (rc <= 0 )
@@ -482,7 +487,6 @@ int cvs_exec_cmd(enum cvs_command command)
482487 if (cvs -> i2c_shared && cvs -> icvs_state != CV_FW_DOWNLOADING_STATE )
483488 cvs_release_camera_sensor_internal ();
484489
485-
486490 pr_err ("%s:CVs command 0x%x failed, cvs_read_i2c: %d\n" , __func__ ,
487491 command , rc );
488492 return - EIO ;
@@ -532,30 +536,27 @@ static ssize_t coredump_show(struct device *dev, struct device_attribute *attr,
532536 cvs -> ver .hotfix , cvs -> ver .build , cvs -> ver .major , cvs -> ver .minor ,
533537 cvs -> ver .hotfix , cvs -> ver .build , cvs -> cvs_state , stat_name ,
534538 cvs -> ref_count , cvs -> int_ref_count ,
535- (cvs -> owner == CVS_CAMERA_CVS ) ?
536- "CVS" :
537- ((cvs -> owner == CVS_CAMERA_IPU ) ? "IPU" : "none" ),
539+ ((cvs -> owner == CVS_CAMERA_NONE ) ? "NONE" :
540+ (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" ),
538543 cvs -> i2c_shared );
539544}
540545static DEVICE_ATTR_RO (coredump );
541546
542547static ssize_t cmd_store (struct device * dev , struct device_attribute * attr ,
543548 const char * buf , size_t count )
544549{
545- if (sysfs_streq (buf , "reset" ))
546- schedule_work (& cvs -> rst_task );
547- else if (sysfs_streq (buf , "acquire" ))
550+ if (sysfs_streq (buf , "acquire" ))
548551 cvs_acquire_camera_sensor (NULL , NULL , NULL , NULL );
549552 else if (sysfs_streq (buf , "release" ))
550553 cvs_release_camera_sensor (NULL );
551554 else if (sysfs_streq (buf , "state" ))
552- cvs_get_state ( );
555+ cvs_exec_cmd ( GET_DEVICE_STATE );
553556 else if (sysfs_streq (buf , "version" ))
554557 cvs_exec_cmd (GET_FW_VERSION );
555558 else if (sysfs_streq (buf , "id" ))
556559 cvs_exec_cmd (GET_VID_PID );
557- else if (sysfs_streq (buf , "update" ))
558- pr_err ("%s:update not implemented\n" , __func__ );
559560 else
560561 pr_err ("%s:invalid %s command\n" , __func__ , buf );
561562
@@ -567,7 +568,7 @@ static ssize_t cmd_show(struct device *dev, struct device_attribute *attr,
567568{
568569 return sysfs_emit (
569570 buf , "command: %s\n" ,
570- "[coredump, reset, acquire, release, state, version, id, update ]" );
571+ "[coredump, acquire, release, state, version, id]" );
571572}
572573static DEVICE_ATTR_RW (cmd );
573574
@@ -587,6 +588,7 @@ static int cvs_suspend(struct device *dev)
587588 int ret = 0 ;
588589 u64 timeout ;
589590
591+ dev_info (icvs -> dev , "%s entered\n" , __func__ );
590592 /* Wait for FW update complete */
591593 if (icvs -> cap == ICVS_FULLCAP && cvs -> fw_dl_task_finished != true) {
592594 cvs -> close_fw_dl_task = true;
@@ -601,6 +603,7 @@ static int cvs_suspend(struct device *dev)
601603 ret = - EAGAIN ;
602604 }
603605 }
606+
604607 if (icvs -> cap == ICVS_FULLCAP ) {
605608 /* Disable wdt & IRQ */
606609 hrtimer_cancel (& icvs -> wdt );
@@ -617,6 +620,7 @@ static int cvs_resume(struct device *dev)
617620 struct intel_cvs * icvs = i2c_get_clientdata (i2c );
618621 int val = -1 , retry = FW_MAX_RETRY ;
619622
623+ dev_info (icvs -> dev , "%s entered\n" , __func__ );
620624 /* Wait for bridge ready */
621625 while (val < 0 && retry -- ) {
622626 val = gpiod_get_value_cansleep (cvs -> resp );
0 commit comments