layerscape: add ls2088ardb device support
[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 diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c
25 index acfcef3..386f86f 100644
26 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c
27 +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c
28 @@ -63,6 +63,7 @@ struct pca954x {
29 struct i2c_adapter *virt_adaps[PCA954X_MAX_NCHANS];
30
31 u8 last_chan; /* last register value */
32 + u8 disable_mux; /* do not disable mux if val not 0 */
33 };
34
35 struct chip_desc {
36 @@ -174,6 +175,13 @@ static int pca954x_deselect_mux(struct i2c_adapter *adap,
37 {
38 struct pca954x *data = i2c_get_clientdata(client);
39
40 +#ifdef CONFIG_ARCH_LAYERSCAPE
41 + if (data->disable_mux != 0)
42 + data->last_chan = chips[data->type].nchans;
43 + else
44 + data->last_chan = 0;
45 + return pca954x_reg_write(adap, client, data->disable_mux);
46 +#endif
47 /* Deselect active channel */
48 data->last_chan = 0;
49 return pca954x_reg_write(adap, client, data->last_chan);
50 @@ -201,6 +209,23 @@ static int pca954x_probe(struct i2c_client *client,
51 if (!data)
52 return -ENOMEM;
53
54 +#ifdef CONFIG_ARCH_LAYERSCAPE
55 + /* The point here is that you must not disable a mux if there
56 + * are no pullups on the input or you mess up the I2C. This
57 + * needs to be put into the DTS really as the kernel cannot
58 + * know this otherwise.
59 + */
60 + data->type = id->driver_data;
61 + data->disable_mux = of_node &&
62 + of_property_read_bool(of_node, "i2c-mux-never-disable") &&
63 + chips[data->type].muxtype == pca954x_ismux ?
64 + chips[data->type].enable : 0;
65 + /* force the first selection */
66 + if (data->disable_mux != 0)
67 + data->last_chan = chips[data->type].nchans;
68 + else
69 + data->last_chan = 0;
70 +#endif
71 i2c_set_clientdata(client, data);
72
73 /* Get the mux out of reset if a reset GPIO is specified. */
74 @@ -212,13 +237,19 @@ static int pca954x_probe(struct i2c_client *client,
75 * that the mux is in fact present. This also
76 * initializes the mux to disconnected state.
77 */
78 +#ifdef CONFIG_ARCH_LAYERSCAPE
79 + if (i2c_smbus_write_byte(client, data->disable_mux) < 0) {
80 +#else
81 if (i2c_smbus_write_byte(client, 0) < 0) {
82 +#endif
83 dev_warn(&client->dev, "probe failed\n");
84 return -ENODEV;
85 }
86
87 +#ifndef CONFIG_ARCH_LAYERSCAPE
88 data->type = id->driver_data;
89 data->last_chan = 0; /* force the first selection */
90 +#endif
91
92 idle_disconnect_dt = of_node &&
93 of_property_read_bool(of_node, "i2c-mux-idle-disconnect");
94 @@ -289,6 +320,13 @@ static int pca954x_resume(struct device *dev)
95 struct i2c_client *client = to_i2c_client(dev);
96 struct pca954x *data = i2c_get_clientdata(client);
97
98 +#ifdef CONFIG_ARCH_LAYERSCAPE
99 + if (data->disable_mux != 0)
100 + data->last_chan = chips[data->type].nchans;
101 + else
102 + data->last_chan = 0;
103 + return i2c_smbus_write_byte(client, data->disable_mux);
104 +#endif
105 data->last_chan = 0;
106 return i2c_smbus_write_byte(client, 0);
107 }
108 --
109 1.7.9.5
110