Had this issue for a few years now, but finally fed up with it. I was changing the ram on my mid-2012 13" MBP but forgot to unplug the battery, then my headphone jack glowed red and stopped functioning with normal headphones. Figured something fried the logic board or turned on optical audio but speaker sound is still functional and all remedies that I have found for turning off optical don't work. At the time I was on el capitan, now I am solely using lubuntu 18.04. Any help would be appreciated!