Skip to content

Commit 44af792

Browse files
jonhunterbroonie
authored andcommitted
spi: Map SPI OF client IRQ at probe time
Currently the IRQs for SPI client devices, registered via device-tree, are mapped when the client devices are registered. If the corresponding irq-chip has not been probed yet, then the probing of the client device will fail and will not be retried. Resolve this by mapping the IRQ at probe time and allow the probe to be deferred if the IRQ is not yet available. If of_irq_get() returns an error that is not -EPROBE_DEFER, then assume that the SPI client does not have an IRQ and set the IRQ number to zero (which is equivalent to irq_of_parse_and_map()). This is based on some inputs from Thierry Reding <[email protected]>. Cc: Thierry Reding <[email protected]> Cc: Tomeu Vizoso <[email protected]> Signed-off-by: Jon Hunter <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 6ff33f3 commit 44af792

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

drivers/spi/spi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,15 +270,24 @@ EXPORT_SYMBOL_GPL(spi_bus_type);
270270
static int spi_drv_probe(struct device *dev)
271271
{
272272
const struct spi_driver *sdrv = to_spi_driver(dev->driver);
273+
struct spi_device *spi = to_spi_device(dev);
273274
int ret;
274275

275276
ret = of_clk_set_defaults(dev->of_node, false);
276277
if (ret)
277278
return ret;
278279

280+
if (dev->of_node) {
281+
spi->irq = of_irq_get(dev->of_node, 0);
282+
if (spi->irq == -EPROBE_DEFER)
283+
return -EPROBE_DEFER;
284+
if (spi->irq < 0)
285+
spi->irq = 0;
286+
}
287+
279288
ret = dev_pm_domain_attach(dev, true);
280289
if (ret != -EPROBE_DEFER) {
281-
ret = sdrv->probe(to_spi_device(dev));
290+
ret = sdrv->probe(spi);
282291
if (ret)
283292
dev_pm_domain_detach(dev, true);
284293
}
@@ -1433,9 +1442,6 @@ of_register_spi_device(struct spi_master *master, struct device_node *nc)
14331442
}
14341443
spi->max_speed_hz = value;
14351444

1436-
/* IRQ */
1437-
spi->irq = irq_of_parse_and_map(nc, 0);
1438-
14391445
/* Store a pointer to the node in the device structure */
14401446
of_node_get(nc);
14411447
spi->dev.of_node = nc;

0 commit comments

Comments
 (0)