xref: /haiku/src/add-ons/kernel/drivers/audio/ac97/geode/driver.cpp (revision 4f2fd49bdc6078128b1391191e4edac647044c3d)
1 /*
2  * Copyright 2009, Haiku, Inc. All Rights Reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *	Jérôme Duval (korli@users.berlios.de)
7  */
8 
9 
10 #include "driver.h"
11 
12 
13 int32 api_version = B_CUR_DRIVER_API_VERSION;
14 
15 geode_controller gCards[MAX_CARDS];
16 uint32 gNumCards;
17 pci_module_info* gPci;
18 
19 
20 extern "C" status_t
21 init_hardware(void)
22 {
23 	pci_info info;
24 	long i;
25 
26 	if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPci) != B_OK)
27 		return ENODEV;
28 
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;
36 		}
37 	}
38 
39 	put_module(B_PCI_MODULE_NAME);
40 	return ENODEV;
41 }
42 
43 
44 extern "C" status_t
45 init_driver(void)
46 {
47 	char path[B_PATH_NAME_LENGTH];
48 	pci_info info;
49 	long i;
50 
51 	if (get_module(B_PCI_MODULE_NAME, (module_info**)&gPci) != B_OK)
52 		return ENODEV;
53 
54 	gNumCards = 0;
55 
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 			memset(&gCards[gNumCards], 0, sizeof(geode_controller));
61 			gCards[gNumCards].pci_info = info;
62 			gCards[gNumCards].opened = 0;
63 			sprintf(path, DEVFS_PATH_FORMAT, gNumCards);
64 			gCards[gNumCards++].devfs_path = strdup(path);
65 
66 			dprintf("geode: detected controller @ PCI:%d:%d:%d, IRQ:%d, type %04x/%04x\n",
67 				info.bus, info.device, info.function,
68 				info.u.h0.interrupt_line,
69 				info.vendor_id, info.device_id);
70 		}
71 	}
72 
73 	if (gNumCards == 0) {
74 		put_module(B_PCI_MODULE_NAME);
75 		return ENODEV;
76 	}
77 
78 	return B_OK;
79 }
80 
81 
82 extern "C" void
83 uninit_driver(void)
84 {
85 	for (uint32 i = 0; i < gNumCards; i++) {
86 		free((void*)gCards[i].devfs_path);
87 		gCards[i].devfs_path = NULL;
88 	}
89 
90 	put_module(B_PCI_MODULE_NAME);
91 }
92 
93 
94 extern "C" const char**
95 publish_devices(void)
96 {
97 	static const char* devs[MAX_CARDS + 1];
98 	uint32 i;
99 
100 	for (i = 0; i < gNumCards; i++) {
101 		devs[i] = gCards[i].devfs_path;
102 	}
103 
104 	devs[i] = NULL;
105 
106 	return devs;
107 }
108 
109 
110 extern "C" device_hooks*
111 find_device(const char* name)
112 {
113 	return &gDriverHooks;
114 }
115