It is handled by the firmware, but there's a physical switch that closes/opens what I understand is basically a voltage divider.
Both cases, stuck open and stuck closed, can sometime occur. If yours exhibit a behaviour where as the sound dips somewhat though, I'm not sure this is either.
One thing to note though is that the phone is a direct out of the source, and in theory it should be possible to lower the volume to zero for the speakers while not affecting the phones level. Not ideal, but if the controls respond for you then you can workaround it, I guess.