|
| 1 | +From cb4de56f5b1551eb925329beb4277048a8ba821f Mon Sep 17 00:00:00 2001 |
| 2 | +From: Vadim Pasternak < [email protected]> |
| 3 | +Date: Wed, 6 Jan 2021 01:33:47 +0200 |
| 4 | + |
| 5 | +commit 66b0c2846ba8de569026a067bb5a34ea5768408c upstream |
| 6 | + |
| 7 | +Subject: [PATCH backport 4.19 02/11] i2c: mlxcpld: Add support for I2C bus |
| 8 | + frequency setting |
| 9 | + |
| 10 | +Add support for I2C bus frequency setting according to the specific |
| 11 | +system capability. This capability is obtained from CPLD frequency |
| 12 | +setting register, which could be provided through the platform data. |
| 13 | +If such register is provided, it specifies minimal I2C bus frequency |
| 14 | +to be used for the devices attached to the I2C bus. Supported |
| 15 | +freqeuncies are 100KHz, 400KHz, 1MHz, while 100KHz is the default. |
| 16 | + |
| 17 | +Signed-off-by: Vadim Pasternak < [email protected]> |
| 18 | +Signed-off-by: Wolfram Sang < [email protected]> |
| 19 | +--- |
| 20 | + drivers/i2c/busses/i2c-mlxcpld.c | 63 +++++++++++++++++++++++++++++++++++++++- |
| 21 | + 1 file changed, 62 insertions(+), 1 deletion(-) |
| 22 | + |
| 23 | +diff --git a/drivers/i2c/busses/i2c-mlxcpld.c b/drivers/i2c/busses/i2c-mlxcpld.c |
| 24 | +index ae0d17513422..fa8cc0b71531 100644 |
| 25 | +--- a/drivers/i2c/busses/i2c-mlxcpld.c |
| 26 | ++++ b/drivers/i2c/busses/i2c-mlxcpld.c |
| 27 | +@@ -11,7 +11,9 @@ |
| 28 | + #include <linux/io.h> |
| 29 | + #include <linux/kernel.h> |
| 30 | + #include <linux/module.h> |
| 31 | ++#include <linux/platform_data/mlxreg.h> |
| 32 | + #include <linux/platform_device.h> |
| 33 | ++#include <linux/regmap.h> |
| 34 | + |
| 35 | + /* General defines */ |
| 36 | + #define MLXPLAT_CPLD_LPC_I2C_BASE_ADDR 0x2000 |
| 37 | +@@ -46,6 +48,16 @@ |
| 38 | + #define MLXCPLD_LPCI2C_ACK_IND 1 |
| 39 | + #define MLXCPLD_LPCI2C_NACK_IND 2 |
| 40 | + |
| 41 | ++#define MLXCPLD_I2C_FREQ_1000KHZ_SET 0x04 |
| 42 | ++#define MLXCPLD_I2C_FREQ_400KHZ_SET 0x0f |
| 43 | ++#define MLXCPLD_I2C_FREQ_100KHZ_SET 0x42 |
| 44 | ++ |
| 45 | ++enum mlxcpld_i2c_frequency { |
| 46 | ++ MLXCPLD_I2C_FREQ_1000KHZ = 1, |
| 47 | ++ MLXCPLD_I2C_FREQ_400KHZ = 2, |
| 48 | ++ MLXCPLD_I2C_FREQ_100KHZ = 3, |
| 49 | ++}; |
| 50 | ++ |
| 51 | + struct mlxcpld_i2c_curr_xfer { |
| 52 | + u8 cmd; |
| 53 | + u8 addr_width; |
| 54 | +@@ -463,8 +475,45 @@ static struct i2c_adapter mlxcpld_i2c_adapter = { |
| 55 | + .nr = MLXCPLD_I2C_BUS_NUM, |
| 56 | + }; |
| 57 | + |
| 58 | ++static int |
| 59 | ++mlxcpld_i2c_set_frequency(struct mlxcpld_i2c_priv *priv, |
| 60 | ++ struct mlxreg_core_hotplug_platform_data *pdata) |
| 61 | ++{ |
| 62 | ++ struct mlxreg_core_item *item = pdata->items; |
| 63 | ++ struct mlxreg_core_data *data; |
| 64 | ++ u32 regval; |
| 65 | ++ u8 freq; |
| 66 | ++ int err; |
| 67 | ++ |
| 68 | ++ if (!item) |
| 69 | ++ return 0; |
| 70 | ++ |
| 71 | ++ /* Read frequency setting. */ |
| 72 | ++ data = item->data; |
| 73 | ++ err = regmap_read(pdata->regmap, data->reg, ®val); |
| 74 | ++ if (err) |
| 75 | ++ return err; |
| 76 | ++ |
| 77 | ++ /* Set frequency only if it is not 100KHz, which is default. */ |
| 78 | ++ switch ((data->reg & data->mask) >> data->bit) { |
| 79 | ++ case MLXCPLD_I2C_FREQ_1000KHZ: |
| 80 | ++ freq = MLXCPLD_I2C_FREQ_1000KHZ_SET; |
| 81 | ++ break; |
| 82 | ++ case MLXCPLD_I2C_FREQ_400KHZ: |
| 83 | ++ freq = MLXCPLD_I2C_FREQ_400KHZ_SET; |
| 84 | ++ break; |
| 85 | ++ default: |
| 86 | ++ return 0; |
| 87 | ++ } |
| 88 | ++ |
| 89 | ++ mlxcpld_i2c_write_comm(priv, MLXCPLD_LPCI2C_HALF_CYC_REG, &freq, 1); |
| 90 | ++ |
| 91 | ++ return 0; |
| 92 | ++} |
| 93 | ++ |
| 94 | + static int mlxcpld_i2c_probe(struct platform_device *pdev) |
| 95 | + { |
| 96 | ++ struct mlxreg_core_hotplug_platform_data *pdata; |
| 97 | + struct mlxcpld_i2c_priv *priv; |
| 98 | + int err; |
| 99 | + u8 val; |
| 100 | +@@ -479,6 +528,14 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev) |
| 101 | + priv->dev = &pdev->dev; |
| 102 | + priv->base_addr = MLXPLAT_CPLD_LPC_I2C_BASE_ADDR; |
| 103 | + |
| 104 | ++ /* Set I2C bus frequency if platform data provides this info. */ |
| 105 | ++ pdata = dev_get_platdata(&pdev->dev); |
| 106 | ++ if (pdata) { |
| 107 | ++ err = mlxcpld_i2c_set_frequency(priv, pdata); |
| 108 | ++ if (err) |
| 109 | ++ goto mlxcpld_i2_probe_failed; |
| 110 | ++ } |
| 111 | ++ |
| 112 | + /* Register with i2c layer */ |
| 113 | + mlxcpld_i2c_adapter.timeout = usecs_to_jiffies(MLXCPLD_I2C_XFER_TO); |
| 114 | + /* Read capability register */ |
| 115 | +@@ -497,8 +554,12 @@ static int mlxcpld_i2c_probe(struct platform_device *pdev) |
| 116 | + |
| 117 | + err = i2c_add_numbered_adapter(&priv->adap); |
| 118 | + if (err) |
| 119 | +- mutex_destroy(&priv->lock); |
| 120 | ++ goto mlxcpld_i2_probe_failed; |
| 121 | + |
| 122 | ++ return 0; |
| 123 | ++ |
| 124 | ++mlxcpld_i2_probe_failed: |
| 125 | ++ mutex_destroy(&priv->lock); |
| 126 | + return err; |
| 127 | + } |
| 128 | + |
| 129 | +-- |
| 130 | +2.11.0 |
| 131 | + |
0 commit comments