Skip to content

Commit

Permalink
NFC: Changed HCI and PN544 HCI driver to use the new HCI LLC Core
Browse files Browse the repository at this point in the history
The previous shdlc HCI driver and its header are removed from the tree.
PN544 now registers directly with HCI and passes the name of the llc it
requires (shdlc).
HCI instantiation now allocates the required llc instance. The llc is
started when the HCI device is brought up.

Signed-off-by: Eric Lapuyade <eric.lapuyade@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
  • Loading branch information
Eric Lapuyade authored and Samuel Ortiz committed Sep 24, 2012
1 parent 4a61cd6 commit 412fda5
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 1,152 deletions.
2 changes: 1 addition & 1 deletion drivers/nfc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ config PN544_NFC

config PN544_HCI_NFC
tristate "HCI PN544 NFC driver"
depends on I2C && NFC_SHDLC
depends on I2C && NFC_HCI && NFC_SHDLC
select CRC_CCITT
default n
---help---
Expand Down
73 changes: 37 additions & 36 deletions drivers/nfc/pn544_hci.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

#include <linux/nfc.h>
#include <net/nfc/hci.h>
#include <net/nfc/shdlc.h>
#include <net/nfc/llc.h>

#include <linux/nfc/pn544.h>

Expand Down Expand Up @@ -133,7 +133,7 @@ static struct nfc_hci_gate pn544_gates[] = {

struct pn544_hci_info {
struct i2c_client *i2c_dev;
struct nfc_shdlc *shdlc;
struct nfc_hci_dev *hdev;

enum pn544_state state;

Expand Down Expand Up @@ -362,21 +362,21 @@ static irqreturn_t pn544_hci_irq_thread_fn(int irq, void *dev_id)
if (r == -EREMOTEIO) {
info->hard_fault = r;

nfc_shdlc_recv_frame(info->shdlc, NULL);
nfc_hci_recv_frame(info->hdev, NULL);

return IRQ_HANDLED;
} else if ((r == -ENOMEM) || (r == -EBADMSG)) {
return IRQ_HANDLED;
}

nfc_shdlc_recv_frame(info->shdlc, skb);
nfc_hci_recv_frame(info->hdev, skb);

return IRQ_HANDLED;
}

static int pn544_hci_open(struct nfc_shdlc *shdlc)
static int pn544_hci_open(struct nfc_hci_dev *hdev)
{
struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
struct pn544_hci_info *info = nfc_hci_get_clientdata(hdev);
int r = 0;

mutex_lock(&info->info_lock);
Expand All @@ -396,9 +396,9 @@ static int pn544_hci_open(struct nfc_shdlc *shdlc)
return r;
}

static void pn544_hci_close(struct nfc_shdlc *shdlc)
static void pn544_hci_close(struct nfc_hci_dev *hdev)
{
struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
struct pn544_hci_info *info = nfc_hci_get_clientdata(hdev);

mutex_lock(&info->info_lock);

Expand All @@ -413,9 +413,8 @@ static void pn544_hci_close(struct nfc_shdlc *shdlc)
mutex_unlock(&info->info_lock);
}

static int pn544_hci_ready(struct nfc_shdlc *shdlc)
static int pn544_hci_ready(struct nfc_hci_dev *hdev)
{
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
struct sk_buff *skb;
static struct hw_config {
u8 adr[2];
Expand Down Expand Up @@ -601,9 +600,9 @@ static void pn544_hci_remove_len_crc(struct sk_buff *skb)
skb_trim(skb, PN544_FRAME_TAILROOM);
}

static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb)
static int pn544_hci_xmit(struct nfc_hci_dev *hdev, struct sk_buff *skb)
{
struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
struct pn544_hci_info *info = nfc_hci_get_clientdata(hdev);
struct i2c_client *client = info->i2c_dev;
int r;

Expand All @@ -617,10 +616,9 @@ static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb)
return r;
}

static int pn544_hci_start_poll(struct nfc_shdlc *shdlc,
static int pn544_hci_start_poll(struct nfc_hci_dev *hdev,
u32 im_protocols, u32 tm_protocols)
{
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
u8 phases = 0;
int r;
u8 duration[2];
Expand Down Expand Up @@ -671,7 +669,7 @@ static int pn544_hci_start_poll(struct nfc_shdlc *shdlc,
return r;
}

static int pn544_hci_target_from_gate(struct nfc_shdlc *shdlc, u8 gate,
static int pn544_hci_target_from_gate(struct nfc_hci_dev *hdev, u8 gate,
struct nfc_target *target)
{
switch (gate) {
Expand All @@ -689,11 +687,10 @@ static int pn544_hci_target_from_gate(struct nfc_shdlc *shdlc, u8 gate,
return 0;
}

static int pn544_hci_complete_target_discovered(struct nfc_shdlc *shdlc,
static int pn544_hci_complete_target_discovered(struct nfc_hci_dev *hdev,
u8 gate,
struct nfc_target *target)
{
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
struct sk_buff *uid_skb;
int r = 0;

Expand Down Expand Up @@ -765,13 +762,12 @@ static void pn544_hci_data_exchange_cb(void *context, struct sk_buff *skb,
* <= 0: driver handled the data exchange
* 1: driver doesn't especially handle, please do standard processing
*/
static int pn544_hci_data_exchange(struct nfc_shdlc *shdlc,
static int pn544_hci_data_exchange(struct nfc_hci_dev *hdev,
struct nfc_target *target,
struct sk_buff *skb, data_exchange_cb_t cb,
void *cb_context)
{
struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
struct pn544_hci_info *info = nfc_hci_get_clientdata(hdev);

pr_info(DRIVER_DESC ": %s for gate=%d\n", __func__,
target->hci_reader_gate);
Expand Down Expand Up @@ -824,17 +820,15 @@ static int pn544_hci_data_exchange(struct nfc_shdlc *shdlc,
}
}

static int pn544_hci_check_presence(struct nfc_shdlc *shdlc,
static int pn544_hci_check_presence(struct nfc_hci_dev *hdev,
struct nfc_target *target)
{
struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);

return nfc_hci_send_cmd(hdev, target->hci_reader_gate,
PN544_RF_READER_CMD_PRESENCE_CHECK,
NULL, 0, NULL);
}

static struct nfc_shdlc_ops pn544_shdlc_ops = {
static struct nfc_hci_ops pn544_hci_ops = {
.open = pn544_hci_open,
.close = pn544_hci_close,
.hci_ready = pn544_hci_ready,
Expand Down Expand Up @@ -926,23 +920,30 @@ static int __devinit pn544_hci_probe(struct i2c_client *client,
NFC_PROTO_ISO14443_B_MASK |
NFC_PROTO_NFC_DEP_MASK;

info->shdlc = nfc_shdlc_allocate(&pn544_shdlc_ops,
&init_data, protocols,
PN544_FRAME_HEADROOM + PN544_CMDS_HEADROOM,
PN544_FRAME_TAILROOM,
PN544_HCI_LLC_MAX_PAYLOAD,
dev_name(&client->dev));
if (!info->shdlc) {
dev_err(&client->dev, "Cannot allocate nfc shdlc.\n");
info->hdev = nfc_hci_allocate_device(&pn544_hci_ops, &init_data,
protocols, LLC_SHDLC_NAME,
PN544_FRAME_HEADROOM +
PN544_CMDS_HEADROOM,
PN544_FRAME_TAILROOM,
PN544_HCI_LLC_MAX_PAYLOAD);
if (!info->hdev) {
dev_err(&client->dev, "Cannot allocate nfc hdev.\n");
r = -ENOMEM;
goto err_allocshdlc;
goto err_alloc_hdev;
}

nfc_shdlc_set_clientdata(info->shdlc, info);
nfc_hci_set_clientdata(info->hdev, info);

r = nfc_hci_register_device(info->hdev);
if (r)
goto err_regdev;

return 0;

err_allocshdlc:
err_regdev:
nfc_hci_free_device(info->hdev);

err_alloc_hdev:
free_irq(client->irq, info);

err_rti:
Expand All @@ -963,7 +964,7 @@ static __devexit int pn544_hci_remove(struct i2c_client *client)

dev_dbg(&client->dev, "%s\n", __func__);

nfc_shdlc_free(info->shdlc);
nfc_hci_free_device(info->hdev);

if (info->state != PN544_ST_COLD) {
if (pdata->disable)
Expand Down
3 changes: 3 additions & 0 deletions include/net/nfc/hci.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ struct nfc_hci_dev {

struct nfc_hci_ops *ops;

struct nfc_llc *llc;

struct nfc_hci_init_data init_data;

void *clientdata;
Expand All @@ -113,6 +115,7 @@ struct nfc_hci_dev {
struct nfc_hci_dev *nfc_hci_allocate_device(struct nfc_hci_ops *ops,
struct nfc_hci_init_data *init_data,
u32 protocols,
const char *llc_name,
int tx_headroom,
int tx_tailroom,
int max_link_payload);
Expand Down
106 changes: 0 additions & 106 deletions include/net/nfc/shdlc.h

This file was deleted.

2 changes: 1 addition & 1 deletion net/nfc/hci/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
obj-$(CONFIG_NFC_HCI) += hci.o

hci-y := core.o hcp.o command.o llc.o llc_nop.o
hci-$(CONFIG_NFC_SHDLC) += shdlc.o llc_shdlc.o
hci-$(CONFIG_NFC_SHDLC) += llc_shdlc.o
Loading

0 comments on commit 412fda5

Please sign in to comment.