* Re: [PATCH] of: add devres version of of_iomap [not found] <1346340744-22218-1-git-send-email-m-karicheri2@ti.com> @ 2012-08-30 18:27 ` Rob Herring 2012-08-30 22:09 ` Karicheri, Muralidharan 0 siblings, 1 reply; 3+ messages in thread From: Rob Herring @ 2012-08-30 18:27 UTC (permalink / raw) To: Murali Karicheri; +Cc: grant.likely, devicetree-discuss, linux-kernel On 08/30/2012 10:32 AM, Murali Karicheri wrote: > This adds devres version of the of_iomap() to allow resource to be cleaned > through devres. If you have a struct device, then don't you already have a resource and can just use devm_ioremap in a driver? New drivers should not be using of_iomap. Rob > > Signed-off-by: Murali Karicheri <m-karicheri2@ti.com> > --- > drivers/of/address.c | 26 ++++++++++++++++++++++++-- > include/linux/of_address.h | 2 ++ > 2 files changed, 26 insertions(+), 2 deletions(-) > > diff --git a/drivers/of/address.c b/drivers/of/address.c > index 7e262a6..d3da426 100644 > --- a/drivers/of/address.c > +++ b/drivers/of/address.c > @@ -602,10 +602,9 @@ struct device_node *of_find_matching_node_by_address(struct device_node *from, > return NULL; > } > > - > /** > * of_iomap - Maps the memory mapped IO for a given device_node > - * @device: the device whose io range will be mapped > + * @device_node: Ptr to the device node that has the reg property > * @index: index of the io range > * > * Returns a pointer to the mapped memory > @@ -620,3 +619,26 @@ void __iomem *of_iomap(struct device_node *np, int index) > return ioremap(res.start, resource_size(&res)); > } > EXPORT_SYMBOL(of_iomap); > + > +/** > + * of_devm_iomap - devres version of of_iomap > + * @device: the device whose io range will be mapped > + * @index: index of the io range > + * > + * Returns a pointer to the mapped memory > + */ > +void __iomem *of_devm_iomap(struct device *dev, int index) > +{ > + struct device_node *np; > + struct resource res; > + > + if (!dev) > + return NULL; > + > + np = dev->of_node; > + if (of_address_to_resource(np, index, &res)) > + return NULL; > + > + return devm_ioremap(dev, res.start, resource_size(&res)); > +} > +EXPORT_SYMBOL(of_devm_iomap); > diff --git a/include/linux/of_address.h b/include/linux/of_address.h > index 01b925a..67efa5f 100644 > --- a/include/linux/of_address.h > +++ b/include/linux/of_address.h > @@ -3,6 +3,7 @@ > #include <linux/ioport.h> > #include <linux/errno.h> > #include <linux/of.h> > +#include <linux/device.h> > > #ifdef CONFIG_OF_ADDRESS > extern u64 of_translate_address(struct device_node *np, const __be32 *addr); > @@ -13,6 +14,7 @@ extern struct device_node *of_find_matching_node_by_address( > const struct of_device_id *matches, > u64 base_address); > extern void __iomem *of_iomap(struct device_node *device, int index); > +extern void __iomem *of_devm_iomap(struct device *dev, int index); > > /* Extract an address from a device, returns the region size and > * the address space flags too. The PCI version uses a BAR number > ^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH] of: add devres version of of_iomap 2012-08-30 18:27 ` [PATCH] of: add devres version of of_iomap Rob Herring @ 2012-08-30 22:09 ` Karicheri, Muralidharan 2012-08-31 2:53 ` Rob Herring 0 siblings, 1 reply; 3+ messages in thread From: Karicheri, Muralidharan @ 2012-08-30 22:09 UTC (permalink / raw) To: Rob Herring; +Cc: grant.likely, devicetree-discuss, linux-kernel >> -----Original Message----- >> From: Rob Herring [mailto:robherring2@gmail.com] >> Sent: Thursday, August 30, 2012 2:27 PM >> To: Karicheri, Muralidharan >> Cc: grant.likely@secretlab.ca; devicetree-discuss@lists.ozlabs.org; linux- >> kernel@vger.kernel.org >> Subject: Re: [PATCH] of: add devres version of of_iomap >> >> On 08/30/2012 10:32 AM, Murali Karicheri wrote: >> > This adds devres version of the of_iomap() to allow resource to be cleaned >> > through devres. >> >> If you have a struct device, then don't you already have a resource and >> can just use devm_ioremap in a driver? New drivers should not be using >> of_iomap. >> That is the point. If you do a grep under driver, there are many drivers using the pattern like this. This helper function is mean to replace this code. >From dma/sirf-dma.c ret = of_address_to_resource(dn, 0, &res); if (ret) { dev_err(dev, "Error parsing memory region!\n"); goto error; } regs_start = res.start; regs_size = resource_size(&res); base = devm_ioremap(dev, regs_start, regs_size); if (!base) { dev_err(dev, "Error mapping memory region!\n"); goto error; } Other instances. edac/mpc85xx_edac.c media/video/fsl-viu.c mtd/nand/mpc5121_nfc.c Some of these code uses devm_request_mem_region() as well. Isn't a good idea to add this helper that can be called by new drivers to replace this sequence? I could update the patch to do this call as well? >> Rob >> >> > >> > Signed-off-by: Murali Karicheri <m-karicheri2@ti.com> >> > --- >> > drivers/of/address.c | 26 ++++++++++++++++++++++++-- >> > include/linux/of_address.h | 2 ++ >> > 2 files changed, 26 insertions(+), 2 deletions(-) >> > >> > diff --git a/drivers/of/address.c b/drivers/of/address.c >> > index 7e262a6..d3da426 100644 >> > --- a/drivers/of/address.c >> > +++ b/drivers/of/address.c >> > @@ -602,10 +602,9 @@ struct device_node >> *of_find_matching_node_by_address(struct device_node *from, >> > return NULL; >> > } >> > >> > - >> > /** >> > * of_iomap - Maps the memory mapped IO for a given device_node >> > - * @device: the device whose io range will be mapped >> > + * @device_node: Ptr to the device node that has the reg property >> > * @index: index of the io range >> > * >> > * Returns a pointer to the mapped memory >> > @@ -620,3 +619,26 @@ void __iomem *of_iomap(struct device_node *np, int index) >> > return ioremap(res.start, resource_size(&res)); >> > } >> > EXPORT_SYMBOL(of_iomap); >> > + >> > +/** >> > + * of_devm_iomap - devres version of of_iomap >> > + * @device: the device whose io range will be mapped >> > + * @index: index of the io range >> > + * >> > + * Returns a pointer to the mapped memory >> > + */ >> > +void __iomem *of_devm_iomap(struct device *dev, int index) >> > +{ >> > + struct device_node *np; >> > + struct resource res; >> > + >> > + if (!dev) >> > + return NULL; >> > + >> > + np = dev->of_node; >> > + if (of_address_to_resource(np, index, &res)) >> > + return NULL; >> > + >> > + return devm_ioremap(dev, res.start, resource_size(&res)); >> > +} >> > +EXPORT_SYMBOL(of_devm_iomap); >> > diff --git a/include/linux/of_address.h b/include/linux/of_address.h >> > index 01b925a..67efa5f 100644 >> > --- a/include/linux/of_address.h >> > +++ b/include/linux/of_address.h >> > @@ -3,6 +3,7 @@ >> > #include <linux/ioport.h> >> > #include <linux/errno.h> >> > #include <linux/of.h> >> > +#include <linux/device.h> >> > >> > #ifdef CONFIG_OF_ADDRESS >> > extern u64 of_translate_address(struct device_node *np, const __be32 *addr); >> > @@ -13,6 +14,7 @@ extern struct device_node *of_find_matching_node_by_address( >> > const struct of_device_id *matches, >> > u64 base_address); >> > extern void __iomem *of_iomap(struct device_node *device, int index); >> > +extern void __iomem *of_devm_iomap(struct device *dev, int index); >> > >> > /* Extract an address from a device, returns the region size and >> > * the address space flags too. The PCI version uses a BAR number >> > ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] of: add devres version of of_iomap 2012-08-30 22:09 ` Karicheri, Muralidharan @ 2012-08-31 2:53 ` Rob Herring 0 siblings, 0 replies; 3+ messages in thread From: Rob Herring @ 2012-08-31 2:53 UTC (permalink / raw) To: Karicheri, Muralidharan; +Cc: grant.likely, devicetree-discuss, linux-kernel On 08/30/2012 05:09 PM, Karicheri, Muralidharan wrote: >>> -----Original Message----- >>> From: Rob Herring [mailto:robherring2@gmail.com] >>> Sent: Thursday, August 30, 2012 2:27 PM >>> To: Karicheri, Muralidharan >>> Cc: grant.likely@secretlab.ca; devicetree-discuss@lists.ozlabs.org; linux- >>> kernel@vger.kernel.org >>> Subject: Re: [PATCH] of: add devres version of of_iomap >>> >>> On 08/30/2012 10:32 AM, Murali Karicheri wrote: >>>> This adds devres version of the of_iomap() to allow resource to be cleaned >>>> through devres. >>> >>> If you have a struct device, then don't you already have a resource and >>> can just use devm_ioremap in a driver? New drivers should not be using >>> of_iomap. >>> > > That is the point. If you do a grep under driver, there are many drivers using the pattern > like this. This helper function is mean to replace this code. > > From dma/sirf-dma.c > > ret = of_address_to_resource(dn, 0, &res); > if (ret) { > dev_err(dev, "Error parsing memory region!\n"); > goto error; > } > > regs_start = res.start; > regs_size = resource_size(&res); > > base = devm_ioremap(dev, regs_start, regs_size); > if (!base) { > dev_err(dev, "Error mapping memory region!\n"); > goto error; > } > That's wrong and should be fixed. The resource is already setup and available to the probe function. > Other instances. > > edac/mpc85xx_edac.c > media/video/fsl-viu.c > mtd/nand/mpc5121_nfc.c All PPC drivers that used the old of_platform_driver and also need to be updated. > > Some of these code uses devm_request_mem_region() as well. Isn't a good idea to add this helper > that can be called by new drivers to replace this sequence? I could update the patch to do this call > as well? devm_request_and_ioremap Rob ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-08-31 2:53 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <1346340744-22218-1-git-send-email-m-karicheri2@ti.com> 2012-08-30 18:27 ` [PATCH] of: add devres version of of_iomap Rob Herring 2012-08-30 22:09 ` Karicheri, Muralidharan 2012-08-31 2:53 ` Rob Herring
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).