Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3951664ybg; Fri, 25 Oct 2019 11:11:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqwy9mQ5Gur4oRXNFfqQQWboHPlWwjVBQrHnJBCV/zeVo0yceoidNCAH1BtZQGZ1Z7RXIAJ7 X-Received: by 2002:a50:9254:: with SMTP id j20mr5737578eda.0.1572027081057; Fri, 25 Oct 2019 11:11:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572027081; cv=none; d=google.com; s=arc-20160816; b=kOFEtZx9jKK0xHjQMeYm4roiFEB22vkUuJOCuQPhwh3eXoFMkAOQ/0A3Otrhfg4TFs t2/P1iWWTfZFRgyNq+VSONrMxfcceiD0U1dhZno3LbC5z4l09OfP7/7wR0aCcUJRI9f0 dBVG06ecJczSdHeQfDRDT+Gls/IJooJl3Qx8U+mB0V3JNfACzh7mfFAVuh/FXQqsvGIm Iw9lvizel9rZnmFYnPiIoO1lHnjg0noqs07e6rk8hG02BblTN3n8NV2YT5WnHRnM+nlR Jlyh8HagLqCh4+QTZc/RXrycWVI+A+voz1K78ynLaTpSxywCXUqTctPrUTheQEmaEBbR yfbQ== 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=QdHIheq0u1kbfETofjh9zy8pkEBm58YeSTndJs2NHac=; b=Tn+QUNpB/PaNteH8gnPKv47/uI2A1O7nNYWwfPJ8rJPpRaPYSW4jjzZ+f0mJn/oBcN Ua5ICy30K6tof3HvDwFi53NHlF60ndINg4a3mYH2Rhk+2n6kGFpnjPmV9WSlNUXJ3Cxv qdz2eryqLgmIh0DGgTfFZ9HrtnZar12uXZlrX70bAeTHyly3cXq/LuLD36y6cQaQpsgL lmE/0VjMaW0X/l/BqcBHq16Px0Cky8UT1VGbFoHLUt7QUCO3iBebA2tnMOAcJk2H4cDR Gf7hR9/t+lvYs8s2yPC5ZQoToa1pu0UYfLosUMhZJjfAnn4fCgqvPzBGoDq90IAAVXkw nvYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPwrn6NP; 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=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c22si1749871edn.437.2019.10.25.11.10.57; Fri, 25 Oct 2019 11:11:21 -0700 (PDT) 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=@linaro.org header.s=google header.b=gPwrn6NP; 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=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2503522AbfJXQim (ORCPT + 99 others); Thu, 24 Oct 2019 12:38:42 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:44226 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2503503AbfJXQil (ORCPT ); Thu, 24 Oct 2019 12:38:41 -0400 Received: by mail-wr1-f68.google.com with SMTP id z11so3461390wro.11 for ; Thu, 24 Oct 2019 09:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QdHIheq0u1kbfETofjh9zy8pkEBm58YeSTndJs2NHac=; b=gPwrn6NPz7e9qabl6w9R3rqJrhVP14D5VEoM/nG38JSXosj+EzFKlTPlVNYElFho00 +o+M2rHC0YjYffk6XVRDD8OSdWVwqxIOndJ67G98SIzgVGfeyu2GtRUJFmD/WG6dTihy 1TN9flRSC9i7K1ODhHNV5mHaS7EfS9ZS7dluqdJNoUNzUatqHVKaSg2272m4QJQv9ZET Yat6gdQYo4VoX02nxBEIbJBiFvNigZs/epeRYtuOw5uqzGc5QFRr639xcuDCcKg7YKDZ tEBy/uFvDYMKF2GfDzfZ17TxIKWKBh1DcbZBNXHAlzAEar7zo8EHVVFXUKDoS5K4oPzC ygHg== 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=QdHIheq0u1kbfETofjh9zy8pkEBm58YeSTndJs2NHac=; b=EfxIjxp9x8MmLYf6a/N4p0c4W+4WAYS0mTz0gVF5SAgXCChRgoKPNC+b3aTOoSaFZR Ye13m00iemnJ8pBq9Rg0b1HLMUFPxR6kJnLLCU0vHjjvr5MHbtXb3YTyQ3To8LoaHhDX m9Tnjr1Qgyi0JUYDbD85QKnFSv9qzSXOme4pZZNnTM5MoAs9nvQQJGrqP+N7Kc83KMsR 70xSbujgovuUbZgpWAcl2CQmX2dsGS4CSoWs2k+vHbU12lxRJK6srbtZjitlQxLBl5du +KTHpRVJN9g7+duIIiAIqrNoRbfeNLU/1b0lGwIye14YmRANf9z+AKrX6yHeeUgZ1DEC 1XRA== X-Gm-Message-State: APjAAAWQXjIZDrCZza1WdkhM/2WLDF/wejdlX/DqKQQ+pDkmH50av8Rh VFpksmrEJOS/bDDMfxh0u3VeJg== X-Received: by 2002:adf:f04e:: with SMTP id t14mr4491900wro.106.1571935119378; Thu, 24 Oct 2019 09:38:39 -0700 (PDT) Received: from localhost.localdomain ([95.149.164.99]) by smtp.gmail.com with ESMTPSA id 6sm3446175wmd.36.2019.10.24.09.38.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 09:38:38 -0700 (PDT) From: Lee Jones To: daniel.thompson@linaro.org, arnd@arndb.de, broonie@kernel.org, linus.walleij@linaro.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, baohua@kernel.org, stephan@gerhold.net, Lee Jones Subject: [PATCH v3 03/10] mfd: cs5535-mfd: Request shared IO regions centrally Date: Thu, 24 Oct 2019 17:38:25 +0100 Message-Id: <20191024163832.31326-4-lee.jones@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191024163832.31326-1-lee.jones@linaro.org> References: <20191024163832.31326-1-lee.jones@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Prior to this patch, IO regions were requested via an MFD subsytem-level .enable() call-back and similarly released by a .disable() call-back. Double requests/releases were avoided by a centrally handled usage count mechanism. This complexity can all be avoided by handling IO regions only once during .probe() and .remove() of the parent device. Since this is the only legitimate user of the aforementioned usage count mechanism, this patch will allow it to be removed from MFD core in subsequent steps. Suggested-by: Daniel Thompson Signed-off-by: Lee Jones --- drivers/mfd/cs5535-mfd.c | 71 +++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/drivers/mfd/cs5535-mfd.c b/drivers/mfd/cs5535-mfd.c index b35f1efa01f6..27fa8fa1ec9b 100644 --- a/drivers/mfd/cs5535-mfd.c +++ b/drivers/mfd/cs5535-mfd.c @@ -27,38 +27,6 @@ enum cs5535_mfd_bars { NR_BARS, }; -static int cs5535_mfd_res_enable(struct platform_device *pdev) -{ - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_IO, 0); - if (!res) { - dev_err(&pdev->dev, "can't fetch device resource info\n"); - return -EIO; - } - - if (!request_region(res->start, resource_size(res), DRV_NAME)) { - dev_err(&pdev->dev, "can't request region\n"); - return -EIO; - } - - return 0; -} - -static int cs5535_mfd_res_disable(struct platform_device *pdev) -{ - struct resource *res; - - res = platform_get_resource(pdev, IORESOURCE_IO, 0); - if (!res) { - dev_err(&pdev->dev, "can't fetch device resource info\n"); - return -EIO; - } - - release_region(res->start, resource_size(res)); - return 0; -} - static struct resource cs5535_mfd_resources[NR_BARS]; static struct mfd_cell cs5535_mfd_cells[] = { @@ -81,17 +49,11 @@ static struct mfd_cell cs5535_mfd_cells[] = { .name = "cs5535-pms", .num_resources = 1, .resources = &cs5535_mfd_resources[PMS_BAR], - - .enable = cs5535_mfd_res_enable, - .disable = cs5535_mfd_res_disable, }, { .name = "cs5535-acpi", .num_resources = 1, .resources = &cs5535_mfd_resources[ACPI_BAR], - - .enable = cs5535_mfd_res_enable, - .disable = cs5535_mfd_res_disable, }, }; @@ -117,22 +79,47 @@ static int cs5535_mfd_probe(struct pci_dev *pdev, r->end = pci_resource_end(pdev, bar); } + err = pci_request_region(pdev, PMS_BAR, DRV_NAME); + if (err) { + dev_err(&pdev->dev, "Failed to request PMS_BAR's IO region\n"); + goto err_disable; + } + err = mfd_add_devices(&pdev->dev, PLATFORM_DEVID_NONE, cs5535_mfd_cells, ARRAY_SIZE(cs5535_mfd_cells), NULL, 0, NULL); if (err) { dev_err(&pdev->dev, "Failed to add CS5535 sub-devices: %d\n", err); - goto err_disable; + goto err_release_pms; } - if (machine_is_olpc()) - mfd_clone_cell("cs5535-acpi", olpc_acpi_clones, ARRAY_SIZE(olpc_acpi_clones)); + if (machine_is_olpc()) { + err = pci_request_region(pdev, ACPI_BAR, DRV_NAME); + if (err) { + dev_err(&pdev->dev, + "Failed to request ACPI_BAR's IO region\n"); + goto err_remove_devices; + } + + err = mfd_clone_cell("cs5535-acpi", olpc_acpi_clones, + ARRAY_SIZE(olpc_acpi_clones)); + if (err) { + dev_err(&pdev->dev, "Failed to clone MFD cell\n"); + goto err_release_acpi; + } + } dev_info(&pdev->dev, "%zu devices registered.\n", ARRAY_SIZE(cs5535_mfd_cells)); return 0; +err_release_acpi: + pci_release_region(pdev, ACPI_BAR); +err_remove_devices: + mfd_remove_devices(&pdev->dev); +err_release_pms: + pci_release_region(pdev, PMS_BAR); err_disable: pci_disable_device(pdev); return err; @@ -141,6 +128,8 @@ static int cs5535_mfd_probe(struct pci_dev *pdev, static void cs5535_mfd_remove(struct pci_dev *pdev) { mfd_remove_devices(&pdev->dev); + pci_release_region(pdev, ACPI_BAR); + pci_release_region(pdev, PMS_BAR); pci_disable_device(pdev); } -- 2.17.1