@@ -477,6 +477,80 @@ static ssize_t enable_tgu_store(struct device *dev,
477477}
478478static DEVICE_ATTR_RW (enable_tgu );
479479
480+ /* reset_tgu_store - Reset Trace and Gating Unit (TGU) configuration. */
481+ static ssize_t reset_tgu_store (struct device * dev ,
482+ struct device_attribute * attr , const char * buf ,
483+ size_t size )
484+ {
485+ unsigned long value ;
486+ struct tgu_drvdata * drvdata = dev_get_drvdata (dev -> parent );
487+ int i , j , ret ;
488+
489+ if (kstrtoul (buf , 0 , & value ) || value == 0 )
490+ return - EINVAL ;
491+
492+ if (!drvdata -> enable ) {
493+ ret = pm_runtime_get_sync (drvdata -> dev );
494+ if (ret < 0 ) {
495+ pm_runtime_put (drvdata -> dev );
496+ return ret ;
497+ }
498+ }
499+
500+ spin_lock (& drvdata -> spinlock );
501+ CS_UNLOCK (drvdata -> base );
502+
503+ tgu_writel (drvdata , 0 , TGU_CONTROL );
504+
505+ if (drvdata -> value_table -> priority )
506+ memset (drvdata -> value_table -> priority , 0 ,
507+ MAX_PRIORITY * drvdata -> max_step *
508+ drvdata -> max_reg * sizeof (unsigned int ));
509+
510+ if (drvdata -> value_table -> condition_decode )
511+ memset (drvdata -> value_table -> condition_decode , 0 ,
512+ drvdata -> max_condition_decode * drvdata -> max_step *
513+ sizeof (unsigned int ));
514+
515+ /* Initialize all condition registers to NOT(value=0x1000000) */
516+ for (i = 0 ; i < drvdata -> max_step ; i ++ ) {
517+ for (j = 0 ; j < drvdata -> max_condition_decode ; j ++ ) {
518+ drvdata -> value_table
519+ -> condition_decode [calculate_array_location (
520+ drvdata , i , TGU_CONDITION_DECODE , j )] =
521+ 0x1000000 ;
522+ }
523+ }
524+
525+ if (drvdata -> value_table -> condition_select )
526+ memset (drvdata -> value_table -> condition_select , 0 ,
527+ drvdata -> max_condition_select * drvdata -> max_step *
528+ sizeof (unsigned int ));
529+
530+ if (drvdata -> value_table -> timer )
531+ memset (drvdata -> value_table -> timer , 0 ,
532+ (drvdata -> max_step ) *
533+ (drvdata -> max_timer ) *
534+ sizeof (unsigned int ));
535+
536+ if (drvdata -> value_table -> counter )
537+ memset (drvdata -> value_table -> counter , 0 ,
538+ (drvdata -> max_step ) *
539+ (drvdata -> max_counter ) *
540+ sizeof (unsigned int ));
541+
542+ dev_dbg (dev , "Coresight-TGU reset complete\n" );
543+
544+ CS_LOCK (drvdata -> base );
545+
546+ drvdata -> enable = false;
547+ spin_unlock (& drvdata -> spinlock );
548+ pm_runtime_put (drvdata -> dev );
549+
550+ return size ;
551+ }
552+ static DEVICE_ATTR_WO (reset_tgu );
553+
480554static const struct coresight_ops_helper tgu_helper_ops = {
481555 .enable = tgu_enable ,
482556 .disable = tgu_disable ,
@@ -488,6 +562,7 @@ static const struct coresight_ops tgu_ops = {
488562
489563static struct attribute * tgu_common_attrs [] = {
490564 & dev_attr_enable_tgu .attr ,
565+ & dev_attr_reset_tgu .attr ,
491566 NULL ,
492567};
493568
0 commit comments