dell_wmi_helper.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Helper functions for Dell Mic Mute LED control;
  2. * to be included from codec driver
  3. */
  4. #if IS_ENABLED(CONFIG_LEDS_DELL_NETBOOKS)
  5. #include <linux/dell-led.h>
  6. static int dell_led_value;
  7. static int (*dell_led_set_func)(int, int);
  8. static void (*dell_old_cap_hook)(struct hda_codec *,
  9. struct snd_kcontrol *,
  10. struct snd_ctl_elem_value *);
  11. static void update_dell_wmi_micmute_led(struct hda_codec *codec,
  12. struct snd_kcontrol *kcontrol,
  13. struct snd_ctl_elem_value *ucontrol)
  14. {
  15. if (dell_old_cap_hook)
  16. dell_old_cap_hook(codec, kcontrol, ucontrol);
  17. if (!ucontrol || !dell_led_set_func)
  18. return;
  19. if (strcmp("Capture Switch", ucontrol->id.name) == 0 && ucontrol->id.index == 0) {
  20. /* TODO: How do I verify if it's a mono or stereo here? */
  21. int val = (ucontrol->value.integer.value[0] || ucontrol->value.integer.value[1]) ? 0 : 1;
  22. if (val == dell_led_value)
  23. return;
  24. dell_led_value = val;
  25. if (dell_led_set_func)
  26. dell_led_set_func(DELL_LED_MICMUTE, dell_led_value);
  27. }
  28. }
  29. static void alc_fixup_dell_wmi(struct hda_codec *codec,
  30. const struct hda_fixup *fix, int action)
  31. {
  32. struct alc_spec *spec = codec->spec;
  33. bool removefunc = false;
  34. if (action == HDA_FIXUP_ACT_PROBE) {
  35. if (!dell_led_set_func)
  36. dell_led_set_func = symbol_request(dell_app_wmi_led_set);
  37. if (!dell_led_set_func) {
  38. codec_warn(codec, "Failed to find dell wmi symbol dell_app_wmi_led_set\n");
  39. return;
  40. }
  41. removefunc = true;
  42. if (dell_led_set_func(DELL_LED_MICMUTE, false) >= 0) {
  43. dell_led_value = 0;
  44. if (spec->gen.num_adc_nids > 1)
  45. codec_dbg(codec, "Skipping micmute LED control due to several ADCs");
  46. else {
  47. dell_old_cap_hook = spec->gen.cap_sync_hook;
  48. spec->gen.cap_sync_hook = update_dell_wmi_micmute_led;
  49. removefunc = false;
  50. }
  51. }
  52. }
  53. if (dell_led_set_func && (action == HDA_FIXUP_ACT_FREE || removefunc)) {
  54. symbol_put(dell_app_wmi_led_set);
  55. dell_led_set_func = NULL;
  56. dell_old_cap_hook = NULL;
  57. }
  58. }
  59. #else /* CONFIG_LEDS_DELL_NETBOOKS */
  60. static void alc_fixup_dell_wmi(struct hda_codec *codec,
  61. const struct hda_fixup *fix, int action)
  62. {
  63. }
  64. #endif /* CONFIG_LEDS_DELL_NETBOOKS */