summaryrefslogtreecommitdiffstats
path: root/Linux_x86
diff options
context:
space:
mode:
authorMartijn Coenen <maco@google.com>2011-11-02 15:58:37 -0700
committerMartijn Coenen <maco@google.com>2011-11-03 17:56:36 -0700
commitb99be65c277b0cc65a00a33e784ed49461531737 (patch)
treefa283e7ed283b12e692729a860fb51315d130d78 /Linux_x86
parent366238178f7a6d26ce051150f4fb65e533c2fae4 (diff)
downloadexternal_libnfc-nxp-b99be65c277b0cc65a00a33e784ed49461531737.zip
external_libnfc-nxp-b99be65c277b0cc65a00a33e784ed49461531737.tar.gz
external_libnfc-nxp-b99be65c277b0cc65a00a33e784ed49461531737.tar.bz2
Use NFC HAL for some libnfc settings.
The NFC HAL in libhardware allows us to store and retrieve product-specific settings. This patch moves two product-specific settings to the HAL: the device port, and the usage of the i2c workaround we had for crespo. This means configuring the port no longer needs to be done from JNI land. Change-Id: I2e19b6f188f808bc2f2a1f1abc28f2a6c47e6a4c
Diffstat (limited to 'Linux_x86')
-rw-r--r--Linux_x86/phDal4Nfc.c64
-rw-r--r--Linux_x86/phDal4Nfc_i2c.c18
-rw-r--r--Linux_x86/phDal4Nfc_uart.c38
3 files changed, 51 insertions, 69 deletions
diff --git a/Linux_x86/phDal4Nfc.c b/Linux_x86/phDal4Nfc.c
index 8b4f687..3e031f1 100644
--- a/Linux_x86/phDal4Nfc.c
+++ b/Linux_x86/phDal4Nfc.c
@@ -48,11 +48,9 @@
#include <phDal4Nfc_i2c.h>
#include <phDal4Nfc_link.h>
#include <phDal4Nfc_messageQueueLib.h>
+#include <hardware/hardware.h>
+#include <hardware/nfc.h>
-/*-----------------------------------------------------------------------------------
- MISC DEFINITIONS
-------------------------------------------------------------------------------------*/
-#define DEFAULT_LINK_TYPE ENUM_DAL_LINK_TYPE_COM1
/*-----------------------------------------------------------------------------------
TYPES
@@ -269,7 +267,7 @@ NFCSTATUS phDal4Nfc_Init(void *pContext, void *pHwRef )
else
{
static phDal4Nfc_sConfig_t hw_config;
- hw_config.nLinkType = DEFAULT_LINK_TYPE;
+ hw_config.deviceNode = NULL;
result = phDal4Nfc_Config(&hw_config, pHwRef );
}
}
@@ -351,6 +349,9 @@ NFCSTATUS phDal4Nfc_ConfigRelease(void *pHwRef)
/* Close the link */
gLinkFunc.close();
+ if (gDalContext.pDev != NULL) {
+ nfc_pn544_close(gDalContext.pDev);
+ }
/* Reset the Read Writer context to NULL */
memset((void *)&gReadWriteContext,0,sizeof(gReadWriteContext));
/* Reset the DAL context values to NULL */
@@ -533,22 +534,40 @@ PURPOSE: Configure the serial port.
NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
{
NFCSTATUS retstatus = NFCSTATUS_SUCCESS;
+ const hw_module_t* hw_module;
+ nfc_pn544_device_t* pn544_dev;
+ uint8_t num_eeprom_settings;
+ uint8_t* eeprom_settings;
+ int ret;
+
+ /* Retrieve the hw module from the Android NFC HAL */
+ ret = hw_get_module(NFC_HARDWARE_MODULE_ID, &hw_module);
+ if (ret) {
+ LOGE("hw_get_module() failed");
+ return NFCSTATUS_FAILED;
+ }
+ ret = nfc_pn544_open(hw_module, &pn544_dev);
+ if (ret) {
+ LOGE("Could not open pn544 hw_module");
+ return NFCSTATUS_FAILED;
+ }
+ config->deviceNode = pn544_dev->device_node;
+ if (config->deviceNode == NULL) {
+ LOGE("deviceNode NULL");
+ return NFCSTATUS_FAILED;
+ }
DAL_PRINT("phDal4Nfc_Config");
- if ((config == NULL) || (phwref == NULL) || (config->nClientId == -1))
+ if ((config == NULL) || (phwref == NULL))
return NFCSTATUS_INVALID_PARAMETER;
/* Register the link callbacks */
memset(&gLinkFunc, 0, sizeof(phDal4Nfc_link_cbk_interface_t));
- switch(config->nLinkType)
+ switch(pn544_dev->linktype)
{
- case ENUM_DAL_LINK_TYPE_COM1:
- case ENUM_DAL_LINK_TYPE_COM2:
- case ENUM_DAL_LINK_TYPE_COM3:
- case ENUM_DAL_LINK_TYPE_COM4:
- case ENUM_DAL_LINK_TYPE_COM5:
- case ENUM_DAL_LINK_TYPE_USB:
+ case PN544_LINK_TYPE_UART:
+ case PN544_LINK_TYPE_USB:
{
DAL_PRINT("UART link Config");
/* Uart link interface */
@@ -564,7 +583,7 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
}
break;
- case ENUM_DAL_LINK_TYPE_I2C:
+ case PN544_LINK_TYPE_I2C:
{
DAL_PRINT("I2C link Config");
/* i2c link interface */
@@ -608,6 +627,9 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
#else
nDeferedCallMessageQueueId = config->nClientId;
#endif
+
+ gDalContext.pDev = pn544_dev;
+
/* Start Read and Write Threads */
if(NFCSTATUS_SUCCESS != phDal4Nfc_StartThreads())
{
@@ -615,7 +637,6 @@ NFCSTATUS phDal4Nfc_Config(pphDal4Nfc_sConfig_t config,void **phwref)
}
gDalContext.hw_valid = TRUE;
-
phDal4Nfc_Reset(1);
phDal4Nfc_Reset(0);
phDal4Nfc_Reset(1);
@@ -696,6 +717,13 @@ int phDal4Nfc_ReaderThread(void * pArg)
phOsalNfc_Message_t OsalMsg ;
int i;
int i2c_error_count;
+ int i2c_workaround;
+ if (gDalContext.pDev != NULL) {
+ i2c_workaround = gDalContext.pDev->enable_i2c_workaround;
+ } else {
+ LOGE("gDalContext.pDev is not set");
+ return NFCSTATUS_FAILED;
+ }
pthread_setname_np(pthread_self(), "reader");
@@ -730,12 +758,12 @@ retry:
/* Wait for IRQ !!! */
gReadWriteContext.nNbOfBytesRead = gLinkFunc.read(gReadWriteContext.pReadBuffer, gReadWriteContext.nNbOfBytesToRead);
- /* TODO: Remove this hack
- * Reading the value 0x57 indicates a HW I2C error at I2C address 0x57
+ /* Reading the value 0x57 indicates a HW I2C error at I2C address 0x57
* (pn544). There should not be false positives because a read of length 1
* must be a HCI length read, and a length of 0x57 is impossible (max is 33).
*/
- if(gReadWriteContext.nNbOfBytesToRead == 1 && gReadWriteContext.pReadBuffer[0] == 0x57)
+ if(i2c_workaround && gReadWriteContext.nNbOfBytesToRead == 1 &&
+ gReadWriteContext.pReadBuffer[0] == 0x57)
{
i2c_error_count++;
DAL_DEBUG("RX Thread Read 0x57 %d times\n", i2c_error_count);
diff --git a/Linux_x86/phDal4Nfc_i2c.c b/Linux_x86/phDal4Nfc_i2c.c
index 72da8e7..8b742d9 100644
--- a/Linux_x86/phDal4Nfc_i2c.c
+++ b/Linux_x86/phDal4Nfc_i2c.c
@@ -24,7 +24,7 @@
#define LOG_TAG "NFC_i2c"
#include <cutils/log.h>
-
+#include <hardware/nfc.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -144,24 +144,12 @@ PURPOSE: Closes the link
NFCSTATUS phDal4Nfc_i2c_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle)
{
- char * pComPort;
-
DAL_ASSERT_STR(gI2cPortContext.nOpened==0, "Trying to open but already done!");
- switch(pConfig->nLinkType)
- {
- case ENUM_DAL_LINK_TYPE_I2C:
- pComPort = "/dev/pn544";
- break;
- default:
- DAL_DEBUG("Open failed: unknown type %d\n", pConfig->nLinkType);
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
- DAL_DEBUG("Opening port=%s\n", pComPort);
+ DAL_DEBUG("Opening port=%s\n", pConfig->deviceNode);
/* open port */
- gI2cPortContext.nHandle = open(pComPort, O_RDWR | O_NOCTTY);
+ gI2cPortContext.nHandle = open(pConfig->deviceNode, O_RDWR | O_NOCTTY);
if (gI2cPortContext.nHandle < 0)
{
DAL_DEBUG("Open failed: open() returned %d\n", gI2cPortContext.nHandle);
diff --git a/Linux_x86/phDal4Nfc_uart.c b/Linux_x86/phDal4Nfc_uart.c
index a2f6db3..b19c5c5 100644
--- a/Linux_x86/phDal4Nfc_uart.c
+++ b/Linux_x86/phDal4Nfc_uart.c
@@ -28,7 +28,7 @@
#define LOG_TAG "NFC_uart"
#include <cutils/log.h>
-
+#include <hardware/nfc.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -159,7 +159,6 @@ PURPOSE: Closes the link
NFCSTATUS phDal4Nfc_uart_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void ** pLinkHandle)
{
- char * pComPort;
int nComStatus;
NFCSTATUS nfcret = NFCSTATUS_SUCCESS;
int ret;
@@ -168,41 +167,8 @@ NFCSTATUS phDal4Nfc_uart_open_and_configure(pphDal4Nfc_sConfig_t pConfig, void *
srand(time(NULL));
- switch(pConfig->nLinkType)
- {
- case ENUM_DAL_LINK_TYPE_COM1:
- pComPort = "/dev/ttyO0";
- break;
- case ENUM_DAL_LINK_TYPE_COM2:
- pComPort = "/dev/ttyO1";
- break;
- case ENUM_DAL_LINK_TYPE_COM3:
- pComPort = "/dev/ttyO2";
- break;
- case ENUM_DAL_LINK_TYPE_COM4:
- pComPort = "/dev/ttyO3";
- break;
- case ENUM_DAL_LINK_TYPE_COM5:
- pComPort = "/dev/ttyO4";
- break;
- case ENUM_DAL_LINK_TYPE_COM6:
- pComPort = "/dev/ttyO5";
- break;
- case ENUM_DAL_LINK_TYPE_COM7:
- pComPort = "/dev/ttyO6";
- break;
- case ENUM_DAL_LINK_TYPE_COM8:
- pComPort = "/dev/ttyO7";
- break;
- case ENUM_DAL_LINK_TYPE_USB:
- pComPort = "/dev/ttyUSB0";
- break;
- default:
- return NFCSTATUS_INVALID_PARAMETER;
- }
-
/* open communication port handle */
- gComPortContext.nHandle = open(pComPort, O_RDWR | O_NOCTTY);
+ gComPortContext.nHandle = open(pConfig->deviceNode, O_RDWR | O_NOCTTY);
if (gComPortContext.nHandle < 0)
{
*pLinkHandle = NULL;