Skip to content

Commit ebd334c

Browse files
povikjannau
authored andcommitted
ASoC: tas2764: Export 'die_temp' to sysfs
Export a file for the readout of die temperature measurements. Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
1 parent 8c59e4c commit ebd334c

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

sound/soc/codecs/tas2764.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/of.h>
1818
#include <linux/of_device.h>
1919
#include <linux/slab.h>
20+
#include <linux/sysfs.h>
2021
#include <sound/soc.h>
2122
#include <sound/pcm.h>
2223
#include <sound/pcm_params.h>
@@ -560,6 +561,39 @@ static int tas2764_apply_unk_apple_quirk(struct snd_soc_component *component)
560561
return 0;
561562
}
562563

564+
static int tas2764_read_die_temp(struct tas2764_priv *tas2764, int *result)
565+
{
566+
int ret;
567+
568+
ret = snd_soc_component_read(tas2764->component, TAS2764_TEMP);
569+
if (ret < 0)
570+
return ret;
571+
*result = ret - 93;
572+
return 0;
573+
}
574+
575+
static ssize_t die_temp_show(struct device *dev,
576+
struct device_attribute *attr, char *buf)
577+
{
578+
struct tas2764_priv *tas2764 = i2c_get_clientdata(to_i2c_client(dev));
579+
int ret, temp;
580+
581+
ret = tas2764_read_die_temp(tas2764, &temp);
582+
583+
if (ret < 0)
584+
return ret;
585+
586+
return sysfs_emit(buf, "%d C\n", temp);
587+
}
588+
589+
static DEVICE_ATTR_RO(die_temp);
590+
591+
static struct attribute *tas2764_sysfs_attrs[] = {
592+
&dev_attr_die_temp.attr,
593+
NULL
594+
};
595+
ATTRIBUTE_GROUPS(tas2764_sysfs);
596+
563597
static int tas2764_codec_probe(struct snd_soc_component *component)
564598
{
565599
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
@@ -650,9 +684,19 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
650684
}
651685
}
652686

687+
ret = sysfs_create_groups(&component->dev->kobj, tas2764_sysfs_groups);
688+
689+
if (ret < 0)
690+
return ret;
691+
653692
return 0;
654693
}
655694

695+
static void tas2764_codec_remove(struct snd_soc_component *component)
696+
{
697+
sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups);
698+
}
699+
656700
static DECLARE_TLV_DB_SCALE(tas2764_digital_tlv, 1100, 50, 0);
657701
static DECLARE_TLV_DB_SCALE(tas2764_playback_volume, -10050, 50, 1);
658702

@@ -684,6 +728,7 @@ static const struct snd_kcontrol_new tas2764_snd_controls[] = {
684728

685729
static const struct snd_soc_component_driver soc_component_driver_tas2764 = {
686730
.probe = tas2764_codec_probe,
731+
.remove = tas2764_codec_remove,
687732
.suspend = tas2764_codec_suspend,
688733
.resume = tas2764_codec_resume,
689734
.controls = tas2764_snd_controls,

sound/soc/codecs/tas2764.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@
111111
#define TAS2764_INT_LTCH3 TAS2764_REG(0x0, 0x50)
112112
#define TAS2764_INT_LTCH4 TAS2764_REG(0x0, 0x51)
113113

114+
/* Readout Registers */
115+
#define TAS2764_TEMP TAS2764_REG(0x0, 0x56)
116+
114117
/* Clock/IRQ Settings */
115118
#define TAS2764_INT_CLK_CFG TAS2764_REG(0x0, 0x5c)
116119
#define TAS2764_INT_CLK_CFG_IRQZ_CLR BIT(2)

0 commit comments

Comments
 (0)