Riboswitches are noncoding RNA that regulate gene expression by folding into specific three-dimensional structures (holo-form) upon binding by their cognate ligand in the presence of Mg2+. Riboswitch functioning is also hypothesized to be under kinetic control requiring large cognate ligand concentrations. We ask the question under thermodynamic conditions, can the riboswitches populate structures similar to the holo-form only in the presence of Mg2+ and absence of cognate ligand binding. We addressed this question using thiamine pyrophosphate (TPP) riboswitch as a model system and computer simulations using a coarse-grained model for RNA. The folding free energy surface (FES) shows that with the initial increase in Mg2+ concentration ([Mg2+]), the aptamer domain (AD) of TPP riboswitch undergoes a barrierless collapse in its dimensions. On further increase in [Mg2+], intermediates separated by barriers appear on the FES, and one of the intermediates has a TPP ligand-binding competent structure. We show that site-specific binding of the Mg2+ aids in the formation of tertiary contacts. For [Mg2+] greater than physiological concentration, AD folds into a structure similar to the crystal structure of the TPP holo-form even in the absence of the TPP ligand. The folding kinetics shows that TPP AD populates an intermediate due to the misalignment of two arms present in the structure, which acts as a kinetic trap, leading to larger folding timescales. The predictions of the intermediate structures from the simulations are amenable for experimental verification.