Why do some atoms like Mg have several ionization energy levels? In Dopant Energy Levels in Crystalline Silicon (which asks for a password, but is partially readable if you click "cancel") appears the following image and caption:

Figure 2777b shows the energy levels (also called ionization energies) of the main impurities in crystalline silicon (Si). The donor-like energy levels are indicated in green, and most of them are above the midgap and their values are given with respect to $E_c$. The acceptor-like energy levels are indicated in red, and most of them are below midgap and their values are given with respect to $E_v$. The elements which have both donor-like and acceptor-like energy levels are marked in blue.


Why do some atoms, like Mg, have more than one ionization energy?
 A: There are various reasons for multiple ionization levels for impurities in semiconductors. For instance, silicon atoms in GaAs will occupy either a Ga or an As lattice site, and act as a donor (Ga site) or an acceptor (As site). Now, Si does not have non-equivalent lattice sites, so what is up with Mg?
Measurements of Mg in Si date to a Solid State Communications paper, R.K. Franks and J.B. Robertson, Solids State Communications 5, 4769-481 (1967). They compare their optically measured absorption lines for Mg in Si with theory. The results are in pretty good agreement. The theory numbers are calculated based on Mg sitting on an interstitial site, as Li does. Note that they consider the theory for Li (single donor) and S (also a known double-donor).
So, Mg (and S, and others) will donate two electons. The first, the weakest bound, is from a neutral Mg atom. The second, more deeply bound, comes off an Mg +1 ion. That leaves a Mg +2 charged ion with no more states in the gap.
A recent paper in Phys. Status Solidi (Yuri A. Astrov et al., Phys Status Solidi A 214 (7) 1700192 (2017)/ DOI10.1002/pssa.201700192) has more detail on Mg should you be interested.
