|
17 | 17 | #include <linux/of.h> |
18 | 18 | #include <linux/of_device.h> |
19 | 19 | #include <linux/slab.h> |
| 20 | +#include <linux/sysfs.h> |
20 | 21 | #include <sound/soc.h> |
21 | 22 | #include <sound/pcm.h> |
22 | 23 | #include <sound/pcm_params.h> |
@@ -560,6 +561,39 @@ static int tas2764_apply_unk_apple_quirk(struct snd_soc_component *component) |
560 | 561 | return 0; |
561 | 562 | } |
562 | 563 |
|
| 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 | + |
563 | 597 | static int tas2764_codec_probe(struct snd_soc_component *component) |
564 | 598 | { |
565 | 599 | struct tas2764_priv *tas2764 = snd_soc_component_get_drvdata(component); |
@@ -650,9 +684,19 @@ static int tas2764_codec_probe(struct snd_soc_component *component) |
650 | 684 | } |
651 | 685 | } |
652 | 686 |
|
| 687 | + ret = sysfs_create_groups(&component->dev->kobj, tas2764_sysfs_groups); |
| 688 | + |
| 689 | + if (ret < 0) |
| 690 | + return ret; |
| 691 | + |
653 | 692 | return 0; |
654 | 693 | } |
655 | 694 |
|
| 695 | +static void tas2764_codec_remove(struct snd_soc_component *component) |
| 696 | +{ |
| 697 | + sysfs_remove_groups(&component->dev->kobj, tas2764_sysfs_groups); |
| 698 | +} |
| 699 | + |
656 | 700 | static DECLARE_TLV_DB_SCALE(tas2764_digital_tlv, 1100, 50, 0); |
657 | 701 | static DECLARE_TLV_DB_SCALE(tas2764_playback_volume, -10050, 50, 1); |
658 | 702 |
|
@@ -684,6 +728,7 @@ static const struct snd_kcontrol_new tas2764_snd_controls[] = { |
684 | 728 |
|
685 | 729 | static const struct snd_soc_component_driver soc_component_driver_tas2764 = { |
686 | 730 | .probe = tas2764_codec_probe, |
| 731 | + .remove = tas2764_codec_remove, |
687 | 732 | .suspend = tas2764_codec_suspend, |
688 | 733 | .resume = tas2764_codec_resume, |
689 | 734 | .controls = tas2764_snd_controls, |
|
0 commit comments