1. INTRODUCTION
This document is a step by step guide of the AN11697 PN7120 Linux Software Stack Integration Guidelines application note that can be downloaded from http://www.nxp.com/documents/application_note/AN11697.pdf . It explains how to add the PN7120 driver and NFC libraries to a Linux OS running in the i.MX6Q.
2. REQUIREMENTS
3. KERNEL DRIVER
According to the AN11697.pdf we must follow the below steps:
$ cd drivers/misc $ git clone https://github.com/NXPNFCLinux/nxp-pn5xx.git
obj-y += nxp-pn5xx/
source "drivers/misc/nxp-pn5xx/Kconfig"
$ source source /opt/poky/1.7/environment-setup-cortexa9hf-vfp-neon-poky-linux-gnueabi $ export ARCH=arm $ export CROSS_COMPILE=$TARGET_PREFIX $ make imx_v7_defconfig
$ make modules
$ make INSTALL_MOD_PATH=~/Desktop/modules modules_install $ cd ~/Desktop/modules $ sudo scp -r lib/modules/3.14.28+g91cf351/kernel root@<board_ip>:/lib/modules/3.14.28+g91cf351/
4. DEVICE NODE
The PN7120 interfaces with an MCU or MPU via I2C interface, therefore the device must be described into a i2c node. The signals used in the PN7120 are shown below:
As you can see besides power, ground and I2C lines, an IRQ and Reset pins are needed. These pins must be configured as GPIO and one must generate an interrupt to the iMX6Q.
The chosen connection is shown below:
To achieve the above configuration, the device tree must be changed. The changes consist on adding a device node in the corresponding I2C bus, describing the PN7120.
&i2c1 {
clock-frequency = <100000>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_i2c1>;
status = "okay";
pn547: pn547@28 {
compatible = "nxp,pn547";
reg = <0x28>;
clock-frequency = <400000>;
interrupt-parent = <&gpio6>;
interrupt-gpios = <&gpio6 2 0>;
enable-gpios = <&gpio5 22 0>;
};
};
The pinctrl_i2c1 phandle contains the I2C pins configuration. Make sure that the PADs connected to the PN7120 are not used in other device node.
&iomuxc {
imx6q-udoo {
...
pinctrl_i2c1: i2c1grp {
fsl,pins = <
MX6QDL_PAD_GPIO_5__I2C3_SCL 0x4001b8b1
MX6QDL_PAD_GPIO_6__I2C3_SDA 0x4001b8b1
>;
};
};
};
After this you can generate the dtb file and send it with scp
make dtbs
sudo scp arch/arm/boot/dts/imx6q-udoo.dtb root@<board_ip>:/run/media/mmcblk0p1/imx6q-udoo.dtb
NOTE:
Attached you can find the complete dts and dtsi files used in this document.
5. NFC LIBRARY
To work with the PN7120 in Linux the libnfc-nci stack is needed. You can find more details in http://www.nxp.com/documents/application_note/AN11697.pdf . This sections explains how to cross-compile the libray and install the required files in the target (The below steps must be performed in the host).
$ git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git
$ ./bootstrap
$ sudo mount /dev/sdX2 /mnt
$ ./configure --host=arm-none-linux --prefix=/opt/poky/1.7/sysroots/x86_64-pokysdk-linux/usr --sysconfdir=/mnt/etc
$ make $ make install
$ cd linux_libnfc-nci/.libs $ sudo cp * /mnt/usr/lib/
6. TESTING NFC READER
To test the application you have to follow the below steps on the target:
$ insmod /lib/modules/3.14.28+g91cf351/kernel/drivers/misc/nxp-pn5xx/pn5xx_i2c.ko
$ nfcDemoApp pollYou should get a console output like the shown below when placing a NFC tag next to the NFC reader.
7. REFERENCES
Integrating NFC Controller library with KSDK
Hi gusarambula, jamesbone, CarlosCasillas, jimmychan,
Would you be nice enough to skim through the document and provide your feedback?
Best Regards,
Alejandro
Look very good, alejandrolozano! I just think you didn't attached the device tree files.
Hi Alex, very good and well structured document.
I just recommend changing the second person sentences like "As you can see besides power" to non-personal like "As shown besides power".
Best regards!
Hi,
I follow the document want try on our IMX6DL platform with PN544 (base 3.14.52_v1.1.0qa )
but I get the below error message!
insmod /lib/modules/3.14.52+g92a293a/kernel/drivers/misc/pn5x
pn54x_dev_init
pn54x_probe
pn54x 0-0028: CLKREQ GPIO <OPTIONAL> error getting from OF node
0-0028 supply nxp,pn54x-pvdd not found, using dummy regulator
0-0028 supply nxp,pn54x-vbat not found, using dummy regulator
0-0028 supply nxp,pn54x-pmuvcc not found, using dummy regulator
0-0028 supply nxp,pn54x-sevdd not found, using dummy regulator
pn54x_probe: request irq_gpio 159
pn54x_probe: request ven_gpio 5
pn54x_probe: request firm_gpio 163
pn54x_probe : requesting IRQ 319
root@imx6dltinto:~# nfcDemoApp poll
#########################################################################################
## NFC demo ##
#########################################################################################
## Poll mode actpn54x_dev_open : 10,56
ivated pn54x_dev_ioctl, cmd=1074063617, arg=1
##
#######################pn544_enable power on
##################################################################
... press enter to quit ...
pn54x_dev_ioctl, cmd=1074063617, arg=0
pn544_disable power off
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=0
pn544_disable power off
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn54x_dev_read: i2c_master_recv returned -5
Have anyone can help me to fix this issues!
........................
currently our hardware modify to split VEN and PMUVCC setting
VEN with VBAT/PMUVCC connecttion, will always printing out "pn54x_dev_read: i2c_master_recv returned -5" string
current our PMUVCC/VBAT always keep supply
just control VEN pin
get new result, but still failed, pending on "pn544_enable power on" when run nfcDemoApp poll
#########################################################################################
## NFC demo ##
#########################################################################################
## Poll mode actipn54x_dev_open : 10,56
vated pn54x_dev_ioctl, cmd=1074063617, arg=1
##
########################pn544_enable power on
#################################################################
... press enter to quit ...
pn54x_dev_ioctl, cmd=1074063617, arg=0
pn544_disable power off
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=0
pn544_disable power off
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=0
pn544_disable power off
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
pn54x_dev_ioctl, cmd=1074063617, arg=0
pn544_disable power off
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_read: i2c_master_recv returned -5
pn54x_dev_ioctl, cmd=1074063617, arg=1
pn544_enable power on
Hi,
That error as you may assume it is related to the i2c communication. Please make sure that the PN7120 is connected as it should.
I recommend you either to check with a scope or a logic analizer if the i2c frame is correct.
Best Regards,
Alejandro
Hi Alejandor,
First, thank you for your reply!
I need describe something to let you know
In my case are connection to PN544, not PN7120
And have been testing Linux NFC subsystem , default pn544 with I2C workable still entry initiator mode, can't response tag
So I guess I2C bus should be work well.
please see this https://community.freescale.com/thread/385569 and neard_pn544_dmesg_kunyi - Pastebin.com to get more detail
BTW l'll double check I2C bus signal on our hardware platform now
Hi Alejandor,
Today I debug this, don't like I2C bus issues, Like PN544 chip not response,
this libnfc-nxp want get response, but never have response.
I to modify libnfc-nxp.conf to enable some debug message, I see the program want read 3byte response
when before send "20 00 01 01" to PN544,
I don't know "20 00 01 01" what's mean
but I guess the command not acceptable on PN544
#########################################################################################
## pn54x_dev_open : 10,56
pn54x_dev_ioctl, cmd=1074063617, arg=1
NFC demo pn544_enable power on
##
#########################################################################################
## Poll mode activated ##
#########################################################################################
... press enter to quit ...
NxpHal: Entering phNxpNciHal_init_monitor
NxpHal: Returning with SUCCESS
NxpTml: Opening port=/dev/pn544
NxpTml: phTmlNfc_i2c_reset(), VEN level 1
NxpTml: pn54x_dev_ioctl, cmd=1074063617, arg=0
phTmlNfc_i2c_reset(), VEN level 0pn544_disable power off
NxpTml: pn54x_dev_ioctl, cmd=1074063617, arg=1
phTmlNfc_i2c_reset(), VEN level 1pn544_enable power on
NxpTml: i2c->:00000000: 20 00 01 01
PN54X - Tml Reader Thread Started................
NxpTml: PN54X - Tml Writer Thread Started................
NxpTml: PN54X - Tml Writer Thread Running................
NxpTml: NxpHal: PN54X - Write requested.....
NxpTml: PN54X - Invoking I2C Write.....
thread started
NxpTml: PN54X - Read requested.....
NxpTml: PN54X - Invoking I2C Read.....
NxpTml: PN54X - I2C Write successful.....
NxpTml: PN54X - Posting Fresh Write message.....
NxpTml: PN54X - Tml Writer Thread Running................
NxpHal: write successful status = 0x0
NxpHal: Response timer started
NxpHal: Waiting after ext cmd sent
NxpHal: pn54x_dev_ioctl, cmd=1074063617, arg=1
hal_extns_write_rsp_timeout_cb - pn544_enable power on
write timeout!!!
NxpHal: Response timer stopped
NxpHal: Callback Status is failed!! Timer Expired!! Couldn't read it! 0xff
NxpHal: NCI_CORE_RESET: Failed
NxpHal: Power Cycle
NxpTml: phTmlNfc_i2c_reset(), VEN level 1
NxpTml: pn54x_dev_ioctl, cmd=1074063617, arg=0
phTmlNfc_i2c_reset(), VEN level 0pn544_disable power off
pn54x_dev_read: i2c_master_recv returned -5
NxpTml: _i2c_read() [hdr] errno : 5
Nxppn54x_dev_read: i2c_master_recv returned -5
Tml: PN54X - Error in I2C Reapn54x_dev_read: i2c_master_recv returned -5
d.....
NxpTml: PN54X - Reapn54x_dev_read: i2c_master_recv returned -5
d requested.....
NxpTml: Ppn54x_dev_read: i2c_master_recv returned -5
N54X - Invoking I2C Read.....
pn54x_dev_read: i2c_master_recv returned -5
NxpTml: _i2c_read() [hdr] errpn54x_dev_read: i2c_master_recv returned -5
no : 5
NxpTml: PN54X - Errorpn54x_dev_read: i2c_master_recv returned -5
in I2C Read.....
NxpTml: pn54x_dev_read: i2c_master_recv returned -5
PN54X - Read requested.....
Nxpn54x_dev_read: i2c_master_recv returned -5
For information on using the PN7150 NFC Demoboard you may refer to the following document, which is related to this one.
Thank you for your informations. if possible would you tell me how to get PN544 documents and firmware/FRI-SDK.
because my project will go into MP stage,
from AOSP source code find out some configuration for PN544 and neard & neardal can workable on my project
Hi,
Driver is accessing regulator for NFC from the device tree but here those regulator names are not available in the device tree code . Can anybody help me to add the regulator in dtsi files. I am using SODIMM iMx6Dualite board with Linux 3.10.53 Kernel.
For enabling (pn544_enable) - > (dev->pvdd_reg, dev->vbat_reg,dev->pmuvcc_reg, dev->sevdd_reg). where these regulators are assigned in device tree. Is it really required to enable the NFC.
Regards,
Dooty.
Hi Dooty,
I guess you should use AOSP driver code, due to the driver code use your enabled sequence on PN54x
but just need have an enabled pin, it is dependence hardware design
and the article just for PN71xx not for PN54x
if want add others regulators control pin, check "enable-gpio" in driver code then to add others into same place
Hi KunYi Chen,
Thank your for the response. What is AOSP driver. I agree the points that regulator enable required depends on the hardware design.
Here you are saying about this article is for PN71xx and not for PN54x. But when I check out the driver code from git repository, it is downloading the driver of nxp-pn5xx and the application is nfcDemoApp (linux_libnfc-nci). Then why it is been added the driver code name pn544 for the PN71xx module. It is little bit confusing.
Here I am using the exact nfc module part number is nxp PN7120A0EV and it is connected via i2c interface on SODIMM iMx6Dualite processor.
I am following this document :- http://www.nxp.com/documents/application_note/AN11697.pdf
So please suggest me whether I can go ahead and proceed the above git repository for the Kernel device driver and nfcDemoApp application or do you any other suggestion to support different source code (Kernel and application) for the respective NFC module (PN7120A0EV).
Thank you in Advance.
Regards,
Dooty.
Okay, I see you use NXP PN7120A0EV, so you need check your hardware write first
The article use GPIO5_IO22 to enabled all regulator
you need to check your hardware how to wiring connecting the to modify you driver and device tree file
AOSP: Android Open Source Project
Hi KunYi Chen,
Thank your for the response. Please can youreply me apart from the Hardware desgin, regualator and GPIO pins.
I need to know which Linux driver and application can be used my nfc module. I am working in Linux.
Thank you in Advance.
Regards,
Dooty.
I compiled the linux_linnfc-nci library following the guide. When I try run nfcDemoApp I received the following error
nfcDemoApp: error while loading shared libraries: /usr/lib/libnfc_nci_linux-1.so: internal error