^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Driver for NXP PN533 NFC Chip - I2C transport layer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2011 Instituto Nokia de Tecnologia
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2012-2013 Tieto Poland
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (C) 2016 HALE electronic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/i2c.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/nfc/nfc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "pn533.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define VERSION "0.1"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define PN533_I2C_DRIVER_NAME "pn533_i2c"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct pn533_i2c_phy {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct i2c_client *i2c_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) struct pn533 *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) bool aborted;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) int hard_fault; /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * < 0 if hardware error occurred (e.g. i2c err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * and prevents normal operation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static int pn533_i2c_send_ack(struct pn533 *dev, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct pn533_i2c_phy *phy = dev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct i2c_client *client = phy->i2c_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static const u8 ack[6] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /* spec 6.2.1.3: Preamble, SoPC (2), ACK Code (2), Postamble */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) rc = i2c_master_send(client, ack, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) static int pn533_i2c_send_frame(struct pn533 *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct sk_buff *out)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) struct pn533_i2c_phy *phy = dev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) struct i2c_client *client = phy->i2c_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) if (phy->hard_fault != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) return phy->hard_fault;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) if (phy->priv == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) phy->priv = dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) phy->aborted = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) print_hex_dump_debug("PN533_i2c TX: ", DUMP_PREFIX_NONE, 16, 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) out->data, out->len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) rc = i2c_master_send(client, out->data, out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) if (rc == -EREMOTEIO) { /* Retry, chip was in power down */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) usleep_range(6000, 10000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) rc = i2c_master_send(client, out->data, out->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) if (rc >= 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (rc != out->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) rc = -EREMOTEIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) rc = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) static void pn533_i2c_abort_cmd(struct pn533 *dev, gfp_t flags)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) struct pn533_i2c_phy *phy = dev->phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) phy->aborted = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* An ack will cancel the last issued command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) pn533_i2c_send_ack(dev, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* schedule cmd_complete_work to finish current command execution */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) pn533_recv_frame(phy->priv, NULL, -ENOENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) static int pn533_i2c_read(struct pn533_i2c_phy *phy, struct sk_buff **skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct i2c_client *client = phy->i2c_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) int len = PN533_EXT_FRAME_HEADER_LEN +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) PN533_STD_FRAME_MAX_PAYLOAD_LEN +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) PN533_STD_FRAME_TAIL_LEN + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) *skb = alloc_skb(len, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) if (*skb == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) r = i2c_master_recv(client, skb_put(*skb, len), len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (r != len) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) nfc_err(&client->dev, "cannot read. r=%d len=%d\n", r, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) kfree_skb(*skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -EREMOTEIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (!((*skb)->data[0] & 0x01)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) nfc_err(&client->dev, "READY flag not set");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) kfree_skb(*skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) return -EBUSY;
^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) /* remove READY byte */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) skb_pull(*skb, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) /* trim to frame size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) skb_trim(*skb, phy->priv->ops->rx_frame_size((*skb)->data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static irqreturn_t pn533_i2c_irq_thread_fn(int irq, void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) struct pn533_i2c_phy *phy = data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct i2c_client *client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct sk_buff *skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) if (!phy || irq != phy->i2c_dev->irq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) WARN_ON_ONCE(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return IRQ_NONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) client = phy->i2c_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) dev_dbg(&client->dev, "IRQ\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) if (phy->hard_fault != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) r = pn533_i2c_read(phy, &skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) if (r == -EREMOTEIO) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) phy->hard_fault = r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) pn533_recv_frame(phy->priv, NULL, -EREMOTEIO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) } else if ((r == -ENOMEM) || (r == -EBADMSG) || (r == -EBUSY)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return IRQ_HANDLED;
^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) if (!phy->aborted)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pn533_recv_frame(phy->priv, skb, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static struct pn533_phy_ops i2c_phy_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) .send_frame = pn533_i2c_send_frame,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) .send_ack = pn533_i2c_send_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) .abort_cmd = pn533_i2c_abort_cmd,
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) static int pn533_i2c_probe(struct i2c_client *client,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) const struct i2c_device_id *id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) struct pn533_i2c_phy *phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) struct pn533 *priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int r = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) dev_dbg(&client->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) dev_dbg(&client->dev, "IRQ: %d\n", client->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) nfc_err(&client->dev, "Need I2C_FUNC_I2C\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) phy = devm_kzalloc(&client->dev, sizeof(struct pn533_i2c_phy),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) if (!phy)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) phy->i2c_dev = client;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) i2c_set_clientdata(client, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) priv = pn53x_common_init(PN533_DEVICE_PN532,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) PN533_PROTO_REQ_ACK_RESP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) phy, &i2c_phy_ops, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) &phy->i2c_dev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (IS_ERR(priv)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) r = PTR_ERR(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) phy->priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) r = pn532_i2c_nfc_alloc(priv, PN533_NO_TYPE_B_PROTOCOLS, &client->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) goto nfc_alloc_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) r = request_threaded_irq(client->irq, NULL, pn533_i2c_irq_thread_fn,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) IRQF_TRIGGER_FALLING |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) IRQF_SHARED | IRQF_ONESHOT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) PN533_I2C_DRIVER_NAME, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) if (r < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) nfc_err(&client->dev, "Unable to register IRQ handler\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) goto irq_rqst_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) r = pn533_finalize_setup(priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) goto fn_setup_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) r = nfc_register_device(priv->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) goto fn_setup_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) fn_setup_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) free_irq(client->irq, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) irq_rqst_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) nfc_free_device(priv->nfc_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) nfc_alloc_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) pn53x_common_clean(phy->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) static int pn533_i2c_remove(struct i2c_client *client)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) struct pn533_i2c_phy *phy = i2c_get_clientdata(client);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) dev_dbg(&client->dev, "%s\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) free_irq(client->irq, phy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) pn53x_unregister_nfc(phy->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) pn53x_common_clean(phy->priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) static const struct of_device_id of_pn533_i2c_match[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) { .compatible = "nxp,pn532", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * NOTE: The use of the compatibles with the trailing "...-i2c" is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * deprecated and will be removed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) { .compatible = "nxp,pn533-i2c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) { .compatible = "nxp,pn532-i2c", },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) {},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) MODULE_DEVICE_TABLE(of, of_pn533_i2c_match);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) static const struct i2c_device_id pn533_i2c_id_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) { PN533_I2C_DRIVER_NAME, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) MODULE_DEVICE_TABLE(i2c, pn533_i2c_id_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) static struct i2c_driver pn533_i2c_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) .name = PN533_I2C_DRIVER_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) .of_match_table = of_match_ptr(of_pn533_i2c_match),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) .probe = pn533_i2c_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) .id_table = pn533_i2c_id_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) .remove = pn533_i2c_remove,
^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) module_i2c_driver(pn533_i2c_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) MODULE_AUTHOR("Michael Thalmeier <michael.thalmeier@hale.at>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) MODULE_DESCRIPTION("PN533 I2C driver ver " VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) MODULE_VERSION(VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) MODULE_LICENSE("GPL");