Received: by 2002:a4a:311b:0:0:0:0:0 with SMTP id k27-v6csp4207294ooa; Tue, 14 Aug 2018 02:44:08 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyaIhVEuZvV0fKzPI0hs1XcEuQCn+Dlh40pkp7LQsXqJRQyQYnKexWdYAJ1xG1do7m53UrF X-Received: by 2002:a62:7590:: with SMTP id q138-v6mr22523875pfc.1.1534239848625; Tue, 14 Aug 2018 02:44:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534239848; cv=none; d=google.com; s=arc-20160816; b=deYHqKFZbTO+/ezoPpuiRwnL6Qvfu4EZux/MVf9+oIc6NIiK2nc9vKTx/NoQ/d3uKR N1LvC+EjkWY02PRlx8LjazQB6SjYLISJT8cH6XF7NUt8k7w0JyY7h1YpdRgjMl+ECjP0 OsU/OJvMqby7TxKWVL9BM2EbHb9zAijNm3Rparuu/+GkkioTEfPlQUoFwdLuikVvWZA+ CQYziZrdUDu4tpJZ9JYFRArYNhyHHyP2WGRCG7MIIRMPWbniTYgAPkPSnwtff8rCqHb8 qDOEQNYezJ5rIYvb+uZfpg97PK9YrPquy/JWoTgoQt9VUIEYGeL5GCJZNjcA/yDMogPw vOQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:arc-authentication-results; bh=CpiL4JBHlXCdHQAVuFQ7NZPTdP+xH9SeHmCUtcPHV9g=; b=SLgj3btxZyuaYYcJk1M1CoXT+UE4I8TqI/P6FV6fLDF4Yo2yv8/53FvpG9HWUbJKqR wilLKcSGjAnWW1BHy5FTXrCjqCnyywZ17bRVGIPMmZwKHmbUa+/Y6HHZkSUfMluZzmLB 4Q3eI6XL3vspPjZyaNb5tIGwfoSQYF6rWhXfUjKjOhZB7AwhLa6GYb3XtMSVko2Ri9q9 xhMFA/zpkSUhGOUROtf6Okus4fgDombnhi7Eb1Hjby8fzpDyPR9T10n8/QIGYzGaDNCz Owo8//tIDUJvByYyfssq6X9GAP6CV+xImXf3W2s0J/yhTWl20wGpNjLHEZXTsPgqVUxR 6Qdw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e3-v6si19813728pgh.385.2018.08.14.02.43.53; Tue, 14 Aug 2018 02:44:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731713AbeHNM3Y (ORCPT + 99 others); Tue, 14 Aug 2018 08:29:24 -0400 Received: from mail-oi0-f67.google.com ([209.85.218.67]:37326 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728541AbeHNM3X (ORCPT ); Tue, 14 Aug 2018 08:29:23 -0400 Received: by mail-oi0-f67.google.com with SMTP id j205-v6so32463997oib.4; Tue, 14 Aug 2018 02:42:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=CpiL4JBHlXCdHQAVuFQ7NZPTdP+xH9SeHmCUtcPHV9g=; b=hw+evJRgqLO33piRFzJ4keVK5wODL8Y4kviL+t/huIxAIlcLo0i5fhdeUFm6hgVGk7 seqlZhPR1vYU3pXV/L/Ltm9ieYIjcbQFaourBkOS5CvNPysRGdevEIoc30ulsxs/ZsuN 9k76h34mJlqquc4FHvcL0Wx4BpJqcOvWC/UQ8QqS68MnAfastSFGFyJI0wYAuOIx35es 3tTQ1HM10StCp4/URCC/fY1zYxbMkDcmiTjjLKQ1bsvSgaHipqD23YmoBrU3mLw52jCR YiUTIPje35m0zzskzDbVLhXwVmI1XiD3aZJq9spAjRDE6NXgXdzdtIRESPyDwYmGEBqi hvrg== X-Gm-Message-State: AOUpUlHjSLAebzpCvW9OJN9IwI7RpjMkpY+KHwoHTD/rZ7g77KwfWxG3 NkNfcm3H+AsNDN82QZo/EqljIXyyLxedk9/kNXs= X-Received: by 2002:aca:45c3:: with SMTP id s186-v6mr20522189oia.289.1534239778373; Tue, 14 Aug 2018 02:42:58 -0700 (PDT) MIME-Version: 1.0 References: <20180809214414.20905-1-paul@crapouillou.net> <20180809214414.20905-7-paul@crapouillou.net> In-Reply-To: <20180809214414.20905-7-paul@crapouillou.net> From: Mathieu Malaterre Date: Tue, 14 Aug 2018 11:42:47 +0200 Message-ID: Subject: Re: [PATCH v6 06/24] clocksource: Add driver for the Ingenic JZ47xx OST To: Paul Cercueil Cc: Rob Herring , Mark Rutland , thierry.reding@gmail.com, Daniel Lezcano , Thomas Gleixner , wim@linux-watchdog.org, Guenter Roeck , Ralf Baechle , Paul Burton , James Hogan , Jonathan Corbet , Lee Jones , Ezequiel Garcia , linux-pwm@vger.kernel.org, "open list:OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" , LKML , linux-watchdog@vger.kernel.org, Linux-MIPS , linux-doc@vger.kernel.org, linux-clk@vger.kernel.org, Maarten ter Huurne Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Aug 9, 2018 at 11:44 PM Paul Cercueil wrote: > > From: Maarten ter Huurne > > OST is the OS Timer, a 64-bit timer/counter with buffered reading. > > SoCs before the JZ4770 had (if any) a 32-bit OST; the JZ4770 and > JZ4780 have a 64-bit OST. > > This driver will register both a clocksource and a sched_clock to the > system. With CONFIG_DEBUG_SECTION_MISMATCH=y here is what I see: MODPOST vmlinux.o WARNING: vmlinux.o(.data+0x26600): Section mismatch in reference from the variable ingenic_ost_driver to the function .init.text:ingenic_ost_probe() The variable ingenic_ost_driver references the function __init ingenic_ost_probe() If the reference is valid then annotate the variable with __init* or __refdata (see linux/init.h) or name the variable: *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console WARNING: vmlinux.o(.data+0x26660): Section mismatch in reference from the variable ingenic_tcu_driver to the function .init.text:ingenic_tcu_probe() The variable ingenic_tcu_driver references the function __init ingenic_tcu_probe() If the reference is valid then annotate the variable with __init* or __refdata (see linux/init.h) or name the variable: *_template, *_timer, *_sht, *_ops, *_probe, *_probe_one, *_console Thanks > Signed-off-by: Maarten ter Huurne > Signed-off-by: Paul Cercueil > --- > drivers/clocksource/Kconfig | 8 ++ > drivers/clocksource/Makefile | 1 + > drivers/clocksource/ingenic-ost.c | 208 ++++++++++++++++++++++++++++++++++++++ > 3 files changed, 217 insertions(+) > create mode 100644 drivers/clocksource/ingenic-ost.c > > v5: New patch > > v6: - Get rid of SoC IDs; pass pointer to ingenic_ost_soc_info as > devicetree match data instead. > - Use device_get_match_data() instead of the of_* variant > - Handle error of dev_get_regmap() properly > > diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig > index 98f708208a8d..e855938c69f1 100644 > --- a/drivers/clocksource/Kconfig > +++ b/drivers/clocksource/Kconfig > @@ -619,4 +619,12 @@ config INGENIC_TIMER > help > Support for the timer/counter unit of the Ingenic JZ SoCs. > > +config INGENIC_OST > + bool "Ingenic JZ47xx Operating System Timer" > + depends on MIPS || COMPILE_TEST > + depends on COMMON_CLK > + select INGENIC_TIMER > + help > + Support for the OS Timer of the Ingenic JZ4770 or similar SoC. > + > endmenu > diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile > index 26877505d400..56ce37252944 100644 > --- a/drivers/clocksource/Makefile > +++ b/drivers/clocksource/Makefile > @@ -75,6 +75,7 @@ obj-$(CONFIG_ASM9260_TIMER) += asm9260_timer.o > obj-$(CONFIG_H8300_TMR8) += h8300_timer8.o > obj-$(CONFIG_H8300_TMR16) += h8300_timer16.o > obj-$(CONFIG_H8300_TPU) += h8300_tpu.o > +obj-$(CONFIG_INGENIC_OST) += ingenic-ost.o > obj-$(CONFIG_INGENIC_TIMER) += ingenic-timer.o > obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o > obj-$(CONFIG_X86_NUMACHIP) += numachip.o > diff --git a/drivers/clocksource/ingenic-ost.c b/drivers/clocksource/ingenic-ost.c > new file mode 100644 > index 000000000000..400d30656790 > --- /dev/null > +++ b/drivers/clocksource/ingenic-ost.c > @@ -0,0 +1,208 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/* > + * JZ47xx SoCs TCU Operating System Timer driver > + * > + * Copyright (C) 2016 Maarten ter Huurne > + * Copyright (C) 2018 Paul Cercueil > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "ingenic-timer.h" > + > +#define TCU_OST_TCSR_MASK 0xc0 > +#define TCU_OST_TCSR_CNT_MD BIT(15) > + > +#define TCU_OST_CHANNEL 15 > + > +struct ingenic_ost_soc_info { > + bool is64bit; > +}; > + > +struct ingenic_ost { > + struct regmap *map; > + struct clk *clk; > + > + struct clocksource cs; > +}; > + > +static u64 notrace ingenic_ost_read_cntl(void) > +{ > + /* Bypass the regmap here as we must return as soon as possible */ > + return readl(ingenic_tcu_base + TCU_REG_OST_CNTL); > +} > + > +static u64 notrace ingenic_ost_read_cnth(void) > +{ > + /* Bypass the regmap here as we must return as soon as possible */ > + return readl(ingenic_tcu_base + TCU_REG_OST_CNTH); > +} > + > +static u64 notrace ingenic_ost_clocksource_read(struct clocksource *cs) > +{ > + u32 val1, val2; > + u64 count, recount; > + s64 diff; > + > + /* > + * The buffering of the upper 32 bits of the timer prevents wrong > + * results from the bottom 32 bits overflowing due to the timer ticking > + * along. However, it does not prevent wrong results from simultaneous > + * reads of the timer, which could reset the buffer mid-read. > + * Since this kind of wrong read can happen only when the bottom bits > + * overflow, there will be minutes between wrong reads, so if we read > + * twice in succession, at least one of the reads will be correct. > + */ > + > + /* Bypass the regmap here as we must return as soon as possible */ > + val1 = readl(ingenic_tcu_base + TCU_REG_OST_CNTL); > + val2 = readl(ingenic_tcu_base + TCU_REG_OST_CNTHBUF); > + count = (u64)val1 | (u64)val2 << 32; > + > + val1 = readl(ingenic_tcu_base + TCU_REG_OST_CNTL); > + val2 = readl(ingenic_tcu_base + TCU_REG_OST_CNTHBUF); > + recount = (u64)val1 | (u64)val2 << 32; > + > + /* > + * A wrong read will produce a result that is 1<<32 too high: the bottom > + * part from before overflow and the upper part from after overflow. > + * Therefore, the lower value of the two reads is the correct value. > + */ > + > + diff = (s64)(recount - count); > + if (unlikely(diff < 0)) > + count = recount; > + > + return count; > +} > + > +static int __init ingenic_ost_probe(struct platform_device *pdev) > +{ > + const struct ingenic_ost_soc_info *soc_info; > + struct device *dev = &pdev->dev; > + struct ingenic_ost *ost; > + struct clocksource *cs; > + unsigned long rate, flags; > + int err; > + > + soc_info = device_get_match_data(dev); > + if (!soc_info) > + return -EINVAL; > + > + ost = devm_kzalloc(dev, sizeof(*ost), GFP_KERNEL); > + if (!ost) > + return -ENOMEM; > + > + ost->map = dev_get_regmap(dev->parent, NULL); > + if (!ost->map) { > + dev_err(dev, "regmap not found\n"); > + return -EINVAL; > + } > + > + ost->clk = devm_clk_get(dev, "ost"); > + if (IS_ERR(ost->clk)) > + return PTR_ERR(ost->clk); > + > + err = clk_prepare_enable(ost->clk); > + if (err) > + return err; > + > + /* Clear counter high/low registers */ > + if (soc_info->is64bit) > + regmap_write(ost->map, TCU_REG_OST_CNTL, 0); > + regmap_write(ost->map, TCU_REG_OST_CNTH, 0); > + > + /* Don't reset counter at compare value. */ > + regmap_update_bits(ost->map, TCU_REG_OST_TCSR, > + TCU_OST_TCSR_MASK, TCU_OST_TCSR_CNT_MD); > + > + rate = clk_get_rate(ost->clk); > + > + /* Enable OST TCU channel */ > + regmap_write(ost->map, TCU_REG_TESR, BIT(TCU_OST_CHANNEL)); > + > + cs = &ost->cs; > + cs->name = "ingenic-ost"; > + cs->rating = 320; > + cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; > + > + if (soc_info->is64bit) { > + cs->mask = CLOCKSOURCE_MASK(64); > + cs->read = ingenic_ost_clocksource_read; > + } else { > + cs->mask = CLOCKSOURCE_MASK(32); > + cs->read = (u64 (*)(struct clocksource *))ingenic_ost_read_cnth; > + } > + > + err = clocksource_register_hz(cs, rate); > + if (err) { > + dev_err(dev, "clocksource registration failed: %d\n", err); > + clk_disable_unprepare(ost->clk); > + return err; > + } > + > + /* Cannot register a sched_clock with interrupts on */ > + local_irq_save(flags); > + if (soc_info->is64bit) > + sched_clock_register(ingenic_ost_read_cntl, 32, rate); > + else > + sched_clock_register(ingenic_ost_read_cnth, 32, rate); > + local_irq_restore(flags); > + > + return 0; > +} > + > +#ifdef CONFIG_PM_SLEEP > +static int ingenic_ost_suspend(struct device *dev) > +{ > + struct ingenic_ost *ost = dev_get_drvdata(dev); > + > + clk_disable(ost->clk); > + return 0; > +} > + > +static int ingenic_ost_resume(struct device *dev) > +{ > + struct ingenic_ost *ost = dev_get_drvdata(dev); > + > + return clk_enable(ost->clk); > +} > + > +static SIMPLE_DEV_PM_OPS(ingenic_ost_pm_ops, ingenic_ost_suspend, > + ingenic_ost_resume); > +#define INGENIC_OST_PM_OPS (&ingenic_ost_pm_ops) > +#else > +#define INGENIC_OST_PM_OPS NULL > +#endif /* CONFIG_PM_SUSPEND */ > + > +static const struct ingenic_ost_soc_info jz4725b_ost_soc_info = { > + .is64bit = false, > +}; > + > +static const struct ingenic_ost_soc_info jz4770_ost_soc_info = { > + .is64bit = true, > +}; > + > +static const struct of_device_id ingenic_ost_of_match[] = { > + { .compatible = "ingenic,jz4725b-ost", .data = &jz4725b_ost_soc_info, }, > + { .compatible = "ingenic,jz4770-ost", .data = &jz4770_ost_soc_info, }, > + { } > +}; > +MODULE_DEVICE_TABLE(of, ingenic_ost_of_match); > + > +static struct platform_driver ingenic_ost_driver = { > + .probe = ingenic_ost_probe, > + .driver = { > + .name = "ingenic-ost", > + .pm = INGENIC_OST_PM_OPS, > + .of_match_table = ingenic_ost_of_match, > + }, > +}; > +module_platform_driver(ingenic_ost_driver); > -- > 2.11.0 >