kernel: bump 5.4 to 5.4.109
[openwrt/openwrt.git] / target / linux / layerscape / patches-5.4 / 808-i2c-0005-MLK-20773-i2c-imx-add-a-limit-of-maximum-transfer-sp.patch
1 From ede2da5ea630fa2431145992c43aef51fc9c5c5a Mon Sep 17 00:00:00 2001
2 From: Clark Wang <xiaoning.wang@nxp.com>
3 Date: Fri, 18 Jan 2019 12:00:16 +0800
4 Subject: [PATCH] MLK-20773 i2c-imx: add a limit of maximum transfer speed for
5 imx7d
6
7 According the e7805 in Errata, the SCK low level period should be less
8 than 1.3us.
9
10 The other series platform use this same IP can match the errata, and
11 ensure the low level period longer than 1.3us when the speed set to
12 400KHz. However, only at imx7d platform, the low level period is less
13 than 1.3us in the same situation.
14
15 Therefore, limit the maximum transfer speed to 384KHz when probe at
16 imx7d platform.
17
18 Signed-off-by: Clark Wang <xiaoning.wang@nxp.com>
19 (cherry picked from commit 19f553846e872b5c379b37ed029132b79566cab0)
20 (cherry picked from commit 5d355407812025e5157f82b7763580e7295a40fd)
21 ---
22 drivers/i2c/busses/i2c-imx.c | 26 ++++++++++++++++++++++++++
23 1 file changed, 26 insertions(+)
24
25 --- a/drivers/i2c/busses/i2c-imx.c
26 +++ b/drivers/i2c/busses/i2c-imx.c
27 @@ -51,6 +51,7 @@
28
29 /* Default value */
30 #define IMX_I2C_BIT_RATE 100000 /* 100kHz */
31 +#define IMX_I2C_MAX_E_BIT_RATE 384000 /* 384kHz from e7805 errata*/
32
33 /*
34 * Enable DMA if transfer byte size is bigger than this threshold.
35 @@ -161,6 +162,7 @@ enum imx_i2c_type {
36 IMX1_I2C,
37 IMX21_I2C,
38 VF610_I2C,
39 + IMX7D_I2C,
40 };
41
42 struct imx_i2c_hwdata {
43 @@ -235,6 +237,16 @@ static struct imx_i2c_hwdata vf610_i2c_h
44
45 };
46
47 +static const struct imx_i2c_hwdata imx7d_i2c_hwdata = {
48 + .devtype = IMX7D_I2C,
49 + .regshift = IMX_I2C_REGSHIFT,
50 + .clk_div = imx_i2c_clk_div,
51 + .ndivs = ARRAY_SIZE(imx_i2c_clk_div),
52 + .i2sr_clr_opcode = I2SR_CLR_OPCODE_W0C,
53 + .i2cr_ien_opcode = I2CR_IEN_OPCODE_1,
54 +
55 +};
56 +
57 static const struct platform_device_id imx_i2c_devtype[] = {
58 {
59 .name = "imx1-i2c",
60 @@ -252,6 +264,7 @@ static const struct of_device_id i2c_imx
61 { .compatible = "fsl,imx1-i2c", .data = &imx1_i2c_hwdata, },
62 { .compatible = "fsl,imx21-i2c", .data = &imx21_i2c_hwdata, },
63 { .compatible = "fsl,vf610-i2c", .data = &vf610_i2c_hwdata, },
64 + { .compatible = "fsl,imx7d-i2c", .data = &imx7d_i2c_hwdata, },
65 { /* sentinel */ }
66 };
67 MODULE_DEVICE_TABLE(of, i2c_imx_dt_ids);
68 @@ -267,6 +280,11 @@ static inline int is_imx1_i2c(struct imx
69 return i2c_imx->hwdata->devtype == IMX1_I2C;
70 }
71
72 +static inline int is_imx7d_i2c(struct imx_i2c_struct *i2c_imx)
73 +{
74 + return i2c_imx->hwdata->devtype == IMX7D_I2C;
75 +}
76 +
77 static inline void imx_i2c_write_reg(unsigned int val,
78 struct imx_i2c_struct *i2c_imx, unsigned int reg)
79 {
80 @@ -1187,6 +1205,14 @@ static int i2c_imx_probe(struct platform
81 clk_notifier_register(i2c_imx->clk, &i2c_imx->clk_change_nb);
82 i2c_imx_set_clk(i2c_imx, clk_get_rate(i2c_imx->clk));
83
84 + /*
85 + * This limit caused by an i.MX7D hardware issue(e7805 in Errata).
86 + * If there is no limit, when the bitrate set up to 400KHz, it will
87 + * cause the SCK low level period less than 1.3us.
88 + */
89 + if (is_imx7d_i2c(i2c_imx) && i2c_imx->bitrate > IMX_I2C_MAX_E_BIT_RATE)
90 + i2c_imx->bitrate = IMX_I2C_MAX_E_BIT_RATE;
91 +
92 /* Set up chip registers to defaults */
93 imx_i2c_write_reg(i2c_imx->hwdata->i2cr_ien_opcode ^ I2CR_IEN,
94 i2c_imx, IMX_I2C_I2CR);