kernel: bump to 4.4.40
[openwrt/openwrt.git] / target / linux / layerscape / patches-4.4 / 8233-i2c-pca954x-Add-option-to-skip-disabling-PCA954x-Mux.patch
1 From a4be9046c3a3fc39a06089553df8cc19a2abd814 Mon Sep 17 00:00:00 2001
2 From: Priyanka Jain <Priyanka.Jain@freescale.com>
3 Date: Tue, 3 Nov 2015 11:25:24 +0530
4 Subject: [PATCH 233/238] i2c: pca954x: Add option to skip disabling PCA954x
5 Mux device
6
7 On some Layerscape boards like LS2085ARDB/LS2080ARDB,
8 input pull-up resistors on PCA954x Mux device are
9 missing on board. So, if mux are disabled after powered-on,
10 input lines will float leading to incorrect functionality.
11
12 Hence, PCA954x Mux device should never be turned-off after
13 power-on.
14
15 Add option to skip disabling PCA954x Mux device
16 if device tree contians "i2c-mux-never-disable" property
17 for pca954x device node.
18
19 Signed-off-by: Priyanka Jain <Priyanka.Jain@freescale.com>
20 ---
21 drivers/i2c/muxes/i2c-mux-pca954x.c | 38 +++++++++++++++++++++++++++++++++++
22 1 file changed, 38 insertions(+)
23
24 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c
25 +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
26 @@ -63,6 +63,7 @@ struct pca954x {
27 struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS];
28
29 u8 last_chan; /* last register value */
30 + u8 disable_mux; /* do not disable mux if val not 0 */
31 };
32
33 struct chip_desc {
34 @@ -174,6 +175,13 @@ static int pca954x_deselect_mux(struct i
35 {
36 struct pca954x *data = i2c_get_clientdata(client);
37
38 +#ifdef CONFIG_ARCH_LAYERSCAPE
39 + if (data->disable_mux != 0)
40 + data->last_chan = chips[data->type].nchans;
41 + else
42 + data->last_chan = 0;
43 + return pca954x_reg_write(adap, client, data->disable_mux);
44 +#endif
45 /* Deselect active channel */
46 data->last_chan = 0;
47 return pca954x_reg_write(adap, client, data->last_chan);
48 @@ -201,6 +209,23 @@ static int pca954x_probe(struct i2c_clie
49 if (!data)
50 return -ENOMEM;
51
52 +#ifdef CONFIG_ARCH_LAYERSCAPE
53 + /* The point here is that you must not disable a mux if there
54 + * are no pullups on the input or you mess up the I2C. This
55 + * needs to be put into the DTS really as the kernel cannot
56 + * know this otherwise.
57 + */
58 + data->type = id->driver_data;
59 + data->disable_mux = of_node &&
60 + of_property_read_bool(of_node, "i2c-mux-never-disable") &&
61 + chips[data->type].muxtype == pca954x_ismux ?
62 + chips[data->type].enable : 0;
63 + /* force the first selection */
64 + if (data->disable_mux != 0)
65 + data->last_chan = chips[data->type].nchans;
66 + else
67 + data->last_chan = 0;
68 +#endif
69 i2c_set_clientdata(client, data);
70
71 /* Get the mux out of reset if a reset GPIO is specified. */
72 @@ -212,13 +237,19 @@ static int pca954x_probe(struct i2c_clie
73 * that the mux is in fact present. This also
74 * initializes the mux to disconnected state.
75 */
76 +#ifdef CONFIG_ARCH_LAYERSCAPE
77 + if (i2c_smbus_write_byte(client, data->disable_mux) < 0) {
78 +#else
79 if (i2c_smbus_write_byte(client, 0) < 0) {
80 +#endif
81 dev_warn(&client->dev, "probe failed\n");
82 return -ENODEV;
83 }
84
85 +#ifndef CONFIG_ARCH_LAYERSCAPE
86 data->type = id->driver_data;
87 data->last_chan = 0; /* force the first selection */
88 +#endif
89
90 idle_disconnect_dt = of_node &&
91 of_property_read_bool(of_node, "i2c-mux-idle-disconnect");
92 @@ -289,6 +320,13 @@ static int pca954x_resume(struct device
93 struct i2c_client *client = to_i2c_client(dev);
94 struct pca954x *data = i2c_get_clientdata(client);
95
96 +#ifdef CONFIG_ARCH_LAYERSCAPE
97 + if (data->disable_mux != 0)
98 + data->last_chan = chips[data->type].nchans;
99 + else
100 + data->last_chan = 0;
101 + return i2c_smbus_write_byte(client, data->disable_mux);
102 +#endif
103 data->last_chan = 0;
104 return i2c_smbus_write_byte(client, 0);
105 }