[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250215-apple-codec-changes-v1-11-723569b21b19@gmail.com>
Date: Sat, 15 Feb 2025 10:02:44 +1000
From: James Calligeros <jcalligeros99@...il.com>
To: Liam Girdwood <lgirdwood@...il.com>, Mark Brown <broonie@...nel.org>,
Jaroslav Kysela <perex@...ex.cz>, Takashi Iwai <tiwai@...e.com>,
Shenghao Ding <shenghao-ding@...com>, Kevin Lu <kevin-lu@...com>,
Baojun Xu <baojun.xu@...com>, Dan Murphy <dmurphy@...com>,
Rob Herring <robh@...nel.org>, Krzysztof Kozlowski <krzk+dt@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Shi Fu <shifu0704@...ndersoft.com>
Cc: Alyssa Rosenzweig <alyssa@...enzweig.io>,
Martin Povišer <povik+lin@...ebit.org>,
Hector Martin <marcan@...can.st>, linux-sound@...r.kernel.org,
linux-kernel@...r.kernel.org, devicetree@...r.kernel.org,
asahi@...ts.linux.dev, James Calligeros <jcalligeros99@...il.com>
Subject: [PATCH 11/27] ASoC: tas2770: Export 'die_temp' to sysfs
From: Martin Povišer <povik+lin@...ebit.org>
Export a file for the readout of die temperature measurements.
As per the datasheet, the temperature can be calculated by
dividing the register value by 16 and then subtracting 93.
Signed-off-by: Martin Povišer <povik+lin@...ebit.org>
Signed-off-by: James Calligeros <jcalligeros99@...il.com>
---
sound/soc/codecs/tas2770.c | 57 +++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/sound/soc/codecs/tas2770.c b/sound/soc/codecs/tas2770.c
index 35a4d5a4a3e0cf4f71f81fd59f44f075c59cdbc1..9f3588ec117bb8ed0a6f2bbe5d7dc422862f052b 100644
--- a/sound/soc/codecs/tas2770.c
+++ b/sound/soc/codecs/tas2770.c
@@ -20,6 +20,7 @@
#include <linux/regmap.h>
#include <linux/of.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <sound/soc.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -491,6 +492,51 @@ static struct snd_soc_dai_driver tas2770_dai_driver[] = {
},
};
+static int tas2770_read_die_temp(struct tas2770_priv *tas2770, int *result)
+{
+ int ret, reading;
+
+ ret = snd_soc_component_read(tas2770->component, TAS2770_TEMP_MSB);
+ if (ret < 0)
+ return ret;
+ reading = ret << 4;
+
+ ret = snd_soc_component_read(tas2770->component, TAS2770_TEMP_LSB);
+ if (ret < 0)
+ return ret;
+ reading |= ret >> 4;
+
+ /*
+ * As per datasheet: divide register by 16 and subtract 93. We don't
+ * want to divide just yet though.
+ */
+ *result = reading - (93 * 16);
+ return 0;
+}
+
+static ssize_t die_temp_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct tas2770_priv *tas2770 = i2c_get_clientdata(to_i2c_client(dev));
+ int ret, temp;
+
+ ret = tas2770_read_die_temp(tas2770, &temp);
+
+ if (ret < 0)
+ return ret;
+
+ return sysfs_emit(buf, "%d.%03d C\n", temp / 16,
+ (temp * 1000 / 16) % 1000);
+}
+
+static DEVICE_ATTR_RO(die_temp);
+
+static struct attribute *tas2770_sysfs_attrs[] = {
+ &dev_attr_die_temp.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(tas2770_sysfs);
+
static const struct regmap_config tas2770_i2c_regmap;
static int tas2770_codec_probe(struct snd_soc_component *component)
@@ -517,9 +563,19 @@ static int tas2770_codec_probe(struct snd_soc_component *component)
return ret;
}
+ ret = sysfs_create_groups(&component->dev->kobj, tas2770_sysfs_groups);
+
+ if (ret < 0)
+ return ret;
+
return 0;
}
+static void tas2770_codec_remove(struct snd_soc_component *component)
+{
+ sysfs_remove_groups(&component->dev->kobj, tas2770_sysfs_groups);
+}
+
static DECLARE_TLV_DB_SCALE(tas2770_digital_tlv, 1100, 50, 0);
static DECLARE_TLV_DB_SCALE(tas2770_playback_volume, -12750, 50, 0);
@@ -532,6 +588,7 @@ static const struct snd_kcontrol_new tas2770_snd_controls[] = {
static const struct snd_soc_component_driver soc_component_driver_tas2770 = {
.probe = tas2770_codec_probe,
+ .remove = tas2770_codec_remove,
.suspend = tas2770_codec_suspend,
.resume = tas2770_codec_resume,
.controls = tas2770_snd_controls,
--
2.48.1
Powered by blists - more mailing lists