Commit 3194c687 authored by Vincent Cuissard's avatar Vincent Cuissard Committed by Samuel Ortiz

NFC: nfcmrvl: add firmware download support

Implement firmware download protocol for Marvell NFC controllers.
This protocol is based on NCI frames that's why parts of its
implementation use some NCI generic functions.
Signed-off-by: default avatarVincent Cuissard <cuissard@marvell.com>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent e5629d29
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
# Makefile for NFCMRVL NCI based NFC driver # Makefile for NFCMRVL NCI based NFC driver
# #
nfcmrvl-y += main.o nfcmrvl-y += main.o fw_dnld.o
obj-$(CONFIG_NFC_MRVL) += nfcmrvl.o obj-$(CONFIG_NFC_MRVL) += nfcmrvl.o
nfcmrvl_usb-y += usb.o nfcmrvl_usb-y += usb.o
......
This diff is collapsed.
/**
* Marvell NFC driver: Firmware downloader
*
* Copyright (C) 2015, Marvell International Ltd.
*
* This software file (the "File") is distributed by Marvell International
* Ltd. under the terms of the GNU General Public License Version 2, June 1991
* (the "License"). You may use, redistribute and/or modify this File in
* accordance with the terms and conditions of the License, a copy of which
* is available on the worldwide web at
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
*
* THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
* IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
* ARE EXPRESSLY DISCLAIMED. The License provides additional details about
* this warranty disclaimer.
**/
#ifndef __NFCMRVL_FW_DNLD_H__
#define __NFCMRVL_FW_DNLD_H__
#include <linux/workqueue.h>
#define NFCMRVL_FW_MAGIC 0x88888888
#define NCI_OP_PROP_BOOT_CMD 0x3A
#define NCI_CORE_LC_PROP_FW_DL 0xFD
#define NCI_CORE_LC_CONNID_PROP_FW_DL 0x02
#define HELPER_CMD_ENTRY_POINT 0x04
#define HELPER_CMD_PACKET_FORMAT 0xA5
#define HELPER_ACK_PACKET_FORMAT 0x5A
#define HELPER_RETRY_REQUESTED (1 << 15)
struct nfcmrvl_private;
struct nfcmrvl_fw_uart_config {
uint8_t flow_control;
uint32_t baudrate;
} __packed;
struct nfcmrvl_fw_i2c_config {
uint32_t clk;
} __packed;
struct nfcmrvl_fw_spi_config {
uint32_t clk;
} __packed;
struct nfcmrvl_fw_binary_config {
uint32_t offset;
union {
void *config;
struct nfcmrvl_fw_uart_config uart;
struct nfcmrvl_fw_i2c_config i2c;
struct nfcmrvl_fw_spi_config spi;
uint8_t reserved[64];
};
} __packed;
struct nfcmrvl_fw {
uint32_t magic;
uint32_t ref_clock;
uint32_t phy;
struct nfcmrvl_fw_binary_config bootrom;
struct nfcmrvl_fw_binary_config helper;
struct nfcmrvl_fw_binary_config firmware;
uint8_t reserved[64];
} __packed;
struct nfcmrvl_fw_dnld {
char name[NFC_FIRMWARE_NAME_MAXSIZE + 1];
const struct firmware *fw;
const struct nfcmrvl_fw *header;
const struct nfcmrvl_fw_binary_config *binary_config;
int state;
int substate;
int offset;
int chunk_len;
struct workqueue_struct *rx_wq;
struct work_struct rx_work;
struct sk_buff_head rx_q;
struct timer_list timer;
};
int nfcmrvl_fw_dnld_init(struct nfcmrvl_private *priv);
void nfcmrvl_fw_dnld_deinit(struct nfcmrvl_private *priv);
void nfcmrvl_fw_dnld_abort(struct nfcmrvl_private *priv);
int nfcmrvl_fw_dnld_start(struct nci_dev *ndev, const char *firmware_name);
void nfcmrvl_fw_dnld_recv_frame(struct nfcmrvl_private *priv,
struct sk_buff *skb);
#endif
...@@ -61,9 +61,6 @@ static int nfcmrvl_nci_send(struct nci_dev *ndev, struct sk_buff *skb) ...@@ -61,9 +61,6 @@ static int nfcmrvl_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
skb->dev = (void *)ndev; skb->dev = (void *)ndev;
if (!test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
return -EBUSY;
if (priv->config.hci_muxed) { if (priv->config.hci_muxed) {
unsigned char *hdr; unsigned char *hdr;
unsigned char len = skb->len; unsigned char len = skb->len;
...@@ -86,11 +83,18 @@ static int nfcmrvl_nci_setup(struct nci_dev *ndev) ...@@ -86,11 +83,18 @@ static int nfcmrvl_nci_setup(struct nci_dev *ndev)
return 0; return 0;
} }
static int nfcmrvl_nci_fw_download(struct nci_dev *ndev,
const char *firmware_name)
{
return nfcmrvl_fw_dnld_start(ndev, firmware_name);
}
static struct nci_ops nfcmrvl_nci_ops = { static struct nci_ops nfcmrvl_nci_ops = {
.open = nfcmrvl_nci_open, .open = nfcmrvl_nci_open,
.close = nfcmrvl_nci_close, .close = nfcmrvl_nci_close,
.send = nfcmrvl_nci_send, .send = nfcmrvl_nci_send,
.setup = nfcmrvl_nci_setup, .setup = nfcmrvl_nci_setup,
.fw_download = nfcmrvl_nci_fw_download,
}; };
struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data, struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
...@@ -143,18 +147,26 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data, ...@@ -143,18 +147,26 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
nci_set_drvdata(priv->ndev, priv); nci_set_drvdata(priv->ndev, priv);
nfcmrvl_chip_reset(priv);
rc = nci_register_device(priv->ndev); rc = nci_register_device(priv->ndev);
if (rc) { if (rc) {
nfc_err(dev, "nci_register_device failed %d\n", rc); nfc_err(dev, "nci_register_device failed %d\n", rc);
nci_free_device(priv->ndev); goto error_free_dev;
goto error; }
/* Ensure that controller is powered off */
nfcmrvl_chip_halt(priv);
rc = nfcmrvl_fw_dnld_init(priv);
if (rc) {
nfc_err(dev, "failed to initialize FW download %d\n", rc);
goto error_free_dev;
} }
nfc_info(dev, "registered with nci successfully\n"); nfc_info(dev, "registered with nci successfully\n");
return priv; return priv;
error_free_dev:
nci_free_device(priv->ndev);
error: error:
kfree(priv); kfree(priv);
return ERR_PTR(rc); return ERR_PTR(rc);
...@@ -165,6 +177,11 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv) ...@@ -165,6 +177,11 @@ void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv)
{ {
struct nci_dev *ndev = priv->ndev; struct nci_dev *ndev = priv->ndev;
if (priv->ndev->nfc_dev->fw_download_in_progress)
nfcmrvl_fw_dnld_abort(priv);
nfcmrvl_fw_dnld_deinit(priv);
nci_unregister_device(ndev); nci_unregister_device(ndev);
nci_free_device(ndev); nci_free_device(ndev);
kfree(priv); kfree(priv);
...@@ -185,6 +202,11 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb) ...@@ -185,6 +202,11 @@ int nfcmrvl_nci_recv_frame(struct nfcmrvl_private *priv, struct sk_buff *skb)
} }
} }
if (priv->ndev->nfc_dev->fw_download_in_progress) {
nfcmrvl_fw_dnld_recv_frame(priv, skb);
return 0;
}
if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags)) if (test_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
nci_recv_frame(priv->ndev, skb); nci_recv_frame(priv->ndev, skb);
else { else {
...@@ -213,6 +235,12 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv) ...@@ -213,6 +235,12 @@ void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
nfc_info(priv->dev, "no reset available on this interface\n"); nfc_info(priv->dev, "no reset available on this interface\n");
} }
void nfcmrvl_chip_halt(struct nfcmrvl_private *priv)
{
if (priv->config.reset_n_io)
gpio_set_value(priv->config.reset_n_io, 0);
}
#ifdef CONFIG_OF #ifdef CONFIG_OF
int nfcmrvl_parse_dt(struct device_node *node, int nfcmrvl_parse_dt(struct device_node *node,
......
/** /**
* Marvell NFC driver * Marvell NFC driver
* *
* Copyright (C) 2014, Marvell International Ltd. * Copyright (C) 2014-2015, Marvell International Ltd.
* *
* This software file (the "File") is distributed by Marvell International * This software file (the "File") is distributed by Marvell International
* Ltd. under the terms of the GNU General Public License Version 2, June 1991 * Ltd. under the terms of the GNU General Public License Version 2, June 1991
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include <linux/platform_data/nfcmrvl.h> #include <linux/platform_data/nfcmrvl.h>
#include "fw_dnld.h"
/* Define private flags: */ /* Define private flags: */
#define NFCMRVL_NCI_RUNNING 1 #define NFCMRVL_NCI_RUNNING 1
...@@ -37,6 +39,8 @@ ...@@ -37,6 +39,8 @@
*/ */
#define NFCMRVL_PB_BAIL_OUT 0x11 #define NFCMRVL_PB_BAIL_OUT 0x11
#define NFCMRVL_PROP_REF_CLOCK 0xF0
#define NFCMRVL_PROP_SET_HI_CONFIG 0xF1
/* /*
** HCI defines ** HCI defines
...@@ -52,9 +56,10 @@ ...@@ -52,9 +56,10 @@
enum nfcmrvl_phy { enum nfcmrvl_phy {
NFCMRVL_PHY_USB = 0, NFCMRVL_PHY_USB = 0,
NFCMRVL_PHY_UART = 1, NFCMRVL_PHY_UART = 1,
NFCMRVL_PHY_I2C = 2,
NFCMRVL_PHY_SPI = 3,
}; };
struct nfcmrvl_private { struct nfcmrvl_private {
unsigned long flags; unsigned long flags;
...@@ -62,8 +67,15 @@ struct nfcmrvl_private { ...@@ -62,8 +67,15 @@ struct nfcmrvl_private {
/* Platform configuration */ /* Platform configuration */
struct nfcmrvl_platform_data config; struct nfcmrvl_platform_data config;
/* Parent dev */
struct nci_dev *ndev; struct nci_dev *ndev;
/* FW download context */
struct nfcmrvl_fw_dnld fw_dnld;
/* FW download support */
bool support_fw_dnld;
/* /*
** PHY related information ** PHY related information
*/ */
...@@ -82,6 +94,8 @@ struct nfcmrvl_if_ops { ...@@ -82,6 +94,8 @@ struct nfcmrvl_if_ops {
int (*nci_open) (struct nfcmrvl_private *priv); int (*nci_open) (struct nfcmrvl_private *priv);
int (*nci_close) (struct nfcmrvl_private *priv); int (*nci_close) (struct nfcmrvl_private *priv);
int (*nci_send) (struct nfcmrvl_private *priv, struct sk_buff *skb); int (*nci_send) (struct nfcmrvl_private *priv, struct sk_buff *skb);
void (*nci_update_config)(struct nfcmrvl_private *priv,
const void *param);
}; };
void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv); void nfcmrvl_nci_unregister_dev(struct nfcmrvl_private *priv);
...@@ -93,6 +107,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data, ...@@ -93,6 +107,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
void nfcmrvl_chip_reset(struct nfcmrvl_private *priv); void nfcmrvl_chip_reset(struct nfcmrvl_private *priv);
void nfcmrvl_chip_halt(struct nfcmrvl_private *priv);
int nfcmrvl_parse_dt(struct device_node *node, int nfcmrvl_parse_dt(struct device_node *node,
struct nfcmrvl_platform_data *pdata); struct nfcmrvl_platform_data *pdata);
......
...@@ -50,10 +50,21 @@ static int nfcmrvl_uart_nci_send(struct nfcmrvl_private *priv, ...@@ -50,10 +50,21 @@ static int nfcmrvl_uart_nci_send(struct nfcmrvl_private *priv,
return nu->ops.send(nu, skb); return nu->ops.send(nu, skb);
} }
static void nfcmrvl_uart_nci_update_config(struct nfcmrvl_private *priv,
const void *param)
{
struct nci_uart *nu = priv->drv_data;
const struct nfcmrvl_fw_uart_config *config = param;
nci_uart_set_config(nu, le32_to_cpu(config->baudrate),
config->flow_control);
}
static struct nfcmrvl_if_ops uart_ops = { static struct nfcmrvl_if_ops uart_ops = {
.nci_open = nfcmrvl_uart_nci_open, .nci_open = nfcmrvl_uart_nci_open,
.nci_close = nfcmrvl_uart_nci_close, .nci_close = nfcmrvl_uart_nci_close,
.nci_send = nfcmrvl_uart_nci_send, .nci_send = nfcmrvl_uart_nci_send,
.nci_update_config = nfcmrvl_uart_nci_update_config
}; };
#ifdef CONFIG_OF #ifdef CONFIG_OF
...@@ -132,6 +143,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu) ...@@ -132,6 +143,7 @@ static int nfcmrvl_nci_uart_open(struct nci_uart *nu)
return PTR_ERR(priv); return PTR_ERR(priv);
priv->phy = NFCMRVL_PHY_UART; priv->phy = NFCMRVL_PHY_UART;
priv->support_fw_dnld = true;
nu->drv_data = priv; nu->drv_data = priv;
nu->ndev = priv->ndev; nu->ndev = priv->ndev;
......
...@@ -347,6 +347,8 @@ static int nfcmrvl_probe(struct usb_interface *intf, ...@@ -347,6 +347,8 @@ static int nfcmrvl_probe(struct usb_interface *intf,
drv_data->priv = priv; drv_data->priv = priv;
drv_data->priv->phy = NFCMRVL_PHY_USB; drv_data->priv->phy = NFCMRVL_PHY_USB;
drv_data->priv->support_fw_dnld = false;
priv->dev = &drv_data->udev->dev; priv->dev = &drv_data->udev->dev;
usb_set_intfdata(intf, drv_data); usb_set_intfdata(intf, drv_data);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment