From patchwork Sun Sep 18 19:32:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= X-Patchwork-Id: 9338095 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 400E4607D0 for ; Sun, 18 Sep 2016 19:36:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1F6B528C1E for ; Sun, 18 Sep 2016 19:36:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 012BA28C20; Sun, 18 Sep 2016 19:36:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8089728C1E for ; Sun, 18 Sep 2016 19:36:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1blhrC-00089h-H4; Sun, 18 Sep 2016 19:34:30 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1blhr3-00086m-DW for linux-arm-kernel@lists.infradead.org; Sun, 18 Sep 2016 19:34:22 +0000 Received: by mail-wm0-x242.google.com with SMTP id 133so11795096wmq.2 for ; Sun, 18 Sep 2016 12:34:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=DuyQEifpSjbmEZHxstHTeb96QQhsWObJw66xkxnA1fM=; b=CBZkQffcq/+gE1f/oCSSbdGw2njjCM0H9qmxOzreUhvENVFGAySIm9/AzVzYM3C6T9 HGEPu5tg0fMAUjN5UTGx/m0ct3JBmGIgziI3+zglNUZnpb5I2Ud6qVYvniyUN/l8rsR0 bwIt9FJ3Mc7tHKhhS7y0EDC4lLJn/fmglnuoxx/jXicS/QdkNeVkCDoxcSxdXRJE9vPk odltD3cZDWz1loYL7E2r8b0b6gOco22IhKjRn75aFIH7Ggl1EMy9ZQC7Jsx8hXvvrcth dlQ/n8SqcyABnbMH1l3zUtMnP2SzX8TNKP4GF0OkbdaLDpb09a2Ds9A+a9Yn1XqB+bIi oitw== 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:mime-version :content-transfer-encoding; bh=DuyQEifpSjbmEZHxstHTeb96QQhsWObJw66xkxnA1fM=; b=P4b/Vxzed4+ZBRP+yNhru+j+D/oCHujLd0CiyMo4Bb+YyVANSCwdmrFYeXcpE3f3hT cYFNOiJLclSyc15hm4kQa+5QJOIQgAgp7uAxx+45z22eZEaAE9Gk+2RcZgg7UJ0Ygkzw dAbcwwcj6V+g8igYUkQdyCzbanDLigxL1fod3AF5jLrhIy4VDUOuYEuBDetYXhJYtZSY XY/TpG8a5AO8fmtlx7+Y2zQO36YU5q9LdkuA3ZnEcB09PeTp7uU/MXIxErmes7ZvtXRM ihjjrmLZo4MtDAJKDKE4u3HgPB7aaYXx0Ivvne0socy5cprLlT+sf4D4ut9HMM4AmqRW fRlg== X-Gm-Message-State: AE9vXwMDdObAJVnv+9elgrUm09ZXmExDSlrIceMTiKjJfmCE+DcKqSz2ngJ7WcMhOJkVrg== X-Received: by 10.28.168.14 with SMTP id r14mr723839wme.66.1474227239642; Sun, 18 Sep 2016 12:33:59 -0700 (PDT) Received: from linux-tdhb.lan (evo239.neoplus.adsl.tpnet.pl. [83.20.212.239]) by smtp.gmail.com with ESMTPSA id e5sm18288158wma.13.2016.09.18.12.33.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 18 Sep 2016 12:33:58 -0700 (PDT) From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= To: Florian Fainelli Subject: [PATCH soc/next] ARM: BCM53573: Add custom init_time with arch timer workaroud Date: Sun, 18 Sep 2016 21:32:06 +0200 Message-Id: <20160918193238.21339-1-zajec5@gmail.com> X-Mailer: git-send-email 2.9.3 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160918_123421_699411_18E09CD1 X-CRM114-Status: GOOD ( 22.09 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Scott Branden , Marc Zyngier , Ray Jui , Russell King , open list , "maintainer:BROADCOM BCM281XX/BCM11XXX/BCM216XX ARM ARCHITE..." , Guenter Roeck , Greg Kroah-Hartman , =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= , Geert Uytterhoeven , Andrew Morton , Mauro Carvalho Chehab , "David S. Miller" , Kalle Valo , "moderated list:ARM SUB-ARCHITECTURES" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafał Miłecki BCM53573 uses ARM architected timer but CFE (bootloader) is bugged and doesn't setup hardware properly. As the architecture requirement clock should be enabled and CNTFRQ should be set before starting Linux. Unfortunately it's impossible to have CFE fixed and updated on all released devices. There are plenty of them on the market and updating bootloader isn't a standard procedure. We also don't have CFE sources for BCM53573 devices and no replacement bootloader. We can't modify arch timer to simply accept specifying clock. Quoting Mark: "The clock-frequency property is at best a dodgy workaround, and this is even worse.". Marc also noted that other subsystems may rely on CNTFRQ as well. The only sane workaround seems to be fixing this CFE bug in BCM53573 arch code. It doesn't require modifying other drivers and should allow all subsystems to work correctly. Signed-off-by: Rafał Miłecki Cc: Mark Rutland Cc: Marc Zyngier --- MAINTAINERS | 1 + arch/arm/mach-bcm/Makefile | 3 +++ arch/arm/mach-bcm/bcm_53573.c | 62 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 arch/arm/mach-bcm/bcm_53573.c diff --git a/MAINTAINERS b/MAINTAINERS index a91bca7..0bb0c4b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2568,6 +2568,7 @@ BROADCOM BCM53573 ARM ARCHITECTURE M: Rafał Miłecki L: linux-arm-kernel@lists.infradead.org S: Maintained +F: arch/arm/mach-bcm/bcm_53573.c F: arch/arm/boot/dts/bcm53573* F: arch/arm/boot/dts/bcm47189* diff --git a/arch/arm/mach-bcm/Makefile b/arch/arm/mach-bcm/Makefile index 980f585..0d64778 100644 --- a/arch/arm/mach-bcm/Makefile +++ b/arch/arm/mach-bcm/Makefile @@ -50,6 +50,9 @@ ifeq ($(CONFIG_ARCH_BCM_5301X),y) obj-$(CONFIG_SMP) += platsmp.o endif +# BCM53573 +obj-$(CONFIG_ARCH_BCM_53573) += bcm_53573.o + # BCM63XXx ifeq ($(CONFIG_ARCH_BCM_63XX),y) obj-y += bcm63xx.o diff --git a/arch/arm/mach-bcm/bcm_53573.c b/arch/arm/mach-bcm/bcm_53573.c new file mode 100644 index 0000000..540a247 --- /dev/null +++ b/arch/arm/mach-bcm/bcm_53573.c @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2016 Rafał Miłecki + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +static inline void arch_timer_set_cntfrq(u32 cntfrq) +{ + asm volatile("mcr p15, 0, %0, c14, c0, 0" : : "r" (cntfrq)); +} + +/* + * CFE bootloader doesn't meet arch requirements. It doesn't enable ILP clock + * which is required for arch timer and doesn't set CNTFRQ. + * Fix is up here. + */ +static void __init bcm_53573_setup_arch_timer(void) +{ + struct of_phandle_args out_args = { }; + struct clk *clk; + + out_args.np = of_find_compatible_node(NULL, NULL, "brcm,bcm53573-ilp"); + if (!out_args.np) { + pr_warn("Failed to find ILP node\n"); + return; + } + + clk = of_clk_get_from_provider(&out_args); + if (!IS_ERR(clk)) { + if (!clk_prepare_enable(clk)) + arch_timer_set_cntfrq(clk_get_rate(clk)); + } + + of_node_put(out_args.np); +} + +/* A copy of ARM's time_init with workaround inserted */ +static void __init bcm_53573_init_time(void) +{ +#ifdef CONFIG_COMMON_CLK + of_clk_init(NULL); +#endif + bcm_53573_setup_arch_timer(); + clocksource_probe(); +} + +static const char *const bcm_53573_dt_compat[] __initconst = { + "brcm,bcm53573", + NULL, +}; + +DT_MACHINE_START(BCM5301X, "BCM53573") + .init_time = bcm_53573_init_time, + .dt_compat = bcm_53573_dt_compat, +MACHINE_END