From patchwork Thu Jul 31 21:28:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Emilio_L=C3=B3pez?= X-Patchwork-Id: 4659111 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 459749F377 for ; Thu, 31 Jul 2014 21:32:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3CB0F20145 for ; Thu, 31 Jul 2014 21:32:26 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C79A2012E for ; Thu, 31 Jul 2014 21:32:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XCxvp-0001Pb-9Z; Thu, 31 Jul 2014 21:30:37 +0000 Received: from yotta.elopez.com.ar ([2a00:1768:1004:d00d:c0de:4:f00d:cafe]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XCxvD-0008F3-G9 for linux-arm-kernel@lists.infradead.org; Thu, 31 Jul 2014 21:30:00 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=elopez.com.ar; s=mail; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=X9SrKUpwLbYCZuMsHtSJEZFcDU2xekK4W/oBKGKeQU4=; b=LAh2t/wgDuWzms+eLYEBWVLPOFIAiS2oYnvtAjfCfQ+iXX4u0z4naTSor0F0JfbDNajzmOE3iRZwV/3QmrVqS7hSWEULYf9XuFWh6obCXy5PPM3lRraX+tgOFpB0CgESuRgDjPY0XN9e3jHLJteSlo0jV43pX/RO0fEvCd9cruoynKgaAdRxL6HOeXSs/YypHgzAFVeaUd+bTYk+E61C37GgxNxgTrYsn9Y9jjw8uuaRwDPU04i0hjoVgFXLYhtA7v1ADQschoDhwmCEFEbQVmo8OWqnQQfL2/IkZFTzOU87PmkfOWHHbFEU2EeyZ2iYljUP3KPaxWEE8XRU+zwuXA==; Received: from [181.164.71.8] (helo=desktop.lan) by yotta.elopez.com.ar with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_CBC_SHA256:128) (Exim 4.82_1-5b7a7c0-XX) id 1XCxup-0003Cn-PT; Thu, 31 Jul 2014 18:29:36 -0300 From: =?UTF-8?q?Emilio=20L=C3=B3pez?= To: Maxime Ripard , Mike Turquette Subject: [PATCH 2/9] ARM: sunxi: quirk support Date: Thu, 31 Jul 2014 18:28:05 -0300 Message-Id: <1406842092-25207-3-git-send-email-emilio@elopez.com.ar> X-Mailer: git-send-email 2.0.3 In-Reply-To: <1406842092-25207-1-git-send-email-emilio@elopez.com.ar> References: <1406842092-25207-1-git-send-email-emilio@elopez.com.ar> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140731_142959_837435_27F1774E X-CRM114-Status: GOOD ( 14.53 ) X-Spam-Score: -0.8 (/) Cc: Arnd Bergmann , =?UTF-8?q?Emilio=20L=C3=B3pez?= , codekipper@gmail.com, jonsmirl@gmail.com, Olof Johansson , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, some hardware revisions of sunxi SoCs need special care on some blocks because of hardware differences and/or bugs. Unfortunately, it is unfeasible to account for these issues directly when writing the device tree, as SoC revision can vary between different units of the same device. This commit introduces a place to adjust DT compatibles as needed to work around said issues before devices are probed. To demonstrate usage, two quirks are added for the PLL2 and audio codec on sun4i. Signed-off-by: Emilio López --- arch/arm/mach-sunxi/Makefile | 2 +- arch/arm/mach-sunxi/quirks.c | 82 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 arch/arm/mach-sunxi/quirks.c diff --git a/arch/arm/mach-sunxi/Makefile b/arch/arm/mach-sunxi/Makefile index 589239b..7c13f99 100644 --- a/arch/arm/mach-sunxi/Makefile +++ b/arch/arm/mach-sunxi/Makefile @@ -1,2 +1,2 @@ -obj-$(CONFIG_ARCH_SUNXI) += sunxi.o sunxi-soc-id.o +obj-$(CONFIG_ARCH_SUNXI) += sunxi.o sunxi-soc-id.o quirks.o obj-$(CONFIG_SMP) += platsmp.o diff --git a/arch/arm/mach-sunxi/quirks.c b/arch/arm/mach-sunxi/quirks.c new file mode 100644 index 0000000..99cdaa0 --- /dev/null +++ b/arch/arm/mach-sunxi/quirks.c @@ -0,0 +1,82 @@ +/* + * Runtime quirk handling for sunxi SoCs + * + * Copyright 2014 Emilio López + * + * Emilio López + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include + +#include "sunxi-soc-id.h" + +static int __init update_compatible_string(const char *oldc, const char *newc) +{ + int count = 0; + struct property *newprop; + size_t newlen = strlen(newc); + struct device_node *np = NULL; + + for_each_compatible_node(np, NULL, oldc) { + newprop = kzalloc(sizeof(*newprop), GFP_KERNEL); + if (!newprop) + return -ENOMEM; + + newprop->name = kstrdup("compatible", GFP_KERNEL); + newprop->value = kstrdup(newc, GFP_KERNEL); + newprop->length = newlen; + + if (!newprop->name || !newprop->value) { + kfree(newprop); + return -ENOMEM; + } + + of_update_property(np, newprop); + count++; + } + + return count; +} + +static void __init sun4i_pll2_quirk(void) +{ + /* Only revision A is affected */ + if (sunxi_soc_revision() != 'A') + return; + + WARN_ON(!update_compatible_string("allwinner,sun4i-a10-b-pll2", + "allwinner,sun4i-a10-a-pll2")); +} + +static void __init sun4i_codec_quirk(void) +{ + /* Only revision A is affected */ + if (sunxi_soc_revision() != 'A') + return; + + WARN_ON(!update_compatible_string("allwinner,sun4i-a10-b-codec", + "allwinner,sun4i-a10-a-codec")); +} + +static int __init sunxi_apply_quirks(void) +{ + if (of_machine_is_compatible("allwinner,sun4i-a10")) { + sun4i_pll2_quirk(); + sun4i_codec_quirk(); + } + + return 0; +} +postcore_initcall(sunxi_apply_quirks)