^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Marvell NFC-over-I2C driver: I2C interface related functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2015, Marvell International Ltd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * This software file (the "File") is distributed by Marvell International
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Ltd. under the terms of the GNU General Public License Version 2, June 1991
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * (the "License"). You may use, redistribute and/or modify this File in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * accordance with the terms and conditions of the License, a copy of which
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * is available on the worldwide web at
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * this warranty disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) **/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/pm_runtime.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/of_irq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/of_gpio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <net/nfc/nci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #include <net/nfc/nci_core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #include "nfcmrvl.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct nfcmrvl_i2c_drv_data {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct device *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct i2c_client *i2c;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct nfcmrvl_private *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) static int nfcmrvl_i2c_read(struct nfcmrvl_i2c_drv_data *drv_data,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct sk_buff **skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct nci_ctrl_hdr nci_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* Read NCI header to know the payload size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) ret = i2c_master_recv(drv_data->i2c, (u8 *)&nci_hdr, NCI_CTRL_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (ret != NCI_CTRL_HDR_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) nfc_err(&drv_data->i2c->dev, "cannot read NCI header\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) if (nci_hdr.plen > NCI_MAX_PAYLOAD_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) nfc_err(&drv_data->i2c->dev, "invalid packet payload size\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) *skb = nci_skb_alloc(drv_data->priv->ndev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) nci_hdr.plen + NCI_CTRL_HDR_SIZE, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) if (!*skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) /* Copy NCI header into the SKB */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) skb_put_data(*skb, &nci_hdr, NCI_CTRL_HDR_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) if (nci_hdr.plen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) /* Read the NCI payload */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) ret = i2c_master_recv(drv_data->i2c,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) skb_put(*skb, nci_hdr.plen),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) nci_hdr.plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) if (ret != nci_hdr.plen) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) nfc_err(&drv_data->i2c->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) "Invalid frame payload length: %u (expected %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ret, nci_hdr.plen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) kfree_skb(*skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static irqreturn_t nfcmrvl_i2c_int_irq_thread_fn(int irq, void *drv_data_ptr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) struct nfcmrvl_i2c_drv_data *drv_data = drv_data_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (!drv_data->priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (test_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) ret = nfcmrvl_i2c_read(drv_data, &skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) switch (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) case -EREMOTEIO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) set_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) case -ENOMEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) case -EBADMSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) nfc_err(&drv_data->i2c->dev, "read failed %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) nfc_err(&drv_data->i2c->dev, "corrupted RX packet\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) static int nfcmrvl_i2c_nci_open(struct nfcmrvl_private *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) struct nfcmrvl_i2c_drv_data *drv_data = priv->drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!drv_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) static int nfcmrvl_i2c_nci_close(struct nfcmrvl_private *priv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) static int nfcmrvl_i2c_nci_send(struct nfcmrvl_private *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) struct nfcmrvl_i2c_drv_data *drv_data = priv->drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) if (test_bit(NFCMRVL_PHY_ERROR, &priv->flags))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return -EREMOTEIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) ret = i2c_master_send(drv_data->i2c, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) /* Retry if chip was in standby */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (ret == -EREMOTEIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) nfc_info(drv_data->dev, "chip may sleep, retry\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) usleep_range(6000, 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) ret = i2c_master_send(drv_data->i2c, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (ret >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) if (ret != skb->len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) nfc_err(drv_data->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) "Invalid length sent: %u (expected %u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) ret, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) ret = -EREMOTEIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) } else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) static void nfcmrvl_i2c_nci_update_config(struct nfcmrvl_private *priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) const void *param)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static struct nfcmrvl_if_ops i2c_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) .nci_open = nfcmrvl_i2c_nci_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .nci_close = nfcmrvl_i2c_nci_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .nci_send = nfcmrvl_i2c_nci_send,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .nci_update_config = nfcmrvl_i2c_nci_update_config,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) static int nfcmrvl_i2c_parse_dt(struct device_node *node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) struct nfcmrvl_platform_data *pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ret = nfcmrvl_parse_dt(node, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) pr_err("Failed to get generic entries\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (of_find_property(node, "i2c-int-falling", NULL))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) pdata->irq_polarity = IRQF_TRIGGER_FALLING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) pdata->irq_polarity = IRQF_TRIGGER_RISING;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) ret = irq_of_parse_and_map(node, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) pr_err("Unable to get irq, error: %d\n", ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) pdata->irq = ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) static int nfcmrvl_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) struct nfcmrvl_i2c_drv_data *drv_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) struct nfcmrvl_platform_data *pdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) struct nfcmrvl_platform_data config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) nfc_err(&client->dev, "Need I2C_FUNC_I2C\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) drv_data = devm_kzalloc(&client->dev, sizeof(*drv_data), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) if (!drv_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) drv_data->i2c = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) drv_data->dev = &client->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) drv_data->priv = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) i2c_set_clientdata(client, drv_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) pdata = client->dev.platform_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) if (!pdata && client->dev.of_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (nfcmrvl_i2c_parse_dt(client->dev.of_node, &config) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) pdata = &config;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (!pdata)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Request the read IRQ */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) ret = devm_request_threaded_irq(&drv_data->i2c->dev, pdata->irq,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) NULL, nfcmrvl_i2c_int_irq_thread_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) pdata->irq_polarity | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) "nfcmrvl_i2c_int", drv_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) nfc_err(&drv_data->i2c->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) "Unable to register IRQ handler\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) drv_data->priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_I2C,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) drv_data, &i2c_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) &drv_data->i2c->dev, pdata);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (IS_ERR(drv_data->priv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return PTR_ERR(drv_data->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) drv_data->priv->support_fw_dnld = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static int nfcmrvl_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) struct nfcmrvl_i2c_drv_data *drv_data = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) nfcmrvl_nci_unregister_dev(drv_data->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) static const struct of_device_id of_nfcmrvl_i2c_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) { .compatible = "marvell,nfc-i2c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) MODULE_DEVICE_TABLE(of, of_nfcmrvl_i2c_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static const struct i2c_device_id nfcmrvl_i2c_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) { "nfcmrvl_i2c", 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) MODULE_DEVICE_TABLE(i2c, nfcmrvl_i2c_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static struct i2c_driver nfcmrvl_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .probe = nfcmrvl_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .id_table = nfcmrvl_i2c_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) .remove = nfcmrvl_i2c_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .name = "nfcmrvl_i2c",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .of_match_table = of_match_ptr(of_nfcmrvl_i2c_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) module_i2c_driver(nfcmrvl_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_AUTHOR("Marvell International Ltd.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) MODULE_DESCRIPTION("Marvell NFC-over-I2C driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) MODULE_LICENSE("GPL v2");