Skip to content

Commit e3d280f

Browse files
committed
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 <[email protected]>
1 parent 3372dbd commit e3d280f

File tree

10 files changed

+113
-40
lines changed

10 files changed

+113
-40
lines changed

include/sound/hdaudio.h

+42
Original file line numberDiff line numberDiff line change
@@ -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+
*/
13+
extern struct bus_type snd_hda_bus_type;
14+
15+
/*
16+
* HD-audio codec base device
17+
*/
18+
struct hdac_device {
19+
struct device dev;
20+
int type;
21+
};
22+
23+
/* device/driver type used for matching */
24+
enum {
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+
*/
34+
struct 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 */

sound/Kconfig

+2
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ source "sound/isa/Kconfig"
7676

7777
source "sound/pci/Kconfig"
7878

79+
source "sound/hda/Kconfig"
80+
7981
source "sound/ppc/Kconfig"
8082

8183
source "sound/aoa/Kconfig"

sound/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ obj-$(CONFIG_SOUND_PRIME) += sound_firmware.o
66
obj-$(CONFIG_SOUND_PRIME) += oss/
77
obj-$(CONFIG_DMASOUND) += oss/
88
obj-$(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/
1010
obj-$(CONFIG_SND_AOA) += aoa/
1111

1212
# This one must be compilable even if sound is configured out

sound/hda/Kconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
config SND_HDA_CORE
2+
tristate

sound/hda/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
snd-hda-core-objs := hda_bus_type.o
2+
3+
obj-$(CONFIG_SND_HDA_CORE) += snd-hda-core.o

sound/hda/hda_bus_type.c

+42
Original file line numberDiff line numberDiff line change
@@ -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+
10+
MODULE_DESCRIPTION("HD-audio bus");
11+
MODULE_LICENSE("GPL");
12+
13+
static 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+
25+
struct bus_type snd_hda_bus_type = {
26+
.name = "hdaudio",
27+
.match = hda_bus_match,
28+
};
29+
EXPORT_SYMBOL_GPL(snd_hda_bus_type);
30+
31+
static int __init hda_bus_init(void)
32+
{
33+
return bus_register(&snd_hda_bus_type);
34+
}
35+
36+
static void __exit hda_bus_exit(void)
37+
{
38+
bus_unregister(&snd_hda_bus_type);
39+
}
40+
41+
subsys_initcall(hda_bus_init);
42+
module_exit(hda_bus_exit);

sound/pci/hda/Kconfig

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config SND_HDA
55
select SND_PCM
66
select SND_VMASTER
77
select SND_KCTL_JACK
8+
select SND_HDA_CORE
89

910
config SND_HDA_INTEL
1011
tristate "HD Audio PCI"

sound/pci/hda/hda_bind.c

+14-33
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ static struct hda_vendor_id hda_vendor_ids[] = {
4747
/*
4848
* find a matching codec preset
4949
*/
50-
static int hda_bus_match(struct device *dev, struct device_driver *drv)
50+
static int hda_codec_match(struct hdac_device *dev, struct hdac_driver *drv)
5151
{
52-
struct hda_codec *codec = container_of(dev, struct hda_codec, dev);
52+
struct hda_codec *codec = container_of(dev, struct hda_codec, core);
5353
struct hda_codec_driver *driver =
54-
container_of(drv, struct hda_codec_driver, driver);
54+
container_of(drv, struct hda_codec_driver, core);
5555
const struct hda_codec_preset *preset;
5656
/* check probe_id instead of vendor_id if set */
5757
u32 id = codec->probe_id ? codec->probe_id : codec->vendor_id;
@@ -154,20 +154,22 @@ static void hda_codec_driver_shutdown(struct device *dev)
154154
int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
155155
struct module *owner)
156156
{
157-
drv->driver.name = name;
158-
drv->driver.owner = owner;
159-
drv->driver.bus = &snd_hda_bus_type;
160-
drv->driver.probe = hda_codec_driver_probe;
161-
drv->driver.remove = hda_codec_driver_remove;
162-
drv->driver.shutdown = hda_codec_driver_shutdown;
163-
drv->driver.pm = &hda_codec_driver_pm;
164-
return driver_register(&drv->driver);
157+
drv->core.driver.name = name;
158+
drv->core.driver.owner = owner;
159+
drv->core.driver.bus = &snd_hda_bus_type;
160+
drv->core.driver.probe = hda_codec_driver_probe;
161+
drv->core.driver.remove = hda_codec_driver_remove;
162+
drv->core.driver.shutdown = hda_codec_driver_shutdown;
163+
drv->core.driver.pm = &hda_codec_driver_pm;
164+
drv->core.type = HDA_DEV_LEGACY;
165+
drv->core.match = hda_codec_match;
166+
return driver_register(&drv->core.driver);
165167
}
166168
EXPORT_SYMBOL_GPL(__hda_codec_driver_register);
167169

168170
void hda_codec_driver_unregister(struct hda_codec_driver *drv)
169171
{
170-
driver_unregister(&drv->driver);
172+
driver_unregister(&drv->core.driver);
171173
}
172174
EXPORT_SYMBOL_GPL(hda_codec_driver_unregister);
173175

@@ -319,24 +321,3 @@ int snd_hda_codec_configure(struct hda_codec *codec)
319321
return err;
320322
}
321323
EXPORT_SYMBOL_GPL(snd_hda_codec_configure);
322-
323-
/*
324-
* bus registration
325-
*/
326-
struct bus_type snd_hda_bus_type = {
327-
.name = "hdaudio",
328-
.match = hda_bus_match,
329-
};
330-
331-
static int __init hda_codec_init(void)
332-
{
333-
return bus_register(&snd_hda_bus_type);
334-
}
335-
336-
static void __exit hda_codec_exit(void)
337-
{
338-
bus_unregister(&snd_hda_bus_type);
339-
}
340-
341-
module_init(hda_codec_init);
342-
module_exit(hda_codec_exit);

sound/pci/hda/hda_codec.c

+1
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
12941294
dev_set_name(dev, "hdaudioC%dD%d", card->number, codec_addr);
12951295
dev_set_drvdata(dev, codec); /* for sysfs */
12961296
device_enable_async_suspend(dev);
1297+
codec->core.type = HDA_DEV_LEGACY;
12971298

12981299
codec->bus = bus;
12991300
codec->card = card;

sound/pci/hda/hda_codec.h

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sound/control.h>
2727
#include <sound/pcm.h>
2828
#include <sound/hwdep.h>
29+
#include <sound/hdaudio.h>
2930
#include <sound/hda_verbs.h>
3031

3132
/*
@@ -172,7 +173,7 @@ struct hda_codec_preset {
172173
#define HDA_CODEC_ID_GENERIC 0x00000201
173174

174175
struct hda_codec_driver {
175-
struct device_driver driver;
176+
struct hdac_driver core;
176177
const struct hda_codec_preset *preset;
177178
};
178179

@@ -276,7 +277,7 @@ struct hda_pcm {
276277

277278
/* codec information */
278279
struct hda_codec {
279-
struct device dev;
280+
struct hdac_device core;
280281
struct hda_bus *bus;
281282
struct snd_card *card;
282283
unsigned int addr; /* codec addr*/
@@ -409,10 +410,8 @@ struct hda_codec {
409410
struct snd_array verbs;
410411
};
411412

412-
#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, dev)
413-
#define hda_codec_dev(_dev) (&(_dev)->dev)
414-
415-
extern struct bus_type snd_hda_bus_type;
413+
#define dev_to_hda_codec(_dev) container_of(_dev, struct hda_codec, core.dev)
414+
#define hda_codec_dev(_dev) (&(_dev)->core.dev)
416415

417416
/* direction */
418417
enum {

0 commit comments

Comments
 (0)