Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp4208922imu; Fri, 30 Nov 2018 12:57:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/XUGIVAzF6rpYlDm2WZZPWTQqJPCwh9H8ooM+ZkDs51khma9WJSPn4iHoljR2e1pERrxstY X-Received: by 2002:a63:d747:: with SMTP id w7mr5933848pgi.360.1543611448982; Fri, 30 Nov 2018 12:57:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543611448; cv=none; d=google.com; s=arc-20160816; b=LWjU2/emaPCDQWuNhv4SsEa+imDsoidVdVlPRLS6mO0AUokQdxzVMGjkm43CkZoNHQ 9ThmWN8NvpH0M4js6V5peoe3voKiuTyFRE/26jatF0p0sPzlR1QBsATCL9JFQm8vC1r4 B5RC70/SSwFmIiji+TxiIizILCb5Y49DFOviZnCw14bePi4wZbW65CQk3QFwK6hSEHxB CfVRWQ7UK8y7PMAp8hkvMUM335ooiGBfDR0AsU75bzCfvpqNpscSg3ueg2JC98cIYNgF /G2hiEbou31g9AD60yc+f6ww53p5qz5mdo0wnx+TZ+w3dAAHiQsSgk6njamDAfZnLL/U Kn/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=wJHwQgWDMEBP/NNgbjssB3B91GE0fJoGSOGi0poC1z0=; b=dXXHZv8R9hHNnfdl7O/NC4UvdJN0LinVBvjC2JoQuMzZ+a+pI6sjAe8ea65KiW0u1c e3xgcc0mWXa5KTIm0vF2CLWkDJwLTzIj7htfWypLMj7mjydj1uW4vVGkOAFvfR3NTCMF +Zg5VX42plTNVHVISTE2+9nU5VYJkzej3T9IgYU/+olp1ZUESI4B2hTl2qT9Cgg75kV0 GGg3ZlIHEFjvaniaL3rRnTXxoirl2cCoV/RE7W9e1BOiG/cp8fI/SdURF6yAdGUpn+VW 35w1d5bGyG+MiiQAIJV+BhZUjxTf+NHqoQOeridbu5N980wK2nSZmkjuyclqVo7E6UhY eriw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=daaU4UDp; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v9si6541224pfl.45.2018.11.30.12.57.14; Fri, 30 Nov 2018 12:57:28 -0800 (PST) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=daaU4UDp; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726771AbeLAIHF (ORCPT + 99 others); Sat, 1 Dec 2018 03:07:05 -0500 Received: from mail-io1-f67.google.com ([209.85.166.67]:38247 "EHLO mail-io1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726744AbeLAIHE (ORCPT ); Sat, 1 Dec 2018 03:07:04 -0500 Received: by mail-io1-f67.google.com with SMTP id l14so5649291ioj.5 for ; Fri, 30 Nov 2018 12:56:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wJHwQgWDMEBP/NNgbjssB3B91GE0fJoGSOGi0poC1z0=; b=daaU4UDp/0IK2RAsu/D1B/AmF44RUjoeCdt35uCijib20Tr0GjH6ACB5k4slXbm2WU YV7xfPdw9SfzrtsXZ4v2vWFzYFiQWZ92tvjMrReKak94LW76pJvqTnKmSD3BcrDGEdLn DuEmvs0oEe203eLATGmQYAREvC2sC1OMEcDoeGO5X6fLyC1vBLVqb+NvfbHGMEo/P9na 7XvmxCPueJh/StzWtDojVLga//fBXpmJ3yzSNZpy9M3UiTE0WFhbvquemwt9EQjdLeGl F8l9t9Nnqay2wntojm8HUkhQ6HyAECGNB5lNHUBra23hxYXtXgXri6GL7Pszs8VLKRxE Ernw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wJHwQgWDMEBP/NNgbjssB3B91GE0fJoGSOGi0poC1z0=; b=Kr+jWeD/Oer5JUqxwrLbpFeb0nWUvPu6taEYA00LgyYoe+ls+2E9H7/eXhpn6hfZzg rVh2lIPkcJRMyhG4iP2K+K99uFl8+DspJrN4ZJbiMTNrKC1EumKrY0onNsfpjAbWZh2A Qm2XGVZfaP2gS8j94ETjkUXKe/p7nGAXC9j4mfegVtfck7u2S6UYNKb7Gvpwi26JGp6h xrGglxOL9TpsAmVkPNQYgaLF9WY+5h3R7/Am/i1H2BQvs92g+uj9FWrhXB159CGXOCUS Pl4ccq0vVHuAB5+lBn0m1hjK2L0DjSDrVgCuUFc3sMYPKZpHd+JM1HqibtucyJNP0xQC N+zg== X-Gm-Message-State: AA+aEWY/FzLtP9sPXs+DOwyVzDDVheZc5rYJ0NhQ0lsYmWUjngpIFbGy wRKeO5GfbxXikoASJfqdT70= X-Received: by 2002:a6b:ec07:: with SMTP id c7mr5920815ioh.33.1543611390979; Fri, 30 Nov 2018 12:56:30 -0800 (PST) Received: from localhost.localdomain ([198.52.185.227]) by smtp.gmail.com with ESMTPSA id p198sm126967itb.30.2018.11.30.12.56.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 30 Nov 2018 12:56:30 -0800 (PST) From: thesven73@gmail.com X-Google-Original-From: TheSven73@googlemail.com To: TheSven73@googlemail.com, Shawn Guo , Kees Cook , Rob Herring , Arnd Bergmann Cc: linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] bus: imx-weim: guard against timing configuration conflicts Date: Fri, 30 Nov 2018 15:56:24 -0500 Message-Id: <20181130205624.16227-3-TheSven73@googlemail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181130205624.16227-1-TheSven73@googlemail.com> References: <20181130205624.16227-1-TheSven73@googlemail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sven Van Asbroeck When adding weim child devices, there is a risk that the developer will (by mistake) specify more than one timing setting for the same chip select. The driver cannot support such a configuration. In case of conflict, this patch will print a warning to the log, and will ignore the child node in question. In this example, node acme@1 will be ignored, as it tries to modify timing settings for CS0: &weim { acme@0,0 { compatible = "acme,whatever"; reg = <0 0 0x100>; fsl,weim-cs-timing = ; }; acme@0,500 { compatible = "acme,whatnot"; reg = <0 0x500 0x100>; fsl,weim-cs-timing = ; }; }; However in this example, the driver will be happy: &weim { acme@0,0 { compatible = "acme,whatever"; reg = <0 0 0x100>; fsl,weim-cs-timing = ; }; acme@0,500 { compatible = "acme,whatnot"; reg = <0 0x500 0x100>; fsl,weim-cs-timing = ; }; }; Signed-off-by: Sven Van Asbroeck --- drivers/bus/imx-weim.c | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 24f22285395d..114e503ec785 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -46,8 +46,18 @@ static const struct imx_weim_devtype imx51_weim_devtype = { }; #define MAX_CS_REGS_COUNT 6 +#define MAX_CS_REGS 6 #define OF_REG_SIZE 3 +struct cs_timing { + bool is_applied; + u32 regs[MAX_CS_REGS_COUNT]; +}; + +struct cs_timing_state { + struct cs_timing cs[MAX_CS_REGS]; +}; + static const struct of_device_id weim_id_table[] = { /* i.MX1/21 */ { .compatible = "fsl,imx1-weim", .data = &imx1_weim_devtype, }, @@ -112,11 +122,14 @@ static int __init imx_weim_gpr_setup(struct platform_device *pdev) } /* Parse and set the timing for this device. */ -static int __init weim_timing_setup(struct device_node *np, void __iomem *base, - const struct imx_weim_devtype *devtype) +static int __init weim_timing_setup(struct device *dev, + struct device_node *np, void __iomem *base, + const struct imx_weim_devtype *devtype, + struct cs_timing_state *ts) { u32 cs_idx, value[MAX_CS_REGS_COUNT]; int i, ret, reg_idx, num_regs; + struct cs_timing *cst; if (WARN_ON(devtype->cs_regs_count > MAX_CS_REGS_COUNT)) return -EINVAL; @@ -145,10 +158,23 @@ static int __init weim_timing_setup(struct device_node *np, void __iomem *base, if (cs_idx >= devtype->cs_count) return -EINVAL; + /* prevent re-configuring a CS that's already been configured */ + cst = &ts->cs[cs_idx]; + if (cst->is_applied && memcmp(value, cst->regs, + devtype->cs_regs_count*sizeof(u32))) { + dev_err(dev, "fsl,weim-cs-timing conflict on %pOF", np); + return -EINVAL; + } + /* set the timing for WEIM */ for (i = 0; i < devtype->cs_regs_count; i++) writel(value[i], base + cs_idx * devtype->cs_stride + i * 4); + if (!cst->is_applied) { + cst->is_applied = true; + memcpy(cst->regs, value, + devtype->cs_regs_count*sizeof(u32)); + } } return 0; @@ -165,6 +191,7 @@ static int __init weim_parse_dt(struct platform_device *pdev, const struct imx_weim_devtype *devtype = of_id->data; struct device_node *child; int ret, have_child = 0; + struct cs_timing_state ts = {}; if (devtype == &imx50_weim_devtype) { ret = imx_weim_gpr_setup(pdev); @@ -179,7 +206,7 @@ static int __init weim_parse_dt(struct platform_device *pdev, } for_each_available_child_of_node(pdev->dev.of_node, child) { - ret = weim_timing_setup(child, base, devtype); + ret = weim_timing_setup(&pdev->dev, child, base, devtype, &ts); if (ret) dev_warn(&pdev->dev, "%pOF set timing failed.\n", child); -- 2.17.1