layerscape: add linux 4.9 support
[openwrt/staging/wigyori.git] / target / linux / layerscape / patches-4.9 / 809-i2c-support-layerscape.patch
1 From 3c5032fe34f1af50e9e5fe58d40bf93c1717302f Mon Sep 17 00:00:00 2001
2 From: Yangbo Lu <yangbo.lu@nxp.com>
3 Date: Mon, 25 Sep 2017 12:19:53 +0800
4 Subject: [PATCH] i2c: support layerscape
5
6 This is a integrated patch for layerscape i2c support.
7
8 Signed-off-by: Zhang Ying-22455 <ying.zhang22455@nxp.com>
9 Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com>
10 Signed-off-by: Yangbo Lu <yangbo.lu@nxp.com>
11 ---
12 drivers/i2c/busses/i2c-imx.c | 10 ++++++++-
13 drivers/i2c/muxes/i2c-mux-pca954x.c | 43 +++++++++++++++++++++++++++++++++++++
14 2 files changed, 52 insertions(+), 1 deletion(-)
15
16 diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
17 index 47fc1f1a..a35c366b 100644
18 --- a/drivers/i2c/busses/i2c-imx.c
19 +++ b/drivers/i2c/busses/i2c-imx.c
20 @@ -889,6 +889,14 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
21
22 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
23
24 + /*
25 + * workround for ERR010027: ensure that the I2C BUS is idle
26 + * before switching to master mode and attempting a Start cycle
27 + */
28 + result = i2c_imx_bus_busy(i2c_imx, 0);
29 + if (result)
30 + goto out;
31 +
32 result = pm_runtime_get_sync(i2c_imx->adapter.dev.parent);
33 if (result < 0)
34 goto out;
35 @@ -1100,7 +1108,7 @@ static int i2c_imx_probe(struct platform_device *pdev)
36 }
37
38 /* Request IRQ */
39 - ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, 0,
40 + ret = devm_request_irq(&pdev->dev, irq, i2c_imx_isr, IRQF_SHARED,
41 pdev->name, i2c_imx);
42 if (ret) {
43 dev_err(&pdev->dev, "can't claim irq %d\n", irq);
44 diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
45 index 9c4ac26c..3c27ab84 100644
46 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c
47 +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
48 @@ -74,6 +74,7 @@ struct pca954x {
49 u8 last_chan; /* last register value */
50 u8 deselect;
51 struct i2c_client *client;
52 + u8 disable_mux; /* do not disable mux if val not 0 */
53 };
54
55 /* Provide specs for the PCA954x types we know about */
56 @@ -196,6 +197,13 @@ static int pca954x_deselect_mux(struct i2c_mux_core *muxc, u32 chan)
57 if (!(data->deselect & (1 << chan)))
58 return 0;
59
60 +#ifdef CONFIG_ARCH_LAYERSCAPE
61 + if (data->disable_mux != 0)
62 + data->last_chan = data->chip->nchans;
63 + else
64 + data->last_chan = 0;
65 + return pca954x_reg_write(muxc->parent, client, data->disable_mux);
66 +#endif
67 /* Deselect active channel */
68 data->last_chan = 0;
69 return pca954x_reg_write(muxc->parent, client, data->last_chan);
70 @@ -228,6 +236,28 @@ static int pca954x_probe(struct i2c_client *client,
71 return -ENOMEM;
72 data = i2c_mux_priv(muxc);
73
74 +#ifdef CONFIG_ARCH_LAYERSCAPE
75 + /* The point here is that you must not disable a mux if there
76 + * are no pullups on the input or you mess up the I2C. This
77 + * needs to be put into the DTS really as the kernel cannot
78 + * know this otherwise.
79 + */
80 + match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev);
81 + if (match)
82 + data->chip = of_device_get_match_data(&client->dev);
83 + else
84 + data->chip = &chips[id->driver_data];
85 +
86 + data->disable_mux = of_node &&
87 + of_property_read_bool(of_node, "i2c-mux-never-disable") &&
88 + data->chip->muxtype == pca954x_ismux ?
89 + data->chip->enable : 0;
90 + /* force the first selection */
91 + if (data->disable_mux != 0)
92 + data->last_chan = data->chip->nchans;
93 + else
94 + data->last_chan = 0;
95 +#endif
96 i2c_set_clientdata(client, muxc);
97 data->client = client;
98
99 @@ -240,11 +270,16 @@ static int pca954x_probe(struct i2c_client *client,
100 * that the mux is in fact present. This also
101 * initializes the mux to disconnected state.
102 */
103 +#ifdef CONFIG_ARCH_LAYERSCAPE
104 + if (i2c_smbus_write_byte(client, data->disable_mux) < 0) {
105 +#else
106 if (i2c_smbus_write_byte(client, 0) < 0) {
107 +#endif
108 dev_warn(&client->dev, "probe failed\n");
109 return -ENODEV;
110 }
111
112 +#ifndef CONFIG_ARCH_LAYERSCAPE
113 match = of_match_device(of_match_ptr(pca954x_of_match), &client->dev);
114 if (match)
115 data->chip = of_device_get_match_data(&client->dev);
116 @@ -252,6 +287,7 @@ static int pca954x_probe(struct i2c_client *client,
117 data->chip = &chips[id->driver_data];
118
119 data->last_chan = 0; /* force the first selection */
120 +#endif
121
122 idle_disconnect_dt = of_node &&
123 of_property_read_bool(of_node, "i2c-mux-idle-disconnect");
124 @@ -312,6 +348,13 @@ static int pca954x_resume(struct device *dev)
125 struct i2c_mux_core *muxc = i2c_get_clientdata(client);
126 struct pca954x *data = i2c_mux_priv(muxc);
127
128 +#ifdef CONFIG_ARCH_LAYERSCAPE
129 + if (data->disable_mux != 0)
130 + data->last_chan = data->chip->nchans;
131 + else
132 + data->last_chan = 0;
133 + return i2c_smbus_write_byte(client, data->disable_mux);
134 +#endif
135 data->last_chan = 0;
136 return i2c_smbus_write_byte(client, 0);
137 }
138 --
139 2.14.1
140