* 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:
@@ -40,7 +40,7 @@ mutex gUSBLock;
|
||||
|
||||
// auto-release helper class
|
||||
class USBSmartLock {
|
||||
public:
|
||||
public:
|
||||
USBSmartLock() { mutex_lock(&gUSBLock); }
|
||||
~USBSmartLock() { mutex_unlock(&gUSBLock); }
|
||||
};
|
||||
@@ -68,8 +68,7 @@ BeceemDevice::ReadRegister(unsigned int reg, size_t size, uint32_t* buffer)
|
||||
size, buffer,
|
||||
&actualLength);
|
||||
retries++ ;
|
||||
if (-ENODEV == result)
|
||||
{
|
||||
if (-ENODEV == result) {
|
||||
TRACE_ALWAYS("Error: Device was removed during USB read\n");
|
||||
break;
|
||||
}
|
||||
@@ -78,16 +77,14 @@ BeceemDevice::ReadRegister(unsigned int reg, size_t size, uint32_t* buffer)
|
||||
|
||||
if (result < 0) {
|
||||
TRACE_ALWAYS("Error: USB read request failure."
|
||||
" Result: %d; Attempt: %d.\n",
|
||||
result, retries);
|
||||
" Result: %d; Attempt: %d.\n", result, retries);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
if (size != actualLength) {
|
||||
TRACE_ALWAYS("Error: Size mismatch on USB read request."
|
||||
" Asked: %d; Got: %d; Attempt: %d.\n",
|
||||
size, actualLength, retries);
|
||||
" Asked: %d; Got: %d; Attempt: %d.\n", size, actualLength, retries);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -116,8 +113,7 @@ BeceemDevice::WriteRegister(unsigned int reg, size_t size, uint32_t* buffer)
|
||||
size, buffer,
|
||||
&actualLength);
|
||||
retries++ ;
|
||||
if (-ENODEV == result)
|
||||
{
|
||||
if (-ENODEV == result) {
|
||||
TRACE_ALWAYS("Error: Device was removed during USB write\n");
|
||||
break;
|
||||
}
|
||||
@@ -143,21 +139,23 @@ BeceemDevice::WriteRegister(unsigned int reg, size_t size, uint32_t* buffer)
|
||||
|
||||
|
||||
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
|
||||
|
||||
// Read then flip
|
||||
status_t Status = ReadRegister(reg, size, buffer);
|
||||
status_t status = ReadRegister(reg, size, buffer);
|
||||
|
||||
convertEndian(false, size, buffer);
|
||||
|
||||
return Status;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
|
||||
@@ -165,14 +163,14 @@ BeceemDevice::BizarroWriteRegister(unsigned int reg, size_t size, uint32_t* buff
|
||||
|
||||
convertEndian(true, size, buffer);
|
||||
|
||||
status_t Status = WriteRegister(reg, size, buffer);
|
||||
status_t status = WriteRegister(reg, size, buffer);
|
||||
// Flip then write
|
||||
|
||||
// as we modified the input data, and other things
|
||||
// outside this function may need it, restore the original val.
|
||||
*buffer = reload;
|
||||
|
||||
return Status;
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
@@ -299,9 +297,8 @@ BeceemDevice::Open(uint32 flags)
|
||||
return B_ERROR;
|
||||
|
||||
status_t result = StartDevice();
|
||||
if (result != B_OK) {
|
||||
if (result != B_OK)
|
||||
return result;
|
||||
}
|
||||
|
||||
// setup state notifications
|
||||
result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer,
|
||||
@@ -552,7 +549,6 @@ void
|
||||
BeceemDevice::Removed()
|
||||
{
|
||||
fHasConnection = false;
|
||||
|
||||
pwmxdevice->driverHalt = true;
|
||||
|
||||
TRACE("Debug: Pre InsideNotify\n");
|
||||
@@ -643,9 +639,6 @@ BeceemDevice::IdentifyChipset()
|
||||
status_t
|
||||
BeceemDevice::SetupDevice(bool deviceReplugged)
|
||||
{
|
||||
unsigned int value = 0;
|
||||
unsigned long dwReadValue = 0;
|
||||
|
||||
pwmxdevice->driverState = STATE_INIT;
|
||||
|
||||
// ID the Beceem chipset
|
||||
@@ -658,12 +651,11 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
|
||||
if (LoadConfig() != B_OK)
|
||||
return B_ERROR;
|
||||
|
||||
if (pwmxdevice->deviceChipID >= T3LPB)
|
||||
{
|
||||
if (pwmxdevice->deviceChipID >= T3LPB) {
|
||||
unsigned int value = 0;
|
||||
BizarroReadRegister(SYS_CFG, sizeof(value), &value);
|
||||
pwmxdevice->syscfgBefFw = value;
|
||||
if ((value & 0x60)== 0)
|
||||
{
|
||||
if ((value & 0x60) == 0) {
|
||||
TRACE("Debug: CPU is FlashBoot\n");
|
||||
pwmxdevice->CPUFlashBoot = true;
|
||||
}
|
||||
@@ -714,14 +706,13 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
|
||||
|
||||
TRACE("Debug: Raw PARAM pointer: 0x%x\n", pwmxdevice->hwParamPtr);
|
||||
|
||||
if (pwmxdevice->hwParamPtr < DSD_START_OFFSET ||
|
||||
pwmxdevice->hwParamPtr > pwmxdevice->nvmDSDSize - DSD_START_OFFSET)
|
||||
{
|
||||
if (pwmxdevice->hwParamPtr < DSD_START_OFFSET
|
||||
|| pwmxdevice->hwParamPtr > pwmxdevice->nvmDSDSize - DSD_START_OFFSET) {
|
||||
TRACE_ALWAYS("Error: DSD Status checksum mismatch\n");
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
dwReadValue = pwmxdevice->hwParamPtr;
|
||||
unsigned long dwReadValue = pwmxdevice->hwParamPtr;
|
||||
// hw paramater pointer
|
||||
dwReadValue = dwReadValue + DSD_START_OFFSET;
|
||||
// add DSD start offset
|
||||
@@ -893,7 +884,7 @@ BeceemDevice::_SetupEndpoints()
|
||||
} else if ((epd->attributes & USB_ENDPOINT_ATTR_MASK)
|
||||
== USB_ENDPOINT_ATTR_ISOCHRONOUS) {
|
||||
// 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
|
||||
} else {
|
||||
// Strange...
|
||||
@@ -916,8 +907,8 @@ BeceemDevice::_SetupEndpoints()
|
||||
gUSBModule->set_configuration(fDevice, config);
|
||||
|
||||
fNotifyEndpoint = interface->endpoint[notifyEndpoint].handle;
|
||||
fReadEndpoint = interface->endpoint[readEndpoint ].handle;
|
||||
fWriteEndpoint = interface->endpoint[writeEndpoint ].handle;
|
||||
fReadEndpoint = interface->endpoint[readEndpoint].handle;
|
||||
fWriteEndpoint = interface->endpoint[writeEndpoint].handle;
|
||||
|
||||
return B_OK;
|
||||
}
|
||||
@@ -1014,39 +1005,35 @@ BeceemDevice::StartDevice()
|
||||
status_t
|
||||
BeceemDevice::LoadConfig()
|
||||
{
|
||||
size_t file_size = 0;
|
||||
unsigned int* buffer = 0;
|
||||
struct stat cfgStat;
|
||||
int dtaread = 0;
|
||||
|
||||
int fh = open(FIRM_CFG, O_RDONLY);
|
||||
|
||||
struct stat cfgStat;
|
||||
if (fh == B_ERROR || fstat(fh, &cfgStat) < 0) {
|
||||
TRACE_ALWAYS("Error: Unable to open the configuration at %s\n", FIRM_CFG);
|
||||
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) {
|
||||
TRACE_ALWAYS("Error: Memory allocation error.\n");
|
||||
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");
|
||||
close(fh);
|
||||
free(buffer);
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
if (file_size != sizeof(VENDORCFG))
|
||||
{
|
||||
if (file_size != sizeof(VENDORCFG)) {
|
||||
TRACE_ALWAYS("Error: Size mismatch in vendor configuration struct!\n");
|
||||
close(fh);
|
||||
free(buffer);
|
||||
@@ -1127,43 +1114,38 @@ BeceemDevice::DumpConfig()
|
||||
status_t
|
||||
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);
|
||||
|
||||
struct stat cfgStat;
|
||||
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;
|
||||
}
|
||||
|
||||
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",
|
||||
loc);
|
||||
|
||||
buffer=(unsigned int*)malloc(MAX_USB_TRANSFER);
|
||||
unsigned int* buffer = (unsigned int*)malloc(MAX_USB_TRANSFER);
|
||||
|
||||
if (!buffer) {
|
||||
TRACE_ALWAYS("Error: Memory allocation error.\n");
|
||||
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
|
||||
// much to be written in one go.
|
||||
while (1)
|
||||
{
|
||||
readposition = read(fh , buffer, MAX_USB_TRANSFER);
|
||||
while (1) {
|
||||
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");
|
||||
result = B_ERROR;
|
||||
} else {
|
||||
@@ -1179,23 +1161,22 @@ BeceemDevice::PushConfig(unsigned int loc)
|
||||
|
||||
// As readposition should always be less then MAX_USB_TRANSFER
|
||||
// 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");
|
||||
result = B_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
// +1 as we don't want to write the same sector twice
|
||||
chipwriteloc += (MAX_USB_TRANSFER+1);
|
||||
chipwriteloc += MAX_USB_TRANSFER + 1;
|
||||
}
|
||||
|
||||
close(fh);
|
||||
free(buffer);
|
||||
|
||||
if (result < 0)
|
||||
{
|
||||
TRACE_ALWAYS("Error: Push of vendor configuration failed :%d\n", result);
|
||||
if (result < 0) {
|
||||
TRACE_ALWAYS("Error: Push of vendor configuration failed: %d\n",
|
||||
result);
|
||||
return B_ERROR;
|
||||
} else {
|
||||
TRACE_ALWAYS("Info: Push of vendor configuration was successful.\n");
|
||||
@@ -1207,16 +1188,9 @@ BeceemDevice::PushConfig(unsigned int loc)
|
||||
status_t
|
||||
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);
|
||||
|
||||
struct stat firmStat;
|
||||
if (fh == B_ERROR || fstat(fh, &firmStat) < 0) {
|
||||
TRACE_ALWAYS("Error: Unable to open the firmware at %s\n", FIRM_BIN);
|
||||
return fh;
|
||||
@@ -1226,36 +1200,37 @@ BeceemDevice::PushFirmware(unsigned int loc)
|
||||
// The size of the firmware can very slightly
|
||||
// CLEAR 1900 Beceem firmware is 2018596
|
||||
// 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",
|
||||
file_size, loc);
|
||||
|
||||
// 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) {
|
||||
TRACE_ALWAYS("Error: Memory allocation error.\n");
|
||||
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
|
||||
// Clear the NVM SHADOW signature always before fw download.
|
||||
WriteRegister(EEPROM_CAL_DATA_INTERNAL_LOC-4, 1, 0);
|
||||
WriteRegister(EEPROM_CAL_DATA_INTERNAL_LOC-8, 1, 0);
|
||||
#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
|
||||
// much to be written in one go.
|
||||
while (1)
|
||||
{
|
||||
readposition = read(fh , buffer, MAX_USB_TRANSFER);
|
||||
while (1) {
|
||||
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");
|
||||
result = B_ERROR;
|
||||
} else {
|
||||
@@ -1271,22 +1246,20 @@ BeceemDevice::PushFirmware(unsigned int loc)
|
||||
|
||||
// As readposition should always be less then MAX_USB_TRANSFER
|
||||
// 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");
|
||||
result = B_ERROR;
|
||||
break;
|
||||
}
|
||||
|
||||
// +1 as we don't want to write the same sector twice
|
||||
chipwriteloc += (MAX_USB_TRANSFER+1);
|
||||
chipwriteloc += MAX_USB_TRANSFER + 1;
|
||||
}
|
||||
|
||||
free(buffer);
|
||||
close(fh);
|
||||
|
||||
if (result != B_OK)
|
||||
{
|
||||
if (result != B_OK) {
|
||||
TRACE_ALWAYS("Error: Push of firmware to device failed :%d\n",
|
||||
result);
|
||||
return B_ERROR;
|
||||
|
||||
Reference in New Issue
Block a user