Linux-Devicetree Archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] dt-bindings: net/nfc: ti,trf7970a: Add rx-gain-reduction option
       [not found] <cover.1713305374.git.paul_geurts@live.nl>
@ 2024-04-16 22:18 ` Paul Geurts
  2024-04-17 13:12   ` Krzysztof Kozlowski
  2024-04-16 22:18 ` [PATCH 2/2] NFC: trf7970a: Create device-tree parameter for RX gain reduction Paul Geurts
  1 sibling, 1 reply; 4+ messages in thread
From: Paul Geurts @ 2024-04-16 22:18 UTC (permalink / raw
  To: mgreer, krzk, davem, edumazet, kuba, pabeni, robh, conor+dt,
	linux-wireless, netdev, devicetree, linux-kernel
  Cc: Paul Geurts

Add option to reduce the RX antenna gain to be able to reduce the
sensitivity.

Signed-off-by: Paul Geurts <paul_geurts@live.nl>
---
 Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml b/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
index d0332eb76ad2..bbd045f6cf04 100644
--- a/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
+++ b/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
@@ -55,6 +55,11 @@ properties:
     description: |
       Regulator for supply voltage to VIN pin
 
+  rx-gain-reduction:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: |
+      Specify a RX gain reduction to reduce antenna sensitivity.
+
 required:
   - compatible
   - interrupts
@@ -95,5 +100,6 @@ examples:
             irq-status-read-quirk;
             en2-rf-quirk;
             clock-frequency = <27120000>;
+            rx-gain-reduction = <3>;
         };
     };
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] NFC: trf7970a: Create device-tree parameter for RX gain reduction
       [not found] <cover.1713305374.git.paul_geurts@live.nl>
  2024-04-16 22:18 ` [PATCH 1/2] dt-bindings: net/nfc: ti,trf7970a: Add rx-gain-reduction option Paul Geurts
@ 2024-04-16 22:18 ` Paul Geurts
  1 sibling, 0 replies; 4+ messages in thread
From: Paul Geurts @ 2024-04-16 22:18 UTC (permalink / raw
  To: mgreer, krzk, davem, edumazet, kuba, pabeni, robh, conor+dt,
	linux-wireless, netdev, devicetree, linux-kernel
  Cc: Paul Geurts

The TRF7970a device is sensitive to RF disturbances, which can make it
hard to pass some EMC immunity tests. By reducing the RX antenna gain,
the device becomes less sensitive to EMC disturbances, as a trade-off
against antenna performance.

Add a device tree option to select RX gain reduction to improve EMC
performance.

Selecting a communication standard in the ISO control register resets
the RX antenna gain settings. Therefore set the RX gain reduction
everytime the ISO control register changes, when the option is used.

Signed-off-by: Paul Geurts <paul_geurts@live.nl>
---
 drivers/nfc/trf7970a.c | 86 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 75 insertions(+), 11 deletions(-)

diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
index 7eb17f46a815..0991c717a5de 100644
--- a/drivers/nfc/trf7970a.c
+++ b/drivers/nfc/trf7970a.c
@@ -274,10 +274,14 @@
 
 #define TRF7970A_RX_SPECIAL_SETTINGS_NO_LIM	BIT(0)
 #define TRF7970A_RX_SPECIAL_SETTINGS_AGCR	BIT(1)
-#define TRF7970A_RX_SPECIAL_SETTINGS_GD_0DB	(0x0 << 2)
-#define TRF7970A_RX_SPECIAL_SETTINGS_GD_5DB	(0x1 << 2)
-#define TRF7970A_RX_SPECIAL_SETTINGS_GD_10DB	(0x2 << 2)
-#define TRF7970A_RX_SPECIAL_SETTINGS_GD_15DB	(0x3 << 2)
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT	2
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_MAX	(0x3)
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_MASK	(TRF7970A_RX_SPECIAL_SETTINGS_GD_MAX << \
+							TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT)
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_0DB	(0x0 << TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT)
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_5DB	(0x1 << TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT)
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_10DB	(0x2 << TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT)
+#define TRF7970A_RX_SPECIAL_SETTINGS_GD_15DB	(0x3 << TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT)
 #define TRF7970A_RX_SPECIAL_SETTINGS_HBT	BIT(4)
 #define TRF7970A_RX_SPECIAL_SETTINGS_M848	BIT(5)
 #define TRF7970A_RX_SPECIAL_SETTINGS_C424	BIT(6)
@@ -451,6 +455,8 @@ struct trf7970a {
 	unsigned int			timeout;
 	bool				ignore_timeout;
 	struct delayed_work		timeout_work;
+	u8				rx_gain_reduction;
+	bool			custom_rx_gain_reduction;
 };
 
 static int trf7970a_cmd(struct trf7970a *trf, u8 opcode)
@@ -550,6 +556,41 @@ static int trf7970a_read_irqstatus(struct trf7970a *trf, u8 *status)
 	return ret;
 }
 
+static int trf7970a_update_rx_gain_reduction(struct trf7970a *trf)
+{
+	int ret = 0;
+	u8 reg;
+
+	if (!trf->custom_rx_gain_reduction)
+		return 0;
+
+	ret = trf7970a_read(trf, TRF7970A_RX_SPECIAL_SETTINGS, &reg);
+	if (ret)
+		return ret;
+	reg &= ~(TRF7970A_RX_SPECIAL_SETTINGS_GD_MASK);
+	reg |= trf->rx_gain_reduction;
+
+	ret = trf7970a_write(trf, TRF7970A_RX_SPECIAL_SETTINGS, reg);
+
+	return ret;
+}
+
+static int trf7970a_update_iso_ctrl_register(struct trf7970a *trf, u8 iso_ctrl)
+{
+	int ret;
+
+	ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl);
+	if (ret)
+		return ret;
+	/*
+	 * Every time the ISO_CTRL register is written, the RX special setting register is reset by
+	 * the chip. When a custom gain reguduction is required, it should be rewritten now.
+	 */
+	ret = trf7970a_update_rx_gain_reduction(trf);
+
+	return ret;
+}
+
 static int trf7970a_read_target_proto(struct trf7970a *trf, u8 *target_proto)
 {
 	int ret;
@@ -929,8 +970,7 @@ static irqreturn_t trf7970a_irq(int irq, void *dev_id)
 			}
 
 			if (iso_ctrl != trf->iso_ctrl) {
-				ret = trf7970a_write(trf, TRF7970A_ISO_CTRL,
-						     iso_ctrl);
+				ret = trf7970a_update_iso_ctrl_register(trf, iso_ctrl);
 				if (ret)
 					goto err_unlock_exit;
 
@@ -1034,6 +1074,11 @@ static int trf7970a_init(struct trf7970a *trf)
 	if (ret)
 		goto err_out;
 
+	/* Set the gain reduction after soft init */
+	ret = trf7970a_update_rx_gain_reduction(trf);
+	if (ret)
+		goto err_out;
+
 	ret = trf7970a_cmd(trf, TRF7970A_CMD_IDLE);
 	if (ret)
 		goto err_out;
@@ -1308,7 +1353,7 @@ static int trf7970a_in_config_framing(struct trf7970a *trf, int framing)
 	}
 
 	if (iso_ctrl != trf->iso_ctrl) {
-		ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl);
+		ret = trf7970a_update_iso_ctrl_register(trf, iso_ctrl);
 		if (ret)
 			return ret;
 
@@ -1440,7 +1485,7 @@ static int trf7970a_per_cmd_config(struct trf7970a *trf,
 		}
 
 		if (iso_ctrl != trf->iso_ctrl) {
-			ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl);
+			ret = trf7970a_update_iso_ctrl_register(trf, iso_ctrl);
 			if (ret)
 				return ret;
 
@@ -1604,8 +1649,7 @@ static int trf7970a_tg_config_rf_tech(struct trf7970a *trf, int tech)
 	 */
 	if ((trf->framing == NFC_DIGITAL_FRAMING_NFC_DEP_ACTIVATED) &&
 	    (trf->iso_ctrl_tech != trf->iso_ctrl)) {
-		ret = trf7970a_write(trf, TRF7970A_ISO_CTRL,
-				     trf->iso_ctrl_tech);
+		ret = trf7970a_update_iso_ctrl_register(trf, trf->iso_ctrl_tech);
 
 		trf->iso_ctrl = trf->iso_ctrl_tech;
 	}
@@ -1653,7 +1697,7 @@ static int trf7970a_tg_config_framing(struct trf7970a *trf, int framing)
 	trf->framing = framing;
 
 	if (iso_ctrl != trf->iso_ctrl) {
-		ret = trf7970a_write(trf, TRF7970A_ISO_CTRL, iso_ctrl);
+		ret = trf7970a_update_iso_ctrl_register(trf, iso_ctrl);
 		if (ret)
 			return ret;
 
@@ -1754,6 +1798,10 @@ static int _trf7970a_tg_listen(struct nfc_digital_dev *ddev, u16 timeout,
 	if (ret)
 		goto out_err;
 
+	ret = trf7970a_update_rx_gain_reduction(trf);
+	if (ret)
+		goto out_err;
+
 	ret = trf7970a_write(trf, TRF7970A_REG_IO_CTRL,
 			     trf->io_ctrl | TRF7970A_REG_IO_CTRL_VRS(0x1));
 	if (ret)
@@ -1944,6 +1992,10 @@ static int trf7970a_startup(struct trf7970a *trf)
 	if (ret)
 		return ret;
 
+	ret = trf7970a_update_rx_gain_reduction(trf);
+	if (ret)
+		return ret;
+
 	pm_runtime_set_active(trf->dev);
 	pm_runtime_enable(trf->dev);
 	pm_runtime_mark_last_busy(trf->dev);
@@ -1992,6 +2044,7 @@ static int trf7970a_probe(struct spi_device *spi)
 	struct trf7970a *trf;
 	int uvolts, autosuspend_delay, ret;
 	u32 clk_freq = TRF7970A_13MHZ_CLOCK_FREQUENCY;
+	u32 rx_gain_reduction;
 
 	if (!np) {
 		dev_err(&spi->dev, "No Device Tree entry\n");
@@ -2053,6 +2106,17 @@ static int trf7970a_probe(struct spi_device *spi)
 		trf->modulator_sys_clk_ctrl = 0;
 	}
 
+	if (of_property_read_u32(np, "rx-gain-reduction", &rx_gain_reduction) == 0) {
+		if (rx_gain_reduction > TRF7970A_RX_SPECIAL_SETTINGS_GD_MAX) {
+			dev_warn(trf->dev, "invalid RX gain reduction setting: %u. Limiting to %u\n",
+				 rx_gain_reduction, TRF7970A_RX_SPECIAL_SETTINGS_GD_MAX);
+			rx_gain_reduction = TRF7970A_RX_SPECIAL_SETTINGS_GD_MAX;
+		}
+		trf->rx_gain_reduction = (rx_gain_reduction <<
+			TRF7970A_RX_SPECIAL_SETTINGS_GD_SHIFT);
+		trf->custom_rx_gain_reduction = true;
+	}
+
 	ret = devm_request_threaded_irq(trf->dev, spi->irq, NULL,
 					trf7970a_irq,
 					IRQF_TRIGGER_RISING | IRQF_ONESHOT,
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dt-bindings: net/nfc: ti,trf7970a: Add rx-gain-reduction option
  2024-04-16 22:18 ` [PATCH 1/2] dt-bindings: net/nfc: ti,trf7970a: Add rx-gain-reduction option Paul Geurts
@ 2024-04-17 13:12   ` Krzysztof Kozlowski
  2024-04-19  7:30     ` Paul Geurts
  0 siblings, 1 reply; 4+ messages in thread
From: Krzysztof Kozlowski @ 2024-04-17 13:12 UTC (permalink / raw
  To: Paul Geurts, mgreer, davem, edumazet, kuba, pabeni, robh,
	conor+dt, linux-wireless, netdev, devicetree, linux-kernel

On 17/04/2024 00:18, Paul Geurts wrote:
> Add option to reduce the RX antenna gain to be able to reduce the
> sensitivity.
> 
> Signed-off-by: Paul Geurts <paul_geurts@live.nl>
> ---
>  Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml b/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
> index d0332eb76ad2..bbd045f6cf04 100644
> --- a/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
> +++ b/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
> @@ -55,6 +55,11 @@ properties:
>      description: |
>        Regulator for supply voltage to VIN pin
>  
> +  rx-gain-reduction:

Missing vendor prefix.

> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    description: |

Do not need '|' unless you need to preserve formatting.

> +      Specify a RX gain reduction to reduce antenna sensitivity.

Reduction by what? What are the units?


Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 1/2] dt-bindings: net/nfc: ti,trf7970a: Add rx-gain-reduction option
  2024-04-17 13:12   ` Krzysztof Kozlowski
@ 2024-04-19  7:30     ` Paul Geurts
  0 siblings, 0 replies; 4+ messages in thread
From: Paul Geurts @ 2024-04-19  7:30 UTC (permalink / raw
  To: Krzysztof Kozlowski, mgreer@animalcreek.com, davem@davemloft.net,
	edumazet@google.com, kuba@kernel.org, pabeni@redhat.com,
	robh@kernel.org, conor+dt@kernel.org,
	linux-wireless@vger.kernel.org, netdev@vger.kernel.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org

On 17-04-2024 15:12, Krzysztof Kozlowski wrote:
> On 17/04/2024 00:18, Paul Geurts wrote:
>> Add option to reduce the RX antenna gain to be able to reduce the
>> sensitivity.
>>
>> Signed-off-by: Paul Geurts <paul_geurts@live.nl>
>> ---
>>  Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml b/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
>> index d0332eb76ad2..bbd045f6cf04 100644
>> --- a/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
>> +++ b/Documentation/devicetree/bindings/net/nfc/ti,trf7970a.yaml
>> @@ -55,6 +55,11 @@ properties:
>>      description: |
>>        Regulator for supply voltage to VIN pin
>>  
>> +  rx-gain-reduction:
> Missing vendor prefix.
>
>> +    $ref: /schemas/types.yaml#/definitions/uint32
>> +    description: |
> Do not need '|' unless you need to preserve formatting.
>
>> +      Specify a RX gain reduction to reduce antenna sensitivity.
> Reduction by what? What are the units?

Yes, this is a bit unclear indeed. Will clarify this.

>
>
> Best regards,
> Krzysztof

Thanks!

br,

Paul


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-04-19  7:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <cover.1713305374.git.paul_geurts@live.nl>
2024-04-16 22:18 ` [PATCH 1/2] dt-bindings: net/nfc: ti,trf7970a: Add rx-gain-reduction option Paul Geurts
2024-04-17 13:12   ` Krzysztof Kozlowski
2024-04-19  7:30     ` Paul Geurts
2024-04-16 22:18 ` [PATCH 2/2] NFC: trf7970a: Create device-tree parameter for RX gain reduction Paul Geurts

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).