added driver framework to prepare for driver unification, fixed USB driver, added...
[rpi-open-firmware.git] / drivers / IODevice.cc
1 #include <drivers/IODevice.hpp>
2
3 static IODevice* g_DeviceRegistry[32] = { 0 };
4 static unsigned int g_NewDriverIndex = 0;
5
6 IODevice::IODevice() {
7
8 }
9
10 void IODevice::_beforeInit() {
11 tag = 0;
12 deviceState = kIODeviceUninitialized;
13 }
14
15 void IODevice::_afterInit() {
16 assert(driverName);
17 if (tag)
18 registerDriver();
19 }
20
21 void IODevice::registerDriver() {
22 g_DeviceRegistry[g_NewDriverIndex++] = this;
23 IODriverLog("driver registered on platform IO plane");
24 }
25
26 void IODevice::driverLog(const char* fnName, const char* fmt, ...)
27 {
28 va_list va;
29
30 printf("%s::%s(): ", driverName, fnName);
31 va_start(va, fmt);
32 vprintf(fmt, va);
33 va_end(va);
34 printf("\n");
35 }
36
37 IODevice* IODevice::findByTag(uint32_t tag) {
38 for (int i = 0; i < (sizeof(g_DeviceRegistry) / sizeof(void*)); i++) {
39 IODevice* dev = g_DeviceRegistry[i];
40 if (dev && dev->tag == tag) {
41 return dev;
42 }
43 }
44
45 return nullptr;
46 }
47
48 void IODevice::start() {
49 deviceState = kIODeviceStarted;
50 }
51
52 void IODevice::stop() {
53 deviceState = kIODeviceStopped;
54 }
55
56 void IODevice::init() {
57 panic("IODevice objects have to override init()");
58 }
59
60
This page took 0.074796 seconds and 4 git commands to generate.