Skip to content

Commit 2229544

Browse files
vadimp-nvidiajwrdegoede
authored andcommitted
platform: mellanox: mlx-platform: Prepare driver to allow probing through ACPI infrastructure
Currently driver is activated through DMI hooks. Prepare driver to allow activation also through ACPI trigger. Modify mlxplat_init()/mlxplat_exit() routines. Add mlxplat_probe()/mlxplat_remove() routines and "mlxplat_driver" structure. Signed-off-by: Vadim Pasternak <vadimp@nvidia.com> Reviewed-by: Michael Shych <michaelsh@nvidia.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Link: https://lore.kernel.org/r/20230822113451.13785-11-vadimp@nvidia.com Signed-off-by: Hans de Goede <hdegoede@redhat.com>
1 parent b411dc5 commit 2229544

1 file changed

Lines changed: 61 additions & 30 deletions

File tree

drivers/platform/x86/mlx-platform.c

Lines changed: 61 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5574,6 +5574,17 @@ static void mlxplat_poweroff(void)
55745574
kernel_halt();
55755575
}
55765576

5577+
static int __init mlxplat_register_platform_device(void)
5578+
{
5579+
mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, -1,
5580+
mlxplat_lpc_resources,
5581+
ARRAY_SIZE(mlxplat_lpc_resources));
5582+
if (IS_ERR(mlxplat_dev))
5583+
return PTR_ERR(mlxplat_dev);
5584+
else
5585+
return 1;
5586+
}
5587+
55775588
static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi)
55785589
{
55795590
int i;
@@ -5594,7 +5605,7 @@ static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi)
55945605
mlxplat_wd_data[0] = &mlxplat_mlxcpld_wd_set_type1[0];
55955606
mlxplat_i2c = &mlxplat_mlxcpld_i2c_default_data;
55965607

5597-
return 1;
5608+
return mlxplat_register_platform_device();
55985609
}
55995610

56005611
static int __init mlxplat_dmi_default_wc_matched(const struct dmi_system_id *dmi)
@@ -5617,7 +5628,7 @@ static int __init mlxplat_dmi_default_wc_matched(const struct dmi_system_id *dmi
56175628
mlxplat_wd_data[0] = &mlxplat_mlxcpld_wd_set_type1[0];
56185629
mlxplat_i2c = &mlxplat_mlxcpld_i2c_default_data;
56195630

5620-
return 1;
5631+
return mlxplat_register_platform_device();
56215632
}
56225633

56235634
static int __init mlxplat_dmi_default_eth_wc_blade_matched(const struct dmi_system_id *dmi)
@@ -5642,7 +5653,7 @@ static int __init mlxplat_dmi_default_eth_wc_blade_matched(const struct dmi_syst
56425653
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
56435654
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_ng;
56445655

5645-
return 1;
5656+
return mlxplat_register_platform_device();
56465657
}
56475658

56485659
static int __init mlxplat_dmi_msn21xx_matched(const struct dmi_system_id *dmi)
@@ -5665,7 +5676,7 @@ static int __init mlxplat_dmi_msn21xx_matched(const struct dmi_system_id *dmi)
56655676
mlxplat_wd_data[0] = &mlxplat_mlxcpld_wd_set_type1[0];
56665677
mlxplat_i2c = &mlxplat_mlxcpld_i2c_default_data;
56675678

5668-
return 1;
5679+
return mlxplat_register_platform_device();
56695680
}
56705681

56715682
static int __init mlxplat_dmi_msn274x_matched(const struct dmi_system_id *dmi)
@@ -5688,7 +5699,7 @@ static int __init mlxplat_dmi_msn274x_matched(const struct dmi_system_id *dmi)
56885699
mlxplat_wd_data[0] = &mlxplat_mlxcpld_wd_set_type1[0];
56895700
mlxplat_i2c = &mlxplat_mlxcpld_i2c_default_data;
56905701

5691-
return 1;
5702+
return mlxplat_register_platform_device();
56925703
}
56935704

56945705
static int __init mlxplat_dmi_msn201x_matched(const struct dmi_system_id *dmi)
@@ -5711,7 +5722,7 @@ static int __init mlxplat_dmi_msn201x_matched(const struct dmi_system_id *dmi)
57115722
mlxplat_wd_data[0] = &mlxplat_mlxcpld_wd_set_type1[0];
57125723
mlxplat_i2c = &mlxplat_mlxcpld_i2c_default_data;
57135724

5714-
return 1;
5725+
return mlxplat_register_platform_device();
57155726
}
57165727

57175728
static int __init mlxplat_dmi_qmb7xx_matched(const struct dmi_system_id *dmi)
@@ -5737,7 +5748,7 @@ static int __init mlxplat_dmi_qmb7xx_matched(const struct dmi_system_id *dmi)
57375748
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
57385749
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_ng;
57395750

5740-
return 1;
5751+
return mlxplat_register_platform_device();
57415752
}
57425753

57435754
static int __init mlxplat_dmi_comex_matched(const struct dmi_system_id *dmi)
@@ -5762,7 +5773,7 @@ static int __init mlxplat_dmi_comex_matched(const struct dmi_system_id *dmi)
57625773
mlxplat_i2c = &mlxplat_mlxcpld_i2c_default_data;
57635774
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_comex;
57645775

5765-
return 1;
5776+
return mlxplat_register_platform_device();
57665777
}
57675778

57685779
static int __init mlxplat_dmi_ng400_matched(const struct dmi_system_id *dmi)
@@ -5788,7 +5799,7 @@ static int __init mlxplat_dmi_ng400_matched(const struct dmi_system_id *dmi)
57885799
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
57895800
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_ng400;
57905801

5791-
return 1;
5802+
return mlxplat_register_platform_device();
57925803
}
57935804

57945805
static int __init mlxplat_dmi_modular_matched(const struct dmi_system_id *dmi)
@@ -5808,7 +5819,7 @@ static int __init mlxplat_dmi_modular_matched(const struct dmi_system_id *dmi)
58085819
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
58095820
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_eth_modular;
58105821

5811-
return 1;
5822+
return mlxplat_register_platform_device();
58125823
}
58135824

58145825
static int __init mlxplat_dmi_chassis_blade_matched(const struct dmi_system_id *dmi)
@@ -5830,7 +5841,7 @@ static int __init mlxplat_dmi_chassis_blade_matched(const struct dmi_system_id *
58305841
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
58315842
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_ng400;
58325843

5833-
return 1;
5844+
return mlxplat_register_platform_device();
58345845
}
58355846

58365847
static int __init mlxplat_dmi_rack_switch_matched(const struct dmi_system_id *dmi)
@@ -5851,7 +5862,7 @@ static int __init mlxplat_dmi_rack_switch_matched(const struct dmi_system_id *dm
58515862
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
58525863
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_rack_switch;
58535864

5854-
return 1;
5865+
return mlxplat_register_platform_device();
58555866
}
58565867

58575868
static int __init mlxplat_dmi_ng800_matched(const struct dmi_system_id *dmi)
@@ -5872,7 +5883,7 @@ static int __init mlxplat_dmi_ng800_matched(const struct dmi_system_id *dmi)
58725883
mlxplat_i2c = &mlxplat_mlxcpld_i2c_ng_data;
58735884
mlxplat_regmap_config = &mlxplat_mlxcpld_regmap_config_ng400;
58745885

5875-
return 1;
5886+
return mlxplat_register_platform_device();
58765887
}
58775888

58785889
static int __init mlxplat_dmi_l1_switch_matched(const struct dmi_system_id *dmi)
@@ -5895,7 +5906,7 @@ static int __init mlxplat_dmi_l1_switch_matched(const struct dmi_system_id *dmi)
58955906
pm_power_off = mlxplat_poweroff;
58965907
mlxplat_reboot_nb = &mlxplat_reboot_default_nb;
58975908

5898-
return 1;
5909+
return mlxplat_register_platform_device();
58995910
}
59005911

59015912
static const struct dmi_system_id mlxplat_dmi_table[] __initconst = {
@@ -6139,12 +6150,6 @@ static int mlxplat_lpc_cpld_device_init(struct resource **hotplug_resources,
61396150
{
61406151
int err;
61416152

6142-
mlxplat_dev = platform_device_register_simple(MLX_PLAT_DEVICE_NAME, PLATFORM_DEVID_NONE,
6143-
mlxplat_lpc_resources,
6144-
ARRAY_SIZE(mlxplat_lpc_resources));
6145-
if (IS_ERR(mlxplat_dev))
6146-
return PTR_ERR(mlxplat_dev);
6147-
61486153
mlxplat_mlxcpld_regmap_ctx.base = devm_ioport_map(&mlxplat_dev->dev,
61496154
mlxplat_lpc_resources[1].start, 1);
61506155
if (!mlxplat_mlxcpld_regmap_ctx.base) {
@@ -6158,13 +6163,11 @@ static int mlxplat_lpc_cpld_device_init(struct resource **hotplug_resources,
61586163
return 0;
61596164

61606165
fail_devm_ioport_map:
6161-
platform_device_unregister(mlxplat_dev);
61626166
return err;
61636167
}
61646168

61656169
static void mlxplat_lpc_cpld_device_exit(void)
61666170
{
6167-
platform_device_unregister(mlxplat_dev);
61686171
}
61696172

61706173
static int
@@ -6389,16 +6392,13 @@ static void mlxplat_i2c_main_exit(struct mlxplat_priv *priv)
63896392
platform_device_unregister(priv->pdev_i2c);
63906393
}
63916394

6392-
static int __init mlxplat_init(void)
6395+
static int mlxplat_probe(struct platform_device *pdev)
63936396
{
6394-
unsigned int hotplug_resources_size;
6395-
struct resource *hotplug_resources;
6397+
unsigned int hotplug_resources_size = 0;
6398+
struct resource *hotplug_resources = NULL;
63966399
struct mlxplat_priv *priv;
63976400
int i, err;
63986401

6399-
if (!dmi_check_system(mlxplat_dmi_table))
6400-
return -ENODEV;
6401-
64026402
err = mlxplat_pre_init(&hotplug_resources, &hotplug_resources_size);
64036403
if (err)
64046404
return err;
@@ -6461,9 +6461,8 @@ static int __init mlxplat_init(void)
64616461

64626462
return err;
64636463
}
6464-
module_init(mlxplat_init);
64656464

6466-
static void __exit mlxplat_exit(void)
6465+
static int mlxplat_remove(struct platform_device *pdev)
64676466
{
64686467
struct mlxplat_priv *priv = platform_get_drvdata(mlxplat_dev);
64696468

@@ -6474,6 +6473,38 @@ static void __exit mlxplat_exit(void)
64746473
mlxplat_pre_exit(priv);
64756474
mlxplat_i2c_main_exit(priv);
64766475
mlxplat_post_exit();
6476+
return 0;
6477+
}
6478+
6479+
static struct platform_driver mlxplat_driver = {
6480+
.driver = {
6481+
.name = "mlxplat",
6482+
.probe_type = PROBE_FORCE_SYNCHRONOUS,
6483+
},
6484+
.probe = mlxplat_probe,
6485+
.remove = mlxplat_remove,
6486+
};
6487+
6488+
static int __init mlxplat_init(void)
6489+
{
6490+
int err;
6491+
6492+
if (!dmi_check_system(mlxplat_dmi_table))
6493+
return -ENODEV;
6494+
6495+
err = platform_driver_register(&mlxplat_driver);
6496+
if (err)
6497+
return err;
6498+
return 0;
6499+
}
6500+
module_init(mlxplat_init);
6501+
6502+
static void __exit mlxplat_exit(void)
6503+
{
6504+
if (mlxplat_dev)
6505+
platform_device_unregister(mlxplat_dev);
6506+
6507+
platform_driver_unregister(&mlxplat_driver);
64776508
}
64786509
module_exit(mlxplat_exit);
64796510

0 commit comments

Comments
 (0)