@@ -95,16 +95,22 @@ bool RMII2C::start(IOService *provider) {
95
95
goto exit;
96
96
}
97
97
98
- /* Implementation of polling */
98
+ // Try to get interrupt source, fall back to polling though if we can't get an interrupt source
99
99
interrupt_source = IOInterruptEventSource::interruptEventSource (this , OSMemberFunctionCast (IOInterruptEventAction, this , &RMII2C::interruptOccured), device_nub, 0 );
100
- if (!interrupt_source) {
100
+
101
+ if (interrupt_source) {
102
+ work_loop->addEventSource (interrupt_source);
103
+ } else {
101
104
IOLogInfo (" %s::%s Could not get interrupt event source, falling back to polling" , getName (), name);
102
105
interrupt_simulator = IOTimerEventSource::timerEventSource (this , OSMemberFunctionCast (IOTimerEventSource::Action, this , &RMII2C::simulateInterrupt));
103
106
if (!interrupt_simulator) {
104
107
IOLogError (" %s::%s Could not get timer event source" , getName (), name);
105
108
goto exit;
106
109
}
110
+
111
+ work_loop->addEventSource (interrupt_simulator);
107
112
}
113
+
108
114
109
115
PMinit ();
110
116
provider->joinPMtree (this );
@@ -121,20 +127,30 @@ bool RMII2C::start(IOService *provider) {
121
127
}
122
128
123
129
void RMII2C::releaseResources () {
124
- if (command_gate)
130
+ if (command_gate) {
125
131
work_loop->removeEventSource (command_gate);
126
- OSSafeReleaseNULL (command_gate);
132
+ }
127
133
128
134
stopInterrupt ();
129
- OSSafeReleaseNULL (interrupt_source);
130
- OSSafeReleaseNULL (interrupt_simulator);
131
- OSSafeReleaseNULL (work_loop);
135
+
136
+ if (interrupt_source) {
137
+ work_loop->removeEventSource (interrupt_source);
138
+ }
139
+
140
+ if (interrupt_simulator) {
141
+ work_loop->removeEventSource (interrupt_simulator);
142
+ }
132
143
133
144
if (device_nub) {
134
145
if (device_nub->isOpen (this ))
135
146
device_nub->close (this );
136
147
device_nub = nullptr ;
137
148
}
149
+
150
+ OSSafeReleaseNULL (command_gate);
151
+ OSSafeReleaseNULL (interrupt_source);
152
+ OSSafeReleaseNULL (interrupt_simulator);
153
+ OSSafeReleaseNULL (work_loop);
138
154
OSSafeReleaseNULL (acpi_device);
139
155
140
156
IOLockFree (page_mutex);
@@ -388,11 +404,9 @@ IOReturn RMII2C::setPowerState(unsigned long powerState, IOService *whatDevice){
388
404
389
405
void RMII2C::startInterrupt () {
390
406
if (interrupt_simulator) {
391
- work_loop->addEventSource (interrupt_simulator);
392
407
interrupt_simulator->setTimeoutMS (200 );
393
408
interrupt_simulator->enable ();
394
409
} else if (interrupt_source) {
395
- work_loop->addEventSource (interrupt_source);
396
410
interrupt_source->enable ();
397
411
}
398
412
}
@@ -401,9 +415,7 @@ void RMII2C::stopInterrupt() {
401
415
ready = false ;
402
416
if (interrupt_simulator) {
403
417
interrupt_simulator->disable ();
404
- work_loop->removeEventSource (interrupt_simulator);
405
418
} else if (interrupt_source) {
406
419
interrupt_source->disable ();
407
- work_loop->removeEventSource (interrupt_source);
408
420
}
409
421
}
0 commit comments