forked from mirrors/linux
		
	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 <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>
This commit is contained in:
		
							parent
							
								
									dd635e33b5
								
							
						
					
					
						commit
						0170f616f4
					
				
					 1 changed files with 60 additions and 18 deletions
				
			
		| 
						 | 
					@ -328,6 +328,8 @@
 | 
				
			||||||
 * @pdev_fan - FAN platform devices
 | 
					 * @pdev_fan - FAN platform devices
 | 
				
			||||||
 * @pdev_wd - array of watchdog platform devices
 | 
					 * @pdev_wd - array of watchdog platform devices
 | 
				
			||||||
 * @regmap: device register map
 | 
					 * @regmap: device register map
 | 
				
			||||||
 | 
					 * @hotplug_resources: system hotplug resources
 | 
				
			||||||
 | 
					 * @hotplug_resources_size: size of system hotplug resources
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
struct mlxplat_priv {
 | 
					struct mlxplat_priv {
 | 
				
			||||||
	struct platform_device *pdev_i2c;
 | 
						struct platform_device *pdev_i2c;
 | 
				
			||||||
| 
						 | 
					@ -338,6 +340,8 @@ struct mlxplat_priv {
 | 
				
			||||||
	struct platform_device *pdev_fan;
 | 
						struct platform_device *pdev_fan;
 | 
				
			||||||
	struct platform_device *pdev_wd[MLXPLAT_CPLD_WD_MAX_DEVS];
 | 
						struct platform_device *pdev_wd[MLXPLAT_CPLD_WD_MAX_DEVS];
 | 
				
			||||||
	void *regmap;
 | 
						void *regmap;
 | 
				
			||||||
 | 
						struct resource *hotplug_resources;
 | 
				
			||||||
 | 
						unsigned int hotplug_resources_size;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct platform_device *mlxplat_dev;
 | 
					static struct platform_device *mlxplat_dev;
 | 
				
			||||||
| 
						 | 
					@ -6002,20 +6006,63 @@ static int mlxplat_mlxcpld_check_wd_capability(void *regmap)
 | 
				
			||||||
	return 0;
 | 
						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)
 | 
					static int __init mlxplat_init(void)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
						unsigned int hotplug_resources_size;
 | 
				
			||||||
 | 
						struct resource *hotplug_resources;
 | 
				
			||||||
	struct mlxplat_priv *priv;
 | 
						struct mlxplat_priv *priv;
 | 
				
			||||||
	int i, j, nr, err;
 | 
						int i, j, nr, err;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!dmi_check_system(mlxplat_dmi_table))
 | 
						if (!dmi_check_system(mlxplat_dmi_table))
 | 
				
			||||||
		return -ENODEV;
 | 
							return -ENODEV;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, PLATFORM_DEVID_NONE,
 | 
						err = mlxplat_pre_init(&hotplug_resources, &hotplug_resources_size);
 | 
				
			||||||
					mlxplat_lpc_resources,
 | 
						if (err)
 | 
				
			||||||
					ARRAY_SIZE(mlxplat_lpc_resources));
 | 
							return err;
 | 
				
			||||||
 | 
					 | 
				
			||||||
	if (IS_ERR(mlxplat_dev))
 | 
					 | 
				
			||||||
		return PTR_ERR(mlxplat_dev);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	priv = devm_kzalloc(&mlxplat_dev->dev, sizeof(struct mlxplat_priv),
 | 
						priv = devm_kzalloc(&mlxplat_dev->dev, sizeof(struct mlxplat_priv),
 | 
				
			||||||
			    GFP_KERNEL);
 | 
								    GFP_KERNEL);
 | 
				
			||||||
| 
						 | 
					@ -6025,12 +6072,8 @@ static int __init mlxplat_init(void)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	platform_set_drvdata(mlxplat_dev, priv);
 | 
						platform_set_drvdata(mlxplat_dev, priv);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mlxplat_mlxcpld_regmap_ctx.base = devm_ioport_map(&mlxplat_dev->dev,
 | 
						priv->hotplug_resources = hotplug_resources;
 | 
				
			||||||
			       mlxplat_lpc_resources[1].start, 1);
 | 
						priv->hotplug_resources_size = hotplug_resources_size;
 | 
				
			||||||
	if (!mlxplat_mlxcpld_regmap_ctx.base) {
 | 
					 | 
				
			||||||
		err = -ENOMEM;
 | 
					 | 
				
			||||||
		goto fail_alloc;
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (!mlxplat_regmap_config)
 | 
						if (!mlxplat_regmap_config)
 | 
				
			||||||
		mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config;
 | 
							mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config;
 | 
				
			||||||
| 
						 | 
					@ -6051,8 +6094,8 @@ static int __init mlxplat_init(void)
 | 
				
			||||||
	if (mlxplat_i2c)
 | 
						if (mlxplat_i2c)
 | 
				
			||||||
		mlxplat_i2c->regmap = priv->regmap;
 | 
							mlxplat_i2c->regmap = priv->regmap;
 | 
				
			||||||
	priv->pdev_i2c = platform_device_register_resndata(&mlxplat_dev->dev, "i2c_mlxcpld",
 | 
						priv->pdev_i2c = platform_device_register_resndata(&mlxplat_dev->dev, "i2c_mlxcpld",
 | 
				
			||||||
							   nr, mlxplat_mlxcpld_resources,
 | 
												   nr, priv->hotplug_resources,
 | 
				
			||||||
							   ARRAY_SIZE(mlxplat_mlxcpld_resources),
 | 
												   priv->hotplug_resources_size,
 | 
				
			||||||
							   mlxplat_i2c, sizeof(*mlxplat_i2c));
 | 
												   mlxplat_i2c, sizeof(*mlxplat_i2c));
 | 
				
			||||||
	if (IS_ERR(priv->pdev_i2c)) {
 | 
						if (IS_ERR(priv->pdev_i2c)) {
 | 
				
			||||||
		err = PTR_ERR(priv->pdev_i2c);
 | 
							err = PTR_ERR(priv->pdev_i2c);
 | 
				
			||||||
| 
						 | 
					@ -6076,8 +6119,8 @@ static int __init mlxplat_init(void)
 | 
				
			||||||
		priv->pdev_hotplug =
 | 
							priv->pdev_hotplug =
 | 
				
			||||||
		platform_device_register_resndata(&mlxplat_dev->dev,
 | 
							platform_device_register_resndata(&mlxplat_dev->dev,
 | 
				
			||||||
						  "mlxreg-hotplug", PLATFORM_DEVID_NONE,
 | 
											  "mlxreg-hotplug", PLATFORM_DEVID_NONE,
 | 
				
			||||||
						  mlxplat_mlxcpld_resources,
 | 
											  priv->hotplug_resources,
 | 
				
			||||||
						  ARRAY_SIZE(mlxplat_mlxcpld_resources),
 | 
											  priv->hotplug_resources_size,
 | 
				
			||||||
						  mlxplat_hotplug, sizeof(*mlxplat_hotplug));
 | 
											  mlxplat_hotplug, sizeof(*mlxplat_hotplug));
 | 
				
			||||||
		if (IS_ERR(priv->pdev_hotplug)) {
 | 
							if (IS_ERR(priv->pdev_hotplug)) {
 | 
				
			||||||
			err = PTR_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_mux[i]);
 | 
				
			||||||
	platform_device_unregister(priv->pdev_i2c);
 | 
						platform_device_unregister(priv->pdev_i2c);
 | 
				
			||||||
fail_alloc:
 | 
					fail_alloc:
 | 
				
			||||||
	platform_device_unregister(mlxplat_dev);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return err;
 | 
						return err;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -6207,7 +6249,7 @@ static void __exit mlxplat_exit(void)
 | 
				
			||||||
		platform_device_unregister(priv->pdev_mux[i]);
 | 
							platform_device_unregister(priv->pdev_mux[i]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	platform_device_unregister(priv->pdev_i2c);
 | 
						platform_device_unregister(priv->pdev_i2c);
 | 
				
			||||||
	platform_device_unregister(mlxplat_dev);
 | 
						mlxplat_post_exit();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
module_exit(mlxplat_exit);
 | 
					module_exit(mlxplat_exit);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue