Properties of phosphorus-doped (Zn,Mg)O thin films and device structures