After people understood that there is something wrong with electromagnetic wave (a classical concept and description), the photon came in (search for black-body radiation and ultraviolet catastrophe for details). Here is the rule of Mr. Planck, he stated that the energy of this photon is proportional to the frequency associated with it and the constant that relates these two is Planck Constant.
With this new condition, Planck had imposed the quantization of the energy of the oscillators, "a purely formal assumption … actually I did not think much about it…" in his own words.