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

spi: sh-msiof: Use the core cs_gpio field, and make it optional

In current implementation, CS is controlled by GPIO, which is passed
through spi->controller_data. However, the MSIOF HW module has a function
to output CS by itself, which is already enabled and actual switch will be
done by pinmux.

Store the GPIO number in the core cs_gpio field, and ignore it if it is
an invalid (negative) GPIO number.

Loosely based on a patch from Takashi Yoshii <takasi-y@ops.dti.ne.jp>.

Signed-off-by: Geert Uytterhoeven <geert+renesas@linux-m68k.org>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Geert Uytterhoeven and committed by
Mark Brown
8d19534a 01cfef57

+18 -3
+18 -3
drivers/spi/spi-sh-msiof.c
··· 446 446 return spi_bitbang_setup_transfer(spi, t); 447 447 } 448 448 449 + static int sh_msiof_spi_setup(struct spi_device *spi) 450 + { 451 + struct device_node *np = spi->master->dev.of_node; 452 + 453 + if (!np) { 454 + /* 455 + * Use spi->controller_data for CS (same strategy as spi_gpio), 456 + * if any. otherwise let HW control CS 457 + */ 458 + spi->cs_gpio = (uintptr_t)spi->controller_data; 459 + } 460 + 461 + return spi_bitbang_setup(spi); 462 + } 463 + 449 464 static void sh_msiof_spi_chipselect(struct spi_device *spi, int is_on) 450 465 { 451 466 struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); ··· 486 471 !!(spi->mode & SPI_CS_HIGH)); 487 472 } 488 473 489 - /* use spi->controller data for CS (same strategy as spi_gpio) */ 490 - gpio_set_value((uintptr_t)spi->controller_data, value); 474 + if (spi->cs_gpio >= 0) 475 + gpio_set_value(spi->cs_gpio, value); 491 476 492 477 if (is_on == BITBANG_CS_INACTIVE) { 493 478 if (test_and_clear_bit(0, &p->flags)) { ··· 774 759 master->bus_num = pdev->id; 775 760 master->dev.of_node = pdev->dev.of_node; 776 761 master->num_chipselect = p->info->num_chipselect; 777 - master->setup = spi_bitbang_setup; 762 + master->setup = sh_msiof_spi_setup; 778 763 master->cleanup = spi_bitbang_cleanup; 779 764 780 765 p->bitbang.master = master;