Skip to content

Commit

Permalink
platform: mellanox: Split initialization procedure
Browse files Browse the repository at this point in the history
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>
Link: https://lore.kernel.org/r/20230208063331.15560-7-vadimp@nvidia.com
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
  • Loading branch information
Vadim Pasternak authored and Hans de Goede committed Feb 10, 2023
1 parent dd635e3 commit 0170f61
Showing 1 changed file with 60 additions and 18 deletions.
78 changes: 60 additions & 18 deletions drivers/platform/x86/mlx-platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 0170f61

Please sign in to comment.