Skip to content

Commit

Permalink
Merge tag 'nfc-next-4.1-1' of git://git.kernel.org/pub/scm/linux/kern…
Browse files Browse the repository at this point in the history
…el/git/sameo/nfc-next

Samuel Ortiz says:

====================
NFC: 4.1 pull request

This is the NFC pull request for 4.1.

This is a shorter one than usual, as the Intel Field Peak NFC
driver could not make it in time.

We have:

- A new driver for NXP NCI based chipsets, like e.g. the NPC100 or
  the PN7150. It currently only supports an i2c physical layer, but
  could easily be extended to work on top of e.g. SPI.
  This driver also includes support for user space triggered firmware
  updates.

- A few minor st21nfc[ab] fixes, cleanups, and comments improvements.

- A pn533 error return fix.

- A few NFC related logs formatting cleanups.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Apr 8, 2015
2 parents 51df60f + 3590ebc commit 82740b9
Show file tree
Hide file tree
Showing 26 changed files with 1,207 additions and 55 deletions.
35 changes: 35 additions & 0 deletions Documentation/devicetree/bindings/net/nfc/nxp-nci.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
* NXP Semiconductors NXP NCI NFC Controllers

Required properties:
- compatible: Should be "nxp,nxp-nci-i2c".
- clock-frequency: I²C work frequency.
- reg: address on the bus
- interrupt-parent: phandle for the interrupt gpio controller
- interrupts: GPIO interrupt to which the chip is connected
- enable-gpios: Output GPIO pin used for enabling/disabling the chip
- firmware-gpios: Output GPIO pin used to enter firmware download mode

Optional SoC Specific Properties:
- pinctrl-names: Contains only one value - "default".
- pintctrl-0: Specifies the pin control groups used for this controller.

Example (for ARM-based BeagleBone with NPC100 NFC controller on I2C2):

&i2c2 {

status = "okay";

npc100: npc100@29 {

compatible = "nxp,nxp-nci-i2c";

reg = <0x29>;
clock-frequency = <100000>;

interrupt-parent = <&gpio1>;
interrupts = <29 GPIO_ACTIVE_HIGH>;

enable-gpios = <&gpio0 30 GPIO_ACTIVE_HIGH>;
firmware-gpios = <&gpio0 31 GPIO_ACTIVE_HIGH>;
};
};
7 changes: 7 additions & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -6944,6 +6944,13 @@ S: Supported
F: drivers/block/nvme*
F: include/linux/nvme.h

NXP-NCI NFC DRIVER
M: Clément Perrochaud <clement.perrochaud@effinnov.com>
R: Charles Gorand <charles.gorand@effinnov.com>
L: linux-nfc@lists.01.org (moderated for non-subscribers)
S: Supported
F: drivers/nfc/nxp-nci

NXP TDA998X DRM DRIVER
M: Russell King <rmk+kernel@arm.linux.org.uk>
S: Supported
Expand Down
1 change: 1 addition & 0 deletions drivers/nfc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,5 @@ source "drivers/nfc/microread/Kconfig"
source "drivers/nfc/nfcmrvl/Kconfig"
source "drivers/nfc/st21nfca/Kconfig"
source "drivers/nfc/st21nfcb/Kconfig"
source "drivers/nfc/nxp-nci/Kconfig"
endmenu
1 change: 1 addition & 0 deletions drivers/nfc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ obj-$(CONFIG_NFC_MRVL) += nfcmrvl/
obj-$(CONFIG_NFC_TRF7970A) += trf7970a.o
obj-$(CONFIG_NFC_ST21NFCA) += st21nfca/
obj-$(CONFIG_NFC_ST21NFCB) += st21nfcb/
obj-$(CONFIG_NFC_NXP_NCI) += nxp-nci/

ccflags-$(CONFIG_NFC_DEBUG) := -DDEBUG
2 changes: 1 addition & 1 deletion drivers/nfc/microread/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ static int microread_i2c_probe(struct i2c_client *client,
if (r < 0)
goto err_irq;

nfc_info(&client->dev, "Probed");
nfc_info(&client->dev, "Probed\n");

return 0;

Expand Down
4 changes: 2 additions & 2 deletions drivers/nfc/nfcmrvl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,

priv->ndev = nci_allocate_device(&nfcmrvl_nci_ops, protocols, 0, 0);
if (!priv->ndev) {
nfc_err(dev, "nci_allocate_device failed");
nfc_err(dev, "nci_allocate_device failed\n");
rc = -ENOMEM;
goto error;
}
Expand All @@ -120,7 +120,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,

rc = nci_register_device(priv->ndev);
if (rc) {
nfc_err(dev, "nci_register_device failed %d", rc);
nfc_err(dev, "nci_register_device failed %d\n", rc);
nci_free_device(priv->ndev);
goto error;
}
Expand Down
18 changes: 9 additions & 9 deletions drivers/nfc/nfcmrvl/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static void nfcmrvl_bulk_complete(struct urb *urb)
if (!urb->status) {
if (nfcmrvl_nci_recv_frame(drv_data->priv, urb->transfer_buffer,
urb->actual_length) < 0)
nfc_err(&drv_data->udev->dev, "corrupted Rx packet");
nfc_err(&drv_data->udev->dev, "corrupted Rx packet\n");
}

if (!test_bit(NFCMRVL_USB_BULK_RUNNING, &drv_data->flags))
Expand All @@ -96,7 +96,7 @@ static void nfcmrvl_bulk_complete(struct urb *urb)
*/
if (err != -EPERM && err != -ENODEV)
nfc_err(&drv_data->udev->dev,
"urb %p failed to resubmit (%d)", urb, -err);
"urb %p failed to resubmit (%d)\n", urb, -err);
usb_unanchor_urb(urb);
}
}
Expand Down Expand Up @@ -137,7 +137,7 @@ nfcmrvl_submit_bulk_urb(struct nfcmrvl_usb_drv_data *drv_data, gfp_t mem_flags)
if (err) {
if (err != -EPERM && err != -ENODEV)
nfc_err(&drv_data->udev->dev,
"urb %p submission failed (%d)", urb, -err);
"urb %p submission failed (%d)\n", urb, -err);
usb_unanchor_urb(urb);
}

Expand All @@ -153,7 +153,7 @@ static void nfcmrvl_tx_complete(struct urb *urb)
struct nfcmrvl_private *priv = nci_get_drvdata(ndev);
struct nfcmrvl_usb_drv_data *drv_data = priv->drv_data;

nfc_info(priv->dev, "urb %p status %d count %d",
nfc_info(priv->dev, "urb %p status %d count %d\n",
urb, urb->status, urb->actual_length);

spin_lock(&drv_data->txlock);
Expand Down Expand Up @@ -253,7 +253,7 @@ static int nfcmrvl_usb_nci_send(struct nfcmrvl_private *priv,
if (err) {
if (err != -EPERM && err != -ENODEV)
nfc_err(&drv_data->udev->dev,
"urb %p submission failed (%d)", urb, -err);
"urb %p submission failed (%d)\n", urb, -err);
kfree(urb->setup_packet);
usb_unanchor_urb(urb);
} else {
Expand Down Expand Up @@ -293,7 +293,7 @@ static int nfcmrvl_probe(struct usb_interface *intf,
int i;
struct usb_device *udev = interface_to_usbdev(intf);

nfc_info(&udev->dev, "intf %p id %p", intf, id);
nfc_info(&udev->dev, "intf %p id %p\n", intf, id);

drv_data = devm_kzalloc(&intf->dev, sizeof(*drv_data), GFP_KERNEL);
if (!drv_data)
Expand Down Expand Up @@ -348,7 +348,7 @@ static void nfcmrvl_disconnect(struct usb_interface *intf)
if (!drv_data)
return;

nfc_info(&drv_data->udev->dev, "intf %p", intf);
nfc_info(&drv_data->udev->dev, "intf %p\n", intf);

nfcmrvl_nci_unregister_dev(drv_data->priv);

Expand All @@ -360,7 +360,7 @@ static int nfcmrvl_suspend(struct usb_interface *intf, pm_message_t message)
{
struct nfcmrvl_usb_drv_data *drv_data = usb_get_intfdata(intf);

nfc_info(&drv_data->udev->dev, "intf %p", intf);
nfc_info(&drv_data->udev->dev, "intf %p\n", intf);

if (drv_data->suspend_count++)
return 0;
Expand Down Expand Up @@ -401,7 +401,7 @@ static int nfcmrvl_resume(struct usb_interface *intf)
struct nfcmrvl_usb_drv_data *drv_data = usb_get_intfdata(intf);
int err = 0;

nfc_info(&drv_data->udev->dev, "intf %p", intf);
nfc_info(&drv_data->udev->dev, "intf %p\n", intf);

if (--drv_data->suspend_count)
return 0;
Expand Down
25 changes: 25 additions & 0 deletions drivers/nfc/nxp-nci/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
config NFC_NXP_NCI
tristate "NXP-NCI NFC driver"
depends on NFC_NCI
default n
---help---
Generic core driver for NXP NCI chips such as the NPC100
or PN7150 families.
This is a driver based on the NCI NFC kernel layers and
will thus not work with NXP libnfc library.

To compile this driver as a module, choose m here. The module will
be called nxp_nci.
Say N if unsure.

config NFC_NXP_NCI_I2C
tristate "NXP-NCI I2C support"
depends on NFC_NXP_NCI && I2C
---help---
This module adds support for an I2C interface to the NXP NCI
chips.
Select this if your platform is using the I2C bus.

To compile this driver as a module, choose m here. The module will
be called nxp_nci_i2c.
Say Y if unsure.
11 changes: 11 additions & 0 deletions drivers/nfc/nxp-nci/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#
# Makefile for NXP-NCI NFC driver
#

nxp-nci-objs = core.o firmware.o
nxp-nci_i2c-objs = i2c.o

obj-$(CONFIG_NFC_NXP_NCI) += nxp-nci.o
obj-$(CONFIG_NFC_NXP_NCI_I2C) += nxp-nci_i2c.o

ccflags-$(CONFIG_NFC_DEBUG) := -DDEBUG
186 changes: 186 additions & 0 deletions drivers/nfc/nxp-nci/core.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
/*
* Generic driver for NXP NCI NFC chips
*
* Copyright (C) 2014 NXP Semiconductors All rights reserved.
*
* Authors: Clément Perrochaud <clement.perrochaud@nxp.com>
*
* Derived from PN544 device driver:
* Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <linux/delay.h>
#include <linux/gpio.h>
#include <linux/module.h>
#include <linux/nfc.h>
#include <linux/platform_data/nxp-nci.h>

#include <net/nfc/nci_core.h>

#include "nxp-nci.h"

#define NXP_NCI_HDR_LEN 4

#define NXP_NCI_NFC_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
NFC_PROTO_MIFARE_MASK | \
NFC_PROTO_FELICA_MASK | \
NFC_PROTO_ISO14443_MASK | \
NFC_PROTO_ISO14443_B_MASK | \
NFC_PROTO_NFC_DEP_MASK)

static int nxp_nci_open(struct nci_dev *ndev)
{
struct nxp_nci_info *info = nci_get_drvdata(ndev);
int r = 0;

mutex_lock(&info->info_lock);

if (info->mode != NXP_NCI_MODE_COLD) {
r = -EBUSY;
goto open_exit;
}

if (info->phy_ops->set_mode)
r = info->phy_ops->set_mode(info->phy_id, NXP_NCI_MODE_NCI);

info->mode = NXP_NCI_MODE_NCI;

open_exit:
mutex_unlock(&info->info_lock);
return r;
}

static int nxp_nci_close(struct nci_dev *ndev)
{
struct nxp_nci_info *info = nci_get_drvdata(ndev);
int r = 0;

mutex_lock(&info->info_lock);

if (info->phy_ops->set_mode)
r = info->phy_ops->set_mode(info->phy_id, NXP_NCI_MODE_COLD);

info->mode = NXP_NCI_MODE_COLD;

mutex_unlock(&info->info_lock);
return r;
}

static int nxp_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
{
struct nxp_nci_info *info = nci_get_drvdata(ndev);
int r;

if (!info->phy_ops->write) {
r = -ENOTSUPP;
goto send_exit;
}

if (info->mode != NXP_NCI_MODE_NCI) {
r = -EINVAL;
goto send_exit;
}

r = info->phy_ops->write(info->phy_id, skb);
if (r < 0)
kfree_skb(skb);

send_exit:
return r;
}

static struct nci_ops nxp_nci_ops = {
.open = nxp_nci_open,
.close = nxp_nci_close,
.send = nxp_nci_send,
.fw_download = nxp_nci_fw_download,
};

int nxp_nci_probe(void *phy_id, struct device *pdev,
struct nxp_nci_phy_ops *phy_ops, unsigned int max_payload,
struct nci_dev **ndev)
{
struct nxp_nci_info *info;
int r;

info = devm_kzalloc(pdev, sizeof(struct nxp_nci_info), GFP_KERNEL);
if (!info) {
r = -ENOMEM;
goto probe_exit;
}

info->phy_id = phy_id;
info->pdev = pdev;
info->phy_ops = phy_ops;
info->max_payload = max_payload;
INIT_WORK(&info->fw_info.work, nxp_nci_fw_work);
init_completion(&info->fw_info.cmd_completion);
mutex_init(&info->info_lock);

if (info->phy_ops->set_mode) {
r = info->phy_ops->set_mode(info->phy_id, NXP_NCI_MODE_COLD);
if (r < 0)
goto probe_exit;
}

info->mode = NXP_NCI_MODE_COLD;

info->ndev = nci_allocate_device(&nxp_nci_ops, NXP_NCI_NFC_PROTOCOLS,
NXP_NCI_HDR_LEN, 0);
if (!info->ndev) {
r = -ENOMEM;
goto probe_exit;
}

nci_set_parent_dev(info->ndev, pdev);
nci_set_drvdata(info->ndev, info);
r = nci_register_device(info->ndev);
if (r < 0)
goto probe_exit_free_nci;

*ndev = info->ndev;

goto probe_exit;

probe_exit_free_nci:
nci_free_device(info->ndev);
probe_exit:
return r;
}
EXPORT_SYMBOL(nxp_nci_probe);

void nxp_nci_remove(struct nci_dev *ndev)
{
struct nxp_nci_info *info = nci_get_drvdata(ndev);

if (info->mode == NXP_NCI_MODE_FW)
nxp_nci_fw_work_complete(info, -ESHUTDOWN);
cancel_work_sync(&info->fw_info.work);

mutex_lock(&info->info_lock);

if (info->phy_ops->set_mode)
info->phy_ops->set_mode(info->phy_id, NXP_NCI_MODE_COLD);

nci_unregister_device(ndev);
nci_free_device(ndev);

mutex_unlock(&info->info_lock);
}
EXPORT_SYMBOL(nxp_nci_remove);

MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("NXP NCI NFC driver");
MODULE_AUTHOR("Clément Perrochaud <clement.perrochaud@nxp.com>");
Loading

0 comments on commit 82740b9

Please sign in to comment.