2 * Copyright 2007-2008, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
6 * Ithamar Adema, ithamar AT unet DOT nl
13 int32 api_version
= B_CUR_DRIVER_API_VERSION
;
15 hda_controller gCards
[MAX_CARDS
];
17 pci_module_info
* gPci
;
18 pci_x86_module_info
* gPCIx86Module
;
27 if (get_module(B_PCI_MODULE_NAME
, (module_info
**)&gPci
) != B_OK
)
30 for (i
= 0; gPci
->get_nth_pci_info(i
, &info
) == B_OK
; i
++) {
31 if (info
.class_base
== PCI_multimedia
32 && info
.class_sub
== PCI_hd_audio
) {
33 put_module(B_PCI_MODULE_NAME
);
38 put_module(B_PCI_MODULE_NAME
);
46 char path
[B_PATH_NAME_LENGTH
];
50 if (get_module(B_PCI_MODULE_NAME
, (module_info
**)&gPci
) != B_OK
)
55 for (i
= 0; gPci
->get_nth_pci_info(i
, &info
) == B_OK
56 && gNumCards
< MAX_CARDS
; i
++) {
57 if (info
.class_base
== PCI_multimedia
58 && info
.class_sub
== PCI_hd_audio
) {
60 if ((*gPci
->reserve_device
)(info
.bus
, info
.device
, info
.function
,
61 "hda", &gCards
[gNumCards
]) < B_OK
) {
62 dprintf("HDA: Failed to reserve PCI:%d:%d:%d\n",
63 info
.bus
, info
.device
, info
.function
);
67 memset(&gCards
[gNumCards
], 0, sizeof(hda_controller
));
68 gCards
[gNumCards
].pci_info
= info
;
69 gCards
[gNumCards
].opened
= 0;
70 sprintf(path
, DEVFS_PATH_FORMAT
, gNumCards
);
71 gCards
[gNumCards
++].devfs_path
= strdup(path
);
73 dprintf("HDA: Detected controller @ PCI:%d:%d:%d, IRQ:%d, "
74 "type %04x/%04x (%04x/%04x)\n",
75 info
.bus
, info
.device
, info
.function
,
76 info
.u
.h0
.interrupt_line
, info
.vendor_id
, info
.device_id
,
77 info
.u
.h0
.subsystem_vendor_id
, info
.u
.h0
.subsystem_id
);
82 put_module(B_PCI_MODULE_NAME
);
86 if (get_module(B_PCI_X86_MODULE_NAME
, (module_info
**)&gPCIx86Module
)
97 for (uint32 i
= 0; i
< gNumCards
; i
++) {
99 (*gPci
->unreserve_device
)(gCards
[i
].pci_info
.bus
,
100 gCards
[i
].pci_info
.device
, gCards
[i
].pci_info
.function
, "hda",
103 free((void*)gCards
[i
].devfs_path
);
104 gCards
[i
].devfs_path
= NULL
;
107 put_module(B_PCI_MODULE_NAME
);
108 if (gPCIx86Module
!= NULL
) {
109 put_module(B_PCI_X86_MODULE_NAME
);
110 gPCIx86Module
= NULL
;
115 extern "C" const char**
116 publish_devices(void)
118 static const char* devs
[MAX_CARDS
+ 1];
121 for (i
= 0; i
< gNumCards
; i
++) {
122 devs
[i
] = gCards
[i
].devfs_path
;
131 extern "C" device_hooks
*
132 find_device(const char* name
)
134 return &gDriverHooks
;