/* Enable or disable the clock on a peripheral device (timers, UARTs, USB, etc)  */
int kinetis_periph_enable(kinetis_clock_gate_t gate, int enable)
/* Enable or disable the clock on a peripheral device (timers, UARTs, USB, etc)  */
int kinetis_periph_enable(kinetis_clock_gate_t gate, int enable)
{
	volatile u32 *scgc;
	u32 mask;
	int rv;
	if (KINETIS_CG_REG(gate) >= KINETIS_SIM_CG_NUMREGS ||
	    KINETIS_CG_IDX(gate) >= KINETIS_SIM_CG_NUMBITS) {
		printk("%s: wrong gate = %x\n", __func__, gate);
		rv = -EINVAL;
		goto out;
	}
	scgc = &KINETIS_SIM->scgc[KINETIS_CG_REG(gate)];
	mask = 1 << KINETIS_CG_IDX(gate);
	if (gate == KINETIS_CG_PORTF && enable) {
		mask |= (1 << KINETIS_CG_IDX(KINETIS_CG_PORTE));
	}
	if (enable)
		*scgc |= mask;
	else
		*scgc &= ~mask;
	rv = 0;
out:
	return rv;
}