Skip to content

Commit 0170f61

Browse files
vadimp-nvidiajwrdegoede
authored andcommitted
platform: mellanox: Split initialization procedure
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 <[email protected]> Reviewed-by: Michael Shych <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Hans de Goede <[email protected]>
1 parent dd635e3 commit 0170f61

File tree

1 file changed

+60
-18
lines changed

1 file changed

+60
-18
lines changed

drivers/platform/x86/mlx-platform.c

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,8 @@
328328
* @pdev_fan - FAN platform devices
329329
* @pdev_wd - array of watchdog platform devices
330330
* @regmap: device register map
331+
* @hotplug_resources: system hotplug resources
332+
* @hotplug_resources_size: size of system hotplug resources
331333
*/
332334
struct mlxplat_priv {
333335
struct platform_device *pdev_i2c;
@@ -338,6 +340,8 @@ struct mlxplat_priv {
338340
struct platform_device *pdev_fan;
339341
struct platform_device *pdev_wd[MLXPLAT_CPLD_WD_MAX_DEVS];
340342
void *regmap;
343+
struct resource *hotplug_resources;
344+
unsigned int hotplug_resources_size;
341345
};
342346

343347
static struct platform_device *mlxplat_dev;
@@ -6002,20 +6006,63 @@ static int mlxplat_mlxcpld_check_wd_capability(void *regmap)
60026006
return 0;
60036007
}
60046008

6009+
static int mlxplat_lpc_cpld_device_init(struct resource **hotplug_resources,
6010+
unsigned int *hotplug_resources_size)
6011+
{
6012+
int err;
6013+
6014+
mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, PLATFORM_DEVID_NONE,
6015+
mlxplat_lpc_resources,
6016+
ARRAY_SIZE(mlxplat_lpc_resources));
6017+
if (IS_ERR(mlxplat_dev))
6018+
return PTR_ERR(mlxplat_dev);
6019+
6020+
mlxplat_mlxcpld_regmap_ctx.base = devm_ioport_map(&mlxplat_dev->dev,
6021+
mlxplat_lpc_resources[1].start, 1);
6022+
if (!mlxplat_mlxcpld_regmap_ctx.base) {
6023+
err = -ENOMEM;
6024+
goto fail_devm_ioport_map;
6025+
}
6026+
6027+
*hotplug_resources = mlxplat_mlxcpld_resources;
6028+
*hotplug_resources_size = ARRAY_SIZE(mlxplat_mlxcpld_resources);
6029+
6030+
return 0;
6031+
6032+
fail_devm_ioport_map:
6033+
platform_device_unregister(mlxplat_dev);
6034+
return err;
6035+
}
6036+
6037+
static void mlxplat_lpc_cpld_device_exit(void)
6038+
{
6039+
platform_device_unregister(mlxplat_dev);
6040+
}
6041+
6042+
static int
6043+
mlxplat_pre_init(struct resource **hotplug_resources, unsigned int *hotplug_resources_size)
6044+
{
6045+
return mlxplat_lpc_cpld_device_init(hotplug_resources, hotplug_resources_size);
6046+
}
6047+
6048+
static void mlxplat_post_exit(void)
6049+
{
6050+
mlxplat_lpc_cpld_device_exit();
6051+
}
6052+
60056053
static int __init mlxplat_init(void)
60066054
{
6055+
unsigned int hotplug_resources_size;
6056+
struct resource *hotplug_resources;
60076057
struct mlxplat_priv *priv;
60086058
int i, j, nr, err;
60096059

60106060
if (!dmi_check_system(mlxplat_dmi_table))
60116061
return -ENODEV;
60126062

6013-
mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, PLATFORM_DEVID_NONE,
6014-
mlxplat_lpc_resources,
6015-
ARRAY_SIZE(mlxplat_lpc_resources));
6016-
6017-
if (IS_ERR(mlxplat_dev))
6018-
return PTR_ERR(mlxplat_dev);
6063+
err = mlxplat_pre_init(&hotplug_resources, &hotplug_resources_size);
6064+
if (err)
6065+
return err;
60196066

60206067
priv = devm_kzalloc(&mlxplat_dev->dev, sizeof(struct mlxplat_priv),
60216068
GFP_KERNEL);
@@ -6025,12 +6072,8 @@ static int __init mlxplat_init(void)
60256072
}
60266073
platform_set_drvdata(mlxplat_dev, priv);
60276074

6028-
mlxplat_mlxcpld_regmap_ctx.base = devm_ioport_map(&mlxplat_dev->dev,
6029-
mlxplat_lpc_resources[1].start, 1);
6030-
if (!mlxplat_mlxcpld_regmap_ctx.base) {
6031-
err = -ENOMEM;
6032-
goto fail_alloc;
6033-
}
6075+
priv->hotplug_resources = hotplug_resources;
6076+
priv->hotplug_resources_size = hotplug_resources_size;
60346077

60356078
if (!mlxplat_regmap_config)
60366079
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config;
@@ -6051,8 +6094,8 @@ static int __init mlxplat_init(void)
60516094
if (mlxplat_i2c)
60526095
mlxplat_i2c->regmap = priv->regmap;
60536096
priv->pdev_i2c = platform_device_register_resndata(&mlxplat_dev->dev, "i2c_mlxcpld",
6054-
nr, mlxplat_mlxcpld_resources,
6055-
ARRAY_SIZE(mlxplat_mlxcpld_resources),
6097+
nr, priv->hotplug_resources,
6098+
priv->hotplug_resources_size,
60566099
mlxplat_i2c, sizeof(*mlxplat_i2c));
60576100
if (IS_ERR(priv->pdev_i2c)) {
60586101
err = PTR_ERR(priv->pdev_i2c);
@@ -6076,8 +6119,8 @@ static int __init mlxplat_init(void)
60766119
priv->pdev_hotplug =
60776120
platform_device_register_resndata(&mlxplat_dev->dev,
60786121
"mlxreg-hotplug", PLATFORM_DEVID_NONE,
6079-
mlxplat_mlxcpld_resources,
6080-
ARRAY_SIZE(mlxplat_mlxcpld_resources),
6122+
priv->hotplug_resources,
6123+
priv->hotplug_resources_size,
60816124
mlxplat_hotplug, sizeof(*mlxplat_hotplug));
60826125
if (IS_ERR(priv->pdev_hotplug)) {
60836126
err = PTR_ERR(priv->pdev_hotplug);
@@ -6179,7 +6222,6 @@ static int __init mlxplat_init(void)
61796222
platform_device_unregister(priv->pdev_mux[i]);
61806223
platform_device_unregister(priv->pdev_i2c);
61816224
fail_alloc:
6182-
platform_device_unregister(mlxplat_dev);
61836225

61846226
return err;
61856227
}
@@ -6207,7 +6249,7 @@ static void __exit mlxplat_exit(void)
62076249
platform_device_unregister(priv->pdev_mux[i]);
62086250

62096251
platform_device_unregister(priv->pdev_i2c);
6210-
platform_device_unregister(mlxplat_dev);
6252+
mlxplat_post_exit();
62116253
}
62126254
module_exit(mlxplat_exit);
62136255

0 commit comments

Comments
 (0)