Skip to content

Commit b989d04

Browse files
committed
ALSA: hda - Enable sysfs attributes without CONFIG_SND_HDA_RECONFIG
Some sysfs attributes like init_pin_configs or vendor_name are really basic and should be available no matter whether the codec driver is re-configurable or not. Put them out of #ifdef CONFIG_SND_HDA_RECONFIG and allow the read-only accesses. Signed-off-by: Takashi Iwai <[email protected]>
1 parent 648a8d2 commit b989d04

File tree

2 files changed

+89
-78
lines changed

2 files changed

+89
-78
lines changed

sound/pci/hda/hda_codec.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,8 @@ struct hda_codec {
333333
struct snd_array driver_pins; /* pin configs set by codec parser */
334334
struct snd_array cvt_setups; /* audio convert setups */
335335

336-
#ifdef CONFIG_SND_HDA_RECONFIG
337336
struct mutex user_mutex;
337+
#ifdef CONFIG_SND_HDA_RECONFIG
338338
struct snd_array init_verbs; /* additional init verbs */
339339
struct snd_array hints; /* additional hints */
340340
struct snd_array user_pins; /* default pin configs to override */

sound/pci/hda/hda_sysfs.c

Lines changed: 88 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,65 @@ static DEVICE_ATTR_RO(power_on_acct);
4848
static DEVICE_ATTR_RO(power_off_acct);
4949
#endif /* CONFIG_PM */
5050

51+
#define CODEC_INFO_SHOW(type) \
52+
static ssize_t type##_show(struct device *dev, \
53+
struct device_attribute *attr, \
54+
char *buf) \
55+
{ \
56+
struct hda_codec *codec = dev_get_drvdata(dev); \
57+
return sprintf(buf, "0x%x\n", codec->type); \
58+
}
59+
60+
#define CODEC_INFO_STR_SHOW(type) \
61+
static ssize_t type##_show(struct device *dev, \
62+
struct device_attribute *attr, \
63+
char *buf) \
64+
{ \
65+
struct hda_codec *codec = dev_get_drvdata(dev); \
66+
return sprintf(buf, "%s\n", \
67+
codec->type ? codec->type : ""); \
68+
}
69+
70+
CODEC_INFO_SHOW(vendor_id);
71+
CODEC_INFO_SHOW(subsystem_id);
72+
CODEC_INFO_SHOW(revision_id);
73+
CODEC_INFO_SHOW(afg);
74+
CODEC_INFO_SHOW(mfg);
75+
CODEC_INFO_STR_SHOW(vendor_name);
76+
CODEC_INFO_STR_SHOW(chip_name);
77+
CODEC_INFO_STR_SHOW(modelname);
78+
79+
static ssize_t pin_configs_show(struct hda_codec *codec,
80+
struct snd_array *list,
81+
char *buf)
82+
{
83+
int i, len = 0;
84+
mutex_lock(&codec->user_mutex);
85+
for (i = 0; i < list->used; i++) {
86+
struct hda_pincfg *pin = snd_array_elem(list, i);
87+
len += sprintf(buf + len, "0x%02x 0x%08x\n",
88+
pin->nid, pin->cfg);
89+
}
90+
mutex_unlock(&codec->user_mutex);
91+
return len;
92+
}
93+
94+
static ssize_t init_pin_configs_show(struct device *dev,
95+
struct device_attribute *attr,
96+
char *buf)
97+
{
98+
struct hda_codec *codec = dev_get_drvdata(dev);
99+
return pin_configs_show(codec, &codec->init_pins, buf);
100+
}
101+
102+
static ssize_t driver_pin_configs_show(struct device *dev,
103+
struct device_attribute *attr,
104+
char *buf)
105+
{
106+
struct hda_codec *codec = dev_get_drvdata(dev);
107+
return pin_configs_show(codec, &codec->driver_pins, buf);
108+
}
109+
51110
#ifdef CONFIG_SND_HDA_RECONFIG
52111

53112
/*
@@ -111,34 +170,6 @@ static char *kstrndup_noeol(const char *src, size_t len)
111170
return s;
112171
}
113172

114-
#define CODEC_INFO_SHOW(type) \
115-
static ssize_t type##_show(struct device *dev, \
116-
struct device_attribute *attr, \
117-
char *buf) \
118-
{ \
119-
struct hda_codec *codec = dev_get_drvdata(dev); \
120-
return sprintf(buf, "0x%x\n", codec->type); \
121-
}
122-
123-
#define CODEC_INFO_STR_SHOW(type) \
124-
static ssize_t type##_show(struct device *dev, \
125-
struct device_attribute *attr, \
126-
char *buf) \
127-
{ \
128-
struct hda_codec *codec = dev_get_drvdata(dev); \
129-
return sprintf(buf, "%s\n", \
130-
codec->type ? codec->type : ""); \
131-
}
132-
133-
CODEC_INFO_SHOW(vendor_id);
134-
CODEC_INFO_SHOW(subsystem_id);
135-
CODEC_INFO_SHOW(revision_id);
136-
CODEC_INFO_SHOW(afg);
137-
CODEC_INFO_SHOW(mfg);
138-
CODEC_INFO_STR_SHOW(vendor_name);
139-
CODEC_INFO_STR_SHOW(chip_name);
140-
CODEC_INFO_STR_SHOW(modelname);
141-
142173
#define CODEC_INFO_STORE(type) \
143174
static ssize_t type##_store(struct device *dev, \
144175
struct device_attribute *attr, \
@@ -344,29 +375,6 @@ static ssize_t hints_store(struct device *dev,
344375
return count;
345376
}
346377

347-
static ssize_t pin_configs_show(struct hda_codec *codec,
348-
struct snd_array *list,
349-
char *buf)
350-
{
351-
int i, len = 0;
352-
mutex_lock(&codec->user_mutex);
353-
for (i = 0; i < list->used; i++) {
354-
struct hda_pincfg *pin = snd_array_elem(list, i);
355-
len += sprintf(buf + len, "0x%02x 0x%08x\n",
356-
pin->nid, pin->cfg);
357-
}
358-
mutex_unlock(&codec->user_mutex);
359-
return len;
360-
}
361-
362-
static ssize_t init_pin_configs_show(struct device *dev,
363-
struct device_attribute *attr,
364-
char *buf)
365-
{
366-
struct hda_codec *codec = dev_get_drvdata(dev);
367-
return pin_configs_show(codec, &codec->init_pins, buf);
368-
}
369-
370378
static ssize_t user_pin_configs_show(struct device *dev,
371379
struct device_attribute *attr,
372380
char *buf)
@@ -375,14 +383,6 @@ static ssize_t user_pin_configs_show(struct device *dev,
375383
return pin_configs_show(codec, &codec->user_pins, buf);
376384
}
377385

378-
static ssize_t driver_pin_configs_show(struct device *dev,
379-
struct device_attribute *attr,
380-
char *buf)
381-
{
382-
struct hda_codec *codec = dev_get_drvdata(dev);
383-
return pin_configs_show(codec, &codec->driver_pins, buf);
384-
}
385-
386386
#define MAX_PIN_CONFIGS 32
387387

388388
static int parse_user_pin_configs(struct hda_codec *codec, const char *buf)
@@ -410,19 +410,10 @@ static ssize_t user_pin_configs_store(struct device *dev,
410410
return count;
411411
}
412412

413-
static DEVICE_ATTR_RW(vendor_id);
414-
static DEVICE_ATTR_RW(subsystem_id);
415-
static DEVICE_ATTR_RW(revision_id);
416-
static DEVICE_ATTR_RO(afg);
417-
static DEVICE_ATTR_RO(mfg);
418-
static DEVICE_ATTR_RW(vendor_name);
419-
static DEVICE_ATTR_RW(chip_name);
420-
static DEVICE_ATTR_RW(modelname);
413+
/* sysfs attributes exposed only when CONFIG_SND_HDA_RECONFIG=y */
421414
static DEVICE_ATTR_RW(init_verbs);
422415
static DEVICE_ATTR_RW(hints);
423-
static DEVICE_ATTR_RO(init_pin_configs);
424416
static DEVICE_ATTR_RW(user_pin_configs);
425-
static DEVICE_ATTR_RO(driver_pin_configs);
426417
static DEVICE_ATTR_WO(reconfig);
427418
static DEVICE_ATTR_WO(clear);
428419

@@ -484,6 +475,26 @@ int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
484475
EXPORT_SYMBOL_GPL(snd_hda_get_int_hint);
485476
#endif /* CONFIG_SND_HDA_RECONFIG */
486477

478+
/*
479+
* common sysfs attributes
480+
*/
481+
#ifdef CONFIG_SND_HDA_RECONFIG
482+
#define RECONFIG_DEVICE_ATTR(name) DEVICE_ATTR_RW(name)
483+
#else
484+
#define RECONFIG_DEVICE_ATTR(name) DEVICE_ATTR_RO(name)
485+
#endif
486+
static RECONFIG_DEVICE_ATTR(vendor_id);
487+
static RECONFIG_DEVICE_ATTR(subsystem_id);
488+
static RECONFIG_DEVICE_ATTR(revision_id);
489+
static DEVICE_ATTR_RO(afg);
490+
static DEVICE_ATTR_RO(mfg);
491+
static RECONFIG_DEVICE_ATTR(vendor_name);
492+
static RECONFIG_DEVICE_ATTR(chip_name);
493+
static RECONFIG_DEVICE_ATTR(modelname);
494+
static DEVICE_ATTR_RO(init_pin_configs);
495+
static DEVICE_ATTR_RO(driver_pin_configs);
496+
497+
487498
#ifdef CONFIG_SND_HDA_PATCH_LOADER
488499

489500
/* parser mode */
@@ -708,11 +719,6 @@ EXPORT_SYMBOL_GPL(snd_hda_load_patch);
708719
* sysfs entries
709720
*/
710721
static struct attribute *hda_dev_attrs[] = {
711-
#ifdef CONFIG_PM
712-
&dev_attr_power_on_acct.attr,
713-
&dev_attr_power_off_acct.attr,
714-
#endif
715-
#ifdef CONFIG_SND_HDA_RECONFIG
716722
&dev_attr_vendor_id.attr,
717723
&dev_attr_subsystem_id.attr,
718724
&dev_attr_revision_id.attr,
@@ -721,11 +727,16 @@ static struct attribute *hda_dev_attrs[] = {
721727
&dev_attr_vendor_name.attr,
722728
&dev_attr_chip_name.attr,
723729
&dev_attr_modelname.attr,
730+
&dev_attr_init_pin_configs.attr,
731+
&dev_attr_driver_pin_configs.attr,
732+
#ifdef CONFIG_PM
733+
&dev_attr_power_on_acct.attr,
734+
&dev_attr_power_off_acct.attr,
735+
#endif
736+
#ifdef CONFIG_SND_HDA_RECONFIG
724737
&dev_attr_init_verbs.attr,
725738
&dev_attr_hints.attr,
726-
&dev_attr_init_pin_configs.attr,
727739
&dev_attr_user_pin_configs.attr,
728-
&dev_attr_driver_pin_configs.attr,
729740
&dev_attr_reconfig.attr,
730741
&dev_attr_clear.attr,
731742
#endif
@@ -743,8 +754,8 @@ const struct attribute_group *snd_hda_dev_attr_groups[] = {
743754

744755
void snd_hda_sysfs_init(struct hda_codec *codec)
745756
{
746-
#ifdef CONFIG_SND_HDA_RECONFIG
747757
mutex_init(&codec->user_mutex);
758+
#ifdef CONFIG_SND_HDA_RECONFIG
748759
snd_array_init(&codec->init_verbs, sizeof(struct hda_verb), 32);
749760
snd_array_init(&codec->hints, sizeof(struct hda_hint), 32);
750761
snd_array_init(&codec->user_pins, sizeof(struct hda_pincfg), 16);

0 commit comments

Comments
 (0)