Skip to contentSkip to conversation

Add settings for precharge and internal resistor

PATCH Superseded Gwendal Grignou 2 participants 15 messages Mar 22, 2022 – Mar 25, 2022

Subsystems (3)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add settings for precharge and internal resistor

For Semtech sensors SX9324 and SX9360, allow confugration of the pre-charge resistor (9324/9360) and internal resistor (9324).

Fix register name spelling mistakes first and set default value properly for sx9324 internal resistor register.

The 9360 changes are independent from the 9324 changes, but they are very similar.

Gwendal Grignou (8):
iio: sx9324: Fix default precharge internal resistance register
iio: sx9324: Fix register field spelling
dt-bindings: iio: sx9324: Add precharge resistor setting
iio: sx9324: Add precharge internal resistance setting
dt-bindings: iio: sx9324: Add internal compensation resistor setting
iio: sx9324: Add Setting for internal compensation resistor
dt-bindings: iio: sx9360: Add precharge resistor setting
iio: sx9360: Add pre-charge resistor setting

 .../iio/proximity/semtech,sx9324.yaml         | 19 ++++++++
 .../iio/proximity/semtech,sx9360.yaml         |  9 ++++
 drivers/iio/proximity/sx9324.c                | 44 ++++++++++++++++---
 drivers/iio/proximity/sx9360.c                | 12 ++++-
 4 files changed, 78 insertions(+), 6 deletions(-)
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#1 lore raw

PATCH v2 1/8 iio: sx9324: Fix default precharge internal resistance register

Fix the default value for the register that set the resistance:
it has to be 0x10.

Fixes 4c18a890dff8d ("iio:proximity:sx9324: Add SX9324 support")
---
 drivers/iio/proximity/sx9324.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/proximity/sx9324.c +4 -2
index 0d9bbbb50cb45..d50ce67aafdf2 100644
@@ -70,7 +70,8 @@
 #define SX9324_REG_AFE_PH2		0x2a
 #define SX9324_REG_AFE_PH3		0x2b
 #define SX9324_REG_AFE_CTRL8		0x2c
-#define SX9324_REG_AFE_CTRL8_RESFILTN_4KOHM 0x02
+#define SX9324_REG_AFE_CTRL8_RSVD	0x10
+#define SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM 0x02
 #define SX9324_REG_AFE_CTRL9		0x2d
 #define SX9324_REG_AFE_CTRL9_AGAIN_1	0x08
 
@@ -781,7 +782,8 @@ static const struct sx_common_reg_default sx9324_default_regs[] = {
 	{ SX9324_REG_AFE_PH2, 0x1a },
 	{ SX9324_REG_AFE_PH3, 0x16 },
 
-	{ SX9324_REG_AFE_CTRL8, SX9324_REG_AFE_CTRL8_RESFILTN_4KOHM },
+	{ SX9324_REG_AFE_CTRL8, SX9324_REG_AFE_CTRL8_RSVD |
+		SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM },
 	{ SX9324_REG_AFE_CTRL9, SX9324_REG_AFE_CTRL9_AGAIN_1 },
 
 	{ SX9324_REG_PROX_CTRL0, SX9324_REG_PROX_CTRL0_GAIN_1 |
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#3 lore raw

PATCH v2 2/8 iio: sx9324: Fix register field spelling

In reply to Gwendal Grignou

Field for PROX_CTRL4 should contain PROX_CTRL4.

Fixes 4c18a890dff8d ("iio:proximity:sx9324: Add SX9324 support")

---
Changes since v1:
- Add Fixes keyword in commit message.

 drivers/iio/proximity/sx9324.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/proximity/sx9324.c +2 -2
index d50ce67aafdf2..1dfa19426c210 100644
@@ -90,7 +90,7 @@
 #define SX9324_REG_PROX_CTRL4_AVGNEGFILT_MASK	GENMASK(5, 3)
 #define SX9324_REG_PROX_CTRL4_AVGNEG_FILT_2 0x08
 #define SX9324_REG_PROX_CTRL4_AVGPOSFILT_MASK	GENMASK(2, 0)
-#define SX9324_REG_PROX_CTRL3_AVGPOS_FILT_256 0x04
+#define SX9324_REG_PROX_CTRL4_AVGPOS_FILT_256 0x04
 #define SX9324_REG_PROX_CTRL5		0x35
 #define SX9324_REG_PROX_CTRL5_HYST_MASK			GENMASK(5, 4)
 #define SX9324_REG_PROX_CTRL5_CLOSE_DEBOUNCE_MASK	GENMASK(3, 2)
@@ -794,7 +794,7 @@ static const struct sx_common_reg_default sx9324_default_regs[] = {
 	{ SX9324_REG_PROX_CTRL3, SX9324_REG_PROX_CTRL3_AVGDEB_2SAMPLES |
 		SX9324_REG_PROX_CTRL3_AVGPOS_THRESH_16K },
 	{ SX9324_REG_PROX_CTRL4, SX9324_REG_PROX_CTRL4_AVGNEG_FILT_2 |
-		SX9324_REG_PROX_CTRL3_AVGPOS_FILT_256 },
+		SX9324_REG_PROX_CTRL4_AVGPOS_FILT_256 },
 	{ SX9324_REG_PROX_CTRL5, 0x00 },
 	{ SX9324_REG_PROX_CTRL6, SX9324_REG_PROX_CTRL6_PROXTHRESH_32 },
 	{ SX9324_REG_PROX_CTRL7, SX9324_REG_PROX_CTRL6_PROXTHRESH_32 },
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#5 lore raw

PATCH v2 3/8 dt-bindings: iio: sx9324: Add precharge resistor setting

In reply to Gwendal Grignou

Allow configure the resistance used during precharge.

---
Changes since v1:
- Suffix field with kOhms unit.

 .../bindings/iio/proximity/semtech,sx9324.yaml           | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +9 -0
index b8a6ee16854ff..8fbea71823e76 100644
@@ -126,6 +126,14 @@ properties:
       UINT_MAX (4294967295) represents infinite. Other values
       represent 1-1/N.
 
+  semtech,input-precharge-resistor-kohms:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 4
+    description:
+      Pre-charge input resistance in kOhm.
+    minimum: 0
+    maximum: 30
+
 required:
   - compatible
   - reg
@@ -157,5 +165,6 @@ examples:
         semtech,ph01-proxraw-strength = <2>;
         semtech,ph23-proxraw-strength = <2>;
         semtech,avg-pos-strength = <64>;
+        semtech,input-precharge-resistor-kohms = <2>;
       };
     };
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#6 lore raw

Re: [PATCH v2 3/8] dt-bindings: iio: sx9324: Add precharge resistor setting

Quoting Gwendal Grignou (2022-03-21 23:24:59)

Quoted 15 lines

Allow configure the resistance used during precharge.

---
Changes since v1:
- Suffix field with kOhms unit.

 .../bindings/iio/proximity/semtech,sx9324.yaml           | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +0 -0
index b8a6ee16854ff..8fbea71823e76 100644

Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml properties: · line 129

Quoted 4 lines
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +1 -0
@@ -126,6 +126,14 @@ properties:
       UINT_MAX (4294967295) represents infinite. Other values
       represent 1-1/N.
 
+  semtech,input-precharge-resistor-kohms:

What didn't work about using ohms? I think the goal was to use a standard unit and then scale it up in the binding and in the driver so that we didn't have to have a $ref below.

Quoted 20 lines
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +8 -1
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 4
+    description:
+      Pre-charge input resistance in kOhm.
+    minimum: 0
+    maximum: 30
+
 required:
   - compatible
   - reg
@@ -157,5 +165,6 @@ examples:
         semtech,ph01-proxraw-strength = <2>;
         semtech,ph23-proxraw-strength = <2>;
         semtech,avg-pos-strength = <64>;
+        semtech,input-precharge-resistor-kohms = <2>;
       };
     };
--

2.35.1.894.gb6a874cedc-goog

#7 lore raw

Re: [PATCH v2 3/8] dt-bindings: iio: sx9324: Add precharge resistor setting

Quoted 20 lines · Stephen Boyd

Quoting Gwendal Grignou (2022-03-21 23:24:59)

Quoted 18 lines

Allow configure the resistance used during precharge.

---
Changes since v1:
- Suffix field with kOhms unit.

 .../bindings/iio/proximity/semtech,sx9324.yaml           | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +0 -0
index b8a6ee16854ff..8fbea71823e76 100644
@@ -126,6 +126,14 @@ properties:
       UINT_MAX (4294967295) represents infinite. Other values
       represent 1-1/N.
 
Quoted 5 lines

Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml properties: · line 129

Quoted 1 line
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +1 -0
+  semtech,input-precharge-resistor-kohms:

What didn't work about using ohms? I think the goal was to use a standard unit and then scale it up in the binding and in the driver so that we didn't have to have a $ref below.

You're right, it is better as it is defined in dtschema/schemas/property-units.yaml from
https://github.com/devicetree-org/dt-schema.git
I used kOhms as it already used in the device tree (by bindings/regulator/qcom-labibb-regulator.yaml), but in retrospect, this example should not be followed.
A v3 is coming soon.

Gwendal.

Quoted 21 lines
Quoted 21 lines
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +8 -1
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 4
+    description:
+      Pre-charge input resistance in kOhm.
+    minimum: 0
+    maximum: 30
+
 required:
   - compatible
   - reg
@@ -157,5 +165,6 @@ examples:
         semtech,ph01-proxraw-strength = <2>;
         semtech,ph23-proxraw-strength = <2>;
         semtech,avg-pos-strength = <64>;
+        semtech,input-precharge-resistor-kohms = <2>;
       };
     };
--

2.35.1.894.gb6a874cedc-goog

#8 lore raw

PATCH v2 4/8 iio: sx9324: Add precharge internal resistance setting

In reply to Gwendal Grignou

Add ability to set the precharge internal resistance from the device tree.
Fix the default value for the register that set the resistance:
it has to be 0x10.

---
Changes since v1:
- Suffix field with kOhms unit.

 drivers/iio/proximity/sx9324.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/iio/proximity/sx9324.c +10 -0
index 1dfa19426c210..95de5d9f8eacb 100644
@@ -72,6 +72,7 @@
 #define SX9324_REG_AFE_CTRL8		0x2c
 #define SX9324_REG_AFE_CTRL8_RSVD	0x10
 #define SX9324_REG_AFE_CTRL8_RESFILTIN_4KOHM 0x02
+#define SX9324_REG_AFE_CTRL8_RESFILTIN_MASK GENMASK(3, 0)
 #define SX9324_REG_AFE_CTRL9		0x2d
 #define SX9324_REG_AFE_CTRL9_AGAIN_1	0x08
 
@@ -893,6 +894,15 @@ sx9324_get_default_reg(struct device *dev, int idx,
 		reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL4_RESOLUTION_MASK,
 					   raw);
 		break;
+	case SX9324_REG_AFE_CTRL8:
+		ret = device_property_read_u32(dev,
+				"semtech,input-precharge-resistor-kohms",
+				&raw);
+		reg_def->def &= ~SX9324_REG_AFE_CTRL8_RESFILTIN_MASK;
+		reg_def->def |= FIELD_PREP(SX9324_REG_AFE_CTRL8_RESFILTIN_MASK,
+					   raw / 2);
+		break;
+
 	case SX9324_REG_ADV_CTRL5:
 		ret = device_property_read_u32(dev, "semtech,startup-sensor",
 					       &start);
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#9 lore raw

PATCH v2 5/8 dt-bindings: iio: sx9324: Add internal compensation resistor setting

In reply to Gwendal Grignou

Allow setting the internal resistor used for compensation.

---
Changes since v1:
- Suffix field with kOhms unit.

 .../bindings/iio/proximity/semtech,sx9324.yaml         | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +10 -0
index 8fbea71823e76..b5f59038f9dd7 100644
@@ -126,6 +126,15 @@ properties:
       UINT_MAX (4294967295) represents infinite. Other values
       represent 1-1/N.
 
+  semtech,int-comp-resistor:
+    description:
+      Internal resistor setting for compensation.
+    enum:
+      - lowest
+      - low
+      - high
+      - highest
+
   semtech,input-precharge-resistor-kohms:
     $ref: /schemas/types.yaml#/definitions/uint32
     default: 4
@@ -165,6 +174,7 @@ examples:
         semtech,ph01-proxraw-strength = <2>;
         semtech,ph23-proxraw-strength = <2>;
         semtech,avg-pos-strength = <64>;
+        semtech,int-comp-resistor = "lowest";
         semtech,input-precharge-resistor-kohms = <2>;
       };
     };
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#10 lore raw

Re: [PATCH v2 5/8] dt-bindings: iio: sx9324: Add internal compensation resistor setting

Quoting Gwendal Grignou (2022-03-21 23:25:01)

Quoted 6 lines

Allow setting the internal resistor used for compensation.

---
Changes since v1:
- Suffix field with kOhms unit.

That's not done here though. I guess there aren't any units.

Quoted 35 lines
 .../bindings/iio/proximity/semtech,sx9324.yaml         | 10 ++++++++++
 1 file changed, 10 insertions(+)
Documentation/devicetree/bindings/iio/proximity/semtech,sx9324.yaml +10 -1
index 8fbea71823e76..b5f59038f9dd7 100644
@@ -126,6 +126,15 @@ properties:
       UINT_MAX (4294967295) represents infinite. Other values
       represent 1-1/N.
 
+  semtech,int-comp-resistor:
+    description:
+      Internal resistor setting for compensation.
+    enum:
+      - lowest
+      - low
+      - high
+      - highest
+
   semtech,input-precharge-resistor-kohms:
     $ref: /schemas/types.yaml#/definitions/uint32
     default: 4
@@ -165,6 +174,7 @@ examples:
         semtech,ph01-proxraw-strength = <2>;
         semtech,ph23-proxraw-strength = <2>;
         semtech,avg-pos-strength = <64>;
+        semtech,int-comp-resistor = "lowest";
         semtech,input-precharge-resistor-kohms = <2>;
       };
     };
--

2.35.1.894.gb6a874cedc-goog

#11 lore raw

PATCH v2 6/8 iio: sx9324: Add Setting for internal compensation resistor

In reply to Gwendal Grignou

Based on device tree setting, set the internal compensation resistor.

---
Changes since v1:
- No changes.

 drivers/iio/proximity/sx9324.c | 24 +++++++++++++++++++++++-
 1 file changed, 23 insertions(+), 1 deletion(-)
drivers/iio/proximity/sx9324.c +23 -1
index 95de5d9f8eacb..31179e1925624 100644
@@ -52,6 +52,11 @@
 #define SX9324_REG_CLK_SPRD		0x15
 
 #define SX9324_REG_AFE_CTRL0		0x20
+#define SX9324_REG_AFE_CTRL0_RINT_MASK GENMASK(7, 6)
+#define SX9324_REG_AFE_CTRL0_RINT_LOWEST	0x00
+#define SX9324_REG_AFE_CTRL0_RINT_LOW		0x40
+#define SX9324_REG_AFE_CTRL0_RINT_HIGH		0x80
+#define SX9324_REG_AFE_CTRL0_RINT_HIGHEST	0xc0
 #define SX9324_REG_AFE_CTRL1		0x21
 #define SX9324_REG_AFE_CTRL2		0x22
 #define SX9324_REG_AFE_CTRL3		0x23
@@ -769,7 +774,7 @@ static const struct sx_common_reg_default sx9324_default_regs[] = {
 	 */
 	{ SX9324_REG_GNRL_CTRL1, SX9324_REG_GNRL_CTRL1_PAUSECTRL },
 
-	{ SX9324_REG_AFE_CTRL0, 0x00 },
+	{ SX9324_REG_AFE_CTRL0, SX9324_REG_AFE_CTRL0_RINT_LOWEST },
 	{ SX9324_REG_AFE_CTRL3, 0x00 },
 	{ SX9324_REG_AFE_CTRL4, SX9324_REG_AFE_CTRL4_FREQ_83_33HZ |
 		SX9324_REG_AFE_CTRL4_RES_100 },
@@ -855,6 +860,7 @@ sx9324_get_default_reg(struct device *dev, int idx,
 	char prop[] = SX9324_PROXRAW_DEF;
 	u32 start = 0, raw = 0, pos = 0;
 	int ret, count, ph, pin;
+	const char *res;
 
 	memcpy(reg_def, &sx9324_default_regs[idx], sizeof(*reg_def));
 	switch (reg_def->reg) {
@@ -875,6 +881,22 @@ sx9324_get_default_reg(struct device *dev, int idx,
 			       SX9324_REG_AFE_PH0_PIN_MASK(pin);
 		reg_def->def = raw;
 		break;
+	case SX9324_REG_AFE_CTRL0:
+		ret = device_property_read_string(dev,
+				"semtech,int-comp-resistor", &res);
+		if (ret)
+			break;
+		reg_def->def &= ~SX9324_REG_AFE_CTRL0_RINT_MASK;
+		if (!strcmp(res, "lowest"))
+			reg_def->def |= SX9324_REG_AFE_CTRL0_RINT_LOWEST;
+		else if (!strcmp(res, "low"))
+			reg_def->def |= SX9324_REG_AFE_CTRL0_RINT_LOW;
+		else if (!strcmp(res, "high"))
+			reg_def->def |= SX9324_REG_AFE_CTRL0_RINT_HIGH;
+		else if (!strcmp(res, "highest"))
+			reg_def->def |= SX9324_REG_AFE_CTRL0_RINT_HIGHEST;
+
+		break;
 	case SX9324_REG_AFE_CTRL4:
 	case SX9324_REG_AFE_CTRL7:
 		if (reg_def->reg == SX9324_REG_AFE_CTRL4)
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#13 lore raw

PATCH v2 7/8 dt-bindings: iio: sx9360: Add precharge resistor setting

In reply to Gwendal Grignou

Allow configure the resistance used during precharge.

---
Changes since v1:
- no changes.

 .../bindings/iio/proximity/semtech,sx9360.yaml           | 9 +++++++++
 1 file changed, 9 insertions(+)
Documentation/devicetree/bindings/iio/proximity/semtech,sx9360.yaml +9 -0
index 63e1a1fd00d4c..1225f64f14174 100644
@@ -61,6 +61,14 @@ properties:
       UINT_MAX (4294967295) represents infinite. Other values
       represent 1-1/N.
 
+  semtech,input-precharge-resistor-kohms:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 0
+    description:
+      Pre-charge input resistance in kOhm.
+    minimum: 0
+    maximum: 30
+
 required:
   - compatible
   - reg
@@ -85,5 +93,6 @@ examples:
         semtech,resolution = <256>;
         semtech,proxraw-strength = <2>;
         semtech,avg-pos-strength = <64>;
+        semtech,input-precharge-resistor-kohms = <4>;
       };
     };
Signature · 1 line
2.35.1.894.gb6a874cedc-goog
#14 lore raw

PATCH v2 8/8 iio: sx9360: Add pre-charge resistor setting

In reply to Gwendal Grignou

Add ability to set the precharge internal resistance from the device tree.

---
Changes since v1:
- Suffix field with kOhms unit.

 drivers/iio/proximity/sx9360.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
drivers/iio/proximity/sx9360.c +11 -1
index 3ebb30c8a4f61..a70d2ad808f1a 100644
@@ -51,6 +51,8 @@
 #define SX9360_REG_GNRL_REG_2_FREQ(_r)  (SX9360_FOSC_HZ / ((_r) * 8192))
 
 #define SX9360_REG_AFE_CTRL1		0x21
+#define SX9360_REG_AFE_CTRL1_RESFILTIN_MASK GENMASK(3, 0)
+#define SX9360_REG_AFE_CTRL1_RESFILTIN_0OHMS 0
 #define SX9360_REG_AFE_PARAM0_PHR	0x22
 #define SX9360_REG_AFE_PARAM1_PHR	0x23
 #define SX9360_REG_AFE_PARAM0_PHM	0x24
@@ -671,7 +673,7 @@ static const struct sx_common_reg_default sx9360_default_regs[] = {
 	{ SX9360_REG_GNRL_CTRL1, 0x00 },
 	{ SX9360_REG_GNRL_CTRL2, SX9360_REG_GNRL_CTRL2_PERIOD_102MS },
 
-	{ SX9360_REG_AFE_CTRL1, 0x00 },
+	{ SX9360_REG_AFE_CTRL1, SX9360_REG_AFE_CTRL1_RESFILTIN_0OHMS },
 	{ SX9360_REG_AFE_PARAM0_PHR, SX9360_REG_AFE_PARAM0_RSVD |
 		SX9360_REG_AFE_PARAM0_RESOLUTION_128 },
 	{ SX9360_REG_AFE_PARAM1_PHR, SX9360_REG_AFE_PARAM1_AGAIN_PHM_6PF |
@@ -722,6 +724,14 @@ sx9360_get_default_reg(struct device *dev, int idx,
 
 	memcpy(reg_def, &sx9360_default_regs[idx], sizeof(*reg_def));
 	switch (reg_def->reg) {
+	case SX9360_REG_AFE_CTRL1:
+		ret = device_property_read_u32(dev,
+				"semtech,input-precharge-resistor-kohms",
+				&raw);
+		reg_def->def &= ~SX9360_REG_AFE_CTRL1_RESFILTIN_MASK;
+		reg_def->def |= FIELD_PREP(SX9360_REG_AFE_CTRL1_RESFILTIN_MASK,
+					   raw / 2);
+		break;
 	case SX9360_REG_AFE_PARAM0_PHR:
 	case SX9360_REG_AFE_PARAM0_PHM:
 		ret = device_property_read_u32(dev, "semtech,resolution", &raw);
Signature · 1 line
2.35.1.894.gb6a874cedc-goog