diff options
author | Suresh Mangipudi <smangipudi@nvidia.com> | 2010-07-24 01:13:56 -0700 |
---|---|---|
committer | Gary King <gking@nvidia.com> | 2010-07-26 15:24:17 -0700 |
commit | 76073198f9846a5510c48b72c13bc74a848edc10 (patch) | |
tree | 478431bf0562c8916c5108c79f29b2c5afddba2e /arch | |
parent | 86ec9122a2a50dd4652c05f1090c0f01a4110a6c (diff) |
[accelerometer]:Support on Ventana
removed the BoardID based identification, now use only Peripheral GUID for
determining if the board supports accelerometer or not
Change-Id: I95938ff4836cbb0bb8547e2d9684dfb534816bfc
Reviewed-on: http://git-master/r/4031
Tested-by: Suresh Mangipudi <smangipudi@nvidia.com>
Reviewed-by: Gary King <gking@nvidia.com>
Diffstat (limited to 'arch')
5 files changed, 209 insertions, 43 deletions
diff --git a/arch/arm/mach-tegra/odm_kit/platform/accelerometer/nvodm_accelerometer_kxtf9.c b/arch/arm/mach-tegra/odm_kit/platform/accelerometer/nvodm_accelerometer_kxtf9.c index 8cfd05bff32d..a1775b4f3e38 100755 --- a/arch/arm/mach-tegra/odm_kit/platform/accelerometer/nvodm_accelerometer_kxtf9.c +++ b/arch/arm/mach-tegra/odm_kit/platform/accelerometer/nvodm_accelerometer_kxtf9.c @@ -96,19 +96,29 @@ // I2C clock speed. #define I2C_CLK_SPEED 400 -#define ACCEL_TANGO_GUID NV_ODM_GUID('k','x','t','f','9','t','n','g') -#define ACCEL_VENTANA_GUID NV_ODM_GUID('k','x','t','f','9','v','n','t') -#define EEPROM_ID_E1206 0x0C06 +#define ACCEL_VER0_GUID NV_ODM_GUID('k','x','t','9','-','0','0','0') +#define ACCEL_VER1_GUID NV_ODM_GUID('k','x','t','9','-','0','9','0') + #define NV_DEBOUNCE_TIME_MS 0 #define ENABLE_XYZ_POLLING 0 -#define kxtf9_GUID NV_ODM_GUID('k','x','t','f','9','-','4','0') - static NvU8 s_ReadBuffer[I2C_ACCELRATOR_PACKET_SIZE]; static NvU8 s_WriteBuffer[I2C_ACCELRATOR_PACKET_SIZE]; static NvU8 s_IntSrcReg1; static NvU8 s_IntSrcReg2; +typedef struct discovery_entry_rec +{ + NvU64 guid; + NvU32 axesmapping; +} discovery_entry; + +static discovery_entry disc_entry[] = { + {ACCEL_VER0_GUID, 1}, + {ACCEL_VER1_GUID, 2}, +}; + + static void ConfigPowerRail( NvOdmServicesPmuHandle hPMUDevice, @@ -776,13 +786,7 @@ NvBool kxtf9_init(NvOdmAccelHandle* hDevice) NvOdmIoModule IoModule = NvOdmIoModule_I2c; const NvOdmPeripheralConnectivity *pConnectivity; NvBool FoundGpio = NV_FALSE, FoundI2cModule = NV_FALSE; - NvOdmBoardInfo BoardInfo; - // Accelerometer is supported only on E1206. - if (!NvOdmPeripheralGetBoardInfo(EEPROM_ID_E1206, &BoardInfo)) - { - NVODMACCELEROMETER_PRINTF(("\nkxtf9: Accelerometer not supported")); - return NV_FALSE; - } + NvU32 AxesMapping = 0; hAccel = NvOdmOsAlloc(sizeof(NvOdmAccel)); if (hAccel == NULL) { @@ -805,15 +809,20 @@ NvBool kxtf9_init(NvOdmAccelHandle* hDevice) NVODMACCELEROMETER_PRINTF(("kxtf9 NvOdmServicesPmuOpen Error \n")); goto error; } - - pConnectivity = NvOdmPeripheralGetGuid(ACCEL_TANGO_GUID); - if (!pConnectivity) + for ( i = 0 ; i < NV_ARRAY_SIZE(disc_entry); ++i ) { - NVODMACCELEROMETER_PRINTF(("\nkxtf9: GetGuid Failed for Tango")); + pConnectivity = NvOdmPeripheralGetGuid(disc_entry[i].guid); + if (pConnectivity) + { + AxesMapping = disc_entry[i].axesmapping; + break; + } } - else + if (!pConnectivity) + goto error; + + if (AxesMapping == 1) { - #if AXES_MAPPING_FOR_PROPER_DISPLAY_ALIGNMENT // Axes mapping for display orientation aligning correctly in 3 orientations // (0, 90 & 270 degrees) on Tango with (froyo + K32). hAccel->AxisXMapping = NvOdmAccelAxis_Y; @@ -822,22 +831,6 @@ NvBool kxtf9_init(NvOdmAccelHandle* hDevice) hAccel->AxisYDirection = -1; hAccel->AxisZMapping = NvOdmAccelAxis_Z; hAccel->AxisZDirection = -1; - #else - // Axes mapping for matching acceleration on all axes with android mobile phones - hAccel->AxisXMapping = NvOdmAccelAxis_X; - hAccel->AxisXDirection = -1; - hAccel->AxisYMapping = NvOdmAccelAxis_Y; - hAccel->AxisYDirection = -1; - hAccel->AxisZMapping = NvOdmAccelAxis_Z; - hAccel->AxisZDirection = -1; - #endif - } - - pConnectivity = NvOdmPeripheralGetGuid(ACCEL_VENTANA_GUID); - if (!pConnectivity) - { - NVODMACCELEROMETER_PRINTF(("\nkxtf9: GetGuid Failed for Ventana")); - goto error; } else { diff --git a/arch/arm/mach-tegra/odm_kit/query/harmony/nvodm_query_discovery.c b/arch/arm/mach-tegra/odm_kit/query/harmony/nvodm_query_discovery.c index 51691c5294e7..47506c9e522a 100644 --- a/arch/arm/mach-tegra/odm_kit/query/harmony/nvodm_query_discovery.c +++ b/arch/arm/mach-tegra/odm_kit/query/harmony/nvodm_query_discovery.c @@ -62,7 +62,6 @@ static NvOdmPeripheralConnectivity s_Peripherals_Default[] = #define NVODM_QUERY_MAX_EEPROMS 8 // Maximum number of EEPROMs per bus segment #define NVODM_QUERY_ERASED_EEPROM_VALUE 0xFF - #define PROCESSOR_BOARD_ID_I2C_ADDRESS ((0x56)<<1) #define PROCESSOR_BOARD_ID_I2C_SEGMENT (0x00) @@ -80,7 +79,8 @@ static NvOdmBoardInfo s_BoardModuleTable[NVODM_QUERY_MAX_EEPROMS]; #define NVODM_QUERY_PERIPH_CONN_STRUCT_COMPRESSED 10 // See EEPROM_format.txt #define NVODM_PERIPH_IO_ADDR_STRUCT_SZ_COMPRESSED 2 // See EEPROM_format.txt - +#define EEPROM_ID_E1206 0x0C06 +#define ACCEL_TANGO_GUID NV_ODM_GUID('k','x','t','9','-','0','0','0') static NvOdmI2cStatus NvOdmPeripheralI2cRead8( @@ -621,6 +621,20 @@ NvApGetAllPeripherals (NvU32 *pNum) return (const NvOdmPeripheralConnectivity *)s_Peripherals; } +static NvBool IsBoardTango(void) +{ + NvOdmBoardInfo BoardInfo; + static NvBool s_IsBoardIdRead = NV_FALSE; + static NvBool IsBoardTango = NV_FALSE; + + if (!s_IsBoardIdRead) + { + IsBoardTango = NvOdmPeripheralGetBoardInfo(EEPROM_ID_E1206, &BoardInfo); + s_IsBoardIdRead = NV_TRUE; + } + return IsBoardTango; +} + // This implements a simple linear search across the entire set of currently- // connected peripherals to find the set of GUIDs that Match the search // criteria. More clever implementations are possible, but given the @@ -632,12 +646,15 @@ NvOdmPeripheralGetGuid(NvU64 SearchGuid) const NvOdmPeripheralConnectivity *pAllPeripherals; NvU32 NumPeripherals; NvU32 i; + NvBool IsE1206Board; pAllPeripherals = NvApGetAllPeripherals(&NumPeripherals); + IsE1206Board = IsBoardTango(); if (!pAllPeripherals || !NumPeripherals) return NULL; - + if ((SearchGuid == ACCEL_TANGO_GUID) && (!IsE1206Board)) + return NULL; for (i=0; i<NumPeripherals; i++) { if (SearchGuid == pAllPeripherals[i].Guid) @@ -647,7 +664,6 @@ NvOdmPeripheralGetGuid(NvU64 SearchGuid) return &pAllPeripherals[i]; } } - return NULL; } diff --git a/arch/arm/mach-tegra/odm_kit/query/harmony/subboards/nvodm_query_discovery_e1162_peripherals.h b/arch/arm/mach-tegra/odm_kit/query/harmony/subboards/nvodm_query_discovery_e1162_peripherals.h index 72eac8a2de35..7a0bde368881 100755 --- a/arch/arm/mach-tegra/odm_kit/query/harmony/subboards/nvodm_query_discovery_e1162_peripherals.h +++ b/arch/arm/mach-tegra/odm_kit/query/harmony/subboards/nvodm_query_discovery_e1162_peripherals.h @@ -491,7 +491,7 @@ // Kionix Accelerometer on Tango { - NV_ODM_GUID('k','x','t','f','9','t','n','g'), + NV_ODM_GUID('k','x','t','9','-','0','0','0'), s_KXTFAcceleroAddresses, NV_ARRAY_SIZE(s_KXTFAcceleroAddresses), NvOdmPeripheralClass_Other, diff --git a/arch/arm/mach-tegra/odm_kit/query/ventana/nvodm_query_discovery.c b/arch/arm/mach-tegra/odm_kit/query/ventana/nvodm_query_discovery.c index 274977c7ded7..afed965e0a2f 100644 --- a/arch/arm/mach-tegra/odm_kit/query/ventana/nvodm_query_discovery.c +++ b/arch/arm/mach-tegra/odm_kit/query/ventana/nvodm_query_discovery.c @@ -44,10 +44,132 @@ static NvOdmPeripheralConnectivity s_Peripherals_Default[] = #include "subboards/nvodm_query_discovery_pm275_peripherals.h" }; +#define PROCESSOR_BOARD_ID_I2C_ADDRESS ((0x56)<<1) + +#define NVODM_QUERY_I2C_CLOCK_SPEED 100 // kHz +#define NVODM_QUERY_BOARD_HEADER_START 0x04 // Offset to Part Number in EERPOM +#define NVODM_QUERY_I2C_EEPROM_ADDRESS 0xA0 // I2C device base address for EEPROM (7'h50) + +#define EEPROM_ID_PM275 0x024B +#define VENTANA_REV_C_ACCEL NV_ODM_GUID('k','x','t','9','-','0','0','0') +#define VENTANA_REV_A_ACCEL NV_ODM_GUID('k','x','t','9','-','0','9','0') + +static NvOdmI2cStatus NvOdmPeripheralI2cRead8( + NvOdmServicesI2cHandle hOdmI2c, + NvU8 I2cAddr, + NvU8 Offset, + NvU8 *pData) +{ + NvU8 ReadBuffer[1]; + NvOdmI2cStatus Error; + NvOdmI2cTransactionInfo TransactionInfo; + + ReadBuffer[0] = Offset; + + TransactionInfo.Address = I2cAddr; + TransactionInfo.Buf = ReadBuffer; + TransactionInfo.Flags = NVODM_I2C_IS_WRITE; + TransactionInfo.NumBytes = 1; + + Error = NvOdmI2cTransaction( + hOdmI2c, &TransactionInfo, 1, NVODM_QUERY_I2C_CLOCK_SPEED, NV_WAIT_INFINITE); + if (Error != NvOdmI2cStatus_Success) + { + return Error; + } + + NvOdmOsMemset(ReadBuffer, 0, sizeof(ReadBuffer)); + + TransactionInfo.Address = (I2cAddr | 0x1); + TransactionInfo.Buf = ReadBuffer; + TransactionInfo.Flags = 0; + TransactionInfo.NumBytes = 1; + + // Read data from ROM at the specified offset + Error = NvOdmI2cTransaction( + hOdmI2c, &TransactionInfo, 1, NVODM_QUERY_I2C_CLOCK_SPEED, NV_WAIT_INFINITE); + if (Error != NvOdmI2cStatus_Success) + { + return Error; + } + *pData = ReadBuffer[0]; + return Error; +} + +static NvBool NvOdmPeripheralReadPartNumber( + NvOdmServicesI2cHandle hOdmI2c, + NvU8 EepromInst, + NvOdmBoardInfo *pBoardInfo) +{ + NvOdmI2cStatus Error; + NvU32 i; + NvU8 I2cAddr, Offset; + NvU8 ReadBuffer[sizeof(NvOdmBoardInfo)]; + + NvOdmOsMemset(ReadBuffer, 0, sizeof(ReadBuffer)); + + // EepromInst*2, since 7-bit addressing + I2cAddr = NVODM_QUERY_I2C_EEPROM_ADDRESS + (EepromInst << 1); + + /** + * Offset to the board number entry in EEPROM. + */ + Offset = NVODM_QUERY_BOARD_HEADER_START; + + for (i=0; i<sizeof(NvOdmBoardInfo); i++) + { + Error = NvOdmPeripheralI2cRead8( + hOdmI2c, I2cAddr, Offset+i, (NvU8 *)&ReadBuffer[i]); + if (Error != NvOdmI2cStatus_Success) + { + return NV_FALSE; + } + } + NvOdmOsMemcpy(pBoardInfo, &ReadBuffer[0], sizeof(NvOdmBoardInfo)); + return NV_TRUE; +} + NvBool NvOdmPeripheralGetBoardInfo( NvU16 BoardId, NvOdmBoardInfo *pBoardInfo) { + NvBool RetVal = NV_FALSE; + NvOdmServicesI2cHandle hOdmI2c = NULL; + NvU8 EepromInst=0; + NvOdmBoardInfo BoardModuleTable; + static NvBool s_ReadBoardInfoDone = NV_FALSE; + + if (!s_ReadBoardInfoDone) + hOdmI2c = NvOdmI2cOpen(NvOdmIoModule_I2c_Pmu, 0); + + if (!s_ReadBoardInfoDone) + { + s_ReadBoardInfoDone = NV_TRUE; + if (!hOdmI2c) + { + // Exit + pBoardInfo = NULL; + return NV_FALSE; + } + RetVal = NvOdmPeripheralReadPartNumber( + hOdmI2c, EepromInst, &BoardModuleTable); + } + if (hOdmI2c) + NvOdmI2cClose(hOdmI2c); + + // Linear search for given BoardId; if found, return entry + if (BoardModuleTable.BoardID == BoardId) + { + // Match found + pBoardInfo->BoardID = BoardModuleTable.BoardID; + pBoardInfo->SKU = BoardModuleTable.SKU; + pBoardInfo->Fab = BoardModuleTable.Fab; + pBoardInfo->Revision = BoardModuleTable.Revision; + pBoardInfo->MinorRevision = BoardModuleTable.MinorRevision; + return NV_TRUE; + } + + // Match not found pBoardInfo = NULL; return NV_FALSE; } @@ -58,6 +180,26 @@ static const NvOdmPeripheralConnectivity *NvApGetAllPeripherals(NvU32 *pNum) return s_Peripherals_Default; } +static NvU32 ReadBoardFabVersion(void) +{ + NvOdmBoardInfo BoardInfo; + NvBool IsBoardPresent; + static NvBool s_IsFabRead = NV_FALSE; + static NvU32 BoardFabNumber = -1; + + if (!s_IsFabRead) + { + IsBoardPresent = NvOdmPeripheralGetBoardInfo(EEPROM_ID_PM275, &BoardInfo); + if (!IsBoardPresent) + { + return BoardFabNumber; + } + s_IsFabRead = NV_TRUE; + BoardFabNumber = BoardInfo.Fab; + } + return BoardFabNumber; +} + // This implements a simple linear search across the entire set of currently- // connected peripherals to find the set of GUIDs that Match the search // criteria. More clever implementations are possible, but given the @@ -68,18 +210,26 @@ const NvOdmPeripheralConnectivity *NvOdmPeripheralGetGuid(NvU64 SearchGuid) const NvOdmPeripheralConnectivity *pAllPeripherals; NvU32 NumPeripherals; NvU32 i; + NvU32 BoardFabNum; pAllPeripherals = NvApGetAllPeripherals(&NumPeripherals); if (!pAllPeripherals || !NumPeripherals) return NULL; + BoardFabNum = ReadBoardFabVersion(); + if ((SearchGuid == VENTANA_REV_A_ACCEL) && (BoardFabNum != 0)) + return NULL; + + if ((SearchGuid == VENTANA_REV_C_ACCEL) && (BoardFabNum != 2)) + return NULL; - for (i=0; i<NumPeripherals; i++) + for (i = 0; i < NumPeripherals; i++) { if (SearchGuid == pAllPeripherals[i].Guid) + { return &pAllPeripherals[i]; + } } - return NULL; } diff --git a/arch/arm/mach-tegra/odm_kit/query/ventana/subboards/nvodm_query_discovery_pm275_peripherals.h b/arch/arm/mach-tegra/odm_kit/query/ventana/subboards/nvodm_query_discovery_pm275_peripherals.h index f9269aa70b29..b963c7df8a45 100755 --- a/arch/arm/mach-tegra/odm_kit/query/ventana/subboards/nvodm_query_discovery_pm275_peripherals.h +++ b/arch/arm/mach-tegra/odm_kit/query/ventana/subboards/nvodm_query_discovery_pm275_peripherals.h @@ -433,12 +433,19 @@ NvOdmPeripheralClass_HCI }, -// Accelerometer Module +// Accelerometer Module for Ventana C { - NV_ODM_GUID('k','x','t','f','9','v','n','t'), + NV_ODM_GUID('k','x','t','9','-','0','0','0'), s_AcceleroAddresses, NV_ARRAY_SIZE(s_AcceleroAddresses), NvOdmPeripheralClass_Other, }, +// Accelerometer Module for Ventana A +{ + NV_ODM_GUID('k','x','t','9','-','0','9','0'), + s_AcceleroAddresses, + NV_ARRAY_SIZE(s_AcceleroAddresses), + NvOdmPeripheralClass_Other, +}, // NOTE: This list *must* end with a trailing comma. |