uio/pdrv_genirq: Add OF support
PATCH v4 1/1 uio/pdrv_genirq: Add OF support
Adding OF binding to genirq.
Version string is setup to the "devicetree".
Compatible string is not setup for now but you can add your custom compatible string to uio_of_genirq_match structure.
For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = {
{ .compatible = "vendor,device", },
{ /* empty for now */ },
};---
v4: Remove dev_info messages
Check irq against -ENXIO for no irq
v3: Fix irq binding
Use "devicetree" as version string
v2: Remove additional resource binding
Setup correct version string
Clear compatible string
--- drivers/uio/uio_pdrv_genirq.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-)
drivers/uio/uio_pdrv_genirq.c +39 -0
@@ -23,6 +23,10 @@#include <linux/pm_runtime.h> #include <linux/slab.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/of_address.h> +#define DRIVER_NAME "uio_pdrv_genirq"struct uio_pdrv_genirq_platdata {
@@ -97,6 +101,27 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)int ret = -EINVAL ;int i; +if (!uioinfo) { +int irq; + +/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL ); +if (!uioinfo) { + ret = -ENOMEM ; +dev_err (&pdev->dev,"unable to kmalloc\n" ); + goto bad2; + } + uioinfo->name = pdev->dev.of_node->name; + uioinfo->version ="devicetree" ; + +/* Multiple IRQs are not supported */ + irq =platform_get_irq (pdev,0 ); +if (irq == -ENXIO ) + uioinfo->irq =UIO_IRQ_NONE ; +else + uioinfo->irq = irq; + } +if (!uioinfo || !uioinfo->name || !uioinfo->version) {dev_err (&pdev->dev,"missing platform_data\n" ); goto bad0;
@@ -180,6 +205,10 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)kfree (priv);pm_runtime_disable (&pdev->dev); bad0: +/* kfree uioinfo for CONFIG_OF */ +if (!pdev->dev.platform_data) +kfree (uioinfo); + bad2:return ret; }
@@ -215,6 +244,15 @@ static const struct dev_pm_ops uio_pdrv_genirq_dev_pm_ops = { .runtime_resume = uio_pdrv_genirq_runtime_nop, }; +#ifdef CONFIG_OF +static const struct of_device_id __devinitconst uio_of_genirq_match[] = { + {/* empty for now */ }, +}; +MODULE_DEVICE_TABLE (of, uio_of_genirq_match); +#else +# define uio_of_genirq_match NULL +#endif +static struct platform_driver uio_pdrv_genirq = { .probe = uio_pdrv_genirq_probe, .remove = uio_pdrv_genirq_remove,
@@ -222,6 +260,7 @@ static struct platform_driver uio_pdrv_genirq = { .name = DRIVER_NAME, .owner = THIS_MODULE, .pm = &uio_pdrv_genirq_dev_pm_ops, + .of_match_table = uio_of_genirq_match, }, };
Signature · 1 line
1.5.5.6
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };
Looks OK to me.
Thanks,
Hans
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>
Quoted 98 lines
---
v4: Remove
dev_infomessages
Check irq against-ENXIOfor no irqv3: Fix irq binding
Use "devicetree" as version stringv2: Remove additional resource binding
Setup correct version string
Clear compatible string--- drivers/uio/uio_pdrv_genirq.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-)drivers/uio/uio_pdrv_genirq.c +39
-0@@ -23,6 +23,10 @@#include <linux/pm_runtime.h> #include <linux/slab.h> +#include <linux/of.h> +#include <linux/of_platform.h> +#include <linux/of_address.h> +#define DRIVER_NAME "uio_pdrv_genirq"struct uio_pdrv_genirq_platdata {@@ -97,6 +101,27 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)int ret = -EINVAL ;int i; +if (!uioinfo) { +int irq; + +/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL ); +if (!uioinfo) { + ret = -ENOMEM ; +dev_err (&pdev->dev,"unable to kmalloc\n" ); + goto bad2; + } + uioinfo->name = pdev->dev.of_node->name; + uioinfo->version ="devicetree" ; + +/* Multiple IRQs are not supported */ + irq =platform_get_irq (pdev,0 ); +if (irq == -ENXIO ) + uioinfo->irq =UIO_IRQ_NONE ; +else + uioinfo->irq = irq; + } +if (!uioinfo || !uioinfo->name || !uioinfo->version) {dev_err (&pdev->dev,"missing platform_data\n" ); goto bad0;@@ -180,6 +205,10 @@ static int uio_pdrv_genirq_probe(struct platform_device *pdev)kfree (priv);pm_runtime_disable (&pdev->dev); bad0: +/* kfree uioinfo for CONFIG_OF */ +if (!pdev->dev.platform_data) +kfree (uioinfo); + bad2:return ret; }@@ -215,6 +244,15 @@ static const struct dev_pm_ops uio_pdrv_genirq_dev_pm_ops = { .runtime_resume = uio_pdrv_genirq_runtime_nop, }; +#ifdef CONFIG_OF +static const struct of_device_id __devinitconst uio_of_genirq_match[] = { + {/* empty for now */ }, +}; +MODULE_DEVICE_TABLE (of, uio_of_genirq_match); +#else +# define uio_of_genirq_match NULL +#endif +static struct platform_driver uio_pdrv_genirq = { .probe = uio_pdrv_genirq_probe, .remove = uio_pdrv_genirq_remove,@@ -222,6 +260,7 @@ static struct platform_driver uio_pdrv_genirq = { .name = DRIVER_NAME, .owner = THIS_MODULE, .pm = &uio_pdrv_genirq_dev_pm_ops, + .of_match_table = uio_of_genirq_match, }, };Signature · 1 line
1.5.5.6
Quoted 13 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };Signed-off-by Michal Simek <[email protected]>
[...]
drivers/uio/uio_pdrv_genirq.c static int uio_pdrv_genirq_probe(struct platform_device *pdev) · line 108
Quoted 2 lines
drivers/uio/uio_pdrv_genirq.c +2
-0+/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL );
kfree in remove?
Signature · 2 lines
Pengutronix e.K. | Wolfram Sang | Industrial Linux Solutions | http://www.pengutronix.de/ |
_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss
Quoted 13 lines · Wolfram Sang
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };
Quoted 8 lines
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>[...]
drivers/uio/uio_pdrv_genirq.c static int uio_pdrv_genirq_probe(struct platform_device *pdev) · line 108
Quoted 2 lines
drivers/uio/uio_pdrv_genirq.c +2
-0+/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL );kfree in remove?
Oh yes. Missed that one. It should probably look like the "bad0" case in probe().
Thanks,
Hans
Quoted 6 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.
Quoted 7 lines
For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };Signed-off-by Michal Simek <[email protected]>
Quoted 14 lines · Hans J. Koch
Quoted 13 lines · Wolfram Sang
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>[...]
drivers/uio/uio_pdrv_genirq.c static int uio_pdrv_genirq_probe(struct platform_device *pdev) · line 108
Quoted 2 lines
drivers/uio/uio_pdrv_genirq.c +2
-0+/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL );kfree in remove?
Oh yes. Missed that one. It should probably look like the "bad0" case in
probe().
Yes, freeing uioinfo in uio_pdrv_genirq_remove make sense for CONFIG_OF.
Please correct me if I am wrong dev.of_node is not NULL for OF. I think yes that's why I would prefer to use this construct instead of #ifdef CONFIG_OF.
if (pdev->dev.of_node) kfree(pdev->dev.platform_data);
What do you think?
Michal
Signature · 4 lines
Michal Simek, Ing. (M.Eng) w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/ Microblaze U-BOOT custodian
Quoted 24 lines · Michal Simek
Quoted 14 lines · Hans J. Koch
Quoted 13 lines · Wolfram Sang
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>[...]
drivers/uio/uio_pdrv_genirq.c static int uio_pdrv_genirq_probe(struct platform_device *pdev) · line 108
Quoted 2 lines
drivers/uio/uio_pdrv_genirq.c +2
-0+/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL );kfree in remove?
Oh yes. Missed that one. It should probably look like the "bad0" case in
probe().
Quoted 8 lines
Yes, freeing uioinfo in
uio_pdrv_genirq_removemake sense forCONFIG_OF.Please correct me if I am wrong dev.of_node is not NULL for OF. I think yes that's why I would prefer to use this construct instead of #ifdef
CONFIG_OF.if (pdev->dev.of_node) kfree(pdev->dev.platform_data);
Huh? You didn't allocate platform_data, so you shouldn't free it. It's uioinfo you allocated.
Thanks,
Hans
Quoted 31 lines · Hans J. Koch
Quoted 30 lines · Michal Simek
Quoted 14 lines · Hans J. Koch
Quoted 13 lines · Wolfram Sang
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const structof_device_id__devinitconstuio_of_genirq_match[] = { { .compatible = "vendor,device", },
{ /* empty for now */ },
};Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>[...]
Quoted 2 lines
+ /* alloc uioinfo for one device */
+ uioinfo =kzalloc(sizeof(*uioinfo), GFP_KERNEL);kfree in remove?
Oh yes. Missed that one. It should probably look like the "bad0" case in
probe().Yes, freeing uioinfo in
uio_pdrv_genirq_removemake sense forCONFIG_OF.Please correct me if I am wrong dev.of_node is not NULL for OF. I think yes that's why I would prefer to use this construct instead of #ifdef
CONFIG_OF.
Quoted 5 lines
Quoted 2 lines
if (
pdev->dev.of_node)
kfree(pdev->dev.platform_data);Huh? You didn't allocate
platform_data, so you shouldn't free it. It's uioinfo you allocated.
*never* set or modify the pdev->dev.platform_data pointer from a device driver. If the data needs to be modified, or a new structure allocated, then rework the driver to store it in it's private data structure. platform_data must be considered immutable by drivers. Otherwise you'll break unbindng and rebinding device drivers.
g.
Quoted 29 lines · Hans J. Koch
Quoted 28 lines · Michal Simek
Quoted 14 lines · Hans J. Koch
Quoted 13 lines · Wolfram Sang
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>[...]
drivers/uio/uio_pdrv_genirq.c static int uio_pdrv_genirq_probe(struct platform_device *pdev) · line 108
Quoted 2 lines
drivers/uio/uio_pdrv_genirq.c +2
-0+/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL );kfree in remove?
Oh yes. Missed that one. It should probably look like the "bad0" case in
probe().Yes, freeing uioinfo in
uio_pdrv_genirq_removemake sense forCONFIG_OF.Please correct me if I am wrong dev.of_node is not NULL for OF. I think yes that's why I would prefer to use this construct instead of #ifdef
CONFIG_OF.
Quoted 5 lines
Quoted 2 lines
if (pdev->dev.of_node) kfree(pdev->dev.platform_data);Huh? You didn't allocate
platform_data, so you shouldn't free it. It's uioinfo you allocated.
grrr. I am stupid!
/* kfree uioinfo for CONFIG_OF */ if (pdev->dev.of_node) kfree(priv->uioinfo);
Michal
Signature · 4 lines
Michal Simek, Ing. (M.Eng) w: www.monstr.eu p: +42-0-721842854 Maintainer of Linux kernel 2.6 Microblaze Linux - http://www.monstr.eu/fdt/ Microblaze U-BOOT custodian
Quoted 30 lines · Michal Simek
Quoted 29 lines · Hans J. Koch
Quoted 28 lines · Michal Simek
Quoted 14 lines · Hans J. Koch
Quoted 13 lines · Wolfram Sang
Quoted 12 lines · Michal Simek
Adding OF binding to genirq.
Version string is setup to the "devicetree".Compatible string is not setup for now but you can add your custom compatible string to
uio_of_genirq_matchstructure.For example with "vendor,device" compatible string:
static const struct of_device_id __devinitconst uio_of_genirq_match[] = { { .compatible = "vendor,device", }, { /* empty for now */ }, };Quoted 7 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Michal Simek <[email protected]>[...]
drivers/uio/uio_pdrv_genirq.c static int uio_pdrv_genirq_probe(struct platform_device *pdev) · line 108
Quoted 2 lines
drivers/uio/uio_pdrv_genirq.c +2
-0+/* alloc uioinfo for one device */ + uioinfo =kzalloc (sizeof (*uioinfo),GFP_KERNEL );kfree in remove?
Oh yes. Missed that one. It should probably look like the "bad0" case in
probe().Yes, freeing uioinfo in
uio_pdrv_genirq_removemake sense forCONFIG_OF.Please correct me if I am wrong dev.of_node is not NULL for OF. I think yes that's why I would prefer to use this construct instead of #ifdef
CONFIG_OF.
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
if (pdev->dev.of_node) kfree(pdev->dev.platform_data);Huh? You didn't allocate
platform_data, so you shouldn't free it. It's uioinfo you allocated.grrr. I am stupid!
We all are, sometimes. That's why we have a public review process so that collective stupidity can lead to good code.
Thanks,
Hans