Inability to open the mouth, difficulty in chewing etc. Can happen for several reasons. In your case, the associated headache and ear pain
suggest some problem with the jaw joint. However, given the information available to me, this is no more than a best guess. Suggestion: Find and see an Oral Surgeon or an Oral Medicine specialist in your area to get the appropriate treatment.