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