I bought a motherboard from MSI, Z270 Gaming M5. One of the features that make the choice, was the optical audio output.
I tryed to make it work, but was only working in Stereo mode. DTS and Dolby Digital that is the 5.1 modes, was hidden.
After some hours tying to resolve, I was thinking that was the driver that was wrong, but I found the solution.
Seems that my brand new and expensive motherboad dont have DTS or Dolby license, than the driver wouldnt show it to select.
But in a PC WORLD, where everything is possible, I found a workaround. Let's hack the driver.
Download this patcher and unzip it: realtek.hd.sound.driver-patch.exe
Download your driver installer and unzip it.
Run the patcher and when you click the 'patch' button, it will open a file browser. Browse through your setup to find each of the two DLLs RltkAPO64.dll and RltkAPO.dll. They are probably in a folder named 'WIN64'.
You need to make this two times. One for each file. Make one, close the patch and open again.
Run setup.exe and install as per normal. That means reboot when it says.
Now you can select 5.1 output on the SPDIF.
Enjoy your surround sound.