hc
2024-05-11 04dd17822334871b23ea2862f7798fb0e0007777
kernel/drivers/spi/spi-davinci.c
....@@ -1,21 +1,12 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Copyright (C) 2009 Texas Instruments.
34 * Copyright (C) 2010 EF Johnson Technologies
4
- *
5
- * This program is free software; you can redistribute it and/or modify
6
- * it under the terms of the GNU General Public License as published by
7
- * the Free Software Foundation; either version 2 of the License, or
8
- * (at your option) any later version.
9
- *
10
- * This program is distributed in the hope that it will be useful,
11
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- * GNU General Public License for more details.
145 */
156
167 #include <linux/interrupt.h>
178 #include <linux/io.h>
18
-#include <linux/gpio.h>
9
+#include <linux/gpio/consumer.h>
1910 #include <linux/module.h>
2011 #include <linux/delay.h>
2112 #include <linux/platform_device.h>
....@@ -25,7 +16,6 @@
2516 #include <linux/dma-mapping.h>
2617 #include <linux/of.h>
2718 #include <linux/of_device.h>
28
-#include <linux/of_gpio.h>
2919 #include <linux/spi/spi.h>
3020 #include <linux/spi/spi_bitbang.h>
3121 #include <linux/slab.h>
....@@ -208,13 +198,11 @@
208198 static void davinci_spi_chipselect(struct spi_device *spi, int value)
209199 {
210200 struct davinci_spi *dspi;
211
- struct davinci_spi_platform_data *pdata;
212201 struct davinci_spi_config *spicfg = spi->controller_data;
213202 u8 chip_sel = spi->chip_select;
214203 u16 spidat1 = CS_DEFAULT;
215204
216205 dspi = spi_master_get_devdata(spi->master);
217
- pdata = &dspi->pdata;
218206
219207 /* program delay transfers if tx_delay is non zero */
220208 if (spicfg && spicfg->wdelay)
....@@ -224,15 +212,15 @@
224212 * Board specific chip select logic decides the polarity and cs
225213 * line for the controller
226214 */
227
- if (spi->cs_gpio >= 0) {
215
+ if (spi->cs_gpiod) {
228216 if (value == BITBANG_CS_ACTIVE)
229
- gpio_set_value(spi->cs_gpio, spi->mode & SPI_CS_HIGH);
217
+ gpiod_set_value(spi->cs_gpiod, 1);
230218 else
231
- gpio_set_value(spi->cs_gpio,
232
- !(spi->mode & SPI_CS_HIGH));
219
+ gpiod_set_value(spi->cs_gpiod, 0);
233220 } else {
234221 if (value == BITBANG_CS_ACTIVE) {
235
- spidat1 |= SPIDAT1_CSHOLD_MASK;
222
+ if (!(spi->mode & SPI_CS_WORD))
223
+ spidat1 |= SPIDAT1_CSHOLD_MASK;
236224 spidat1 &= ~(0x1 << chip_sel);
237225 }
238226 }
....@@ -242,7 +230,8 @@
242230
243231 /**
244232 * davinci_spi_get_prescale - Calculates the correct prescale value
245
- * @maxspeed_hz: the maximum rate the SPI clock can run at
233
+ * @dspi: the controller data
234
+ * @max_speed_hz: the maximum rate the SPI clock can run at
246235 *
247236 * This function calculates the prescale value that generates a clock rate
248237 * less than or equal to the specified maximum.
....@@ -419,35 +408,15 @@
419408 */
420409 static int davinci_spi_setup(struct spi_device *spi)
421410 {
422
- int retval = 0;
423411 struct davinci_spi *dspi;
424
- struct davinci_spi_platform_data *pdata;
425
- struct spi_master *master = spi->master;
426412 struct device_node *np = spi->dev.of_node;
427413 bool internal_cs = true;
428414
429415 dspi = spi_master_get_devdata(spi->master);
430
- pdata = &dspi->pdata;
431416
432417 if (!(spi->mode & SPI_NO_CS)) {
433
- if (np && (master->cs_gpios != NULL) && (spi->cs_gpio >= 0)) {
434
- retval = gpio_direction_output(
435
- spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
418
+ if (np && spi->cs_gpiod)
436419 internal_cs = false;
437
- } else if (pdata->chip_sel &&
438
- spi->chip_select < pdata->num_chipselect &&
439
- pdata->chip_sel[spi->chip_select] != SPI_INTERN_CS) {
440
- spi->cs_gpio = pdata->chip_sel[spi->chip_select];
441
- retval = gpio_direction_output(
442
- spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
443
- internal_cs = false;
444
- }
445
-
446
- if (retval) {
447
- dev_err(&spi->dev, "GPIO %d setup failed (%d)\n",
448
- spi->cs_gpio, retval);
449
- return retval;
450
- }
451420
452421 if (internal_cs)
453422 set_io_bits(dspi->base + SPIPC0, 1 << spi->chip_select);
....@@ -602,7 +571,6 @@
602571 u32 errors = 0;
603572 struct davinci_spi_config *spicfg;
604573 struct davinci_spi_platform_data *pdata;
605
- unsigned uninitialized_var(rx_buf_count);
606574
607575 dspi = spi_master_get_devdata(spi->master);
608576 pdata = &dspi->pdata;
....@@ -737,7 +705,7 @@
737705 /**
738706 * dummy_thread_fn - dummy thread function
739707 * @irq: IRQ number for this SPI Master
740
- * @context_data: structure for SPI Master controller davinci_spi
708
+ * @data: structure for SPI Master controller davinci_spi
741709 *
742710 * This is to satisfy the request_threaded_irq() API so that the irq
743711 * handler is called in interrupt context.
....@@ -750,7 +718,7 @@
750718 /**
751719 * davinci_spi_irq - Interrupt handler for SPI Master Controller
752720 * @irq: IRQ number for this SPI Master
753
- * @context_data: structure for SPI Master controller davinci_spi
721
+ * @data: structure for SPI Master controller davinci_spi
754722 *
755723 * ISR will determine that interrupt arrives either for READ or WRITE command.
756724 * According to command it will do the appropriate action. It will check
....@@ -971,11 +939,12 @@
971939 if (ret)
972940 goto free_master;
973941
942
+ master->use_gpio_descriptors = true;
974943 master->dev.of_node = pdev->dev.of_node;
975944 master->bus_num = pdev->id;
976945 master->num_chipselect = pdata->num_chipselect;
977946 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(2, 16);
978
- master->flags = SPI_MASTER_MUST_RX;
947
+ master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_GPIO_SS;
979948 master->setup = davinci_spi_setup;
980949 master->cleanup = davinci_spi_cleanup;
981950 master->can_dma = davinci_spi_can_dma;
....@@ -985,30 +954,9 @@
985954 dspi->prescaler_limit = pdata->prescaler_limit;
986955 dspi->version = pdata->version;
987956
988
- dspi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP;
957
+ dspi->bitbang.flags = SPI_NO_CS | SPI_LSB_FIRST | SPI_LOOP | SPI_CS_WORD;
989958 if (dspi->version == SPI_VERSION_2)
990959 dspi->bitbang.flags |= SPI_READY;
991
-
992
- if (pdev->dev.of_node) {
993
- int i;
994
-
995
- for (i = 0; i < pdata->num_chipselect; i++) {
996
- int cs_gpio = of_get_named_gpio(pdev->dev.of_node,
997
- "cs-gpios", i);
998
-
999
- if (cs_gpio == -EPROBE_DEFER) {
1000
- ret = cs_gpio;
1001
- goto free_clk;
1002
- }
1003
-
1004
- if (gpio_is_valid(cs_gpio)) {
1005
- ret = devm_gpio_request(&pdev->dev, cs_gpio,
1006
- dev_name(&pdev->dev));
1007
- if (ret)
1008
- goto free_clk;
1009
- }
1010
- }
1011
- }
1012960
1013961 dspi->bitbang.txrx_bufs = davinci_spi_bufs;
1014962