|
16 | 16 | #include <linux/of.h> |
17 | 17 | #include <linux/of_device.h> |
18 | 18 | #include <linux/slab.h> |
| 19 | +#include <linux/sysfs.h> |
19 | 20 | #include <sound/soc.h> |
20 | 21 | #include <sound/pcm.h> |
21 | 22 | #include <sound/pcm_params.h> |
@@ -567,6 +568,39 @@ static int tas2764_apply_unk_apple_quirk(struct snd_soc_component *component) |
567 | 568 | return 0; |
568 | 569 | } |
569 | 570 |
|
| 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 | + |
570 | 604 | static int tas2764_codec_probe(struct snd_soc_component *component) |
571 | 605 | { |
572 | 606 | struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component); |
@@ -657,9 +691,19 @@ static int tas2764_codec_probe(struct snd_soc_component *component) |
657 | 691 | } |
658 | 692 | } |
659 | 693 |
|
| 694 | + ret = sysfs_create_groups(&component->dev->kobj, tas2764_sysfs_groups); |
| 695 | + |
| 696 | + if (ret < 0) |
| 697 | + return ret; |
| 698 | + |
660 | 699 | return 0; |
661 | 700 | } |
662 | 701 |
|
| 702 | +static void tas2764_codec_remove(struct snd_soc_component *component) |
| 703 | +{ |
| 704 | + sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups); |
| 705 | +} |
| 706 | + |
663 | 707 | static DECLARE_TLV_DB_SCALE(tas2764_digital_tlv, 1100, 50, 0); |
664 | 708 | static DECLARE_TLV_DB_SCALE(tas2764_playback_volume, -10050, 50, 1); |
665 | 709 |
|
@@ -691,6 +735,7 @@ static const struct snd_kcontrol_new tas2764_snd_controls[] = { |
691 | 735 |
|
692 | 736 | static const struct snd_soc_component_driver soc_component_driver_tas2764 = { |
693 | 737 | .probe = tas2764_codec_probe, |
| 738 | + .remove = tas2764_codec_remove, |
694 | 739 | .suspend = tas2764_codec_suspend, |
695 | 740 | .resume = tas2764_codec_resume, |
696 | 741 | .controls = tas2764_snd_controls, |
|
0 commit comments