Go to Realtek official site, accept the disclaimer, then download the audio driver for linux/unix. You need to select version 3 for Kernel 3 or later.
Setup necessary tools to compile this driver.
sudo apt-get install build-essential gcc make
Extract the downloaded file, run
sudo ./install file from a terminal after going to the extracted folder to compile the driver.
Readme.txt file for more information.
Install gnome-alsamixer by this command.
sudo apt-get install gnome-alsamixer
Open the gnome-alsamixer by typing alsamixer in the dash.
Select the "Auto mute mode" in the new window.
Reboot and see whether it fixed now. (Step 6 and 7 might not necessary). Automute will automatically enabled upon restart
I have just found another solution:
(It worked for me with Only S/PDIF profile, Sound from both headphone and speaker and not being able to switch profile)
Add this ppa by the command
sudo apt-add-repository ppa:ubuntu-audio-dev/alsa-daily
Update packages list. by
sudo apt-get update
Then install "alsa-hda-dkms" package:
sudo apt-get install alsa-hda-dkms
Reboot, And See the result!