From patchwork Thu Oct 24 16:38:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 177542 Delivered-To: patch@linaro.org Received: by 2002:ac9:3c86:0:0:0:0:0 with SMTP id w6csp2399992ocf; Thu, 24 Oct 2019 09:38:48 -0700 (PDT) X-Google-Smtp-Source: APXvYqxaK10GrBSYWljYCwss+hWs7L/xBcEujshQQDXaOVDSdeHEZlBIUbsaDhXa2P9E73LAVx66 X-Received: by 2002:a05:6402:3072:: with SMTP id bs18mr25958414edb.120.1571935128004; Thu, 24 Oct 2019 09:38:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571935127; cv=none; d=google.com; s=arc-20160816; b=iLsbssxboQ3BYG/Y4Wkk8jxACJg/Y28BOSvaTeFOtbDmpsXxs8/66dcAQ3bxymhspF UXlhpKHHC8qoIezefztuidF2hXWtyg1IiiclFzFO3HJU7gkemWKXMRnuMykGsEYszGOD vomSNkWneDByBdddGz4vHgtYM440HyoI16iH9+KeWY+tEuzt5HbMW5ebqZOkf3L9q6im g/ke2xP8WknvCw85JD1Zp4J0A1vXXlQQzOtb4h8f7e3ppYiaU25W8ZLba+kSU85FjpWX TzTjOU+6cLK0k3uz5xX1FyidrZSqWT5JnfWbpw+Cj1vGP4vFVT94AWk8rIMk9VEnUgTP VDuQ== 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 jo12si4186058ejb.176.2019.10.24.09.38.47; Thu, 24 Oct 2019 09:38:47 -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 S2503527AbfJXQin (ORCPT + 26 others); Thu, 24 Oct 2019 12:38:43 -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(-) -- 2.17.1 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); }