Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: ts3a227e control debounce times

Merge series from Astrid Rost <astrid.rost@axis.com>:

Add debounce support to the ts3a227e driver.

+149 -36
+94
Documentation/devicetree/bindings/sound/ti,ts3a227e.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/sound/ti,ts3a227e.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Texas Instruments TS3A227E 8 + Autonomous Audio Accessory Detection and Configuration Switch 9 + 10 + maintainers: 11 + - Dylan Reid <dgreid@chromium.org> 12 + 13 + description: | 14 + The TS3A227E detect headsets of 3-ring and 4-ring standards and 15 + switches automatically to route the microphone correctly. It also 16 + handles key press detection in accordance with the Android audio 17 + headset specification v1.0. 18 + 19 + properties: 20 + compatible: 21 + enum: 22 + - ti,ts3a227e 23 + 24 + reg: 25 + const: 0x3b 26 + 27 + interrupts: 28 + maxItems: 1 29 + 30 + ti,micbias: 31 + $ref: /schemas/types.yaml#/definitions/uint32 32 + description: Intended MICBIAS voltage (datasheet section 9.6.7). 33 + enum: 34 + - 0 # 2.1 V 35 + - 1 # 2.2 V 36 + - 2 # 2.3 V 37 + - 3 # 2.4 V 38 + - 4 # 2.5 V 39 + - 5 # 2.6 V 40 + - 6 # 2.7 V 41 + - 7 # 2.8 V 42 + default: 1 43 + 44 + ti,debounce-release-ms: 45 + description: key release debounce time in ms (datasheet section 9.6.7). 46 + enum: 47 + - 0 48 + - 20 49 + default: 20 50 + 51 + ti,debounce-press-ms: 52 + description: key press debounce time in ms (datasheet section 9.6.7). 53 + enum: 54 + - 2 55 + - 40 56 + - 80 57 + - 120 58 + default: 80 59 + 60 + ti,debounce-insertion-ms: 61 + description: headset insertion debounce time in ms (datasheet section 9.6.5). 62 + enum: 63 + - 2 64 + - 30 65 + - 60 66 + - 90 67 + - 120 68 + - 150 69 + - 1000 70 + - 2000 71 + default: 90 72 + 73 + required: 74 + - compatible 75 + - reg 76 + - interrupts 77 + 78 + additionalProperties: false 79 + 80 + examples: 81 + - | 82 + #include <dt-bindings/interrupt-controller/irq.h> 83 + i2c { 84 + #address-cells = <1>; 85 + #size-cells = <0>; 86 + codec: audio-controller@3b { 87 + compatible = "ti,ts3a227e"; 88 + reg = <0x3b>; 89 + interrupt-parent = <&gpio1>; 90 + interrupts = <3 IRQ_TYPE_LEVEL_LOW>; 91 + }; 92 + }; 93 + 94 + ...
-30
Documentation/devicetree/bindings/sound/ts3a227e.txt
··· 1 - Texas Instruments TS3A227E 2 - Autonomous Audio Accessory Detection and Configuration Switch 3 - 4 - The TS3A227E detect headsets of 3-ring and 4-ring standards and 5 - switches automatically to route the microphone correctly. It also 6 - handles key press detection in accordance with the Android audio 7 - headset specification v1.0. 8 - 9 - Required properties: 10 - 11 - - compatible: Should contain "ti,ts3a227e". 12 - - reg: The i2c address. Should contain <0x3b>. 13 - - interrupts: Interrupt number for /INT pin from the 227e 14 - 15 - Optional properies: 16 - - ti,micbias: Intended MICBIAS voltage (datasheet section 9.6.7). 17 - Select 0/1/2/3/4/5/6/7 to specify MICBIAS voltage 18 - 2.1V/2.2V/2.3V/2.4V/2.5V/2.6V/2.7V/2.8V 19 - Default value is "1" (2.2V). 20 - 21 - Examples: 22 - 23 - i2c { 24 - ts3a227e@3b { 25 - compatible = "ti,ts3a227e"; 26 - reg = <0x3b>; 27 - interrupt-parent = <&gpio>; 28 - interrupts = <3 IRQ_TYPE_LEVEL_LOW>; 29 - }; 30 - };
+55 -6
sound/soc/codecs/ts3a227e.c
··· 78 78 #define ADC_COMPLETE_INT_DISABLE 0x04 79 79 #define INTB_DISABLE 0x08 80 80 81 + /* TS3A227E_REG_SETTING_1 0x4 */ 82 + #define DEBOUNCE_INSERTION_SETTING_SFT (0) 83 + #define DEBOUNCE_INSERTION_SETTING_MASK (0x7 << DEBOUNCE_PRESS_SETTING_SFT) 84 + 81 85 /* TS3A227E_REG_SETTING_2 0x05 */ 82 86 #define KP_ENABLE 0x04 83 87 84 88 /* TS3A227E_REG_SETTING_3 0x06 */ 85 - #define MICBIAS_SETTING_SFT (3) 89 + #define MICBIAS_SETTING_SFT 3 86 90 #define MICBIAS_SETTING_MASK (0x7 << MICBIAS_SETTING_SFT) 91 + #define DEBOUNCE_RELEASE_SETTING_SFT 2 92 + #define DEBOUNCE_RELEASE_SETTING_MASK (0x1 << DEBOUNCE_RELEASE_SETTING_SFT) 93 + #define DEBOUNCE_PRESS_SETTING_SFT 0 94 + #define DEBOUNCE_PRESS_SETTING_MASK (0x3 << DEBOUNCE_PRESS_SETTING_SFT) 87 95 88 96 /* TS3A227E_REG_ACCESSORY_STATUS 0x0b */ 89 97 #define TYPE_3_POLE 0x01 ··· 144 136 { 145 137 switch (reg) { 146 138 case TS3A227E_REG_INTERRUPT ... TS3A227E_REG_INTERRUPT_DISABLE: 147 - case TS3A227E_REG_SETTING_2: 139 + case TS3A227E_REG_SETTING_1 ... TS3A227E_REG_SETTING_2: 148 140 case TS3A227E_REG_SWITCH_STATUS_1 ... TS3A227E_REG_ADC_OUTPUT: 149 141 return true; 150 142 default: ··· 277 269 static int ts3a227e_parse_device_property(struct ts3a227e *ts3a227e, 278 270 struct device *dev) 279 271 { 280 - u32 micbias; 272 + u32 value; 273 + u32 value_ms; 274 + u32 setting3_value = 0; 275 + u32 setting3_mask = 0; 281 276 int err; 282 277 283 - err = device_property_read_u32(dev, "ti,micbias", &micbias); 278 + err = device_property_read_u32(dev, "ti,micbias", &value); 284 279 if (!err) { 280 + setting3_mask = MICBIAS_SETTING_MASK; 281 + setting3_value = (value << MICBIAS_SETTING_SFT) & 282 + MICBIAS_SETTING_MASK; 283 + } 284 + 285 + err = device_property_read_u32(dev, "ti,debounce-release-ms", 286 + &value_ms); 287 + if (!err) { 288 + value = (value_ms > 10); 289 + setting3_mask |= DEBOUNCE_RELEASE_SETTING_MASK; 290 + setting3_value |= (value << DEBOUNCE_RELEASE_SETTING_SFT) & 291 + DEBOUNCE_RELEASE_SETTING_MASK; 292 + } 293 + 294 + err = device_property_read_u32(dev, "ti,debounce-press-ms", &value_ms); 295 + if (!err) { 296 + value = (value_ms + 20) / 40; 297 + if (value > 3) 298 + value = 3; 299 + setting3_mask |= DEBOUNCE_PRESS_SETTING_MASK; 300 + setting3_value |= (value << DEBOUNCE_PRESS_SETTING_SFT) & 301 + DEBOUNCE_PRESS_SETTING_MASK; 302 + } 303 + 304 + if (setting3_mask) 285 305 regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_3, 286 - MICBIAS_SETTING_MASK, 287 - (micbias & 0x07) << MICBIAS_SETTING_SFT); 306 + setting3_mask, setting3_value); 307 + 308 + err = device_property_read_u32(dev, "ti,debounce-insertion-ms", 309 + &value_ms); 310 + if (!err) { 311 + if (value_ms < 165) 312 + value = (value_ms + 15) / 30; 313 + else if (value_ms < 1500) 314 + value = 6; 315 + else 316 + value = 7; 317 + regmap_update_bits(ts3a227e->regmap, TS3A227E_REG_SETTING_1, 318 + DEBOUNCE_INSERTION_SETTING_MASK, 319 + (value << DEBOUNCE_INSERTION_SETTING_SFT) & 320 + DEBOUNCE_INSERTION_SETTING_MASK); 288 321 } 289 322 290 323 return 0;