blob: 81dbd2fae51334f38fe75ce03e7d9dfe77d8d7af [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
168index cf73a403d22d..250e5e536a9c 100644
169--- 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
179@@ -265,7 +266,6 @@ static int mcp_pinconf_get(struct pinctrl_dev *pctldev, unsigned int pin,
180 status = (data & BIT(pin)) ? 1 : 0;
181 break;
182 default:
183- dev_err(mcp->dev, "Invalid config param %04x\n", param);
184 return -ENOTSUPP;
185 }
186
187@@ -292,7 +292,7 @@ static int mcp_pinconf_set(struct pinctrl_dev *pctldev, unsigned int pin,
188 ret = mcp_set_bit(mcp, MCP_GPPU, pin, arg);
189 break;
190 default:
191- dev_err(mcp->dev, "Invalid config param %04x\n", param);
192+ dev_dbg(mcp->dev, "Invalid config param %04x\n", param);
193 return -ENOTSUPP;
194 }
195 }
196@@ -664,115 +664,6 @@ static int mcp23s08_irqchip_setup(struct mcp23s08 *mcp)
197
198 /*----------------------------------------------------------------------*/
199
200-#ifdef CONFIG_DEBUG_FS
201-
202-#include <linux/seq_file.h>
203-
204-/*
205- * This compares the chip's registers with the register
206- * cache and corrects any incorrectly set register. This
207- * can be used to fix state for MCP23xxx, that temporary
208- * lost its power supply.
209- */
210-#define MCP23S08_CONFIG_REGS 7
211-static int __check_mcp23s08_reg_cache(struct mcp23s08 *mcp)
212-{
213- int cached[MCP23S08_CONFIG_REGS];
214- int err = 0, i;
215-
216- /* read cached config registers */
217- for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
218- err = mcp_read(mcp, i, &cached[i]);
219- if (err)
220- goto out;
221- }
222-
223- regcache_cache_bypass(mcp->regmap, true);
224-
225- for (i = 0; i < MCP23S08_CONFIG_REGS; i++) {
226- int uncached;
227- err = mcp_read(mcp, i, &uncached);
228- if (err)
229- goto out;
230-
231- if (uncached != cached[i]) {
232- dev_err(mcp->dev, "restoring reg 0x%02x from 0x%04x to 0x%04x (power-loss?)\n",
233- i, uncached, cached[i]);
234- mcp_write(mcp, i, cached[i]);
235- }
236- }
237-
238-out:
239- if (err)
240- dev_err(mcp->dev, "read error: reg=%02x, err=%d", i, err);
241- regcache_cache_bypass(mcp->regmap, false);
242- return err;
243-}
244-
245-/*
246- * This shows more info than the generic gpio dump code:
247- * pullups, deglitching, open drain drive.
248- */
249-static void mcp23s08_dbg_show(struct seq_file *s, struct gpio_chip *chip)
250-{
251- struct mcp23s08 *mcp;
252- char bank;
253- int t;
254- unsigned mask;
255- int iodir, gpio, gppu;
256-
257- mcp = gpiochip_get_data(chip);
258-
259- /* NOTE: we only handle one bank for now ... */
260- bank = '0' + ((mcp->addr >> 1) & 0x7);
261-
262- mutex_lock(&mcp->lock);
263-
264- t = __check_mcp23s08_reg_cache(mcp);
265- if (t) {
266- seq_printf(s, " I/O Error\n");
267- goto done;
268- }
269- t = mcp_read(mcp, MCP_IODIR, &iodir);
270- if (t) {
271- seq_printf(s, " I/O Error\n");
272- goto done;
273- }
274- t = mcp_read(mcp, MCP_GPIO, &gpio);
275- if (t) {
276- seq_printf(s, " I/O Error\n");
277- goto done;
278- }
279- t = mcp_read(mcp, MCP_GPPU, &gppu);
280- if (t) {
281- seq_printf(s, " I/O Error\n");
282- goto done;
283- }
284-
285- for (t = 0, mask = BIT(0); t < chip->ngpio; t++, mask <<= 1) {
286- const char *label;
287-
288- label = gpiochip_is_requested(chip, t);
289- if (!label)
290- continue;
291-
292- seq_printf(s, " gpio-%-3d P%c.%d (%-12s) %s %s %s\n",
293- chip->base + t, bank, t, label,
294- (iodir & mask) ? "in " : "out",
295- (gpio & mask) ? "hi" : "lo",
296- (gppu & mask) ? "up" : " ");
297- /* NOTE: ignoring the irq-related registers */
298- }
299-done:
300- mutex_unlock(&mcp->lock);
301-}
302-
303-#else
304-#define mcp23s08_dbg_show NULL
305-#endif
306-
307-/*----------------------------------------------------------------------*/
308-
309 static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
310 void *data, unsigned addr, unsigned type,
311 unsigned int base, int cs)
312@@ -793,7 +684,6 @@ static int mcp23s08_probe_one(struct mcp23s08 *mcp, struct device *dev,
313 mcp->chip.get = mcp23s08_get;
314 mcp->chip.direction_output = mcp23s08_direction_output;
315 mcp->chip.set = mcp23s08_set;
316- mcp->chip.dbg_show = mcp23s08_dbg_show;
317 #ifdef CONFIG_OF_GPIO
318 mcp->chip.of_gpio_n_cells = 2;
319 mcp->chip.of_node = dev->of_node;
320@@ -1099,6 +989,7 @@ static int mcp23s08_probe(struct spi_device *spi)
321 int status, type;
322 unsigned ngpio = 0;
323 const struct of_device_id *match;
324+ struct device_node *np;
325
326 match = of_match_device(of_match_ptr(mcp23s08_spi_of_match), &spi->dev);
327 if (match)
328@@ -1161,6 +1052,16 @@ static int mcp23s08_probe(struct spi_device *spi)
329 if (pdata->base != -1)
330 pdata->base += data->mcp[addr]->chip.ngpio;
331 ngpio += data->mcp[addr]->chip.ngpio;
332+
333+ for_each_available_child_of_node(spi->dev.of_node, np) {
334+ u32 chip_addr;
335+ status = of_property_read_u32(np, "address", &chip_addr);
336+ if (status)
337+ continue;
338+ if (chip_addr != addr)
339+ continue;
340+ devprop_gpiochip_set_names(&data->mcp[addr]->chip, of_fwnode_handle(np));
341+ }
342 }
343 data->ngpio = ngpio;
344
345diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c
346index 47ef6b1a2e76..d28ecdf3bafc 100644
347--- a/drivers/spi/spi-orion.c
348+++ b/drivers/spi/spi-orion.c
349@@ -93,6 +93,7 @@ struct orion_direct_acc {
350
351 struct orion_child_options {
352 struct orion_direct_acc direct_access;
353+ u16 word_delay;
354 };
355
356 struct orion_spi {
357@@ -432,7 +433,7 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
358 struct orion_spi *orion_spi;
359 int cs = spi->chip_select;
360
361- word_len = spi->bits_per_word;
362+ word_len = xfer->bits_per_word;
363 count = xfer->len;
364
365 orion_spi = spi_master_get_devdata(spi->master);
366@@ -470,6 +471,8 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
367 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
368 goto out;
369 count--;
370+ if (orion_spi->child[cs].word_delay)
371+ udelay(orion_spi->child[cs].word_delay);
372 } while (count);
373 } else if (word_len == 16) {
374 const u16 *tx = xfer->tx_buf;
375@@ -478,6 +481,8 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer)
376 do {
377 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
378 goto out;
379+ if (orion_spi->child[cs].word_delay)
380+ udelay(orion_spi->child[cs].word_delay);
381 count -= 2;
382 } while (count);
383 }
384@@ -733,6 +738,12 @@ static int orion_spi_probe(struct platform_device *pdev)
385 }
386 }
387
388+ spi->child[cs].word_delay = 0;
389+ if (!of_property_read_u16(np, "linux,spi-wdelay",
390+ &spi->child[cs].word_delay))
391+ dev_info(&pdev->dev, "%pOF: %dus delay between words\n",
392+ np, spi->child[cs].word_delay);
393+
394 /*
395 * Check if an address is configured for this SPI device. If
396 * not, the MBus mapping via the 'ranges' property in the 'soc'
397@@ -744,6 +755,12 @@ static int orion_spi_probe(struct platform_device *pdev)
398 if (status)
399 continue;
400
401+ if (spi->child[cs].word_delay) {
402+ dev_warn(&pdev->dev,
403+ "%pOF linux,spi-wdelay takes preference over a direct-mode", np);
404+ continue;
405+ }
406+
407 /*
408 * Only map one page for direct access. This is enough for the
409 * simple TX transfer which only writes to the first word.
410diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
411index 9da0bc5a036c..097883f1fabd 100644
412--- a/drivers/spi/spi.c
413+++ b/drivers/spi/spi.c
414@@ -60,6 +60,7 @@ static void spidev_release(struct device *dev)
415 spi->controller->cleanup(spi);
416
417 spi_controller_put(spi->controller);
418+ kfree(spi->driver_override);
419 kfree(spi);
420 }
421
422@@ -77,6 +78,58 @@ modalias_show(struct device *dev, struct device_attribute *a, char *buf)
423 }
424 static DEVICE_ATTR_RO(modalias);
425
426+static ssize_t driver_override_store(struct device *dev,
427+ struct device_attribute *a,
428+ const char *buf, size_t count)
429+{
430+ struct spi_device *spi = to_spi_device(dev);
431+ const char *end = memchr(buf, '\n', count);
432+ const size_t len = end ? end - buf : count;
433+ const char *driver_override, *old;
434+ int ret;
435+
436+ /* We need to keep extra room for a newline when displaying value */
437+ if (len >= (PAGE_SIZE - 1))
438+ return -EINVAL;
439+
440+ driver_override = kstrndup(buf, len, GFP_KERNEL);
441+ if (!driver_override)
442+ return -ENOMEM;
443+
444+ device_lock(dev);
445+ old = spi->driver_override;
446+ if (len) {
447+ spi->driver_override = driver_override;
448+ } else {
449+ /* Emptry string, disable driver override */
450+ spi->driver_override = NULL;
451+ kfree(driver_override);
452+ }
453+ device_unlock(dev);
454+ kfree(old);
455+
456+ /* Attach device to new driver if it's not already attached */
457+ ret = device_attach(dev);
458+ if (ret < 0 && ret != -EPROBE_DEFER)
459+ dev_warn(dev, "device attach to '%s' failed (%d)\n",
460+ spi->driver_override, ret);
461+
462+ return count;
463+}
464+
465+static ssize_t driver_override_show(struct device *dev,
466+ struct device_attribute *a, char *buf)
467+{
468+ const struct spi_device *spi = to_spi_device(dev);
469+ ssize_t len;
470+
471+ device_lock(dev);
472+ len = snprintf(buf, PAGE_SIZE, "%s\n", spi->driver_override ? : "");
473+ device_unlock(dev);
474+ return len;
475+}
476+static DEVICE_ATTR_RW(driver_override);
477+
478 #define SPI_STATISTICS_ATTRS(field, file) \
479 static ssize_t spi_controller_##field##_show(struct device *dev, \
480 struct device_attribute *attr, \
481@@ -158,6 +211,7 @@ SPI_STATISTICS_SHOW(transfers_split_maxsize, "%lu");
482
483 static struct attribute *spi_dev_attrs[] = {
484 &dev_attr_modalias.attr,
485+ &dev_attr_driver_override.attr,
486 NULL,
487 };
488
489@@ -305,6 +359,10 @@ static int spi_match_device(struct device *dev, struct device_driver *drv)
490 const struct spi_device *spi = to_spi_device(dev);
491 const struct spi_driver *sdrv = to_spi_driver(drv);
492
493+ /* Check override first, and if set, only use the named driver */
494+ if (spi->driver_override)
495+ return strcmp(spi->driver_override, drv->name) == 0;
496+
497 /* Attempt an OF style match */
498 if (of_driver_match_device(dev, drv))
499 return 1;
500diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
501index cda10719d1d1..c5fe08bc34a0 100644
502--- a/drivers/spi/spidev.c
503+++ b/drivers/spi/spidev.c
504@@ -724,11 +724,9 @@ static int spidev_probe(struct spi_device *spi)
505 * compatible string, it is a Linux implementation thing
506 * rather than a description of the hardware.
507 */
508- if (spi->dev.of_node && !of_match_device(spidev_dt_ids, &spi->dev)) {
509- dev_err(&spi->dev, "buggy DT: spidev listed directly in DT\n");
510- WARN_ON(spi->dev.of_node &&
511- !of_match_device(spidev_dt_ids, &spi->dev));
512- }
513+ WARN(spi->dev.of_node &&
514+ of_device_is_compatible(spi->dev.of_node, "spidev"),
515+ "%pOF: buggy DT: spidev listed directly in DT\n", spi->dev.of_node);
516
517 spidev_probe_acpi(spi);
518
519diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
520index a64235e05321..e28f7c5d6eb6 100644
521--- a/include/linux/spi/spi.h
522+++ b/include/linux/spi/spi.h
523@@ -167,6 +167,7 @@ struct spi_device {
524 void *controller_state;
525 void *controller_data;
526 char modalias[SPI_NAME_SIZE];
527+ const char *driver_override;
528 int cs_gpio; /* chip select gpio */
529
530 /* the statistics */