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

spi: gpio: Convert to be used outside of OF

Merge series from Andy Shevchenko <andriy.shevchenko@linux.intel.com>:

Convert the driver to be used outside of OF and a couple of cleanups.

+25 -41
+25 -41
drivers/spi/spi-gpio.c
··· 5 5 * Copyright (C) 2006,2008 David Brownell 6 6 * Copyright (C) 2017 Linus Walleij 7 7 */ 8 + #include <linux/gpio/consumer.h> 8 9 #include <linux/kernel.h> 10 + #include <linux/mod_devicetable.h> 9 11 #include <linux/module.h> 10 12 #include <linux/platform_device.h> 11 - #include <linux/gpio/consumer.h> 12 - #include <linux/of.h> 13 + #include <linux/property.h> 13 14 14 15 #include <linux/spi/spi.h> 15 16 #include <linux/spi/spi_bitbang.h> 16 17 #include <linux/spi/spi_gpio.h> 17 - 18 18 19 19 /* 20 20 * This bitbanging SPI host driver should help make systems usable ··· 239 239 static int spi_gpio_setup(struct spi_device *spi) 240 240 { 241 241 struct gpio_desc *cs; 242 - int status = 0; 243 242 struct spi_gpio *spi_gpio = spi_to_spi_gpio(spi); 243 + int ret; 244 244 245 245 /* 246 246 * The CS GPIOs have already been ··· 248 248 */ 249 249 if (spi_gpio->cs_gpios) { 250 250 cs = spi_gpio->cs_gpios[spi_get_chipselect(spi, 0)]; 251 - if (!spi->controller_state && cs) 252 - status = gpiod_direction_output(cs, 253 - !(spi->mode & SPI_CS_HIGH)); 251 + if (!spi->controller_state && cs) { 252 + ret = gpiod_direction_output(cs, !(spi->mode & SPI_CS_HIGH)); 253 + if (ret) 254 + return ret; 255 + } 254 256 } 255 257 256 - if (!status) 257 - status = spi_bitbang_setup(spi); 258 - 259 - return status; 258 + return spi_bitbang_setup(spi); 260 259 } 261 260 262 261 static int spi_gpio_set_direction(struct spi_device *spi, bool output) ··· 325 326 return PTR_ERR_OR_ZERO(spi_gpio->sck); 326 327 } 327 328 328 - #ifdef CONFIG_OF 329 - static const struct of_device_id spi_gpio_dt_ids[] = { 330 - { .compatible = "spi-gpio" }, 331 - {} 332 - }; 333 - MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); 334 - 335 - static int spi_gpio_probe_dt(struct platform_device *pdev, 336 - struct spi_controller *host) 337 - { 338 - host->dev.of_node = pdev->dev.of_node; 339 - host->use_gpio_descriptors = true; 340 - 341 - return 0; 342 - } 343 - #else 344 - static inline int spi_gpio_probe_dt(struct platform_device *pdev, 345 - struct spi_controller *host) 346 - { 347 - return 0; 348 - } 349 - #endif 350 - 351 329 static int spi_gpio_probe_pdata(struct platform_device *pdev, 352 330 struct spi_controller *host) 353 331 { ··· 365 389 struct spi_controller *host; 366 390 struct spi_gpio *spi_gpio; 367 391 struct device *dev = &pdev->dev; 392 + struct fwnode_handle *fwnode = dev_fwnode(dev); 368 393 struct spi_bitbang *bb; 369 394 370 395 host = devm_spi_alloc_host(dev, sizeof(*spi_gpio)); 371 396 if (!host) 372 397 return -ENOMEM; 373 398 374 - if (pdev->dev.of_node) 375 - status = spi_gpio_probe_dt(pdev, host); 376 - else 399 + if (fwnode) { 400 + device_set_node(&host->dev, fwnode); 401 + host->use_gpio_descriptors = true; 402 + } else { 377 403 status = spi_gpio_probe_pdata(pdev, host); 378 - 379 - if (status) 380 - return status; 404 + if (status) 405 + return status; 406 + } 381 407 382 408 spi_gpio = spi_controller_get_devdata(host); 383 409 ··· 437 459 438 460 MODULE_ALIAS("platform:" DRIVER_NAME); 439 461 462 + static const struct of_device_id spi_gpio_dt_ids[] = { 463 + { .compatible = "spi-gpio" }, 464 + {} 465 + }; 466 + MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); 467 + 440 468 static struct platform_driver spi_gpio_driver = { 441 469 .driver = { 442 470 .name = DRIVER_NAME, 443 - .of_match_table = of_match_ptr(spi_gpio_dt_ids), 471 + .of_match_table = spi_gpio_dt_ids, 444 472 }, 445 473 .probe = spi_gpio_probe, 446 474 };