svn commit: r243513 - projects/efika_mx/sys/arm/freescale/imx

Aleksandr Rybalko ray at FreeBSD.org
Sun Nov 25 12:34:49 UTC 2012


Author: ray
Date: Sun Nov 25 12:34:48 2012
New Revision: 243513
URL: http://svnweb.freebsd.org/changeset/base/243513

Log:
  imx_gpt can serve ET_FLAGS_PERIODIC too now.
  ET_FLAGS_PERIODIC not well tested yet.
  
  Sponsored by:	FreeBSD Foundation

Modified:
  projects/efika_mx/sys/arm/freescale/imx/imx_gpt.c
  projects/efika_mx/sys/arm/freescale/imx/imx_gptvar.h

Modified: projects/efika_mx/sys/arm/freescale/imx/imx_gpt.c
==============================================================================
--- projects/efika_mx/sys/arm/freescale/imx/imx_gpt.c	Sun Nov 25 12:29:01 2012	(r243512)
+++ projects/efika_mx/sys/arm/freescale/imx/imx_gpt.c	Sun Nov 25 12:34:48 2012	(r243513)
@@ -171,7 +171,7 @@ imx_gpt_attach(device_t dev)
 	}
 
 	sc->et.et_name = "i.MXxxx GPT Eventtimer";
-	sc->et.et_flags = ET_FLAGS_ONESHOT;
+	sc->et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERIODIC;
 	sc->et.et_quality = 1000;
 	sc->et.et_frequency = sc->clkfreq;
 	sc->et.et_min_period.sec = 0;
@@ -215,7 +215,15 @@ imx_gpt_timer_start(struct eventtimer *e
 	uint32_t ticks;
 
 	sc = (struct imx_gpt_softc *)et->et_priv;
-	if (first != NULL) {
+
+	if (period != NULL) {
+		sc->sc_period = (et->et_frequency * (first->frac >> 32)) >> 32;
+		sc->sc_period += et->et_frequency * first->sec;
+		/* Set expected value */
+		WRITE4(sc, IMX_GPT_OCR2, READ4(sc, IMX_GPT_CNT) + sc->sc_period);
+		/* Enable compare register 2 Interrupt */
+		SET4(sc, IMX_GPT_IR, GPT_IR_OF2);
+	} else if (first != NULL) {
 
 		ticks = (et->et_frequency * (first->frac >> 32)) >> 32;
 		if (first->sec != 0)
@@ -248,9 +256,10 @@ imx_gpt_timer_stop(struct eventtimer *et
 
 	sc = (struct imx_gpt_softc *)et->et_priv;
 
-	/* Disable OF1 Interrupt */
-	CLEAR4(sc, IMX_GPT_IR, GPT_IR_OF1);
-	WRITE4(sc, IMX_GPT_SR, GPT_IR_OF1);
+	/* Disable OF2 Interrupt */
+	CLEAR4(sc, IMX_GPT_IR, GPT_IR_OF2);
+	WRITE4(sc, IMX_GPT_SR, GPT_IR_OF2);
+	sc->sc_period = 0;
 
 	return (0);
 }
@@ -295,6 +304,14 @@ imx_gpt_intr(void *arg)
 			sc->et.et_event_cb(&sc->et, sc->et.et_arg);
 		}
 	}
+	if (status & GPT_IR_OF2) {
+		if (sc->et.et_active) {
+			sc->et.et_event_cb(&sc->et, sc->et.et_arg);
+			/* Set expected value */
+			WRITE4(sc, IMX_GPT_OCR2, READ4(sc, IMX_GPT_CNT) +
+			    sc->sc_period);
+		}
+	}
 
 	/* ACK */
 	WRITE4(sc, IMX_GPT_SR, status);

Modified: projects/efika_mx/sys/arm/freescale/imx/imx_gptvar.h
==============================================================================
--- projects/efika_mx/sys/arm/freescale/imx/imx_gptvar.h	Sun Nov 25 12:29:01 2012	(r243512)
+++ projects/efika_mx/sys/arm/freescale/imx/imx_gptvar.h	Sun Nov 25 12:34:48 2012	(r243513)
@@ -38,6 +38,7 @@ struct imx_gpt_softc {
 	bus_space_tag_t sc_iot;
 	bus_space_handle_t sc_ioh;
 	void 		*sc_ih;			/* interrupt handler */
+	uint32_t 	sc_period;
 	uint32_t 	sc_clksrc;
 	uint32_t 	clkfreq;
 	struct eventtimer et;


More information about the svn-src-projects mailing list