328
328
* @pdev_fan - FAN platform devices
329
329
* @pdev_wd - array of watchdog platform devices
330
330
* @regmap: device register map
331
+ * @hotplug_resources: system hotplug resources
332
+ * @hotplug_resources_size: size of system hotplug resources
331
333
*/
332
334
struct mlxplat_priv {
333
335
struct platform_device * pdev_i2c ;
@@ -338,6 +340,8 @@ struct mlxplat_priv {
338
340
struct platform_device * pdev_fan ;
339
341
struct platform_device * pdev_wd [MLXPLAT_CPLD_WD_MAX_DEVS ];
340
342
void * regmap ;
343
+ struct resource * hotplug_resources ;
344
+ unsigned int hotplug_resources_size ;
341
345
};
342
346
343
347
static struct platform_device * mlxplat_dev ;
@@ -6002,20 +6006,63 @@ static int mlxplat_mlxcpld_check_wd_capability(void *regmap)
6002
6006
return 0 ;
6003
6007
}
6004
6008
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
+
6005
6053
static int __init mlxplat_init (void )
6006
6054
{
6055
+ unsigned int hotplug_resources_size ;
6056
+ struct resource * hotplug_resources ;
6007
6057
struct mlxplat_priv * priv ;
6008
6058
int i , j , nr , err ;
6009
6059
6010
6060
if (!dmi_check_system (mlxplat_dmi_table ))
6011
6061
return - ENODEV ;
6012
6062
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 ;
6019
6066
6020
6067
priv = devm_kzalloc (& mlxplat_dev -> dev , sizeof (struct mlxplat_priv ),
6021
6068
GFP_KERNEL );
@@ -6025,12 +6072,8 @@ static int __init mlxplat_init(void)
6025
6072
}
6026
6073
platform_set_drvdata (mlxplat_dev , priv );
6027
6074
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 ;
6034
6077
6035
6078
if (!mlxplat_regmap_config )
6036
6079
mlxplat_regmap_config = & mlxplat_mlxcpld_regmap_config ;
@@ -6051,8 +6094,8 @@ static int __init mlxplat_init(void)
6051
6094
if (mlxplat_i2c )
6052
6095
mlxplat_i2c -> regmap = priv -> regmap ;
6053
6096
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 ,
6056
6099
mlxplat_i2c , sizeof (* mlxplat_i2c ));
6057
6100
if (IS_ERR (priv -> pdev_i2c )) {
6058
6101
err = PTR_ERR (priv -> pdev_i2c );
@@ -6076,8 +6119,8 @@ static int __init mlxplat_init(void)
6076
6119
priv -> pdev_hotplug =
6077
6120
platform_device_register_resndata (& mlxplat_dev -> dev ,
6078
6121
"mlxreg-hotplug" , PLATFORM_DEVID_NONE ,
6079
- mlxplat_mlxcpld_resources ,
6080
- ARRAY_SIZE ( mlxplat_mlxcpld_resources ) ,
6122
+ priv -> hotplug_resources ,
6123
+ priv -> hotplug_resources_size ,
6081
6124
mlxplat_hotplug , sizeof (* mlxplat_hotplug ));
6082
6125
if (IS_ERR (priv -> pdev_hotplug )) {
6083
6126
err = PTR_ERR (priv -> pdev_hotplug );
@@ -6179,7 +6222,6 @@ static int __init mlxplat_init(void)
6179
6222
platform_device_unregister (priv -> pdev_mux [i ]);
6180
6223
platform_device_unregister (priv -> pdev_i2c );
6181
6224
fail_alloc :
6182
- platform_device_unregister (mlxplat_dev );
6183
6225
6184
6226
return err ;
6185
6227
}
@@ -6207,7 +6249,7 @@ static void __exit mlxplat_exit(void)
6207
6249
platform_device_unregister (priv -> pdev_mux [i ]);
6208
6250
6209
6251
platform_device_unregister (priv -> pdev_i2c );
6210
- platform_device_unregister ( mlxplat_dev );
6252
+ mlxplat_post_exit ( );
6211
6253
}
6212
6254
module_exit (mlxplat_exit );
6213
6255
0 commit comments