[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200518155304.28639-2-zhengdejin5@gmail.com>
Date: Mon, 18 May 2020 23:53:03 +0800
From: Dejin Zheng <zhengdejin5@...il.com>
To: gregkh@...uxfoundation.org, rafael@...nel.org,
f.fainelli@...il.com, rjui@...adcom.com, sbranden@...adcom.com,
michal.simek@...inx.com, baruch@...s.co.il,
wsa+renesas@...g-engineering.com, paul@...pouillou.net,
khilman@...libre.com, shawnguo@...nel.org, s.hauer@...gutronix.de,
festevam@...il.com, linux-imx@....com, vz@...ia.com,
slemieux.tyco@...il.com, heiko@...ech.de, baohua@...nel.org,
linus.walleij@...aro.org, ardb@...nel.org,
radu_nicolae.pirea@....ro, zhouyanjie@...yeetech.com,
linux-i2c@...r.kernel.org
Cc: linux-kernel@...r.kernel.org, Dejin Zheng <zhengdejin5@...il.com>
Subject: [PATCH v1 1/2] drivers: provide devm_platform_request_irq()
It will call devm_request_irq() after platform_get_irq() function
in many drivers, sometimes, it is not right of the error handling
for these two functions in some drivers. so provide this function
to simplify the driver.
Signed-off-by: Dejin Zheng <zhengdejin5@...il.com>
---
drivers/base/platform.c | 33 +++++++++++++++++++++++++++++++++
include/linux/platform_device.h | 4 ++++
2 files changed, 37 insertions(+)
diff --git a/drivers/base/platform.c b/drivers/base/platform.c
index 823646ffb978..75c600e286a8 100644
--- a/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -275,6 +275,39 @@ int platform_irq_count(struct platform_device *dev)
}
EXPORT_SYMBOL_GPL(platform_irq_count);
+/**
+ * devm_platform_request_irq - get an irq and allocate an interrupt
+ * line for a managed device
+ * @pdev: platform device
+ * @num: IRQ number index
+ * @irq: get an IRQ for a device if irq != NULL
+ * @handler: function to be called when the IRQ occurs
+ * @irqflags: interrupt type flags
+ * @devname: an ascii name for the claiming device, dev_name(dev) if NULL
+ * @dev_id: a cookie passed back to the handler function
+ *
+ * Return: zero on success, negative error number on failure.
+ */
+int devm_platform_request_irq(struct platform_device *pdev, unsigned int num,
+ unsigned int *irq, irq_handler_t handler,
+ unsigned long irqflags, const char *devname, void *dev_id)
+{
+ int tmp_irq, ret;
+
+ tmp_irq = platform_get_irq(pdev, num);
+ if (tmp_irq < 0)
+ return tmp_irq;
+
+ ret = devm_request_irq(&pdev->dev, tmp_irq, handler, irqflags,
+ devname, dev_id);
+ if (ret < 0)
+ dev_err(&pdev->dev, "can't request IRQ\n");
+ else if (irq != NULL)
+ *irq = tmp_irq;
+ return ret;
+}
+EXPORT_SYMBOL_GPL(devm_platform_request_irq);
+
/**
* platform_get_resource_byname - get a resource for a device by name
* @dev: platform device
diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h
index 77a2aada106d..d94652deea5c 100644
--- a/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -11,6 +11,7 @@
#define _PLATFORM_DEVICE_H_
#include <linux/device.h>
+#include <linux/interrupt.h>
#define PLATFORM_DEVID_NONE (-1)
#define PLATFORM_DEVID_AUTO (-2)
@@ -70,6 +71,9 @@ devm_platform_ioremap_resource_byname(struct platform_device *pdev,
extern int platform_get_irq(struct platform_device *, unsigned int);
extern int platform_get_irq_optional(struct platform_device *, unsigned int);
extern int platform_irq_count(struct platform_device *);
+extern int devm_platform_request_irq(struct platform_device *pdev,
+ unsigned int num, unsigned int *irq, irq_handler_t handler,
+ unsigned long irqflags, const char *devname, void *dev_id);
extern struct resource *platform_get_resource_byname(struct platform_device *,
unsigned int,
const char *);
--
2.25.0
Powered by blists - more mailing lists