From patchwork Tue May 12 12:58:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 471320 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from mail-wi0-x239.google.com (mail-wi0-x239.google.com [IPv6:2a00:1450:400c:c05::239]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 06944140D24 for ; Tue, 12 May 2015 22:58:31 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=googlegroups.com header.i=@googlegroups.com header.b=EsN5yDC5; dkim-atps=neutral Received: by wivr20 with SMTP id r20sf2846423wiv.1 for ; Tue, 12 May 2015 05:58:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20120806; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe; bh=/ZqjQ2a59axEIpiry/gslZr5YiUbivXp0Q1Ibswvg9Y=; b=EsN5yDC5gK+OnPttrwSApOgTd89nZnK49nZ3ZBllo51HjibUtcC1rxYE/83K0MpW3I Dn6n14lFk+M2JzK+v3D++nmqTI76rYWzeaeXXKj2MO/99LsFlMrhlxtOipXbWILgrgEb Ag9byaPznQK05fJElOFjF9NShrb5yc5SFFpgE8hc5FV7Jit0FpeAjDa0N6UkH0Z7e4Dm BbDZPu6Rvvni3RwTI00xh6fDJv0JkHTrdh8t5mYEGTVIIjA73M5RY3D3rDuGcoU5a6aB QtfKPe1OBtBrJU1GnkT2vLGDf/hgYCyebftGmK99QBU8Bmom/7QoEh8WjkOFnhuw9B5c PFVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-type:content-transfer-encoding :x-original-sender:x-original-authentication-results:reply-to :precedence:mailing-list:list-id:list-post:list-help:list-archive :sender:list-subscribe:list-unsubscribe; bh=/ZqjQ2a59axEIpiry/gslZr5YiUbivXp0Q1Ibswvg9Y=; b=dPVH2y6kT7q21DG7bqb6B2ss93w1N3PiFs4gJOYmMr/HyLO8It9qAUqMJNPT5TbtGQ Lj0QgTQzs0dQqGqjJ+EuadJ1KNV+mBCpBnoaGI+V/DX2adSsvrx30R78wEzH3MjbMKJM fYgMkj8W/RG6kW4+D27SKqRt6KKlKImHAu+6mxeChzNoc2kNgHIj2T0XJaM9s8SimZpz oZlU1sVojmYfZu5JQNAlLhAojwj13kT+FntkeNiOSoILBqREOcpTmxMeMH2GNo67z9vM EoSX6mp2zIIpdkZwuVp/Pv6m0mlQBSfotsmwC+4Ea5bS+9KK/N4AdQfcvz/UTpL6WGPj 3ccg== X-Received: by 10.180.97.7 with SMTP id dw7mr143618wib.1.1431435508384; Tue, 12 May 2015 05:58:28 -0700 (PDT) X-BeenThere: rtc-linux@googlegroups.com Received: by 10.180.94.10 with SMTP id cy10ls88112wib.32.gmail; Tue, 12 May 2015 05:58:28 -0700 (PDT) X-Received: by 10.180.106.10 with SMTP id gq10mr11083520wib.0.1431435508043; Tue, 12 May 2015 05:58:28 -0700 (PDT) Received: from mail-wi0-f181.google.com (mail-wi0-f181.google.com. [209.85.212.181]) by gmr-mx.google.com with ESMTPS id g5si98713wix.1.2015.05.12.05.58.27 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 May 2015 05:58:28 -0700 (PDT) Received-SPF: pass (google.com: domain of lee.jones@linaro.org designates 209.85.212.181 as permitted sender) client-ip=209.85.212.181; Received: by mail-wi0-f181.google.com with SMTP id nf17so14256346wic.1 for ; Tue, 12 May 2015 05:58:27 -0700 (PDT) X-Gm-Message-State: ALoCoQkWfDPA+ZmPzPtGF8PpXoD0UlXn7EIk8X1DRHOldQ2mE/VsaeS8TDhCff+WpTsBjbaQfNs+ X-Received: by 10.180.91.40 with SMTP id cb8mr29410290wib.64.1431435507885; Tue, 12 May 2015 05:58:27 -0700 (PDT) Received: from localhost.localdomain (host81-129-169-99.range81-129.btcentralplus.com. [81.129.169.99]) by mx.google.com with ESMTPSA id k2sm2783057wix.4.2015.05.12.05.58.26 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 May 2015 05:58:26 -0700 (PDT) From: Lee Jones To: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, daniel.lezcano@linaro.org, tglx@linutronix.de, wim@iguana.be, a.zummo@towertech.it, linux-watchdog@vger.kernel.org, rtc-linux@googlegroups.com, linux@roeck-us.net Cc: kernel@stlinux.com, Lee Jones Subject: [rtc-linux] [PATCH v2 02/12] clocksource: sti: Provide support for the ST LPC Clocksource IP Date: Tue, 12 May 2015 13:58:10 +0100 Message-Id: <1431435500-22899-3-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1431435500-22899-1-git-send-email-lee.jones@linaro.org> References: <1431435500-22899-1-git-send-email-lee.jones@linaro.org> MIME-Version: 1.0 X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: gmr-mx.google.com; spf=pass (google.com: domain of lee.jones@linaro.org designates 209.85.212.181 as permitted sender) smtp.mail=lee.jones@linaro.org Reply-To: rtc-linux@googlegroups.com Precedence: list Mailing-list: list rtc-linux@googlegroups.com; contact rtc-linux+owners@googlegroups.com List-ID: X-Google-Group-Id: 712029733259 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , This IP is shared with Watchdog and RTC functionality. All 3 of these devices are mutually exclusive from one another i.e. Only 1 IP can be used at any given time. We use the device-driver model combined with a DT 'mode' property to enforce this. The ST LPC Clocksource IP can be used as the system (tick) timer. Signed-off-by: Lee Jones --- drivers/clocksource/Kconfig | 9 +++ drivers/clocksource/Makefile | 1 + drivers/clocksource/clksrc_st_lpc.c | 121 ++++++++++++++++++++++++++++++++++++ 3 files changed, 131 insertions(+) create mode 100644 drivers/clocksource/clksrc_st_lpc.c diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index 68161f7..01a07a6 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -250,4 +250,13 @@ config CLKSRC_PXA help This enables OST0 support available on PXA and SA-11x0 platforms. + +config CLKSRC_ST_LPC + bool + depends on ARCH_STI + select CLKSRC_OF if OF + help + Enable this option to use the Low Power controller timer + as clocksource. + endmenu diff --git a/drivers/clocksource/Makefile b/drivers/clocksource/Makefile index 752d5c7..e08da4d 100644 --- a/drivers/clocksource/Makefile +++ b/drivers/clocksource/Makefile @@ -51,3 +51,4 @@ obj-$(CONFIG_ARCH_INTEGRATOR_AP) += timer-integrator-ap.o obj-$(CONFIG_CLKSRC_VERSATILE) += versatile.o obj-$(CONFIG_CLKSRC_MIPS_GIC) += mips-gic-timer.o obj-$(CONFIG_ASM9260_TIMER) += asm9260_timer.o +obj-$(CONFIG_CLKSRC_ST_LPC) += clksrc_st_lpc.o diff --git a/drivers/clocksource/clksrc_st_lpc.c b/drivers/clocksource/clksrc_st_lpc.c new file mode 100644 index 0000000..1ad1714 --- /dev/null +++ b/drivers/clocksource/clksrc_st_lpc.c @@ -0,0 +1,121 @@ +/* + * Clocksource using the Low Power Timer found in the Low Power Controller (LPC) + * + * Copyright (C) 2015 STMicroelectronics – All Rights Reserved + * + * Author(s): Francesco Virlinzi + * Ajit Pal Singh + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include +#include + +#include + +/* Low Power Timer */ +#define LPC_LPT_LSB_OFF 0x400 +#define LPC_LPT_MSB_OFF 0x404 +#define LPC_LPT_START_OFF 0x408 + +static struct st_clksrc_ddata { + struct clk *clk; + void __iomem *base; +} ddata; + +static void st_clksrc_reset(void) +{ + writel_relaxed(0, ddata.base + LPC_LPT_START_OFF); + writel_relaxed(0, ddata.base + LPC_LPT_MSB_OFF); + writel_relaxed(0, ddata.base + LPC_LPT_LSB_OFF); + writel_relaxed(1, ddata.base + LPC_LPT_START_OFF); +} + +static int __init st_clksrc_init(void) +{ + unsigned long rate; + int ret; + + st_clksrc_reset(); + + rate = clk_get_rate(ddata.clk); + + ret = clocksource_mmio_init(ddata.base + LPC_LPT_LSB_OFF, + "clksrc-st-lpc", rate, 300, 32, + clocksource_mmio_readl_up); + if (ret) { + pr_err("clksrc-st-lpc: Failed to register clocksource\n"); + return ret; + } + + return 0; +} + +static int st_clksrc_setup_clk(struct device_node *np) +{ + struct clk *clk; + + clk = of_clk_get(np, 0); + if (IS_ERR(clk)) { + pr_err("clksrc-st-lpc: Failed to get LPC clock\n"); + return PTR_ERR(clk); + } + + if (clk_prepare_enable(clk)) { + pr_err("clksrc-st-lpc: Failed to enable LPC clock\n"); + return -EINVAL; + } + + if (!clk_get_rate(clk)) { + pr_err("clksrc-st-lpc: Failed to get LPC clock rate\n"); + clk_disable_unprepare(clk); + return -EINVAL; + } + + ddata.clk = clk; + + return 0; +} + +static void __init st_clksrc_of_register(struct device_node *np) +{ + int ret; + uint32_t mode; + + ret = of_property_read_u32(np, "st,lpc-mode", &mode); + if (ret) { + pr_err("clksrc-st-lpc: An LPC mode must be provided\n"); + return; + } + + /* LPC can either run as a Clocksource or in RTC or WDT mode */ + if (mode != ST_LPC_MODE_CLKSRC) + return; + + ddata.base = of_iomap(np, 0); + if (!ddata.base) { + pr_err("clksrc-st-lpc: Unable to map iomem\n"); + return; + } + + if (st_clksrc_setup_clk(np)) { + iounmap(ddata.base); + return; + } + + if (st_clksrc_init()) { + iounmap(ddata.base); + return; + } + + pr_info("clksrc-st-lpc: clocksource initialised - running @ %luHz\n", + clk_get_rate(ddata.clk)); +} +CLOCKSOURCE_OF_DECLARE(ddata, "st,stih407-lpc", st_clksrc_of_register);