The first thing you might consider is taking him to his pediatrician to determine whether he has an underlying medical condition that may be causing him to hit his head. As strange as it may seem, head banging is somewhat normal for toddlers as a self-regulating behavior. Children who head-bang generally will not hit their heads hard enough to hurt themselves. That said, we encourage you to consult with your son's physician regarding the intensity of his head banging. If possible, you should try to record his behavior discretely to show it to the physician.
If your son is hitting his head to get your attention, one thing you can do is give him a lot of attention when he is not head-banging. You can also practice delaying attention by playing with him and then setting a timer and directing him to play by himself. Start out with a short time (five to 10 minutes), and gradually lengthen it. You also can set aside certain preferred toys for his independent playtime. However, at 22 months, he should be supervised somewhat closely, so when he is playing independently, you should observe him. When he is playing by himself, praise him lavishly. Let him know that he is a big boy for playing by himself. You can even reward him for playing independently by spending time doing activities he likes with him.