/*
* Sony NFC Port-100 Series driver
* Copyright (c) 2013, Intel Corporation.
*
* Partly based/Inspired by Stephen Tiedemann's nfcpy
*
* 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 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.
*
*/
#include <linux/module.h>
#include <linux/usb.h>
#include <net/nfc/digital.h>
#define VERSION "0.1"
#define SONY_VENDOR_ID 0x054c
#define RCS380_PRODUCT_ID 0x06c1
#define PORT100_PROTOCOLS (NFC_PROTO_JEWEL_MASK | \
NFC_PROTO_MIFARE_MASK | \
NFC_PROTO_FELICA_MASK | \
NFC_PROTO_NFC_DEP_MASK | \
NFC_PROTO_ISO14443_MASK | \
NFC_PROTO_ISO14443_B_MASK)
#define PORT100_CAPABILITIES (NFC_DIGITAL_DRV_CAPS_IN_CRC | \
NFC_DIGITAL_DRV_CAPS_TG_CRC)
/* Standard port100 frame definitions */
#define PORT100_FRAME_HEADER_LEN (sizeof(struct port100_frame) \
+ 2) /* data[0] CC, data[1] SCC */
#define PORT100_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/
#define PORT100_COMM_RF_HEAD_MAX_LEN (sizeof(struct port100_tg_comm_rf_cmd))
/*
* Max extended frame payload len, excluding CC and SCC
* which are already in PORT100_FRAME_HEADER_LEN.
*/
#define PORT100_FRAME_MAX_PAYLOAD_LEN 1001
#define PORT100_FRAME_ACK_SIZE 6 /* Preamble (1), SoPC (2), ACK Code (2),
Postamble (1) */
static u8 ack_frame[PORT100_FRAME_ACK_SIZE] = {
0x00, 0x00, 0xff, 0x00, 0xff, 0x00
};
#define PORT100_FRAME_CHECKSUM(f) (f->data[le16_to_cpu(f->datalen)])
#define PORT100_FRAME_POSTAMBLE(f) (f->data[le16_to_cpu(f->datalen) + 1])
/* start of frame */
#define PORT100_FRAME_SOF 0x00FF
#define PORT100_FRAME_EXT 0xFFFF
#define PORT100_FRAME_ACK 0x00FF
/* Port-100 command: in or out */
#define PORT100_FRAME_DIRECTION(f) (f->data[0]) /* CC */
#define PORT100_FRAME_DIR_OUT 0xD6
#define PORT100_FRAME_DIR_IN 0xD7
/* Port-100 sub-command */
#define PORT100_FRAME_CMD(f) (f->data[1]) /* SCC */
#define PORT100_CMD_GET_FIRMWARE_VERSION 0x20
#define PORT100_CMD_GET_COMMAND_TYPE 0x28
#define PORT100_CMD_SET_COMMAND_TYPE 0x2A
#define PORT100_CMD_IN_SET_RF 0x00
#define PORT100_CMD_IN_SET_PROTOCOL 0x02
#define PORT100_CMD_IN_COMM_RF 0x04
#define PORT100_CMD_TG_SET_RF 0x40
#define PORT100_CMD_TG_SET_PROTOCOL 0x42
#define PORT100_CMD_TG_SET_RF_OFF 0x46
#define PORT100_CMD_TG_COMM_RF 0x48
#define PORT100_CMD_SWITCH_RF 0x06
#define PORT100_CMD_RESPONSE(cmd) (cmd + 1)
#define PORT100_CMD_TYPE_IS_SUPPORTED(mask, cmd_type) \
((mask) & (0x01 << (cmd_type)))
#define PORT100_CMD_TYPE_0 0
#define PORT100_CMD_TYPE_1 1
#define PORT100_CMD_STATUS_OK 0x00
#define PORT100_CMD_STATUS_TIMEOUT 0x80
#define PORT100_MDAA_TGT_HAS_BEEN_ACTIVATED_MASK 0x01
#define PORT100_MDAA_TGT_WAS_ACTIVATED_MASK 0x02
struct port100;
typedef void (*port100_send_async_complete_t)(struct port100 *dev, void *arg,
struct sk_buff *resp);
/**
* Setting sets structure for in_set_rf command
*
* @in_*_set_number: Represent the entry indexes in the port-100 RF Base Table.
* This table contains multiple RF setting sets required for RF
* communication.
*
* @in_*_comm_type: Theses fields set the communication type to be used.
*/
struct port100_in_rf_setting {
u8 in_send_set_number;
u8 in_send_comm_type;
u8 in_recv_set_number;
u8 in_recv_comm_type;
} __pa
|