usb_ecm: Use the current configuration instead of a fixed one.
[haiku.git] / src / add-ons / kernel / drivers / audio / ac97 / geode / driver.cpp
blob76d0a7e5b5a369fb1ad8467c1fb33a157b153f95
1 /*
2 * Copyright 2009, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Jérôme Duval (korli@users.berlios.de)
7 */
10 #include "driver.h"
13 int32 api_version = B_CUR_DRIVER_API_VERSION;
15 geode_controller gCards[MAX_CARDS];
16 uint32 gNumCards;
17 pci_module_info* gPci;
20 extern "C" status_t
21 init_hardware(void)
23 pci_info info;
24 long i;
26 if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPci) != B_OK)
27 return ENODEV;
29 for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK; i++) {
30 if ((info.vendor_id == AMD_VENDOR_ID
31 && info.device_id == AMD_CS5536_AUDIO_DEVICE_ID)
32 || (info.vendor_id == NS_VENDOR_ID
33 && info.device_id == NS_CS5535_AUDIO_DEVICE_ID)) {
34 put_module(B_PCI_MODULE_NAME);
35 return B_OK;
39 put_module(B_PCI_MODULE_NAME);
40 return ENODEV;
44 extern "C" status_t
45 init_driver(void)
47 char path[B_PATH_NAME_LENGTH];
48 pci_info info;
49 long i;
51 if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPci) != B_OK)
52 return ENODEV;
54 gNumCards = 0;
56 for (i = 0; gPci->get_nth_pci_info(i, &info) == B_OK
57 && gNumCards < MAX_CARDS; i++) {
58 if ((info.vendor_id == AMD_VENDOR_ID
59 && info.device_id == AMD_CS5536_AUDIO_DEVICE_ID)
60 || (info.vendor_id == NS_VENDOR_ID
61 && info.device_id == NS_CS5535_AUDIO_DEVICE_ID)) {
62 memset(&gCards[gNumCards], 0, sizeof(geode_controller));
63 gCards[gNumCards].pci_info = info;
64 gCards[gNumCards].opened = 0;
65 sprintf(path, DEVFS_PATH_FORMAT, gNumCards);
66 gCards[gNumCards++].devfs_path = strdup(path);
68 dprintf("geode: detected controller @ PCI:%d:%d:%d, IRQ:%d, type %04x/%04x\n",
69 info.bus, info.device, info.function,
70 info.u.h0.interrupt_line,
71 info.vendor_id, info.device_id);
75 if (gNumCards == 0) {
76 put_module(B_PCI_MODULE_NAME);
77 return ENODEV;
80 return B_OK;
84 extern "C" void
85 uninit_driver(void)
87 for (uint32 i = 0; i < gNumCards; i++) {
88 free((void*)gCards[i].devfs_path);
89 gCards[i].devfs_path = NULL;
92 put_module(B_PCI_MODULE_NAME);
96 extern "C" const char**
97 publish_devices(void)
99 static const char* devs[MAX_CARDS + 1];
100 uint32 i;
102 for (i = 0; i < gNumCards; i++) {
103 devs[i] = gCards[i].devfs_path;
106 devs[i] = NULL;
108 return devs;
112 extern "C" device_hooks*
113 find_device(const char* name)
115 return &gDriverHooks;