Skip to content

Commit

Permalink
Add reset code (#110)
Browse files Browse the repository at this point in the history
* Add reset handling for resume/uncommanded resets
  • Loading branch information
1Revenger1 authored Apr 7, 2021
1 parent f949a20 commit 7b64f34
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 129 deletions.
2 changes: 1 addition & 1 deletion VoodooRMI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@
isa = PBXGroup;
children = (
286587D824C13D9600E74848 /* Info.plist */,
A4560F0B247F406F0009CBE0 /* RMISMBus.cpp */,
286587AE24C13D0B00E74848 /* RMISMBus.hpp */,
A4560F0B247F406F0009CBE0 /* RMISMBus.cpp */,
);
path = SMBus;
sourceTree = "<group>";
Expand Down
10 changes: 6 additions & 4 deletions VoodooRMI/Functions/F01.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,20 +449,22 @@ void F01::rmi_f01_attention()

IOReturn F01::message(UInt32 type, IOService *provider, void *argument)
{
int error;
int error = 0;
switch (type) {
case kHandleRMISuspend:
case kHandleRMISleep:
error = rmi_f01_suspend();
if (error) return kIOReturnError;
break;
case kHandleRMIResume:
error = rmi_f01_resume();
if (error) return kIOReturnError;
break;
case kHandleRMIAttention:
rmi_f01_attention();
break;
case kHandleRMIConfig:
error = rmi_f01_config();
break;
}

if (error) return kIOReturnError;
return kIOReturnSuccess;
}
6 changes: 3 additions & 3 deletions VoodooRMI/Functions/F03.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,15 @@ class F03 : public RMIFunction {

IOWorkLoop* getWorkLoop();

int rmi_f03_pt_write (unsigned char val);
int rmi_f03_pt_write(unsigned char val);
int ps2DoSendbyteGated(u8 byte, uint64_t timeout);
int ps2CommandGated(u8 *param, unsigned int *command);
int ps2Command(u8 *param, unsigned int command);
void handleByte(u8);
void initPS2();
void initPS2Interrupt (OSObject *owner, IOTimerEventSource *timer);
void initPS2Interrupt(OSObject *owner, IOTimerEventSource *timer);
// TODO: Move to math file as long as with abs in rmi_driver.h
int signum (int value);
int signum(int value);

void handlePacket(u8 *packet);
};
Expand Down
16 changes: 11 additions & 5 deletions VoodooRMI/Functions/F11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,10 @@ bool F11::start(IOService *provider)
if (!super::start(provider))
return false;

int rc;

rc = f11_write_control_regs(&sens_query, &dev_controls,
fn_descriptor->query_base_addr);
int rc = rmi_f11_config();

if (rc < 0)
return !rc;
return false;

registerService();

Expand Down Expand Up @@ -97,6 +94,9 @@ IOReturn F11::message(UInt32 type, IOService *provider, void *argument)
case kHandleRMIClickpadSet:
case kHandleRMITrackpoint:
return messageClient(type, sensor, argument);
case kHandleRMIConfig:
rmi_f11_config();
break;
}

return kIOReturnSuccess;
Expand Down Expand Up @@ -168,6 +168,12 @@ bool F11::getReport()
return true;
}

int F11::rmi_f11_config()
{
return f11_write_control_regs(&sens_query, &dev_controls,
fn_descriptor->query_base_addr);
}

int F11::f11_read_control_regs(f11_2d_ctrl *ctrl, u16 ctrl_base_addr)
{
int error = 0;
Expand Down
1 change: 1 addition & 0 deletions VoodooRMI/Functions/F11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ class F11 : public RMIFunction {
unsigned long *rel_mask;

bool getReport();
int rmi_f11_config();
int rmi_f11_initialize();
int rmi_f11_get_query_parameters(f11_2d_sensor_queries *sensor_query,
u16 query_base_addr);
Expand Down
85 changes: 48 additions & 37 deletions VoodooRMI/Functions/F12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,54 @@ bool F12::attach(IOService *provider)
}

bool F12::start(IOService *provider)
{
int ret = rmi_f12_config();
if (ret < 0)
return false;

registerService();

if (!sensor->attach(this))
return false;

if (!sensor->start(this))
return false;

return super::start(provider);
}

void F12::stop(IOService *provider)
{
sensor->detach(this);
sensor->stop(this);
super::stop(provider);
}

void F12::free()
{
clearDesc();
OSSafeReleaseNULL(sensor);
super::free();
}

IOReturn F12::message(UInt32 type, IOService *provider, void *argument)
{
switch (type)
{
case kHandleRMIAttention:
getReport();
break;
case kHandleRMIClickpadSet:
case kHandleRMITrackpoint:
return messageClient(type, sensor, argument);
case kHandleRMIConfig:
return rmi_f12_config();
}

return kIOReturnSuccess;
}

int F12::rmi_f12_config()
{
const struct rmi_register_desc_item *item;
unsigned long control_size;
Expand Down Expand Up @@ -191,43 +239,6 @@ bool F12::start(IOService *provider)
}
}

registerService();

if (!sensor->attach(this))
return false;

if (!sensor->start(this))
return false;

return super::start(provider);
}

void F12::stop(IOService *provider)
{
sensor->detach(this);
sensor->stop(this);
super::stop(provider);
}

void F12::free()
{
clearDesc();
OSSafeReleaseNULL(sensor);
super::free();
}

IOReturn F12::message(UInt32 type, IOService *provider, void *argument)
{
switch (type)
{
case kHandleRMIAttention:
getReport();
break;
case kHandleRMIClickpadSet:
case kHandleRMITrackpoint:
return messageClient(type, sensor, argument);
}

return kIOReturnSuccess;
}

Expand Down
2 changes: 2 additions & 0 deletions VoodooRMI/Functions/F12.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ class F12 : public RMIFunction {
static bool rmi_register_desc_has_subpacket(const rmi_register_desc_item *item,
u8 subpacket);

int rmi_f12_config();

/* F12 Data */
RMI2DSensor *sensor;
struct rmi_2d_sensor_platform_data sensor_pdata;
Expand Down
27 changes: 18 additions & 9 deletions VoodooRMI/Functions/F30.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ bool F30::start(IOService *provider)
if (!super::start(provider))
return false;

int error = rmiBus->blockWrite(fn_descriptor->control_base_addr,
ctrl_regs, ctrl_regs_size);

if (error) {
IOLogError("%s: Could not write control registers at 0x%x: 0x%x",
__func__, fn_descriptor->control_base_addr, error);
return false;;
}
int ret = rmi_f30_config();
if (ret < 0) return false;

voodooTrackpointInstance = rmiBus->getVoodooInput();

Expand All @@ -62,9 +56,10 @@ void F30::free()

IOReturn F30::message(UInt32 type, IOService *provider, void *argument)
{
int error;
switch (type) {
case kHandleRMIAttention:
int error = rmiBus->readBlock(fn_descriptor->data_base_addr,
error = rmiBus->readBlock(fn_descriptor->data_base_addr,
data_regs, register_count);

if (error < 0) {
Expand All @@ -76,11 +71,25 @@ IOReturn F30::message(UInt32 type, IOService *provider, void *argument)

rmi_f30_report_button();
break;
case kHandleRMIConfig:
return rmi_f30_config();
}

return kIOReturnSuccess;
}

int F30::rmi_f30_config()
{
int error = rmiBus->blockWrite(fn_descriptor->control_base_addr,
ctrl_regs, ctrl_regs_size);

if (error) {
IOLogError("%s: Could not write control registers at 0x%x: 0x%x",
__func__, fn_descriptor->control_base_addr, error);
}
return error;
}

int F30::rmi_f30_initialize()
{
u8 *ctrl_reg = ctrl_regs;
Expand Down
1 change: 1 addition & 0 deletions VoodooRMI/Functions/F30.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class F30 : public RMIFunction {
bool hasTrackpointButtons;

int rmi_f30_initialize();
int rmi_f30_config();
void rmi_f30_set_ctrl_data(rmi_f30_ctrl_data *ctrl,
int *ctrl_addr, int len, u8 **reg);
int rmi_f30_read_control_parameters();
Expand Down
Loading

0 comments on commit 7b64f34

Please sign in to comment.