| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Copyright (C) 2012-2013 Uwe Kleine-Koenig for Pengutronix |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify it under |
|---|
| 5 | | - * the terms of the GNU General Public License version 2 as published by the |
|---|
| 6 | | - * Free Software Foundation. |
|---|
| 7 | 4 | */ |
|---|
| 8 | 5 | #include <linux/kernel.h> |
|---|
| 9 | 6 | #include <linux/io.h> |
|---|
| 10 | 7 | #include <linux/spi/spi.h> |
|---|
| 11 | 8 | #include <linux/spi/spi_bitbang.h> |
|---|
| 12 | | -#include <linux/gpio.h> |
|---|
| 13 | 9 | #include <linux/interrupt.h> |
|---|
| 14 | 10 | #include <linux/platform_device.h> |
|---|
| 15 | 11 | #include <linux/clk.h> |
|---|
| 16 | 12 | #include <linux/err.h> |
|---|
| 17 | 13 | #include <linux/module.h> |
|---|
| 18 | | -#include <linux/of_gpio.h> |
|---|
| 19 | 14 | #include <linux/platform_data/efm32-spi.h> |
|---|
| 15 | +#include <linux/of.h> |
|---|
| 20 | 16 | |
|---|
| 21 | 17 | #define DRIVER_NAME "efm32-spi" |
|---|
| 22 | 18 | |
|---|
| .. | .. |
|---|
| 85 | 81 | const u8 *tx_buf; |
|---|
| 86 | 82 | u8 *rx_buf; |
|---|
| 87 | 83 | unsigned tx_len, rx_len; |
|---|
| 88 | | - |
|---|
| 89 | | - /* chip selects */ |
|---|
| 90 | | - unsigned csgpio[]; |
|---|
| 91 | 84 | }; |
|---|
| 92 | 85 | |
|---|
| 93 | 86 | #define ddata_to_dev(ddata) (&(ddata->bitbang.master->dev)) |
|---|
| .. | .. |
|---|
| 103 | 96 | static u32 efm32_spi_read32(struct efm32_spi_ddata *ddata, unsigned offset) |
|---|
| 104 | 97 | { |
|---|
| 105 | 98 | return readl_relaxed(ddata->base + offset); |
|---|
| 106 | | -} |
|---|
| 107 | | - |
|---|
| 108 | | -static void efm32_spi_chipselect(struct spi_device *spi, int is_on) |
|---|
| 109 | | -{ |
|---|
| 110 | | - struct efm32_spi_ddata *ddata = spi_master_get_devdata(spi->master); |
|---|
| 111 | | - int value = !(spi->mode & SPI_CS_HIGH) == !(is_on == BITBANG_CS_ACTIVE); |
|---|
| 112 | | - |
|---|
| 113 | | - gpio_set_value(ddata->csgpio[spi->chip_select], value); |
|---|
| 114 | 99 | } |
|---|
| 115 | 100 | |
|---|
| 116 | 101 | static int efm32_spi_setup_transfer(struct spi_device *spi, |
|---|
| .. | .. |
|---|
| 323 | 308 | int ret; |
|---|
| 324 | 309 | struct spi_master *master; |
|---|
| 325 | 310 | struct device_node *np = pdev->dev.of_node; |
|---|
| 326 | | - int num_cs, i; |
|---|
| 327 | 311 | |
|---|
| 328 | 312 | if (!np) |
|---|
| 329 | 313 | return -EINVAL; |
|---|
| 330 | 314 | |
|---|
| 331 | | - num_cs = of_gpio_named_count(np, "cs-gpios"); |
|---|
| 332 | | - if (num_cs < 0) |
|---|
| 333 | | - return num_cs; |
|---|
| 334 | | - |
|---|
| 335 | | - master = spi_alloc_master(&pdev->dev, |
|---|
| 336 | | - sizeof(*ddata) + num_cs * sizeof(unsigned)); |
|---|
| 315 | + master = spi_alloc_master(&pdev->dev, sizeof(*ddata)); |
|---|
| 337 | 316 | if (!master) { |
|---|
| 338 | 317 | dev_dbg(&pdev->dev, |
|---|
| 339 | 318 | "failed to allocate spi master controller\n"); |
|---|
| .. | .. |
|---|
| 343 | 322 | |
|---|
| 344 | 323 | master->dev.of_node = pdev->dev.of_node; |
|---|
| 345 | 324 | |
|---|
| 346 | | - master->num_chipselect = num_cs; |
|---|
| 347 | 325 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
|---|
| 348 | 326 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); |
|---|
| 327 | + master->use_gpio_descriptors = true; |
|---|
| 349 | 328 | |
|---|
| 350 | 329 | ddata = spi_master_get_devdata(master); |
|---|
| 351 | 330 | |
|---|
| 352 | 331 | ddata->bitbang.master = master; |
|---|
| 353 | | - ddata->bitbang.chipselect = efm32_spi_chipselect; |
|---|
| 354 | 332 | ddata->bitbang.setup_transfer = efm32_spi_setup_transfer; |
|---|
| 355 | 333 | ddata->bitbang.txrx_bufs = efm32_spi_txrx_bufs; |
|---|
| 356 | 334 | |
|---|
| .. | .. |
|---|
| 362 | 340 | ret = PTR_ERR(ddata->clk); |
|---|
| 363 | 341 | dev_err(&pdev->dev, "failed to get clock: %d\n", ret); |
|---|
| 364 | 342 | goto err; |
|---|
| 365 | | - } |
|---|
| 366 | | - |
|---|
| 367 | | - for (i = 0; i < num_cs; ++i) { |
|---|
| 368 | | - ret = of_get_named_gpio(np, "cs-gpios", i); |
|---|
| 369 | | - if (ret < 0) { |
|---|
| 370 | | - dev_err(&pdev->dev, "failed to get csgpio#%u (%d)\n", |
|---|
| 371 | | - i, ret); |
|---|
| 372 | | - goto err; |
|---|
| 373 | | - } |
|---|
| 374 | | - ddata->csgpio[i] = ret; |
|---|
| 375 | | - dev_dbg(&pdev->dev, "csgpio#%u = %u\n", i, ddata->csgpio[i]); |
|---|
| 376 | | - ret = devm_gpio_request_one(&pdev->dev, ddata->csgpio[i], |
|---|
| 377 | | - GPIOF_OUT_INIT_LOW, DRIVER_NAME); |
|---|
| 378 | | - if (ret < 0) { |
|---|
| 379 | | - dev_err(&pdev->dev, |
|---|
| 380 | | - "failed to configure csgpio#%u (%d)\n", |
|---|
| 381 | | - i, ret); |
|---|
| 382 | | - goto err; |
|---|
| 383 | | - } |
|---|
| 384 | 343 | } |
|---|
| 385 | 344 | |
|---|
| 386 | 345 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
|---|
| .. | .. |
|---|
| 403 | 362 | } |
|---|
| 404 | 363 | |
|---|
| 405 | 364 | ret = platform_get_irq(pdev, 0); |
|---|
| 406 | | - if (ret <= 0) { |
|---|
| 407 | | - dev_err(&pdev->dev, "failed to get rx irq (%d)\n", ret); |
|---|
| 365 | + if (ret <= 0) |
|---|
| 408 | 366 | goto err; |
|---|
| 409 | | - } |
|---|
| 410 | 367 | |
|---|
| 411 | 368 | ddata->rxirq = ret; |
|---|
| 412 | 369 | |
|---|