Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: mediatek: single device does not require cs_gpios

When only one device is present, it is not necessary to specify
cs_gpios, as the CS line can be controlled by the hardware
module.

Without this patch, older device tree bindings used before
37457607 "spi: mediatek: mt8173 spi multiple devices support"
would cause a panic on boot. This fixes the crash, and
re-introduces backward compatibility.

Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Acked-by: Leilk Liu <leilk.liu@mediatek.com>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Nicolas Boichat and committed by
Mark Brown
98c8dccf 8005c49d

+18 -8
+18 -8
drivers/spi/spi-mt65xx.c
··· 410 410 if (!spi->controller_data) 411 411 spi->controller_data = (void *)&mtk_default_chip_info; 412 412 413 - if (mdata->dev_comp->need_pad_sel) 413 + if (mdata->dev_comp->need_pad_sel && gpio_is_valid(spi->cs_gpio)) 414 414 gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); 415 415 416 416 return 0; ··· 632 632 goto err_put_master; 633 633 } 634 634 635 - for (i = 0; i < master->num_chipselect; i++) { 636 - ret = devm_gpio_request(&pdev->dev, master->cs_gpios[i], 637 - dev_name(&pdev->dev)); 638 - if (ret) { 639 - dev_err(&pdev->dev, 640 - "can't get CS GPIO %i\n", i); 641 - goto err_put_master; 635 + if (!master->cs_gpios && master->num_chipselect > 1) { 636 + dev_err(&pdev->dev, 637 + "cs_gpios not specified and num_chipselect > 1\n"); 638 + ret = -EINVAL; 639 + goto err_put_master; 640 + } 641 + 642 + if (master->cs_gpios) { 643 + for (i = 0; i < master->num_chipselect; i++) { 644 + ret = devm_gpio_request(&pdev->dev, 645 + master->cs_gpios[i], 646 + dev_name(&pdev->dev)); 647 + if (ret) { 648 + dev_err(&pdev->dev, 649 + "can't get CS GPIO %i\n", i); 650 + goto err_put_master; 651 + } 642 652 } 643 653 } 644 654 }