i2c: mux: mlxcpld: Extend driver to support word address space devices
authorVadim Pasternak <vadimp@nvidia.com>
Mon, 8 Feb 2021 20:16:04 +0000 (22:16 +0200)
committerWolfram Sang <wsa@kernel.org>
Tue, 9 Feb 2021 10:35:34 +0000 (11:35 +0100)
Extend driver to allow I2C routing control through CPLD devices with
word address space. Till now only CPLD devices with byte address space
have been supported.

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>
drivers/i2c/muxes/i2c-mux-mlxcpld.c
include/linux/platform_data/mlxcpld.h

index e99a7ad09886e10e0a8251cf47b24421f193a180..10767ad4adb4e8f51093e0aba5610a3b94486483 100644 (file)
@@ -63,19 +63,39 @@ static int mlxcpld_mux_reg_write(struct i2c_adapter *adap,
                                 struct mlxcpld_mux *mux, u32 val)
 {
        struct i2c_client *client = mux->client;
-       union i2c_smbus_data data = { .byte = val };
-
-       return __i2c_smbus_xfer(adap, client->addr, client->flags,
-                               I2C_SMBUS_WRITE, mux->pdata.sel_reg_addr,
-                               I2C_SMBUS_BYTE_DATA, &data);
+       union i2c_smbus_data data;
+       struct i2c_msg msg;
+       u8 buf[3];
+
+       switch (mux->pdata.reg_size) {
+       case 1:
+               data.byte = val;
+               return __i2c_smbus_xfer(adap, client->addr, client->flags,
+                                       I2C_SMBUS_WRITE, mux->pdata.sel_reg_addr,
+                                       I2C_SMBUS_BYTE_DATA, &data);
+       case 2:
+               buf[0] = mux->pdata.sel_reg_addr >> 8;
+               buf[1] = mux->pdata.sel_reg_addr;
+               buf[2] = val;
+               msg.addr = client->addr;
+               msg.buf = buf;
+               msg.len = mux->pdata.reg_size + 1;
+               msg.flags = 0;
+               return __i2c_transfer(adap, &msg, 1);
+       default:
+               return -EINVAL;
+       }
 }
 
 static int mlxcpld_mux_select_chan(struct i2c_mux_core *muxc, u32 chan)
 {
        struct mlxcpld_mux *mux = i2c_mux_priv(muxc);
-       u32 regval = chan + 1;
+       u32 regval = chan;
        int err = 0;
 
+       if (mux->pdata.reg_size == 1)
+               regval += 1;
+
        /* Only select the channel if its different from the last channel */
        if (mux->last_val != regval) {
                err = mlxcpld_mux_reg_write(muxc->parent, mux, regval);
@@ -103,12 +123,23 @@ static int mlxcpld_mux_probe(struct platform_device *pdev)
        struct i2c_mux_core *muxc;
        struct mlxcpld_mux *data;
        int num, err;
+       u32 func;
 
        if (!pdata)
                return -EINVAL;
 
-       if (!i2c_check_functionality(client->adapter,
-                                    I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
+       switch (pdata->reg_size) {
+       case 1:
+               func = I2C_FUNC_SMBUS_WRITE_BYTE_DATA;
+               break;
+       case 2:
+               func = I2C_FUNC_I2C;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (!i2c_check_functionality(client->adapter, func))
                return -ENODEV;
 
        muxc = i2c_mux_alloc(client->adapter, &pdev->dev, CPLD_MUX_MAX_NCHANS,
index 04d93c563c04c24206654c5bad8d56272677baa5..a7bee798d99175f69f065b21e04a75cb63728db1 100644 (file)
  * @chan_ids - channels array
  * @num_adaps - number of adapters
  * @sel_reg_addr - mux select register offset in CPLD space
+ * @reg_size: register size in bytes
  */
 struct mlxcpld_mux_plat_data {
        int *chan_ids;
        int num_adaps;
        int sel_reg_addr;
+       u8 reg_size;
 };
 
 #endif /* _LINUX_I2C_MLXCPLD_H */