hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/spi/spi-orion.c
....@@ -1,12 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Marvell Orion SPI controller driver
34 *
45 * Author: Shadi Ammouri <shadi@marvell.com>
56 * Copyright (C) 2007-2008 Marvell Ltd.
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License version 2 as
9
- * published by the Free Software Foundation.
107 */
118
129 #include <linux/interrupt.h>
....@@ -20,10 +17,8 @@
2017 #include <linux/of.h>
2118 #include <linux/of_address.h>
2219 #include <linux/of_device.h>
23
-#include <linux/of_gpio.h>
2420 #include <linux/clk.h>
2521 #include <linux/sizes.h>
26
-#include <linux/gpio.h>
2722 #include <asm/unaligned.h>
2823
2924 #define DRIVER_NAME "orion_spi"
....@@ -101,7 +96,6 @@
10196 struct clk *clk;
10297 struct clk *axi_clk;
10398 const struct orion_spi_dev *devdata;
104
- int unused_hw_gpio;
10599
106100 struct orion_child_options child[ORION_NUM_CHIPSELECTS];
107101 };
....@@ -328,20 +322,27 @@
328322 static void orion_spi_set_cs(struct spi_device *spi, bool enable)
329323 {
330324 struct orion_spi *orion_spi;
331
- int cs;
332325
333326 orion_spi = spi_master_get_devdata(spi->master);
334327
335
- if (gpio_is_valid(spi->cs_gpio))
336
- cs = orion_spi->unused_hw_gpio;
337
- else
338
- cs = spi->chip_select;
339
-
328
+ /*
329
+ * If this line is using a GPIO to control chip select, this internal
330
+ * .set_cs() function will still be called, so we clear any previous
331
+ * chip select. The CS we activate will not have any elecrical effect,
332
+ * as it is handled by a GPIO, but that doesn't matter. What we need
333
+ * is to deassert the old chip select and assert some other chip select.
334
+ */
340335 orion_spi_clrbits(orion_spi, ORION_SPI_IF_CTRL_REG, ORION_SPI_CS_MASK);
341336 orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG,
342
- ORION_SPI_CS(cs));
337
+ ORION_SPI_CS(spi->chip_select));
343338
344
- /* Chip select logic is inverted from spi_set_cs */
339
+ /*
340
+ * Chip select logic is inverted from spi_set_cs(). For lines using a
341
+ * GPIO to do chip select SPI_CS_HIGH is enforced and inversion happens
342
+ * in the GPIO library, but we don't care about that, because in those
343
+ * cases we are dealing with an unused native CS anyways so the polarity
344
+ * doesn't matter.
345
+ */
345346 if (!enable)
346347 orion_spi_setbits(orion_spi, ORION_SPI_IF_CTRL_REG, 0x1);
347348 else
....@@ -431,6 +432,7 @@
431432 int word_len;
432433 struct orion_spi *orion_spi;
433434 int cs = spi->chip_select;
435
+ void __iomem *vaddr;
434436
435437 word_len = spi->bits_per_word;
436438 count = xfer->len;
....@@ -441,8 +443,9 @@
441443 * Use SPI direct write mode if base address is available. Otherwise
442444 * fall back to PIO mode for this transfer.
443445 */
444
- if ((orion_spi->child[cs].direct_access.vaddr) && (xfer->tx_buf) &&
445
- (word_len == 8)) {
446
+ vaddr = orion_spi->child[cs].direct_access.vaddr;
447
+
448
+ if (vaddr && xfer->tx_buf && word_len == 8) {
446449 unsigned int cnt = count / 4;
447450 unsigned int rem = count % 4;
448451
....@@ -450,13 +453,11 @@
450453 * Send the TX-data to the SPI device via the direct
451454 * mapped address window
452455 */
453
- iowrite32_rep(orion_spi->child[cs].direct_access.vaddr,
454
- xfer->tx_buf, cnt);
456
+ iowrite32_rep(vaddr, xfer->tx_buf, cnt);
455457 if (rem) {
456458 u32 *buf = (u32 *)xfer->tx_buf;
457459
458
- iowrite8_rep(orion_spi->child[cs].direct_access.vaddr,
459
- &buf[cnt], rem);
460
+ iowrite8_rep(vaddr, &buf[cnt], rem);
460461 }
461462
462463 return count;
....@@ -470,6 +471,7 @@
470471 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0)
471472 goto out;
472473 count--;
474
+ spi_delay_exec(&xfer->word_delay, xfer);
473475 } while (count);
474476 } else if (word_len == 16) {
475477 const u16 *tx = xfer->tx_buf;
....@@ -479,6 +481,7 @@
479481 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0)
480482 goto out;
481483 count -= 2;
484
+ spi_delay_exec(&xfer->word_delay, xfer);
482485 } while (count);
483486 }
484487
....@@ -504,9 +507,6 @@
504507
505508 static int orion_spi_setup(struct spi_device *spi)
506509 {
507
- if (gpio_is_valid(spi->cs_gpio)) {
508
- gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH));
509
- }
510510 return orion_spi_setup_transfer(spi, NULL);
511511 }
512512
....@@ -623,13 +623,13 @@
623623 master->setup = orion_spi_setup;
624624 master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
625625 master->auto_runtime_pm = true;
626
+ master->use_gpio_descriptors = true;
626627 master->flags = SPI_MASTER_GPIO_SS;
627628
628629 platform_set_drvdata(pdev, master);
629630
630631 spi = spi_master_get_devdata(master);
631632 spi->master = master;
632
- spi->unused_hw_gpio = -1;
633633
634634 of_id = of_match_device(orion_spi_of_match_table, &pdev->dev);
635635 devdata = (of_id) ? of_id->data : &orion_spi_dev_data;
....@@ -647,8 +647,7 @@
647647
648648 /* The following clock is only used by some SoCs */
649649 spi->axi_clk = devm_clk_get(&pdev->dev, "axi");
650
- if (IS_ERR(spi->axi_clk) &&
651
- PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) {
650
+ if (PTR_ERR(spi->axi_clk) == -EPROBE_DEFER) {
652651 status = -EPROBE_DEFER;
653652 goto out_rel_clk;
654653 }
....@@ -683,8 +682,8 @@
683682 }
684683
685684 for_each_available_child_of_node(pdev->dev.of_node, np) {
685
+ struct orion_direct_acc *dir_acc;
686686 u32 cs;
687
- int cs_gpio;
688687
689688 /* Get chip-select number from the "reg" property */
690689 status = of_property_read_u32(np, "reg", &cs);
....@@ -693,44 +692,6 @@
693692 "%pOF has no valid 'reg' property (%d)\n",
694693 np, status);
695694 continue;
696
- }
697
-
698
- /*
699
- * Initialize the CS GPIO:
700
- * - properly request the actual GPIO signal
701
- * - de-assert the logical signal so that all GPIO CS lines
702
- * are inactive when probing for slaves
703
- * - find an unused physical CS which will be driven for any
704
- * slave which uses a CS GPIO
705
- */
706
- cs_gpio = of_get_named_gpio(pdev->dev.of_node, "cs-gpios", cs);
707
- if (cs_gpio > 0) {
708
- char *gpio_name;
709
- int cs_flags;
710
-
711
- if (spi->unused_hw_gpio == -1) {
712
- dev_info(&pdev->dev,
713
- "Selected unused HW CS#%d for any GPIO CSes\n",
714
- cs);
715
- spi->unused_hw_gpio = cs;
716
- }
717
-
718
- gpio_name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
719
- "%s-CS%d", dev_name(&pdev->dev), cs);
720
- if (!gpio_name) {
721
- status = -ENOMEM;
722
- goto out_rel_axi_clk;
723
- }
724
-
725
- cs_flags = of_property_read_bool(np, "spi-cs-high") ?
726
- GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH;
727
- status = devm_gpio_request_one(&pdev->dev, cs_gpio,
728
- cs_flags, gpio_name);
729
- if (status) {
730
- dev_err(&pdev->dev,
731
- "Can't request GPIO for CS %d\n", cs);
732
- goto out_rel_axi_clk;
733
- }
734695 }
735696
736697 /*
....@@ -747,17 +708,16 @@
747708 /*
748709 * Only map one page for direct access. This is enough for the
749710 * simple TX transfer which only writes to the first word.
750
- * This needs to get extended for the direct SPI-NOR / SPI-NAND
711
+ * This needs to get extended for the direct SPI NOR / SPI NAND
751712 * support, once this gets implemented.
752713 */
753
- spi->child[cs].direct_access.vaddr = devm_ioremap(&pdev->dev,
754
- r->start,
755
- PAGE_SIZE);
756
- if (!spi->child[cs].direct_access.vaddr) {
714
+ dir_acc = &spi->child[cs].direct_access;
715
+ dir_acc->vaddr = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE);
716
+ if (!dir_acc->vaddr) {
757717 status = -ENOMEM;
758718 goto out_rel_axi_clk;
759719 }
760
- spi->child[cs].direct_access.size = PAGE_SIZE;
720
+ dir_acc->size = PAGE_SIZE;
761721
762722 dev_info(&pdev->dev, "CS%d configured for direct access\n", cs);
763723 }
....@@ -770,9 +730,6 @@
770730 status = orion_spi_reset(spi);
771731 if (status < 0)
772732 goto out_rel_pm;
773
-
774
- pm_runtime_mark_last_busy(&pdev->dev);
775
- pm_runtime_put_autosuspend(&pdev->dev);
776733
777734 master->dev.of_node = pdev->dev.of_node;
778735 status = spi_register_master(master);