aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2015-02-17 15:46:37 -0500
committerTakashi Iwai <tiwai@suse.de>2015-03-23 08:15:51 -0400
commite3d280fc6d42017b2379503fbda83655a05294fe (patch)
treecc89c4b22054d620163f0d6bdad901f43957dbf5
parent3372dbdd8ca11f51be8c6a30b2bc79eb04c4a902 (diff)
ALSA: hda - Make snd_hda_bus_type public
Define the common hd-audio driver and device types to bind over snd_hda_bus_type publicly. This allows to implement other type of device and driver code over hd-audio bus. Now both struct hda_codec and struct hda_codec_driver inherit these new struct hdac_device and struct hdac_driver, respectively. The bus registration is done in subsys_initcall() to assure it before any other driver registrations. Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--include/sound/hdaudio.h42
-rw-r--r--sound/Kconfig2
-rw-r--r--sound/Makefile2
-rw-r--r--sound/hda/Kconfig2
-rw-r--r--sound/hda/Makefile3
-rw-r--r--sound/hda/hda_bus_type.c42
-rw-r--r--sound/pci/hda/Kconfig1
-rw-r--r--sound/pci/hda/hda_bind.c47
-rw-r--r--sound/pci/hda/hda_codec.c1
-rw-r--r--sound/pci/hda/hda_codec.h11
10 files changed, 113 insertions, 40 deletions
diff --git a/include/sound/hdaudio.h b/include/sound/hdaudio.h
new file mode 100644
index 000000000000..2381509bee9f
--- /dev/null
+++ b/include/sound/hdaudio.h
@@ -0,0 +1,42 @@
1/*
2 * HD-audio core stuff
3 */
4
5#ifndef __SOUND_HDAUDIO_H
6#define __SOUND_HDAUDIO_H
7
8#include <linux/device.h>
9
10/*
11 * exported bus type
12 */
13extern struct bus_type snd_hda_bus_type;
14
15/*
16 * HD-audio codec base device
17 */
18struct hdac_device {
19 struct device dev;
20 int type;
21};
22
23/* device/driver type used for matching */
24enum {
25 HDA_DEV_CORE,
26 HDA_DEV_LEGACY,
27};
28
29#define dev_to_hdac_dev(_dev) container_of(_dev, struct hdac_device, dev)
30
31/*
32 * HD-audio codec base driver
33 */
34struct hdac_driver {
35 struct device_driver driver;
36 int type;
37 int (*match)(struct hdac_device *dev, struct hdac_driver *drv);
38};
39
40#define drv_to_hdac_driver(_drv) container_of(_drv, struct hdac_driver, driver)
41
42#endif /* __SOUND_HDAUDIO_H */
diff --git a/sound/Kconfig b/sound/Kconfig
index c710ce2c5c37..5a240e050ae6 100644
--- a/sound/Kconfig
+++ b/sound/Kconfig
@@ -76,6 +76,8 @@ source "sound/isa/Kconfig"
76 76
77source "sound/pci/Kconfig" 77source "sound/pci/Kconfig"
78 78
79source "sound/hda/Kconfig"
80
79source "sound/ppc/Kconfig" 81source "sound/ppc/Kconfig"
80 82
81source "sound/aoa/Kconfig" 83source "sound/aoa/Kconfig"
diff --git a/sound/Makefile b/sound/Makefile
index ce9132b1c395..77320709fd26 100644
--- a/sound/Makefile
+++ b/sound/Makefile
@@ -6,7 +6,7 @@ obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o
6obj-$(CONFIG_SOUND_PRIME) += oss/ 6obj-$(CONFIG_SOUND_PRIME) += oss/
7obj-$(CONFIG_DMASOUND) += oss/ 7obj-$(CONFIG_DMASOUND) += oss/
8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \ 8obj-$(CONFIG_SND) += core/ i2c/ drivers/ isa/ pci/ ppc/ arm/ sh/ synth/ usb/ \
9 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ 9 firewire/ sparc/ spi/ parisc/ pcmcia/ mips/ soc/ atmel/ hda/
10obj-$(CONFIG_SND_AOA) += aoa/ 10obj-$(CONFIG_SND_AOA) += aoa/
11 11
12# This one must be compilable even if sound is configured out 12# This one must be compilable even if sound is configured out
diff --git a/sound/hda/Kconfig b/sound/hda/Kconfig
new file mode 100644
index 000000000000..4f428ccf64ad
--- /dev/null
+++ b/sound/hda/Kconfig
@@ -0,0 +1,2 @@
1config SND_HDA_CORE
2 tristate
diff --git a/sound/hda/Makefile b/sound/hda/Makefile
new file mode 100644
index 000000000000..59c8d1feb5aa
--- /dev/null
+++ b/sound/hda/Makefile
@@ -0,0 +1,3 @@
1snd-hda-core-objs := hda_bus_type.o
2
3obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o
diff --git a/sound/hda/hda_bus_type.c b/sound/hda/hda_bus_type.c
new file mode 100644
index 000000000000..519914a12e8a
--- /dev/null
+++ b/sound/hda/hda_bus_type.c
@@ -0,0 +1,42 @@
1/*
2 * HD-audio bus
3 */
4#include <linux/init.h>
5#include <linux/device.h>
6#include <linux/module.h>
7#include <linux/export.h>
8#include <sound/hdaudio.h>
9
10MODULE_DESCRIPTION("HD-audio bus");
11MODULE_LICENSE("GPL");
12
13static int hda_bus_match(struct device *dev, struct device_driver *drv)
14{
15 struct hdac_device *hdev = dev_to_hdac_dev(dev);
16 struct hdac_driver *hdrv = drv_to_hdac_driver(drv);
17
18 if (hdev->type != hdrv->type)
19 return 0;
20 if (hdrv->match)
21 return hdrv->match(hdev, hdrv);
22 return 1;
23}
24
25struct bus_type snd_hda_bus_type = {
26 .name = "hdaudio",
27 .match = hda_bus_match,
28};
29EXPORT_SYMBOL_GPL(snd_hda_bus_type);
30
31static int __init hda_bus_init(void)
32{
33 return bus_register(&snd_hda_bus_type);
34}
35
36static void __exit hda_bus_exit(void)
37{
38 bus_unregister(&snd_hda_bus_type);
39}
40
41subsys_initcall(hda_bus_init);
42module_exit(hda_bus_exit);
diff --git a/sound/pci/hda/Kconfig b/sound/pci/hda/Kconfig
index 7f0f2c5a4e97..a5ed1c181784 100644
--- a/sound/pci/hda/Kconfig
+++ b/sound/pci/hda/Kconfig
@@ -5,6 +5,7 @@ config SND_HDA
5 select SND_PCM 5 select SND_PCM
6 select SND_VMASTER 6 select SND_VMASTER
7 select SND_KCTL_JACK 7 select SND_KCTL_JACK
8 select SND_HDA_CORE
8 9
9config SND_HDA_INTEL 10config SND_HDA_INTEL
10 tristate "HD Audio PCI" 11 tristate "HD Audio PCI"
diff --git a/sound/pci/hda/hda_bind.c b/sound/pci/hda/hda_bind.c
index 1f40ce3c1696..e3bd2807b644 100644
--- a/sound/pci/hda/hda_bind.c
+++ b/sound/pci/hda/hda_bind.c
@@ -47,11 +47,11 @@ static struct hda_vendor_id hda_vendor_ids[] = {
47/* 47/*
48 * find a matching codec preset 48 * find a matching codec preset
49 */ 49 */
50static int hda_bus_match(struct device *dev, struct device_driver *drv) 50static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
51{ 51{
52 struct hda_codec *codec = container_of(dev, struct hda_codec, dev); 52 struct hda_codec *codec = container_of(dev, struct hda_codec, core);
53 struct hda_codec_driver *driver = 53 struct hda_codec_driver *driver =
54 container_of(drv, struct hda_codec_driver, driver); 54 container_of(drv, struct hda_codec_driver, core);
55 const struct hda_codec_preset *preset; 55 const struct hda_codec_preset *preset;
56 /* check probe_id instead of vendor_id if set */ 56 /* check probe_id instead of vendor_id if set */
57 u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id; 57 u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id;
@@ -154,20 +154,22 @@ static void hda_codec_driver_shutdown(struct device *dev)
154int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name, 154int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
155 struct module *owner) 155 struct module *owner)
156{ 156{
157 drv->driver.name = name; 157 drv->core.driver.name = name;
158 drv->driver.owner = owner; 158 drv->core.driver.owner = owner;
159 drv->driver.bus = &snd_hda_bus_type; 159 drv->core.driver.bus = &snd_hda_bus_type;
160 drv->driver.probe = hda_codec_driver_probe; 160 drv->core.driver.probe = hda_codec_driver_probe;
161 drv->driver.remove = hda_codec_driver_remove; 161 drv->core.driver.remove = hda_codec_driver_remove;
162 drv->driver.shutdown = hda_codec_driver_shutdown; 162 drv->core.driver.shutdown = hda_codec_driver_shutdown;
163 drv->driver.pm = &hda_codec_driver_pm; 163 drv->core.driver.pm = &hda_codec_driver_pm;
164 return driver_register(&drv->driver); 164 drv->core.type = HDA_DEV_LEGACY;
165 drv->core.match = hda_codec_match;
166 return driver_register(&drv->core.driver);
165} 167}
166EXPORT_SYMBOL_GPL(__hda_codec_driver_register); 168EXPORT_SYMBOL_GPL(__hda_codec_driver_register);
167 169
168void hda_codec_driver_unregister(struct hda_codec_driver *drv) 170void hda_codec_driver_unregister(struct hda_codec_driver *drv)
169{ 171{
170 driver_unregister(&drv->driver); 172 driver_unregister(&drv->core.driver);
171} 173}
172EXPORT_SYMBOL_GPL(hda_codec_driver_unregister); 174EXPORT_SYMBOL_GPL(hda_codec_driver_unregister);
173 175
@@ -319,24 +321,3 @@ int snd_hda_codec_configure(struct hda_codec *codec)
319 return err; 321 return err;
320} 322}
321EXPORT_SYMBOL_GPL(snd_hda_codec_configure); 323EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
322
323/*
324 * bus registration
325 */
326struct bus_type snd_hda_bus_type = {
327 .name = "hdaudio",
328 .match = hda_bus_match,
329};
330
331static int __init hda_codec_init(void)
332{
333 return bus_register(&snd_hda_bus_type);
334}
335
336static void __exit hda_codec_exit(void)
337{
338 bus_unregister(&snd_hda_bus_type);
339}
340
341module_init(hda_codec_init);
342module_exit(hda_codec_exit);
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 7e38d6f7314b..e14f9f562874 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -1294,6 +1294,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
1294 dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr); 1294 dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr);
1295 dev_set_drvdata(dev, codec); /* for sysfs */ 1295 dev_set_drvdata(dev, codec); /* for sysfs */
1296 device_enable_async_suspend(dev); 1296 device_enable_async_suspend(dev);
1297 codec->core.type = HDA_DEV_LEGACY;
1297 1298
1298 codec->bus = bus; 1299 codec->bus = bus;
1299 codec->card = card; 1300 codec->card = card;
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index ccf355d4a8fa..31a9e10e5137 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -26,6 +26,7 @@
26#include <sound/control.h> 26#include <sound/control.h>
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/hwdep.h> 28#include <sound/hwdep.h>
29#include <sound/hdaudio.h>
29#include <sound/hda_verbs.h> 30#include <sound/hda_verbs.h>
30 31
31/* 32/*
@@ -172,7 +173,7 @@ struct hda_codec_preset {
172#define HDA_CODEC_ID_GENERIC 0x00000201 173#define HDA_CODEC_ID_GENERIC 0x00000201
173 174
174struct hda_codec_driver { 175struct hda_codec_driver {
175 struct device_driver driver; 176 struct hdac_driver core;
176 const struct hda_codec_preset *preset; 177 const struct hda_codec_preset *preset;
177}; 178};
178 179
@@ -276,7 +277,7 @@ struct hda_pcm {
276 277
277/* codec information */ 278/* codec information */
278struct hda_codec { 279struct hda_codec {
279 struct device dev; 280 struct hdac_device core;
280 struct hda_bus *bus; 281 struct hda_bus *bus;
281 struct snd_card *card; 282 struct snd_card *card;
282 unsigned int addr; /* codec addr*/ 283 unsigned int addr; /* codec addr*/
@@ -409,10 +410,8 @@ struct hda_codec {
409 struct snd_array verbs; 410 struct snd_array verbs;
410}; 411};
411 412
412#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, dev) 413#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev)
413#define hda_codec_dev(_dev) (&(_dev)->dev) 414#define hda_codec_dev(_dev) (&(_dev)->core.dev)
414
415extern struct bus_type snd_hda_bus_type;
416 415
417/* direction */ 416/* direction */
418enum { 417enum {