no functional change; header copyright correction; more spacing/line-length cleanup, yes there a lot more to go

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40551 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV
2011-02-18 20:30:05 +00:00
parent 7f08510a9a
commit 1b53751478
10 changed files with 225 additions and 139 deletions
@@ -8,14 +8,17 @@
* Description: Wrangle Beceem volatile DDR memory. * Description: Wrangle Beceem volatile DDR memory.
*/ */
#include "Settings.h" #include "Settings.h"
#include "BeceemDDR.h" #include "BeceemDDR.h"
BeceemDDR::BeceemDDR() BeceemDDR::BeceemDDR()
{ {
TRACE("Debug: Load DDR handler\n"); TRACE("Debug: Load DDR handler\n");
} }
status_t status_t
BeceemDDR::DDRInit(WIMAX_DEVICE* swmxdevice) BeceemDDR::DDRInit(WIMAX_DEVICE* swmxdevice)
{ {
@@ -1,18 +1,24 @@
/* /*
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <[email protected]> * Copyright (c) 2010 Alexander von Gluck <[email protected]>
* Distributed under the terms of the GNU General Public License. * Distributed under the terms of the GNU General Public License.
* *
* Based on GPL code developed by: Beceem Communications Pvt. Ltd * Based on GPL code developed by: Beceem Communications Pvt. Ltd
* *
* Driver for USB Ethernet Control Model devices * Authors:
* Copyright (C) 2008 Michael Lotz <[email protected]> * Alexander von Gluck, <[email protected]>
* Distributed under the terms of the MIT license. *
* Partially using:
* USB Ethernet Control Model devices
* (c) 2008 by Michael Lotz, <[email protected]>
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver
* (c) 2008 by S.Zharski, <[email protected]>
* *
* This code is the entry point for the operating system to * This code is the entry point for the operating system to
* Beceem device communications. * Beceem device communications.
*/ */
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <unistd.h> #include <unistd.h>
@@ -24,10 +30,10 @@
#include "BeOSCompatibility.h" // for pseudo mutex #include "BeOSCompatibility.h" // for pseudo mutex
#endif #endif
#include "BeceemDevice.h"
#include "Driver.h" #include "Driver.h"
#include "Settings.h" #include "Settings.h"
#include "BeceemDevice.h"
mutex gUSBLock; mutex gUSBLock;
@@ -1,17 +1,19 @@
/* /*
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <[email protected]> * Copyright 2010-2011 Haiku, Inc. All rights reserved.
* Distributed under the terms of the GNU General Public License.
*
* Based on GPL code developed by: Beceem Communications Pvt. Ltd
*
* Driver for USB Ethernet Control Model devices
* Copyright (C) 2008 Michael Lotz <[email protected]>
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Description: Wrangle Beceem wimax usb device * Authors:
* Alexander von Gluck, <[email protected]>
*
* Partially using:
* USB Ethernet Control Model devices
* (c) 2008 by Michael Lotz, <[email protected]>
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver
* (c) 2008 by S.Zharski, <[email protected]>
*/ */
#ifndef _USB_BECEEM_DEVICE_H_ #ifndef _USB_BECEEM_DEVICE_H_
#define _USB_BECEEM_DEVICE_H_ #define _USB_BECEEM_DEVICE_H_
@@ -1,42 +1,52 @@
/* /*
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <[email protected]> * Copyright 2010-2011 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
*
* Authors:
* Alexander von Gluck, <[email protected]>
*/ */
#ifndef _USB_BECEEM_LED_H_ #ifndef _USB_BECEEM_LED_H_
#define _USB_BECEEM_LED_H_ #define _USB_BECEEM_LED_H_
#include <ByteOrder.h>
#include <ByteOrder.h>
#include "DeviceStruct.h" #include "DeviceStruct.h"
class BeceemLED class BeceemLED
{ {
public: public:
BeceemLED(); BeceemLED();
status_t LEDInit(WIMAX_DEVICE* wmxdevice); status_t LEDInit(WIMAX_DEVICE* wmxdevice);
status_t LEDThreadTerminate(); status_t LEDThreadTerminate();
status_t LEDOff(unsigned int index); status_t LEDOff(unsigned int index);
status_t LEDOn(unsigned int index); status_t LEDOn(unsigned int index);
status_t LightsOut(); status_t LightsOut();
static status_t LEDThread(void *cookie); static status_t LEDThread(void *cookie);
WIMAX_DEVICE* pwmxdevice; WIMAX_DEVICE* pwmxdevice;
// yuck. These are in a parent class // yuck. These are in a parent class
virtual status_t ReadRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; virtual status_t ReadRegister(unsigned int reg,
virtual status_t WriteRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; size_t size, uint32_t* buffer)
virtual status_t BizarroReadRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; { return NULL; };
virtual status_t BizarroWriteRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; virtual status_t WriteRegister(unsigned int reg,
size_t size, uint32_t* buffer)
{ return NULL; };
virtual status_t BizarroReadRegister(unsigned int reg,
size_t size, uint32_t* buffer)
{ return NULL; };
virtual status_t BizarroWriteRegister(unsigned int reg,
size_t size, uint32_t* buffer)
{ return NULL; };
private: private:
status_t GPIOReset(); status_t GPIOReset();
}; };
typedef enum _LEDColors{ typedef enum _LEDColors{
RED_LED = 1, RED_LED = 1,
BLUE_LED = 2, BLUE_LED = 2,
@@ -44,5 +54,6 @@ typedef enum _LEDColors{
GREEN_LED = 4 GREEN_LED = 4
} LEDColors; } LEDColors;
#endif // _USB_BECEEM_LED_H #endif // _USB_BECEEM_LED_H
@@ -20,6 +20,7 @@
#include "BeceemDevice.h" #include "BeceemDevice.h"
#include "BeceemNVM.h" #include "BeceemNVM.h"
BeceemNVM::BeceemNVM() BeceemNVM::BeceemNVM()
{ {
TRACE("Debug: Load non-volatile memory handler\n"); TRACE("Debug: Load non-volatile memory handler\n");
@@ -84,7 +85,7 @@ BeceemNVM::NVMDetect()
EEPROMBulkRead(0x0, 4, &uiData); EEPROMBulkRead(0x0, 4, &uiData);
if (uiData == BECM) if (uiData == BECM)
{ {
TRACE_ALWAYS("Info: EEPROM non-volatile memory detected.\n"); TRACE_ALWAYS("Info: EEPROM nvm detected.\n");
pwmxdevice->nvmType = NVM_EEPROM; pwmxdevice->nvmType = NVM_EEPROM;
pwmxdevice->nvmDSDSize = EEPROMGetSize(); pwmxdevice->nvmDSDSize = EEPROMGetSize();
return B_OK; return B_OK;
@@ -95,9 +96,9 @@ BeceemNVM::NVMDetect()
return B_ERROR; return B_ERROR;
FlashBulkRead(0x0 + pwmxdevice->nvmFlashCalStart, 4, &uiData); FlashBulkRead(0x0 + pwmxdevice->nvmFlashCalStart, 4, &uiData);
if(uiData == BECM) if (uiData == BECM)
{ {
TRACE_ALWAYS("Info: Flash non-volatile memory detected.\n"); TRACE_ALWAYS("Info: Flash nvm detected.\n");
pwmxdevice->nvmType = NVM_FLASH; pwmxdevice->nvmType = NVM_FLASH;
pwmxdevice->nvmDSDSize = FlashGetSize(); pwmxdevice->nvmDSDSize = FlashGetSize();
return B_OK; return B_OK;
@@ -105,7 +106,7 @@ BeceemNVM::NVMDetect()
pwmxdevice->nvmType = NVM_UNKNOWN; pwmxdevice->nvmType = NVM_UNKNOWN;
TRACE_ALWAYS("Error: Couldn't detect non-volatile storage method, found 0x%X\n", TRACE_ALWAYS("Error: Couldn't detect nvm storage method, found 0x%X\n",
uiData); uiData);
return B_ERROR; return B_ERROR;
} }
@@ -125,7 +126,8 @@ BeceemNVM::NVMChipSelect(unsigned int offset)
if (bSelectedChip == ChipIndex) if (bSelectedChip == ChipIndex)
return B_OK; return B_OK;
TRACE("Debug: Selecting chip %d for transaction at 0x%x\n", ChipIndex, offset); TRACE("Debug: Selecting chip %d for transaction at 0x%x\n",
ChipIndex, offset);
// Migrate selected chip to new selection // Migrate selected chip to new selection
bSelectedChip = ChipIndex; bSelectedChip = ChipIndex;
@@ -136,7 +138,7 @@ BeceemNVM::NVMChipSelect(unsigned int offset)
// TRACE("Reading GPIO config 0x%x\n", &GPIOConfig); // TRACE("Reading GPIO config 0x%x\n", &GPIOConfig);
// TRACE("Reading Flash config 0x%x\n", &FlashConfig); // TRACE("Reading Flash config 0x%x\n", &FlashConfig);
switch(ChipIndex) switch (ChipIndex)
{ {
case 0: case 0:
PartNum = 0; PartNum = 0;
@@ -190,7 +192,7 @@ BeceemNVM::NVMRead(unsigned int offset, unsigned int size, unsigned int* buffer)
// Increase offset by FlashCalibratedStart // Increase offset by FlashCalibratedStart
myOffset = offset + pwmxdevice->nvmFlashCalStart; myOffset = offset + pwmxdevice->nvmFlashCalStart;
TRACE("Debug: Performing read of non-volatile flash memory at 0x%x (%d)\n", TRACE("Debug: Performing read of flash nvm at 0x%x (%d)\n",
myOffset, size); myOffset, size);
// If firmware was already pushed, Beceem notes a hardware bug here. // If firmware was already pushed, Beceem notes a hardware bug here.
@@ -257,16 +259,21 @@ int
BeceemNVM::FlashGetBaseAddr() BeceemNVM::FlashGetBaseAddr()
{ {
if (pwmxdevice->driverDDRinit == true) { if (pwmxdevice->driverDDRinit == true) {
if (pwmxdevice->nvmFlashCSDone == true && pwmxdevice->nvmFlashRaw == false && if (pwmxdevice->nvmFlashCSDone == true
!((pwmxdevice->nvmFlashMajor == 1) && (pwmxdevice->nvmFlashMinor == 1)) ) { && pwmxdevice->nvmFlashRaw == false
&& !((pwmxdevice->nvmFlashMajor == 1)
&& (pwmxdevice->nvmFlashMinor == 1))) {
return pwmxdevice->nvmFlashBaseAddr; return pwmxdevice->nvmFlashBaseAddr;
} else { } else {
return FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT; return FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT;
} }
} else { } else {
if (pwmxdevice->nvmFlashCSDone == true && pwmxdevice->nvmFlashRaw == false && if (pwmxdevice->nvmFlashCSDone == true
!((pwmxdevice->nvmFlashMajor == 1) && (pwmxdevice->nvmFlashMinor == 1)) ) { && pwmxdevice->nvmFlashRaw == false
return pwmxdevice->nvmFlashBaseAddr | FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT; && !((pwmxdevice->nvmFlashMajor == 1)
&& (pwmxdevice->nvmFlashMinor == 1))) {
return pwmxdevice->nvmFlashBaseAddr
| FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
} else { } else {
return FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT; return FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT;
} }
@@ -298,7 +305,8 @@ BeceemNVM::FlashReadID()
// Read SPI READQ Register, The output will be 4 bytes long // Read SPI READQ Register, The output will be 4 bytes long
// The ID is the first 3 bytes. // The ID is the first 3 bytes.
BizarroReadRegister(FLASH_SPI_READQ_REG, sizeof(RDID), (unsigned int*)&RDID); BizarroReadRegister(FLASH_SPI_READQ_REG, sizeof(RDID),
(unsigned int*)&RDID);
return (RDID >>8); return (RDID >>8);
} }
@@ -325,16 +333,21 @@ BeceemNVM::FlashReadCS()
} }
// CS Signature(4), Minor(2), Major(2) // CS Signature(4), Minor(2), Major(2)
FlashBulkRead(pwmxdevice->nvmFlashCSStart, 8, (unsigned int*)pwmxdevice->nvmFlashCSInfo); FlashBulkRead(pwmxdevice->nvmFlashCSStart, 8,
pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion = ntohl(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion); (unsigned int*)pwmxdevice->nvmFlashCSInfo);
pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion
= ntohl(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion);
TRACE_ALWAYS("Info: Flash CS Version/Signature: 0x%X/0x%X\n", TRACE_ALWAYS("Info: Flash CS Version/Signature: 0x%X/0x%X\n",
(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion), (pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion),
ntohl(pwmxdevice->nvmFlashCSInfo->MagicNumber)); ntohl(pwmxdevice->nvmFlashCSInfo->MagicNumber));
if ( ntohl(pwmxdevice->nvmFlashCSInfo->MagicNumber) == FLASH_CS_SIGNATURE ) { if (ntohl(pwmxdevice->nvmFlashCSInfo->MagicNumber) == FLASH_CS_SIGNATURE) {
pwmxdevice->nvmFlashMajor = MAJOR_VERSION(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion); pwmxdevice->nvmFlashMajor
pwmxdevice->nvmFlashMinor = MINOR_VERSION(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion); = MAJOR_VERSION(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion);
pwmxdevice->nvmFlashMinor
= MINOR_VERSION(pwmxdevice->nvmFlashCSInfo->FlashLayoutVersion);
} else { } else {
TRACE_ALWAYS("Error: Unknown flash magic signature!\n"); TRACE_ALWAYS("Error: Unknown flash magic signature!\n");
pwmxdevice->nvmFlashMajor = 0; pwmxdevice->nvmFlashMajor = 0;
@@ -345,16 +358,20 @@ BeceemNVM::FlashReadCS()
if (pwmxdevice->nvmFlashMajor == 0x1) if (pwmxdevice->nvmFlashMajor == 0x1)
{ {
// device is older flash map // device is older flash map
FlashBulkRead(pwmxdevice->nvmFlashCSStart, sizeof(FLASH_CS_INFO), (unsigned int*)pwmxdevice->nvmFlashCSInfo); FlashBulkRead(pwmxdevice->nvmFlashCSStart, sizeof(FLASH_CS_INFO),
(unsigned int*)pwmxdevice->nvmFlashCSInfo);
snooze(100); snooze(100);
FlashCSFlip(pwmxdevice->nvmFlashCSInfo); FlashCSFlip(pwmxdevice->nvmFlashCSInfo);
FlashCSDump(pwmxdevice->nvmFlashCSInfo); FlashCSDump(pwmxdevice->nvmFlashCSInfo);
pwmxdevice->nvmFlashCalStart = (pwmxdevice->nvmFlashCSInfo->OffsetFromZeroForCalibrationStart); pwmxdevice->nvmFlashCalStart
= (pwmxdevice->nvmFlashCSInfo->OffsetFromZeroForCalibrationStart);
if(!((pwmxdevice->nvmFlashMajor == 1) && (pwmxdevice->nvmFlashMinor == 1))) if (!((pwmxdevice->nvmFlashMajor == 1)
&& (pwmxdevice->nvmFlashMinor == 1)))
{ {
pwmxdevice->nvmFlashCSStart = (pwmxdevice->nvmFlashCSInfo->OffsetFromZeroForControlSectionStart); pwmxdevice->nvmFlashCSStart
= (pwmxdevice->nvmFlashCSInfo->OffsetFromZeroForControlSectionStart);
} }
// TODO : Flash Write sizes.. no write support atm // TODO : Flash Write sizes.. no write support atm
@@ -373,12 +390,13 @@ BeceemNVM::FlashReadCS()
pwmxdevice->fpFlashWriteWithStatusCheck = flashWriteStatus; pwmxdevice->fpFlashWriteWithStatusCheck = flashWriteStatus;
} }
*/ */
//BcmGetFlashSectorSize(Adapter, (Adapter->psFlashCSInfo->FlashSectorSizeSig), //BcmGetFlashSectorSize(Adapter, (Adapter->psFlashCSInfo->FlashSectorSizeSig),
// (Adapter->psFlashCSInfo->FlashSectorSize)); // (Adapter->psFlashCSInfo->FlashSectorSize));
#endif #endif
pwmxdevice->nvmFlashBaseAddr = pwmxdevice->nvmFlashCSInfo->FlashBaseAddr & 0xFCFFFFFF; pwmxdevice->nvmFlashBaseAddr = pwmxdevice->nvmFlashCSInfo->FlashBaseAddr
& 0xFCFFFFFF;
} else { } else {
// device is newer flash map layout // device is newer flash map layout
@@ -604,11 +622,12 @@ BeceemNVM::FlashBulkWrite(unsigned int offset, unsigned int size, unsigned int*
if (NumSectTobeRead > 1) if (NumSectTobeRead > 1)
{ {
memcpy(&TempBuffer[CurrSectOffsetAddr], ucBuffer, SectBoundary-(SectAlignAddr+CurrSectOffsetAddr)); memcpy(&TempBuffer[CurrSectOffsetAddr], ucBuffer,
SectBoundary - (SectAlignAddr + CurrSectOffsetAddr));
ucBuffer += ((SectBoundary-(SectAlignAddr + CurrSectOffsetAddr))); ucBuffer += ((SectBoundary-(SectAlignAddr + CurrSectOffsetAddr)));
size -= (SectBoundary-(SectAlignAddr + CurrSectOffsetAddr)); size -= (SectBoundary-(SectAlignAddr + CurrSectOffsetAddr));
} else { } else {
memcpy(&TempBuffer[CurrSectOffsetAddr],ucBuffer, size); memcpy(&TempBuffer[CurrSectOffsetAddr], ucBuffer, size);
} }
// TODO : SaveHeaderIfPresent if IsFlash2x? // TODO : SaveHeaderIfPresent if IsFlash2x?
@@ -668,7 +687,7 @@ BeceemNVM::FlashBulkWrite(unsigned int offset, unsigned int size, unsigned int*
} }
#endif #endif
if(BPStatus) if (BPStatus)
{ {
RestoreBlockProtect(BPStatus); RestoreBlockProtect(BPStatus);
BPStatus = 0; BPStatus = 0;
@@ -773,15 +792,15 @@ BeceemNVM::EEPROMGetSize()
unsigned int uiIndex = 0; unsigned int uiIndex = 0;
// To find the EEPROM size read the possible boundaries of the // To find the EEPROM size read the possible boundaries of the
// EEPROM like 4K,8K etc..accessing the EEPROM beyond its size will // EEPROM like 4K,8K etc..accessing the EEPROM beyond its size will
// result in wrap around. So when we get the End of the EEPROM we will // result in wrap around. So when we get the End of the EEPROM we will
// get 'BECM' string which is indeed at offset 0. // get 'BECM' string which is indeed at offset 0.
EEPROMBulkRead(0x0, 4, &uiData); EEPROMBulkRead(0x0, 4, &uiData);
if (ntohl(uiData) == BECM) if (ntohl(uiData) == BECM)
{ {
// If EEPROM is present ,it will have 'BECM' string at 0th offset. // If EEPROM is present, it will have 'BECM' string at 0th offset.
for (uiIndex = 1 ; uiIndex <= 256; uiIndex *= 2) for (uiIndex = 1 ; uiIndex <= 256; uiIndex *= 2)
{ {
@@ -854,7 +873,8 @@ BeceemNVM::EEPROMRead(unsigned int offset, unsigned int *pdwData)
return B_ERROR; return B_ERROR;
} }
BizarroReadRegister(EEPROM_SPI_Q_STATUS_REG, sizeof(unsigned int), &Value); BizarroReadRegister(EEPROM_SPI_Q_STATUS_REG, sizeof(unsigned int),
&Value);
} }
BizarroReadRegister(EEPROM_READ_DATAQ_REG, sizeof(unsigned int), &Value); BizarroReadRegister(EEPROM_READ_DATAQ_REG, sizeof(unsigned int), &Value);
@@ -2,10 +2,9 @@
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver.
* Copyright (c) 2010 Alexander von Gluck <kallisti5@unixzen.com> * Copyright (c) 2010 Alexander von Gluck <kallisti5@unixzen.com>
* Distributed under the terms of the GNU General Public License. * Distributed under the terms of the GNU General Public License.
* *
* Based on GPL code developed by: Beceem Communications Pvt. Ltd * Based on GPL code developed by: Beceem Communications Pvt. Ltd
*/ */
#ifndef _USB_BECEEM_NVM_H_ #ifndef _USB_BECEEM_NVM_H_
#define _USB_BECEEM_NVM_H_ #define _USB_BECEEM_NVM_H_
@@ -26,19 +25,23 @@
#define FLASH_PART_SIZE (16 * 1024 * 1024) #define FLASH_PART_SIZE (16 * 1024 * 1024)
#define FLASH_CONFIG_REG 0xAF003050 #define FLASH_CONFIG_REG 0xAF003050
#define FLASH_GPIO_CONFIG_REG 0xAF000030 #define FLASH_GPIO_CONFIG_REG 0xAF000030
#define FLASH_CS_INFO_START_ADDR 0xFF0000 // Location for Flash calibration info
// Locations for Flash calibration info
#define FLASH_CS_INFO_START_ADDR 0xFF0000
#define FLASH_AUTO_INIT_BASE_ADDR 0xF00000 #define FLASH_AUTO_INIT_BASE_ADDR 0xF00000
#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000 // Flash base before DDR Init
#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000 // Flash base after DDR Init // NVM Flash addresses before and after DDR Init
#define FLASH_CONTIGIOUS_START_ADDR_BEFORE_INIT 0x1F000000
#define FLASH_CONTIGIOUS_START_ADDR_AFTER_INIT 0x1C000000
#define FLASH_SPI_CMDQ_REG 0xAF003040 #define FLASH_SPI_CMDQ_REG 0xAF003040
#define FLASH_SPI_WRITEQ_REG 0xAF003044 #define FLASH_SPI_WRITEQ_REG 0xAF003044
#define FLASH_SPI_READQ_REG 0xAF003048 #define FLASH_SPI_READQ_REG 0xAF003048
#define FLASH_SIZE_ADDR 0xFFFFEC // Location of Flash memory size #define FLASH_SIZE_ADDR 0xFFFFEC
#define FLASH_CMD_STATUS_REG_WRITE 0x01 #define FLASH_CMD_STATUS_REG_WRITE 0x01
#define FLASH_CMD_STATUS_REG_READ 0x05 #define FLASH_CMD_STATUS_REG_READ 0x05
#define FLASH_CMD_WRITE_ENABLE 0x06 #define FLASH_CMD_WRITE_ENABLE 0x06
#define FLASH_CMD_READ_ID 0x9F // Command to read the flash chip ID #define FLASH_CMD_READ_ID 0x9F
#define FLASH_CS_SIGNATURE 0xBECEF1A5 // Beceem FLAS(H) (get it?) #define FLASH_CS_SIGNATURE 0xBECEF1A5
// Our EEPROM addresses // Our EEPROM addresses
#define EEPROM_SPI_Q_STATUS_REG 0x0F003008 #define EEPROM_SPI_Q_STATUS_REG 0x0F003008
@@ -57,9 +60,9 @@
#define NVM_VERSION_OFFSET 0x020E #define NVM_VERSION_OFFSET 0x020E
#define NVM_SECTOR_SIZE 0x10000 #define NVM_SECTOR_SIZE 0x10000
#define NVM_READ_DATA_AVAIL 0x00000020 // was EEPROM_READ_DATA_AVAIL #define NVM_READ_DATA_AVAIL 0x00000020 // was EEPROM_READ_DATA_AVAIL
#define NVM_SPI_Q_STATUS1_REG 0x0F003004 // was EEPROM_SPI_Q_STATUS1_REG #define NVM_SPI_Q_STATUS1_REG 0x0F003004 // was EEPROM_SPI_Q_STATUS1_REG
#define NVM_ALL_QUEUE_FLUSH 0x0000000f // was EEPROM_ALL_QUEUE_FLUSH #define NVM_ALL_QUEUE_FLUSH 0x0000000f // was EEPROM_ALL_QUEUE_FLUSH
#define SCSI_FIRMWARE_MINOR_VERSION 0x5 #define SCSI_FIRMWARE_MINOR_VERSION 0x5
@@ -70,50 +73,68 @@
#define MAJOR_VERSION(x) (x & 0xFFFF) #define MAJOR_VERSION(x) (x & 0xFFFF)
#define MINOR_VERSION(x) ((x >>16) & 0xFFFF) #define MINOR_VERSION(x) ((x >>16) & 0xFFFF)
class BeceemNVM class BeceemNVM
{ {
int bSelectedChip; // selected chip
public: public:
BeceemNVM(); BeceemNVM();
status_t NVMInit(WIMAX_DEVICE* swmxdevice); status_t NVMInit(WIMAX_DEVICE* swmxdevice);
status_t ReadMACFromNVM(ether_address *address); status_t ReadMACFromNVM(ether_address *address);
status_t ValidateDSD(unsigned long hwParam); status_t ValidateDSD(unsigned long hwParam);
int NVMRead(unsigned int offset, unsigned int size, unsigned int* buffer); int NVMRead(unsigned int offset, unsigned int size,
int NVMWrite(unsigned int offset, unsigned int size, unsigned int* buffer); unsigned int* buffer);
int NVMWrite(unsigned int offset, unsigned int size,
unsigned int* buffer);
// yuck. These are in a child class class // yuck. These are in a child class class
virtual status_t ReadRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; virtual status_t ReadRegister(unsigned int reg,
virtual status_t WriteRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; size_t size, uint32_t* buffer)
virtual status_t BizarroReadRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; { return NULL; };
virtual status_t BizarroWriteRegister(unsigned int reg, size_t size, uint32_t* buffer){ return NULL; }; virtual status_t WriteRegister(unsigned int reg,
size_t size, uint32_t* buffer)
{ return NULL; };
virtual status_t BizarroReadRegister(unsigned int reg,
size_t size, uint32_t* buffer)
{ return NULL; };
virtual status_t BizarroWriteRegister(unsigned int reg,
size_t size, uint32_t* buffer)
{ return NULL; };
int bSelectedChip; // selected chip
private: private:
WIMAX_DEVICE* pwmxdevice; WIMAX_DEVICE* pwmxdevice;
status_t NVMDetect(); status_t NVMDetect();
status_t NVMFlush(); status_t NVMFlush();
status_t NVMChipSelect(unsigned int offset); status_t NVMChipSelect(unsigned int offset);
status_t RestoreBlockProtect(unsigned long writestatus); status_t RestoreBlockProtect(unsigned long writestatus);
unsigned long DisableBlockProtect(unsigned int offset, size_t size); unsigned long DisableBlockProtect(unsigned int offset,
size_t size);
int FlashGetBaseAddr(); int FlashGetBaseAddr();
unsigned long FlashReadID(); unsigned long FlashReadID();
status_t FlashReadCS(); status_t FlashReadCS();
status_t FlashSectorErase(unsigned int addr, unsigned int numOfSectors); status_t FlashSectorErase(unsigned int addr,
status_t FlashBulkRead(unsigned int offset, unsigned int size, unsigned int* buffer); unsigned int numOfSectors);
status_t FlashBulkWrite(unsigned int offset, unsigned int size, unsigned int* buffer); status_t FlashBulkRead(unsigned int offset,
status_t FlashCSFlip(PFLASH_CS_INFO FlashCSInfo); unsigned int size, unsigned int* buffer);
status_t FlashCSDump(PFLASH_CS_INFO FlashCSInfo); status_t FlashBulkWrite(unsigned int offset,
unsigned int size, unsigned int* buffer);
status_t FlashCSFlip(PFLASH_CS_INFO FlashCSInfo);
status_t FlashCSDump(PFLASH_CS_INFO FlashCSInfo);
unsigned int EEPROMGetSize(); unsigned int EEPROMGetSize();
unsigned int FlashGetSize(); unsigned int FlashGetSize();
status_t EEPROMRead(unsigned int offset, unsigned int *pdwData); status_t EEPROMRead(unsigned int offset,
status_t EEPROMBulkRead( unsigned int offset, size_t numBytes, unsigned int* buffer); unsigned int *pdwData);
status_t EEPROMBulkRead( unsigned int offset,
size_t numBytes, unsigned int* buffer);
}; };
#endif // _USB_BECEEM_NVM_H #endif // _USB_BECEEM_NVM_H
@@ -1,19 +1,19 @@
/* /*
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <kallisti5@unixzen.com> * Copyright 2010-2011 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Heavily based on code of :
* Driver for USB Ethernet Control Model devices
* Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* The Beceem chipset can be used via multiple interfaces * Authors:
* such as PCMCIA, MII, PCI, SDIO, and Serial. However I have * Alexander von Gluck, <kallisti5@unixzen.com>
* only found it implemented commercially for PC use as USB.
* *
* Partially using:
* USB Ethernet Control Model devices
* (c) 2008 by Michael Lotz, <mmlr@mlotz.ch>
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver
* (c) 2008 by S.Zharski, <imker@gmx.li>
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@@ -28,12 +28,14 @@
#include "Driver.h" #include "Driver.h"
#include "Settings.h" #include "Settings.h"
int32 api_version = B_CUR_DRIVER_API_VERSION; int32 api_version = B_CUR_DRIVER_API_VERSION;
static const char *sDeviceBaseName = "net/usb_beceemwmx/"; static const char *sDeviceBaseName = "net/usb_beceemwmx/";
BeceemDevice *gBeceemDevices[MAX_DEVICES]; BeceemDevice *gBeceemDevices[MAX_DEVICES];
char *gDeviceNames[MAX_DEVICES + 1]; char *gDeviceNames[MAX_DEVICES + 1];
usb_module_info *gUSBModule = NULL; usb_module_info *gUSBModule = NULL;
usb_support_descriptor gSupportedDevices[] = { usb_support_descriptor gSupportedDevices[] = {
{ 0, 0, 0, 0x0489, 0xe016}, { 0, 0, 0, 0x0489, 0xe016},
// "Ubee WiMAX Mobile USB - PXU1900 (Clear)" // "Ubee WiMAX Mobile USB - PXU1900 (Clear)"
@@ -47,8 +49,10 @@ usb_support_descriptor gSupportedDevices[] = {
// "ZTE TU25 WiMAX Adapter [Beceem BCS200]" // "ZTE TU25 WiMAX Adapter [Beceem BCS200]"
}; };
mutex gDriverLock; mutex gDriverLock;
// auto-release helper class // auto-release helper class
class DriverSmartLock { class DriverSmartLock {
public: public:
@@ -56,6 +60,7 @@ public:
~DriverSmartLock() { mutex_unlock(&gDriverLock); } ~DriverSmartLock() { mutex_unlock(&gDriverLock); }
}; };
BeceemDevice * BeceemDevice *
create_beceem_device(usb_device device) create_beceem_device(usb_device device)
{ {
@@ -1,18 +1,21 @@
/* /*
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <kallisti5@unixzen.com> * Copyright 2010-2011 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Heavily based on code of : * Authors:
* Driver for USB Ethernet Control Model devices * Alexander von Gluck, <kallisti5@unixzen.com>
* Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
* Distributed under the terms of the MIT license.
* *
* Partially using:
* USB Ethernet Control Model devices
* (c) 2008 by Michael Lotz, <mmlr@mlotz.ch>
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver
* (c) 2008 by S.Zharski, <imker@gmx.li>
*/ */
#ifndef _USB_BECEEM_DRIVER_H_ #ifndef _USB_BECEEM_DRIVER_H_
#define _USB_BECEEM_DRIVER_H_ #define _USB_BECEEM_DRIVER_H_
#include <OS.h> #include <OS.h>
#include <KernelExport.h> #include <KernelExport.h>
#include <Drivers.h> #include <Drivers.h>
@@ -25,6 +28,7 @@
#include <util/kernel_cpp.h> #include <util/kernel_cpp.h>
#define DRIVER_NAME "usb_beceemwmx" #define DRIVER_NAME "usb_beceemwmx"
#define MAX_DEVICES 8 #define MAX_DEVICES 8
@@ -101,6 +105,7 @@ const char* const kVersion = "ver.5.2.45.1";
extern usb_module_info *gUSBModule; extern usb_module_info *gUSBModule;
extern "C" { extern "C" {
status_t usb_beceem_device_added(usb_device device, void **cookie); status_t usb_beceem_device_added(usb_device device, void **cookie);
status_t usb_beceem_device_removed(void *cookie); status_t usb_beceem_device_removed(void *cookie);
@@ -112,5 +117,6 @@ const char **publish_devices();
device_hooks *find_device(const char *name); device_hooks *find_device(const char *name);
} }
#endif //_USB_BECEEM_DRIVER_H_ #endif //_USB_BECEEM_DRIVER_H_
@@ -1,19 +1,24 @@
/* /*
* Beceem WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <kallisti5@unixzen.com> * Copyright 2010-2011 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Heavily based on code of :
* Driver for USB Ethernet Control Model devices
* Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors:
* Alexander von Gluck, <kallisti5@unixzen.com>
*
* Partially using:
* USB Ethernet Control Model devices
* (c) 2008 by Michael Lotz, <mmlr@mlotz.ch>
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver
* (c) 2008 by S.Zharski, <imker@gmx.li>
*/ */
#include <lock.h> // for mutex #include <lock.h> // for mutex
#include "Settings.h" #include "Settings.h"
bool gTraceOn = false; bool gTraceOn = false;
bool gTruncateLogFile = false; bool gTruncateLogFile = false;
bool gAddTimeStamp = true; bool gAddTimeStamp = true;
@@ -21,6 +26,7 @@ bool gTraceFlow = false;
static char *gLogFilePath = NULL; static char *gLogFilePath = NULL;
mutex gLogLock; mutex gLogLock;
static static
void create_log() void create_log()
{ {
@@ -33,6 +39,7 @@ void create_log()
mutex_init(&gLogLock, DRIVER_NAME"-logging"); mutex_init(&gLogLock, DRIVER_NAME"-logging");
} }
void load_settings() void load_settings()
{ {
void *handle = load_driver_settings(DRIVER_NAME); void *handle = load_driver_settings(DRIVER_NAME);
@@ -56,6 +63,7 @@ void load_settings()
create_log(); create_log();
} }
void release_settings() void release_settings()
{ {
if(gLogFilePath != NULL) { if(gLogFilePath != NULL) {
@@ -64,6 +72,7 @@ void release_settings()
} }
} }
void usb_beceem_trace(bool force, const char* func, const char *fmt, ...) void usb_beceem_trace(bool force, const char* func, const char *fmt, ...)
{ {
if(!(force || gTraceOn)) { if(!(force || gTraceOn)) {
@@ -1,22 +1,25 @@
/* /*
* Ubee WiMax USB Driver. * Beceem WiMax USB Driver
* Copyright (c) 2010 Alexander von Gluck <kallisti5@unixzen.com> * Copyright 2010-2011 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT license.
*
* Heavily based on code of :
* Driver for USB Ethernet Control Model devices
* Copyright (C) 2008 Michael Lotz <mmlr@mlotz.ch>
* Distributed under the terms of the MIT license. * Distributed under the terms of the MIT license.
* *
* Authors:
* Alexander von Gluck, <kallisti5@unixzen.com>
*
* Partially using:
* USB Ethernet Control Model devices
* (c) 2008 by Michael Lotz, <mmlr@mlotz.ch>
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver
* (c) 2008 by S.Zharski, <imker@gmx.li>
*/ */
#ifndef _USB_BECEEM_SETTINGS_H_ #ifndef _USB_BECEEM_SETTINGS_H_
#define _USB_BECEEM_SETTINGS_H_ #define _USB_BECEEM_SETTINGS_H_
#include <driver_settings.h>
#include <driver_settings.h>
#include "Driver.h" #include "Driver.h"
void load_settings(); void load_settings();
void release_settings(); void release_settings();