.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Driver for Cirrus Logic EP93xx SPI controller. |
---|
3 | 4 | * |
---|
.. | .. |
---|
9 | 10 | * |
---|
10 | 11 | * For more information about the SPI controller see documentation on Cirrus |
---|
11 | 12 | * Logic web site: |
---|
12 | | - * http://www.cirrus.com/en/pubs/manual/EP93xx_Users_Guide_UM1.pdf |
---|
13 | | - * |
---|
14 | | - * This program is free software; you can redistribute it and/or modify |
---|
15 | | - * it under the terms of the GNU General Public License version 2 as |
---|
16 | | - * published by the Free Software Foundation. |
---|
| 13 | + * https://www.cirrus.com/en/pubs/manual/EP93xx_Users_Guide_UM1.pdf |
---|
17 | 14 | */ |
---|
18 | 15 | |
---|
19 | 16 | #include <linux/io.h> |
---|
.. | .. |
---|
28 | 25 | #include <linux/platform_device.h> |
---|
29 | 26 | #include <linux/sched.h> |
---|
30 | 27 | #include <linux/scatterlist.h> |
---|
31 | | -#include <linux/gpio.h> |
---|
32 | 28 | #include <linux/spi/spi.h> |
---|
33 | 29 | |
---|
34 | 30 | #include <linux/platform_data/dma-ep93xx.h> |
---|
35 | 31 | #include <linux/platform_data/spi-ep93xx.h> |
---|
36 | 32 | |
---|
37 | 33 | #define SSPCR0 0x0000 |
---|
38 | | -#define SSPCR0_MODE_SHIFT 6 |
---|
| 34 | +#define SSPCR0_SPO BIT(6) |
---|
| 35 | +#define SSPCR0_SPH BIT(7) |
---|
39 | 36 | #define SSPCR0_SCR_SHIFT 8 |
---|
40 | 37 | |
---|
41 | 38 | #define SSPCR1 0x0004 |
---|
.. | .. |
---|
163 | 160 | return err; |
---|
164 | 161 | |
---|
165 | 162 | cr0 = div_scr << SSPCR0_SCR_SHIFT; |
---|
166 | | - cr0 |= (spi->mode & (SPI_CPHA | SPI_CPOL)) << SSPCR0_MODE_SHIFT; |
---|
| 163 | + if (spi->mode & SPI_CPOL) |
---|
| 164 | + cr0 |= SSPCR0_SPO; |
---|
| 165 | + if (spi->mode & SPI_CPHA) |
---|
| 166 | + cr0 |= SSPCR0_SPH; |
---|
167 | 167 | cr0 |= dss; |
---|
168 | 168 | |
---|
169 | 169 | dev_dbg(&master->dev, "setup: mode %d, cpsr %d, scr %d, dss %d\n", |
---|
.. | .. |
---|
214 | 214 | |
---|
215 | 215 | /** |
---|
216 | 216 | * ep93xx_spi_read_write() - perform next RX/TX transfer |
---|
217 | | - * @espi: ep93xx SPI controller struct |
---|
| 217 | + * @master: SPI master |
---|
218 | 218 | * |
---|
219 | 219 | * This function transfers next bytes (or half-words) to/from RX/TX FIFOs. If |
---|
220 | 220 | * called several times, the whole transfer will be completed. Returns |
---|
.. | .. |
---|
652 | 652 | struct resource *res; |
---|
653 | 653 | int irq; |
---|
654 | 654 | int error; |
---|
655 | | - int i; |
---|
656 | 655 | |
---|
657 | 656 | info = dev_get_platdata(&pdev->dev); |
---|
658 | 657 | if (!info) { |
---|
.. | .. |
---|
661 | 660 | } |
---|
662 | 661 | |
---|
663 | 662 | irq = platform_get_irq(pdev, 0); |
---|
664 | | - if (irq < 0) { |
---|
665 | | - dev_err(&pdev->dev, "failed to get irq resources\n"); |
---|
| 663 | + if (irq < 0) |
---|
666 | 664 | return -EBUSY; |
---|
667 | | - } |
---|
668 | 665 | |
---|
669 | 666 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
---|
670 | 667 | if (!res) { |
---|
.. | .. |
---|
676 | 673 | if (!master) |
---|
677 | 674 | return -ENOMEM; |
---|
678 | 675 | |
---|
| 676 | + master->use_gpio_descriptors = true; |
---|
679 | 677 | master->prepare_transfer_hardware = ep93xx_spi_prepare_hardware; |
---|
680 | 678 | master->unprepare_transfer_hardware = ep93xx_spi_unprepare_hardware; |
---|
681 | 679 | master->prepare_message = ep93xx_spi_prepare_message; |
---|
.. | .. |
---|
683 | 681 | master->bus_num = pdev->id; |
---|
684 | 682 | master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; |
---|
685 | 683 | master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 16); |
---|
686 | | - |
---|
687 | | - master->num_chipselect = info->num_chipselect; |
---|
688 | | - master->cs_gpios = devm_kcalloc(&master->dev, |
---|
689 | | - master->num_chipselect, sizeof(int), |
---|
690 | | - GFP_KERNEL); |
---|
691 | | - if (!master->cs_gpios) { |
---|
692 | | - error = -ENOMEM; |
---|
693 | | - goto fail_release_master; |
---|
694 | | - } |
---|
695 | | - |
---|
696 | | - for (i = 0; i < master->num_chipselect; i++) { |
---|
697 | | - master->cs_gpios[i] = info->chipselect[i]; |
---|
698 | | - |
---|
699 | | - if (!gpio_is_valid(master->cs_gpios[i])) |
---|
700 | | - continue; |
---|
701 | | - |
---|
702 | | - error = devm_gpio_request_one(&pdev->dev, master->cs_gpios[i], |
---|
703 | | - GPIOF_OUT_INIT_HIGH, |
---|
704 | | - "ep93xx-spi"); |
---|
705 | | - if (error) { |
---|
706 | | - dev_err(&pdev->dev, "could not request cs gpio %d\n", |
---|
707 | | - master->cs_gpios[i]); |
---|
708 | | - goto fail_release_master; |
---|
709 | | - } |
---|
710 | | - } |
---|
| 684 | + /* |
---|
| 685 | + * The SPI core will count the number of GPIO descriptors to figure |
---|
| 686 | + * out the number of chip selects available on the platform. |
---|
| 687 | + */ |
---|
| 688 | + master->num_chipselect = 0; |
---|
711 | 689 | |
---|
712 | 690 | platform_set_drvdata(pdev, master); |
---|
713 | 691 | |
---|