Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mfd: ocelot: Add helper to get regmap from a resource

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().

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.

Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Lee Jones <lee@kernel.org>
Link: https://lore.kernel.org/r/20220905162132.2943088-2-colin.foster@in-advantage.com

authored by

Colin Foster and committed by
Lee Jones
bb5721f0 568035b0

+67
+5
MAINTAINERS
··· 14741 14741 F: net/dsa/tag_ocelot_8021q.c 14742 14742 F: tools/testing/selftests/drivers/net/ocelot/* 14743 14743 14744 + OCELOT EXTERNAL SWITCH CONTROL 14745 + M: Colin Foster <colin.foster@in-advantage.com> 14746 + S: Supported 14747 + F: include/linux/mfd/ocelot.h 14748 + 14744 14749 OCXL (Open Coherent Accelerator Processor Interface OpenCAPI) DRIVER 14745 14750 M: Frederic Barrat <fbarrat@linux.ibm.com> 14746 14751 M: Andrew Donnellan <ajd@linux.ibm.com>
+62
include/linux/mfd/ocelot.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 OR MIT */ 2 + /* Copyright 2022 Innovative Advantage Inc. */ 3 + 4 + #ifndef _LINUX_MFD_OCELOT_H 5 + #define _LINUX_MFD_OCELOT_H 6 + 7 + #include <linux/err.h> 8 + #include <linux/errno.h> 9 + #include <linux/ioport.h> 10 + #include <linux/platform_device.h> 11 + #include <linux/regmap.h> 12 + #include <linux/types.h> 13 + 14 + struct resource; 15 + 16 + static inline struct regmap * 17 + ocelot_regmap_from_resource_optional(struct platform_device *pdev, 18 + unsigned int index, 19 + const struct regmap_config *config) 20 + { 21 + struct device *dev = &pdev->dev; 22 + struct resource *res; 23 + void __iomem *regs; 24 + 25 + /* 26 + * Don't use _get_and_ioremap_resource() here, since that will invoke 27 + * prints of "invalid resource" which will simply add confusion. 28 + */ 29 + res = platform_get_resource(pdev, IORESOURCE_MEM, index); 30 + if (res) { 31 + regs = devm_ioremap_resource(dev, res); 32 + if (IS_ERR(regs)) 33 + return ERR_CAST(regs); 34 + return devm_regmap_init_mmio(dev, regs, config); 35 + } 36 + 37 + /* 38 + * Fall back to using REG and getting the resource from the parent 39 + * device, which is possible in an MFD configuration 40 + */ 41 + if (dev->parent) { 42 + res = platform_get_resource(pdev, IORESOURCE_REG, index); 43 + if (!res) 44 + return NULL; 45 + 46 + return dev_get_regmap(dev->parent, res->name); 47 + } 48 + 49 + return NULL; 50 + } 51 + 52 + static inline struct regmap * 53 + ocelot_regmap_from_resource(struct platform_device *pdev, unsigned int index, 54 + const struct regmap_config *config) 55 + { 56 + struct regmap *map; 57 + 58 + map = ocelot_regmap_from_resource_optional(pdev, index, config); 59 + return map ?: ERR_PTR(-ENOENT); 60 + } 61 + 62 + #endif