18c2ecf20Sopenharmony_ci/**
28c2ecf20Sopenharmony_ci * Marvell NFC driver: Firmware downloader
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright (C) 2015, Marvell International Ltd.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * This software file (the "File") is distributed by Marvell International
78c2ecf20Sopenharmony_ci * Ltd. under the terms of the GNU General Public License Version 2, June 1991
88c2ecf20Sopenharmony_ci * (the "License").  You may use, redistribute and/or modify this File in
98c2ecf20Sopenharmony_ci * accordance with the terms and conditions of the License, a copy of which
108c2ecf20Sopenharmony_ci * is available on the worldwide web at
118c2ecf20Sopenharmony_ci * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
128c2ecf20Sopenharmony_ci *
138c2ecf20Sopenharmony_ci * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
148c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
158c2ecf20Sopenharmony_ci * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
168c2ecf20Sopenharmony_ci * this warranty disclaimer.
178c2ecf20Sopenharmony_ci **/
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#ifndef __NFCMRVL_FW_DNLD_H__
208c2ecf20Sopenharmony_ci#define __NFCMRVL_FW_DNLD_H__
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#include <linux/workqueue.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#define NFCMRVL_FW_MAGIC		0x88888888
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci#define NCI_OP_PROP_BOOT_CMD		0x3A
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci#define NCI_CORE_LC_PROP_FW_DL		0xFD
298c2ecf20Sopenharmony_ci#define NCI_CORE_LC_CONNID_PROP_FW_DL	0x02
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define HELPER_CMD_ENTRY_POINT		0x04
328c2ecf20Sopenharmony_ci#define HELPER_CMD_PACKET_FORMAT	0xA5
338c2ecf20Sopenharmony_ci#define HELPER_ACK_PACKET_FORMAT	0x5A
348c2ecf20Sopenharmony_ci#define HELPER_RETRY_REQUESTED		(1 << 15)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct nfcmrvl_private;
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistruct nfcmrvl_fw_uart_config {
398c2ecf20Sopenharmony_ci	uint8_t flow_control;
408c2ecf20Sopenharmony_ci	uint32_t baudrate;
418c2ecf20Sopenharmony_ci} __packed;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_cistruct nfcmrvl_fw_i2c_config {
448c2ecf20Sopenharmony_ci	uint32_t clk;
458c2ecf20Sopenharmony_ci} __packed;
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_cistruct nfcmrvl_fw_spi_config {
488c2ecf20Sopenharmony_ci	uint32_t clk;
498c2ecf20Sopenharmony_ci} __packed;
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistruct nfcmrvl_fw_binary_config {
528c2ecf20Sopenharmony_ci	uint32_t offset;
538c2ecf20Sopenharmony_ci	union {
548c2ecf20Sopenharmony_ci		void *config;
558c2ecf20Sopenharmony_ci		struct nfcmrvl_fw_uart_config uart;
568c2ecf20Sopenharmony_ci		struct nfcmrvl_fw_i2c_config i2c;
578c2ecf20Sopenharmony_ci		struct nfcmrvl_fw_spi_config spi;
588c2ecf20Sopenharmony_ci		uint8_t reserved[64];
598c2ecf20Sopenharmony_ci	};
608c2ecf20Sopenharmony_ci} __packed;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct nfcmrvl_fw {
638c2ecf20Sopenharmony_ci	uint32_t magic;
648c2ecf20Sopenharmony_ci	uint32_t ref_clock;
658c2ecf20Sopenharmony_ci	uint32_t phy;
668c2ecf20Sopenharmony_ci	struct nfcmrvl_fw_binary_config bootrom;
678c2ecf20Sopenharmony_ci	struct nfcmrvl_fw_binary_config helper;
688c2ecf20Sopenharmony_ci	struct nfcmrvl_fw_binary_config firmware;
698c2ecf20Sopenharmony_ci	uint8_t reserved[64];
708c2ecf20Sopenharmony_ci} __packed;
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistruct nfcmrvl_fw_dnld {
738c2ecf20Sopenharmony_ci	char name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
748c2ecf20Sopenharmony_ci	const struct firmware *fw;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	const struct nfcmrvl_fw *header;
778c2ecf20Sopenharmony_ci	const struct nfcmrvl_fw_binary_config *binary_config;
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	int state;
808c2ecf20Sopenharmony_ci	int substate;
818c2ecf20Sopenharmony_ci	int offset;
828c2ecf20Sopenharmony_ci	int chunk_len;
838c2ecf20Sopenharmony_ci
848c2ecf20Sopenharmony_ci	struct workqueue_struct	*rx_wq;
858c2ecf20Sopenharmony_ci	struct work_struct rx_work;
868c2ecf20Sopenharmony_ci	struct sk_buff_head rx_q;
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	struct timer_list timer;
898c2ecf20Sopenharmony_ci};
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ciint nfcmrvl_fw_dnld_init(struct nfcmrvl_private *priv);
928c2ecf20Sopenharmony_civoid nfcmrvl_fw_dnld_deinit(struct nfcmrvl_private *priv);
938c2ecf20Sopenharmony_civoid nfcmrvl_fw_dnld_abort(struct nfcmrvl_private *priv);
948c2ecf20Sopenharmony_ciint nfcmrvl_fw_dnld_start(struct nci_dev *ndev, const char *firmware_name);
958c2ecf20Sopenharmony_civoid nfcmrvl_fw_dnld_recv_frame(struct nfcmrvl_private *priv,
968c2ecf20Sopenharmony_ci				struct sk_buff *skb);
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#endif
99