Merge branch 'x15-audio-fixes' into omap-for-v4.4/fixes
[firefly-linux-kernel-4.4.55.git] / drivers / nfc / nfcmrvl / main.c
index 6fb23cc9a6590c1c5ad65e12bb4bae25b900eaa8..8079ae0de21ebac54153e7202bb469ae413ed765 100644 (file)
@@ -33,6 +33,9 @@ static int nfcmrvl_nci_open(struct nci_dev *ndev)
        if (test_and_set_bit(NFCMRVL_NCI_RUNNING, &priv->flags))
                return 0;
 
+       /* Reset possible fault of previous session */
+       clear_bit(NFCMRVL_PHY_ERROR, &priv->flags);
+
        err = priv->if_ops->nci_open(priv);
 
        if (err)
@@ -97,14 +100,16 @@ static struct nci_ops nfcmrvl_nci_ops = {
        .fw_download = nfcmrvl_nci_fw_download,
 };
 
-struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
+struct nfcmrvl_private *nfcmrvl_nci_register_dev(enum nfcmrvl_phy phy,
+                               void *drv_data,
                                struct nfcmrvl_if_ops *ops,
                                struct device *dev,
                                struct nfcmrvl_platform_data *pdata)
 {
        struct nfcmrvl_private *priv;
        int rc;
-       int headroom = 0;
+       int headroom;
+       int tailroom;
        u32 protocols;
 
        priv = kzalloc(sizeof(*priv), GFP_KERNEL);
@@ -114,6 +119,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
        priv->drv_data = drv_data;
        priv->if_ops = ops;
        priv->dev = dev;
+       priv->phy = phy;
 
        memcpy(&priv->config, pdata, sizeof(*pdata));
 
@@ -126,8 +132,14 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
                        nfc_err(dev, "failed to request reset_n io\n");
        }
 
+       if (phy == NFCMRVL_PHY_SPI) {
+               headroom = NCI_SPI_HDR_LEN;
+               tailroom = 1;
+       } else
+               headroom = tailroom = 0;
+
        if (priv->config.hci_muxed)
-               headroom = NFCMRVL_HCI_EVENT_HEADER_SIZE;
+               headroom += NFCMRVL_HCI_EVENT_HEADER_SIZE;
 
        protocols = NFC_PROTO_JEWEL_MASK
                | NFC_PROTO_MIFARE_MASK
@@ -138,7 +150,7 @@ struct nfcmrvl_private *nfcmrvl_nci_register_dev(void *drv_data,
                | NFC_PROTO_NFC_DEP_MASK;
 
        priv->ndev = nci_allocate_device(&nfcmrvl_nci_ops, protocols,
-                                        headroom, 0);
+                                        headroom, tailroom);
        if (!priv->ndev) {
                nfc_err(dev, "nci_allocate_device failed\n");
                rc = -ENOMEM;
@@ -221,10 +233,8 @@ EXPORT_SYMBOL_GPL(nfcmrvl_nci_recv_frame);
 
 void nfcmrvl_chip_reset(struct nfcmrvl_private *priv)
 {
-       /*
-        * This function does not take care if someone is using the device.
-        * To be improved.
-        */
+       /* Reset possible fault of previous session */
+       clear_bit(NFCMRVL_PHY_ERROR, &priv->flags);
 
        if (priv->config.reset_n_io) {
                nfc_info(priv->dev, "reset the chip\n");