nfc: supply: Add PN7160 drivers This patch adds support for the PN7160 ICs used in Qualcomm reference designs.
Subsystems (4)
PATCH 1/1 nfc: supply: Add PN7160 drivers This patch adds support for the PN7160 ICs used in Qualcomm reference designs.
From: xuchen <[email protected]>
--- drivers/nfc/pn7160/Kconfig | 40 +++ drivers/nfc/pn7160/Makefile | 6 + drivers/nfc/pn7160/common.c | 371 ++++++++++++++++++++++++ drivers/nfc/pn7160/common.h | 36 +++ drivers/nfc/pn7160/i2c_drv.c | 531 ++++++++++++++++++++++++++++++++++ drivers/nfc/pn7160/i2c_drv.h | 26 ++ drivers/nfc/pn7160/platform.h | 164 +++++++++++ 7 files changed, 1174 insertions(+) create mode 100644 drivers/nfc/pn7160/Kconfig create mode 100644 drivers/nfc/pn7160/Makefile create mode 100644 drivers/nfc/pn7160/common.c create mode 100644 drivers/nfc/pn7160/common.h create mode 100644 drivers/nfc/pn7160/i2c_drv.c create mode 100644 drivers/nfc/pn7160/i2c_drv.h create mode 100644 drivers/nfc/pn7160/platform.h
drivers/nfc/pn7160/Kconfig new file +40 -0
@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# near field communication configuration +# + +config NXP_NFC_I2C + tristate "NFC I2C Slave driver for NXP-NFCC" + depends on I2C + help + This enables the NFC driver for PN71xx based devices. + This is for I2C connected version. NCI protocol logic + resides in the usermode and it has no other NFC dependencies. + + If unsure, say N. + +config NXP_NFC_SPI + tristate "NFC SPI Slave driver for NXP-NFCC" + depends on SPI + help + This enables the NFC driver for PN71xx based devices. + This is for SPI connected version. NCI protocol logic + resides in the usermode and it has no other NFC dependencies. + + If unsure, say N. + +config NXP_NFC_RECOVERY + bool "NXP based NFC minimal FW update support" + depends on NXP_NFC_I2C && I2C + default y + help + This enables NFC minimal FW update. + This feature allows updating the firmware of NXP NFC controllers + in recovery mode. It is required for field updates and bug fixes. + The driver will handle the download mode and firmware transfer + when this option is enabled. + + If unsure, say N. + +source "drivers/nfc/pn7160/Kconfig" +endif
drivers/nfc/pn7160/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Makefile for nfc devices +# +obj-m += nxpnfc_i2c.o +nxpnfc_i2c-objs := common.o i2c_drv.o
drivers/nfc/pn7160/common.c new file +371 -0
371 lines not on this page · raw message
drivers/nfc/pn7160/common.h new file +36 -0
@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2015, The Linux Foundation. All rights reserved. +* Copyright (C) 2019-2021 NXP +*/ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include "platform.h" + +/* 函数声明 */ +int nfc_dev_open (struct inode *inode,struct file *filp); +int nfc_dev_close (struct inode *inode,struct file *filp); +long nfc_dev_ioctl (struct file *pfile,unsigned int cmd,unsigned long arg); +int nfc_parse_dt (struct device *dev,struct platform_configs *nfc_configs, +uint8_t interface); +int nfc_misc_register (struct nfc_dev *nfc_dev, +const struct file_operations *nfc_fops,int count, +char *devname,char *classname); +void nfc_misc_unregister (struct nfc_dev *nfc_dev,int count); +int configure_gpio (unsigned int gpio,int flag); +void gpio_set_ven (struct nfc_dev *nfc_dev,int value); +void gpio_free_all (struct nfc_dev *nfc_dev); +int validate_nfc_state_nci (struct nfc_dev *nfc_dev); +void set_valid_gpio (int gpio,int value); +int get_valid_gpio (int gpio); + +/* I2C specific functions */ +int i2c_disable_irq (struct nfc_dev *dev); +int i2c_enable_irq (struct nfc_dev *dev); +int i2c_read (struct nfc_dev *nfc_dev,char *buf,size_t count,int timeout); +int i2c_write (struct nfc_dev *nfc_dev,const char *buf,size_t count, +int max_retry_cnt); + +#endif /* _COMMON_H_ */
drivers/nfc/pn7160/i2c_drv.c new file +531 -0
531 lines not on this page · raw message
drivers/nfc/pn7160/i2c_drv.h new file +26 -0
@@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2015, The Linux Foundation. All rights reserved. +* Copyright (C) 2019-2021 NXP +*/ + +#ifndef _I2C_DRV_H_ +#define _I2C_DRV_H_ + +#include "platform.h" + +/* kept same as dts */ +#define NFC_I2C_DRV_STR "nxp,nxpnfc" +#define NFC_I2C_DEV_ID "nxpnfc" + +/* Function declarations */ +ssize_t nfc_i2c_dev_read (struct file *filp,char __user *buf,size_t count, +loff_t *offset); +ssize_t nfc_i2c_dev_write (struct file *filp,const char __user *buf, +size_t count,loff_t *offset); +int nfc_i2c_dev_probe (struct i2c_client *client); +void nfc_i2c_dev_remove (struct i2c_client *client); +int nfc_i2c_dev_suspend (struct device *device); +int nfc_i2c_dev_resume (struct device *device); + +#endif /* _I2C_DRV_H_ */
drivers/nfc/pn7160/platform.h new file +164 -0
164 lines not on this page · raw message
Signature · 1 line
2.25.1
Quoted 2 lines · On Fri, Feb 06, 2026 at 01:31:10AM -0500, [email protected] wrote:
From: xuchen <[email protected]>
This patch fails on so many levels that I am not going to provide any deep review. If you followed basic guidelines, basic patch submission guides (e.g. see Michael Opdenacker talk on this year FOSDEM), tutorials or docs, you would solve all of the trivialities.
You did not read these basic docs, so do not be surprised if your contributions will be entirely ignored.
Please use subject prefixes matching the subsystem. You can get them for example with 'git log --oneline -- DIRECTORY_OR_FILE' on the directory your patch is touching. For bindings, the preferred subjects are explained here:
https://www.kernel.org/doc/html/latest/devicetree/bindings/submitting-patches.html#i-for-patch-submitters
There is no "supply" here.
Please run scripts/checkpatch.pl on the patches and fix reported warnings. After that, run also 'scripts/checkpatch.pl --strict' on the patches and (probably) fix more warnings. Some warnings can be ignored, especially from --strict run, but the code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
Please run standard kernel tools for static analysis, like coccinelle, smatch and sparse, and fix reported warnings. Also please check for warnings when building with W=1 for gcc and clang. Most of these commands (checks or W=1 build) can build specific targets, like some directory, to narrow the scope to only your code. The code here looks like it needs a fix. Feel free to get in touch if the warning is not clear.
Quoted 110 lines
Signed-off-by xuchen <[email protected]>--- drivers/nfc/pn7160/Kconfig | 40 +++ drivers/nfc/pn7160/Makefile | 6 + drivers/nfc/pn7160/common.c | 371 ++++++++++++++++++++++++ drivers/nfc/pn7160/common.h | 36 +++ drivers/nfc/pn7160/i2c_drv.c | 531 ++++++++++++++++++++++++++++++++++ drivers/nfc/pn7160/i2c_drv.h | 26 ++ drivers/nfc/pn7160/platform.h | 164 +++++++++++ 7 files changed, 1174 insertions(+) create mode 100644 drivers/nfc/pn7160/Kconfig create mode 100644 drivers/nfc/pn7160/Makefile create mode 100644 drivers/nfc/pn7160/common.c create mode 100644 drivers/nfc/pn7160/common.h create mode 100644 drivers/nfc/pn7160/i2c_drv.c create mode 100644 drivers/nfc/pn7160/i2c_drv.h create mode 100644 drivers/nfc/pn7160/platform.hdrivers/nfc/pn7160/Kconfig new file +40
-0@@ -0,0 +1,40 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# near field communication configuration +# + +config NXP_NFC_I2C + tristate "NFC I2C Slave driver for NXP-NFCC" + depends on I2C + help + This enables the NFC driver for PN71xx based devices. + This is for I2C connected version. NCI protocol logic + resides in the usermode and it has no other NFC dependencies. + + If unsure, say N. + +config NXP_NFC_SPI + tristate "NFC SPI Slave driver for NXP-NFCC" + depends on SPI + help + This enables the NFC driver for PN71xx based devices. + This is for SPI connected version. NCI protocol logic + resides in the usermode and it has no other NFC dependencies. + + If unsure, say N. + +config NXP_NFC_RECOVERY + bool "NXP based NFC minimal FW update support" + depends on NXP_NFC_I2C && I2C + default y + help + This enables NFC minimal FW update. + This feature allows updating the firmware of NXP NFC controllers + in recovery mode. It is required for field updates and bug fixes. + The driver will handle the download mode and firmware transfer + when this option is enabled. + + If unsure, say N. + +source "drivers/nfc/pn7160/Kconfig" +endifdrivers/nfc/pn7160/Makefile new file +6
-0@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# +# Makefile for nfc devices +# +obj-m += nxpnfc_i2c.o +nxpnfc_i2c-objs := common.o i2c_drv.odrivers/nfc/pn7160/common.c new file +28
-0@@ -0,0 +1,371 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2015, The Linux Foundation. All rights reserved. +* Copyright (C) 2019-2021 NXP +*/ + +#include <linux/gpio.h> +#include <linux/of_gpio.h> +#include <linux/delay.h> +#include <linux/module.h> +#include <linux/fs.h> + +#include "common.h" + +int nfc_parse_dt (struct device *dev,struct platform_configs *nfc_configs, +uint8_t interface) +{ +struct device_node *np = dev->of_node; +struct platform_gpio *nfc_gpio = &nfc_configs->gpio; + +if (!np) { +pr_err ("%s: nfc of_node NULL\n" , __func__); +return -EINVAL ; + } + + nfc_gpio->irq = -EINVAL ; + nfc_gpio->dwl_req = -EINVAL ; + nfc_gpio->ven = -EINVAL ;
drivers/nfc/pn7160/common.c line 38
Quoted 10 lines
drivers/nfc/pn7160/common.c new file +10
-0+ +/* irq required for i2c based chips only */ +if (interface ==PLATFORM_IF_I2C || interface ==PLATFORM_IF_SPI ) { + nfc_gpio->irq =of_get_named_gpio (np,DTS_IRQ_GPIO_STR ,0 ); +if ((!gpio_is_valid (nfc_gpio->irq))) { +pr_err ("%s: irq gpio invalid %d\n" , __func__, + nfc_gpio->irq); +return -EINVAL ; + } +pr_info ("%s: irq %d\n" , __func__, nfc_gpio->irq);
Drivers use dev_xxx and there is no need to put __func__ everywhere.
There is even no need for this debug print. Read coding style.
This is such a poor code...
Quoted 7 lines
drivers/nfc/pn7160/common.c new file +7
-0+ } + nfc_gpio->ven =of_get_named_gpio (np,DTS_VEN_GPIO_STR ,0 ); +if ((!gpio_is_valid (nfc_gpio->ven))) { +pr_err ("%s: ven gpio invalid %d\n" , __func__, nfc_gpio->ven); +return -EINVAL ; + } +/* some products like sn220 does not required fw dwl pin */
drivers/nfc/pn7160/common.c line 55
Quoted 10 lines
drivers/nfc/pn7160/common.c new file +10
-0+ nfc_gpio->dwl_req =of_get_named_gpio (np,DTS_FWDN_GPIO_STR ,0 ); +if ((!gpio_is_valid (nfc_gpio->dwl_req))) +pr_warn ("%s: dwl_req gpio invalid %d\n" , __func__, + nfc_gpio->dwl_req); + +pr_info ("%s: %d, %d, %d\n" , __func__, nfc_gpio->irq, nfc_gpio->ven, + nfc_gpio->dwl_req); +return 0 ; +} +EXPORT_SYMBOL (nfc_parse_dt);
No, why the heck you export internal functions? This is not even needed.
...
drivers/nfc/pn7160/common.c line 162
Quoted 3 lines
drivers/nfc/pn7160/common.c new file +3
-0+void nfc_misc_unregister (struct nfc_dev *nfc_dev,int count) +{ +pr_debug ("%s: entry\n" , __func__);
No, this is not accepted since long time.
Quoted 4 lines
drivers/nfc/pn7160/common.c new file +4
-0+device_destroy (nfc_dev->nfc_class, nfc_dev->devno); +cdev_del (&nfc_dev->c_dev); +class_destroy (nfc_dev->nfc_class); +unregister_chrdev_region (nfc_dev->devno, count);
drivers/nfc/pn7160/common.c line 176
Quoted 10 lines
drivers/nfc/pn7160/common.c new file +10
-0+} +EXPORT_SYMBOL (nfc_misc_unregister); + +int nfc_misc_register (struct nfc_dev *nfc_dev, +const struct file_operations *nfc_fops,int count, +char *devname,char *classname) +{ +int ret =0 ; + + ret =alloc_chrdev_region (&nfc_dev->devno,0 , count, devname);
So you just added custom interface? No, NAK.
Quoted 42 lines
drivers/nfc/pn7160/common.c new file +42
-0+if (ret <0 ) { +pr_err ("%s: failed to alloc chrdev region ret %d\n" , __func__, + ret); +return ret; + } + nfc_dev->nfc_class =class_create (classname); +if (IS_ERR (nfc_dev->nfc_class)) { + ret =PTR_ERR (nfc_dev->nfc_class); +pr_err ("%s: failed to register device class ret %d\n" , __func__, + ret); +unregister_chrdev_region (nfc_dev->devno, count); +return ret; + } +cdev_init (&nfc_dev->c_dev, nfc_fops); + ret =cdev_add (&nfc_dev->c_dev, nfc_dev->devno, count); +if (ret <0 ) { +pr_err ("%s: failed to add cdev ret %d\n" , __func__, ret); +class_destroy (nfc_dev->nfc_class); +unregister_chrdev_region (nfc_dev->devno, count); +return ret; + } + nfc_dev->nfc_device =device_create (nfc_dev->nfc_class,NULL , + nfc_dev->devno, nfc_dev, devname); +if (IS_ERR (nfc_dev->nfc_device)) { + ret =PTR_ERR (nfc_dev->nfc_device); +pr_err ("%s: failed to create the device ret %d\n" , __func__, + ret); +cdev_del (&nfc_dev->c_dev); +class_destroy (nfc_dev->nfc_class); +unregister_chrdev_region (nfc_dev->devno, count); +return ret; + } +return 0 ; +} +EXPORT_SYMBOL (nfc_misc_register); + +/** +* nfc_ioctl_power_states() - power control +* @nfc_dev: nfc device data structure +* @arg: mode that we want to move to +* +* Device power control. Depending on the arg value, device moves to
drivers/nfc/pn7160/common.c line 228
Quoted 10 lines
drivers/nfc/pn7160/common.c new file +10
-0+* different states, refer platform.h for args +* +* Return: -ENOIOCTLCMD if arg is not supported, 0 in any other case +*/ +static int nfc_ioctl_power_states (struct nfc_dev *nfc_dev,unsigned long arg) +{ +int ret =0 ; +struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio; + +if (arg ==NFC_POWER_OFF ) {
No. Look at other drivers how this is handled.
NAK
...
Quoted 8 lines
drivers/nfc/pn7160/common.h new file +2
-0@@ -0,0 +1,36 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/*
drivers/nfc/pn7160/common.h line 12
Quoted 10 lines
drivers/nfc/pn7160/common.h new file +10
-0+* Copyright (C) 2015, The Linux Foundation. All rights reserved. +* Copyright (C) 2019-2021 NXP +*/ + +#ifndef _COMMON_H_ +#define _COMMON_H_ + +#include "platform.h" + +/* 函数声明 */
Super, to teraz będziemy pisać w naszych własnych językach? Uważam to za niedopuszczalne.
...
drivers/nfc/pn7160/common.h line 20
Quoted 8 lines
drivers/nfc/pn7160/common.h new file +8
-0+static const struct i2c_device_id nfc_i2c_dev_id[] = { + {"nxpnfc" ,0 }, + {} +}; +MODULE_DEVICE_TABLE (i2c, nfc_i2c_dev_id); + +static const struct of_device_id nfc_i2c_dev_match_table[] = { + { .compatible ="nxp,nxpnfc" },
Undocumented ABI. Really, you could have followed basic guidelines. This is not really acceptable.
NAK
Best regards,
Krzysztof