extcon: madera: Report accessory detect events through input key events
authorStuart Henderson <stuarth@opensource.wolfsonmicro.com>
Thu, 27 Apr 2017 09:49:34 +0000 (10:49 +0100)
committerCosmin Tanislav <demonsingur@gmail.com>
Mon, 22 Apr 2024 17:22:27 +0000 (20:22 +0300)
Change-Id: I1120594bc9f36efba6111c033eb9c1201ed8ea5b
Signed-off-by: Stuart Henderson <stuarth@opensource.wolfsonmicro.com>
drivers/extcon/Kconfig
drivers/extcon/extcon-madera.c

index f70fffbb3d70fd1c884c3d804a5bcd875ca8844b..c77a9c2e23aa787e94bde363ffd93da783ac5816 100644 (file)
@@ -66,6 +66,15 @@ config EXTCON_MADERA
          Say Y here to enable support for external accessory detection
          on Cirrus Logic Madera class codecs.
 
+config EXTCON_MADERA_INPUT_EVENT
+       bool "Report events through input key events"
+       depends on EXTCON_MADERA
+       default n
+       help
+         Say Y here to enable support for reporting external accessory
+         detection events through input key events on Cirrus Logic Madera
+         class codecs.
+
 config EXTCON_MAX14577
        tristate "Maxim MAX14577/77836 EXTCON Support"
        depends on MFD_MAX14577
index a0a565b3dc9380682ce2aaec8e98d3fe73ee5710..eb933c9f7a655404b8498dfaf78aed9c3597e268 100644 (file)
@@ -519,14 +519,33 @@ inline void madera_extcon_report(struct madera_extcon *info,
        int ret;
 
        dev_dbg(info->dev, "Extcon report: %d is %s\n",
-               which,
-               attached ? "attached" : "removed");
+               which, attached ? "attached" : "removed");
 
        ret = extcon_set_state_sync(info->edev, which, attached);
        if (ret != 0)
-               dev_warn(info->dev,
-                        "Failed to report cable state: %d\n",
-                        ret);
+               dev_warn(info->dev, "Failed to report cable state: %d\n", ret);
+
+       if (IS_ENABLED(CONFIG_EXTCON_MADERA_INPUT_EVENT)) {
+               switch (which) {
+               case EXTCON_MECHANICAL:
+                       input_report_switch(info->input,
+                                           SW_JACK_PHYSICAL_INSERT,
+                                           attached);
+                       break;
+               case EXTCON_JACK_HEADPHONE:
+                       input_report_switch(info->input,
+                                           SW_HEADPHONE_INSERT,
+                                           attached);
+                       break;
+               case EXTCON_JACK_MICROPHONE:
+                       input_report_switch(info->input,
+                                           SW_MICROPHONE_INSERT,
+                                           attached);
+                       break;
+               }
+
+               input_sync(info->input);
+       }
 }
 EXPORT_SYMBOL_GPL(madera_extcon_report);
 
@@ -3122,6 +3141,18 @@ static int madera_extcon_probe(struct platform_device *pdev)
 
        pm_runtime_put(&pdev->dev);
 
+       if (IS_ENABLED(CONFIG_EXTCON_MADERA_INPUT_EVENT)) {
+               input_set_capability(info->input,
+                                    EV_SW,
+                                    SW_MICROPHONE_INSERT);
+               input_set_capability(info->input,
+                                    EV_SW,
+                                    SW_HEADPHONE_INSERT);
+               input_set_capability(info->input,
+                                    EV_SW,
+                                    SW_JACK_PHYSICAL_INSERT);
+       }
+
        ret = input_register_device(info->input);
        if (ret) {
                dev_err(&pdev->dev, "Can't register input device: %d\n", ret);