From patchwork Wed Dec 9 20:36:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11962515 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58CD8C4361B for ; Wed, 9 Dec 2020 20:38:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 20CA723B99 for ; Wed, 9 Dec 2020 20:38:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732884AbgLIUii (ORCPT ); Wed, 9 Dec 2020 15:38:38 -0500 Received: from mga04.intel.com ([192.55.52.120]:10548 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729213AbgLIUii (ORCPT ); Wed, 9 Dec 2020 15:38:38 -0500 IronPort-SDR: 7giOMYbGVopHkmni2utGr3G5+ExGrdo8XsGwLQZelc2ZBvQg5emAEvIlAuNESXZxRGFIMnfh8/ wVf6qW/6GLuw== X-IronPort-AV: E=McAfee;i="6000,8403,9830"; a="171570350" X-IronPort-AV: E=Sophos;i="5.78,405,1599548400"; d="scan'208";a="171570350" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2020 12:36:46 -0800 IronPort-SDR: FeNYAK3Gyy9HFFGiBtyTiMiIK1351ysdS6Fwu4Q7OrbwlpLs2gX2ZKgIkft8+dRAEFoSAR07FS SNLGDb5nusIA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,405,1599548400"; d="scan'208";a="542523753" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 09 Dec 2020 12:36:44 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 7C8641C8; Wed, 9 Dec 2020 22:36:43 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , Eric Auger , Alex Williamson , kvm@vger.kernel.org, linux-usb@vger.kernel.org, Peng Hao , Arnd Bergmann , Cornelia Huck Subject: [PATCH v2 1/5] driver core: platform: Introduce platform_get_mem_or_io() Date: Wed, 9 Dec 2020 22:36:38 +0200 Message-Id: <20201209203642.27648-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org There are at least few existing users of the proposed API which retrieves either MEM or IO resource from platform device. Make it common to utilize in the existing and new users. Cc: Eric Auger Cc: Alex Williamson Cc: kvm@vger.kernel.org Cc: linux-usb@vger.kernel.org Cc: Peng Hao Cc: Arnd Bergmann Signed-off-by: Andy Shevchenko Reviewed-by: Cornelia Huck --- v2: moved to C-file and renamed for the sake of consistency with the rest platform code drivers/base/platform.c | 15 +++++++++++++++ include/linux/platform_device.h | 3 +++ 2 files changed, 18 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 88aef93eb4dd..af0c37f720e6 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -63,6 +63,21 @@ struct resource *platform_get_resource(struct platform_device *dev, } EXPORT_SYMBOL_GPL(platform_get_resource); +struct resource *platform_get_mem_or_io(struct platform_device *dev, + unsigned int num) +{ + u32 i; + + for (i = 0; i < dev->num_resources; i++) { + struct resource *r = &dev->resource[i]; + + if ((resource_type(r) & (IORESOURCE_MEM|IORESOURCE_IO)) && num-- == 0) + return r; + } + return NULL; +} +EXPORT_SYMBOL_GPL(platform_get_mem_or_io); + #ifdef CONFIG_HAS_IOMEM /** * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 77a2aada106d..ee6a9f10c2c7 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -52,6 +52,9 @@ extern struct device platform_bus; extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); +extern struct resource *platform_get_mem_or_io(struct platform_device *, + unsigned int); + extern struct device * platform_find_device_by_driver(struct device *start, const struct device_driver *drv); From patchwork Wed Dec 9 20:36:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 11962517 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.7 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCEA8C1B0D8 for ; Wed, 9 Dec 2020 20:39:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 869ED23D1C for ; Wed, 9 Dec 2020 20:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730285AbgLIUii (ORCPT ); Wed, 9 Dec 2020 15:38:38 -0500 Received: from mga12.intel.com ([192.55.52.136]:6795 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725816AbgLIUii (ORCPT ); Wed, 9 Dec 2020 15:38:38 -0500 IronPort-SDR: a+Jme+p862qPOl7JVqSs0pzwHZ7sW/IHasyBUnKcVfsVFuXNSluBUgAhplUBPeVvq8SU1mAvJX oneV2Qyz8JgA== X-IronPort-AV: E=McAfee;i="6000,8403,9830"; a="153384185" X-IronPort-AV: E=Sophos;i="5.78,405,1599548400"; d="scan'208";a="153384185" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2020 12:36:45 -0800 IronPort-SDR: V22kb8zRx4wB7Y4newVE1FGMV1uxDJAqp7RQW/L2IH4CzDzryLaXpHdEPE3B+vMoLt8N8EbSLI MffEP0iSOWDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.78,405,1599548400"; d="scan'208";a="348497562" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga002.jf.intel.com with ESMTP; 09 Dec 2020 12:36:44 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 927DF1F1; Wed, 9 Dec 2020 22:36:43 +0200 (EET) From: Andy Shevchenko To: Greg Kroah-Hartman , linux-kernel@vger.kernel.org Cc: Andy Shevchenko , linux-usb@vger.kernel.org Subject: [PATCH v2 3/5] usb: host: sl811: Switch to use platform_get_mem_or_io() Date: Wed, 9 Dec 2020 22:36:40 +0200 Message-Id: <20201209203642.27648-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201209203642.27648-1-andriy.shevchenko@linux.intel.com> References: <20201209203642.27648-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Switch to use new platform_get_mem_or_io() instead of home grown analogue. Note, the code has been moved upper in the function to allow farther cleanups, such as resource sanity check. Cc: linux-usb@vger.kernel.org Signed-off-by: Andy Shevchenko --- v2: no changes drivers/usb/host/sl811-hcd.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/drivers/usb/host/sl811-hcd.c b/drivers/usb/host/sl811-hcd.c index adaf4063690a..115ced0d93e1 100644 --- a/drivers/usb/host/sl811-hcd.c +++ b/drivers/usb/host/sl811-hcd.c @@ -1614,12 +1614,18 @@ sl811h_probe(struct platform_device *dev) void __iomem *addr_reg; void __iomem *data_reg; int retval; - u8 tmp, ioaddr = 0; + u8 tmp, ioaddr; unsigned long irqflags; if (usb_disabled()) return -ENODEV; + /* the chip may be wired for either kind of addressing */ + addr = platform_get_mem_or_io(dev, 0); + data = platform_get_mem_or_io(dev, 1); + if (!addr || !data || resource_type(addr) != resource_type(data)) + return -ENODEV; + /* basic sanity checks first. board-specific init logic should * have initialized these three resources and probably board * specific platform_data. we don't probe for IRQs, and do only @@ -1632,16 +1638,8 @@ sl811h_probe(struct platform_device *dev) irq = ires->start; irqflags = ires->flags & IRQF_TRIGGER_MASK; - /* the chip may be wired for either kind of addressing */ - addr = platform_get_resource(dev, IORESOURCE_MEM, 0); - data = platform_get_resource(dev, IORESOURCE_MEM, 1); - retval = -EBUSY; - if (!addr || !data) { - addr = platform_get_resource(dev, IORESOURCE_IO, 0); - data = platform_get_resource(dev, IORESOURCE_IO, 1); - if (!addr || !data) - return -ENODEV; - ioaddr = 1; + ioaddr = resource_type(addr) == IORESOURCE_IO; + if (ioaddr) { /* * NOTE: 64-bit resource->start is getting truncated * to avoid compiler warning, assuming that ->start