• Home
  • Raw
  • Download

Lines Matching +full:phy +full:- +full:i2c

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for NXP PN533 NFC Chip - I2C transport layer
6 * Copyright (C) 2012-2013 Tieto Poland
14 #include <linux/i2c.h>
32 * < 0 if hardware error occurred (e.g. i2c err)
39 struct pn533_i2c_phy *phy = dev->phy; in pn533_i2c_send_ack() local
40 struct i2c_client *client = phy->i2c_dev; in pn533_i2c_send_ack()
53 struct pn533_i2c_phy *phy = dev->phy; in pn533_i2c_send_frame() local
54 struct i2c_client *client = phy->i2c_dev; in pn533_i2c_send_frame()
57 if (phy->hard_fault != 0) in pn533_i2c_send_frame()
58 return phy->hard_fault; in pn533_i2c_send_frame()
60 if (phy->priv == NULL) in pn533_i2c_send_frame()
61 phy->priv = dev; in pn533_i2c_send_frame()
63 phy->aborted = false; in pn533_i2c_send_frame()
66 out->data, out->len, false); in pn533_i2c_send_frame()
68 rc = i2c_master_send(client, out->data, out->len); in pn533_i2c_send_frame()
70 if (rc == -EREMOTEIO) { /* Retry, chip was in power down */ in pn533_i2c_send_frame()
72 rc = i2c_master_send(client, out->data, out->len); in pn533_i2c_send_frame()
76 if (rc != out->len) in pn533_i2c_send_frame()
77 rc = -EREMOTEIO; in pn533_i2c_send_frame()
87 struct pn533_i2c_phy *phy = dev->phy; in pn533_i2c_abort_cmd() local
89 phy->aborted = true; in pn533_i2c_abort_cmd()
95 pn533_recv_frame(phy->priv, NULL, -ENOENT); in pn533_i2c_abort_cmd()
98 static int pn533_i2c_read(struct pn533_i2c_phy *phy, struct sk_buff **skb) in pn533_i2c_read() argument
100 struct i2c_client *client = phy->i2c_dev; in pn533_i2c_read()
108 return -ENOMEM; in pn533_i2c_read()
112 nfc_err(&client->dev, "cannot read. r=%d len=%d\n", r, len); in pn533_i2c_read()
114 return -EREMOTEIO; in pn533_i2c_read()
117 if (!((*skb)->data[0] & 0x01)) { in pn533_i2c_read()
118 nfc_err(&client->dev, "READY flag not set"); in pn533_i2c_read()
120 return -EBUSY; in pn533_i2c_read()
126 skb_trim(*skb, phy->priv->ops->rx_frame_size((*skb)->data)); in pn533_i2c_read()
133 struct pn533_i2c_phy *phy = data; in pn533_i2c_irq_thread_fn() local
138 if (!phy || irq != phy->i2c_dev->irq) { in pn533_i2c_irq_thread_fn()
143 client = phy->i2c_dev; in pn533_i2c_irq_thread_fn()
144 dev_dbg(&client->dev, "IRQ\n"); in pn533_i2c_irq_thread_fn()
146 if (phy->hard_fault != 0) in pn533_i2c_irq_thread_fn()
149 r = pn533_i2c_read(phy, &skb); in pn533_i2c_irq_thread_fn()
150 if (r == -EREMOTEIO) { in pn533_i2c_irq_thread_fn()
151 phy->hard_fault = r; in pn533_i2c_irq_thread_fn()
153 pn533_recv_frame(phy->priv, NULL, -EREMOTEIO); in pn533_i2c_irq_thread_fn()
156 } else if ((r == -ENOMEM) || (r == -EBADMSG) || (r == -EBUSY)) { in pn533_i2c_irq_thread_fn()
160 if (!phy->aborted) in pn533_i2c_irq_thread_fn()
161 pn533_recv_frame(phy->priv, skb, 0); in pn533_i2c_irq_thread_fn()
176 struct pn533_i2c_phy *phy; in pn533_i2c_probe() local
180 dev_dbg(&client->dev, "%s\n", __func__); in pn533_i2c_probe()
181 dev_dbg(&client->dev, "IRQ: %d\n", client->irq); in pn533_i2c_probe()
183 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in pn533_i2c_probe()
184 nfc_err(&client->dev, "Need I2C_FUNC_I2C\n"); in pn533_i2c_probe()
185 return -ENODEV; in pn533_i2c_probe()
188 phy = devm_kzalloc(&client->dev, sizeof(struct pn533_i2c_phy), in pn533_i2c_probe()
190 if (!phy) in pn533_i2c_probe()
191 return -ENOMEM; in pn533_i2c_probe()
193 phy->i2c_dev = client; in pn533_i2c_probe()
194 i2c_set_clientdata(client, phy); in pn533_i2c_probe()
198 phy, &i2c_phy_ops, NULL, in pn533_i2c_probe()
199 &phy->i2c_dev->dev); in pn533_i2c_probe()
206 phy->priv = priv; in pn533_i2c_probe()
207 r = pn532_i2c_nfc_alloc(priv, PN533_NO_TYPE_B_PROTOCOLS, &client->dev); in pn533_i2c_probe()
211 r = request_threaded_irq(client->irq, NULL, pn533_i2c_irq_thread_fn, in pn533_i2c_probe()
214 PN533_I2C_DRIVER_NAME, phy); in pn533_i2c_probe()
216 nfc_err(&client->dev, "Unable to register IRQ handler\n"); in pn533_i2c_probe()
224 r = nfc_register_device(priv->nfc_dev); in pn533_i2c_probe()
231 free_irq(client->irq, phy); in pn533_i2c_probe()
234 nfc_free_device(priv->nfc_dev); in pn533_i2c_probe()
237 pn53x_common_clean(phy->priv); in pn533_i2c_probe()
244 struct pn533_i2c_phy *phy = i2c_get_clientdata(client); in pn533_i2c_remove() local
246 dev_dbg(&client->dev, "%s\n", __func__); in pn533_i2c_remove()
248 free_irq(client->irq, phy); in pn533_i2c_remove()
250 pn53x_unregister_nfc(phy->priv); in pn533_i2c_remove()
251 pn53x_common_clean(phy->priv); in pn533_i2c_remove()
259 * NOTE: The use of the compatibles with the trailing "...-i2c" is
262 { .compatible = "nxp,pn533-i2c", },
263 { .compatible = "nxp,pn532-i2c", },
272 MODULE_DEVICE_TABLE(i2c, pn533_i2c_id_table);
287 MODULE_DESCRIPTION("PN533 I2C driver ver " VERSION);