Skip to content

Commit 84af1b1

Browse files
vadimp-nvidiawsakernel
authored andcommitted
i2c: mux: mlxcpld: Convert driver to platform driver
Convert driver from 'i2c' to 'platform'. The motivation is to avoid I2C addressing conflict between ‘i2c-mux-cpld’ driver, providing mux selection and deselection through CPLD ‘mux control’ register, and CPLD host driver. The CPLD is I2C device and is multi-functional device performing logic for different components, like LED, ‘hwmon’, interrupt control, watchdog etcetera. For such configuration CPLD should be host I2C device, connected to the relevant I2C bus with the relevant I2C address and all others component drivers are supposed to be its children. The hierarchy in such case will be like in the below example: ls /sys/bus/i2c/devices/44-0032 i2c-mux-mlxcpld.44 leds-mlxreg.44 mlxreg-io.44 ls /sys/bus/i2c/devices/44-0032/i2c-mux-mlxcpld.44 channel-0, …, channel-X Currently this driver is not activated by any kernel driver, so this conversion doesn’t affect any user. Signed-off-by: Vadim Pasternak <vadimp@nvidia.com> Reviewed-by: Michael Shych <michaelsh@nvidia.com> Acked-by: Peter Rosin <peda@axentia.se> Signed-off-by: Wolfram Sang <wsa@kernel.org>
1 parent 05ae60b commit 84af1b1

File tree

1 file changed

+28
-34
lines changed

1 file changed

+28
-34
lines changed

drivers/i2c/muxes/i2c-mux-mlxcpld.c

Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
/* mlxcpld_mux - mux control structure:
2121
* @last_chan - last register value
2222
* @client - I2C device client
23+
* @pdata: platform data
2324
*/
2425
struct mlxcpld_mux {
2526
u8 last_chan;
2627
struct i2c_client *client;
28+
struct mlxcpld_mux_plat_data pdata;
2729
};
2830

2931
/* MUX logic description.
@@ -54,59 +56,50 @@ struct mlxcpld_mux {
5456
*
5557
*/
5658

57-
static const struct i2c_device_id mlxcpld_mux_id[] = {
58-
{ "mlxcpld_mux_module", 0 },
59-
{ }
60-
};
61-
MODULE_DEVICE_TABLE(i2c, mlxcpld_mux_id);
62-
6359
/* Write to mux register. Don't use i2c_transfer() and i2c_smbus_xfer()
6460
* for this as they will try to lock adapter a second time.
6561
*/
6662
static int mlxcpld_mux_reg_write(struct i2c_adapter *adap,
67-
struct i2c_client *client, u8 val)
63+
struct mlxcpld_mux *mux, u8 val)
6864
{
69-
struct mlxcpld_mux_plat_data *pdata = dev_get_platdata(&client->dev);
65+
struct i2c_client *client = mux->client;
7066
union i2c_smbus_data data = { .byte = val };
7167

7268
return __i2c_smbus_xfer(adap, client->addr, client->flags,
73-
I2C_SMBUS_WRITE, pdata->sel_reg_addr,
69+
I2C_SMBUS_WRITE, mux->pdata.sel_reg_addr,
7470
I2C_SMBUS_BYTE_DATA, &data);
7571
}
7672

7773
static int mlxcpld_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
7874
{
79-
struct mlxcpld_mux *data = i2c_mux_priv(muxc);
80-
struct i2c_client *client = data->client;
75+
struct mlxcpld_mux *mux = i2c_mux_priv(muxc);
8176
u8 regval = chan + 1;
8277
int err = 0;
8378

8479
/* Only select the channel if its different from the last channel */
85-
if (data->last_chan != regval) {
86-
err = mlxcpld_mux_reg_write(muxc->parent, client, regval);
87-
data->last_chan = err < 0 ? 0 : regval;
80+
if (mux->last_chan != regval) {
81+
err = mlxcpld_mux_reg_write(muxc->parent, mux, regval);
82+
mux->last_chan = err < 0 ? 0 : regval;
8883
}
8984

9085
return err;
9186
}
9287

9388
static int mlxcpld_mux_deselect(struct i2c_mux_core *muxc, u32 chan)
9489
{
95-
struct mlxcpld_mux *data = i2c_mux_priv(muxc);
96-
struct i2c_client *client = data->client;
90+
struct mlxcpld_mux *mux = i2c_mux_priv(muxc);
9791

9892
/* Deselect active channel */
99-
data->last_chan = 0;
93+
mux->last_chan = 0;
10094

101-
return mlxcpld_mux_reg_write(muxc->parent, client, data->last_chan);
95+
return mlxcpld_mux_reg_write(muxc->parent, mux, mux->last_chan);
10296
}
10397

10498
/* Probe/reomove functions */
105-
static int mlxcpld_mux_probe(struct i2c_client *client,
106-
const struct i2c_device_id *id)
99+
static int mlxcpld_mux_probe(struct platform_device *pdev)
107100
{
108-
struct i2c_adapter *adap = client->adapter;
109-
struct mlxcpld_mux_plat_data *pdata = dev_get_platdata(&client->dev);
101+
struct mlxcpld_mux_plat_data *pdata = dev_get_platdata(&pdev->dev);
102+
struct i2c_client *client = to_i2c_client(pdev->dev.parent);
110103
struct i2c_mux_core *muxc;
111104
int num, force;
112105
struct mlxcpld_mux *data;
@@ -115,18 +108,20 @@ static int mlxcpld_mux_probe(struct i2c_client *client,
115108
if (!pdata)
116109
return -EINVAL;
117110

118-
if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
111+
if (!i2c_check_functionality(client->adapter,
112+
I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
119113
return -ENODEV;
120114

121-
muxc = i2c_mux_alloc(adap, &client->dev, CPLD_MUX_MAX_NCHANS,
115+
muxc = i2c_mux_alloc(client->adapter, &pdev->dev, CPLD_MUX_MAX_NCHANS,
122116
sizeof(*data), 0, mlxcpld_mux_select_chan,
123117
mlxcpld_mux_deselect);
124118
if (!muxc)
125119
return -ENOMEM;
126120

121+
platform_set_drvdata(pdev, muxc);
127122
data = i2c_mux_priv(muxc);
128-
i2c_set_clientdata(client, muxc);
129123
data->client = client;
124+
memcpy(&data->pdata, pdata, sizeof(*pdata));
130125
data->last_chan = 0; /* force the first selection */
131126

132127
/* Create an adapter for each channel. */
@@ -149,24 +144,23 @@ static int mlxcpld_mux_probe(struct i2c_client *client,
149144
return err;
150145
}
151146

152-
static int mlxcpld_mux_remove(struct i2c_client *client)
147+
static int mlxcpld_mux_remove(struct platform_device *pdev)
153148
{
154-
struct i2c_mux_core *muxc = i2c_get_clientdata(client);
149+
struct i2c_mux_core *muxc = platform_get_drvdata(pdev);
155150

156151
i2c_mux_del_adapters(muxc);
157152
return 0;
158153
}
159154

160-
static struct i2c_driver mlxcpld_mux_driver = {
161-
.driver = {
162-
.name = "mlxcpld-mux",
155+
static struct platform_driver mlxcpld_mux_driver = {
156+
.driver = {
157+
.name = "i2c-mux-mlxcpld",
163158
},
164-
.probe = mlxcpld_mux_probe,
165-
.remove = mlxcpld_mux_remove,
166-
.id_table = mlxcpld_mux_id,
159+
.probe = mlxcpld_mux_probe,
160+
.remove = mlxcpld_mux_remove,
167161
};
168162

169-
module_i2c_driver(mlxcpld_mux_driver);
163+
module_platform_driver(mlxcpld_mux_driver);
170164

171165
MODULE_AUTHOR("Michael Shych (michaels@mellanox.com)");
172166
MODULE_DESCRIPTION("Mellanox I2C-CPLD-MUX driver");

0 commit comments

Comments
 (0)