From patchwork Wed Nov 28 04:37:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Smirnov X-Patchwork-Id: 10701883 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0169813BF for ; Wed, 28 Nov 2018 04:38:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E49EB296D3 for ; Wed, 28 Nov 2018 04:38:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D86592C91C; Wed, 28 Nov 2018 04:38:16 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 025C1296D3 for ; Wed, 28 Nov 2018 04:38:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pet5CsHFVB2jGimOGDCzhi7hzpcB0EOENJd9vmbBxYg=; b=jVbfHnsdFzpvvI Xk1jgJTw/jbYnUHKAdrBGz6beR9gPs9NFqVGt3qddEFC2Vh6kf3IIke+m9TYmQDpyL2ep7em7UaY+ HsyYj6llq2QUbFdk2QPDs3kfpOxUE68PtDuzcNRFiS/a5SePzMz3SibC5O9c72UjFVD6dj3NEdtTC ziO3Lews04KrliNuBLG8NHQiQq4K8pvmJY0F05cfJ6UXuzCulD0g8iRhIWqJ0cjlmRYcQa3I3S/Yg ONmDWnzmJLr8Bp8yvAP+JfcYjYWQTvNnyeLEr4dDBml9KGVeQJV/iag5/1Av6zLJ1jn0rIFNIIVJp 3gwv0lGLCM7bzmchNPtA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRrbz-0003hI-EU; Wed, 28 Nov 2018 04:38:07 +0000 Received: from mail-pg1-x543.google.com ([2607:f8b0:4864:20::543]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gRrbw-0003ey-DB for linux-arm-kernel@lists.infradead.org; Wed, 28 Nov 2018 04:38:06 +0000 Received: by mail-pg1-x543.google.com with SMTP id 70so8896481pgh.8 for ; Tue, 27 Nov 2018 20:37:54 -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 :mime-version:content-transfer-encoding; bh=wKMQWWfUHZZOA8Vzj6/uHTz4rgCPTS/PQKfPLKAd68k=; b=Aikvz4gZIOSGLjoKRlkArv9rJlKlnMWzRKpjyaJOYGn438UAppm4ZTIkPsieyPJs/J mWB0BLnXPbOKwT6K3OWVec63a2jFEREcsrmlukroyuJE8EsQqQ7eirtWLtzBoGaol3RH MNSkBtvVQZOdW8A/38TlTcACZJU1iV8zL6axmc/KPlD04/yc11BA7XBxi7Auw/41HXBI vw2kVx0oaGdLbmLHnzMxAMaeU5+LB43vOdMwOrXhtxTjfHpDwuO6EaVE1rWe+OZSqqSd 4gKnnWissIS5rT+slIROQ5Ya0Vjni/K0oEnMVwxer4sjJQh5JpGUqoiwUycXSIdYTi29 lcxQ== 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:mime-version:content-transfer-encoding; bh=wKMQWWfUHZZOA8Vzj6/uHTz4rgCPTS/PQKfPLKAd68k=; b=SS3AnS0qDSgRCYiAsB3RIGUqQwTHiBJe8v/Z7RF2r0JwH+SOli9E9duMPguBaCjrGA gP9+MHCS5qquDYqsp1A2j2Wx2X8FaplqWhB9mqvVgZcXPuDdlLXyg8ERB0H5fz9vVM/P ZH1HXDSah3B8j7dJMahPiben4kaIj+pOaVqno9N+/2PGYWSMSq6qfpaEN19BaIYfcYNg nDnxLUmVfVl9mf478zUaOrVx45PDDhdNALPlHUPoCtkVOiHVqtk07vYXIGAosI8baNt3 2h0f8nXdFz0ROEOQtpiPVQ6KUj3oL5sHZkQGGnIjmqwlF/cyNO9HR4w3ooXYe6jBaioC RoWA== X-Gm-Message-State: AA+aEWbHCVgyQOarT1GrUGdTdTatJ+3WVcuiTSBes9kOiiL3mYTWJ1fA IJ0UCTGqgahfyDD+v/VngqY= X-Google-Smtp-Source: AFSGD/V+/SqdeXkkcw3/hIVS3ALxB9OUqaIJsoKIXJ23hshuqHsH02bGsjXbkm6ujP9vOguuqYgnYQ== X-Received: by 2002:a63:f811:: with SMTP id n17mr32690225pgh.23.1543379873586; Tue, 27 Nov 2018 20:37:53 -0800 (PST) Received: from squirtle.lan (c-24-22-235-96.hsd1.wa.comcast.net. [24.22.235.96]) by smtp.gmail.com with ESMTPSA id v2sm6387369pgs.0.2018.11.27.20.37.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 27 Nov 2018 20:37:52 -0800 (PST) From: Andrey Smirnov To: linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] reset: imx7: Add plubming to support multiple IP variants Date: Tue, 27 Nov 2018 20:37:36 -0800 Message-Id: <20181128043738.12714-2-andrew.smirnov@gmail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181128043738.12714-1-andrew.smirnov@gmail.com> References: <20181128043738.12714-1-andrew.smirnov@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181127_203804_452861_3236FABD X-CRM114-Status: GOOD ( 15.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "A.s. Dong" , Rob Herring , Richard Zhu , linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.org, Andrey Smirnov , linux-imx@nxp.com, p.zabel@pengutronix.de, Fabio Estevam , Leonard Crestez , cphealy@gmail.com, l.stach@pengutronix.de 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 In order to enable supporting i.MX8MQ with this driver, convert it to expect variant specific bits to be passed via driver data. Cc: p.zabel@pengutronix.de Cc: Fabio Estevam Cc: cphealy@gmail.com Cc: l.stach@pengutronix.de Cc: Leonard Crestez Cc: "A.s. Dong" Cc: Richard Zhu Cc: Rob Herring Cc: devicetree@vger.kernel.org Cc: linux-imx@nxp.com Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Andrey Smirnov --- drivers/reset/reset-imx7.c | 62 +++++++++++++++++++++++++++----------- 1 file changed, 45 insertions(+), 17 deletions(-) diff --git a/drivers/reset/reset-imx7.c b/drivers/reset/reset-imx7.c index 77911fa8f31d..cfbb6346a72e 100644 --- a/drivers/reset/reset-imx7.c +++ b/drivers/reset/reset-imx7.c @@ -17,14 +17,29 @@ #include #include +#include #include #include #include #include +struct imx7_src_signal { + unsigned int offset, bit; +}; + +struct imx7_src; + +struct imx7_src_variant { + const struct imx7_src_signal *signals; + unsigned int signals_num; + unsigned int (*prepare)(struct imx7_src *imx7src, unsigned long id, + bool assert); +}; + struct imx7_src { struct reset_controller_dev rcdev; struct regmap *regmap; + struct imx7_src_variant *variant; }; enum imx7_src_registers { @@ -39,10 +54,6 @@ enum imx7_src_registers { SRC_DDRC_RCR = 0x1000, }; -struct imx7_src_signal { - unsigned int offset, bit; -}; - static const struct imx7_src_signal imx7_src_signals[IMX7_RESET_NUM] = { [IMX7_RESET_A7_CORE_POR_RESET0] = { SRC_A7RCR0, BIT(0) }, [IMX7_RESET_A7_CORE_POR_RESET1] = { SRC_A7RCR0, BIT(1) }, @@ -72,17 +83,11 @@ static const struct imx7_src_signal imx7_src_signals[IMX7_RESET_NUM] = { [IMX7_RESET_DDRC_CORE_RST] = { SRC_DDRC_RCR, BIT(1) }, }; -static struct imx7_src *to_imx7_src(struct reset_controller_dev *rcdev) +static unsigned int +imx7_src_prepare(struct imx7_src *imx7src, unsigned long id, bool assert) { - return container_of(rcdev, struct imx7_src, rcdev); -} - -static int imx7_reset_set(struct reset_controller_dev *rcdev, - unsigned long id, bool assert) -{ - struct imx7_src *imx7src = to_imx7_src(rcdev); - const struct imx7_src_signal *signal = &imx7_src_signals[id]; - unsigned int value = assert ? signal->bit : 0; + const unsigned int bit = imx7src->variant->signals[id].bit; + unsigned int value = assert ? bit : 0; switch (id) { case IMX7_RESET_PCIEPHY: @@ -95,10 +100,32 @@ static int imx7_reset_set(struct reset_controller_dev *rcdev, break; case IMX7_RESET_PCIE_CTRL_APPS_EN: - value = (assert) ? 0 : signal->bit; + value = assert ? 0 : bit; break; } + return value; +} + +static const struct imx7_src_variant variant_imx7 = { + .signals = imx7_src_signals, + .signals_num = ARRAY_SIZE(imx7_src_signals), + .prepare = imx7_src_prepare, +}; + +static struct imx7_src *to_imx7_src(struct reset_controller_dev *rcdev) +{ + return container_of(rcdev, struct imx7_src, rcdev); +} + +static int imx7_reset_set(struct reset_controller_dev *rcdev, + unsigned long id, bool assert) +{ + struct imx7_src *imx7src = to_imx7_src(rcdev); + const struct imx7_src_variant *variant = imx7src->variant; + const struct imx7_src_signal *signal = &variant->signals[id]; + const unsigned int value = variant->prepare(imx7src, id, assert); + return regmap_update_bits(imx7src->regmap, signal->offset, signal->bit, value); } @@ -130,6 +157,7 @@ static int imx7_reset_probe(struct platform_device *pdev) if (!imx7src) return -ENOMEM; + imx7src->variant = of_device_get_match_data(dev); imx7src->regmap = syscon_node_to_regmap(dev->of_node); if (IS_ERR(imx7src->regmap)) { dev_err(dev, "Unable to get imx7-src regmap"); @@ -138,7 +166,7 @@ static int imx7_reset_probe(struct platform_device *pdev) regmap_attach_dev(dev, imx7src->regmap, &config); imx7src->rcdev.owner = THIS_MODULE; - imx7src->rcdev.nr_resets = IMX7_RESET_NUM; + imx7src->rcdev.nr_resets = imx7src->variant->signals_num; imx7src->rcdev.ops = &imx7_reset_ops; imx7src->rcdev.of_node = dev->of_node; @@ -146,7 +174,7 @@ static int imx7_reset_probe(struct platform_device *pdev) } static const struct of_device_id imx7_reset_dt_ids[] = { - { .compatible = "fsl,imx7d-src", }, + { .compatible = "fsl,imx7d-src", .data = &variant_imx7 }, { /* sentinel */ }, };