linux/drivers/nfc/pn544/i2c.c

// SPDX-License-Identifier: GPL-2.0-only
/*
 * I2C Link Layer for PN544 HCI based Driver
 *
 * Copyright (C) 2012  Intel Corporation. All rights reserved.
 */

#define pr_fmt(fmt)

#include <linux/crc-ccitt.h>
#include <linux/module.h>
#include <linux/i2c.h>
#include <linux/acpi.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/nfc.h>
#include <linux/firmware.h>
#include <linux/gpio/consumer.h>

#include <linux/unaligned.h>

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

#include "pn544.h"

#define PN544_I2C_FRAME_HEADROOM
#define PN544_I2C_FRAME_TAILROOM

/* GPIO names */
#define PN544_GPIO_NAME_IRQ
#define PN544_GPIO_NAME_FW
#define PN544_GPIO_NAME_EN

/* framing in HCI mode */
#define PN544_HCI_I2C_LLC_LEN
#define PN544_HCI_I2C_LLC_CRC
#define PN544_HCI_I2C_LLC_LEN_CRC
#define PN544_HCI_I2C_LLC_MIN_SIZE
#define PN544_HCI_I2C_LLC_MAX_PAYLOAD
#define PN544_HCI_I2C_LLC_MAX_SIZE

static const struct i2c_device_id pn544_hci_i2c_id_table[] =;

MODULE_DEVICE_TABLE(i2c, pn544_hci_i2c_id_table);

static const struct acpi_device_id pn544_hci_i2c_acpi_match[] __maybe_unused =;

MODULE_DEVICE_TABLE(acpi, pn544_hci_i2c_acpi_match);

#define PN544_HCI_I2C_DRIVER_NAME

/*
 * Exposed through the 4 most significant bytes
 * from the HCI SW_VERSION first byte, a.k.a.
 * SW RomLib.
 */
#define PN544_HW_VARIANT_C2
#define PN544_HW_VARIANT_C3

#define PN544_FW_CMD_RESET
#define PN544_FW_CMD_WRITE
#define PN544_FW_CMD_CHECK
#define PN544_FW_CMD_SECURE_WRITE
#define PN544_FW_CMD_SECURE_CHUNK_WRITE

struct pn544_i2c_fw_frame_write {} __packed;

struct pn544_i2c_fw_frame_check {} __packed;

struct pn544_i2c_fw_frame_response {} __packed;

struct pn544_i2c_fw_blob {};

struct pn544_i2c_fw_secure_frame {} __packed;

struct pn544_i2c_fw_secure_blob {};

#define PN544_FW_CMD_RESULT_TIMEOUT
#define PN544_FW_CMD_RESULT_BAD_CRC
#define PN544_FW_CMD_RESULT_ACCESS_DENIED
#define PN544_FW_CMD_RESULT_PROTOCOL_ERROR
#define PN544_FW_CMD_RESULT_INVALID_PARAMETER
#define PN544_FW_CMD_RESULT_UNSUPPORTED_COMMAND
#define PN544_FW_CMD_RESULT_INVALID_LENGTH
#define PN544_FW_CMD_RESULT_CRYPTOGRAPHIC_ERROR
#define PN544_FW_CMD_RESULT_VERSION_CONDITIONS_ERROR
#define PN544_FW_CMD_RESULT_MEMORY_ERROR
#define PN544_FW_CMD_RESULT_CHUNK_OK
#define PN544_FW_CMD_RESULT_WRITE_FAILED
#define PN544_FW_CMD_RESULT_COMMAND_REJECTED
#define PN544_FW_CMD_RESULT_CHUNK_ERROR

#define PN544_FW_WRITE_BUFFER_MAX_LEN
#define PN544_FW_I2C_MAX_PAYLOAD
#define PN544_FW_I2C_WRITE_FRAME_HEADER_LEN
#define PN544_FW_I2C_WRITE_DATA_MAX_LEN
#define PN544_FW_SECURE_CHUNK_WRITE_HEADER_LEN
#define PN544_FW_SECURE_CHUNK_WRITE_DATA_MAX_LEN
#define PN544_FW_SECURE_FRAME_HEADER_LEN
#define PN544_FW_SECURE_BLOB_HEADER_LEN

#define FW_WORK_STATE_IDLE
#define FW_WORK_STATE_START
#define FW_WORK_STATE_WAIT_WRITE_ANSWER
#define FW_WORK_STATE_WAIT_CHECK_ANSWER
#define FW_WORK_STATE_WAIT_SECURE_WRITE_ANSWER

struct pn544_i2c_phy {};

#define I2C_DUMP_SKB(info, skb)

static void pn544_hci_i2c_platform_init(struct pn544_i2c_phy *phy)
{}

static void pn544_hci_i2c_enable_mode(struct pn544_i2c_phy *phy, int run_mode)
{}

static int pn544_hci_i2c_enable(void *phy_id)
{}

static void pn544_hci_i2c_disable(void *phy_id)
{}

static void pn544_hci_i2c_add_len_crc(struct sk_buff *skb)
{}

static void pn544_hci_i2c_remove_len_crc(struct sk_buff *skb)
{}

/*
 * Writing a frame must not return the number of written bytes.
 * It must return either zero for success, or <0 for error.
 * In addition, it must not alter the skb
 */
static int pn544_hci_i2c_write(void *phy_id, struct sk_buff *skb)
{}

static int check_crc(u8 *buf, int buflen)
{}

/*
 * Reads an shdlc frame and returns it in a newly allocated sk_buff. Guarantees
 * that i2c bus will be flushed and that next read will start on a new frame.
 * returned skb contains only LLC header and payload.
 * returns:
 * -EREMOTEIO : i2c read error (fatal)
 * -EBADMSG : frame was incorrect and discarded
 * -ENOMEM : cannot allocate skb, frame dropped
 */
static int pn544_hci_i2c_read(struct pn544_i2c_phy *phy, struct sk_buff **skb)
{}

static int pn544_hci_i2c_fw_read_status(struct pn544_i2c_phy *phy)
{}

/*
 * Reads an shdlc frame from the chip. This is not as straightforward as it
 * seems. There are cases where we could loose the frame start synchronization.
 * The frame format is len-data-crc, and corruption can occur anywhere while
 * transiting on i2c bus, such that we could read an invalid len.
 * In order to recover synchronization with the next frame, we must be sure
 * to read the real amount of data without using the len byte. We do this by
 * assuming the following:
 * - the chip will always present only one single complete frame on the bus
 *   before triggering the interrupt
 * - the chip will not present a new frame until we have completely read
 *   the previous one (or until we have handled the interrupt).
 * The tricky case is when we read a corrupted len that is less than the real
 * len. We must detect this here in order to determine that we need to flush
 * the bus. This is the reason why we check the crc here.
 */
static irqreturn_t pn544_hci_i2c_irq_thread_fn(int irq, void *phy_id)
{}

static const struct nfc_phy_ops i2c_phy_ops =;

static int pn544_hci_i2c_fw_download(void *phy_id, const char *firmware_name,
					u8 hw_variant)
{}

static void pn544_hci_i2c_fw_work_complete(struct pn544_i2c_phy *phy,
					   int result)
{}

static int pn544_hci_i2c_fw_write_cmd(struct i2c_client *client, u32 dest_addr,
				      const u8 *data, u16 datalen)
{}

static int pn544_hci_i2c_fw_check_cmd(struct i2c_client *client, u32 start_addr,
				      const u8 *data, u16 datalen)
{}

static int pn544_hci_i2c_fw_write_chunk(struct pn544_i2c_phy *phy)
{}

static int pn544_hci_i2c_fw_secure_write_frame_cmd(struct pn544_i2c_phy *phy,
					const u8 *data, u16 datalen)
{}

static int pn544_hci_i2c_fw_secure_write_frame(struct pn544_i2c_phy *phy)
{}

static void pn544_hci_i2c_fw_work(struct work_struct *work)
{}

static const struct acpi_gpio_params enable_gpios =;
static const struct acpi_gpio_params firmware_gpios =;

static const struct acpi_gpio_mapping acpi_pn544_gpios[] =;

static int pn544_hci_i2c_probe(struct i2c_client *client)
{}

static void pn544_hci_i2c_remove(struct i2c_client *client)
{}

static const struct of_device_id of_pn544_i2c_match[] __maybe_unused =;
MODULE_DEVICE_TABLE(of, of_pn544_i2c_match);

static struct i2c_driver pn544_hci_i2c_driver =;

module_i2c_driver();

MODULE_LICENSE();
MODULE_DESCRIPTION();