There's no way, music is extremely dynamic and much easier on a speaker than the sine wave you will set max gain to. And in order to do what you want, you will have to set the head unit volume to a max point and never pass that. So when you get a very dynamic track or a low recording level, it then won't get as loud as your modern tracks. And when you turn it up past that determine point to compensate, you will loss that mark where you "set gain to x wattage to protect the driver". And you won't know where that new point is since you don't know where the song peaks.
And as the voice coil starts to heat up it becomes more resistive which causes the amp to put out less power, by as much as half the power. which throws off your calculation there too.
Pointless. Look how home receivers leave almost 50% of the volume scale without ever hardly being used, it's there for the reasons above and is needed.
Best thing you can do is listen for when the speaker doesn't get any louder and starts to distort, then turn it down a bit.