@@ -48,6 +48,65 @@ static DEVICE_ATTR_RO(power_on_acct);
48
48
static DEVICE_ATTR_RO (power_off_acct );
49
49
#endif /* CONFIG_PM */
50
50
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
+
51
110
#ifdef CONFIG_SND_HDA_RECONFIG
52
111
53
112
/*
@@ -111,34 +170,6 @@ static char *kstrndup_noeol(const char *src, size_t len)
111
170
return s ;
112
171
}
113
172
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
-
142
173
#define CODEC_INFO_STORE (type ) \
143
174
static ssize_t type##_store(struct device *dev, \
144
175
struct device_attribute *attr, \
@@ -344,29 +375,6 @@ static ssize_t hints_store(struct device *dev,
344
375
return count ;
345
376
}
346
377
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
-
370
378
static ssize_t user_pin_configs_show (struct device * dev ,
371
379
struct device_attribute * attr ,
372
380
char * buf )
@@ -375,14 +383,6 @@ static ssize_t user_pin_configs_show(struct device *dev,
375
383
return pin_configs_show (codec , & codec -> user_pins , buf );
376
384
}
377
385
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
-
386
386
#define MAX_PIN_CONFIGS 32
387
387
388
388
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,
410
410
return count ;
411
411
}
412
412
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 */
421
414
static DEVICE_ATTR_RW (init_verbs );
422
415
static DEVICE_ATTR_RW (hints );
423
- static DEVICE_ATTR_RO (init_pin_configs );
424
416
static DEVICE_ATTR_RW (user_pin_configs );
425
- static DEVICE_ATTR_RO (driver_pin_configs );
426
417
static DEVICE_ATTR_WO (reconfig );
427
418
static DEVICE_ATTR_WO (clear );
428
419
@@ -484,6 +475,26 @@ int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
484
475
EXPORT_SYMBOL_GPL (snd_hda_get_int_hint );
485
476
#endif /* CONFIG_SND_HDA_RECONFIG */
486
477
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
+
487
498
#ifdef CONFIG_SND_HDA_PATCH_LOADER
488
499
489
500
/* parser mode */
@@ -708,11 +719,6 @@ EXPORT_SYMBOL_GPL(snd_hda_load_patch);
708
719
* sysfs entries
709
720
*/
710
721
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
716
722
& dev_attr_vendor_id .attr ,
717
723
& dev_attr_subsystem_id .attr ,
718
724
& dev_attr_revision_id .attr ,
@@ -721,11 +727,16 @@ static struct attribute *hda_dev_attrs[] = {
721
727
& dev_attr_vendor_name .attr ,
722
728
& dev_attr_chip_name .attr ,
723
729
& 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
724
737
& dev_attr_init_verbs .attr ,
725
738
& dev_attr_hints .attr ,
726
- & dev_attr_init_pin_configs .attr ,
727
739
& dev_attr_user_pin_configs .attr ,
728
- & dev_attr_driver_pin_configs .attr ,
729
740
& dev_attr_reconfig .attr ,
730
741
& dev_attr_clear .attr ,
731
742
#endif
@@ -743,8 +754,8 @@ const struct attribute_group *snd_hda_dev_attr_groups[] = {
743
754
744
755
void snd_hda_sysfs_init (struct hda_codec * codec )
745
756
{
746
- #ifdef CONFIG_SND_HDA_RECONFIG
747
757
mutex_init (& codec -> user_mutex );
758
+ #ifdef CONFIG_SND_HDA_RECONFIG
748
759
snd_array_init (& codec -> init_verbs , sizeof (struct hda_verb ), 32 );
749
760
snd_array_init (& codec -> hints , sizeof (struct hda_hint ), 32 );
750
761
snd_array_init (& codec -> user_pins , sizeof (struct hda_pincfg ), 16 );
0 commit comments