Messages in this thread | | | From | Andy Shevchenko <> | Date | Mon, 25 Jul 2022 11:39:48 +0200 | Subject | Re: [PATCH v14 mfd 1/9] mfd: ocelot: add helper to get regmap from a resource |
| |
On Fri, Jul 22, 2022 at 6:06 AM Colin Foster <colin.foster@in-advantage.com> wrote: > > Several ocelot-related modules are designed for MMIO / regmaps. As such, > they often use a combination of devm_platform_get_and_ioremap_resource and > devm_regmap_init_mmio.
When we refer to functions we put it like func().
> Operating in an MFD might be different, in that it could be memory mapped, > or it could be SPI, I2C... In these cases a fallback to use IORESOURCE_REG > instead of IORESOURCE_MEM becomes necessary. > > When this happens, there's redundant logic that needs to be implemented in > every driver. In order to avoid this redundancy, utilize a single function > that, if the MFD scenario is enabled, will perform this fallback logic.
...
> +#include <linux/err.h>
You also missed errno.h
> +#include <linux/platform_device.h> > +#include <linux/regmap.h> > +#include <linux/types.h>
...
> +static inline struct regmap * > +ocelot_regmap_from_resource_optional(struct platform_device *pdev, > + unsigned int index, > + const struct regmap_config *config) > +{ > + struct device *dev = &pdev->dev; > + struct resource *res; > + void __iomem *regs; > + > + /* > + * Don't use get_and_ioremap_resource here, since that will invoke
_get_and_ioremap_resource()
> + * prints of "invalid resource" which simply add confusion > + */
will simply add
Missed period.
> + res = platform_get_resource(pdev, IORESOURCE_MEM, index);
Where are the IORESOURCE_* defined? Haven't you missed a header?
> + if (res) { > + regs = devm_ioremap_resource(dev, res); > + if (IS_ERR(regs)) > + return ERR_CAST(regs); > + return devm_regmap_init_mmio(dev, regs, config); > + } > + > + /* > + * Fall back to using REG and getting the resource from the parent > + * device, which is possible in an MFD configuration > + */ > + if (dev->parent) { > + res = platform_get_resource(pdev, IORESOURCE_REG, index); > + if (!res) > + return NULL; > + > + return dev_get_regmap(dev->parent, res->name); > + } > + > + return NULL; > +}
-- With Best Regards, Andy Shevchenko
| |