X86 platform drivers
 help / color / mirror / Atom feed
From: Vadim Pasternak <vadimp@nvidia.com>
To: <hdegoede@redhat.com>
Cc: <platform-driver-x86@vger.kernel.org>,
	Vadim Pasternak <vadimp@nvidia.com>
Subject: [PATCH platform-next 06/13] platform: mellanox: Split initialization procedure
Date: Wed, 8 Feb 2023 08:33:23 +0200	[thread overview]
Message-ID: <20230208063331.15560-7-vadimp@nvidia.com> (raw)
In-Reply-To: <20230208063331.15560-1-vadimp@nvidia.com>

Split mlxplat_init() into two by adding mlxplat_pre_init().

Motivation is to prepare 'mlx-platform' driver to support systems
equipped PCIe based programming logic device.

Such systems are supposed to use different system resources, thus this
commit separates resources allocation related code.

Signed-off-by: Vadim Pasternak <vadimp@nvidia.com>
Reviewed-by: Michael Shych <michaelsh@nvidia.com>
---
 drivers/platform/x86/mlx-platform.c | 78 ++++++++++++++++++++++-------
 1 file changed, 60 insertions(+), 18 deletions(-)

diff --git a/drivers/platform/x86/mlx-platform.c b/drivers/platform/x86/mlx-platform.c
index 1a07a9994f05..2d33d1e5d427 100644
--- a/drivers/platform/x86/mlx-platform.c
+++ b/drivers/platform/x86/mlx-platform.c
@@ -328,6 +328,8 @@
  * @pdev_fan - FAN platform devices
  * @pdev_wd - array of watchdog platform devices
  * @regmap: device register map
+ * @hotplug_resources: system hotplug resources
+ * @hotplug_resources_size: size of system hotplug resources
  */
 struct mlxplat_priv {
 	struct platform_device *pdev_i2c;
@@ -338,6 +340,8 @@ struct mlxplat_priv {
 	struct platform_device *pdev_fan;
 	struct platform_device *pdev_wd[MLXPLAT_CPLD_WD_MAX_DEVS];
 	void *regmap;
+	struct resource *hotplug_resources;
+	unsigned int hotplug_resources_size;
 };
 
 static struct platform_device *mlxplat_dev;
@@ -6002,20 +6006,63 @@ static int mlxplat_mlxcpld_check_wd_capability(void *regmap)
 	return 0;
 }
 
+static int mlxplat_lpc_cpld_device_init(struct resource **hotplug_resources,
+					unsigned int *hotplug_resources_size)
+{
+	int err;
+
+	mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, PLATFORM_DEVID_NONE,
+						      mlxplat_lpc_resources,
+						      ARRAY_SIZE(mlxplat_lpc_resources));
+	if (IS_ERR(mlxplat_dev))
+		return PTR_ERR(mlxplat_dev);
+
+	mlxplat_mlxcpld_regmap_ctx.base = devm_ioport_map(&mlxplat_dev->dev,
+							  mlxplat_lpc_resources[1].start, 1);
+	if (!mlxplat_mlxcpld_regmap_ctx.base) {
+		err = -ENOMEM;
+		goto fail_devm_ioport_map;
+	}
+
+	*hotplug_resources = mlxplat_mlxcpld_resources;
+	*hotplug_resources_size = ARRAY_SIZE(mlxplat_mlxcpld_resources);
+
+	return 0;
+
+fail_devm_ioport_map:
+	platform_device_unregister(mlxplat_dev);
+	return err;
+}
+
+static void mlxplat_lpc_cpld_device_exit(void)
+{
+	platform_device_unregister(mlxplat_dev);
+}
+
+static int
+mlxplat_pre_init(struct resource **hotplug_resources, unsigned int *hotplug_resources_size)
+{
+	return mlxplat_lpc_cpld_device_init(hotplug_resources, hotplug_resources_size);
+}
+
+static void mlxplat_post_exit(void)
+{
+	mlxplat_lpc_cpld_device_exit();
+}
+
 static int __init mlxplat_init(void)
 {
+	unsigned int hotplug_resources_size;
+	struct resource *hotplug_resources;
 	struct mlxplat_priv *priv;
 	int i, j, nr, err;
 
 	if (!dmi_check_system(mlxplat_dmi_table))
 		return -ENODEV;
 
-	mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, PLATFORM_DEVID_NONE,
-					mlxplat_lpc_resources,
-					ARRAY_SIZE(mlxplat_lpc_resources));
-
-	if (IS_ERR(mlxplat_dev))
-		return PTR_ERR(mlxplat_dev);
+	err = mlxplat_pre_init(&hotplug_resources, &hotplug_resources_size);
+	if (err)
+		return err;
 
 	priv = devm_kzalloc(&mlxplat_dev->dev, sizeof(struct mlxplat_priv),
 			    GFP_KERNEL);
@@ -6025,12 +6072,8 @@ static int __init mlxplat_init(void)
 	}
 	platform_set_drvdata(mlxplat_dev, priv);
 
-	mlxplat_mlxcpld_regmap_ctx.base = devm_ioport_map(&mlxplat_dev->dev,
-			       mlxplat_lpc_resources[1].start, 1);
-	if (!mlxplat_mlxcpld_regmap_ctx.base) {
-		err = -ENOMEM;
-		goto fail_alloc;
-	}
+	priv->hotplug_resources = hotplug_resources;
+	priv->hotplug_resources_size = hotplug_resources_size;
 
 	if (!mlxplat_regmap_config)
 		mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config;
@@ -6051,8 +6094,8 @@ static int __init mlxplat_init(void)
 	if (mlxplat_i2c)
 		mlxplat_i2c->regmap = priv->regmap;
 	priv->pdev_i2c = platform_device_register_resndata(&mlxplat_dev->dev, "i2c_mlxcpld",
-							   nr, mlxplat_mlxcpld_resources,
-							   ARRAY_SIZE(mlxplat_mlxcpld_resources),
+							   nr, priv->hotplug_resources,
+							   priv->hotplug_resources_size,
 							   mlxplat_i2c, sizeof(*mlxplat_i2c));
 	if (IS_ERR(priv->pdev_i2c)) {
 		err = PTR_ERR(priv->pdev_i2c);
@@ -6076,8 +6119,8 @@ static int __init mlxplat_init(void)
 		priv->pdev_hotplug =
 		platform_device_register_resndata(&mlxplat_dev->dev,
 						  "mlxreg-hotplug", PLATFORM_DEVID_NONE,
-						  mlxplat_mlxcpld_resources,
-						  ARRAY_SIZE(mlxplat_mlxcpld_resources),
+						  priv->hotplug_resources,
+						  priv->hotplug_resources_size,
 						  mlxplat_hotplug, sizeof(*mlxplat_hotplug));
 		if (IS_ERR(priv->pdev_hotplug)) {
 			err = PTR_ERR(priv->pdev_hotplug);
@@ -6179,7 +6222,6 @@ static int __init mlxplat_init(void)
 		platform_device_unregister(priv->pdev_mux[i]);
 	platform_device_unregister(priv->pdev_i2c);
 fail_alloc:
-	platform_device_unregister(mlxplat_dev);
 
 	return err;
 }
@@ -6207,7 +6249,7 @@ static void __exit mlxplat_exit(void)
 		platform_device_unregister(priv->pdev_mux[i]);
 
 	platform_device_unregister(priv->pdev_i2c);
-	platform_device_unregister(mlxplat_dev);
+	mlxplat_post_exit();
 }
 module_exit(mlxplat_exit);
 
-- 
2.20.1


  parent reply	other threads:[~2023-02-08  6:35 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08  6:33 [PATCH platform-next 00/13] platform/x86: Add new systems and features for Nvidia systems Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 01/13] platform: mellanox: Introduce support for rack manager switch Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 02/13] platform: mellanox: Change "reset_pwr_converter_fail" attribute Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 03/13] platform: mellanox: Cosmetic changes - rename to more common name Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 04/13] platform: mellanox: Introduce support for next-generation 800GB/s switch Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 05/13] platform: mellanox: Introduce support of new Nvidia L1 switch Vadim Pasternak
2023-02-08  6:33 ` Vadim Pasternak [this message]
2023-02-08  6:33 ` [PATCH platform-next 07/13] platform: mellanox: Split logic in init and exit flow Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 08/13] platform: mellanox: Extend all systems with I2C notification callback Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 09/13] platform/mellanox: mlxreg-hotplug: Allow more flexible hotplug events configuration Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 10/13] platform_data/mlxreg: Add field with mapped resource address Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 11/13] platform: mellanox: mlx-platform: Add mux selection register to regmap Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 12/13] platform: mellanox: mlx-platform: Move bus shift assignment out of the loop Vadim Pasternak
2023-02-08  6:33 ` [PATCH platform-next 13/13] Documentation/ABI: Add new attribute for mlxreg-io sysfs interfaces Vadim Pasternak
2023-02-10 17:46 ` [PATCH platform-next 00/13] platform/x86: Add new systems and features for Nvidia systems Hans de Goede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230208063331.15560-7-vadimp@nvidia.com \
    --to=vadimp@nvidia.com \
    --cc=hdegoede@redhat.com \
    --cc=platform-driver-x86@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox