Lines Matching +full:phy +full:- +full:i2c
1 // SPDX-License-Identifier: GPL-2.0-only
3 * I2C link layer for the NXP NCI driver
6 * Copyright (C) 2012-2015 Intel Corporation. All rights reserved.
17 #include <linux/i2c.h>
26 #include "nxp-nci.h"
28 #define NXP_NCI_I2C_DRIVER_NAME "nxp-nci_i2c"
40 * < 0 if hardware error occurred (e.g. i2c err)
48 struct nxp_nci_i2c_phy *phy = (struct nxp_nci_i2c_phy *) phy_id; in nxp_nci_i2c_set_mode() local
50 gpiod_set_value(phy->gpiod_fw, (mode == NXP_NCI_MODE_FW) ? 1 : 0); in nxp_nci_i2c_set_mode()
51 gpiod_set_value(phy->gpiod_en, (mode != NXP_NCI_MODE_COLD) ? 1 : 0); in nxp_nci_i2c_set_mode()
55 phy->hard_fault = 0; in nxp_nci_i2c_set_mode()
63 struct nxp_nci_i2c_phy *phy = phy_id; in nxp_nci_i2c_write() local
64 struct i2c_client *client = phy->i2c_dev; in nxp_nci_i2c_write()
66 if (phy->hard_fault != 0) in nxp_nci_i2c_write()
67 return phy->hard_fault; in nxp_nci_i2c_write()
69 r = i2c_master_send(client, skb->data, skb->len); in nxp_nci_i2c_write()
73 r = i2c_master_send(client, skb->data, skb->len); in nxp_nci_i2c_write()
77 nfc_err(&client->dev, "Error %d on I2C send\n", r); in nxp_nci_i2c_write()
78 } else if (r != skb->len) { in nxp_nci_i2c_write()
79 nfc_err(&client->dev, in nxp_nci_i2c_write()
81 r, skb->len); in nxp_nci_i2c_write()
82 r = -EREMOTEIO; in nxp_nci_i2c_write()
96 static int nxp_nci_i2c_fw_read(struct nxp_nci_i2c_phy *phy, in nxp_nci_i2c_fw_read() argument
99 struct i2c_client *client = phy->i2c_dev; in nxp_nci_i2c_fw_read()
108 nfc_err(&client->dev, "Incorrect header length: %u\n", r); in nxp_nci_i2c_fw_read()
109 r = -EBADMSG; in nxp_nci_i2c_fw_read()
118 r = -ENOMEM; in nxp_nci_i2c_fw_read()
128 nfc_err(&client->dev, in nxp_nci_i2c_fw_read()
131 r = -EBADMSG; in nxp_nci_i2c_fw_read()
143 static int nxp_nci_i2c_nci_read(struct nxp_nci_i2c_phy *phy, in nxp_nci_i2c_nci_read() argument
147 struct i2c_client *client = phy->i2c_dev; in nxp_nci_i2c_nci_read()
154 nfc_err(&client->dev, "Incorrect header length: %u\n", r); in nxp_nci_i2c_nci_read()
155 r = -EBADMSG; in nxp_nci_i2c_nci_read()
161 r = -ENOMEM; in nxp_nci_i2c_nci_read()
174 nfc_err(&client->dev, in nxp_nci_i2c_nci_read()
177 r = -EBADMSG; in nxp_nci_i2c_nci_read()
191 struct nxp_nci_i2c_phy *phy = phy_id; in nxp_nci_i2c_irq_thread_fn() local
198 if (!phy || !phy->ndev) in nxp_nci_i2c_irq_thread_fn()
201 client = phy->i2c_dev; in nxp_nci_i2c_irq_thread_fn()
203 if (!client || irq != client->irq) in nxp_nci_i2c_irq_thread_fn()
206 info = nci_get_drvdata(phy->ndev); in nxp_nci_i2c_irq_thread_fn()
211 mutex_lock(&info->info_lock); in nxp_nci_i2c_irq_thread_fn()
213 if (phy->hard_fault != 0) in nxp_nci_i2c_irq_thread_fn()
216 switch (info->mode) { in nxp_nci_i2c_irq_thread_fn()
218 r = nxp_nci_i2c_nci_read(phy, &skb); in nxp_nci_i2c_irq_thread_fn()
221 r = nxp_nci_i2c_fw_read(phy, &skb); in nxp_nci_i2c_irq_thread_fn()
224 r = -EREMOTEIO; in nxp_nci_i2c_irq_thread_fn()
228 if (r == -EREMOTEIO) { in nxp_nci_i2c_irq_thread_fn()
229 phy->hard_fault = r; in nxp_nci_i2c_irq_thread_fn()
230 if (info->mode == NXP_NCI_MODE_FW) in nxp_nci_i2c_irq_thread_fn()
231 nxp_nci_fw_recv_frame(phy->ndev, NULL); in nxp_nci_i2c_irq_thread_fn()
234 nfc_err(&client->dev, "Read failed with error %d\n", r); in nxp_nci_i2c_irq_thread_fn()
238 switch (info->mode) { in nxp_nci_i2c_irq_thread_fn()
240 nci_recv_frame(phy->ndev, skb); in nxp_nci_i2c_irq_thread_fn()
243 nxp_nci_fw_recv_frame(phy->ndev, skb); in nxp_nci_i2c_irq_thread_fn()
250 mutex_unlock(&info->info_lock); in nxp_nci_i2c_irq_thread_fn()
261 { "enable-gpios", &enable_gpios, 1 },
262 { "firmware-gpios", &firmware_gpios, 1 },
268 struct device *dev = &client->dev; in nxp_nci_i2c_probe()
269 struct nxp_nci_i2c_phy *phy; in nxp_nci_i2c_probe() local
272 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { in nxp_nci_i2c_probe()
273 nfc_err(&client->dev, "Need I2C_FUNC_I2C\n"); in nxp_nci_i2c_probe()
274 return -ENODEV; in nxp_nci_i2c_probe()
277 phy = devm_kzalloc(&client->dev, sizeof(struct nxp_nci_i2c_phy), in nxp_nci_i2c_probe()
279 if (!phy) in nxp_nci_i2c_probe()
280 return -ENOMEM; in nxp_nci_i2c_probe()
282 phy->i2c_dev = client; in nxp_nci_i2c_probe()
283 i2c_set_clientdata(client, phy); in nxp_nci_i2c_probe()
289 phy->gpiod_en = devm_gpiod_get(dev, "enable", GPIOD_OUT_LOW); in nxp_nci_i2c_probe()
290 if (IS_ERR(phy->gpiod_en)) { in nxp_nci_i2c_probe()
292 return PTR_ERR(phy->gpiod_en); in nxp_nci_i2c_probe()
295 phy->gpiod_fw = devm_gpiod_get_optional(dev, "firmware", GPIOD_OUT_LOW); in nxp_nci_i2c_probe()
296 if (IS_ERR(phy->gpiod_fw)) { in nxp_nci_i2c_probe()
298 return PTR_ERR(phy->gpiod_fw); in nxp_nci_i2c_probe()
301 r = nxp_nci_probe(phy, &client->dev, &i2c_phy_ops, in nxp_nci_i2c_probe()
302 NXP_NCI_I2C_MAX_PAYLOAD, &phy->ndev); in nxp_nci_i2c_probe()
306 r = request_threaded_irq(client->irq, NULL, in nxp_nci_i2c_probe()
309 NXP_NCI_I2C_DRIVER_NAME, phy); in nxp_nci_i2c_probe()
311 nfc_err(&client->dev, "Unable to register IRQ handler\n"); in nxp_nci_i2c_probe()
318 struct nxp_nci_i2c_phy *phy = i2c_get_clientdata(client); in nxp_nci_i2c_remove() local
320 nxp_nci_remove(phy->ndev); in nxp_nci_i2c_remove()
321 free_irq(client->irq, phy); in nxp_nci_i2c_remove()
325 { "nxp-nci_i2c" },
328 MODULE_DEVICE_TABLE(i2c, nxp_nci_i2c_id_table);
331 { .compatible = "nxp,nxp-nci-i2c", },
360 MODULE_DESCRIPTION("I2C driver for NXP NCI NFC controllers");