Lines Matching +full:i2c +full:- +full:int +full:- +full:falling

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Marvell NFC-over-I2C driver: I2C interface related functions
10 #include <linux/i2c.h>
21 struct i2c_client *i2c; member
25 static int nfcmrvl_i2c_read(struct nfcmrvl_i2c_drv_data *drv_data, in nfcmrvl_i2c_read()
28 int ret; in nfcmrvl_i2c_read()
32 ret = i2c_master_recv(drv_data->i2c, (u8 *)&nci_hdr, NCI_CTRL_HDR_SIZE); in nfcmrvl_i2c_read()
34 nfc_err(&drv_data->i2c->dev, "cannot read NCI header\n"); in nfcmrvl_i2c_read()
35 return -EBADMSG; in nfcmrvl_i2c_read()
38 *skb = nci_skb_alloc(drv_data->priv->ndev, in nfcmrvl_i2c_read()
41 return -ENOMEM; in nfcmrvl_i2c_read()
48 ret = i2c_master_recv(drv_data->i2c, in nfcmrvl_i2c_read()
53 nfc_err(&drv_data->i2c->dev, in nfcmrvl_i2c_read()
57 return -EBADMSG; in nfcmrvl_i2c_read()
64 static irqreturn_t nfcmrvl_i2c_int_irq_thread_fn(int irq, void *drv_data_ptr) in nfcmrvl_i2c_int_irq_thread_fn()
68 int ret; in nfcmrvl_i2c_int_irq_thread_fn()
70 if (!drv_data->priv) in nfcmrvl_i2c_int_irq_thread_fn()
73 if (test_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags)) in nfcmrvl_i2c_int_irq_thread_fn()
79 case -EREMOTEIO: in nfcmrvl_i2c_int_irq_thread_fn()
80 set_bit(NFCMRVL_PHY_ERROR, &drv_data->priv->flags); in nfcmrvl_i2c_int_irq_thread_fn()
82 case -ENOMEM: in nfcmrvl_i2c_int_irq_thread_fn()
83 case -EBADMSG: in nfcmrvl_i2c_int_irq_thread_fn()
84 nfc_err(&drv_data->i2c->dev, "read failed %d\n", ret); in nfcmrvl_i2c_int_irq_thread_fn()
87 if (nfcmrvl_nci_recv_frame(drv_data->priv, skb) < 0) in nfcmrvl_i2c_int_irq_thread_fn()
88 nfc_err(&drv_data->i2c->dev, "corrupted RX packet\n"); in nfcmrvl_i2c_int_irq_thread_fn()
94 static int nfcmrvl_i2c_nci_open(struct nfcmrvl_private *priv) in nfcmrvl_i2c_nci_open()
96 struct nfcmrvl_i2c_drv_data *drv_data = priv->drv_data; in nfcmrvl_i2c_nci_open()
99 return -ENODEV; in nfcmrvl_i2c_nci_open()
104 static int nfcmrvl_i2c_nci_close(struct nfcmrvl_private *priv) in nfcmrvl_i2c_nci_close()
109 static int nfcmrvl_i2c_nci_send(struct nfcmrvl_private *priv, in nfcmrvl_i2c_nci_send()
112 struct nfcmrvl_i2c_drv_data *drv_data = priv->drv_data; in nfcmrvl_i2c_nci_send()
113 int ret; in nfcmrvl_i2c_nci_send()
115 if (test_bit(NFCMRVL_PHY_ERROR, &priv->flags)) { in nfcmrvl_i2c_nci_send()
117 return -EREMOTEIO; in nfcmrvl_i2c_nci_send()
120 ret = i2c_master_send(drv_data->i2c, skb->data, skb->len); in nfcmrvl_i2c_nci_send()
123 if (ret == -EREMOTEIO) { in nfcmrvl_i2c_nci_send()
124 nfc_info(drv_data->dev, "chip may sleep, retry\n"); in nfcmrvl_i2c_nci_send()
126 ret = i2c_master_send(drv_data->i2c, skb->data, skb->len); in nfcmrvl_i2c_nci_send()
130 if (ret != skb->len) { in nfcmrvl_i2c_nci_send()
131 nfc_err(drv_data->dev, in nfcmrvl_i2c_nci_send()
133 ret, skb->len); in nfcmrvl_i2c_nci_send()
134 ret = -EREMOTEIO; in nfcmrvl_i2c_nci_send()
160 static int nfcmrvl_i2c_parse_dt(struct device_node *node, in nfcmrvl_i2c_parse_dt()
163 int ret; in nfcmrvl_i2c_parse_dt()
171 if (of_find_property(node, "i2c-int-falling", NULL)) in nfcmrvl_i2c_parse_dt()
172 pdata->irq_polarity = IRQF_TRIGGER_FALLING; in nfcmrvl_i2c_parse_dt()
174 pdata->irq_polarity = IRQF_TRIGGER_RISING; in nfcmrvl_i2c_parse_dt()
179 return -EINVAL; in nfcmrvl_i2c_parse_dt()
181 pdata->irq = ret; in nfcmrvl_i2c_parse_dt()
186 static int nfcmrvl_i2c_probe(struct i2c_client *client, in nfcmrvl_i2c_probe()
192 int ret; in nfcmrvl_i2c_probe()
194 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in nfcmrvl_i2c_probe()
195 nfc_err(&client->dev, "Need I2C_FUNC_I2C\n"); in nfcmrvl_i2c_probe()
196 return -ENODEV; in nfcmrvl_i2c_probe()
199 drv_data = devm_kzalloc(&client->dev, sizeof(*drv_data), GFP_KERNEL); in nfcmrvl_i2c_probe()
201 return -ENOMEM; in nfcmrvl_i2c_probe()
203 drv_data->i2c = client; in nfcmrvl_i2c_probe()
204 drv_data->dev = &client->dev; in nfcmrvl_i2c_probe()
205 drv_data->priv = NULL; in nfcmrvl_i2c_probe()
209 pdata = client->dev.platform_data; in nfcmrvl_i2c_probe()
211 if (!pdata && client->dev.of_node) in nfcmrvl_i2c_probe()
212 if (nfcmrvl_i2c_parse_dt(client->dev.of_node, &config) == 0) in nfcmrvl_i2c_probe()
216 return -EINVAL; in nfcmrvl_i2c_probe()
219 ret = devm_request_threaded_irq(&drv_data->i2c->dev, pdata->irq, in nfcmrvl_i2c_probe()
221 pdata->irq_polarity | IRQF_ONESHOT, in nfcmrvl_i2c_probe()
224 nfc_err(&drv_data->i2c->dev, in nfcmrvl_i2c_probe()
229 drv_data->priv = nfcmrvl_nci_register_dev(NFCMRVL_PHY_I2C, in nfcmrvl_i2c_probe()
231 &drv_data->i2c->dev, pdata); in nfcmrvl_i2c_probe()
233 if (IS_ERR(drv_data->priv)) in nfcmrvl_i2c_probe()
234 return PTR_ERR(drv_data->priv); in nfcmrvl_i2c_probe()
236 drv_data->priv->support_fw_dnld = true; in nfcmrvl_i2c_probe()
245 nfcmrvl_nci_unregister_dev(drv_data->priv); in nfcmrvl_i2c_remove()
250 { .compatible = "marvell,nfc-i2c", },
259 MODULE_DEVICE_TABLE(i2c, nfcmrvl_i2c_id_table);
274 MODULE_DESCRIPTION("Marvell NFC-over-I2C driver");