BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / drivers / network / wb840 / driver.c
blob85b7c8cde077cd1929c296a233be3e0fec74654f
1 /* Copyright (c) 2003-2011
2 * Stefano Ceccherini <stefano.ceccherini@gmail.com>. All rights reserved.
3 */
4 #include "debug.h"
5 #include <Debug.h>
7 #include <KernelExport.h>
8 #include <Errors.h>
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <string.h>
13 #include "wb840.h"
14 #include "device.h"
15 #include "driver.h"
17 #define MAX_CARDS 4
19 int32 api_version = B_CUR_DRIVER_API_VERSION;
21 pci_module_info* gPci;
22 char* gDevNameList[MAX_CARDS + 1];
23 pci_info* gDevList[MAX_CARDS];
26 static bool
27 probe(pci_info* item)
29 if ((item->vendor_id == WB_VENDORID && item->device_id == WB_DEVICEID_840F)
30 || (item->vendor_id == CP_VENDORID && item->device_id == CP_DEVICEID_RL100))
31 return true;
32 return false;
36 status_t
37 init_hardware(void)
39 LOG((DEVICE_NAME ": init_hardware\n"));
40 return B_OK;
44 status_t
45 init_driver(void)
47 struct pci_info* item = NULL;
48 int index = 0;
49 int card_found = 0;
50 char devName[64];
51 status_t status;
53 LOG((DEVICE_NAME ": init_driver\n"));
55 #ifdef DEBUG
56 set_dprintf_enabled(true);
57 #endif
59 status = get_module(B_PCI_MODULE_NAME, (module_info**)&gPci);
60 if (status < B_OK)
61 return status;
63 item = (pci_info*)malloc(sizeof(pci_info));
64 if (item == NULL) {
65 put_module(B_PCI_MODULE_NAME);
66 return B_NO_MEMORY;
69 while (gPci->get_nth_pci_info(index, item) == B_OK) {
70 if (probe(item)) {
71 gPci->write_pci_config(item->bus, item->device, item->function,
72 PCI_command, 2, PCI_command_master | gPci->read_pci_config(
73 item->bus, item->device, item->function,
74 PCI_command, 2));
75 gDevList[card_found++] = item;
77 dprintf(DEVICE_NAME ": revision = %x\n", item->revision);
79 item = (pci_info *)malloc(sizeof(pci_info));
81 index++;
83 free(item);
85 gDevList[card_found] = NULL;
87 if (card_found == 0) {
88 put_module(B_PCI_MODULE_NAME);
89 return ENODEV;
92 for (index = 0; index < card_found; index++) {
93 sprintf(devName, DEVICE_NAME "/%d", index);
94 LOG((DEVICE_NAME ":enabled %s\n", devName));
95 gDevNameList[index] = strdup(devName);
98 gDevNameList[index] = NULL;
100 return B_OK;
104 void
105 uninit_driver(void)
107 int32 i = 0;
109 LOG((DEVICE_NAME ": uninit_driver()\n"));
110 while(gDevNameList[i] != NULL) {
111 free(gDevList[i]);
112 free(gDevNameList[i]);
113 i++;
116 put_module(B_PCI_MODULE_NAME);
120 const char**
121 publish_devices()
123 return (const char**)gDevNameList;
127 device_hooks*
128 find_device(const char* name)
130 int32 i;
131 char* item;
133 LOG((DEVICE_NAME ": find_device()\n"));
134 // Find device name
135 for (i = 0; (item = gDevNameList[i]); i++) {
136 if (!strcmp(name, item)) {
137 return &gDeviceHooks;
140 return NULL; // Device not found