Cascode Amplifier Gain
Since gmb2 is usually ignored when the substrate connection is properly grounded, I'll ignore it and make thing slightly simpler. So gmb2 = 0

Then looking "up" into the source of M2 I see:

$$1/(gm_2)$$ 

Looking right from the drain of M1 I see:

$$Rp$$ 

The current coming out of the drain of M1 is:

$$Id_1 = gm_1Vin$$

Now this current splits between that 1/gm2 and Rp:

$$Id_2 = Id_1\frac{gm_2Rp}{1+gm_2Rp}$$

(Note that this uses the "current dividing into two resistances" formula. It is similar to the voltage divider formula but then for current.)

Then filling in Id1 that makes:

$$Id_2 = gm_1Vin\frac{gm_2Rp}{1+gm_2Rp}$$

You can now replace gm2 with (gm2 + gmb2) if you like, the end result remains the same.

Drain current Id2 does not split anymore after M2, all the current goes into the drain load resistor Rd. So the voltage gain Av is simply Id2 as derived above multiplied by the value of the load resistor Rd. With a negative sign as a rising Vin results in a falling Vout.