* Some cleanup of some really bad style introduced by myself

* No functional change


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42412 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV
2011-07-11 20:02:19 +00:00
parent 3fe7883778
commit b8d5c5cec2
@@ -40,7 +40,7 @@ mutex gUSBLock;
// auto-release helper class // auto-release helper class
class USBSmartLock { class USBSmartLock {
public: public:
USBSmartLock() { mutex_lock(&gUSBLock); } USBSmartLock() { mutex_lock(&gUSBLock); }
~USBSmartLock() { mutex_unlock(&gUSBLock); } ~USBSmartLock() { mutex_unlock(&gUSBLock); }
}; };
@@ -68,8 +68,7 @@ BeceemDevice::ReadRegister(unsigned int reg, size_t size, uint32_t* buffer)
size, buffer, size, buffer,
&actualLength); &actualLength);
retries++ ; retries++ ;
if (-ENODEV == result) if (-ENODEV == result) {
{
TRACE_ALWAYS("Error: Device was removed during USB read\n"); TRACE_ALWAYS("Error: Device was removed during USB read\n");
break; break;
} }
@@ -78,16 +77,14 @@ BeceemDevice::ReadRegister(unsigned int reg, size_t size, uint32_t* buffer)
if (result < 0) { if (result < 0) {
TRACE_ALWAYS("Error: USB read request failure." TRACE_ALWAYS("Error: USB read request failure."
" Result: %d; Attempt: %d.\n", " Result: %d; Attempt: %d.\n", result, retries);
result, retries);
return result; return result;
} }
if (size != actualLength) { if (size != actualLength) {
TRACE_ALWAYS("Error: Size mismatch on USB read request." TRACE_ALWAYS("Error: Size mismatch on USB read request."
" Asked: %d; Got: %d; Attempt: %d.\n", " Asked: %d; Got: %d; Attempt: %d.\n", size, actualLength, retries);
size, actualLength, retries);
} }
return result; return result;
@@ -116,8 +113,7 @@ BeceemDevice::WriteRegister(unsigned int reg, size_t size, uint32_t* buffer)
size, buffer, size, buffer,
&actualLength); &actualLength);
retries++ ; retries++ ;
if (-ENODEV == result) if (-ENODEV == result) {
{
TRACE_ALWAYS("Error: Device was removed during USB write\n"); TRACE_ALWAYS("Error: Device was removed during USB write\n");
break; break;
} }
@@ -143,21 +139,23 @@ BeceemDevice::WriteRegister(unsigned int reg, size_t size, uint32_t* buffer)
status_t status_t
BeceemDevice::BizarroReadRegister(unsigned int reg, size_t size, uint32_t* buffer) BeceemDevice::BizarroReadRegister(unsigned int reg, size_t size,
uint32_t* buffer)
{ {
// NET_TO_HOST long // NET_TO_HOST long
// Read then flip // Read then flip
status_t Status = ReadRegister(reg, size, buffer); status_t status = ReadRegister(reg, size, buffer);
convertEndian(false, size, buffer); convertEndian(false, size, buffer);
return Status; return status;
} }
status_t status_t
BeceemDevice::BizarroWriteRegister(unsigned int reg, size_t size, uint32_t* buffer) BeceemDevice::BizarroWriteRegister(unsigned int reg, size_t size,
uint32_t* buffer)
{ {
// HOST_TO_NET long // HOST_TO_NET long
@@ -165,14 +163,14 @@ BeceemDevice::BizarroWriteRegister(unsigned int reg, size_t size, uint32_t* buff
convertEndian(true, size, buffer); convertEndian(true, size, buffer);
status_t Status = WriteRegister(reg, size, buffer); status_t status = WriteRegister(reg, size, buffer);
// Flip then write // Flip then write
// as we modified the input data, and other things // as we modified the input data, and other things
// outside this function may need it, restore the original val. // outside this function may need it, restore the original val.
*buffer = reload; *buffer = reload;
return Status; return status;
} }
@@ -299,9 +297,8 @@ BeceemDevice::Open(uint32 flags)
return B_ERROR; return B_ERROR;
status_t result = StartDevice(); status_t result = StartDevice();
if (result != B_OK) { if (result != B_OK)
return result; return result;
}
// setup state notifications // setup state notifications
result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer, result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer,
@@ -552,7 +549,6 @@ void
BeceemDevice::Removed() BeceemDevice::Removed()
{ {
fHasConnection = false; fHasConnection = false;
pwmxdevice->driverHalt = true; pwmxdevice->driverHalt = true;
TRACE("Debug: Pre InsideNotify\n"); TRACE("Debug: Pre InsideNotify\n");
@@ -643,9 +639,6 @@ BeceemDevice::IdentifyChipset()
status_t status_t
BeceemDevice::SetupDevice(bool deviceReplugged) BeceemDevice::SetupDevice(bool deviceReplugged)
{ {
unsigned int value = 0;
unsigned long dwReadValue = 0;
pwmxdevice->driverState = STATE_INIT; pwmxdevice->driverState = STATE_INIT;
// ID the Beceem chipset // ID the Beceem chipset
@@ -658,12 +651,11 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
if (LoadConfig() != B_OK) if (LoadConfig() != B_OK)
return B_ERROR; return B_ERROR;
if (pwmxdevice->deviceChipID >= T3LPB) if (pwmxdevice->deviceChipID >= T3LPB) {
{ unsigned int value = 0;
BizarroReadRegister(SYS_CFG, sizeof(value), &value); BizarroReadRegister(SYS_CFG, sizeof(value), &value);
pwmxdevice->syscfgBefFw = value; pwmxdevice->syscfgBefFw = value;
if ((value & 0x60)== 0) if ((value & 0x60) == 0) {
{
TRACE("Debug: CPU is FlashBoot\n"); TRACE("Debug: CPU is FlashBoot\n");
pwmxdevice->CPUFlashBoot = true; pwmxdevice->CPUFlashBoot = true;
} }
@@ -714,14 +706,13 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
TRACE("Debug: Raw PARAM pointer: 0x%x\n", pwmxdevice->hwParamPtr); TRACE("Debug: Raw PARAM pointer: 0x%x\n", pwmxdevice->hwParamPtr);
if (pwmxdevice->hwParamPtr < DSD_START_OFFSET || if (pwmxdevice->hwParamPtr < DSD_START_OFFSET
pwmxdevice->hwParamPtr > pwmxdevice->nvmDSDSize - DSD_START_OFFSET) || pwmxdevice->hwParamPtr > pwmxdevice->nvmDSDSize - DSD_START_OFFSET) {
{
TRACE_ALWAYS("Error: DSD Status checksum mismatch\n"); TRACE_ALWAYS("Error: DSD Status checksum mismatch\n");
return B_ERROR; return B_ERROR;
} }
dwReadValue = pwmxdevice->hwParamPtr; unsigned long dwReadValue = pwmxdevice->hwParamPtr;
// hw paramater pointer // hw paramater pointer
dwReadValue = dwReadValue + DSD_START_OFFSET; dwReadValue = dwReadValue + DSD_START_OFFSET;
// add DSD start offset // add DSD start offset
@@ -893,7 +884,7 @@ BeceemDevice::_SetupEndpoints()
} else if ((epd->attributes & USB_ENDPOINT_ATTR_MASK) } else if ((epd->attributes & USB_ENDPOINT_ATTR_MASK)
== USB_ENDPOINT_ATTR_ISOCHRONOUS) { == USB_ENDPOINT_ATTR_ISOCHRONOUS) {
// Isochronous endpoint // Isochronous endpoint
// TODO : do we need the Isochronous USB endpoints this device provides? // TODO : do we need the Isochronous USB endpoints?
// http://www.beyondlogic.org/usbnutshell/usb4.shtml#Isochronous // http://www.beyondlogic.org/usbnutshell/usb4.shtml#Isochronous
} else { } else {
// Strange... // Strange...
@@ -916,8 +907,8 @@ BeceemDevice::_SetupEndpoints()
gUSBModule->set_configuration(fDevice, config); gUSBModule->set_configuration(fDevice, config);
fNotifyEndpoint = interface->endpoint[notifyEndpoint].handle; fNotifyEndpoint = interface->endpoint[notifyEndpoint].handle;
fReadEndpoint = interface->endpoint[readEndpoint ].handle; fReadEndpoint = interface->endpoint[readEndpoint].handle;
fWriteEndpoint = interface->endpoint[writeEndpoint ].handle; fWriteEndpoint = interface->endpoint[writeEndpoint].handle;
return B_OK; return B_OK;
} }
@@ -1014,39 +1005,35 @@ BeceemDevice::StartDevice()
status_t status_t
BeceemDevice::LoadConfig() BeceemDevice::LoadConfig()
{ {
size_t file_size = 0;
unsigned int* buffer = 0;
struct stat cfgStat;
int dtaread = 0; int dtaread = 0;
int fh = open(FIRM_CFG, O_RDONLY); int fh = open(FIRM_CFG, O_RDONLY);
struct stat cfgStat;
if (fh == B_ERROR || fstat(fh, &cfgStat) < 0) { if (fh == B_ERROR || fstat(fh, &cfgStat) < 0) {
TRACE_ALWAYS("Error: Unable to open the configuration at %s\n", FIRM_CFG); TRACE_ALWAYS("Error: Unable to open the configuration at %s\n", FIRM_CFG);
return fh; return fh;
} }
file_size = cfgStat.st_size; size_t file_size = cfgStat.st_size;
buffer=(unsigned int*)malloc(MAX_USB_TRANSFER); unsigned int* buffer = (unsigned int*)malloc(MAX_USB_TRANSFER);
if (!buffer) { if (!buffer) {
TRACE_ALWAYS("Error: Memory allocation error.\n"); TRACE_ALWAYS("Error: Memory allocation error.\n");
return B_ERROR; return B_ERROR;
} }
dtaread = read(fh , buffer, MAX_USB_TRANSFER); dtaread = read(fh, buffer, MAX_USB_TRANSFER);
if (dtaread < 0) if (dtaread < 0) {
{
TRACE_ALWAYS("Error: Error reading from vendor configuration.\n"); TRACE_ALWAYS("Error: Error reading from vendor configuration.\n");
close(fh); close(fh);
free(buffer); free(buffer);
return B_ERROR; return B_ERROR;
} }
if (file_size != sizeof(VENDORCFG)) if (file_size != sizeof(VENDORCFG)) {
{
TRACE_ALWAYS("Error: Size mismatch in vendor configuration struct!\n"); TRACE_ALWAYS("Error: Size mismatch in vendor configuration struct!\n");
close(fh); close(fh);
free(buffer); free(buffer);
@@ -1127,43 +1114,38 @@ BeceemDevice::DumpConfig()
status_t status_t
BeceemDevice::PushConfig(unsigned int loc) BeceemDevice::PushConfig(unsigned int loc)
{ {
size_t file_size = 0;
unsigned int* buffer = 0;
struct stat cfgStat;
status_t result;
int chipwriteloc = 0;
int readposition = 0;
int fh = open(FIRM_CFG, O_RDONLY); int fh = open(FIRM_CFG, O_RDONLY);
struct stat cfgStat;
if (fh == B_ERROR || fstat(fh, &cfgStat) < 0) { if (fh == B_ERROR || fstat(fh, &cfgStat) < 0) {
TRACE_ALWAYS("Error: Unable to open the configuration at %s\n", FIRM_CFG); TRACE_ALWAYS("Error: Unable to open the configuration at %s\n",
FIRM_CFG);
return fh; return fh;
} }
file_size = cfgStat.st_size; size_t file_size = cfgStat.st_size;
TRACE_ALWAYS("Info: Vendor configuration to be pushed to 0x%x on device.\n", TRACE_ALWAYS("Info: Vendor configuration to be pushed to 0x%x on device.\n",
loc); loc);
buffer=(unsigned int*)malloc(MAX_USB_TRANSFER); unsigned int* buffer = (unsigned int*)malloc(MAX_USB_TRANSFER);
if (!buffer) { if (!buffer) {
TRACE_ALWAYS("Error: Memory allocation error.\n"); TRACE_ALWAYS("Error: Memory allocation error.\n");
return B_ERROR; return B_ERROR;
} }
int chipwriteloc = 0;
int readposition = 0;
status_t result;
// We have to spoon feed the data to the usb device as it is probbably too // We have to spoon feed the data to the usb device as it is probbably too
// much to be written in one go. // much to be written in one go.
while (1) while (1) {
{ readposition = read(fh, buffer, MAX_USB_TRANSFER);
readposition = read(fh , buffer, MAX_USB_TRANSFER);
if (readposition <= 0) if (readposition <= 0) {
{ if (readposition < 0) {
if (readposition < 0)
{
TRACE_ALWAYS("Error: Error reading firmware.\n"); TRACE_ALWAYS("Error: Error reading firmware.\n");
result = B_ERROR; result = B_ERROR;
} else { } else {
@@ -1179,23 +1161,22 @@ BeceemDevice::PushConfig(unsigned int loc)
// As readposition should always be less then MAX_USB_TRANSFER // As readposition should always be less then MAX_USB_TRANSFER
// and we have checked the validity of read's output above. // and we have checked the validity of read's output above.
if (WriteRegister(loc + chipwriteloc, readposition, buffer) != B_OK) if (WriteRegister(loc + chipwriteloc, readposition, buffer) != B_OK) {
{
TRACE_ALWAYS("Write failure\n"); TRACE_ALWAYS("Write failure\n");
result = B_ERROR; result = B_ERROR;
break; break;
} }
// +1 as we don't want to write the same sector twice // +1 as we don't want to write the same sector twice
chipwriteloc += (MAX_USB_TRANSFER+1); chipwriteloc += MAX_USB_TRANSFER + 1;
} }
close(fh); close(fh);
free(buffer); free(buffer);
if (result < 0) if (result < 0) {
{ TRACE_ALWAYS("Error: Push of vendor configuration failed: %d\n",
TRACE_ALWAYS("Error: Push of vendor configuration failed :%d\n", result); result);
return B_ERROR; return B_ERROR;
} else { } else {
TRACE_ALWAYS("Info: Push of vendor configuration was successful.\n"); TRACE_ALWAYS("Info: Push of vendor configuration was successful.\n");
@@ -1207,16 +1188,9 @@ BeceemDevice::PushConfig(unsigned int loc)
status_t status_t
BeceemDevice::PushFirmware(unsigned int loc) BeceemDevice::PushFirmware(unsigned int loc)
{ {
size_t file_size = 0;
int chipwriteloc = 0;
int readposition = 0;
unsigned int* buffer = 0;
struct stat firmStat;
status_t result;
int fh = open(FIRM_BIN, O_RDONLY); int fh = open(FIRM_BIN, O_RDONLY);
struct stat firmStat;
if (fh == B_ERROR || fstat(fh, &firmStat) < 0) { if (fh == B_ERROR || fstat(fh, &firmStat) < 0) {
TRACE_ALWAYS("Error: Unable to open the firmware at %s\n", FIRM_BIN); TRACE_ALWAYS("Error: Unable to open the firmware at %s\n", FIRM_BIN);
return fh; return fh;
@@ -1226,36 +1200,37 @@ BeceemDevice::PushFirmware(unsigned int loc)
// The size of the firmware can very slightly // The size of the firmware can very slightly
// CLEAR 1900 Beceem firmware is 2018596 // CLEAR 1900 Beceem firmware is 2018596
// Sprint 1901 Beceem firmware is 2028080 // Sprint 1901 Beceem firmware is 2028080
file_size = firmStat.st_size; size_t file_size = firmStat.st_size;
TRACE_ALWAYS("Info: %ld byte firmware to be pushed to 0x%x on device.\n", TRACE_ALWAYS("Info: %ld byte firmware to be pushed to 0x%x on device.\n",
file_size, loc); file_size, loc);
// For the push we load the file into the buffer // For the push we load the file into the buffer
buffer=(unsigned int*)malloc(MAX_USB_TRANSFER); unsigned int* buffer = (unsigned int*)malloc(MAX_USB_TRANSFER);
if (!buffer) { if (!buffer) {
TRACE_ALWAYS("Error: Memory allocation error.\n"); TRACE_ALWAYS("Error: Memory allocation error.\n");
return B_ERROR; return B_ERROR;
} }
// TODO : Firmware Download : investigate this, SHADOW clearing thing causes a KDL atm // TODO : Firmware Download : investigate this, SHADOW clearing causes a KDL
#if 0 #if 0
// Clear the NVM SHADOW signature always before fw download. // Clear the NVM SHADOW signature always before fw download.
WriteRegister(EEPROM_CAL_DATA_INTERNAL_LOC-4, 1, 0); WriteRegister(EEPROM_CAL_DATA_INTERNAL_LOC-4, 1, 0);
WriteRegister(EEPROM_CAL_DATA_INTERNAL_LOC-8, 1, 0); WriteRegister(EEPROM_CAL_DATA_INTERNAL_LOC-8, 1, 0);
#endif #endif
int chipwriteloc = 0;
int readposition = 0;
status_t result;
// We have to spoon feed the data to the usb device as it is probbably too // We have to spoon feed the data to the usb device as it is probbably too
// much to be written in one go. // much to be written in one go.
while (1) while (1) {
{ readposition = read(fh, buffer, MAX_USB_TRANSFER);
readposition = read(fh , buffer, MAX_USB_TRANSFER);
if (readposition <= 0) if (readposition <= 0) {
{ if (readposition < 0) {
if (readposition < 0)
{
TRACE_ALWAYS("Error: Error reading firmware.\n"); TRACE_ALWAYS("Error: Error reading firmware.\n");
result = B_ERROR; result = B_ERROR;
} else { } else {
@@ -1271,22 +1246,20 @@ BeceemDevice::PushFirmware(unsigned int loc)
// As readposition should always be less then MAX_USB_TRANSFER // As readposition should always be less then MAX_USB_TRANSFER
// and we have checked the validity of read's output above. // and we have checked the validity of read's output above.
if (WriteRegister(loc + chipwriteloc, readposition, buffer) != B_OK) if (WriteRegister(loc + chipwriteloc, readposition, buffer) != B_OK) {
{
TRACE_ALWAYS("Write failure\n"); TRACE_ALWAYS("Write failure\n");
result = B_ERROR; result = B_ERROR;
break; break;
} }
// +1 as we don't want to write the same sector twice // +1 as we don't want to write the same sector twice
chipwriteloc += (MAX_USB_TRANSFER+1); chipwriteloc += MAX_USB_TRANSFER + 1;
} }
free(buffer); free(buffer);
close(fh); close(fh);
if (result != B_OK) if (result != B_OK) {
{
TRACE_ALWAYS("Error: Push of firmware to device failed :%d\n", TRACE_ALWAYS("Error: Push of firmware to device failed :%d\n",
result); result);
return B_ERROR; return B_ERROR;