The Pedigree Project 0.1
modules/drivers/common/dm9601/main.cc
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20#include "pedigree/kernel/Log.h"
21#include "pedigree/kernel/processor/types.h"
22#include "pedigree/kernel/utilities/new"
23
24#include "Dm9601.h"
25#include "modules/Module.h"
26#include "modules/system/usb/UsbPnP.h"
27
28class UsbDevice;
29
30static struct {
31 uint16_t vendor;
32 uint16_t product;
33} g_Devices[] = {
34 {0x2630, 0x9601}, // Specification defines these for the chip
35 {0x0fe6, 0x8101}, // Kontron product
36};
37
38#define NUM_DEVICES (sizeof(g_Devices) / sizeof(g_Devices[0]))
39
40static UsbPnP::Registration g_Registrations[NUM_DEVICES];
41
42static UsbDevice* dm9601Connected(UsbDevice* pDevice) {
43 return new Dm9601(pDevice);
44}
45
46static bool entry() {
47 for (size_t i = 0; i < NUM_DEVICES; i++) {
48 if (!UsbPnP::instance().registerCallback(g_Devices[i].vendor, g_Devices[i].product,
49 dm9601Connected, g_Registrations[i])) {
50 while (i) {
51 g_Registrations[--i].reset();
52 }
53 return false;
54 }
55 }
56
57 return true;
58}
59
60static void exit() {
61 for (size_t i = NUM_DEVICES; i; --i) {
62 if (!g_Registrations[i - 1].reset())
63 FATAL("DM9601 USB binding could not be retired");
64 }
65}
66
67MODULE_INFO("dm9601", &entry, &exit, "usb", "network-stack");
static UsbPnP & instance()
Singleton design.
Definition UsbPnP.h:95