Deleted Added
full compact
imx_gpt.c (266152) imx_gpt.c (266203)
1/*-
2 * Copyright (c) 2012, 2013 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Oleksandr Rybalko under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2012, 2013 The FreeBSD Foundation
3 * All rights reserved.
4 *
5 * This software was developed by Oleksandr Rybalko under sponsorship
6 * from the FreeBSD Foundation.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 14 unchanged lines hidden (view full) ---

23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__FBSDID("$FreeBSD: stable/10/sys/arm/freescale/imx/imx_gpt.c 266152 2014-05-15 16:11:06Z ian $");
31__FBSDID("$FreeBSD: stable/10/sys/arm/freescale/imx/imx_gpt.c 266203 2014-05-16 00:14:50Z ian $");
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/bus.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/malloc.h>
39#include <sys/rman.h>

--- 30 unchanged lines hidden (view full) ---

70 sbintime_t);
71static int imx_gpt_timer_stop(struct eventtimer *);
72
73static int imx_gpt_intr(void *);
74static int imx_gpt_probe(device_t);
75static int imx_gpt_attach(device_t);
76
77static struct timecounter imx_gpt_timecounter = {
32
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/bus.h>
36#include <sys/kernel.h>
37#include <sys/module.h>
38#include <sys/malloc.h>
39#include <sys/rman.h>

--- 30 unchanged lines hidden (view full) ---

70 sbintime_t);
71static int imx_gpt_timer_stop(struct eventtimer *);
72
73static int imx_gpt_intr(void *);
74static int imx_gpt_probe(device_t);
75static int imx_gpt_attach(device_t);
76
77static struct timecounter imx_gpt_timecounter = {
78 .tc_name = "i.MX GPT Timecounter",
78 .tc_name = "iMXGPT",
79 .tc_get_timecount = imx_gpt_get_timecount,
80 .tc_counter_mask = ~0u,
81 .tc_frequency = 0,
82 .tc_quality = 1000,
83};
84
85/* Global softc pointer for use in DELAY(). */
86struct imx_gpt_softc *imx_gpt_sc = NULL;

--- 152 unchanged lines hidden (view full) ---

239 if (err != 0) {
240 bus_release_resources(dev, imx_gpt_spec, sc->res);
241 device_printf(dev, "Unable to setup the clock irq handler, "
242 "err = %d\n", err);
243 return (ENXIO);
244 }
245
246 /* Register as an eventtimer. */
79 .tc_get_timecount = imx_gpt_get_timecount,
80 .tc_counter_mask = ~0u,
81 .tc_frequency = 0,
82 .tc_quality = 1000,
83};
84
85/* Global softc pointer for use in DELAY(). */
86struct imx_gpt_softc *imx_gpt_sc = NULL;

--- 152 unchanged lines hidden (view full) ---

239 if (err != 0) {
240 bus_release_resources(dev, imx_gpt_spec, sc->res);
241 device_printf(dev, "Unable to setup the clock irq handler, "
242 "err = %d\n", err);
243 return (ENXIO);
244 }
245
246 /* Register as an eventtimer. */
247 sc->et.et_name = "i.MXxxx GPT Eventtimer";
247 sc->et.et_name = "iMXGPT";
248 sc->et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERIODIC;
248 sc->et.et_flags = ET_FLAGS_ONESHOT | ET_FLAGS_PERIODIC;
249 sc->et.et_quality = 1000;
249 sc->et.et_quality = 800;
250 sc->et.et_frequency = sc->clkfreq;
251 sc->et.et_min_period = (MIN_ET_PERIOD << 32) / sc->et.et_frequency;
252 sc->et.et_max_period = (0xfffffffeLLU << 32) / sc->et.et_frequency;
253 sc->et.et_start = imx_gpt_timer_start;
254 sc->et.et_stop = imx_gpt_timer_stop;
255 sc->et.et_priv = sc;
256 et_register(&sc->et);
257

--- 23 unchanged lines hidden (view full) ---

281 /* Enable compare register 2 Interrupt */
282 SET4(sc, IMX_GPT_IR, GPT_IR_OF2);
283 return (0);
284 } else if (first != 0) {
285 ticks = ((uint32_t)et->et_frequency * first) >> 32;
286 /* Do not disturb, otherwise event will be lost */
287 spinlock_enter();
288 /* Set expected value */
250 sc->et.et_frequency = sc->clkfreq;
251 sc->et.et_min_period = (MIN_ET_PERIOD << 32) / sc->et.et_frequency;
252 sc->et.et_max_period = (0xfffffffeLLU << 32) / sc->et.et_frequency;
253 sc->et.et_start = imx_gpt_timer_start;
254 sc->et.et_stop = imx_gpt_timer_stop;
255 sc->et.et_priv = sc;
256 et_register(&sc->et);
257

--- 23 unchanged lines hidden (view full) ---

281 /* Enable compare register 2 Interrupt */
282 SET4(sc, IMX_GPT_IR, GPT_IR_OF2);
283 return (0);
284 } else if (first != 0) {
285 ticks = ((uint32_t)et->et_frequency * first) >> 32;
286 /* Do not disturb, otherwise event will be lost */
287 spinlock_enter();
288 /* Set expected value */
289 WRITE4(sc, IMX_GPT_OCR1, READ4(sc, IMX_GPT_CNT) + ticks);
289 WRITE4(sc, IMX_GPT_OCR3, READ4(sc, IMX_GPT_CNT) + ticks);
290 /* Enable compare register 1 Interrupt */
290 /* Enable compare register 1 Interrupt */
291 SET4(sc, IMX_GPT_IR, GPT_IR_OF1);
291 SET4(sc, IMX_GPT_IR, GPT_IR_OF3);
292 /* Now everybody can relax */
293 spinlock_exit();
294 return (0);
295 }
296
297 return (EINVAL);
298}
299

--- 44 unchanged lines hidden (view full) ---

344 * Clear interrupt status before invoking event callbacks. The callback
345 * often sets up a new one-shot timer event and if the interval is short
346 * enough it can fire before we get out of this function. If we cleared
347 * at the bottom we'd miss the interrupt and hang until the clock wraps.
348 */
349 WRITE4(sc, IMX_GPT_SR, status);
350
351 /* Handle one-shot timer events. */
292 /* Now everybody can relax */
293 spinlock_exit();
294 return (0);
295 }
296
297 return (EINVAL);
298}
299

--- 44 unchanged lines hidden (view full) ---

344 * Clear interrupt status before invoking event callbacks. The callback
345 * often sets up a new one-shot timer event and if the interval is short
346 * enough it can fire before we get out of this function. If we cleared
347 * at the bottom we'd miss the interrupt and hang until the clock wraps.
348 */
349 WRITE4(sc, IMX_GPT_SR, status);
350
351 /* Handle one-shot timer events. */
352 if (status & GPT_IR_OF1) {
352 if (status & GPT_IR_OF3) {
353 if (sc->et.et_active) {
354 sc->et.et_event_cb(&sc->et, sc->et.et_arg);
355 }
356 }
357
358 /* Handle periodic timer events. */
359 if (status & GPT_IR_OF2) {
360 if (sc->et.et_active)

--- 67 unchanged lines hidden ---
353 if (sc->et.et_active) {
354 sc->et.et_event_cb(&sc->et, sc->et.et_arg);
355 }
356 }
357
358 /* Handle periodic timer events. */
359 if (status & GPT_IR_OF2) {
360 if (sc->et.et_active)

--- 67 unchanged lines hidden ---