Thermodynamics of impurities in semiconductors