blob: d975bf617cd6d182f93e7476059b9f26583335f4 [file] [log] [blame]
Jan Kundrát25016432019-03-04 21:40:58 +01001diff --git a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
2index 625a22e2f211..7872d61d23e4 100644
3--- a/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
4+++ b/Documentation/devicetree/bindings/pinctrl/pinctrl-mcp23s08.txt
5@@ -144,3 +144,38 @@ gpio21: gpio@21 {
6 bias-pull-up;
7 };
8 };
9+
10+Line naming
11+===========
12+
13+Because several gpio_chip instances are hidden below a single device tree
14+node, it is necessary to split the names into several child nodes. Ensure
15+that the configured addresses match those in the microchip,spi-present-mask:
16+
17+gpio@0 {
18+ compatible = "microchip,mcp23s17";
19+ gpio-controller;
20+ #gpio-cells = <2>;
21+ /* this bitmask has bits #0 (0x01) and #2 (0x04) set */
22+ spi-present-mask = <0x05>;
23+ reg = <0>;
24+ spi-max-frequency = <1000000>;
25+
26+ gpio-bank@1 {
27+ address = <0>;
28+ gpio-line-names =
29+ "GPA0",
30+ "GPA1",
31+ ...
32+ "GPA7",
33+ "GPB0",
34+ "GPB1",
35+ ...
36+ "GPB7";
37+ };
38+
39+ gpio-bank@2 {
40+ address = <2>;
41+ gpio-line-names = ...
42+ };
43+};
44diff --git a/Documentation/devicetree/bindings/spi/spi-orion.txt b/Documentation/devicetree/bindings/spi/spi-orion.txt
45index 8434a65fc12a..ed35cba1bc33 100644
46--- a/Documentation/devicetree/bindings/spi/spi-orion.txt
47+++ b/Documentation/devicetree/bindings/spi/spi-orion.txt
48@@ -29,6 +29,10 @@ Optional properties:
49 used, the name must be "core", and "axi" (the latter
50 is only for Armada 7K/8K).
51
52+Optional properties of child nodes (SPI slave devices):
53+- linux,spi-wdelay : If present and non-zero, specifies a delay in
54+ microseconds between words transferred over the SPI bus.
55+
56
57 Example:
58 spi@10600 {
59@@ -77,3 +81,19 @@ are used in the default indirect (PIO) mode):
60 For further information on the MBus bindings, please see the MBus
61 DT documentation:
62 Documentation/devicetree/bindings/bus/mvebu-mbus.txt
63+
64+Example of a per-child inter-word delay:
65+
66+ spi0: spi@10600 {
67+ /* ... */
68+
69+ some_slave_device@2 {
70+ reg = <2>;
71+ compatible = "something";
72+ /* ... */
73+
74+ /* Wait 3 microseconds between all words within all
75+ SPI transactions */
76+ linux,spi-wdelay = /bits/ 16 <3>;
77+ };
78+ };
79diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
80index a5a95ea5b81a..469374ded7ae 100644
81--- a/drivers/i2c/busses/i2c-mv64xxx.c
82+++ b/drivers/i2c/busses/i2c-mv64xxx.c
83@@ -317,6 +317,14 @@ mv64xxx_i2c_fsm(struct mv64xxx_i2c_data *drv_data, u32 status)
84 drv_data->rc = -ENXIO;
85 break;
86
87+ case MV64XXX_I2C_STATUS_BUS_ERR: /* 0x00 */
88+ dev_warn(&drv_data->adapter.dev,
89+ "bus error: slave has driven SDA/SCL unexpectedly\n");
90+ drv_data->action = MV64XXX_I2C_ACTION_SEND_STOP;
91+ mv64xxx_i2c_hw_init(drv_data);
92+ drv_data->rc = -EIO;
93+ break;
94+
95 default:
96 dev_err(&drv_data->adapter.dev,
97 "mv64xxx_i2c_fsm: Ctlr Error -- state: 0x%x, "
98diff --git a/drivers/leds/leds-tlc591xx.c b/drivers/leds/leds-tlc591xx.c
99index f5357f6d9e58..efbe9c83c514 100644
100--- a/drivers/leds/leds-tlc591xx.c
101+++ b/drivers/leds/leds-tlc591xx.c
102@@ -42,6 +42,9 @@
103
104 #define ldev_to_led(c) container_of(c, struct tlc591xx_led, ldev)
105
106+#define TLC591XX_RESET_BYTE_0 0xa5
107+#define TLC591XX_RESET_BYTE_1 0x5a
108+
109 struct tlc591xx_led {
110 bool active;
111 unsigned int led_no;
112@@ -53,21 +56,25 @@ struct tlc591xx_priv {
113 struct tlc591xx_led leds[TLC591XX_MAX_LEDS];
114 struct regmap *regmap;
115 unsigned int reg_ledout_offset;
116+ struct i2c_client *swrst_client;
117 };
118
119 struct tlc591xx {
120 unsigned int max_leds;
121 unsigned int reg_ledout_offset;
122+ u8 swrst_addr;
123 };
124
125 static const struct tlc591xx tlc59116 = {
126 .max_leds = 16,
127 .reg_ledout_offset = 0x14,
128+ .swrst_addr = 0x6b,
129 };
130
131 static const struct tlc591xx tlc59108 = {
132 .max_leds = 8,
133 .reg_ledout_offset = 0x0c,
134+ .swrst_addr = 0x4b,
135 };
136
137 static int
138@@ -140,6 +147,8 @@ tlc591xx_destroy_devices(struct tlc591xx_priv *priv, unsigned int j)
139 if (priv->leds[i].active)
140 led_classdev_unregister(&priv->leds[i].ldev);
141 }
142+
143+ i2c_unregister_device(priv->swrst_client);
144 }
145
146 static int
147@@ -245,6 +254,19 @@ tlc591xx_probe(struct i2c_client *client,
148 priv->leds[reg].ldev.default_trigger =
149 of_get_property(child, "linux,default-trigger", NULL);
150 }
151+
152+ priv->swrst_client = i2c_new_dummy(client->adapter, tlc591xx->swrst_addr);
153+ if (priv->swrst_client) {
154+ err = i2c_smbus_write_byte_data(priv->swrst_client,
155+ TLC591XX_RESET_BYTE_0, TLC591XX_RESET_BYTE_1);
156+ if (err) {
157+ dev_warn(dev, "SW reset failed\n");
158+ }
159+ } else {
160+ dev_info(dev, "Skipping reset: address %02x already used\n",
161+ tlc591xx->swrst_addr);
162+ }
163+
164 return tlc591xx_configure(dev, priv, tlc591xx);
165 }
166
167diff --git a/drivers/pinctrl/pinctrl-mcp23s08.c b/drivers/pinctrl/pinctrl-mcp23s08.c
Jan Kundrát549db872019-03-05 12:23:25 +0100168index 98905d4a79ca..64c67478f781 100644
Jan Kundrát25016432019-03-04 21:40:58 +0100169--- a/drivers/pinctrl/pinctrl-mcp23s08.c
170+++ b/drivers/pinctrl/pinctrl-mcp23s08.c
171@@ -16,6 +16,7 @@
172 #include <linux/pinctrl/pinctrl.h>
173 #include <linux/pinctrl/pinconf.h>
174 #include <linux/pinctrl/pinconf-generic.h>
175+#include "../gpio/gpiolib.h"
176
177 /*
178 * MCP types supported by driver
Jan Kundrát549db872019-03-05 12:23:25 +0100179@@ -68,6 +69,7 @@ struct mcp23s08 {
180 struct mutex lock;
181
182 struct gpio_chip chip;
183+ struct irq_chip irq_chip;
184
185 struct regmap *regmap;
186 struct device *dev;
187@@ -265,7 +267,6 @@ static int mcp_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
Jan Kundrát25016432019-03-04 21:40:58 +0100188 status = (data & BIT(pin)) ? 1 : 0;
189 break;
190 default:
191- dev_err(mcp->dev, "Invalid config param %04x\n", param);
192 return -ENOTSUPP;
193 }
194
Jan Kundrát549db872019-03-05 12:23:25 +0100195@@ -292,7 +293,7 @@ static int mcp_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
Jan Kundrát25016432019-03-04 21:40:58 +0100196 ret = mcp_set_bit(mcp, MCP_GPPU, pin, arg);
197 break;
198 default:
199- dev_err(mcp->dev, "Invalid config param %04x\n", param);
200+ dev_dbg(mcp->dev, "Invalid config param %04x\n", param);
201 return -ENOTSUPP;
202 }
203 }
Jan Kundrát549db872019-03-05 12:23:25 +0100204@@ -607,15 +608,6 @@ static void mcp23s08_irq_bus_unlock(struct irq_data *data)
205 mutex_unlock(&mcp->lock);
206 }
207
208-static struct irq_chip mcp23s08_irq_chip = {
209- .name = "gpio-mcp23xxx",
210- .irq_mask = mcp23s08_irq_mask,
211- .irq_unmask = mcp23s08_irq_unmask,
212- .irq_set_type = mcp23s08_irq_set_type,
213- .irq_bus_lock = mcp23s08_irq_bus_lock,
214- .irq_bus_sync_unlock = mcp23s08_irq_bus_unlock,
215-};
216-
217 static int mcp23s08_irq_setup(struct mcp23s08 *mcp)
218 {
219 struct gpio_chip *chip = &mcp->chip;
220@@ -645,7 +637,7 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
221 int err;
222
223 err = gpiochip_irqchip_add_nested(chip,
224- &mcp23s08_irq_chip,
225+ &mcp->irq_chip,
226 0,
227 handle_simple_irq,
228 IRQ_TYPE_NONE);
229@@ -656,7 +648,7 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
230 }
231
232 gpiochip_set_nested_irqchip(chip,
233- &mcp23s08_irq_chip,
234+ &mcp->irq_chip,
235 mcp->irq);
236
237 return 0;
238@@ -664,115 +656,6 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
Jan Kundrát25016432019-03-04 21:40:58 +0100239
240 /*----------------------------------------------------------------------*/
241
242-#ifdef CONFIG_DEBUG_FS
243-
244-#include <linux/seq_file.h>
245-
246-/*
247- * This compares the chip's registers with the register
248- * cache and corrects any incorrectly set register. This
249- * can be used to fix state for MCP23xxx, that temporary
250- * lost its power supply.
251- */
252-#define MCP23S08_CONFIG_REGS 7
253-static int __check_mcp23s08_reg_cache(struct mcp23s08 *mcp)
254-{
255- int cached[MCP23S08_CONFIG_REGS];
256- int err = 0, i;
257-
258- /* read cached config registers */
259- for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
260- err = mcp_read(mcp, i, &cached[i]);
261- if (err)
262- goto out;
263- }
264-
265- regcache_cache_bypass(mcp->regmap, true);
266-
267- for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
268- int uncached;
269- err = mcp_read(mcp, i, &uncached);
270- if (err)
271- goto out;
272-
273- if (uncached != cached[i]) {
274- dev_err(mcp->dev, "restoring reg 0x%02x from 0x%04x to 0x%04x (power-loss?)\n",
275- i, uncached, cached[i]);
276- mcp_write(mcp, i, cached[i]);
277- }
278- }
279-
280-out:
281- if (err)
282- dev_err(mcp->dev, "read error: reg=%02x, err=%d", i, err);
283- regcache_cache_bypass(mcp->regmap, false);
284- return err;
285-}
286-
287-/*
288- * This shows more info than the generic gpio dump code:
289- * pullups, deglitching, open drain drive.
290- */
291-static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
292-{
293- struct mcp23s08 *mcp;
294- char bank;
295- int t;
296- unsigned mask;
297- int iodir, gpio, gppu;
298-
299- mcp = gpiochip_get_data(chip);
300-
301- /* NOTE: we only handle one bank for now ... */
302- bank = '0' + ((mcp->addr >> 1) & 0x7);
303-
304- mutex_lock(&mcp->lock);
305-
306- t = __check_mcp23s08_reg_cache(mcp);
307- if (t) {
308- seq_printf(s, " I/O Error\n");
309- goto done;
310- }
311- t = mcp_read(mcp, MCP_IODIR, &iodir);
312- if (t) {
313- seq_printf(s, " I/O Error\n");
314- goto done;
315- }
316- t = mcp_read(mcp, MCP_GPIO, &gpio);
317- if (t) {
318- seq_printf(s, " I/O Error\n");
319- goto done;
320- }
321- t = mcp_read(mcp, MCP_GPPU, &gppu);
322- if (t) {
323- seq_printf(s, " I/O Error\n");
324- goto done;
325- }
326-
327- for (t = 0, mask = BIT(0); t < chip->ngpio; t++, mask <<= 1) {
328- const char *label;
329-
330- label = gpiochip_is_requested(chip, t);
331- if (!label)
332- continue;
333-
334- seq_printf(s, " gpio-%-3d P%c.%d (%-12s) %s %s %s\n",
335- chip->base + t, bank, t, label,
336- (iodir & mask) ? "in " : "out",
337- (gpio & mask) ? "hi" : "lo",
338- (gppu & mask) ? "up" : " ");
339- /* NOTE: ignoring the irq-related registers */
340- }
341-done:
342- mutex_unlock(&mcp->lock);
343-}
344-
345-#else
346-#define mcp23s08_dbg_show NULL
347-#endif
348-
349-/*----------------------------------------------------------------------*/
350-
351 static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
352 void *data, unsigned addr, unsigned type,
353 unsigned int base, int cs)
Jan Kundrát549db872019-03-05 12:23:25 +0100354@@ -793,7 +676,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
Jan Kundrát25016432019-03-04 21:40:58 +0100355 mcp->chip.get = mcp23s08_get;
356 mcp->chip.direction_output = mcp23s08_direction_output;
357 mcp->chip.set = mcp23s08_set;
358- mcp->chip.dbg_show = mcp23s08_dbg_show;
359 #ifdef CONFIG_OF_GPIO
360 mcp->chip.of_gpio_n_cells = 2;
361 mcp->chip.of_node = dev->of_node;
Jan Kundrát549db872019-03-05 12:23:25 +0100362@@ -1047,6 +929,13 @@ static int mcp230xx_probe(struct i2c_client *client,
363 return -ENOMEM;
364
365 mcp->irq = client->irq;
366+ mcp->irq_chip.name = dev_name(&client->dev);
367+ mcp->irq_chip.irq_mask = mcp23s08_irq_mask;
368+ mcp->irq_chip.irq_unmask = mcp23s08_irq_unmask;
369+ mcp->irq_chip.irq_set_type = mcp23s08_irq_set_type;
370+ mcp->irq_chip.irq_bus_lock = mcp23s08_irq_bus_lock;
371+ mcp->irq_chip.irq_bus_sync_unlock = mcp23s08_irq_bus_unlock;
372+
373 status = mcp23s08_probe_one(mcp, &client->dev, client, client->addr,
374 id->driver_data, pdata->base, 0);
375 if (status)
376@@ -1104,6 +993,7 @@ static int mcp23s08_probe(struct spi_device *spi)
Jan Kundrát25016432019-03-04 21:40:58 +0100377 int status, type;
378 unsigned ngpio = 0;
379 const struct of_device_id *match;
380+ struct device_node *np;
381
382 match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev);
383 if (match)
Jan Kundrát549db872019-03-05 12:23:25 +0100384@@ -1144,8 +1034,7 @@ static int mcp23s08_probe(struct spi_device *spi)
385 return -ENODEV;
386
387 data = devm_kzalloc(&spi->dev,
388- sizeof(*data) + chips * sizeof(struct mcp23s08),
389- GFP_KERNEL);
390+ struct_size(data, chip, chips), GFP_KERNEL);
391 if (!data)
392 return -ENOMEM;
393
394@@ -1157,6 +1046,13 @@ static int mcp23s08_probe(struct spi_device *spi)
395 chips--;
396 data->mcp[addr] = &data->chip[chips];
397 data->mcp[addr]->irq = spi->irq;
398+ data->mcp[addr]->irq_chip.name = dev_name(&spi->dev);
399+ data->mcp[addr]->irq_chip.irq_mask = mcp23s08_irq_mask;
400+ data->mcp[addr]->irq_chip.irq_unmask = mcp23s08_irq_unmask;
401+ data->mcp[addr]->irq_chip.irq_set_type = mcp23s08_irq_set_type;
402+ data->mcp[addr]->irq_chip.irq_bus_lock = mcp23s08_irq_bus_lock;
403+ data->mcp[addr]->irq_chip.irq_bus_sync_unlock =
404+ mcp23s08_irq_bus_unlock;
405 status = mcp23s08_probe_one(data->mcp[addr], &spi->dev, spi,
406 0x40 | (addr << 1), type,
407 pdata->base, addr);
408@@ -1166,6 +1062,16 @@ static int mcp23s08_probe(struct spi_device *spi)
Jan Kundrát25016432019-03-04 21:40:58 +0100409 if (pdata->base != -1)
410 pdata->base += data->mcp[addr]->chip.ngpio;
411 ngpio += data->mcp[addr]->chip.ngpio;
412+
413+ for_each_available_child_of_node(spi->dev.of_node, np) {
414+ u32 chip_addr;
415+ status = of_property_read_u32(np, "address", &chip_addr);
416+ if (status)
417+ continue;
418+ if (chip_addr != addr)
419+ continue;
420+ devprop_gpiochip_set_names(&data->mcp[addr]->chip, of_fwnode_handle(np));
421+ }
422 }
423 data->ngpio = ngpio;
424
425diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
Jan Kundrát549db872019-03-05 12:23:25 +0100426index 7f280567093e..1c4ec4452700 100644
Jan Kundrát25016432019-03-04 21:40:58 +0100427--- a/drivers/spi/spi-orion.c
428+++ b/drivers/spi/spi-orion.c
429@@ -93,6 +93,7 @@ struct orion_direct_acc {
430
431 struct orion_child_options {
432 struct orion_direct_acc direct_access;
433+ u16 word_delay;
434 };
435
436 struct orion_spi {
Jan Kundrát549db872019-03-05 12:23:25 +0100437@@ -433,7 +434,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
Jan Kundrát25016432019-03-04 21:40:58 +0100438 int cs = spi->chip_select;
Jan Kundrát549db872019-03-05 12:23:25 +0100439 void __iomem *vaddr;
Jan Kundrát25016432019-03-04 21:40:58 +0100440
441- word_len = spi->bits_per_word;
442+ word_len = xfer->bits_per_word;
443 count = xfer->len;
444
445 orion_spi = spi_master_get_devdata(spi->master);
446@@ -470,6 +471,8 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
447 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
448 goto out;
449 count--;
450+ if (orion_spi->child[cs].word_delay)
451+ udelay(orion_spi->child[cs].word_delay);
452 } while (count);
453 } else if (word_len == 16) {
454 const u16 *tx = xfer->tx_buf;
455@@ -478,6 +481,8 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
456 do {
457 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
458 goto out;
459+ if (orion_spi->child[cs].word_delay)
460+ udelay(orion_spi->child[cs].word_delay);
461 count -= 2;
462 } while (count);
463 }
Jan Kundrát549db872019-03-05 12:23:25 +0100464@@ -734,6 +739,12 @@ static int orion_spi_probe(struct platform_device *pdev)
Jan Kundrát25016432019-03-04 21:40:58 +0100465 }
466 }
467
468+ spi->child[cs].word_delay = 0;
469+ if (!of_property_read_u16(np, "linux,spi-wdelay",
470+ &spi->child[cs].word_delay))
471+ dev_info(&pdev->dev, "%pOF: %dus delay between words\n",
472+ np, spi->child[cs].word_delay);
473+
474 /*
475 * Check if an address is configured for this SPI device. If
476 * not, the MBus mapping via the 'ranges' property in the 'soc'
Jan Kundrát549db872019-03-05 12:23:25 +0100477@@ -745,6 +756,12 @@ static int orion_spi_probe(struct platform_device *pdev)
Jan Kundrát25016432019-03-04 21:40:58 +0100478 if (status)
479 continue;
480
481+ if (spi->child[cs].word_delay) {
482+ dev_warn(&pdev->dev,
483+ "%pOF linux,spi-wdelay takes preference over a direct-mode", np);
484+ continue;
485+ }
486+
487 /*
488 * Only map one page for direct access. This is enough for the
489 * simple TX transfer which only writes to the first word.
490diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
Jan Kundrát549db872019-03-05 12:23:25 +0100491index 9a7def7c3237..1c618bd5b55c 100644
Jan Kundrát25016432019-03-04 21:40:58 +0100492--- a/drivers/spi/spi.c
493+++ b/drivers/spi/spi.c
Jan Kundrát549db872019-03-05 12:23:25 +0100494@@ -75,6 +75,7 @@ static ssize_t driver_override_store(struct device *dev,
495 const char *end = memchr(buf, '\n', count);
496 const size_t len = end ? end - buf : count;
497 const char *driver_override, *old;
Jan Kundrát25016432019-03-04 21:40:58 +0100498+ int ret;
Jan Kundrát549db872019-03-05 12:23:25 +0100499
500 /* We need to keep extra room for a newline when displaying value */
501 if (len >= (PAGE_SIZE - 1))
502@@ -96,6 +97,12 @@ static ssize_t driver_override_store(struct device *dev,
503 device_unlock(dev);
504 kfree(old);
505
Jan Kundrát25016432019-03-04 21:40:58 +0100506+ /* Attach device to new driver if it's not already attached */
507+ ret = device_attach(dev);
508+ if (ret < 0 && ret != -EPROBE_DEFER)
509+ dev_warn(dev, "device attach to '%s' failed (%d)\n",
510+ spi->driver_override, ret);
511+
Jan Kundrát549db872019-03-05 12:23:25 +0100512 return count;
513 }
Jan Kundrát25016432019-03-04 21:40:58 +0100514