drivers/platform/x86: add mlxcpld-hotplug driver registration to mlx-platform driver
PATCH v2 2/2 drivers/platform/x86: add mlxcpld-hotplug driver registration to mlx-platform driver
Add calls for mlxcpld-hotplug platform driver registration/unregistration and add platform hotplug data configurations. This driver, when registered within system will handle system hot-plug events for the power suppliers, power cables and fans (insertion and removing). These events are controlled through CPLD Lattice device.
v1->v2:
Comments pointed out by Andy:
- Remove "from sender" from the message body;
- Add more information to commit message. (When CPLD spec will be available at Mellanox portal - MAINTAINERS Web-page info is to be updated);
- Do not change include order.
--- drivers/platform/x86/mlx-platform.c | 98 ++++++++++++++++++++++++++++++++++++- 1 file changed, 97 insertions(+), 1 deletion(-)
drivers/platform/x86/mlx-platform.c +97 -1
@@ -39,6 +39,7 @@#include <linux/module.h> #include <linux/platform_device.h> #include <linux/platform_data/i2c-mux-reg.h> +#include <linux/platform_data/mlxcpld-hotplug.h> #define MLX_PLAT_DEVICE_NAME "mlxplat"
@@ -70,6 +71,7 @@struct mlxplat_priv {struct platform_device *pdev_i2c;struct platform_device *pdev_mux[MLXPLAT_CPLD_LPC_MUX_DEVS ]; +struct platform_device *pdev_hotplug; };/* Regions for LPC I2C controller and LPC base register space */
@@ -121,7 +123,87 @@ static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { }; -static struct platform_device *mlxplat_dev; +/* Platform hotplug devices */ +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_psu[] = { + { + .brdinfo = {I2C_BOARD_INFO ("24c02" ,0x51 ) }, + .bus =10 , + }, + { + .brdinfo = {I2C_BOARD_INFO ("24c02" ,0x50 ) }, + .bus =10 , + }, +}; + +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_pwr[] = { + { + .brdinfo = {I2C_BOARD_INFO ("dps460" ,0x59 ) }, + .bus =10 , + }, + { + .brdinfo = {I2C_BOARD_INFO ("dps460" ,0x58 ) }, + .bus =10 , + }, +}; + +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_fan[] = { + { + .brdinfo = {I2C_BOARD_INFO ("24c32" ,0x50 ) }, + .bus =11 , + }, + { + .brdinfo = {I2C_BOARD_INFO ("24c32" ,0x50 ) }, + .bus =12 , + }, + { + .brdinfo = {I2C_BOARD_INFO ("24c32" ,0x50 ) }, + .bus =13 , + }, + { + .brdinfo = {I2C_BOARD_INFO ("24c32" ,0x50 ) }, + .bus =14 , + }, +}; + +/* Platform hotplug default data */ +static +struct mlxcpld_hotplug_platform_data mlxplat_mlxcpld_hotplug_default_data = { + .top_aggr_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR |0x3a ), + .top_aggr_mask =0x48 , + .top_aggr_psu_mask =0x08 , + .psu_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR |0x58 ), + .psu_mask =0x03 , + .psu_count =ARRAY_SIZE (mlxplat_mlxcpld_hotplug_psu), + .psu = mlxplat_mlxcpld_hotplug_psu, + .top_aggr_pwr_mask =0x08 , + .pwr_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR |0x64 ), + .pwr_mask =0x03 , + .pwr_count =ARRAY_SIZE (mlxplat_mlxcpld_hotplug_pwr), + .pwr = mlxplat_mlxcpld_hotplug_pwr, + .top_aggr_fan_mask =0x40 , + .fan_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR |0x88 ), + .fan_mask =0x0f , + .fan_count =ARRAY_SIZE (mlxplat_mlxcpld_hotplug_fan), + .fan = mlxplat_mlxcpld_hotplug_fan, +}; + +/* Platform hotplug MSN21xx system family data */ +static +struct mlxcpld_hotplug_platform_data mlxplat_mlxcpld_hotplug_msn21xx_data = { + .top_aggr_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR |0x3a ), + .top_aggr_mask =0x04 , + .top_aggr_pwr_mask =0x04 , + .pwr_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR |0x64 ), + .pwr_mask =0x03 , + .pwr_count =ARRAY_SIZE (mlxplat_mlxcpld_hotplug_pwr), +}; + +static struct resource mlxplat_mlxcpld_hotplug_resources[] = { + [0 ] =DEFINE_RES_IRQ_NAMED (17 ,"mlxcpld-hotplug" ), +}; + +struct platform_device *mlxplat_dev; +struct mlxcpld_hotplug_platform_data *mlxplat_hotplug;static int __init mlxplat_dmi_default_matched (const struct dmi_system_id *dmi) {
@@ -132,6 +214,7 @@ static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi) mlxplat_mux_data[i].n_values =ARRAY_SIZE (mlxplat_default_channels[i]); } + mlxplat_hotplug = &mlxplat_mlxcpld_hotplug_default_data;return 1 ; };
@@ -145,6 +228,7 @@ static int __init mlxplat_dmi_msn21xx_matched(const struct dmi_system_id *dmi) mlxplat_mux_data[i].n_values =ARRAY_SIZE (mlxplat_msn21xx_channels); } + mlxplat_hotplug = &mlxplat_mlxcpld_hotplug_msn21xx_data;return 1 ; };
@@ -230,6 +314,16 @@ static int __init mlxplat_init(void) } } + priv->pdev_hotplug =platform_device_register_resndata ( + &mlxplat_dev->dev,"mlxcpld-hotplug" ,-1 , + mlxplat_mlxcpld_hotplug_resources, +ARRAY_SIZE (mlxplat_mlxcpld_hotplug_resources), + mlxplat_hotplug,sizeof (*mlxplat_hotplug)); +if (IS_ERR (priv->pdev_hotplug)) { + err =PTR_ERR (priv->pdev_hotplug); + goto fail_platform_mux_register; + } +return 0 ; fail_platform_mux_register:
@@ -248,6 +342,8 @@ static void __exit mlxplat_exit(void)struct mlxplat_priv *priv =platform_get_drvdata (mlxplat_dev);int i; +platform_device_unregister (priv->pdev_hotplug); +for (i =ARRAY_SIZE (mlxplat_mux_data) -1 ; i >=0 ; i--)platform_device_unregister (priv->pdev_mux[i]);
Signature · 1 line
2.1.4
Same comment regarding series (Use --thread to git send-email)
Quoted 11 lines · Vadim Pasternak
Add calls for mlxcpld-hotplug platform driver registration/unregistration
and add platform hotplug data configurations. This driver, when registered
within system will handle system hot-plug events for the power suppliers,
power cables and fans (insertion and removing). These events are controlled through CPLD Lattice device.Signed-off-by Vadim Pasternak <[email protected]>
Quoted 7 lines
v1->v2:
Comments pointed out by Andy:
- Remove "from sender" from the message body;
- Add more information to commit message. (When CPLD spec will be available at Mellanox portal -MAINTAINERSWeb-page info is to be updated);
- Do not change include order.
Same comment. Put it below '---' line.
Quoted 10 lines
---
(quoted diff) +0
-0@@ -121,7 +123,87 @@ static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = {
};-static struct
platform_device*mlxplat_dev;
Why did you move it? Seems like it's not needed in this patch.
Review
Quoted 2 lines
(quoted diff) +2
-0+/* Platform hotplug devices */ +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_psu[] =
I_really_like_long_names_of_variables. No, I don't.
Review
Quoted 8 lines
(quoted diff) +4
-0+static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_pwr[] = +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_fan[] = +static +struct mlxcpld_hotplug_platform_data
mlxplat_mlxcpld_hotplug_default_data= {(quoted diff) +1
-0+ .top_aggr_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x3a),
| ?! Can you elaborate why it's ORred and not just added?
Besides that redundant parens.
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 173
Quoted 2 lines
drivers/platform/x86/mlx-platform.c +2
-0+ .top_aggr_mask = 0x48, + .top_aggr_psu_mask = 0x08,
And above explanation might shed a light why you are using interesting masks like 0b101.
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 175
Quoted 2 lines
drivers/platform/x86/mlx-platform.c +2
-0+ .psu_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x58), + .psu_mask = 0x03,
GENMASK()?
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 187
Quoted 12 lines
drivers/platform/x86/mlx-platform.c +12
-0+ .psu_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_psu), + .psu = mlxplat_mlxcpld_hotplug_psu, + .top_aggr_pwr_mask = 0x08, + .pwr_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x64), + .pwr_mask = 0x03, + .pwr_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_pwr), + .pwr = mlxplat_mlxcpld_hotplug_pwr, + .top_aggr_fan_mask = 0x40, + .fan_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x88), + .fan_mask = 0x0f, + .fan_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_fan), + .fan = mlxplat_mlxcpld_hotplug_fan,
Wouldn't be cleaner like this:
struct hotplug_dev_pdata {
reg_offset;
mask;
count;
void *somethig;
};
struct hotplug_pdata {
/* top stuff, will see later how to put it here */
struct hotplug_dev_data psu;
struct hotplug_dev_data pwr;
struct hotplug_dev_data fan;
};
Quoted 31 lines
drivers/platform/x86/mlx-platform.c +5
-0+}; + +/* Platform hotplug MSN21xx system family data */ +static +struct mlxcpld_hotplug_platform_data
mlxplat_mlxcpld_hotplug_msn21xx_data= {drivers/platform/x86/mlx-platform.c +14
-0+ .top_aggr_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x3a), + .top_aggr_mask = 0x04, + .top_aggr_pwr_mask = 0x04, + .pwr_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x64), + .pwr_mask = 0x03, + .pwr_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_pwr), +}; + +static struct resource mlxplat_mlxcpld_hotplug_resources[] = { + [0 ] =DEFINE_RES_IRQ_NAMED (17 ,"mlxcpld-hotplug" ), +}; + +struct platform_device *mlxplat_dev; +struct mlxcpld_hotplug_platform_data *mlxplat_hotplug;
static int__initmlxplat_dmi_default_matched(const struct dmi_system_id *dmi)
{(quoted diff) +0
-0@@ -132,6 +214,7 @@ static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi)mlxplat_mux_data[i].n_values =
ARRAY_SIZE(mlxplat_default_channels[i ]);
}
drivers/platform/x86/mlx-platform.c static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi) · line 217
Quoted 1 line
drivers/platform/x86/mlx-platform.c +1
-0+ mlxplat_hotplug = &mlxplat_mlxcpld_hotplug_default_data;
Is it only one hotplug device at a time? Otherwise it will be affected by race conditions.
Quoted 16 lines
return 1;
};(quoted diff) +0
-0@@ -145,6 +228,7 @@ static int __init mlxplat_dmi_msn21xx_matched(const struct dmi_system_id *dmi)mlxplat_mux_data[i].n_values =
ARRAY_SIZE(mlxplat_msn21xx_channels); }drivers/platform/x86/mlx-platform.c +1
-0+ mlxplat_hotplug = &mlxplat_mlxcpld_hotplug_msn21xx_data;
return 1;
};(quoted diff) +0
-0@@ -230,6 +314,16 @@ static int __init mlxplat_init(void) } }
drivers/platform/x86/mlx-platform.c static int __init mlxplat_init(void)
Quoted 4 lines
drivers/platform/x86/mlx-platform.c +2
-1+ priv->pdev_hotplug = platform_device_register_resndata( + &mlxplat_dev->dev, "mlxcpld-hotplug", -1,
Isn't it something like PLATFORM_DEVID_AUTO / NONE ?
Quoted 23 lines
(quoted diff) +2
-0+ mlxplat_mlxcpld_hotplug_resources, + ARRAY_SIZE(mlxplat_mlxcpld_hotplug_resources),
(quoted diff) +1
-0+ mlxplat_hotplug,
sizeof(*mlxplat_hotplug));drivers/platform/x86/mlx-platform.c +5
-0+if (IS_ERR (priv->pdev_hotplug)) { + err =PTR_ERR (priv->pdev_hotplug); + goto fail_platform_mux_register; + } +return 0;
fail_platform_mux_register:(quoted diff) +0
-0@@ -248,6 +342,8 @@ static void __exit mlxplat_exit(void)struct
mlxplat_priv*priv =platform_get_drvdata(mlxplat_dev);
int i;drivers/platform/x86/mlx-platform.c +2
-0+platform_device_unregister (priv->pdev_hotplug); +for (i =
ARRAY_SIZE(mlxplat_mux_data)- 1; i >= 0 ; i--)platform_device_unregister(priv->pdev_mux[i]);
Signature · 2 lines
Andy Shevchenko <[email protected]> Intel Finland Oy
Quoted 42 lines
-----Original Message-----
From: Andy Shevchenko [mailto:[email protected]]
Sent: Thursday, October 27, 2016 9:25 PM
To: Vadim Pasternak <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; akpm@linux- foundation.org; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [patch v2 2/2]drivers/platform/x86: add mlxcpld-hotplug driver registration to mlx-platform driverSame comment regarding series (Use --thread to git send-email)
Quoted 9 lines · Vadim Pasternak
Add calls for mlxcpld-hotplug platform driver registration/unregistration and add platform hotplug data configurations. This driver, when registered within system will handle system hot-plug events for the power suppliers, power cables and fans (insertion and removing). These events are controlled through CPLD Lattice device.
Signed-off-by Vadim Pasternak <[email protected]>Quoted 7 lines
v1->v2:
Comments pointed out by Andy:
- Remove "from sender" from the message body;
- Add more information to commit message. (When CPLD spec will be available at Mellanox portal -MAINTAINERSWeb-page info is to be updated);
- Do not change include order.Same comment. Put it below '---' line.
Quoted 6 lines
---
(quoted diff) +0
-0@@ -121,7 +123,87 @@ static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = {
Quoted 6 lines
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 124
Quoted 4 lines
drivers/platform/x86/mlx-platform.c +0
-1}; -static struct platform_device *mlxplat_dev;Why did you move it? Seems like it's not needed in this patch.
Just by mistake.
Sorry.
Quoted 5 lines
Review static struct i2c_mux_reg_platform_data · line 129
Quoted 3 lines
(quoted diff) +2
-0+/* Platform hotplug devices */ +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_psu[] =
I_really_like_long_names_of_variables. No, I don't.
I keep prefix mlxplat_mlxcpld for consistency. Maybe I can remove " hotplug_" to make variable shorter?
Quoted 7 lines
Quoted 5 lines
(quoted diff) +3
-0+static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_pwr[] = +static struct mlxcpld_hotplug_device mlxplat_mlxcpld_hotplug_fan[] = +static struct mlxcpld_hotplug_platform_data mlxplat_mlxcpld_hotplug_default_data = {
Quoted 5 lines
Review static struct i2c_mux_reg_platform_data · line 134
Quoted 1 line
(quoted diff) +1
-0+ .top_aggr_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x3a),| ?! Can you elaborate why it's ORred and not just added?
Besides that redundant parens.
Will remove parens and change "or" to + (no special reason).
Quoted 6 lines
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 173
Quoted 3 lines
drivers/platform/x86/mlx-platform.c +2
-0+ .top_aggr_mask = 0x48, + .top_aggr_psu_mask = 0x08,And above explanation might shed a light why you are using interesting masks like 0b101.
Will add comments for masks (just 0x40 is masking in CPLD aggregation register PSU and PWR events, 0x08 - FAN events) for default system type.
Quoted 5 lines
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 175
Quoted 3 lines
drivers/platform/x86/mlx-platform.c +2
-0+ .psu_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x58), + .psu_mask = 0x03,
GENMASK()?
OK, will change it to
.psu_mask = GENMASK(0, 1) and other appearances.
Quoted 23 lines
drivers/platform/x86/mlx-platform.c static struct i2c_mux_reg_platform_data mlxplat_mux_data[] = { · line 187
Quoted 13 lines
drivers/platform/x86/mlx-platform.c +12
-0+ .psu_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_psu), + .psu = mlxplat_mlxcpld_hotplug_psu, + .top_aggr_pwr_mask = 0x08, + .pwr_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x64), + .pwr_mask = 0x03, + .pwr_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_pwr), + .pwr = mlxplat_mlxcpld_hotplug_pwr, + .top_aggr_fan_mask = 0x40, + .fan_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x88), + .fan_mask = 0x0f, + .fan_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_fan), + .fan = mlxplat_mlxcpld_hotplug_fan,Wouldn't be cleaner like this:
struct
hotplug_dev_pdata{
reg_offset;
mask;
count;
void *somethig;
};
Quoted 7 lines
struct
hotplug_pdata{
/* top stuff, will see later how to put it here */struct
hotplug_dev_datapsu;
structhotplug_dev_datapwr;
structhotplug_dev_datafan;
};
I will consider this change for the next patch.
Quoted 32 lines
Quoted 31 lines
drivers/platform/x86/mlx-platform.c +5
-0+}; + +/* Platform hotplug MSN21xx system family data */ +static +struct mlxcpld_hotplug_platform_data
mlxplat_mlxcpld_hotplug_msn21xx_data= {drivers/platform/x86/mlx-platform.c +14
-0+ .top_aggr_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x3a), + .top_aggr_mask = 0x04, + .top_aggr_pwr_mask = 0x04, + .pwr_reg_offset = (MLXPLAT_CPLD_LPC_REG_BASE_ADRR | 0x64), + .pwr_mask = 0x03, + .pwr_count = ARRAY_SIZE(mlxplat_mlxcpld_hotplug_pwr), +}; + +static struct resource mlxplat_mlxcpld_hotplug_resources[] = { + [0 ] =DEFINE_RES_IRQ_NAMED (17 ,"mlxcpld-hotplug" ), +}; + +struct platform_device *mlxplat_dev; +struct mlxcpld_hotplug_platform_data *mlxplat_hotplug;static int
__initmlxplat_dmi_default_matched(const struct dmi_system_id *dmi)
{(quoted diff) +0
-0@@ -132,6 +214,7 @@ static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi)mlxplat_mux_data[i].n_values =
ARRAY_SIZE(mlxplat_default_channels[i ]);
}
Quoted 5 lines
drivers/platform/x86/mlx-platform.c static int __init mlxplat_dmi_default_matched(const struct dmi_system_id *dmi) · line 217
Quoted 1 line
drivers/platform/x86/mlx-platform.c +1
-0+ mlxplat_hotplug = &mlxplat_mlxcpld_hotplug_default_data;Is it only one hotplug device at a time? Otherwise it will be affected by race conditions.
Only one CPLD per box, which handles all the events.
Quoted 16 lines
Quoted 16 lines
return 1;
};(quoted diff) +0
-0@@ -145,6 +228,7 @@ static int __init mlxplat_dmi_msn21xx_matched(const struct dmi_system_id *dmi)mlxplat_mux_data[i].n_values =
ARRAY_SIZE(mlxplat_msn21xx_channels); }drivers/platform/x86/mlx-platform.c +1
-0+ mlxplat_hotplug = &mlxplat_mlxcpld_hotplug_msn21xx_data;return 1;
};(quoted diff) +0
-0@@ -230,6 +314,16 @@ static int __init mlxplat_init(void) } }
Quoted 6 lines
drivers/platform/x86/mlx-platform.c static int __init mlxplat_init(void)
Quoted 4 lines
drivers/platform/x86/mlx-platform.c +2
-1+ priv->pdev_hotplug = platform_device_register_resndata( + &mlxplat_dev->dev, "mlxcpld-hotplug", -1,Isn't it something like
PLATFORM_DEVID_AUTO/ NONE ?
Will change -1 to PLATFORM_DEVID_NONE.
Quoted 19 lines
Quoted 19 lines
(quoted diff) +3
-0+ mlxplat_mlxcpld_hotplug_resources, + ARRAY_SIZE(mlxplat_mlxcpld_hotplug_re sources), + mlxplat_hotplug,
sizeof(*mlxplat_hotplug));drivers/platform/x86/mlx-platform.c +5
-0+if (IS_ERR (priv->pdev_hotplug)) { + err =PTR_ERR (priv->pdev_hotplug); + goto fail_platform_mux_register; + } +return 0;
fail_platform_mux_register:
(quoted diff) +0
-0@@ -248,6 +342,8 @@ static void __exit mlxplat_exit(void)struct
mlxplat_priv*priv =platform_get_drvdata(mlxplat_dev);
int i;
Quoted 9 lines
Quoted 5 lines
drivers/platform/x86/mlx-platform.c +2
-0+platform_device_unregister (priv->pdev_hotplug); +for (i =
ARRAY_SIZE(mlxplat_mux_data)- 1; i >= 0 ; i--)platform_device_unregister(priv->pdev_mux[i]);--
Andy Shevchenko <[email protected]> Intel Finland Oy
Thank you for review,
Vadim.