Received: by 2002:a25:31c3:0:0:0:0:0 with SMTP id x186csp144634ybx; Fri, 1 Nov 2019 00:48:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqwK8f9UacOx7OlFv35r0sFyvd0+/ldtV/xnhIBdh9D6U5zv7JUDq8hjnBVnAyTSZMlTygYF X-Received: by 2002:a17:906:9504:: with SMTP id u4mr8058802ejx.317.1572594482744; Fri, 01 Nov 2019 00:48:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572594482; cv=none; d=google.com; s=arc-20160816; b=pXjkb337lHLOoQ2M6qPBga7BsZdcEN4TOJMt3mtmUqaicPocVQMH4TBsyjmwEaVWYS bxVIrzviTV6OPjy8eIrEY7JPshoIJT6h7ridnLPQs5oOjbNDkx41yIJwmALUw2UrekCU SC7rfjYrxh7IX09tFKWjBLSpxlF4AE+pR/GnKo+elYn/bbzVa3NT4zJMN2bZi+0k4UAR LaS/MLOqI+0V2qWI8Ve78lrFRyyZPTgeXJPKVeu2c8lX70aOrJqXzXn3XyNvKF2+lDzE r4goBFzYhBD4RXT2xzA4LYjGwpsMIOehfQrtQGAYxVgQIW6zx2jVFshz6d9PEW9pRHb+ Z6nw== 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=YwP+Ou3x0Xq501y6yZMGhDxJBzedJFnXI45wlydnDjg=; b=wZ62xpST6TBeiSlBjK31qfWBfNMeaFJLqhCwMT4gRCxRfbNbjlzl+E6dvAymkaq8M5 ATHcvnL3s2TrcIZLG06brN+6HGaUVca+lIV2A2+Ue9DdQX+N/hvvs5fQbors2lNR8ybe muQyyjCdzFCWm2niSM+S2+db+CDzuA6GFlFukCjPBTsLFXrfh8lCAXpEpR2r2meDMjbW 08/v4oJ5Zt4UTE6dwOCy9KvdkgWE+7eXf0xFq1pjZo5qxqHcHku3lPlZDJINyv+LG9uA gRPEEov2/KFWCfbLs+bcphXAf6f9Lz/eUzJZw580PqyoQEryU1lIt6McykrAUN/HUUuG 7fgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=At9PfBtn; 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 k16si6515194edj.133.2019.11.01.00.47.39; Fri, 01 Nov 2019 00:48:02 -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=At9PfBtn; 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 S1730100AbfKAHp1 (ORCPT + 99 others); Fri, 1 Nov 2019 03:45:27 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:51194 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726921AbfKAHp0 (ORCPT ); Fri, 1 Nov 2019 03:45:26 -0400 Received: by mail-wm1-f68.google.com with SMTP id 11so8467355wmk.0 for ; Fri, 01 Nov 2019 00:45:25 -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=YwP+Ou3x0Xq501y6yZMGhDxJBzedJFnXI45wlydnDjg=; b=At9PfBtnr200Qg5yCgwaj6cV7dJ1Xi6kY3lokTY5Um/mHszQ9tQ+oE0Fjdi27WE2t9 rhbGMrbX/WTBMw5kFNO9WoiX86d+KsjMX31m+b3OI4FhvnOqTDs1pzpNL8aH6R0lHkxW rIBOf0w6MlhnutR0f9HYYnStgyMhE5bsGFxKe5/b/SI+/PH5FXzb8DrcKt6+JlOYYBiA w7dk4wFw2cJGqmwTAuFVYf2F+WoOKbafPV8vZDGik639QE64nAb/ABYNof59zIsL8KNy +jmYlSanPX1wsWSZv1VeBm3REATgSbK1eJkuULXZAHIXHgTR5YEAHrOJjGoZm07HAkXw aWeA== 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=YwP+Ou3x0Xq501y6yZMGhDxJBzedJFnXI45wlydnDjg=; b=tL2y0reGmqhIEJSHPTqT0zHjJopoU37NyCt9Xhi+sA63wIBZjvGJCDsGFn+haBukKi 9cUDpuXPAzbg9wfWd33C3Z33rIDBX4IWcKNFIMUDgeXF/XkP+hYftWR8GOPW9MfL5Iup gTYF7NONIQYm1hwnyqR7bicmLTPrV50TPg5nbsQicvK4tsYK0It/L4Jh7Ni7/9Wjklrr tvDJb4WxjW6YVSS4rkFvZe71jzpnifGH2dcvHA4sTYkTPnbVjEig0YSYjTKZDhS3FtIX I6YbjCjkvGRIvdzjNZWqikE46VgdwwILCWZSos4E+nFCH+9HYXAFR+ltgZ6QUDE845fV Kr5w== X-Gm-Message-State: APjAAAUuQiuIRnTxqGnvVW1u8oRh6ma5ElyWuYE0g5SRWBpOXGIwnEcz TRG4ftciuiZZ2/qzZqzoJ7A06A== X-Received: by 2002:a7b:cb43:: with SMTP id v3mr8689669wmj.137.1572594324646; Fri, 01 Nov 2019 00:45:24 -0700 (PDT) Received: from localhost.localdomain ([2.31.163.64]) by smtp.gmail.com with ESMTPSA id b1sm576215wrw.77.2019.11.01.00.45.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2019 00:45:24 -0700 (PDT) From: Lee Jones To: daniel.thompson@linaro.org, broonie@kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, arnd@arndb.de, linus.walleij@linaro.org, baohua@kernel.org, stephan@gerhold.net, Lee Jones Subject: [PATCH v4 03/10] mfd: cs5535-mfd: Request shared IO regions centrally Date: Fri, 1 Nov 2019 07:45:11 +0000 Message-Id: <20191101074518.26228-4-lee.jones@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191101074518.26228-1-lee.jones@linaro.org> References: <20191101074518.26228-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 | 74 ++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 41 deletions(-) diff --git a/drivers/mfd/cs5535-mfd.c b/drivers/mfd/cs5535-mfd.c index b35f1efa01f6..3b569b231510 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,11 @@ static int cs5535_mfd_probe(struct pci_dev *pdev, static void cs5535_mfd_remove(struct pci_dev *pdev) { mfd_remove_devices(&pdev->dev); + + if (machine_is_olpc()) + pci_release_region(pdev, ACPI_BAR); + + pci_release_region(pdev, PMS_BAR); pci_disable_device(pdev); } -- 2.17.1