I recently upgraded my HTPC from Ubuntu 12.04 to 13.04, and I was a bit miffed to find digital optical (which I use to send to my home speakers) was no longer working.
I search around without much luck, finding solutions that involved driver tweaks and such. In my case, none of that applied, as my Intel sound device was correctly detected and working in every other way. Ubuntu’s sound controls even showed the optical S/PDIF as present, and unmuted.

Eventually, I stumbled across this bug: https://bugs.launchpad.net/ubuntu/+source/pulseaudio/+bug/1158248

It turns out, all you need to do is start up alsamixer:
alsamixer

Then unmute S/PDIF 1 (arrow over to select it, then hit the ‘m’ key. You should see the ‘mm’ at the bottom replaced by ’00’).

It looks like the default for this channel on Intel devices was set to muted in recent versions of Ubuntu, probably because so few people use it and were scared by a little red light coming out of their machines. Unfortunately, the alsamixer mute isn’t exposed by the Pulse Audio sound controls in Ubuntu, so you’ve got to re-enable it this way for now.