linux/drivers/nfc/pn544_hci.c
<<
>>
Prefs
   1/*
   2 * HCI based Driver for NXP PN544 NFC Chip
   3 *
   4 * Copyright (C) 2012  Intel Corporation. All rights reserved.
   5 *
   6 * This program is free software; you can redistribute it and/or modify it
   7 * under the terms and conditions of the GNU General Public License,
   8 * version 2, as published by the Free Software Foundation.
   9 *
  10 * This program is distributed in the hope that it will be useful,
  11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13 * GNU General Public License for more details.
  14 *
  15 * You should have received a copy of the GNU General Public License
  16 * along with this program; if not, write to the
  17 * Free Software Foundation, Inc.,
  18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19 */
  20
  21#include <linux/crc-ccitt.h>
  22#include <linux/module.h>
  23#include <linux/delay.h>
  24#include <linux/slab.h>
  25#include <linux/miscdevice.h>
  26#include <linux/interrupt.h>
  27#include <linux/gpio.h>
  28#include <linux/i2c.h>
  29
  30#include <linux/nfc.h>
  31#include <net/nfc/hci.h>
  32#include <net/nfc/shdlc.h>
  33
  34#include <linux/nfc/pn544.h>
  35
  36#define DRIVER_DESC "HCI NFC driver for PN544"
  37
  38#define PN544_HCI_DRIVER_NAME "pn544_hci"
  39
  40/* Timing restrictions (ms) */
  41#define PN544_HCI_RESETVEN_TIME         30
  42
  43static struct i2c_device_id pn544_hci_id_table[] = {
  44        {"pn544", 0},
  45        {}
  46};
  47
  48MODULE_DEVICE_TABLE(i2c, pn544_hci_id_table);
  49
  50#define HCI_MODE 0
  51#define FW_MODE 1
  52
  53/* framing in HCI mode */
  54#define PN544_HCI_LLC_LEN               1
  55#define PN544_HCI_LLC_CRC               2
  56#define PN544_HCI_LLC_LEN_CRC           (PN544_HCI_LLC_LEN + PN544_HCI_LLC_CRC)
  57#define PN544_HCI_LLC_MIN_SIZE          (1 + PN544_HCI_LLC_LEN_CRC)
  58#define PN544_HCI_LLC_MAX_PAYLOAD       29
  59#define PN544_HCI_LLC_MAX_SIZE          (PN544_HCI_LLC_LEN_CRC + 1 + \
  60                                         PN544_HCI_LLC_MAX_PAYLOAD)
  61
  62enum pn544_state {
  63        PN544_ST_COLD,
  64        PN544_ST_FW_READY,
  65        PN544_ST_READY,
  66};
  67
  68#define FULL_VERSION_LEN 11
  69
  70/* Proprietary commands */
  71#define PN544_WRITE             0x3f
  72
  73/* Proprietary gates, events, commands and registers */
  74
  75/* NFC_HCI_RF_READER_A_GATE additional registers and commands */
  76#define PN544_RF_READER_A_AUTO_ACTIVATION                       0x10
  77#define PN544_RF_READER_A_CMD_CONTINUE_ACTIVATION               0x12
  78#define PN544_MIFARE_CMD                                        0x21
  79
  80/* Commands that apply to all RF readers */
  81#define PN544_RF_READER_CMD_PRESENCE_CHECK      0x30
  82#define PN544_RF_READER_CMD_ACTIVATE_NEXT       0x32
  83
  84/* NFC_HCI_ID_MGMT_GATE additional registers */
  85#define PN544_ID_MGMT_FULL_VERSION_SW           0x10
  86
  87#define PN544_RF_READER_ISO15693_GATE           0x12
  88
  89#define PN544_RF_READER_F_GATE                  0x14
  90#define PN544_FELICA_ID                         0x04
  91#define PN544_FELICA_RAW                        0x20
  92
  93#define PN544_RF_READER_JEWEL_GATE              0x15
  94#define PN544_JEWEL_RAW_CMD                     0x23
  95
  96#define PN544_RF_READER_NFCIP1_INITIATOR_GATE   0x30
  97#define PN544_RF_READER_NFCIP1_TARGET_GATE      0x31
  98
  99#define PN544_SYS_MGMT_GATE                     0x90
 100#define PN544_SYS_MGMT_INFO_NOTIFICATION        0x02
 101
 102#define PN544_POLLING_LOOP_MGMT_GATE            0x94
 103#define PN544_PL_RDPHASES                       0x06
 104#define PN544_PL_EMULATION                      0x07
 105#define PN544_PL_NFCT_DEACTIVATED               0x09
 106
 107#define PN544_SWP_MGMT_GATE                     0xA0
 108
 109#define PN544_NFC_WI_MGMT_GATE                  0xA1
 110
 111static struct nfc_hci_gate pn544_gates[] = {
 112        {NFC_HCI_ADMIN_GATE, NFC_HCI_INVALID_PIPE},
 113        {NFC_HCI_LOOPBACK_GATE, NFC_HCI_INVALID_PIPE},
 114        {NFC_HCI_ID_MGMT_GATE, NFC_HCI_INVALID_PIPE},
 115        {NFC_HCI_LINK_MGMT_GATE, NFC_HCI_INVALID_PIPE},
 116        {NFC_HCI_RF_READER_B_GATE, NFC_HCI_INVALID_PIPE},
 117        {NFC_HCI_RF_READER_A_GATE, NFC_HCI_INVALID_PIPE},
 118        {PN544_SYS_MGMT_GATE, NFC_HCI_INVALID_PIPE},
 119        {PN544_SWP_MGMT_GATE, NFC_HCI_INVALID_PIPE},
 120        {PN544_POLLING_LOOP_MGMT_GATE, NFC_HCI_INVALID_PIPE},
 121        {PN544_NFC_WI_MGMT_GATE, NFC_HCI_INVALID_PIPE},
 122        {PN544_RF_READER_F_GATE, NFC_HCI_INVALID_PIPE},
 123        {PN544_RF_READER_JEWEL_GATE, NFC_HCI_INVALID_PIPE},
 124        {PN544_RF_READER_ISO15693_GATE, NFC_HCI_INVALID_PIPE},
 125        {PN544_RF_READER_NFCIP1_INITIATOR_GATE, NFC_HCI_INVALID_PIPE},
 126        {PN544_RF_READER_NFCIP1_TARGET_GATE, NFC_HCI_INVALID_PIPE}
 127};
 128
 129/* Largest headroom needed for outgoing custom commands */
 130#define PN544_CMDS_HEADROOM     2
 131
 132struct pn544_hci_info {
 133        struct i2c_client *i2c_dev;
 134        struct nfc_shdlc *shdlc;
 135
 136        enum pn544_state state;
 137
 138        struct mutex info_lock;
 139
 140        unsigned int gpio_en;
 141        unsigned int gpio_irq;
 142        unsigned int gpio_fw;
 143        unsigned int en_polarity;
 144
 145        int hard_fault;         /*
 146                                 * < 0 if hardware error occured (e.g. i2c err)
 147                                 * and prevents normal operation.
 148                                 */
 149};
 150
 151static void pn544_hci_platform_init(struct pn544_hci_info *info)
 152{
 153        int polarity, retry, ret;
 154        char rset_cmd[] = { 0x05, 0xF9, 0x04, 0x00, 0xC3, 0xE5 };
 155        int count = sizeof(rset_cmd);
 156
 157        pr_info(DRIVER_DESC ": %s\n", __func__);
 158        dev_info(&info->i2c_dev->dev, "Detecting nfc_en polarity\n");
 159
 160        /* Disable fw download */
 161        gpio_set_value(info->gpio_fw, 0);
 162
 163        for (polarity = 0; polarity < 2; polarity++) {
 164                info->en_polarity = polarity;
 165                retry = 3;
 166                while (retry--) {
 167                        /* power off */
 168                        gpio_set_value(info->gpio_en, !info->en_polarity);
 169                        usleep_range(10000, 15000);
 170
 171                        /* power on */
 172                        gpio_set_value(info->gpio_en, info->en_polarity);
 173                        usleep_range(10000, 15000);
 174
 175                        /* send reset */
 176                        dev_dbg(&info->i2c_dev->dev, "Sending reset cmd\n");
 177                        ret = i2c_master_send(info->i2c_dev, rset_cmd, count);
 178                        if (ret == count) {
 179                                dev_info(&info->i2c_dev->dev,
 180                                         "nfc_en polarity : active %s\n",
 181                                         (polarity == 0 ? "low" : "high"));
 182                                goto out;
 183                        }
 184                }
 185        }
 186
 187        dev_err(&info->i2c_dev->dev,
 188                "Could not detect nfc_en polarity, fallback to active high\n");
 189
 190out:
 191        gpio_set_value(info->gpio_en, !info->en_polarity);
 192}
 193
 194static int pn544_hci_enable(struct pn544_hci_info *info, int mode)
 195{
 196        pr_info(DRIVER_DESC ": %s\n", __func__);
 197
 198        gpio_set_value(info->gpio_fw, 0);
 199        gpio_set_value(info->gpio_en, info->en_polarity);
 200        usleep_range(10000, 15000);
 201
 202        return 0;
 203}
 204
 205static void pn544_hci_disable(struct pn544_hci_info *info)
 206{
 207        pr_info(DRIVER_DESC ": %s\n", __func__);
 208
 209        gpio_set_value(info->gpio_fw, 0);
 210        gpio_set_value(info->gpio_en, !info->en_polarity);
 211        usleep_range(10000, 15000);
 212
 213        gpio_set_value(info->gpio_en, info->en_polarity);
 214        usleep_range(10000, 15000);
 215
 216        gpio_set_value(info->gpio_en, !info->en_polarity);
 217        usleep_range(10000, 15000);
 218}
 219
 220static int pn544_hci_i2c_write(struct i2c_client *client, u8 *buf, int len)
 221{
 222        int r;
 223
 224        usleep_range(3000, 6000);
 225
 226        r = i2c_master_send(client, buf, len);
 227
 228        if (r == -EREMOTEIO) {  /* Retry, chip was in standby */
 229                usleep_range(6000, 10000);
 230                r = i2c_master_send(client, buf, len);
 231        }
 232
 233        if (r >= 0 && r != len)
 234                r = -EREMOTEIO;
 235
 236        return r;
 237}
 238
 239static int check_crc(u8 *buf, int buflen)
 240{
 241        int len;
 242        u16 crc;
 243
 244        len = buf[0] + 1;
 245        crc = crc_ccitt(0xffff, buf, len - 2);
 246        crc = ~crc;
 247
 248        if (buf[len - 2] != (crc & 0xff) || buf[len - 1] != (crc >> 8)) {
 249                pr_err(PN544_HCI_DRIVER_NAME ": CRC error 0x%x != 0x%x 0x%x\n",
 250                       crc, buf[len - 1], buf[len - 2]);
 251
 252                pr_info(DRIVER_DESC ": %s : BAD CRC\n", __func__);
 253                print_hex_dump(KERN_DEBUG, "crc: ", DUMP_PREFIX_NONE,
 254                               16, 2, buf, buflen, false);
 255                return -EPERM;
 256        }
 257        return 0;
 258}
 259
 260/*
 261 * Reads an shdlc frame and returns it in a newly allocated sk_buff. Guarantees
 262 * that i2c bus will be flushed and that next read will start on a new frame.
 263 * returned skb contains only LLC header and payload.
 264 * returns:
 265 * -EREMOTEIO : i2c read error (fatal)
 266 * -EBADMSG : frame was incorrect and discarded
 267 * -ENOMEM : cannot allocate skb, frame dropped
 268 */
 269static int pn544_hci_i2c_read(struct i2c_client *client, struct sk_buff **skb)
 270{
 271        int r;
 272        u8 len;
 273        u8 tmp[PN544_HCI_LLC_MAX_SIZE - 1];
 274
 275        r = i2c_master_recv(client, &len, 1);
 276        if (r != 1) {
 277                dev_err(&client->dev, "cannot read len byte\n");
 278                return -EREMOTEIO;
 279        }
 280
 281        if ((len < (PN544_HCI_LLC_MIN_SIZE - 1)) ||
 282            (len > (PN544_HCI_LLC_MAX_SIZE - 1))) {
 283                dev_err(&client->dev, "invalid len byte\n");
 284                r = -EBADMSG;
 285                goto flush;
 286        }
 287
 288        *skb = alloc_skb(1 + len, GFP_KERNEL);
 289        if (*skb == NULL) {
 290                r = -ENOMEM;
 291                goto flush;
 292        }
 293
 294        *skb_put(*skb, 1) = len;
 295
 296        r = i2c_master_recv(client, skb_put(*skb, len), len);
 297        if (r != len) {
 298                kfree_skb(*skb);
 299                return -EREMOTEIO;
 300        }
 301
 302        r = check_crc((*skb)->data, (*skb)->len);
 303        if (r != 0) {
 304                kfree_skb(*skb);
 305                r = -EBADMSG;
 306                goto flush;
 307        }
 308
 309        skb_pull(*skb, 1);
 310        skb_trim(*skb, (*skb)->len - 2);
 311
 312        usleep_range(3000, 6000);
 313
 314        return 0;
 315
 316flush:
 317        if (i2c_master_recv(client, tmp, sizeof(tmp)) < 0)
 318                r = -EREMOTEIO;
 319
 320        usleep_range(3000, 6000);
 321
 322        return r;
 323}
 324
 325/*
 326 * Reads an shdlc frame from the chip. This is not as straightforward as it
 327 * seems. There are cases where we could loose the frame start synchronization.
 328 * The frame format is len-data-crc, and corruption can occur anywhere while
 329 * transiting on i2c bus, such that we could read an invalid len.
 330 * In order to recover synchronization with the next frame, we must be sure
 331 * to read the real amount of data without using the len byte. We do this by
 332 * assuming the following:
 333 * - the chip will always present only one single complete frame on the bus
 334 *   before triggering the interrupt
 335 * - the chip will not present a new frame until we have completely read
 336 *   the previous one (or until we have handled the interrupt).
 337 * The tricky case is when we read a corrupted len that is less than the real
 338 * len. We must detect this here in order to determine that we need to flush
 339 * the bus. This is the reason why we check the crc here.
 340 */
 341static irqreturn_t pn544_hci_irq_thread_fn(int irq, void *dev_id)
 342{
 343        struct pn544_hci_info *info = dev_id;
 344        struct i2c_client *client = info->i2c_dev;
 345        struct sk_buff *skb = NULL;
 346        int r;
 347
 348        BUG_ON(!info);
 349        BUG_ON(irq != info->i2c_dev->irq);
 350
 351        dev_dbg(&client->dev, "IRQ\n");
 352
 353        if (info->hard_fault != 0)
 354                return IRQ_HANDLED;
 355
 356        r = pn544_hci_i2c_read(client, &skb);
 357        if (r == -EREMOTEIO) {
 358                info->hard_fault = r;
 359
 360                nfc_shdlc_recv_frame(info->shdlc, NULL);
 361
 362                return IRQ_HANDLED;
 363        } else if ((r == -ENOMEM) || (r == -EBADMSG)) {
 364                return IRQ_HANDLED;
 365        }
 366
 367        nfc_shdlc_recv_frame(info->shdlc, skb);
 368
 369        return IRQ_HANDLED;
 370}
 371
 372static int pn544_hci_open(struct nfc_shdlc *shdlc)
 373{
 374        struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
 375        int r = 0;
 376
 377        mutex_lock(&info->info_lock);
 378
 379        if (info->state != PN544_ST_COLD) {
 380                r = -EBUSY;
 381                goto out;
 382        }
 383
 384        r = pn544_hci_enable(info, HCI_MODE);
 385
 386        if (r == 0)
 387                info->state = PN544_ST_READY;
 388
 389out:
 390        mutex_unlock(&info->info_lock);
 391        return r;
 392}
 393
 394static void pn544_hci_close(struct nfc_shdlc *shdlc)
 395{
 396        struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
 397
 398        mutex_lock(&info->info_lock);
 399
 400        if (info->state == PN544_ST_COLD)
 401                goto out;
 402
 403        pn544_hci_disable(info);
 404
 405        info->state = PN544_ST_COLD;
 406
 407out:
 408        mutex_unlock(&info->info_lock);
 409}
 410
 411static int pn544_hci_ready(struct nfc_shdlc *shdlc)
 412{
 413        struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
 414        struct sk_buff *skb;
 415        static struct hw_config {
 416                u8 adr[2];
 417                u8 value;
 418        } hw_config[] = {
 419                {{0x9f, 0x9a}, 0x00},
 420
 421                {{0x98, 0x10}, 0xbc},
 422
 423                {{0x9e, 0x71}, 0x00},
 424
 425                {{0x98, 0x09}, 0x00},
 426
 427                {{0x9e, 0xb4}, 0x00},
 428
 429                {{0x9e, 0xd9}, 0xff},
 430                {{0x9e, 0xda}, 0xff},
 431                {{0x9e, 0xdb}, 0x23},
 432                {{0x9e, 0xdc}, 0x21},
 433                {{0x9e, 0xdd}, 0x22},
 434                {{0x9e, 0xde}, 0x24},
 435
 436                {{0x9c, 0x01}, 0x08},
 437
 438                {{0x9e, 0xaa}, 0x01},
 439
 440                {{0x9b, 0xd1}, 0x0d},
 441                {{0x9b, 0xd2}, 0x24},
 442                {{0x9b, 0xd3}, 0x0a},
 443                {{0x9b, 0xd4}, 0x22},
 444                {{0x9b, 0xd5}, 0x08},
 445                {{0x9b, 0xd6}, 0x1e},
 446                {{0x9b, 0xdd}, 0x1c},
 447
 448                {{0x9b, 0x84}, 0x13},
 449                {{0x99, 0x81}, 0x7f},
 450                {{0x99, 0x31}, 0x70},
 451
 452                {{0x98, 0x00}, 0x3f},
 453
 454                {{0x9f, 0x09}, 0x00},
 455
 456                {{0x9f, 0x0a}, 0x05},
 457
 458                {{0x9e, 0xd1}, 0xa1},
 459                {{0x99, 0x23}, 0x00},
 460
 461                {{0x9e, 0x74}, 0x80},
 462
 463                {{0x9f, 0x28}, 0x10},
 464
 465                {{0x9f, 0x35}, 0x14},
 466
 467                {{0x9f, 0x36}, 0x60},
 468
 469                {{0x9c, 0x31}, 0x00},
 470
 471                {{0x9c, 0x32}, 0xc8},
 472
 473                {{0x9c, 0x19}, 0x40},
 474
 475                {{0x9c, 0x1a}, 0x40},
 476
 477                {{0x9c, 0x0c}, 0x00},
 478
 479                {{0x9c, 0x0d}, 0x00},
 480
 481                {{0x9c, 0x12}, 0x00},
 482
 483                {{0x9c, 0x13}, 0x00},
 484
 485                {{0x98, 0xa2}, 0x0e},
 486
 487                {{0x98, 0x93}, 0x40},
 488
 489                {{0x98, 0x7d}, 0x02},
 490                {{0x98, 0x7e}, 0x00},
 491                {{0x9f, 0xc8}, 0x01},
 492        };
 493        struct hw_config *p = hw_config;
 494        int count = ARRAY_SIZE(hw_config);
 495        struct sk_buff *res_skb;
 496        u8 param[4];
 497        int r;
 498
 499        param[0] = 0;
 500        while (count--) {
 501                param[1] = p->adr[0];
 502                param[2] = p->adr[1];
 503                param[3] = p->value;
 504
 505                r = nfc_hci_send_cmd(hdev, PN544_SYS_MGMT_GATE, PN544_WRITE,
 506                                     param, 4, &res_skb);
 507                if (r < 0)
 508                        return r;
 509
 510                if (res_skb->len != 1) {
 511                        kfree_skb(res_skb);
 512                        return -EPROTO;
 513                }
 514
 515                if (res_skb->data[0] != p->value) {
 516                        kfree_skb(res_skb);
 517                        return -EIO;
 518                }
 519
 520                kfree_skb(res_skb);
 521
 522                p++;
 523        }
 524
 525        param[0] = NFC_HCI_UICC_HOST_ID;
 526        r = nfc_hci_set_param(hdev, NFC_HCI_ADMIN_GATE,
 527                              NFC_HCI_ADMIN_WHITELIST, param, 1);
 528        if (r < 0)
 529                return r;
 530
 531        param[0] = 0x3d;
 532        r = nfc_hci_set_param(hdev, PN544_SYS_MGMT_GATE,
 533                              PN544_SYS_MGMT_INFO_NOTIFICATION, param, 1);
 534        if (r < 0)
 535                return r;
 536
 537        param[0] = 0x0;
 538        r = nfc_hci_set_param(hdev, NFC_HCI_RF_READER_A_GATE,
 539                              PN544_RF_READER_A_AUTO_ACTIVATION, param, 1);
 540        if (r < 0)
 541                return r;
 542
 543        r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
 544                               NFC_HCI_EVT_END_OPERATION, NULL, 0);
 545        if (r < 0)
 546                return r;
 547
 548        param[0] = 0x1;
 549        r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE,
 550                              PN544_PL_NFCT_DEACTIVATED, param, 1);
 551        if (r < 0)
 552                return r;
 553
 554        param[0] = 0x0;
 555        r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE,
 556                              PN544_PL_RDPHASES, param, 1);
 557        if (r < 0)
 558                return r;
 559
 560        r = nfc_hci_get_param(hdev, NFC_HCI_ID_MGMT_GATE,
 561                              PN544_ID_MGMT_FULL_VERSION_SW, &skb);
 562        if (r < 0)
 563                return r;
 564
 565        if (skb->len != FULL_VERSION_LEN) {
 566                kfree_skb(skb);
 567                return -EINVAL;
 568        }
 569
 570        print_hex_dump(KERN_DEBUG, "FULL VERSION SOFTWARE INFO: ",
 571                       DUMP_PREFIX_NONE, 16, 1,
 572                       skb->data, FULL_VERSION_LEN, false);
 573
 574        kfree_skb(skb);
 575
 576        return 0;
 577}
 578
 579static int pn544_hci_xmit(struct nfc_shdlc *shdlc, struct sk_buff *skb)
 580{
 581        struct pn544_hci_info *info = nfc_shdlc_get_clientdata(shdlc);
 582        struct i2c_client *client = info->i2c_dev;
 583
 584        if (info->hard_fault != 0)
 585                return info->hard_fault;
 586
 587        return pn544_hci_i2c_write(client, skb->data, skb->len);
 588}
 589
 590static int pn544_hci_start_poll(struct nfc_shdlc *shdlc,
 591                                u32 im_protocols, u32 tm_protocols)
 592{
 593        struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
 594        u8 phases = 0;
 595        int r;
 596        u8 duration[2];
 597        u8 activated;
 598
 599        pr_info(DRIVER_DESC ": %s protocols 0x%x 0x%x\n",
 600                __func__, im_protocols, tm_protocols);
 601
 602        r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
 603                               NFC_HCI_EVT_END_OPERATION, NULL, 0);
 604        if (r < 0)
 605                return r;
 606
 607        duration[0] = 0x18;
 608        duration[1] = 0x6a;
 609        r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE,
 610                              PN544_PL_EMULATION, duration, 2);
 611        if (r < 0)
 612                return r;
 613
 614        activated = 0;
 615        r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE,
 616                              PN544_PL_NFCT_DEACTIVATED, &activated, 1);
 617        if (r < 0)
 618                return r;
 619
 620        if (im_protocols & (NFC_PROTO_ISO14443_MASK | NFC_PROTO_MIFARE_MASK |
 621                         NFC_PROTO_JEWEL_MASK))
 622                phases |= 1;            /* Type A */
 623        if (im_protocols & NFC_PROTO_FELICA_MASK) {
 624                phases |= (1 << 2);     /* Type F 212 */
 625                phases |= (1 << 3);     /* Type F 424 */
 626        }
 627
 628        phases |= (1 << 5);             /* NFC active */
 629
 630        r = nfc_hci_set_param(hdev, PN544_POLLING_LOOP_MGMT_GATE,
 631                              PN544_PL_RDPHASES, &phases, 1);
 632        if (r < 0)
 633                return r;
 634
 635        r = nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
 636                               NFC_HCI_EVT_READER_REQUESTED, NULL, 0);
 637        if (r < 0)
 638                nfc_hci_send_event(hdev, NFC_HCI_RF_READER_A_GATE,
 639                                   NFC_HCI_EVT_END_OPERATION, NULL, 0);
 640
 641        return r;
 642}
 643
 644static int pn544_hci_target_from_gate(struct nfc_shdlc *shdlc, u8 gate,
 645                                      struct ss="sref">nfc_hci_send_event2tivatedtarget5refclass="sref">r < 0)
 637  f">u8 ) {
nfc_hci_send_event2tivatedtarget5refskb" class="sref">sksupported    if (ode=r" class="sref">r;
r;
) {
nfc_hci_send_event2tivatedtarget5refskb" class="sref">sksupported    if (r;
 503      ci_send_event2tivatedtarget5refskb" class="sref">sksens_r &activated = 0;
r;
) {
                        return -EPROTO;
 642}
 598
 576        return 0;
 642}
 601
 644static int completee" classdisco01"mp;(struct nfc_shdlc * 601
shdlc, u8 gate,
 544                                                struct ss="sref">nfc_hci_send_event2tivatedtarget5refclass="sref">r < 0)
 593        struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
shdlc, struct sk_uid     EPROTO;
 595        int activated = 0;
 569
 620  ci_send_event2tivatedtarget5refskb" class="sref">sksupported    if (im_protocols & NFC_PROTO_FELICA_MASK) {
 620  ci_send_event2tivatedtarget5refskb" class="sref">sk->im_protocolssk->) {
 57">im_protocolssk->r < 0)
                        return -EPROTO;
 634
 505                r = nfc_hci_send_cmd(hdev, NFC_HCI_RF_READER_A_GATE,
 636      "L505"> 505      _MGMT_    PN544E_NEXde=NFC_HCI_ADMIN_MGMT_    PN544E_NEXd>NFC_HCI_RF_READER_A_GATE,
 527     72"> 57">im_protocolssk->ci_send_event2tivatedtarget5refskb" class="sref">sk->, shdlc);
 620  ci_send_event2tivatedtarget5refskb" class="sref">sksupported    if (im_protocols & NFC_PROTO_FELICA_MASK) {
nfc_ha>        r = nfc_hci_get_param(          ,
 610       "L505"> 505      _MGMT_" class"+code=NFC_HCI_UI_MGMT_" class"+="sref">PN544_PL_RDPHASESshdlc);
 620        if (r < 0)
 577777e="L641"> 641        return r;
 583
 620  uid     skb->) {
 505      a>        kfreuid     shdlc);
 636                        return -EPROTO;
 642}
 598
nfc_ha>        r = nfc_hci_send_cmd(          ,
 610       "L505> 505      _MGMT_    PN544E_NEXde=NFC_HCI_ADMIN_MGMT_    PN544E_NEXd>NFC_HCI_RF_READER_A_GATE,
 591       "L505> 505      uid     skb->uid     skb->shdlc);
nfc_ha>        kfreuid     shdlc);
 620  ci_send_event2tivatedtarget5refskb" class="sref">sksupported    if (im_protocols & NFNFC_PROTO_FELICA_MASK) {
lt;< 5);            comment">/* NFC active */
 quire some kind of continuecomment">/* NFC active */
/* NFC active */
/* NFC active */
 620  ci_send_event2tivatedtarget5refskb" class="sref">sksens_r & |= (1 << 3);     /* NFC active */
 639nfc_ha>        r = nfc_hci_send_cmd(hdev, NFC_HCI_RF_READER_A_GATE,
 639nfc_hACTIVATION" class=CMDfCONTINUEde=PN544_RF_READER_A_AUTO_ACTIVATION" class=CMDfCONTINUEde=PN544_RF>NFC_HCI_RF_READER_A_GATE,
 631                    TION, , shdlc);
 642}
 583
 641        return r;
 642}
 606
 641     " classCMDf"UTH_KEY_A  return  606
 641     " classCMDf"UTH_KEY_B  return  606
 641     " classCMDfH" cla  return  606
 641     " classUID href="+code=FULL_V" classUID hres="line" name=4ine" name="L606"> 606
 641     " classKEY_href="+code=FULL_V" classKEY_hres="line" name=6ine" name="L606"> 606
 641     " classCMDfhref="+code=FULL_V" classCMDfhres="line" name=12ine" name="L606"> 606
/* NFC active */
/* NFC active */
/* NFC active */
/* NFC active */
/* NFC active */
 644static int +cod_exchangef="+code=FULL_Vtatic int +cod_exchanges="srhci_target_from_gate(struct nfc_shdlc * 601
 639                                   struct ss="sref">nfc_hci_send_event2tivatedtarget5refcine" name="L601"> 601
 610       "L5 class="sref">shdlc, struct sk_buff * 601
 621       "L5 class="sref">shdlc, struct sk_r &      601
 592{
 593        struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev(shdlc);
 595        int r;
 575
 596        pr_info(DRIVER_DESC  600                 575
 620  ci_send_event2tivatedtarget5refskb" class="sref">skass=readerode=pn544_hci_targetass=readerode=pshdlc" class="sref">shdlc);
 598
 637  ci_send_event2tivatedtarget5refskb" class="sref">skass=readerode=pn544_hci_targetass=readerode=pshdlcFC_PROTO_FELICA_MASK) {
, NFC:_PROTO_FELICA_MASK) {
 620  ci_send_event2tivatedtarget5refskb" class="sref">sksupported    if (im_protocols & NFC_PROTO_FELICA_MASK) {
 577777>lt;< 5);            comment">/* NFC active */
 621       "L5* It seems that an>
< isme=ve tDES key and UIDsforcomment">/* NFC active */
 621       "L5* " clas authen" nvaion     ands.comment">/* NFC active */
/* NFC active */
 636 565        if (skb->h" classCMDfhref="+code=FULL_V" classCMDfhres="li="sre="sre_PROTO_FELICA_MASK) {
 527   L565"> 565        if (skb->h" classCMDf"UTH_KEY_A  return  565        if (skb->h" classCMDf"UTH_KEY_B  return  639       ass="sref">kfreudlc,  641     " classUID href="+code=FULL_V" classUID hres="lass="sref">duration[2];
 610       ass="sref">kfreudlc, nfc_hcib->h      if (skb-> 641     " classCMDfH" cla  return duration[2];
 601
 577777>       ass="sref">kfrememcpy  return kfreuidf="+code=nfc_hcuiee=daf">PN544_PL_EMULAT-> 641     " classKEY_href="+code=FULL_V" classKEY_hres="lcine" name="L575"> 575
 641     " classUID href="+code=FULL_V" classUID hres="lc" class="sref">shdlc);
 544       ass="sref">kfrememmovpn544_hci_targetmemmovpb" class="sref">kfreT-> 641     " classUID href="+code=FULL_V" classUID hres="lf">PN544_PL_EMULAT-> 575
 645             """> 641     " classKEY_href="+code=FULL_V" classKEY_hres="lc" class="sref">shdlc);
 636      "ass="sref">kfrememcpy  return kfreb->uidf="+code=nfc_hcuiee=daf">PN544_PL_EMULA" classUID href="+code=FULL_V" classUID hres="lc" class="sref">shdlc);
 527 642}
 598
 641     ">r = nfc_hci_send_cmd(ci_send_event2tivatedtarget5refskb" class="sref">skass=readerode=pn544_hci_targetass=readerode=pshdlcine" name="L575"> 575
 636      "ass="sref">kfreACTIVA" classCMD_READER_A_AUTO_ACTIVA" classCMDshdlcine" name="L575"> 575
 591       "L505      "ass="sref">kfreient, skb->data, skb->r &     shdlc);
shdlc);
shdlc);
) {
sk_buf_pusha, nfc_shdlc_get_hciuff *activated = 0;
sk_buf_pusha, nfc_shdlc_get_hciuff *activated = 0;
 627
 638      a>        r = nfc_hci_send_cmd(ci_send_event2tivatedtarget5refskb" class="sref">skass=readerode=pn544_hci_targetass=readerode=pshdlcine" name="L575"> 575
 639          5"> 505      _MGMT_" classRAW44_POLLING_LOOP_MGMT_" classRAWshdlcine" name="L575"> 575
 610       "L505> 505      ient, skb->data, skb->r &     shdlc);
 620        if ( 601
 577777>ass="sref">sk_buf_pulla, sk_r &     phases, 1);
 641        return r;
) {
 605             ">r = nfc_hci_send_cmd(ci_send_event2tivatedtarget5refskb" class="sref">skass=readerode=pn544_hci_targetass=readerode=pshdlcine" name="L575"> 575
 636      "L505"777>ass="sref">sk__MGMT_" clasRAWsCMD_READER_A_AUTO_ACTIVA" clasRAWsCMDshdlcine" name="L575"> 575
 527     72"> 57777>ass="sref">sk_buft, skb->data, skb->r &     shdlc);
) {
shdlc);
 642}
 642}
 642}
 644static int check_pr &encef="+code=FULL_Vtatic int check_pr &ences="srhci_target_from_gate(struct nfc_shdlc * 601
 544                                   struct ss="sref">nfc_hci_send_event2tivatedtarget5refclass="sref">r < 0)
 593        struct nfc_hci_dev *hdev = nfc_shdlc_get_hci_dev( 627
 605             ">r = nfc_hci_send_cmd(ci_send_event2tivatedtarget5refskb" class="sref">skass=readerode=pn544_hci_targetass=readerode=pshdlcine" name="L575"> 575
     72"> 57777>ass="sref">sk__MGMT_     575
 610       >ass="sref">sk_TION, , shdlc);
 642}
 642}
(struct_opa href="+code=ima>(struct_opa+code=u8" class="srea>}
) {
htatic int op-> 575
htatic int clospn544_hci_targettatic int clospshdlcine" name="L575"> 575
htatic int ready  return  575
htatic int xmind_event2tivatedtatic int xminshdlcine" name="L575"> 575
htatic int inert_polla,  575
pn544ev" class="sref">htatic int pn544cine" name="L575"> 575
htatic int completee" classdisco01"mp; 575
htatic int +cod_exchangef="+code=FULL_Vtatic int +cod_exchanges="scine" name="L575"> 575
htatic int check_pr &encef="+code=FULL_Vtatic int check_pr &ences="scine" name="L575"> 575
shdlc);
 634
 644s_="srinind_event2tivated_="srinin+code=u8" class="srea>}
nfc_hciclief="+code=nfc_hci_clief= clacine" name="L575"> 575
 636      "L505"constahci_target_from_gatenfc_hciidf="+code=nfc_hcid5refclass="sref">r < 0)
nfc_hcii      shdlc);
(splatform_b->nfc_hcipb->shdlc);
 595        int activated = 0;
 595  u/pn544_hci.nfc_hcu3ss="li="sref">nfc_hcip  if (activated = 0;
 593        strucinin_b->nfc_hciinin_b->activated = 0;
 583
PN544_PL_RDPHASESskbcmd(DRIVER_DESC  600                shdlc);
PN544_PL_RDPHASESskbcmd(DRIVER_DESC  600      clief="+code=nfc_hci_clief= claskb" class="sref">skirq>->shdlc);
 606
nfc_hci_senclief="+code=nfc_hci_clief= claskb" class="sref">skadapte      int I2C_FUNC_I2C     int ) {
 638      +ev_er      int PN544_PL_RDPHASESskbcmd(DRIVER_DESC shdlc);
activated = 0;
 642}
 601
hkzallov(GFP_KERNEN, shdlc);
) {
 638      +ev_er      int PN544_PL_RDPHASESskbcmd(="sref">DRIVER_DESC shdlc);
 595        int activated = 0;
 595  er      _allov(activated = 0;
 642}
 569
ski2c "srf="+code=nfc_hci2c "sr claev" class="sref">hclief="+code=nfc_hci_clief= cla="sref">activated = 0;
 595  i      skine"ef="+code=FULL_Vine"e claev" class="sref">h_MGMT_ST_COLD_READER_A_AUTO_ACTIVAST_COLD cla="sref">activated = 0;
PN544_PL_RDPHASESski   _lovk   shdlc);
ski2c set clief=b->nfc_hci_senclief="+code=nfc_hci_clief= claev" class="sref">i      shdlc);
 634
hclief="+code=nfc_hci_clief= claskb" class="sref">skbcmd(shdlc);
 620  pb->hTION,  620  +ev_er      int PN544_PL_RDPHASESskbcmd(DRIVER_DESC shdlc);
 638      a>        shdlc);
 595  er  pb->shdlc);
 642}
 601
 620  pb->sk> quest_r &ourc &hTION,  620  +ev_er      int PN544_PL_RDPHASESskbcmd(DRIVER_DESC  quest_r &ourc &() missingotocols 0x%c" class="sref">shdlc);
 638      a>        shdlc);
 595  er  pb->shdlc);
 642}
 627
 638      a>         620  pb->sk> quest_r &ourc &nfc_hci_senclief="+code=nfc_hci_clief= clac" class="sref">shdlc);
 620        if ( 620  +ev_er      int PN544_PL_RDPHASESskbcmd(DRIVER_DESC shdlc);
 595  er  pb->shdlc);
 642}
 583
skgpio_-> 620  pb->sklassgpioa>->nfc_hci_senIFARGPIO_ENABL544_POLLING_LOOPIFARGPIO_ENABL5 clac" class="sref">shdlc);
skgpio_fwa>-> 620  pb->sklassgpioa>->nfc_hci_senIFARGPIO_FW_RESEde=NFC_HCI_ADMINIFARGPIO_FW_RESEd clac" class="sref">shdlc);
 596skgpio_irq>-> 620  pb->sklassgpioa>->nfc_hci_senIFARGPIO_IRQe=NFC_HCI_ADMINIFARGPIO_IRQ clac" class="sref">shdlc);
 627
 638      tatic int platform_inind_event2tivatedtatic int platform_inin claref">nfc_hci_seni      shdlc);
 569
         620  > quest_threaded_irq>->nfc_hci_senclief="+code=nfc_hci_clief= claskb" class="sref">skirq>->,  591       "" class="sref">IRQF_TRIGGER_RISING     int ) {
 591       "" class="sref">i      shdlc);
) {
 638      +ev_er      int PN544_PL_RDPHASESskbcmd(DRIVER_DESC shdlc);
 595  er  rti>->shdlc);
 642}
 627
 638      inin_b->p_couf="+code=nfc_hci_f">p_couf=="+code620"> 620  ARRAY_SIZ544_POLLING_LOOPARRAY_SIZ5s="sref">nfc_hci_sen/a>
pa href="+code=ima>}
pa claN" class="sref">shdlc);
 569
kfreinin_b->pa href="+code=imf">pa claHCI_EVT_END_OPERAdatic f">pa href="+code=ima>}
pa cla, hizeofref">nfc_hci_sen/a>
pa href="+code=ima>}
pa claNN" class="sref">shdlc);
 601
lt;< 5);            comment">/* NFC active */
 6* TODO: Sessioners must include the +tive 3" id + soid bus addrcomment">/* NFC active */
 6* pe *istent info if"discriminate 2ersen" nvl chipae=mment">/* NFC active */
/* NFC active */
 596kfreinin_b->DRIVER_DESC 
shdlc);
 627
 638      t  if ( 620  IFARE_MASK" clas="+code=NFC_PROTO_MIFARE_MASK" clas="+c="+coFC_PROTO_MIFARE_MASK |
 638      /a> & oFC_PROTO_MIFARE_MASK |
 61> 638      /a> & " class="+code=NFC_PROTO_MIFARE_MASK" class="+cef">oFC_PROTO_MIFARE_MASK |
 59> 638      /a> & ISO14443s="+code=NFC_PROTO_MIFARE_MASKISO14443s="+cef">oFC_PROTO_MIFARE_MASK |
 59> 638      /a> & ISO14443sBs="+code=NFC_PROTO_MIFARE_MASKISO14443sBs="+cef">oFC_PROTO_MIFARE_MASK |
 638      /a> & /a> DEPs="+code=NFC_PROTO_MIFARE_MASK/a> DEPs="+c cla" class="sref">shdlc);
 634
ski_dev(hdev = allovate(PN544_PL_RDPHASES
 636      "L505"777 ">PN544_PL_RDPHASES->) {
 527     72"> 57777CI_EVT_END_OPERAACTIVACMDSfH" cROOMd( 57777CI_EVT_END_OPERAACTIVAA_GALLCs="X_PAYLOAD_READER_A_AUTO_ACTIVAA_GALLCs="X_PAYLOAD="+ce_PROTO_FELICA_MASK) {
     72"> 57777"> 57777CI_EVT_END_OPERA+ev_" id     int PN544_PL_RDPHASESskbcmd(shdlc);
ski_dev( 638      +ev_er      int PN544_PL_RDPHASESskbcmd(DRIVER_DESC shdlc);
 638      a>        activated = 0;
 595  er  allovi_dev(activated = 0;
 642}
 575
 596 = set clief=b->nfc_hci_seni      ski_dev(i      shdlc);
 627
 605activated = 0;
 569
 595  er  allovi_dev() {
 595  free_irq>->nfc_hci_senclief="+code=nfc_hci_clief= claskb" class="sref">skirq>->shdlc);
 642}
 595  er  rti>-> 620  pb->skfree_r &ourc &hTION,  620  pb->skfree_r &ourc &shdlc);
 606
 595  er  pb-> 638      kfree>->nfc_hci_seni      shdlc);
 569
 595  er      _allov() {
 641        return r;
 642}
 583
 641     _="srexind_event2tivated_="srexins="lime="L644"> 644static int removpn544_hci_targettatic int removp clarhci_target_from_gatenfc_hciclief="+code=nfc_hci_clief= clac_PROTO_FELICA_MASK) {
 593     tatic int        nfc_hcii      hi2c get clief=b->nfc_hci_senclief="+code=nfc_hci_clief= clac" class="sref">shdlc);
(splatform_b->nfc_hcipb->hclief="+code=nfc_hci_clief= claskb" class="sref">skbcmd(shdlc);
 598
 638      +ev_dbgf="+code=FULL_V+ev_dbgs="sr">PN544_PL_RDPHASESskbcmd(DRIVER_DESC  600                shdlc);
shdlc);
 595  dev = free>->nfc_hci_seni      ski_dev(shdlc);
 642}
nfc_hci_seni      skine"ef="+code=FULL_Vine"e clae!v" class="sref">h_MGMT_ST_COLD_READER_A_AUTO_ACTIVAST_COLD clacFC_PROTO_FELICA_MASK) {
 620  pb->skdisabled(20"> 620  pb->skdisabled(shdlc);
 642}
 627
 638      free_irq>->nfc_hci_senclief="+code=nfc_hci_clief= claskb" class="sref">skirq>->shdlc);
 620  pb->skfree_r &ourc &) {
 620  pb->skfree_r &ourc &shdlc);
 601
nfc_hci_seni      shdlc);
 583
 605activated = 0;
 642}
 606
-> 593     tatic int "L606">->) {
->) {
h_MGMT_A_GARIVER_DNAM544_POLLING_LOOP_MGMT_A_GARIVER_DNAM5e=hde_PROTO_FELICA_MASK) {
 }e_PROTO_FELICA_MASK) {
htatic int probef="+code=FULL_Vtatic int probes="se_PROTO_FELICA_MASK) {
htatic int id_tabled() {
h_="srexin_pd_event2tivated_="srexin_p claref">nfc_hci_sentatic int removpn544_hci_targettatic int removp cla)e_PROTO_FELICA_MASK) {
shdlc);
 575
 644s_=inind_event2tivated_=inin+code=u8" class="srea>}
) {
 595        int shdlc);
 569
nfc_hci_senRIVER_DDESC     int DRIVER_DESC  600                shdlc);
 601
 620  i2c add "L606">->PN544_PL_RDPHASES->shdlc);
) {
 638      pr=er      int nfc_hci_sen_MGMT_A_GARIVER_DNAM544_POLLING_LOOP_MGMT_A_GARIVER_DNAM5e=hde=="sref">DRIVER_DESC shdlc);
 641        return r;
 642}
 627
 605activated = 0;
 642}
shdlc);
 600        exind_event2tivated_=exins="li44_PL_RDPHASES) {
->PN544_PL_RDPHASES->shdlc);
 642}
 575
nfc_hci_sentatic int inind_event2tivatedtatic int inin clac" class="sref">shdlc);
 595  module_exind_event2tivatedmodule_exin claref">nfc_hci_sentatic int exind_event2tivatedtatic int exin clac" class="sref">shdlc);
 598
nfc_hci_senMODULE_LICENS544_POLLING_LOOPMODULE_LICENS5 clare="sref">DRIVER_DESC shdlc);
 595  MODULE_DESCRIPTION44_POLLING_LOOPMODULE_DESCRIPTION claref">nfc_hci_senRIVER_DDESC     int shdlc);
LXR     unitys="s, this experi    al >shdion by class="srmailto:lx @c#Lux.no">lx @c#Lux.noe=hd.
lx .c#Lux.no kindly hosted by class="srhttp://www.redpill-c#Lpro.no">Redpill L#Lpro ASs="s, provide 3of L#Lux"consultDES and operaaions serrices since 1995.