@@ -626,18 +626,33 @@ static int tas2764_read_die_temp(struct tas2764_priv *tas2764, long *result)
626626 * As per datasheet, subtract 93 from raw value to get degrees
627627 * Celsius. hwmon wants millidegrees.
628628 *
629- * NOTE: The chip will initialise the TAS2764_TEMP register to
630- * 2.6 *C to avoid triggering temperature protection. Since the
631- * ADC is powered down during software shutdown, this value will
632- * persist until the chip is fully powered up (e.g. the PCM it's
633- * attached to is opened). The ADC will power down again when
634- * the chip is put back into software shutdown, with the last
635- * value sampled persisting in the ADC's register.
629+ * NOTE: The TAS2764 datasheet mentions initialising TAS2764_TEMP
630+ * such that the temperature is 2.6 *C, however the register
631+ * is actually initialised to 0. The ADC is also powered down during
632+ * software shutdown. The last sampled temperature will persist
633+ * in the register while the amp is in this power state.
636634 */
635+ if (reg == 0 )
636+ return - ENODATA ;
637+
637638 * result = (reg - 93 ) * 1000 ;
638639 return 0 ;
639640}
640641
642+ static int tas2764_hwmon_is_fault (struct tas2764_priv * tas2764 , long * result )
643+ {
644+ int ret ;
645+ long temp ;
646+
647+ ret = tas2764_read_die_temp (tas2764 , & temp );
648+ if (ret == - ENODATA ) {
649+ * result = true;
650+ return 0 ;
651+ }
652+
653+ return ret ;
654+ }
655+
641656static umode_t tas2764_hwmon_is_visible (const void * data ,
642657 enum hwmon_sensor_types type , u32 attr ,
643658 int channel )
@@ -647,6 +662,7 @@ static umode_t tas2764_hwmon_is_visible(const void *data,
647662
648663 switch (attr ) {
649664 case hwmon_temp_input :
665+ case hwmon_temp_fault :
650666 return 0444 ;
651667 default :
652668 break ;
@@ -666,6 +682,9 @@ static int tas2764_hwmon_read(struct device *dev,
666682 case hwmon_temp_input :
667683 ret = tas2764_read_die_temp (tas2764 , val );
668684 break ;
685+ case hwmon_temp_fault :
686+ ret = tas2764_hwmon_is_fault (tas2764 , val );
687+ break ;
669688 default :
670689 ret = - EOPNOTSUPP ;
671690 break ;
@@ -675,7 +694,7 @@ static int tas2764_hwmon_read(struct device *dev,
675694}
676695
677696static const struct hwmon_channel_info * const tas2764_hwmon_info [] = {
678- HWMON_CHANNEL_INFO (temp , HWMON_T_INPUT ),
697+ HWMON_CHANNEL_INFO (temp , HWMON_T_INPUT | HWMON_T_FAULT ),
679698 NULL
680699};
681700
@@ -876,6 +895,7 @@ static bool tas2764_volatile_register(struct device *dev, unsigned int reg)
876895{
877896 switch (reg ) {
878897 case TAS2764_SW_RST :
898+ case TAS2764_TEMP :
879899 case TAS2764_INT_LTCH0 ... TAS2764_INT_LTCH4 :
880900 case TAS2764_INT_CLK_CFG :
881901 return true;
0 commit comments