27

I have a mic mute button on my Lenovo Thinkpad T420 , but it doesn't work.

So I tried xev command to monitor press event, and that key wasn't captured.

Is there anyway to fix it , like add raw key code ?

OS & Laptop

Ubuntu 12.04 , also hope it works on Arch Linux , but doesn't matter much ;-P

Thinkpad Module: X220 4290LY9

Kernel patch for Arch Linux

Download Here

FINALLY

It's a little tricky , but with the kernel patch and acpid script , it works now.

The rest I need is a notify daemon like the one for output mute , but it doesn't matter much now.

Braiam
  • 67,791
  • 32
  • 179
  • 269
daisy
  • 6,582

3 Answers3

35

This solution should work for all Thinkpads with a mute button which also has a built-in light. It may also work for other Thinkpads.

Apart from the notification bubbles:

enter image description hereenter image description here

There are two possible "hardware" indicators (to show that mute is on or off):

  1. The Power button light (green) will blink to show when mute is on
  2. The Mic mute button light (orange) will be on or off to show mute status (just like in Windows)

    Solution 2 requires a patched thinkpad_acpi kernel module, and is only recommended for advanced users who know what they are doing. This is because the patch is not included by the thinkpad_acpi developers by default, (See this discussion for more details).

Common Steps


a. Determining the Mic-Mute hotkey code and Mic input device

  • Open terminal with Ctrl+Alt+T
  • Run acpi_listen, and press the mute key
  • Note the result, which should be something like: ibm/hotkey HKEY 00000080 0000101b

  • Then run amixer scontrols, you should see one of the following in the output:

Simple mixer control 'Internal Mic',0

or

Simple mixer control 'Capture',0

Depending on what you see, "Internal Mic" or "Capture" is your input device.

b. Create the Mic-Mute ACPI event handler

  • Open terminal, type gksudo gedit /etc/acpi/events/lenovo-mutemic to open the editor.
  • In the editor, paste in the following, where the first line should be the code shown in the previous section by acpi_listen:
    event=ibm/hotkey HKEY 00000080 0000101b
    action=/etc/acpi/lenovo-mutemic.sh
    
  • Save and exit the editor.

Choosing either the Power Light or Mic Mute indicators


c-1. Mic-Mute script with Power Button indicator

  • Do this if you want an easy solution and do not want to use the patched kernel module (see C-2).
  • Open terminal, type gksudo gedit /etc/acpi/lenovo-mutemic.sh
  • In the editor, paste:

    #!/bin/bash
    INPUT_DEVICE="'Internal Mic'"
    YOUR_USERNAME="place_your_username_here"
    if amixer sget $INPUT_DEVICE,0 | grep '\[on\]' ; then
        amixer sset $INPUT_DEVICE,0 toggle
        echo "0 blink" > /proc/acpi/ibm/led
        su $YOUR_USERNAME -c 'DISPLAY=":0.0" notify-send -t 50 \
                -i microphone-sensitivity-muted-symbolic "Mic MUTED"'
    else
        amixer sset $INPUT_DEVICE,0 toggle                       
        su $YOUR_USERNAME -c 'DISPLAY=":0.0" notify-send -t 50 \
                -i microphone-sensitivity-high-symbolic "Mic ON"'
        echo "0 on" > /proc/acpi/ibm/led 
    fi
    
  • Replace value of INPUT_DEVICE variable with Capture if that is your input device name (leave all the ticks intact).

  • Replace value of YOUR_USERNAME variable with the account name of the user you want to send notifications to
  • Save and exit the editor.
  • Now run the following (from the terminal):
    sudo chmod +x /etc/acpi/lenovo-mutemic.sh
    sudo service acpid restart
    
  • Jump to the Testing section (d) to confirm that it works.

c-2. Mic-mute with official Mic-mute Indicator Light

Setting up the script

  • Please do not use this method if you are not familiar with the terminal/shell.
  • This will require compiling a patched thinkpad_acpi module and has been verified to work with Ubuntu Precise 12.04 and Quantal 12.10, kernels 3.2.0-23 and 3.2.0-24 and 3.5.0-21.
  • Let's create the script first: /etc/acpi/lenovo-mutemic.sh should be as in section c-1, with the following additions:

  • Insert this line after the header (#!/bin/bash):

    MICMUTE=/sys/devices/platform/thinkpad_acpi/leds/tpacpi::micmute/brightness
    
  • After the first echo... line, insert:

    echo 1 > $MICMUTE
    
  • And after the second echo... line, insert:

    echo 0 > $MICMUTE
    
  • You can find an example of what the full script should look like in this paste

  • Then:

    sudo chmod +x /etc/acpi/lenovo-mutemic.sh
    sudo service acpid restart
    
  • Confirm that pressing the mute button results in a blinking power light; pressing again gives a steady power light.

Building, testing and installing the kernel module

  • Install (or ensure) you have the headers and built tools for your currently running kernel with:

    sudo apt-get install linux-headers-$(uname -r) build-essential
    
  • Make a temporary directory and change to it:

    mkdir ~/tpacpi && cd ~/tpacpi
    
  • Download the source file thinkpad_acpi.c from the Ubuntu Kernel git repository:

    wget -Othinkpad_acpi.c "http://kernel.ubuntu.com/git?p=ubuntu/ubuntu-$(lsb_release -sc).git;\
    a=blob_plain;f=drivers/platform/x86/thinkpad_acpi.c;hb=HEAD" 
    
  • Patch it with (copy and paste the full line):

    sed -i -e 's/"tpacpi::thinkvantage",/"tpacpi::thinkvantage",\n\t"tpacpi::unknown_led4",\n\t"tpacpi::micmute",/g' -e 's/0x1081U/0x5081U/g' -e 's/0x1fffU/0x5fffU/g' thinkpad_acpi.c
    
  • In the same folder where thinkpad_acpi.c has been downloaded, you will need a "Makefile". You can download it directly from this Pastebin, using:

    wget -OMakefile http://pastebin.com/raw.php?i=ybpnxeUT
    

    OR paste the below into a file called Makefile:

    obj-m += thinkpad_acpi.o
    all: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    clean: make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
  • Now type make to create the module; you will see a thinkpad_acpi.ko file in the folder when done.

  • Test the patched module after loading it with:

    sudo rmmod thinkpad_acpi && sudo insmod thinkpad_acpi.ko
    
  • Now confirm that pressing the mic button will turn the orange mic light on/off AND the power light blinking/steady.

  • If confirmed, do the following to replace your current thinkpad_acpi module:

    TPDIR=/lib/modules/$(uname -r)/kernel/drivers/platform/x86
    sudo mv $TPDIR/thinkpad_acpi.ko $TPDIR/thinkpad_acpi.ko.stock
    sudo mv /where/you/built/it/tpacpi_micmute/thinkpad_acpi.ko $TPDIR/thinkpad_acpi.ko
    
  • Comment out or delete the power led lines in lenovo-micmute.sh


d. Testing

  • Apart from your choice of indicator, you can also confirm mute via the following:

Mic Input

  • Click on the volume icon on the top right, and sound settings at the bottom:
  • Switch to the "Input" tab.
  • Now have fun pressing the Mic Mute button, you should see it reflected in:

    1. The Mute checkbox in the window
    2. Notification bubbles (won't appear instantly if you press the Mic Mute more than once every few seconds!)
    3. Your chosen indicator: the blinking power button light or the built-in Mic Mute light.
bender
  • 1,814
ish
  • 139,926
  • Added a blinking power light as indicator -- impossible to use actual mic light without a custom kernel. – ish May 16 '12 at 07:47
  • @warlock: patch works just fine for me :) – ish May 18 '12 at 06:50
  • No need to build the kernel, just try this. Get this patched tarball, unpack, make sure you have headers for running kernel installed. make will give you kernel module thinkpad_acpi.ko.

    Unload stock module with rmmod thinkpad_acpi, then insmod /path/to/fresh/thinkpad_acpi.ko.

    cd to /sys/devices/platform/thinkpad_acpi/leds, and you'll see a new tpacpi::micmute. Test by echoing 0 and 1 to tpacpi::micmute/brightness, and please let me know.

    (building the module should work on Arch too, unless it's built-in to the kernel)

    – ish May 18 '12 at 07:51
  • it worked , please update the ACPID script , and i'll pick this as the best answer ;-P – daisy May 18 '12 at 07:59
  • thanks, give me a little time to see if the whole package can be made more user-friendly :). could you pastebin the output of amixer please? I'd like to detect capture vs. internal mic. – ish May 18 '12 at 08:12
  • okay , i'll do it after reboot , just FYI: the patch works on arch linux , but I had to do it from scratch ;-P – daisy May 18 '12 at 08:16
  • here http://pastebin.mozilla.org/1644525 – daisy May 18 '12 at 08:18
  • @izx, unfortunately, your link http://i.zdom.org/tpacpi-micmute.tar.gz doesn't work. Could you please reupload the tarball? – Andrey Aug 20 '12 at 10:34
  • @Andrey I will soon. Thanks for letting me know – ish Aug 20 '12 at 10:35
  • 1
    @Andrey: I have added an inline-patch instead of downloading the modified source. Please search the answer page for Patch it with and you'll find the sed line necessary to activate the mic mute LED. – ish Aug 24 '12 at 22:35
  • Solution by izx is great, but there is a little mistake in the paste file. echo 1 > $MICMUTE; is there twice but there should be echo 1 first and echo 0 then (otherwise you would have always LEDturned on. – Peter Sivák Aug 28 '12 at 00:57
  • Thanks for this! I bundled it into my collection of ThinkPad scripts (think-rotate). – Martin Ueding Feb 09 '13 at 11:41
  • 2
    Unfortunately, I can't compile thinkpad_acpi.c no more. Make output is here. Could someone, please, help me resolve this issue? – Andrey Apr 07 '13 at 18:01
  • Wowza it all actually worked perfectly first time with Thinkpad X1 Carbon! On 13.04 Raring Ringtail! – Robin Winslow Apr 28 '13 at 21:56
  • @izx: Is it okay if I license this in my script as GPL2 or later and drop the CC-BY-SA which is a little unusual for software? – Martin Ueding Oct 07 '13 at 16:26
  • 1
    13.10 (Saucy) requires a different thinkpad_acpi.c. The patch remains the same as in the original answer. This worked for me on a 3.11.0-15-generic kernel (and corresponding headers). – Daniel Jan 19 '14 at 07:06
  • After I rebooted my laptop, the script doesn't work anymore. Neither does acpi_listen. Does anyone know how to fix this? – Quaxton Hale Mar 09 '14 at 21:46
  • This works brilliantly now. I used to have a delay before the offical LED came on, but it's gone now. You rock! I'm using Ubuntu Gnome btw 13.10. – Costa Michailidis Apr 18 '14 at 13:58
  • In Vivid Vervet on X240 c-1 approach works as c-2. It controls mic-mute key on keyboard. No kernel patching is necessary. Only change is that every amixer command needs device number 1, i.e. amixer -c 1 ... – Jan Blechta Aug 17 '15 at 15:41
  • When I run acpi_listen and press my mic mute button, nothing happens. Other buttons do work, like the output mute. Do I need to try solution #2 or will it not make a difference? – Matt Apr 20 '16 at 21:28
  • 1
    In 16.10, it looks like the mic mute light turns itself on when you use the first method and press the mute button, so the blinking power light is not necessary anymore. – ExplodingKittens Feb 08 '17 at 01:02
1

Installing indicator-sound solved the problem for me.

0

I couldn't get it to work straight away on Ubuntu 12.10 first time using a linux desktop environment as well.

It was fixed with just adding quotes and removing the comma (and adding my username):

#!/bin/bash
MICMUTE=/sys/devices/platform/thinkpad_acpi/leds/tpacpi::micmute/brightness

ID='"Internal Mic"'
USERNAME="" #put your username here
if amixer sget "$ID"ntenter code herernal Mic" 0 | grep '\[on\]' ; then
    amixer sset "$ID" 0 toggle
    #echo "0 blink" > /proc/acpi/ibm/led #related to blinking power
    echo 1 > $MICMUTE
    su $USERNAME -c 'DISPLAY=":0.0" notify-send -t 50 \
            -i microphone-sensitivity-muted-symbolic "Mic MUTED"'
    echo "MUTE ON"
else
    amixer sset "$ID" 0 toggle                       
    su $USERNAME -c 'DISPLAY=":0.0" notify-send -t 50 \
            -i microphone-sensitivity-high-symbolic "Mic ON"'
    #echo "0 on" > /proc/acpi/ibm/led 
    echo 0 > $MICMUTE
    echo "MUTE OFF"
fi

and then followed your steps in compiling the thinkpad_acpi.

All on a Thinkpad T520 with NVS 4200M, Ubuntu 12.10. Haven't rebooted yet but I tested with the test step you have outlined and it works with turning the mute LED on and OFF and actually muting it (with the notification). Jumping the gun a little bit seems to work fine. Thanks.

Well rebooted, the script itself works fine muting and unmuting but I didn't install the patched thinkpad_acpi... oops

Okay, rebooted again after installing it properly this time and the LED lights up as well. Should probably have a start-up script to check if the mic is muted or not and turn the light on/off, since the current setup will only turn the light on/off when the button is pushed.


To get the light to show if it's been muted or not at start-up instead of when the button is first pushed, I just saved:

#!/bin/bash
MICMUTE=/sys/devices/platform/thinkpad_acpi/leds/tpacpi::micmute/brightness
if amixer sget "Internal Mic" 0 | grep '\[on\]' ; then
    echo 0 > $MICMUTE
elif amixer sget "Internal Mic" 0 | grep '\[off\]' ; then
    echo 1 > $MICMUTE
else
    echo "No Mic Detected";
fi

Gave it permission to execute

sudo chmod +x /etc/init.d/lenovo-mic-check

As lenovo-mic-check to /etc/init.d/ and then ran:

sudo update-rc.d lenovo-mic-check defauts 98 02

Also don't forget to copy to /etc/pm/sleep.d/

sudo cp /etc/init.d/lenovo-mic-check /etc/pm/sleep.d/lenovo-mic-check

Now the light is on if I reboot the computer, NOTE: the second if could just be an else.

  • @andrey This might be a dumb quesiton but have you tried downloading, patching and compiling a clean copy of the thinkpad_acpi.c? – JQuantum Apr 14 '13 at 20:45