All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] ASoC: ts3a227e control debounce times
@ 2022-09-15 11:39 ` Astrid Rost
  0 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid
  Cc: kernel, alsa-devel, linux-kernel, Astrid Rost, Astrid Rost

From: Astrid Rost <astridr@axis.com>

PATCH 1 - convert ts3a227e bindings to yaml.
PATCH 2 - add ts3a227e bindings to support debounce times.
PATCH 3 - add ts3a227e driver to support debounce times.

v1 -> v2
- Converted the devicetree-bindings to YAML.
- The debounce-times are in ms. The closed match is used, if the
given times do not match the register values.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>.


Astrid Rost (3):
  dt-bindings: sound: ts3a227e: convert to yaml
  dt-bindings: sound: ts3a227e: add control of debounce times
  ASoC: ts3a227e: add parameters to control debounce times

 .../devicetree/bindings/sound/ts3a227e.txt    | 30 ------
 .../devicetree/bindings/sound/ts3a227e.yaml   | 98 +++++++++++++++++++
 sound/soc/codecs/ts3a227e.c                   | 58 +++++++++--
 3 files changed, 150 insertions(+), 36 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.txt
 create mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.yaml

-- 
2.20.1


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

* [PATCH v2 0/3] ASoC: ts3a227e control debounce times
@ 2022-09-15 11:39 ` Astrid Rost
  0 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid
  Cc: Astrid Rost, kernel, Astrid Rost, alsa-devel, linux-kernel

From: Astrid Rost <astridr@axis.com>

PATCH 1 - convert ts3a227e bindings to yaml.
PATCH 2 - add ts3a227e bindings to support debounce times.
PATCH 3 - add ts3a227e driver to support debounce times.

v1 -> v2
- Converted the devicetree-bindings to YAML.
- The debounce-times are in ms. The closed match is used, if the
given times do not match the register values.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>.


Astrid Rost (3):
  dt-bindings: sound: ts3a227e: convert to yaml
  dt-bindings: sound: ts3a227e: add control of debounce times
  ASoC: ts3a227e: add parameters to control debounce times

 .../devicetree/bindings/sound/ts3a227e.txt    | 30 ------
 .../devicetree/bindings/sound/ts3a227e.yaml   | 98 +++++++++++++++++++
 sound/soc/codecs/ts3a227e.c                   | 58 +++++++++--
 3 files changed, 150 insertions(+), 36 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.txt
 create mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.yaml

-- 
2.20.1


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

* [PATCH v2 1/3] dt-bindings: sound: ts3a227e: convert to yaml
  2022-09-15 11:39 ` Astrid Rost
@ 2022-09-15 11:39   ` Astrid Rost
  -1 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid, Rob Herring
  Cc: kernel, alsa-devel, linux-kernel, Astrid Rost, Astrid Rost, devicetree

Convert from ts3a227e.txt to yaml.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>
---
 .../devicetree/bindings/sound/ts3a227e.txt    | 30 --------
 .../devicetree/bindings/sound/ts3a227e.yaml   | 69 +++++++++++++++++++
 2 files changed, 69 insertions(+), 30 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.txt
 create mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.yaml

diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.txt b/Documentation/devicetree/bindings/sound/ts3a227e.txt
deleted file mode 100644
index 21ab45bc7e8f..000000000000
--- a/Documentation/devicetree/bindings/sound/ts3a227e.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-Texas Instruments TS3A227E
-Autonomous Audio Accessory Detection and Configuration Switch
-
-The TS3A227E detect headsets of 3-ring and 4-ring standards and
-switches automatically to route the microphone correctly.  It also
-handles key press detection in accordance with the Android audio
-headset specification v1.0.
-
-Required properties:
-
- - compatible:		Should contain "ti,ts3a227e".
- - reg:			The i2c address. Should contain <0x3b>.
- - interrupts:		Interrupt number for /INT pin from the 227e
-
-Optional properies:
- - ti,micbias:   Intended MICBIAS voltage (datasheet section 9.6.7).
-      Select 0/1/2/3/4/5/6/7 to specify MICBIAS voltage
-      2.1V/2.2V/2.3V/2.4V/2.5V/2.6V/2.7V/2.8V
-      Default value is "1" (2.2V).
-
-Examples:
-
-	i2c {
-		ts3a227e@3b {
-			compatible = "ti,ts3a227e";
-			reg = <0x3b>;
-			interrupt-parent = <&gpio>;
-			interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
-		};
-	};
diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.yaml b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
new file mode 100644
index 000000000000..3512b1f1e32b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/sound/ts3a227e.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Texas Instruments TS3A227E
+  Autonomous Audio Accessory Detection and Configuration Switch
+
+maintainers:
+  - Dylan Reid <dgreid@chromium.org>
+
+description: |
+  The TS3A227E detect headsets of 3-ring and 4-ring standards and
+  switches automatically to route the microphone correctly. It also
+  handles key press detection in accordance with the Android audio
+  headset specification v1.0.
+
+properties:
+  compatible:
+    enum:
+      - ti,ts3a227e
+
+  reg:
+    description: I2C address of the device.
+    const: 0x3b
+
+  interrupts:
+    maxItems: 1
+    description: |
+      Interrupt number for /INT pin from the ts3a227e.
+
+  ti,micbias:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Intended MICBIAS voltage (datasheet section 9.6.7).
+    enum:
+      - 0 # 2.1 V
+      - 1 # 2.2 V
+      - 2 # 2.3 V
+      - 3 # 2.4 V
+      - 4 # 2.5 V
+      - 5 # 2.6 V
+      - 6 # 2.7 V
+      - 7 # 2.8 V
+    default: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        codec: ts3a227e@3b {
+            compatible = "ti,ts3a227e";
+            reg = <0x3b>;
+            interrupt-parent = <&gpio1>;
+            interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+        };
+    };
+
+...
-- 
2.20.1


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

* [PATCH v2 1/3] dt-bindings: sound: ts3a227e: convert to yaml
@ 2022-09-15 11:39   ` Astrid Rost
  0 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid, Rob Herring
  Cc: devicetree, alsa-devel, Astrid Rost, linux-kernel, kernel, Astrid Rost

Convert from ts3a227e.txt to yaml.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>
---
 .../devicetree/bindings/sound/ts3a227e.txt    | 30 --------
 .../devicetree/bindings/sound/ts3a227e.yaml   | 69 +++++++++++++++++++
 2 files changed, 69 insertions(+), 30 deletions(-)
 delete mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.txt
 create mode 100644 Documentation/devicetree/bindings/sound/ts3a227e.yaml

diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.txt b/Documentation/devicetree/bindings/sound/ts3a227e.txt
deleted file mode 100644
index 21ab45bc7e8f..000000000000
--- a/Documentation/devicetree/bindings/sound/ts3a227e.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-Texas Instruments TS3A227E
-Autonomous Audio Accessory Detection and Configuration Switch
-
-The TS3A227E detect headsets of 3-ring and 4-ring standards and
-switches automatically to route the microphone correctly.  It also
-handles key press detection in accordance with the Android audio
-headset specification v1.0.
-
-Required properties:
-
- - compatible:		Should contain "ti,ts3a227e".
- - reg:			The i2c address. Should contain <0x3b>.
- - interrupts:		Interrupt number for /INT pin from the 227e
-
-Optional properies:
- - ti,micbias:   Intended MICBIAS voltage (datasheet section 9.6.7).
-      Select 0/1/2/3/4/5/6/7 to specify MICBIAS voltage
-      2.1V/2.2V/2.3V/2.4V/2.5V/2.6V/2.7V/2.8V
-      Default value is "1" (2.2V).
-
-Examples:
-
-	i2c {
-		ts3a227e@3b {
-			compatible = "ti,ts3a227e";
-			reg = <0x3b>;
-			interrupt-parent = <&gpio>;
-			interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
-		};
-	};
diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.yaml b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
new file mode 100644
index 000000000000..3512b1f1e32b
--- /dev/null
+++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
@@ -0,0 +1,69 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: "http://devicetree.org/schemas/sound/ts3a227e.yaml#"
+$schema: "http://devicetree.org/meta-schemas/core.yaml#"
+
+title: Texas Instruments TS3A227E
+  Autonomous Audio Accessory Detection and Configuration Switch
+
+maintainers:
+  - Dylan Reid <dgreid@chromium.org>
+
+description: |
+  The TS3A227E detect headsets of 3-ring and 4-ring standards and
+  switches automatically to route the microphone correctly. It also
+  handles key press detection in accordance with the Android audio
+  headset specification v1.0.
+
+properties:
+  compatible:
+    enum:
+      - ti,ts3a227e
+
+  reg:
+    description: I2C address of the device.
+    const: 0x3b
+
+  interrupts:
+    maxItems: 1
+    description: |
+      Interrupt number for /INT pin from the ts3a227e.
+
+  ti,micbias:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description: Intended MICBIAS voltage (datasheet section 9.6.7).
+    enum:
+      - 0 # 2.1 V
+      - 1 # 2.2 V
+      - 2 # 2.3 V
+      - 3 # 2.4 V
+      - 4 # 2.5 V
+      - 5 # 2.6 V
+      - 6 # 2.7 V
+      - 7 # 2.8 V
+    default: 2
+
+required:
+  - compatible
+  - reg
+  - interrupts
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+    #include <dt-bindings/interrupt-controller/irq.h>
+    i2c0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        codec: ts3a227e@3b {
+            compatible = "ti,ts3a227e";
+            reg = <0x3b>;
+            interrupt-parent = <&gpio1>;
+            interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+        };
+    };
+
+...
-- 
2.20.1


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

* [PATCH v2 2/3] dt-bindings: sound: ts3a227e: add control of debounce times
  2022-09-15 11:39 ` Astrid Rost
@ 2022-09-15 11:39   ` Astrid Rost
  -1 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid, Rob Herring
  Cc: kernel, alsa-devel, linux-kernel, Astrid Rost, Astrid Rost, devicetree

Add devicetree parameters to control the insertion, release and press
debounce times.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>
---
 .../devicetree/bindings/sound/ts3a227e.yaml   | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.yaml b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
index 3512b1f1e32b..8c27f298733a 100644
--- a/Documentation/devicetree/bindings/sound/ts3a227e.yaml
+++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
@@ -44,6 +44,35 @@ properties:
       - 7 # 2.8 V
     default: 2
 
+  ti,debounce-release-ms:
+    description: key release debounce time in ms (datasheet section 9.6.7).
+    enum:
+      - 0  #  0 ms (0)
+      - 20 # 20 ms (1)
+    default: 20
+
+  ti,debounce-press-ms:
+    description: key press debounce time in ms (datasheet section 9.6.7).
+    enum:
+      - 2   #   2 ms (0)
+      - 40  #  40 ms (1)
+      - 80  #  80 ms (2)
+      - 120 # 120 ms (3)
+    default: 80
+
+  ti,debounce-insertion-ms:
+    description: headset insertion debounce time in ms (datasheet section 9.6.5).
+    enum:
+      - 2    #   2 ms (0)
+      - 30   #  30 ms (1)
+      - 60   #  60 ms (2)
+      - 90   #  90 ms (3)
+      - 120  # 120 ms (4)
+      - 150  # 150 ms (5)
+      - 1000 # 1 s    (6)
+      - 2000 # 2 s    (7)
+    default: 90
+
 required:
   - compatible
   - reg
-- 
2.20.1


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

* [PATCH v2 2/3] dt-bindings: sound: ts3a227e: add control of debounce times
@ 2022-09-15 11:39   ` Astrid Rost
  0 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid, Rob Herring
  Cc: devicetree, alsa-devel, Astrid Rost, linux-kernel, kernel, Astrid Rost

Add devicetree parameters to control the insertion, release and press
debounce times.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>
---
 .../devicetree/bindings/sound/ts3a227e.yaml   | 29 +++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.yaml b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
index 3512b1f1e32b..8c27f298733a 100644
--- a/Documentation/devicetree/bindings/sound/ts3a227e.yaml
+++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
@@ -44,6 +44,35 @@ properties:
       - 7 # 2.8 V
     default: 2
 
+  ti,debounce-release-ms:
+    description: key release debounce time in ms (datasheet section 9.6.7).
+    enum:
+      - 0  #  0 ms (0)
+      - 20 # 20 ms (1)
+    default: 20
+
+  ti,debounce-press-ms:
+    description: key press debounce time in ms (datasheet section 9.6.7).
+    enum:
+      - 2   #   2 ms (0)
+      - 40  #  40 ms (1)
+      - 80  #  80 ms (2)
+      - 120 # 120 ms (3)
+    default: 80
+
+  ti,debounce-insertion-ms:
+    description: headset insertion debounce time in ms (datasheet section 9.6.5).
+    enum:
+      - 2    #   2 ms (0)
+      - 30   #  30 ms (1)
+      - 60   #  60 ms (2)
+      - 90   #  90 ms (3)
+      - 120  # 120 ms (4)
+      - 150  # 150 ms (5)
+      - 1000 # 1 s    (6)
+      - 2000 # 2 s    (7)
+    default: 90
+
 required:
   - compatible
   - reg
-- 
2.20.1


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

* [PATCH v2 3/3] ASoC: ts3a227e: add parameters to control debounce times
  2022-09-15 11:39 ` Astrid Rost
@ 2022-09-15 11:39   ` Astrid Rost
  -1 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid,
	Jaroslav Kysela, Takashi Iwai
  Cc: kernel, alsa-devel, linux-kernel, Astrid Rost, Astrid Rost

Add devicetree parameters to control the insert, release and press
debounce times.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>
---
 sound/soc/codecs/ts3a227e.c | 58 +++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index d8ab0810fceb..f2d1367c46ca 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -78,12 +78,20 @@ static const int ts3a227e_buttons[] = {
 #define ADC_COMPLETE_INT_DISABLE 0x04
 #define INTB_DISABLE 0x08
 
+/* TS3A227E_REG_SETTING_1 0x4 */
+#define DEBOUNCE_INSERTION_SETTING_SFT (0)
+#define DEBOUNCE_INSERTION_SETTING_MASK (0x7 << DEBOUNCE_PRESS_SETTING_SFT)
+
 /* TS3A227E_REG_SETTING_2 0x05 */
 #define KP_ENABLE 0x04
 
 /* TS3A227E_REG_SETTING_3 0x06 */
-#define MICBIAS_SETTING_SFT (3)
+#define MICBIAS_SETTING_SFT 3
 #define MICBIAS_SETTING_MASK (0x7 << MICBIAS_SETTING_SFT)
+#define DEBOUNCE_RELEASE_SETTING_SFT 2
+#define DEBOUNCE_RELEASE_SETTING_MASK (0x1 << DEBOUNCE_RELEASE_SETTING_SFT)
+#define DEBOUNCE_PRESS_SETTING_SFT 0
+#define DEBOUNCE_PRESS_SETTING_MASK (0x3 << DEBOUNCE_PRESS_SETTING_SFT)
 
 /* TS3A227E_REG_ACCESSORY_STATUS  0x0b */
 #define TYPE_3_POLE 0x01
@@ -136,7 +144,7 @@ static bool ts3a227e_volatile_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
 	case TS3A227E_REG_INTERRUPT ... TS3A227E_REG_INTERRUPT_DISABLE:
-	case TS3A227E_REG_SETTING_2:
+	case TS3A227E_REG_SETTING_1 ... TS3A227E_REG_SETTING_2:
 	case TS3A227E_REG_SWITCH_STATUS_1 ... TS3A227E_REG_ADC_OUTPUT:
 		return true;
 	default:
@@ -269,14 +277,52 @@ static const struct regmap_config ts3a227e_regmap_config = {
 static int ts3a227e_parse_device_property(struct ts3a227e *ts3a227e,
 				struct device *dev)
 {
-	u32 micbias;
+	u32 value;
+	u32 value_ms;
+	u32 setting3_value = 0;
+	u32 setting3_mask = 0;
 	int err;
 
-	err = device_property_read_u32(dev, "ti,micbias", &micbias);
+	err = device_property_read_u32(dev, "ti,micbias", &value);
+	if (!err) {
+		setting3_mask = MICBIAS_SETTING_MASK;
+		setting3_value =
+			(value << MICBIAS_SETTING_SFT) & MICBIAS_SETTING_MASK;
+	}
+
+	err = device_property_read_u32(dev, "ti,debounce-release-ms", &value_ms);
 	if (!err) {
+		value = (value_ms > 10);
+		setting3_mask |= DEBOUNCE_RELEASE_SETTING_MASK;
+		setting3_value |= (value << DEBOUNCE_RELEASE_SETTING_SFT) &
+				  DEBOUNCE_RELEASE_SETTING_MASK;
+	}
+
+	err = device_property_read_u32(dev, "ti,debounce-press-ms", &value_ms);
+	if (!err) {
+		value = (value_ms + 20) / 40;
+		if (value > 3)
+			value = 3;
+		setting3_mask |= DEBOUNCE_PRESS_SETTING_MASK;
+		setting3_value |= (value << DEBOUNCE_PRESS_SETTING_SFT) &
+				  DEBOUNCE_PRESS_SETTING_MASK;
+	}
+
+	if (setting3_mask)
 		regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_3,
-			MICBIAS_SETTING_MASK,
-			(micbias & 0x07) << MICBIAS_SETTING_SFT);
+				   setting3_mask, setting3_value);
+
+	err = device_property_read_u32(dev, "ti,debounce-insertion-ms", &value_ms);
+	if (!err) {
+		if (value_ms < 165)
+			value = (value_ms + 15) / 30;
+		else if (value_ms < 1500)
+			value = 6;
+		else
+			value = 7;
+		regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_1,
+			DEBOUNCE_INSERTION_SETTING_MASK, (value << DEBOUNCE_INSERTION_SETTING_SFT)
+			& DEBOUNCE_INSERTION_SETTING_MASK);
 	}
 
 	return 0;
-- 
2.20.1


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

* [PATCH v2 3/3] ASoC: ts3a227e: add parameters to control debounce times
@ 2022-09-15 11:39   ` Astrid Rost
  0 siblings, 0 replies; 14+ messages in thread
From: Astrid Rost @ 2022-09-15 11:39 UTC (permalink / raw)
  To: Mark Brown, Liam Girdwood, Krzysztof Kozlowski, Dylan Reid,
	Jaroslav Kysela, Takashi Iwai
  Cc: Astrid Rost, kernel, Astrid Rost, alsa-devel, linux-kernel

Add devicetree parameters to control the insert, release and press
debounce times.

Signed-off-by: Astrid Rost <astrid.rost@axis.com>
---
 sound/soc/codecs/ts3a227e.c | 58 +++++++++++++++++++++++++++++++++----
 1 file changed, 52 insertions(+), 6 deletions(-)

diff --git a/sound/soc/codecs/ts3a227e.c b/sound/soc/codecs/ts3a227e.c
index d8ab0810fceb..f2d1367c46ca 100644
--- a/sound/soc/codecs/ts3a227e.c
+++ b/sound/soc/codecs/ts3a227e.c
@@ -78,12 +78,20 @@ static const int ts3a227e_buttons[] = {
 #define ADC_COMPLETE_INT_DISABLE 0x04
 #define INTB_DISABLE 0x08
 
+/* TS3A227E_REG_SETTING_1 0x4 */
+#define DEBOUNCE_INSERTION_SETTING_SFT (0)
+#define DEBOUNCE_INSERTION_SETTING_MASK (0x7 << DEBOUNCE_PRESS_SETTING_SFT)
+
 /* TS3A227E_REG_SETTING_2 0x05 */
 #define KP_ENABLE 0x04
 
 /* TS3A227E_REG_SETTING_3 0x06 */
-#define MICBIAS_SETTING_SFT (3)
+#define MICBIAS_SETTING_SFT 3
 #define MICBIAS_SETTING_MASK (0x7 << MICBIAS_SETTING_SFT)
+#define DEBOUNCE_RELEASE_SETTING_SFT 2
+#define DEBOUNCE_RELEASE_SETTING_MASK (0x1 << DEBOUNCE_RELEASE_SETTING_SFT)
+#define DEBOUNCE_PRESS_SETTING_SFT 0
+#define DEBOUNCE_PRESS_SETTING_MASK (0x3 << DEBOUNCE_PRESS_SETTING_SFT)
 
 /* TS3A227E_REG_ACCESSORY_STATUS  0x0b */
 #define TYPE_3_POLE 0x01
@@ -136,7 +144,7 @@ static bool ts3a227e_volatile_reg(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
 	case TS3A227E_REG_INTERRUPT ... TS3A227E_REG_INTERRUPT_DISABLE:
-	case TS3A227E_REG_SETTING_2:
+	case TS3A227E_REG_SETTING_1 ... TS3A227E_REG_SETTING_2:
 	case TS3A227E_REG_SWITCH_STATUS_1 ... TS3A227E_REG_ADC_OUTPUT:
 		return true;
 	default:
@@ -269,14 +277,52 @@ static const struct regmap_config ts3a227e_regmap_config = {
 static int ts3a227e_parse_device_property(struct ts3a227e *ts3a227e,
 				struct device *dev)
 {
-	u32 micbias;
+	u32 value;
+	u32 value_ms;
+	u32 setting3_value = 0;
+	u32 setting3_mask = 0;
 	int err;
 
-	err = device_property_read_u32(dev, "ti,micbias", &micbias);
+	err = device_property_read_u32(dev, "ti,micbias", &value);
+	if (!err) {
+		setting3_mask = MICBIAS_SETTING_MASK;
+		setting3_value =
+			(value << MICBIAS_SETTING_SFT) & MICBIAS_SETTING_MASK;
+	}
+
+	err = device_property_read_u32(dev, "ti,debounce-release-ms", &value_ms);
 	if (!err) {
+		value = (value_ms > 10);
+		setting3_mask |= DEBOUNCE_RELEASE_SETTING_MASK;
+		setting3_value |= (value << DEBOUNCE_RELEASE_SETTING_SFT) &
+				  DEBOUNCE_RELEASE_SETTING_MASK;
+	}
+
+	err = device_property_read_u32(dev, "ti,debounce-press-ms", &value_ms);
+	if (!err) {
+		value = (value_ms + 20) / 40;
+		if (value > 3)
+			value = 3;
+		setting3_mask |= DEBOUNCE_PRESS_SETTING_MASK;
+		setting3_value |= (value << DEBOUNCE_PRESS_SETTING_SFT) &
+				  DEBOUNCE_PRESS_SETTING_MASK;
+	}
+
+	if (setting3_mask)
 		regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_3,
-			MICBIAS_SETTING_MASK,
-			(micbias & 0x07) << MICBIAS_SETTING_SFT);
+				   setting3_mask, setting3_value);
+
+	err = device_property_read_u32(dev, "ti,debounce-insertion-ms", &value_ms);
+	if (!err) {
+		if (value_ms < 165)
+			value = (value_ms + 15) / 30;
+		else if (value_ms < 1500)
+			value = 6;
+		else
+			value = 7;
+		regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_1,
+			DEBOUNCE_INSERTION_SETTING_MASK, (value << DEBOUNCE_INSERTION_SETTING_SFT)
+			& DEBOUNCE_INSERTION_SETTING_MASK);
 	}
 
 	return 0;
-- 
2.20.1


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

* Re: [PATCH v2 1/3] dt-bindings: sound: ts3a227e: convert to yaml
  2022-09-15 11:39   ` Astrid Rost
@ 2022-09-18  9:50     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-18  9:50 UTC (permalink / raw)
  To: Astrid Rost, Mark Brown, Liam Girdwood, Krzysztof Kozlowski,
	Dylan Reid, Rob Herring
  Cc: Astrid Rost, kernel, alsa-devel, devicetree, linux-kernel

On 15/09/2022 12:39, Astrid Rost wrote:
> Convert from ts3a227e.txt to yaml.
> 
> Signed-off-by: Astrid Rost <astrid.rost@axis.com>

Thank you for your patch. There is something to discuss/improve.

> ---
>  .../devicetree/bindings/sound/ts3a227e.txt    | 30 --------
>  .../devicetree/bindings/sound/ts3a227e.yaml   | 69 +++++++++++++++++++
>  2 files changed, 69 insertions(+), 30 deletions(-)


> --- /dev/null
> +++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> @@ -0,0 +1,69 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: "http://devicetree.org/schemas/sound/ts3a227e.yaml#"


Filename based on compatible, so ti,ts3a227e.yaml

> +$schema: "http://devicetree.org/meta-schemas/core.yaml#"

Drop quotes from both lines above.

> +
> +title: Texas Instruments TS3A227E
> +  Autonomous Audio Accessory Detection and Configuration Switch
> +
> +maintainers:
> +  - Dylan Reid <dgreid@chromium.org>
> +
> +description: |
> +  The TS3A227E detect headsets of 3-ring and 4-ring standards and
> +  switches automatically to route the microphone correctly. It also
> +  handles key press detection in accordance with the Android audio
> +  headset specification v1.0.
> +
> +properties:
> +  compatible:
> +    enum:
> +      - ti,ts3a227e
> +
> +  reg:
> +    description: I2C address of the device.

Skip description, it's obvious.

> +    const: 0x3b
> +
> +  interrupts:
> +    maxItems: 1
> +    description: |
> +      Interrupt number for /INT pin from the ts3a227e.

Skip description

> +
> +  ti,micbias:
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    description: Intended MICBIAS voltage (datasheet section 9.6.7).
> +    enum:
> +      - 0 # 2.1 V
> +      - 1 # 2.2 V
> +      - 2 # 2.3 V
> +      - 3 # 2.4 V
> +      - 4 # 2.5 V
> +      - 5 # 2.6 V
> +      - 6 # 2.7 V
> +      - 7 # 2.8 V
> +    default: 2

Old bindings said default is 1. It this was intended, please mention in
commit msg deviations from pure conversion.

> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>

This header is not used.

> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    i2c0 {

Node name just "i2c"

> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +        codec: ts3a227e@3b {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

audio-controller? audio-switch?

> +            compatible = "ti,ts3a227e";
> +            reg = <0x3b>;
> +            interrupt-parent = <&gpio1>;
> +            interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
> +        };
> +    };
> +
> +...


Best regards,
Krzysztof

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

* Re: [PATCH v2 1/3] dt-bindings: sound: ts3a227e: convert to yaml
@ 2022-09-18  9:50     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-18  9:50 UTC (permalink / raw)
  To: Astrid Rost, Mark Brown, Liam Girdwood, Krzysztof Kozlowski,
	Dylan Reid, Rob Herring
  Cc: kernel, alsa-devel, linux-kernel, Astrid Rost, devicetree

On 15/09/2022 12:39, Astrid Rost wrote:
> Convert from ts3a227e.txt to yaml.
> 
> Signed-off-by: Astrid Rost <astrid.rost@axis.com>

Thank you for your patch. There is something to discuss/improve.

> ---
>  .../devicetree/bindings/sound/ts3a227e.txt    | 30 --------
>  .../devicetree/bindings/sound/ts3a227e.yaml   | 69 +++++++++++++++++++
>  2 files changed, 69 insertions(+), 30 deletions(-)


> --- /dev/null
> +++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> @@ -0,0 +1,69 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: "http://devicetree.org/schemas/sound/ts3a227e.yaml#"


Filename based on compatible, so ti,ts3a227e.yaml

> +$schema: "http://devicetree.org/meta-schemas/core.yaml#"

Drop quotes from both lines above.

> +
> +title: Texas Instruments TS3A227E
> +  Autonomous Audio Accessory Detection and Configuration Switch
> +
> +maintainers:
> +  - Dylan Reid <dgreid@chromium.org>
> +
> +description: |
> +  The TS3A227E detect headsets of 3-ring and 4-ring standards and
> +  switches automatically to route the microphone correctly. It also
> +  handles key press detection in accordance with the Android audio
> +  headset specification v1.0.
> +
> +properties:
> +  compatible:
> +    enum:
> +      - ti,ts3a227e
> +
> +  reg:
> +    description: I2C address of the device.

Skip description, it's obvious.

> +    const: 0x3b
> +
> +  interrupts:
> +    maxItems: 1
> +    description: |
> +      Interrupt number for /INT pin from the ts3a227e.

Skip description

> +
> +  ti,micbias:
> +    $ref: /schemas/types.yaml#/definitions/uint32
> +    description: Intended MICBIAS voltage (datasheet section 9.6.7).
> +    enum:
> +      - 0 # 2.1 V
> +      - 1 # 2.2 V
> +      - 2 # 2.3 V
> +      - 3 # 2.4 V
> +      - 4 # 2.5 V
> +      - 5 # 2.6 V
> +      - 6 # 2.7 V
> +      - 7 # 2.8 V
> +    default: 2

Old bindings said default is 1. It this was intended, please mention in
commit msg deviations from pure conversion.

> +
> +required:
> +  - compatible
> +  - reg
> +  - interrupts
> +
> +additionalProperties: false
> +
> +examples:
> +  - |
> +    #include <dt-bindings/gpio/gpio.h>

This header is not used.

> +    #include <dt-bindings/interrupt-controller/irq.h>
> +    i2c0 {

Node name just "i2c"

> +        #address-cells = <1>;
> +        #size-cells = <0>;
> +        codec: ts3a227e@3b {

Node names should be generic.
https://devicetree-specification.readthedocs.io/en/latest/chapter2-devicetree-basics.html#generic-names-recommendation

audio-controller? audio-switch?

> +            compatible = "ti,ts3a227e";
> +            reg = <0x3b>;
> +            interrupt-parent = <&gpio1>;
> +            interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
> +        };
> +    };
> +
> +...


Best regards,
Krzysztof

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

* Re: [PATCH v2 2/3] dt-bindings: sound: ts3a227e: add control of debounce times
  2022-09-15 11:39   ` Astrid Rost
@ 2022-09-18  9:51     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-18  9:51 UTC (permalink / raw)
  To: Astrid Rost, Mark Brown, Liam Girdwood, Krzysztof Kozlowski,
	Dylan Reid, Rob Herring
  Cc: Astrid Rost, kernel, alsa-devel, devicetree, linux-kernel

On 15/09/2022 12:39, Astrid Rost wrote:
> Add devicetree parameters to control the insertion, release and press
> debounce times.
> 

Thank you for your patch. There is something to discuss/improve.

> Signed-off-by: Astrid Rost <astrid.rost@axis.com>
> ---
>  .../devicetree/bindings/sound/ts3a227e.yaml   | 29 +++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.yaml b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> index 3512b1f1e32b..8c27f298733a 100644
> --- a/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> +++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> @@ -44,6 +44,35 @@ properties:
>        - 7 # 2.8 V
>      default: 2
>  
> +  ti,debounce-release-ms:
> +    description: key release debounce time in ms (datasheet section 9.6.7).
> +    enum:
> +      - 0  #  0 ms (0)
> +      - 20 # 20 ms (1)

Skip comments. The values are in ms, so they are not helping.

Same in all other places.

> +    default: 20

Except that looks ok, thanks for the changes. Appreciated!


Best regards,
Krzysztof

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

* Re: [PATCH v2 2/3] dt-bindings: sound: ts3a227e: add control of debounce times
@ 2022-09-18  9:51     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 14+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-18  9:51 UTC (permalink / raw)
  To: Astrid Rost, Mark Brown, Liam Girdwood, Krzysztof Kozlowski,
	Dylan Reid, Rob Herring
  Cc: kernel, alsa-devel, linux-kernel, Astrid Rost, devicetree

On 15/09/2022 12:39, Astrid Rost wrote:
> Add devicetree parameters to control the insertion, release and press
> debounce times.
> 

Thank you for your patch. There is something to discuss/improve.

> Signed-off-by: Astrid Rost <astrid.rost@axis.com>
> ---
>  .../devicetree/bindings/sound/ts3a227e.yaml   | 29 +++++++++++++++++++
>  1 file changed, 29 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/sound/ts3a227e.yaml b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> index 3512b1f1e32b..8c27f298733a 100644
> --- a/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> +++ b/Documentation/devicetree/bindings/sound/ts3a227e.yaml
> @@ -44,6 +44,35 @@ properties:
>        - 7 # 2.8 V
>      default: 2
>  
> +  ti,debounce-release-ms:
> +    description: key release debounce time in ms (datasheet section 9.6.7).
> +    enum:
> +      - 0  #  0 ms (0)
> +      - 20 # 20 ms (1)

Skip comments. The values are in ms, so they are not helping.

Same in all other places.

> +    default: 20

Except that looks ok, thanks for the changes. Appreciated!


Best regards,
Krzysztof

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

* Re: [PATCH v2 0/3] ASoC: ts3a227e control debounce times
  2022-09-15 11:39 ` Astrid Rost
@ 2022-09-19 16:58   ` Mark Brown
  -1 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2022-09-19 16:58 UTC (permalink / raw)
  To: Astrid Rost
  Cc: Liam Girdwood, Krzysztof Kozlowski, Dylan Reid, kernel,
	alsa-devel, linux-kernel, Astrid Rost

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

On Thu, Sep 15, 2022 at 01:39:52PM +0200, Astrid Rost wrote:
> From: Astrid Rost <astridr@axis.com>
> 
> PATCH 1 - convert ts3a227e bindings to yaml.
> PATCH 2 - add ts3a227e bindings to support debounce times.
> PATCH 3 - add ts3a227e driver to support debounce times.

In general it's better to put new features before binding
conversions, the binding conversions can require more work than
simple feature additions.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: [PATCH v2 0/3] ASoC: ts3a227e control debounce times
@ 2022-09-19 16:58   ` Mark Brown
  0 siblings, 0 replies; 14+ messages in thread
From: Mark Brown @ 2022-09-19 16:58 UTC (permalink / raw)
  To: Astrid Rost
  Cc: alsa-devel, Liam Girdwood, linux-kernel, kernel,
	Krzysztof Kozlowski, Dylan Reid, Astrid Rost

[-- Attachment #1: Type: text/plain, Size: 429 bytes --]

On Thu, Sep 15, 2022 at 01:39:52PM +0200, Astrid Rost wrote:
> From: Astrid Rost <astridr@axis.com>
> 
> PATCH 1 - convert ts3a227e bindings to yaml.
> PATCH 2 - add ts3a227e bindings to support debounce times.
> PATCH 3 - add ts3a227e driver to support debounce times.

In general it's better to put new features before binding
conversions, the binding conversions can require more work than
simple feature additions.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2022-09-19 16:59 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-15 11:39 [PATCH v2 0/3] ASoC: ts3a227e control debounce times Astrid Rost
2022-09-15 11:39 ` Astrid Rost
2022-09-15 11:39 ` [PATCH v2 1/3] dt-bindings: sound: ts3a227e: convert to yaml Astrid Rost
2022-09-15 11:39   ` Astrid Rost
2022-09-18  9:50   ` Krzysztof Kozlowski
2022-09-18  9:50     ` Krzysztof Kozlowski
2022-09-15 11:39 ` [PATCH v2 2/3] dt-bindings: sound: ts3a227e: add control of debounce times Astrid Rost
2022-09-15 11:39   ` Astrid Rost
2022-09-18  9:51   ` Krzysztof Kozlowski
2022-09-18  9:51     ` Krzysztof Kozlowski
2022-09-15 11:39 ` [PATCH v2 3/3] ASoC: ts3a227e: add parameters to control " Astrid Rost
2022-09-15 11:39   ` Astrid Rost
2022-09-19 16:58 ` [PATCH v2 0/3] ASoC: ts3a227e " Mark Brown
2022-09-19 16:58   ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.