Skip to content

Commit 7524980

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 7e19f89 commit 7524980

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
@@ -16,6 +16,7 @@
1616
#include <linux/of.h>
1717
#include <linux/of_device.h>
1818
#include <linux/slab.h>
19+
#include <linux/sysfs.h>
1920
#include <sound/soc.h>
2021
#include <sound/pcm.h>
2122
#include <sound/pcm_params.h>
@@ -567,6 +568,39 @@ static int tas2764_apply_unk_apple_quirk(struct snd_soc_component *component)
567568
return 0;
568569
}
569570

571+
static int tas2764_read_die_temp(struct tas2764_priv *tas2764, int *result)
572+
{
573+
int ret;
574+
575+
ret = snd_soc_component_read(tas2764->component, TAS2764_TEMP);
576+
if (ret < 0)
577+
return ret;
578+
*result = ret - 93;
579+
return 0;
580+
}
581+
582+
static ssize_t die_temp_show(struct device *dev,
583+
struct device_attribute *attr, char *buf)
584+
{
585+
struct tas2764_priv *tas2764 = i2c_get_clientdata(to_i2c_client(dev));
586+
int ret, temp;
587+
588+
ret = tas2764_read_die_temp(tas2764, &temp);
589+
590+
if (ret < 0)
591+
return ret;
592+
593+
return sysfs_emit(buf, "%d C\n", temp);
594+
}
595+
596+
static DEVICE_ATTR_RO(die_temp);
597+
598+
static struct attribute *tas2764_sysfs_attrs[] = {
599+
&dev_attr_die_temp.attr,
600+
NULL
601+
};
602+
ATTRIBUTE_GROUPS(tas2764_sysfs);
603+
570604
static int tas2764_codec_probe(struct snd_soc_component *component)
571605
{
572606
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
@@ -657,9 +691,19 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
657691
}
658692
}
659693

694+
ret = sysfs_create_groups(&component->dev->kobj, tas2764_sysfs_groups);
695+
696+
if (ret < 0)
697+
return ret;
698+
660699
return 0;
661700
}
662701

702+
static void tas2764_codec_remove(struct snd_soc_component *component)
703+
{
704+
sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups);
705+
}
706+
663707
static DECLARE_TLV_DB_SCALE(tas2764_digital_tlv, 1100, 50, 0);
664708
static DECLARE_TLV_DB_SCALE(tas2764_playback_volume, -10050, 50, 1);
665709

@@ -691,6 +735,7 @@ static const struct snd_kcontrol_new tas2764_snd_controls[] = {
691735

692736
static const struct snd_soc_component_driver soc_component_driver_tas2764 = {
693737
.probe = tas2764_codec_probe,
738+
.remove = tas2764_codec_remove,
694739
.suspend = tas2764_codec_suspend,
695740
.resume = tas2764_codec_resume,
696741
.controls = tas2764_snd_controls,

sound/soc/codecs/tas2764.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@
117117
#define TAS2764_INT_LTCH3 TAS2764_REG(0x0, 0x50)
118118
#define TAS2764_INT_LTCH4 TAS2764_REG(0x0, 0x51)
119119

120+
/* Readout Registers */
121+
#define TAS2764_TEMP TAS2764_REG(0x0, 0x56)
122+
120123
/* Clock/IRQ Settings */
121124
#define TAS2764_INT_CLK_CFG TAS2764_REG(0x0, 0x5c)
122125
#define TAS2764_INT_CLK_CFG_IRQZ_CLR BIT(2)

0 commit comments

Comments
 (0)