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

spi: sh-msiof: Convert to use GPIO descriptors

Convert GPIO chip selects in the Renesas MSIOF SPI driver from legacy
GPIO numbers to GPIO descriptors.

Notes:
- The board file for the SH7724-based Ecovec24 development board now
registers a GPIO descriptor lookup, instead of passing a GPIO number
through controller_data,
- sh_msiof_get_cs_gpios() must release all GPIOs, else
spi_get_gpio_descs() cannot claim them during SPI controller
registration.

Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Geert Uytterhoeven and committed by
Mark Brown
9fda6693 1a8fa516

+13 -19
+9 -3
arch/sh/boards/mach-ecovec24/setup.c
··· 806 806 .platform_data = &mmc_spi_info, 807 807 .max_speed_hz = 5000000, 808 808 .mode = SPI_MODE_0, 809 - .controller_data = (void *) GPIO_PTM4, 810 809 }, 811 810 }; 812 811 ··· 835 836 }, 836 837 .num_resources = ARRAY_SIZE(msiof0_resources), 837 838 .resource = msiof0_resources, 839 + }; 840 + 841 + static struct gpiod_lookup_table msiof_gpio_table = { 842 + .dev_id = "spi_sh_msiof.0", 843 + .table = { 844 + GPIO_LOOKUP("sh7724_pfc", GPIO_PTM4, "cs", GPIO_ACTIVE_HIGH), 845 + { }, 846 + }, 838 847 }; 839 848 840 849 #endif ··· 1303 1296 gpio_request(GPIO_FN_MSIOF0_TXD, NULL); 1304 1297 gpio_request(GPIO_FN_MSIOF0_RXD, NULL); 1305 1298 gpio_request(GPIO_FN_MSIOF0_TSCK, NULL); 1306 - gpio_request(GPIO_PTM4, NULL); /* software CS control of TSYNC pin */ 1307 - gpio_direction_output(GPIO_PTM4, 1); /* active low CS */ 1308 1299 gpio_request(GPIO_PTB6, NULL); /* 3.3V power control */ 1309 1300 gpio_direction_output(GPIO_PTB6, 0); /* disable power by default */ 1310 1301 1311 1302 gpiod_add_lookup_table(&mmc_spi_gpio_table); 1303 + gpiod_add_lookup_table(&msiof_gpio_table); 1312 1304 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); 1313 1305 #endif 1314 1306
+4 -16
drivers/spi/spi-sh-msiof.c
··· 549 549 550 550 static int sh_msiof_spi_setup(struct spi_device *spi) 551 551 { 552 - struct device_node *np = spi->controller->dev.of_node; 553 552 struct sh_msiof_spi_priv *p = 554 553 spi_controller_get_devdata(spi->controller); 555 554 u32 clr, set, tmp; 556 555 557 - if (!np) { 558 - /* 559 - * Use spi->controller_data for CS (same strategy as spi_gpio), 560 - * if any. otherwise let HW control CS 561 - */ 562 - spi->cs_gpio = (uintptr_t)spi->controller_data; 563 - } 564 - 565 - if (gpio_is_valid(spi->cs_gpio)) { 566 - gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); 567 - return 0; 568 - } 569 - 570 - if (spi_controller_is_slave(p->ctlr)) 556 + if (spi->cs_gpiod || spi_controller_is_slave(p->ctlr)) 571 557 return 0; 572 558 573 559 if (p->native_cs_inited && ··· 586 600 u32 ss, cs_high; 587 601 588 602 /* Configure pins before asserting CS */ 589 - if (gpio_is_valid(spi->cs_gpio)) { 603 + if (spi->cs_gpiod) { 590 604 ss = p->unused_ss; 591 605 cs_high = p->native_cs_high; 592 606 } else { ··· 1142 1156 1143 1157 gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS); 1144 1158 if (!IS_ERR(gpiod)) { 1159 + devm_gpiod_put(dev, gpiod); 1145 1160 cs_gpios++; 1146 1161 continue; 1147 1162 } ··· 1394 1407 ctlr->bits_per_word_mask = chipdata->bits_per_word_mask; 1395 1408 ctlr->auto_runtime_pm = true; 1396 1409 ctlr->transfer_one = sh_msiof_transfer_one; 1410 + ctlr->use_gpio_descriptors = true; 1397 1411 1398 1412 ret = sh_msiof_request_dma(p); 1399 1413 if (ret < 0)