linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource()
@ 2020-10-27 17:58 Andy Shevchenko
  2020-10-27 17:58 ` [PATCH v1 3/5] usb: host: sl811: Switch to use platform_get_mem_or_io_resource() Andy Shevchenko
  2020-12-03 13:21 ` [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Cornelia Huck
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-10-27 17:58 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel
  Cc: Andy Shevchenko, Eric Auger, Alex Williamson, Cornelia Huck, kvm,
	linux-usb, Peng Hao, Arnd Bergmann

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.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Cc: Eric Auger <eric.auger@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.com>
Cc: Cornelia Huck <cohuck@redhat.com>
Cc: kvm@vger.kernel.org
Cc: linux-usb@vger.kernel.org
Cc: Peng Hao <peng.hao2@zte.com.cn>
Cc: Arnd Bergmann <arnd@arndb.de>
---
 include/linux/platform_device.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 77a2aada106d..eb8d74744e29 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -52,6 +52,19 @@ extern struct device platform_bus;
 
 extern struct resource *platform_get_resource(struct platform_device *,
 					      unsigned int, unsigned int);
+static inline
+struct resource *platform_get_mem_or_io_resource(struct platform_device *pdev,
+						 unsigned int num)
+{
+	struct resource *res;
+
+	res = platform_get_resource(pdev, IORESOURCE_MEM, num);
+	if (res)
+		return res;
+
+	return platform_get_resource(pdev, IORESOURCE_IO, num);
+}
+
 extern struct device *
 platform_find_device_by_driver(struct device *start,
 			       const struct device_driver *drv);
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v1 3/5] usb: host: sl811: Switch to use platform_get_mem_or_io_resource()
  2020-10-27 17:58 [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Andy Shevchenko
@ 2020-10-27 17:58 ` Andy Shevchenko
  2020-12-03 13:21 ` [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Cornelia Huck
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Shevchenko @ 2020-10-27 17:58 UTC (permalink / raw)
  To: Greg Kroah-Hartman, linux-kernel; +Cc: Andy Shevchenko, linux-usb

Switch to use new platform_get_mem_or_io_resource() 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 <andriy.shevchenko@linux.intel.com>
---
 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..7e0d6f686231 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_resource(dev, 0);
+	data = platform_get_mem_or_io_resource(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
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource()
  2020-10-27 17:58 [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Andy Shevchenko
  2020-10-27 17:58 ` [PATCH v1 3/5] usb: host: sl811: Switch to use platform_get_mem_or_io_resource() Andy Shevchenko
@ 2020-12-03 13:21 ` Cornelia Huck
  1 sibling, 0 replies; 3+ messages in thread
From: Cornelia Huck @ 2020-12-03 13:21 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Greg Kroah-Hartman, linux-kernel, Eric Auger, Alex Williamson,
	kvm, linux-usb, Peng Hao, Arnd Bergmann

On Tue, 27 Oct 2020 19:58:02 +0200
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> 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.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> Cc: Eric Auger <eric.auger@redhat.com>
> Cc: Alex Williamson <alex.williamson@redhat.com>
> Cc: Cornelia Huck <cohuck@redhat.com>
> Cc: kvm@vger.kernel.org
> Cc: linux-usb@vger.kernel.org
> Cc: Peng Hao <peng.hao2@zte.com.cn>
> Cc: Arnd Bergmann <arnd@arndb.de>
> ---
>  include/linux/platform_device.h | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
> 
> diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
> index 77a2aada106d..eb8d74744e29 100644
> --- a/include/linux/platform_device.h
> +++ b/include/linux/platform_device.h
> @@ -52,6 +52,19 @@ extern struct device platform_bus;
>  
>  extern struct resource *platform_get_resource(struct platform_device *,
>  					      unsigned int, unsigned int);
> +static inline
> +struct resource *platform_get_mem_or_io_resource(struct platform_device *pdev,

Minor nit: If I would want to break up the long line, I'd use

static inline struct resource *
platform_get_mem_or_io_resource(...)

> +						 unsigned int num)
> +{
> +	struct resource *res;
> +
> +	res = platform_get_resource(pdev, IORESOURCE_MEM, num);
> +	if (res)
> +		return res;
> +
> +	return platform_get_resource(pdev, IORESOURCE_IO, num);
> +}
> +
>  extern struct device *
>  platform_find_device_by_driver(struct device *start,
>  			       const struct device_driver *drv);

Reviewed-by: Cornelia Huck <cohuck@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-12-03 13:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 17:58 [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Andy Shevchenko
2020-10-27 17:58 ` [PATCH v1 3/5] usb: host: sl811: Switch to use platform_get_mem_or_io_resource() Andy Shevchenko
2020-12-03 13:21 ` [PATCH v1 1/5] driver core: platform: Introduce platform_get_mem_or_io_resource() Cornelia Huck

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).