@@ -16,6 +16,7 @@
#include <linux/of.h>
#include <linux/of_device.h>
#include <linux/slab.h>
+#include <linux/sysfs.h>
#include <sound/soc.h>
#include <sound/pcm.h>
#include <sound/pcm_params.h>
@@ -571,6 +572,39 @@ static int tas2764_apply_init_quirks(struct tas2764_priv *tas2764)
return 0;
}
+static int tas2764_read_die_temp(struct tas2764_priv *tas2764, int *result)
+{
+ int ret;
+
+ ret = snd_soc_component_read(tas2764->component, TAS2764_TEMP);
+ if (ret < 0)
+ return ret;
+ *result = ret - 93;
+ return 0;
+}
+
+static ssize_t die_temp_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct tas2764_priv *tas2764 = i2c_get_clientdata(to_i2c_client(dev));
+ int ret, temp;
+
+ ret = tas2764_read_die_temp(tas2764, &temp);
+
+ if (ret < 0)
+ return ret;
+
+ return sysfs_emit(buf, "%d C\n", temp);
+}
+
+static DEVICE_ATTR_RO(die_temp);
+
+static struct attribute *tas2764_sysfs_attrs[] = {
+ &dev_attr_die_temp.attr,
+ NULL
+};
+ATTRIBUTE_GROUPS(tas2764_sysfs);
+
static int tas2764_codec_probe(struct snd_soc_component *component)
{
struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component);
@@ -664,9 +698,19 @@ static int tas2764_codec_probe(struct snd_soc_component *component)
return ret;
}
+ ret = sysfs_create_groups(&component->dev->kobj, tas2764_sysfs_groups);
+
+ if (ret < 0)
+ return ret;
+
return 0;
}
+static void tas2764_codec_remove(struct snd_soc_component *component)
+{
+ sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups);
+}
+
static DECLARE_TLV_DB_SCALE(tas2764_digital_tlv, 1100, 50, 0);
static DECLARE_TLV_DB_SCALE(tas2764_playback_volume, -10050, 50, 1);
@@ -698,6 +742,7 @@ static const struct snd_kcontrol_new tas2764_snd_controls[] = {
static const struct snd_soc_component_driver soc_component_driver_tas2764 = {
.probe = tas2764_codec_probe,
+ .remove = tas2764_codec_remove,
.suspend = tas2764_codec_suspend,
.resume = tas2764_codec_resume,
.controls = tas2764_snd_controls,
@@ -111,6 +111,9 @@
#define TAS2764_INT_LTCH3 TAS2764_REG(0x0, 0x50)
#define TAS2764_INT_LTCH4 TAS2764_REG(0x0, 0x51)
+/* Readout Registers */
+#define TAS2764_TEMP TAS2764_REG(0x0, 0x56)
+
/* Clock/IRQ Settings */
#define TAS2764_INT_CLK_CFG TAS2764_REG(0x0, 0x5c)
#define TAS2764_INT_CLK_CFG_IRQZ_CLR BIT(2)