From nobody Fri Nov 29 11:35:10 2024 Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13B8A17C9E; Fri, 20 Sep 2024 07:53:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726818794; cv=none; b=kirDYk3eqXGmp0tiwa+g2/SQUtQZE67kCJqNC8BxhAGVXZd3bVGrDWRYe/mGqy8CceN+W2e7+/rpUU2TOyfo3MGjaNexj/A8rrfiQEoYQz2aBiAGeeWyj7Bk86A3sya9itdUfcaT1wAfrrpVeSiMeNuqxpb0mPW5bVR+D7X8Z0M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726818794; c=relaxed/simple; bh=eeK13g47w+IFBb509m1BPpU11t5vkm09BwbCUE0yR0g=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=VakDA0MSxnDGWRxu0RW/B3tZZPbancgsDKLxVBssO+13O8KKddAt8jx79DiKfuS91wy4tQe/8WN5GirZO1VDjok159IyOAHo24xmHR2D5Cq1IC2WHhd+LobF60PosSQ3kow7aBNI9IfK+JHeTCFVs2mYK+R+t4MJHXq48mhcUYk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=X3B+6bj2; arc=none smtp.client-ip=209.85.128.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X3B+6bj2" Received: by mail-wm1-f53.google.com with SMTP id 5b1f17b1804b1-42e5e758093so14980115e9.1; Fri, 20 Sep 2024 00:53:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726818791; x=1727423591; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=4bb1MBPLpzmsmwHPmevdCgN7+Gg+hPpfRNj9sIsjVy0=; b=X3B+6bj2blc8X0BM3SKYeATVfqcIX2BYgnb6gFJ8jSWHXJ14nXE8+yvf8BPgjutuZp N6diOb4kp/EhzHx2lyVXW+HpkqW8apYsFlplcc3jbvfH4gArgpbXQ5tWSgeDbR80eAzV 25UGIKD3E9Z5hgoR8zjS57yrTN2skoVcdzMcCcJmXGICZhG2EBzRiHgPOIwoG7/SS8sC U6gIVLFqbcjU3uj2sw8XrUz9SI3/XdhfIs5BiBIbPrvkDRPVi8XP6Oc54CAhATCosQMH W84I1U3jJlTFoJNxUeups2D+7OeGUUSERiYDWJDtLCwiw++cufAozuKaBpyqmSwXA2Hf JcSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726818791; x=1727423591; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4bb1MBPLpzmsmwHPmevdCgN7+Gg+hPpfRNj9sIsjVy0=; b=EfTFd06XM7KAYISx0uGVlrWTQ7E32ahq1Y+8qMbYtf/Ewco3cWFMeV8WwiBpzoRT4w 1wp7X2y+jiNy+QgCm3m0uwwYg05SApDJl9N0rGsVfg1QKYpCRyw8nnlTsVbp8dWuxhMr PJWU40dJuasBq79dLG7CGfc8H2A6jUGV1vIOjK4bpP1B81320eE2EFYIo3neq33bSgzh p/TRf75S6AIcNI+ppuZPIeVdqibD840eHsa0TjYSCj+zfrbcEG9xBPIe8s6/KbICVJDq Mdo8jk6+oyc6Obf6xtNMjMLnUz18hIfZhlO+CYXa1gMZeQlwUls7ThfDnx5ZjS/2KrE9 mvmg== X-Forwarded-Encrypted: i=1; AJvYcCUHqpHZmqzzScxgZNQ7DT88OYN0B5sCuJ0LMXHnH0RAYl2JC7O82Fr+n2lqMl0QQVA03E4kGQTcQmMEzGI=@vger.kernel.org X-Gm-Message-State: AOJu0Yx6sAgBskqbLAvq+9ApZu32ruQM/nYiEYZGiwFoA6GkD+BJ+Mbe II1JiT/Eenr0BxGpmoF5wOD7suICBk8DWp1IXv1NmqWxfLUSzaWYjyC3Bw== X-Google-Smtp-Source: AGHT+IFPK2ruG0da4VoubzCqvAnyVcI63/P5PEfAXYXVW5fSUfJDamQ9XNsvDZk3KpYJ26UVAV6Lzw== X-Received: by 2002:a05:600c:1e25:b0:42c:b6e4:e3ac with SMTP id 5b1f17b1804b1-42e7abe228fmr14637665e9.3.1726818790568; Fri, 20 Sep 2024 00:53:10 -0700 (PDT) Received: from localhost.localdomain (201.red-88-10-59.dynamicip.rima-tde.net. [88.10.59.201]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e7afbfbfbsm15178465e9.22.2024.09.20.00.53.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 00:53:09 -0700 (PDT) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: daniel.lezcano@linaro.org, tglx@linutronix.de, tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, yangshiji66@outlook.com Subject: [PATCH 1/2] clocksource: Add Ralink System Tick Counter driver Date: Fri, 20 Sep 2024 09:53:05 +0200 Message-Id: <20240920075306.704665-2-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240920075306.704665-1-sergio.paracuellos@gmail.com> References: <20240920075306.704665-1-sergio.paracuellos@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" System Tick Counter is present on Ralink SoCs RT3352 and MT7620. This driver has been in 'arch/mips/ralink' directory since the beggining of Ralink architecture support. However, it can be moved into a more proper place in 'drivers/clocksource'. Hence add it here adding also support for compile test targets. Signed-off-by: Sergio Paracuellos --- drivers/clocksource/Kconfig | 10 ++ drivers/clocksource/Makefile | 1 + drivers/clocksource/timer-ralink.c | 150 +++++++++++++++++++++++++++++ 3 files changed, 161 insertions(+) create mode 100644 drivers/clocksource/timer-ralink.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 95dd4660b5b6..50339f4d3201 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -753,4 +753,14 @@ config EP93XX_TIMER Enables support for the Cirrus Logic timer block EP93XX. =20 +config CLKSRC_RALINK + bool "Ralink System Tick Counter" + depends on SOC_RT305X || SOC_MT7620 || COMPILE_TEST + default y if SOC_RT305X || SOC_MT7620 + select CLKSRC_MMIO + select TIMER_OF + help + Enables support for system tick counter present on + Ralink SoCs RT3352 and MT7620. + endmenu diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 22743785299e..c9214afcb712 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -91,3 +91,4 @@ obj-$(CONFIG_GOLDFISH_TIMER) +=3D timer-goldfish.o obj-$(CONFIG_GXP_TIMER) +=3D timer-gxp.o obj-$(CONFIG_CLKSRC_LOONGSON1_PWM) +=3D timer-loongson1-pwm.o obj-$(CONFIG_EP93XX_TIMER) +=3D timer-ep93xx.o +obj-$(CONFIG_CLKSRC_RALINK) +=3D timer-ralink.o diff --git a/drivers/clocksource/timer-ralink.c b/drivers/clocksource/timer= -ralink.c new file mode 100644 index 000000000000..6ecdb4228f76 --- /dev/null +++ b/drivers/clocksource/timer-ralink.c @@ -0,0 +1,150 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Ralink System Tick Counter driver present on RT3352 and MT7620 SoCs. + * + * Copyright (C) 2013 by John Crispin + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SYSTICK_FREQ (50 * 1000) + +#define SYSTICK_CONFIG 0x00 +#define SYSTICK_COMPARE 0x04 +#define SYSTICK_COUNT 0x08 + +/* route systick irq to mips irq 7 instead of the r4k-timer */ +#define CFG_EXT_STK_EN 0x2 +/* enable the counter */ +#define CFG_CNT_EN 0x1 + +struct systick_device { + void __iomem *membase; + struct clock_event_device dev; + int irq_requested; + int freq_scale; +}; + +static int systick_set_oneshot(struct clock_event_device *evt); +static int systick_shutdown(struct clock_event_device *evt); + +static int systick_next_event(unsigned long delta, + struct clock_event_device *evt) +{ + struct systick_device *sdev; + u32 count; + + sdev =3D container_of(evt, struct systick_device, dev); + count =3D ioread32(sdev->membase + SYSTICK_COUNT); + count =3D (count + delta) % SYSTICK_FREQ; + iowrite32(count, sdev->membase + SYSTICK_COMPARE); + + return 0; +} + +static void systick_event_handler(struct clock_event_device *dev) +{ + /* noting to do here */ +} + +static irqreturn_t systick_interrupt(int irq, void *dev_id) +{ + struct clock_event_device *dev =3D (struct clock_event_device *)dev_id; + + dev->event_handler(dev); + + return IRQ_HANDLED; +} + +static struct systick_device systick =3D { + .dev =3D { + /* + * cevt-r4k uses 300, make sure systick + * gets used if available + */ + .rating =3D 310, + .features =3D CLOCK_EVT_FEAT_ONESHOT, + .set_next_event =3D systick_next_event, + .set_state_shutdown =3D systick_shutdown, + .set_state_oneshot =3D systick_set_oneshot, + .event_handler =3D systick_event_handler, + }, +}; + +static int systick_shutdown(struct clock_event_device *evt) +{ + struct systick_device *sdev; + + sdev =3D container_of(evt, struct systick_device, dev); + + if (sdev->irq_requested) + free_irq(systick.dev.irq, &systick.dev); + sdev->irq_requested =3D 0; + iowrite32(0, systick.membase + SYSTICK_CONFIG); + + return 0; +} + +static int systick_set_oneshot(struct clock_event_device *evt) +{ + const char *name =3D systick.dev.name; + struct systick_device *sdev; + int irq =3D systick.dev.irq; + + sdev =3D container_of(evt, struct systick_device, dev); + + if (!sdev->irq_requested) { + if (request_irq(irq, systick_interrupt, + IRQF_PERCPU | IRQF_TIMER, name, &systick.dev)) + pr_err("Failed to request irq %d (%s)\n", irq, name); + } + sdev->irq_requested =3D 1; + iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN, + systick.membase + SYSTICK_CONFIG); + + return 0; +} + +static int __init ralink_systick_init(struct device_node *np) +{ + int ret; + + systick.membase =3D of_iomap(np, 0); + if (!systick.membase) + return -ENXIO; + + systick.dev.name =3D np->name; + clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60); + systick.dev.max_delta_ns =3D clockevent_delta2ns(0x7fff, &systick.dev); + systick.dev.max_delta_ticks =3D 0x7fff; + systick.dev.min_delta_ns =3D clockevent_delta2ns(0x3, &systick.dev); + systick.dev.min_delta_ticks =3D 0x3; + systick.dev.irq =3D irq_of_parse_and_map(np, 0); + if (!systick.dev.irq) { + pr_err("%pOFn: request_irq failed", np); + return -EINVAL; + } + + ret =3D clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name, + SYSTICK_FREQ, 301, 16, + clocksource_mmio_readl_up); + if (ret) + return ret; + + clockevents_register_device(&systick.dev); + + pr_info("%pOFn: running - mult: %d, shift: %d\n", + np, systick.dev.mult, systick.dev.shift); + + return 0; +} + +TIMER_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init); --=20 2.25.1 From nobody Fri Nov 29 11:35:10 2024 Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C1B26F2FE; Fri, 20 Sep 2024 07:53:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726818798; cv=none; b=mK9/uSEfIbjqtNbEJ2umWzT3ay67gvZZ1ct09gs8TW8C99eDFguK5wU9dV8cOgHZZwJu/reeewP+UTJN5F97Xa7NDfE73OzmJnRQyLjzBGH/CIQTWexLcE3XveU3sVrywj1+4jFRF2MaRoZKcftQy9hDHnBfjfciAQyZ0mybKn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726818798; c=relaxed/simple; bh=T1W6L5QpnQKpwKjC1poc2NjFmxjZ471D3fP2Aphip1Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FnZfRjNo0nZ/P6f0W+lKy628X1ZfMtE7Pnt26C2Stcpfd8ES8WkpiwIE58kPdrZqF4ff3q/Dp4WeP3xsUEGppBqfSC6VtYNlI5T4bIx8M8lNhRv+wsjT9KSpxxmD8khZhfCrsDS0BWXyNIaaUtxUSCGIARdlqq2OTzjIY8t/eX4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eHcTgol+; arc=none smtp.client-ip=209.85.208.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eHcTgol+" Received: by mail-lj1-f170.google.com with SMTP id 38308e7fff4ca-2f763e9e759so20083581fa.3; Fri, 20 Sep 2024 00:53:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726818793; x=1727423593; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VhugxSGuV6ZvqI3s0b5MXFKYtefsB4pkxXmNwlWj1fo=; b=eHcTgol+Zk7vQllRrTE1s9/xVjmRmyiJk6MQrSYR+OukweaOtVNA5kl2HG8BkpF6Wa kdSRaxdkg95J/y2LSnXn2eRN2a5pOT0mluW0DXwiYLJDfC6M1a+t7ulLzvnBNZkGt07y L7bYt6H0bbMaBCVpM+OAPcHSgkNAxN22jWnBi84WJHordo+0tm8UVhQGUJi/F0f+Lnxk C7CPP7OQqrL4wDmaUhTAqLf46is6obQqybSczRuJhgI9pFL8HO9/vrjS/eee8JP+6xnG drxQDB+GGEyPSJgrDyEJmTePEF7leLaa1RA+ELpWjOFbiIQQTYmLtBd5IIxWuWSKIMFq T1OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726818793; x=1727423593; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VhugxSGuV6ZvqI3s0b5MXFKYtefsB4pkxXmNwlWj1fo=; b=jUpu4JO8KsFzGOFhlgUioeRYndjmUUdjGfkxf02aJQFzBr32O/I9IzTM8ku+PmoBcV Ev2MqNXmInm3/U+6ckL6BsIAz2wdrhR9pUAPHjfdmvHPZr4n6brMEr6x9ZSB239bJwMi Zvcq/RZEdXOfiyw9geGBLAq/4AEIYyAUIMrDxNbsee9baNSVu5y/qEEaSgkz05iiKG7S FxK0TeM3zpxa8QdWUXlM5Pho8VXJfxx5sE+ULYq87OsLSx/d2fkZ8t0hRAfzxrKcfbGt nLrKKpqHoCboy8+iCqFxgpe2w+dAyZ+6BWwPH/9yfJSbCbyxJyWV5uQ/ULCxK2m7LAup tDgQ== X-Forwarded-Encrypted: i=1; AJvYcCUDh7IL5xSQLtaT3JQ+qIe+ie1sUJhFREjAqP60XiV4z9Nv2D3PfT4pz6/kyMB6AfzFVAVX7Ye4S+uHpvI=@vger.kernel.org X-Gm-Message-State: AOJu0YxdP5siYMphgnLJN/Or5b/qWC70Uf9IWgL17TWmj0Xsh0ncmtP6 Rmo1FOShikW3Z0Ybi+xMplmOU5SzZor7ydOPoZMm+vSdkzW7tFeFrPm8AA== X-Google-Smtp-Source: AGHT+IG8WOndB0FwjkumAaCBnQpmRu7CyX2FaSkFZM0+mzqe+usnKcJK0+AdYUSoG5HdowTVkXvFGw== X-Received: by 2002:a05:651c:542:b0:2f7:4b90:204b with SMTP id 38308e7fff4ca-2f7cb319284mr11382871fa.12.1726818792590; Fri, 20 Sep 2024 00:53:12 -0700 (PDT) Received: from localhost.localdomain (201.red-88-10-59.dynamicip.rima-tde.net. [88.10.59.201]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-42e7afbfbfbsm15178465e9.22.2024.09.20.00.53.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Sep 2024 00:53:11 -0700 (PDT) From: Sergio Paracuellos To: linux-mips@vger.kernel.org Cc: daniel.lezcano@linaro.org, tglx@linutronix.de, tsbogend@alpha.franken.de, john@phrozen.org, linux-kernel@vger.kernel.org, yangshiji66@outlook.com Subject: [PATCH 2/2] MIPS: ralink: remove System Tick Counter driver Date: Fri, 20 Sep 2024 09:53:06 +0200 Message-Id: <20240920075306.704665-3-sergio.paracuellos@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240920075306.704665-1-sergio.paracuellos@gmail.com> References: <20240920075306.704665-1-sergio.paracuellos@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This driver has been moved into a more accurate place in the kernel tree in 'drivers/clocksource' directory as 'timer-ralink.c'. Hence, remove it from here so we can reduce architecture code folder. Signed-off-by: Sergio Paracuellos --- arch/mips/ralink/Kconfig | 7 -- arch/mips/ralink/Makefile | 2 - arch/mips/ralink/cevt-rt3352.c | 153 --------------------------------- 3 files changed, 162 deletions(-) delete mode 100644 arch/mips/ralink/cevt-rt3352.c diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig index 08c012a2591f..910d059ec70b 100644 --- a/arch/mips/ralink/Kconfig +++ b/arch/mips/ralink/Kconfig @@ -1,13 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 if RALINK =20 -config CLKEVT_RT3352 - bool - depends on SOC_RT305X || SOC_MT7620 - default y - select TIMER_OF - select CLKSRC_MMIO - config RALINK_ILL_ACC bool depends on SOC_RT305X diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile index 26fabbdea1f1..0c109eae1953 100644 --- a/arch/mips/ralink/Makefile +++ b/arch/mips/ralink/Makefile @@ -10,8 +10,6 @@ ifndef CONFIG_MIPS_GIC obj-y +=3D clk.o timer.o endif =20 -obj-$(CONFIG_CLKEVT_RT3352) +=3D cevt-rt3352.o - obj-$(CONFIG_RALINK_ILL_ACC) +=3D ill_acc.o =20 obj-$(CONFIG_IRQ_INTC) +=3D irq.o diff --git a/arch/mips/ralink/cevt-rt3352.c b/arch/mips/ralink/cevt-rt3352.c deleted file mode 100644 index 269d4877d120..000000000000 --- a/arch/mips/ralink/cevt-rt3352.c +++ /dev/null @@ -1,153 +0,0 @@ -/* - * This file is subject to the terms and conditions of the GNU General Pub= lic - * License. See the file "COPYING" in the main directory of this archive - * for more details. - * - * Copyright (C) 2013 by John Crispin - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#define SYSTICK_FREQ (50 * 1000) - -#define SYSTICK_CONFIG 0x00 -#define SYSTICK_COMPARE 0x04 -#define SYSTICK_COUNT 0x08 - -/* route systick irq to mips irq 7 instead of the r4k-timer */ -#define CFG_EXT_STK_EN 0x2 -/* enable the counter */ -#define CFG_CNT_EN 0x1 - -struct systick_device { - void __iomem *membase; - struct clock_event_device dev; - int irq_requested; - int freq_scale; -}; - -static int systick_set_oneshot(struct clock_event_device *evt); -static int systick_shutdown(struct clock_event_device *evt); - -static int systick_next_event(unsigned long delta, - struct clock_event_device *evt) -{ - struct systick_device *sdev; - u32 count; - - sdev =3D container_of(evt, struct systick_device, dev); - count =3D ioread32(sdev->membase + SYSTICK_COUNT); - count =3D (count + delta) % SYSTICK_FREQ; - iowrite32(count, sdev->membase + SYSTICK_COMPARE); - - return 0; -} - -static void systick_event_handler(struct clock_event_device *dev) -{ - /* noting to do here */ -} - -static irqreturn_t systick_interrupt(int irq, void *dev_id) -{ - struct clock_event_device *dev =3D (struct clock_event_device *) dev_id; - - dev->event_handler(dev); - - return IRQ_HANDLED; -} - -static struct systick_device systick =3D { - .dev =3D { - /* - * cevt-r4k uses 300, make sure systick - * gets used if available - */ - .rating =3D 310, - .features =3D CLOCK_EVT_FEAT_ONESHOT, - .set_next_event =3D systick_next_event, - .set_state_shutdown =3D systick_shutdown, - .set_state_oneshot =3D systick_set_oneshot, - .event_handler =3D systick_event_handler, - }, -}; - -static int systick_shutdown(struct clock_event_device *evt) -{ - struct systick_device *sdev; - - sdev =3D container_of(evt, struct systick_device, dev); - - if (sdev->irq_requested) - free_irq(systick.dev.irq, &systick.dev); - sdev->irq_requested =3D 0; - iowrite32(0, systick.membase + SYSTICK_CONFIG); - - return 0; -} - -static int systick_set_oneshot(struct clock_event_device *evt) -{ - const char *name =3D systick.dev.name; - struct systick_device *sdev; - int irq =3D systick.dev.irq; - - sdev =3D container_of(evt, struct systick_device, dev); - - if (!sdev->irq_requested) { - if (request_irq(irq, systick_interrupt, - IRQF_PERCPU | IRQF_TIMER, name, &systick.dev)) - pr_err("Failed to request irq %d (%s)\n", irq, name); - } - sdev->irq_requested =3D 1; - iowrite32(CFG_EXT_STK_EN | CFG_CNT_EN, - systick.membase + SYSTICK_CONFIG); - - return 0; -} - -static int __init ralink_systick_init(struct device_node *np) -{ - int ret; - - systick.membase =3D of_iomap(np, 0); - if (!systick.membase) - return -ENXIO; - - systick.dev.name =3D np->name; - clockevents_calc_mult_shift(&systick.dev, SYSTICK_FREQ, 60); - systick.dev.max_delta_ns =3D clockevent_delta2ns(0x7fff, &systick.dev); - systick.dev.max_delta_ticks =3D 0x7fff; - systick.dev.min_delta_ns =3D clockevent_delta2ns(0x3, &systick.dev); - systick.dev.min_delta_ticks =3D 0x3; - systick.dev.irq =3D irq_of_parse_and_map(np, 0); - if (!systick.dev.irq) { - pr_err("%pOFn: request_irq failed", np); - return -EINVAL; - } - - ret =3D clocksource_mmio_init(systick.membase + SYSTICK_COUNT, np->name, - SYSTICK_FREQ, 301, 16, - clocksource_mmio_readl_up); - if (ret) - return ret; - - clockevents_register_device(&systick.dev); - - pr_info("%pOFn: running - mult: %d, shift: %d\n", - np, systick.dev.mult, systick.dev.shift); - - return 0; -} - -TIMER_OF_DECLARE(systick, "ralink,cevt-systick", ralink_systick_init); --=20 2.25.1