Porting pn54x driver to Raspberry Pi 3

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Porting pn54x driver to Raspberry Pi 3

2,247 Views
sangdolee
Contributor I

Hi,

I have tested OM5577, NFC developing kit, using rasberry pi linux demo image from NXP. It works well.

I want to make new raspberry pi OS image.

I did port pn54x i2c driver to new image according to NXP porting guide(PN71x0 Linux Software Stack Integration Guidelines), changing device tree and platform data, interrupt and ven port to GPIO 23 and 24.

&i2c{ status = "okay"; pn547: pn547@28 {

compatible = "nxp,pn547";

reg = <0x28>; clock-frequency = <400000>;

interrupt-gpios = <&gpio 23 0>;

enable-gpios = <&gpio 23 0>; };

};

static struct pn544_i2c_platform_data nfc_pdata = {

.irq_gpio = GPIO_TO_PIN(1,23),

.ven_gpio = GPIO_TO_PIN(0,24),

.firm_gpio = GPIO_UNUSED

.clkreq_gpio = GPIO_UNUSED };

static struct i2c_board_info __initdata nfc_board_info[] = { { I2C_BOARD_INFO("pn547", 0x28), .platform_data = &nfc_pdata, }, };

But, "nfcDemo poll" is not working at all.

PN7120 seems to be installed on 28 properly, I think.

 

raspberrypi:/dev# i2cdetect -l
i2c-1 i2c 3f804000.i2c I2C adapter
raspberrypi:/dev#
raspberrypi:/dev#
raspberrypi:/dev# lsmod | grep i2c
pn5xx_i2c 7587 0
i2c_dev 6372 0
i2c_bcm2708 4948 0
raspberrypi:/dev#
raspberrypi:/dev#
raspberrypi:/dev# sudo i2cdetect -y 1
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: — — — — — — — — — — — — —
10: — — — — — — — — — — — — — — — —
20: — — — — — — — — UU — — — — — — —
30: — — — — — — — — — — — — — — — —
40: — — — — — — — — — — — — — — — —
50: — — — — — — — — — — — — — — — —
60: — — — — — — — — — — — — — — — —
70: — — — — — — — —
raspberrypi:/dev# ls -al pn544
crw-rw-rw- 1 root root 10, 58 Oct 19 17:28 pn544

Is there anyone who have done porting to new image?

Let me know how I have to...

BR

Paul

Labels (2)
0 Kudos
3 Replies

1,111 Views
jasonwu23
Contributor I

Hi, I am doing exactly the same thing. 

Using Raspberry Pi 3 - B and following the document NXPNCI Android Porting Guidelines. 

Also, the demo image OM5577-PN7120S_Rpi_Linux_demo_v1.2.zip works well too. 

2.2.3.1 Device tree

I tried to follow the instructions, and modified /arch/arm/boot/dts/bcm2710-rpi-3-b.dts file

but i got this inside dmesg

[ 4.259228] i2c i2c-0: Failed to register i2c client pn547 at 0x28 (-16)
[ 4.259251] i2c i2c-0: Can't create device at 0x28

......

[ 88.630261] pn54x_dev_write : i2c_master_send returned -5
[ 88.632645] pn54x_dev_write : i2c_master_send returned -5
[ 88.634940] pn54x_dev_write : i2c_master_send returned -5
[ 88.637216] pn54x_dev_write : i2c_master_send returned -5
[ 88.639491] pn54x_dev_write : i2c_master_send returned -5
[ 88.641805] pn54x_dev_write : i2c_master_send returned -5

so does that means my i2c doesn't set up properly?

what i have done with 2.2.3.2

2.2.3.2 Platform data

void __init bcm2709_init(void)
{
   int ret;

   vc_cma_early_init();

   pm_power_off = bcm2709_power_off;

   ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
   if (ret) {
      pr_err("of_platform_populate failed: %d\n", ret);
      BUG();
   }

   i2c_register_board_info(0, nfc_board_info, ARRAY_SIZE(nfc_board_info));

   bcm2709_init_uart1();

   system_rev = boardrev;
   system_serial_low = serial;
}

###################################################################

here are some more informations.

root@raspberrypi:~# lsmod | grep i2c
pn5xx_i2c 7549 0
i2c_bcm2708 4834 0
i2c_dev 5859 0

root@raspberrypi:~# i2cdetect -y 0
    0   1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- 1c -- -- --
20: -- -- -- -- -- -- -- -- UU -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- 43 -- -- -- -- -- -- -- -- -- -- -- --
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
70: -- -- -- -- -- -- -- --

and of course my ./nfcDemoApp poll not going to work.

#########################################################################################
## NFC demo ##
#########################################################################################
## Poll mode activated ##
#########################################################################################
... press enter to quit ...

NxpFunc: nativeNfcManager_doInitialize: enter; NCI_VERSION=0x10
NxpFunc: NfcAdaptation::Initialize: enter
NxpFunc: NfcAdaptation::Initialize: Overriding NFA_EE_MAX_EE_SUPPORTED to use 1
NxpFunc: NfcAdaptation::NFCA_TASK: enter
NxpFunc: NfcAdaptation::Thread: enter
NxpFunc: Brcm: NFC_TASK started.

NxpFunc: NfcAdaptation::Thread: exit
NxpFunc: NfcAdaptation::InitializeHalDeviceContext: enter
NxpFunc: NfcAdaptation::InitializeHalDeviceContext: exit
NxpFunc: NfcAdaptation::Initialize: exit
NxpFunc: Brcm: nfa_dm_init ()

NxpFunc: Brcm: nfa_sys_register () id=1, enable_cplt_mask=0x0

NxpFunc: Brcm: nfa_sys_register () id=3, enable_cplt_mask=0x8

NxpFunc: Brcm: nfa_sys_register () id=4, enable_cplt_mask=0x18

NxpFunc: Brcm: nfa_snep_init (): is_dta_mode=0

NxpFunc: Brcm: nfa_snep_default_init ()

NxpFunc: Brcm: nfa_sys_register () id=5, enable_cplt_mask=0x38

NxpFunc: Brcm: nfa_rw_init ()

NxpFunc: Brcm: nfa_sys_register () id=6, enable_cplt_mask=0x78

NxpFunc: Brcm: nfa_ce_init ()

NxpFunc: Brcm: nfa_sys_register () id=7, enable_cplt_mask=0xf8

NxpFunc: Brcm: nfa_ee_init ()

NxpFunc: Brcm: nfa_sys_register () id=2, enable_cplt_mask=0xfc

NxpFunc: Brcm: nfa_hci_init ()

NxpFunc: Brcm: nfa_sys_register () id=8, enable_cplt_mask=0x1fc

NxpFunc: Brcm: LLCP - llcp_init ()

NxpFunc: Brcm: num_rx_buff = 9, rx_congest_start = 6, rx_congest_end = 4, max_num_ll_rx_buff = 2

NxpFunc: Brcm: max_num_tx_buff = 21, max_num_ll_tx_buff = 6

NxpFunc: Brcm: LLCP_RegisterServer (): SAP:0x1, link_type:0x2, ServiceName:<urn:nfc:sn:sdp>

NxpFunc: Brcm: LLCP_RegisterServer (): Registered SAP = 0x01

NxpFunc: Brcm: NFA_Enable ()

NxpFunc: Brcm: NFA got event 0x0100

NxpFunc: Brcm: NFA got event 0x0100

NxpFunc: NfcAdaptation::HalOpen
NxpFunc: phNxpLog_InitializeLogLevel: global =0, Fwdnld =0, extns =0, hal =0, tml =0, ncir =0, ncix =0
NxpFunc: NfcAdaptation::HalDeviceContextCallback: event=6

Can you please help me on setting up this?

i think it probably the dts file problem

0 Kudos

1,111 Views
jasonwu23
Contributor I

Can be able to read nfc card now. 

#########################################################################################
## Poll mode activated ##
#########################################################################################
... press enter to quit ...

Waiting for a Tag/Device...

NFC Tag Found

Type : 'Type A - Mifare Classic'
NFCID1 : 'C0 CE F2 61 '
NDEF Content : NO

Mifare Authenticate command sent
Response :
40 03

Mifare Read command sent
Response :
10 04 00

NFC Tag Lost

Waiting for a Tag/Device...

########################################################################################

i have modified files

arch/arm/boot/dts/bcm2710-rpi-3-b.dts

&i2c1 {
   pinctrl-names = "default";
   pinctrl-0 = <&i2c1_pins>;
   clock-frequency = <100000>;
   status = "okay";
   pn547: pn547@28 {
      compatible = "nxp,pn547";
      reg = <0x28>;
      clock-frequency = <400000>;
      interrupt-gpios = <&gpio 23 0>;
      enable-gpios = <&gpio 24 0>;

      firmware-gpios = <&gpio 25 0>;
   };
};

################################################################################

and platform file looks like this

arch/arm/mach-bcm2709/bcm2709.c

static void __init bcm2709_init_uart1(void)
{
   struct device_node *np;

   np = of_find_compatible_node(NULL, NULL, "brcm,bcm2835-aux-uart");
   if (of_device_is_available(np)) {
      pr_info("bcm2709: Mini UART enabled\n");
      writel(1, __io_address(UART1_BASE + 0x4));
   }
}

static struct pn544_i2c_platform_data nfc_pdata =
{
   .irq_gpio = GPIO_TO_PIN(1,23),
   .ven_gpio = GPIO_TO_PIN(0,24),
   .firm_gpio = GPIO_UNUSED,
   .clkreq_gpio = GPIO_UNUSED,
};

static struct i2c_board_info __initdata nfc_board_info[] =
{
   {
      I2C_BOARD_INFO("pn547", 0x28),
      .platform_data = &nfc_pdata,
   },
};

void __init bcm2709_init(void)
{
   int ret;

   vc_cma_early_init();

   pm_power_off = bcm2709_power_off;

   ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
   if (ret) {
      pr_err("of_platform_populate failed: %d\n", ret);
      BUG();
   }

   i2c_register_board_info(1, nfc_board_info, ARRAY_SIZE(nfc_board_info));

   bcm2709_init_uart1();

   system_rev = boardrev;
   system_serial_low = serial;
}

################################################################################

But my dmesg still have erorr, i guess cannot write. 

[ 85.835165] pn54x_dev_open : 10,58
[ 85.835203] pn54x_dev_ioctl, cmd=1074063617, arg=1
[ 85.835214] pn544_enable power on
[ 86.039488] pn54x_dev_ioctl, cmd=1074063617, arg=0
[ 86.039508] pn544_disable power off
[ 86.249569] pn54x_dev_ioctl, cmd=1074063617, arg=1
[ 86.249586] pn544_enable power on
[ 391.291311] pn54x_dev_write : i2c_master_send returned -5

##################################################################################

please let me know if you know how to set up for write. 

Thanks!

0 Kudos

1,111 Views
jimmychan
NXP TechSupport
NXP TechSupport

As you mentioned, "changing device tree and platform data, interrupt and ven port to GPIO 23 and 24". So, your gpio setting should be like this ?

   enable-gpios = <&gpio 24 0>; 

and the GPIO 23 is in bank 0, right? 

so, the .irq_gpio = GPIO_TO_PIN(0,23),

please double check your GPIO setting.

0 Kudos