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

Merge branch 'spi-5.2' into spi-next

+2412 -653
+4
Documentation/devicetree/bindings/spi/fsl-spi.txt
··· 18 18 - gpios : specifies the gpio pins to be used for chipselects. 19 19 The gpios will be referred to as reg = <index> in the SPI child nodes. 20 20 If unspecified, a single SPI device without a chip select can be used. 21 + - fsl,spisel_boot : for the MPC8306 and MPC8309, specifies that the 22 + SPISEL_BOOT signal is used as chip select for a slave device. Use 23 + reg = <number of gpios> in the corresponding child node, i.e. 0 if 24 + the gpios property is not present. 21 25 22 26 Example: 23 27 spi@4c0 {
+20
Documentation/devicetree/bindings/spi/nvidia,tegra114-spi.txt
··· 23 23 Recommended properties: 24 24 - spi-max-frequency: Definition as per 25 25 Documentation/devicetree/bindings/spi/spi-bus.txt 26 + Optional properties: 27 + - nvidia,tx-clk-tap-delay: Delays the clock going out to the external device 28 + with this tap value. This property is used to tune the outgoing data from 29 + Tegra SPI master with respect to outgoing Tegra SPI master clock. 30 + Tap values vary based on the platform design trace lengths from Tegra SPI 31 + to corresponding slave devices. Valid tap values are from 0 thru 63. 32 + - nvidia,rx-clk-tap-delay: Delays the clock coming in from the external device 33 + with this tap value. This property is used to adjust the Tegra SPI master 34 + clock with respect to the data from the SPI slave device. 35 + Tap values vary based on the platform design trace lengths from Tegra SPI 36 + to corresponding slave devices. Valid tap values are from 0 thru 63. 37 + 26 38 Example: 27 39 28 40 spi@7000d600 { ··· 50 38 reset-names = "spi"; 51 39 dmas = <&apbdma 16>, <&apbdma 16>; 52 40 dma-names = "rx", "tx"; 41 + <spi-client>@<bus_num> { 42 + ... 43 + ... 44 + nvidia,rx-clk-tap-delay = <0>; 45 + nvidia,tx-clk-tap-delay = <16>; 46 + ... 47 + }; 48 + 53 49 };
+1
Documentation/devicetree/bindings/spi/sh-msiof.txt
··· 4 4 - compatible : "renesas,msiof-r8a7743" (RZ/G1M) 5 5 "renesas,msiof-r8a7744" (RZ/G1N) 6 6 "renesas,msiof-r8a7745" (RZ/G1E) 7 + "renesas,msiof-r8a77470" (RZ/G1C) 7 8 "renesas,msiof-r8a774a1" (RZ/G2M) 8 9 "renesas,msiof-r8a774c0" (RZ/G2E) 9 10 "renesas,msiof-r8a7790" (R-Car H2)
+9 -1
Documentation/devicetree/bindings/spi/snps,dw-apb-ssi.txt
··· 8 8 - interrupts : One interrupt, used by the controller. 9 9 - #address-cells : <1>, as required by generic SPI binding. 10 10 - #size-cells : <0>, also as required by generic SPI binding. 11 + - clocks : phandles for the clocks, see the description of clock-names below. 12 + The phandle for the "ssi_clk" is required. The phandle for the "pclk" clock 13 + is optional. If a single clock is specified but no clock-name, it is the 14 + "ssi_clk" clock. If both clocks are listed, the "ssi_clk" must be first. 11 15 12 16 Optional properties: 13 - - cs-gpios : Specifies the gpio pis to be used for chipselects. 17 + - clock-names : Contains the names of the clocks: 18 + "ssi_clk", for the core clock used to generate the external SPI clock. 19 + "pclk", the interface clock, required for register access. 20 + - cs-gpios : Specifies the gpio pins to be used for chipselects. 14 21 - num-cs : The number of chipselects. If omitted, this will default to 4. 15 22 - reg-io-width : The I/O register width (in bytes) implemented by this 16 23 device. Supported values are 2 or 4 (the default). ··· 32 25 interrupts = <0 154 4>; 33 26 #address-cells = <1>; 34 27 #size-cells = <0>; 28 + clocks = <&spi_m_clk>; 35 29 num-cs = <2>; 36 30 cs-gpios = <&gpio0 13 0>, 37 31 <&gpio0 14 0>;
+8 -2
Documentation/devicetree/bindings/spi/spi-fsl-lpspi.txt
··· 7 7 - reg : address and length of the lpspi master registers 8 8 - interrupt-parent : core interrupt controller 9 9 - interrupts : lpspi interrupt 10 - - clocks : lpspi clock specifier 10 + - clocks : lpspi clock specifier. Its number and order need to correspond to the 11 + value in clock-names. 12 + - clock-names : Corresponding to per clock and ipg clock in "clocks" 13 + respectively. In i.MX7ULP, it only has per clk, so use CLK_DUMMY 14 + to fill the "ipg" blank. 11 15 - spi-slave : spi slave mode support. In slave mode, add this attribute without 12 16 value. In master mode, remove it. 13 17 ··· 22 18 reg = <0x40290000 0x10000>; 23 19 interrupt-parent = <&intc>; 24 20 interrupts = <GIC_SPI 28 IRQ_TYPE_LEVEL_HIGH>; 25 - clocks = <&clks IMX7ULP_CLK_LPSPI2>; 21 + clocks = <&clks IMX7ULP_CLK_LPSPI2>, 22 + <&clks IMX7ULP_CLK_DUMMY>; 23 + clock-names = "per", "ipg"; 26 24 spi-slave; 27 25 };
+1
Documentation/devicetree/bindings/spi/spi-mt65xx.txt
··· 10 10 - mediatek,mt8135-spi: for mt8135 platforms 11 11 - mediatek,mt8173-spi: for mt8173 platforms 12 12 - mediatek,mt8183-spi: for mt8183 platforms 13 + - "mediatek,mt8516-spi", "mediatek,mt2712-spi": for mt8516 platforms 13 14 14 15 - #address-cells: should be 1. 15 16
+26
Documentation/devicetree/bindings/spi/spi-mt7621.txt
··· 1 + Binding for MTK SPI controller (MT7621 MIPS) 2 + 3 + Required properties: 4 + - compatible: Should be one of the following: 5 + - "ralink,mt7621-spi": for mt7621/mt7628/mt7688 platforms 6 + - #address-cells: should be 1. 7 + - #size-cells: should be 0. 8 + - reg: Address and length of the register set for the device 9 + - resets: phandle to the reset controller asserting this device in 10 + reset 11 + See ../reset/reset.txt for details. 12 + 13 + Optional properties: 14 + - cs-gpios: see spi-bus.txt. 15 + 16 + Example: 17 + 18 + - SoC Specific Portion: 19 + spi0: spi@b00 { 20 + compatible = "ralink,mt7621-spi"; 21 + reg = <0xb00 0x100>; 22 + #address-cells = <1>; 23 + #size-cells = <0>; 24 + resets = <&rstctrl 18>; 25 + reset-names = "spi"; 26 + };
+25
Documentation/devicetree/bindings/spi/spi-zynq-qspi.txt
··· 1 + Xilinx Zynq QSPI controller Device Tree Bindings 2 + ------------------------------------------------------------------- 3 + 4 + Required properties: 5 + - compatible : Should be "xlnx,zynq-qspi-1.0". 6 + - reg : Physical base address and size of QSPI registers map. 7 + - interrupts : Property with a value describing the interrupt 8 + number. 9 + - clock-names : List of input clock names - "ref_clk", "pclk" 10 + (See clock bindings for details). 11 + - clocks : Clock phandles (see clock bindings for details). 12 + 13 + Optional properties: 14 + - num-cs : Number of chip selects used. 15 + 16 + Example: 17 + qspi: spi@e000d000 { 18 + compatible = "xlnx,zynq-qspi-1.0"; 19 + reg = <0xe000d000 0x1000>; 20 + interrupt-parent = <&intc>; 21 + interrupts = <0 19 4>; 22 + clock-names = "ref_clk", "pclk"; 23 + clocks = <&clkc 10>, <&clkc 43>; 24 + num-cs = <1>; 25 + };
+6
Documentation/spi/spi-summary
··· 572 572 0: transfer is finished 573 573 1: transfer is still in progress 574 574 575 + master->set_cs_timing(struct spi_device *spi, u8 setup_clk_cycles, 576 + u8 hold_clk_cycles, u8 inactive_clk_cycles) 577 + This method allows SPI client drivers to request SPI master controller 578 + for configuring device specific CS setup, hold and inactive timing 579 + requirements. 580 + 575 581 DEPRECATED METHODS 576 582 577 583 master->transfer(struct spi_device *spi, struct spi_message *message)
+9 -4
arch/arm/mach-ep93xx/edb93xx.c
··· 29 29 #include <linux/platform_device.h> 30 30 #include <linux/i2c.h> 31 31 #include <linux/spi/spi.h> 32 + #include <linux/gpio/machine.h> 32 33 33 34 #include <sound/cs4271.h> 34 35 ··· 106 105 }, 107 106 }; 108 107 109 - static int edb93xx_spi_chipselects[] __initdata = { 110 - EP93XX_GPIO_LINE_EGPIO6, 108 + static struct gpiod_lookup_table edb93xx_spi_cs_gpio_table = { 109 + .dev_id = "ep93xx-spi.0", 110 + .table = { 111 + GPIO_LOOKUP("A", 6, "cs", GPIO_ACTIVE_LOW), 112 + { }, 113 + }, 111 114 }; 112 115 113 116 static struct ep93xx_spi_info edb93xx_spi_info __initdata = { 114 - .chipselect = edb93xx_spi_chipselects, 115 - .num_chipselect = ARRAY_SIZE(edb93xx_spi_chipselects), 117 + /* Intentionally left blank */ 116 118 }; 117 119 118 120 static void __init edb93xx_register_spi(void) ··· 127 123 else if (machine_is_edb9315a()) 128 124 edb93xx_cs4271_data.gpio_nreset = EP93XX_GPIO_LINE_EGPIO14; 129 125 126 + gpiod_add_lookup_table(&edb93xx_spi_cs_gpio_table); 130 127 ep93xx_register_spi(&edb93xx_spi_info, edb93xx_spi_board_info, 131 128 ARRAY_SIZE(edb93xx_spi_board_info)); 132 129 }
+7 -4
arch/arm/mach-ep93xx/simone.c
··· 77 77 * low between multi-message command blocks. From v1.4, it uses a GPIO instead. 78 78 * v1.3 parts will still work, since the signal on SFRMOUT is automatic. 79 79 */ 80 - static int simone_spi_chipselects[] __initdata = { 81 - EP93XX_GPIO_LINE_EGPIO1, 80 + static struct gpiod_lookup_table simone_spi_cs_gpio_table = { 81 + .dev_id = "ep93xx-spi.0", 82 + .table = { 83 + GPIO_LOOKUP("A", 1, "cs", GPIO_ACTIVE_LOW), 84 + { }, 85 + }, 82 86 }; 83 87 84 88 static struct ep93xx_spi_info simone_spi_info __initdata = { 85 - .chipselect = simone_spi_chipselects, 86 - .num_chipselect = ARRAY_SIZE(simone_spi_chipselects), 87 89 .use_dma = 1, 88 90 }; 89 91 ··· 115 113 ep93xx_register_i2c(simone_i2c_board_info, 116 114 ARRAY_SIZE(simone_i2c_board_info)); 117 115 gpiod_add_lookup_table(&simone_mmc_spi_gpio_table); 116 + gpiod_add_lookup_table(&simone_spi_cs_gpio_table); 118 117 ep93xx_register_spi(&simone_spi_info, simone_spi_devices, 119 118 ARRAY_SIZE(simone_spi_devices)); 120 119 simone_register_audio();
+17 -8
arch/arm/mach-ep93xx/ts72xx.c
··· 22 22 #include <linux/spi/mmc_spi.h> 23 23 #include <linux/mmc/host.h> 24 24 #include <linux/platform_data/spi-ep93xx.h> 25 + #include <linux/gpio/machine.h> 25 26 26 27 #include <mach/gpio-ep93xx.h> 27 28 #include <mach/hardware.h> ··· 270 269 * The all work is performed automatically by !SPI_FRAME (SFRM1) and 271 270 * goes through CPLD 272 271 */ 273 - static int bk3_spi_chipselects[] __initdata = { 274 - EP93XX_GPIO_LINE_F(3), 272 + static struct gpiod_lookup_table bk3_spi_cs_gpio_table = { 273 + .dev_id = "ep93xx-spi.0", 274 + .table = { 275 + GPIO_LOOKUP("F", 3, "cs", GPIO_ACTIVE_LOW), 276 + { }, 277 + }, 275 278 }; 276 279 277 280 static struct ep93xx_spi_info bk3_spi_master __initdata = { 278 - .chipselect = bk3_spi_chipselects, 279 - .num_chipselect = ARRAY_SIZE(bk3_spi_chipselects), 280 281 .use_dma = 1, 281 282 }; 282 283 ··· 319 316 }, 320 317 }; 321 318 322 - static int ts72xx_spi_chipselects[] __initdata = { 323 - EP93XX_GPIO_LINE_F(2), /* DIO_17 */ 319 + static struct gpiod_lookup_table ts72xx_spi_cs_gpio_table = { 320 + .dev_id = "ep93xx-spi.0", 321 + .table = { 322 + /* DIO_17 */ 323 + GPIO_LOOKUP("F", 2, "cs", GPIO_ACTIVE_LOW), 324 + { }, 325 + }, 324 326 }; 325 327 326 328 static struct ep93xx_spi_info ts72xx_spi_info __initdata = { 327 - .chipselect = ts72xx_spi_chipselects, 328 - .num_chipselect = ARRAY_SIZE(ts72xx_spi_chipselects), 329 + /* Intentionally left blank */ 329 330 }; 330 331 331 332 static void __init ts72xx_init_machine(void) ··· 346 339 if (board_is_ts7300()) 347 340 platform_device_register(&ts73xx_fpga_device); 348 341 #endif 342 + gpiod_add_lookup_table(&ts72xx_spi_cs_gpio_table); 349 343 ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices, 350 344 ARRAY_SIZE(ts72xx_spi_devices)); 351 345 } ··· 406 398 407 399 ep93xx_register_eth(&ts72xx_eth_data, 1); 408 400 401 + gpiod_add_lookup_table(&bk3_spi_cs_gpio_table); 409 402 ep93xx_register_spi(&bk3_spi_master, bk3_spi_board_info, 410 403 ARRAY_SIZE(bk3_spi_board_info)); 411 404
+9 -6
arch/arm/mach-ep93xx/vision_ep9307.c
··· 245 245 }, 246 246 }; 247 247 248 - static int vision_spi_chipselects[] __initdata = { 249 - EP93XX_GPIO_LINE_EGPIO6, 250 - EP93XX_GPIO_LINE_EGPIO7, 251 - EP93XX_GPIO_LINE_G(2), 248 + static struct gpiod_lookup_table vision_spi_cs_gpio_table = { 249 + .dev_id = "ep93xx-spi.0", 250 + .table = { 251 + GPIO_LOOKUP_IDX("A", 6, "cs", 0, GPIO_ACTIVE_LOW), 252 + GPIO_LOOKUP_IDX("A", 7, "cs", 1, GPIO_ACTIVE_LOW), 253 + GPIO_LOOKUP_IDX("G", 2, "cs", 2, GPIO_ACTIVE_LOW), 254 + { }, 255 + }, 252 256 }; 253 257 254 258 static struct ep93xx_spi_info vision_spi_master __initdata = { 255 - .chipselect = vision_spi_chipselects, 256 - .num_chipselect = ARRAY_SIZE(vision_spi_chipselects), 257 259 .use_dma = 1, 258 260 }; 259 261 ··· 297 295 ep93xx_register_i2c(vision_i2c_info, 298 296 ARRAY_SIZE(vision_i2c_info)); 299 297 gpiod_add_lookup_table(&vision_spi_mmc_gpio_table); 298 + gpiod_add_lookup_table(&vision_spi_cs_gpio_table); 300 299 ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, 301 300 ARRAY_SIZE(vision_spi_board_info)); 302 301 vision_register_i2s();
+9 -3
arch/sh/boards/mach-ecovec24/setup.c
··· 806 806 .platform_data = &mmc_spi_info, 807 807 .max_speed_hz = 5000000, 808 808 .mode = SPI_MODE_0, 809 - .controller_data = (void *) GPIO_PTM4, 810 809 }, 811 810 }; 812 811 ··· 835 836 }, 836 837 .num_resources = ARRAY_SIZE(msiof0_resources), 837 838 .resource = msiof0_resources, 839 + }; 840 + 841 + static struct gpiod_lookup_table msiof_gpio_table = { 842 + .dev_id = "spi_sh_msiof.0", 843 + .table = { 844 + GPIO_LOOKUP("sh7724_pfc", GPIO_PTM4, "cs", GPIO_ACTIVE_HIGH), 845 + { }, 846 + }, 838 847 }; 839 848 840 849 #endif ··· 1303 1296 gpio_request(GPIO_FN_MSIOF0_TXD, NULL); 1304 1297 gpio_request(GPIO_FN_MSIOF0_RXD, NULL); 1305 1298 gpio_request(GPIO_FN_MSIOF0_TSCK, NULL); 1306 - gpio_request(GPIO_PTM4, NULL); /* software CS control of TSYNC pin */ 1307 - gpio_direction_output(GPIO_PTM4, 1); /* active low CS */ 1308 1299 gpio_request(GPIO_PTB6, NULL); /* 3.3V power control */ 1309 1300 gpio_direction_output(GPIO_PTB6, 0); /* disable power by default */ 1310 1301 1311 1302 gpiod_add_lookup_table(&mmc_spi_gpio_table); 1303 + gpiod_add_lookup_table(&msiof_gpio_table); 1312 1304 spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); 1313 1305 #endif 1314 1306
+15 -1
drivers/spi/Kconfig
··· 426 426 say Y or M here.If you are not sure, say N. 427 427 SPI drivers for Mediatek MT65XX and MT81XX series ARM SoCs. 428 428 429 + config SPI_MT7621 430 + tristate "MediaTek MT7621 SPI Controller" 431 + depends on RALINK || COMPILE_TEST 432 + help 433 + This selects a driver for the MediaTek MT7621 SPI Controller. 434 + 429 435 config SPI_NPCM_PSPI 430 436 tristate "Nuvoton NPCM PSPI Controller" 431 437 depends on ARCH_NPCM || COMPILE_TEST ··· 848 842 16 bit words in SPI mode 0, automatically asserting CS on transfer 849 843 start and deasserting on end. 850 844 845 + config SPI_ZYNQ_QSPI 846 + tristate "Xilinx Zynq QSPI controller" 847 + depends on ARCH_ZYNQ || COMPILE_TEST 848 + help 849 + This enables support for the Zynq Quad SPI controller 850 + in master mode. 851 + This controller only supports SPI memory interface. 852 + 851 853 config SPI_ZYNQMP_GQSPI 852 854 tristate "Xilinx ZynqMP GQSPI controller" 853 - depends on SPI_MASTER && HAS_DMA 855 + depends on (SPI_MASTER && HAS_DMA) || COMPILE_TEST 854 856 help 855 857 Enables Xilinx GQSPI controller driver for Zynq UltraScale+ MPSoC. 856 858
+2
drivers/spi/Makefile
··· 60 60 obj-$(CONFIG_SPI_MPC52xx_PSC) += spi-mpc52xx-psc.o 61 61 obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o 62 62 obj-$(CONFIG_SPI_MT65XX) += spi-mt65xx.o 63 + obj-$(CONFIG_SPI_MT7621) += spi-mt7621.o 63 64 obj-$(CONFIG_SPI_MXIC) += spi-mxic.o 64 65 obj-$(CONFIG_SPI_MXS) += spi-mxs.o 65 66 obj-$(CONFIG_SPI_NPCM_PSPI) += spi-npcm-pspi.o ··· 119 118 obj-$(CONFIG_SPI_XILINX) += spi-xilinx.o 120 119 obj-$(CONFIG_SPI_XLP) += spi-xlp.o 121 120 obj-$(CONFIG_SPI_XTENSA_XTFPGA) += spi-xtensa-xtfpga.o 121 + obj-$(CONFIG_SPI_ZYNQ_QSPI) += spi-zynq-qspi.o 122 122 obj-$(CONFIG_SPI_ZYNQMP_GQSPI) += spi-zynqmp-gqspi.o 123 123 124 124 # SPI slave protocol handlers
+1 -1
drivers/spi/atmel-quadspi.c
··· 366 366 return err; 367 367 } 368 368 369 - const char *atmel_qspi_get_name(struct spi_mem *spimem) 369 + static const char *atmel_qspi_get_name(struct spi_mem *spimem) 370 370 { 371 371 return dev_name(spimem->spi->dev.parent); 372 372 }
+1 -7
drivers/spi/spi-at91-usart.c
··· 178 178 struct at91_usart_spi *aus = spi_master_get_devdata(spi->controller); 179 179 u32 *ausd = spi->controller_state; 180 180 unsigned int mr = at91_usart_spi_readl(aus, MR); 181 - u8 bits = spi->bits_per_word; 182 - 183 - if (bits != 8) { 184 - dev_dbg(&spi->dev, "Only 8 bits per word are supported\n"); 185 - return -EINVAL; 186 - } 187 181 188 182 if (spi->mode & SPI_CPOL) 189 183 mr |= US_MR_CPOL; ··· 206 212 207 213 dev_dbg(&spi->dev, 208 214 "setup: bpw %u mode 0x%x -> mr %d %08x\n", 209 - bits, spi->mode, spi->chip_select, mr); 215 + spi->bits_per_word, spi->mode, spi->chip_select, mr); 210 216 211 217 return 0; 212 218 }
+11 -28
drivers/spi/spi-bcm2835.c
··· 335 335 return 1; 336 336 } 337 337 338 - /* 339 - * DMA support 340 - * 341 - * this implementation has currently a few issues in so far as it does 342 - * not work arrount limitations of the HW. 343 - * 344 - * the main one being that DMA transfers are limited to 16 bit 345 - * (so 0 to 65535 bytes) by the SPI HW due to BCM2835_SPI_DLEN 346 - * 347 - * there may be a few more border-cases we may need to address as well 348 - * but unfortunately this would mean splitting up the scatter-gather 349 - * list making it slightly unpractical... 350 - */ 351 - 352 338 /** 353 339 * bcm2835_spi_transfer_prologue() - transfer first few bytes without DMA 354 340 * @master: SPI master ··· 616 630 if (tfr->len < BCM2835_SPI_DMA_MIN_LENGTH) 617 631 return false; 618 632 619 - /* BCM2835_SPI_DLEN has defined a max transfer size as 620 - * 16 bit, so max is 65535 621 - * we can revisit this by using an alternative transfer 622 - * method - ideally this would get done without any more 623 - * interaction... 624 - */ 625 - if (tfr->len > 65535) { 626 - dev_warn_once(&spi->dev, 627 - "transfer size of %d too big for dma-transfer\n", 628 - tfr->len); 629 - return false; 630 - } 631 - 632 633 /* return OK */ 633 634 return true; 634 635 } ··· 680 707 681 708 /* all went well, so set can_dma */ 682 709 master->can_dma = bcm2835_spi_can_dma; 683 - master->max_dma_len = 65535; /* limitation by BCM2835_SPI_DLEN */ 684 710 /* need to do TX AND RX DMA, so we need dummy buffers */ 685 711 master->flags = SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX; 686 712 ··· 816 844 struct spi_device *spi = msg->spi; 817 845 struct bcm2835_spi *bs = spi_master_get_devdata(master); 818 846 u32 cs = bcm2835_rd(bs, BCM2835_SPI_CS); 847 + int ret; 848 + 849 + /* 850 + * DMA transfers are limited to 16 bit (0 to 65535 bytes) by the SPI HW 851 + * due to DLEN. Split up transfers (32-bit FIFO aligned) if the limit is 852 + * exceeded. 853 + */ 854 + ret = spi_split_transfers_maxsize(master, msg, 65532, 855 + GFP_KERNEL | GFP_DMA); 856 + if (ret) 857 + return ret; 819 858 820 859 cs &= ~(BCM2835_SPI_CS_CPOL | BCM2835_SPI_CS_CPHA); 821 860
+148 -57
drivers/spi/spi-bcm2835aux.c
··· 21 21 22 22 #include <linux/clk.h> 23 23 #include <linux/completion.h> 24 + #include <linux/debugfs.h> 24 25 #include <linux/delay.h> 25 26 #include <linux/err.h> 26 27 #include <linux/interrupt.h> ··· 36 35 #include <linux/regmap.h> 37 36 #include <linux/spi/spi.h> 38 37 #include <linux/spinlock.h> 38 + 39 + /* define polling limits */ 40 + static unsigned int polling_limit_us = 30; 41 + module_param(polling_limit_us, uint, 0664); 42 + MODULE_PARM_DESC(polling_limit_us, 43 + "time in us to run a transfer in polling mode - if zero no polling is used\n"); 39 44 40 45 /* 41 46 * spi register defines ··· 95 88 #define BCM2835_AUX_SPI_STAT_BUSY 0x00000040 96 89 #define BCM2835_AUX_SPI_STAT_BITCOUNT 0x0000003F 97 90 98 - /* timeout values */ 99 - #define BCM2835_AUX_SPI_POLLING_LIMIT_US 30 100 - #define BCM2835_AUX_SPI_POLLING_JIFFIES 2 101 - 102 91 struct bcm2835aux_spi { 103 92 void __iomem *regs; 104 93 struct clk *clk; ··· 105 102 int tx_len; 106 103 int rx_len; 107 104 int pending; 105 + 106 + u64 count_transfer_polling; 107 + u64 count_transfer_irq; 108 + u64 count_transfer_irq_after_poll; 109 + 110 + struct dentry *debugfs_dir; 108 111 }; 112 + 113 + #if defined(CONFIG_DEBUG_FS) 114 + static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, 115 + const char *dname) 116 + { 117 + char name[64]; 118 + struct dentry *dir; 119 + 120 + /* get full name */ 121 + snprintf(name, sizeof(name), "spi-bcm2835aux-%s", dname); 122 + 123 + /* the base directory */ 124 + dir = debugfs_create_dir(name, NULL); 125 + bs->debugfs_dir = dir; 126 + 127 + /* the counters */ 128 + debugfs_create_u64("count_transfer_polling", 0444, dir, 129 + &bs->count_transfer_polling); 130 + debugfs_create_u64("count_transfer_irq", 0444, dir, 131 + &bs->count_transfer_irq); 132 + debugfs_create_u64("count_transfer_irq_after_poll", 0444, dir, 133 + &bs->count_transfer_irq_after_poll); 134 + } 135 + 136 + static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) 137 + { 138 + debugfs_remove_recursive(bs->debugfs_dir); 139 + bs->debugfs_dir = NULL; 140 + } 141 + #else 142 + static void bcm2835aux_debugfs_create(struct bcm2835aux_spi *bs, 143 + const char *dname) 144 + { 145 + } 146 + 147 + static void bcm2835aux_debugfs_remove(struct bcm2835aux_spi *bs) 148 + { 149 + } 150 + #endif /* CONFIG_DEBUG_FS */ 109 151 110 152 static inline u32 bcm2835aux_rd(struct bcm2835aux_spi *bs, unsigned reg) 111 153 { ··· 171 123 data = bcm2835aux_rd(bs, BCM2835_AUX_SPI_IO); 172 124 if (bs->rx_buf) { 173 125 switch (count) { 174 - case 4: 175 - *bs->rx_buf++ = (data >> 24) & 0xff; 176 - /* fallthrough */ 177 126 case 3: 178 127 *bs->rx_buf++ = (data >> 16) & 0xff; 179 128 /* fallthrough */ ··· 223 178 BCM2835_AUX_SPI_CNTL0_CLEARFIFO); 224 179 } 225 180 226 - static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id) 181 + static void bcm2835aux_spi_transfer_helper(struct bcm2835aux_spi *bs) 227 182 { 228 - struct spi_master *master = dev_id; 229 - struct bcm2835aux_spi *bs = spi_master_get_devdata(master); 230 - irqreturn_t ret = IRQ_NONE; 231 - 232 - /* IRQ may be shared, so return if our interrupts are disabled */ 233 - if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) & 234 - (BCM2835_AUX_SPI_CNTL1_TXEMPTY | BCM2835_AUX_SPI_CNTL1_IDLE))) 235 - return ret; 183 + u32 stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); 236 184 237 185 /* check if we have data to read */ 238 - while (bs->rx_len && 239 - (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & 240 - BCM2835_AUX_SPI_STAT_RX_EMPTY))) { 186 + for (; bs->rx_len && (stat & BCM2835_AUX_SPI_STAT_RX_LVL); 187 + stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT)) 241 188 bcm2835aux_rd_fifo(bs); 242 - ret = IRQ_HANDLED; 243 - } 244 189 245 190 /* check if we have data to write */ 246 191 while (bs->tx_len && ··· 238 203 (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & 239 204 BCM2835_AUX_SPI_STAT_TX_FULL))) { 240 205 bcm2835aux_wr_fifo(bs); 241 - ret = IRQ_HANDLED; 242 206 } 207 + } 243 208 244 - /* and check if we have reached "done" */ 245 - while (bs->rx_len && 246 - (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT) & 247 - BCM2835_AUX_SPI_STAT_BUSY))) { 248 - bcm2835aux_rd_fifo(bs); 249 - ret = IRQ_HANDLED; 250 - } 209 + static irqreturn_t bcm2835aux_spi_interrupt(int irq, void *dev_id) 210 + { 211 + struct spi_master *master = dev_id; 212 + struct bcm2835aux_spi *bs = spi_master_get_devdata(master); 213 + 214 + /* IRQ may be shared, so return if our interrupts are disabled */ 215 + if (!(bcm2835aux_rd(bs, BCM2835_AUX_SPI_CNTL1) & 216 + (BCM2835_AUX_SPI_CNTL1_TXEMPTY | BCM2835_AUX_SPI_CNTL1_IDLE))) 217 + return IRQ_NONE; 218 + 219 + /* do common fifo handling */ 220 + bcm2835aux_spi_transfer_helper(bs); 251 221 252 222 if (!bs->tx_len) { 253 223 /* disable tx fifo empty interrupt */ ··· 266 226 complete(&master->xfer_completion); 267 227 } 268 228 269 - /* and return */ 270 - return ret; 229 + return IRQ_HANDLED; 271 230 } 272 231 273 232 static int __bcm2835aux_spi_transfer_one_irq(struct spi_master *master, ··· 290 251 { 291 252 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); 292 253 254 + /* update statistics */ 255 + bs->count_transfer_irq++; 256 + 293 257 /* fill in registers and fifos before enabling interrupts */ 294 258 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); 295 259 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); ··· 315 273 { 316 274 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); 317 275 unsigned long timeout; 318 - u32 stat; 276 + 277 + /* update statistics */ 278 + bs->count_transfer_polling++; 319 279 320 280 /* configure spi */ 321 281 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]); 322 282 bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]); 323 283 324 - /* set the timeout */ 325 - timeout = jiffies + BCM2835_AUX_SPI_POLLING_JIFFIES; 284 + /* set the timeout to at least 2 jiffies */ 285 + timeout = jiffies + 2 + HZ * polling_limit_us / 1000000; 326 286 327 287 /* loop until finished the transfer */ 328 288 while (bs->rx_len) { 329 - /* read status */ 330 - stat = bcm2835aux_rd(bs, BCM2835_AUX_SPI_STAT); 331 289 332 - /* fill in tx fifo with remaining data */ 333 - if ((bs->tx_len) && (!(stat & BCM2835_AUX_SPI_STAT_TX_FULL))) { 334 - bcm2835aux_wr_fifo(bs); 335 - continue; 336 - } 337 - 338 - /* read data from fifo for both cases */ 339 - if (!(stat & BCM2835_AUX_SPI_STAT_RX_EMPTY)) { 340 - bcm2835aux_rd_fifo(bs); 341 - continue; 342 - } 343 - if (!(stat & BCM2835_AUX_SPI_STAT_BUSY)) { 344 - bcm2835aux_rd_fifo(bs); 345 - continue; 346 - } 290 + /* do common fifo handling */ 291 + bcm2835aux_spi_transfer_helper(bs); 347 292 348 293 /* there is still data pending to read check the timeout */ 349 294 if (bs->rx_len && time_after(jiffies, timeout)) { ··· 339 310 jiffies - timeout, 340 311 bs->tx_len, bs->rx_len); 341 312 /* forward to interrupt handler */ 313 + bs->count_transfer_irq_after_poll++; 342 314 return __bcm2835aux_spi_transfer_one_irq(master, 343 315 spi, tfr); 344 316 } ··· 354 324 struct spi_transfer *tfr) 355 325 { 356 326 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); 357 - unsigned long spi_hz, clk_hz, speed; 358 - unsigned long spi_used_hz; 327 + unsigned long spi_hz, clk_hz, speed, spi_used_hz; 328 + unsigned long hz_per_byte, byte_limit; 359 329 360 330 /* calculate the registers to handle 361 331 * ··· 399 369 * of Hz per byte per polling limit. E.g., we can transfer 1 byte in 400 370 * 30 µs per 300,000 Hz of bus clock. 401 371 */ 402 - #define HZ_PER_BYTE ((9 * 1000000) / BCM2835_AUX_SPI_POLLING_LIMIT_US) 372 + hz_per_byte = polling_limit_us ? (9 * 1000000) / polling_limit_us : 0; 373 + byte_limit = hz_per_byte ? spi_used_hz / hz_per_byte : 1; 374 + 403 375 /* run in polling mode for short transfers */ 404 - if (tfr->len < spi_used_hz / HZ_PER_BYTE) 376 + if (tfr->len < byte_limit) 405 377 return bcm2835aux_spi_transfer_one_poll(master, spi, tfr); 406 378 407 379 /* run in interrupt mode for all others */ 408 380 return bcm2835aux_spi_transfer_one_irq(master, spi, tfr); 409 - #undef HZ_PER_BYTE 410 381 } 411 382 412 383 static int bcm2835aux_spi_prepare_message(struct spi_master *master, ··· 452 421 bcm2835aux_spi_reset_hw(bs); 453 422 } 454 423 424 + static int bcm2835aux_spi_setup(struct spi_device *spi) 425 + { 426 + int ret; 427 + 428 + /* sanity check for native cs */ 429 + if (spi->mode & SPI_NO_CS) 430 + return 0; 431 + if (gpio_is_valid(spi->cs_gpio)) { 432 + /* with gpio-cs set the GPIO to the correct level 433 + * and as output (in case the dt has the gpio not configured 434 + * as output but native cs) 435 + */ 436 + ret = gpio_direction_output(spi->cs_gpio, 437 + (spi->mode & SPI_CS_HIGH) ? 0 : 1); 438 + if (ret) 439 + dev_err(&spi->dev, 440 + "could not set gpio %i as output: %i\n", 441 + spi->cs_gpio, ret); 442 + 443 + return ret; 444 + } 445 + 446 + /* for dt-backwards compatibility: only support native on CS0 447 + * known things not supported with broken native CS: 448 + * * multiple chip-selects: cs0-cs2 are all 449 + * simultaniously asserted whenever there is a transfer 450 + * this even includes SPI_NO_CS 451 + * * SPI_CS_HIGH: cs are always asserted low 452 + * * cs_change: cs is deasserted after each spi_transfer 453 + * * cs_delay_usec: cs is always deasserted one SCK cycle 454 + * after the last transfer 455 + * probably more... 456 + */ 457 + dev_warn(&spi->dev, 458 + "Native CS is not supported - please configure cs-gpio in device-tree\n"); 459 + 460 + if (spi->chip_select == 0) 461 + return 0; 462 + 463 + dev_warn(&spi->dev, "Native CS is not working for cs > 0\n"); 464 + 465 + return -EINVAL; 466 + } 467 + 455 468 static int bcm2835aux_spi_probe(struct platform_device *pdev) 456 469 { 457 470 struct spi_master *master; ··· 513 438 platform_set_drvdata(pdev, master); 514 439 master->mode_bits = (SPI_CPOL | SPI_CS_HIGH | SPI_NO_CS); 515 440 master->bits_per_word_mask = SPI_BPW_MASK(8); 516 - master->num_chipselect = -1; 441 + /* even though the driver never officially supported native CS 442 + * allow a single native CS for legacy DT support purposes when 443 + * no cs-gpio is configured. 444 + * Known limitations for native cs are: 445 + * * multiple chip-selects: cs0-cs2 are all simultaniously asserted 446 + * whenever there is a transfer - this even includes SPI_NO_CS 447 + * * SPI_CS_HIGH: is ignores - cs are always asserted low 448 + * * cs_change: cs is deasserted after each spi_transfer 449 + * * cs_delay_usec: cs is always deasserted one SCK cycle after 450 + * a spi_transfer 451 + */ 452 + master->num_chipselect = 1; 453 + master->setup = bcm2835aux_spi_setup; 517 454 master->transfer_one = bcm2835aux_spi_transfer_one; 518 455 master->handle_err = bcm2835aux_spi_handle_err; 519 456 master->prepare_message = bcm2835aux_spi_prepare_message; ··· 589 502 goto out_clk_disable; 590 503 } 591 504 505 + bcm2835aux_debugfs_create(bs, dev_name(&pdev->dev)); 506 + 592 507 return 0; 593 508 594 509 out_clk_disable: ··· 604 515 { 605 516 struct spi_master *master = platform_get_drvdata(pdev); 606 517 struct bcm2835aux_spi *bs = spi_master_get_devdata(master); 518 + 519 + bcm2835aux_debugfs_remove(bs); 607 520 608 521 bcm2835aux_spi_reset_hw(bs); 609 522
+39 -27
drivers/spi/spi-bitbang.c
··· 335 335 336 336 /*----------------------------------------------------------------------*/ 337 337 338 + int spi_bitbang_init(struct spi_bitbang *bitbang) 339 + { 340 + struct spi_master *master = bitbang->master; 341 + 342 + if (!master || !bitbang->chipselect) 343 + return -EINVAL; 344 + 345 + mutex_init(&bitbang->lock); 346 + 347 + if (!master->mode_bits) 348 + master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags; 349 + 350 + if (master->transfer || master->transfer_one_message) 351 + return -EINVAL; 352 + 353 + master->prepare_transfer_hardware = spi_bitbang_prepare_hardware; 354 + master->unprepare_transfer_hardware = spi_bitbang_unprepare_hardware; 355 + master->transfer_one = spi_bitbang_transfer_one; 356 + master->set_cs = spi_bitbang_set_cs; 357 + 358 + if (!bitbang->txrx_bufs) { 359 + bitbang->use_dma = 0; 360 + bitbang->txrx_bufs = spi_bitbang_bufs; 361 + if (!master->setup) { 362 + if (!bitbang->setup_transfer) 363 + bitbang->setup_transfer = 364 + spi_bitbang_setup_transfer; 365 + master->setup = spi_bitbang_setup; 366 + master->cleanup = spi_bitbang_cleanup; 367 + } 368 + } 369 + 370 + return 0; 371 + } 372 + EXPORT_SYMBOL_GPL(spi_bitbang_init); 373 + 338 374 /** 339 375 * spi_bitbang_start - start up a polled/bitbanging SPI master driver 340 376 * @bitbang: driver handle ··· 404 368 struct spi_master *master = bitbang->master; 405 369 int ret; 406 370 407 - if (!master || !bitbang->chipselect) 408 - return -EINVAL; 409 - 410 - mutex_init(&bitbang->lock); 411 - 412 - if (!master->mode_bits) 413 - master->mode_bits = SPI_CPOL | SPI_CPHA | bitbang->flags; 414 - 415 - if (master->transfer || master->transfer_one_message) 416 - return -EINVAL; 417 - 418 - master->prepare_transfer_hardware = spi_bitbang_prepare_hardware; 419 - master->unprepare_transfer_hardware = spi_bitbang_unprepare_hardware; 420 - master->transfer_one = spi_bitbang_transfer_one; 421 - master->set_cs = spi_bitbang_set_cs; 422 - 423 - if (!bitbang->txrx_bufs) { 424 - bitbang->use_dma = 0; 425 - bitbang->txrx_bufs = spi_bitbang_bufs; 426 - if (!master->setup) { 427 - if (!bitbang->setup_transfer) 428 - bitbang->setup_transfer = 429 - spi_bitbang_setup_transfer; 430 - master->setup = spi_bitbang_setup; 431 - master->cleanup = spi_bitbang_cleanup; 432 - } 433 - } 371 + ret = spi_bitbang_init(bitbang); 372 + if (ret) 373 + return ret; 434 374 435 375 /* driver may get busy before register() returns, especially 436 376 * if someone registered boardinfo for devices
+12
drivers/spi/spi-dw-mmio.c
··· 30 30 struct dw_spi_mmio { 31 31 struct dw_spi dws; 32 32 struct clk *clk; 33 + struct clk *pclk; 33 34 void *priv; 34 35 }; 35 36 ··· 173 172 if (ret) 174 173 return ret; 175 174 175 + /* Optional clock needed to access the registers */ 176 + dwsmmio->pclk = devm_clk_get_optional(&pdev->dev, "pclk"); 177 + if (IS_ERR(dwsmmio->pclk)) 178 + return PTR_ERR(dwsmmio->pclk); 179 + ret = clk_prepare_enable(dwsmmio->pclk); 180 + if (ret) 181 + goto out_clk; 182 + 176 183 dws->bus_num = pdev->id; 177 184 178 185 dws->max_freq = clk_get_rate(dwsmmio->clk); ··· 208 199 return 0; 209 200 210 201 out: 202 + clk_disable_unprepare(dwsmmio->pclk); 203 + out_clk: 211 204 clk_disable_unprepare(dwsmmio->clk); 212 205 return ret; 213 206 } ··· 219 208 struct dw_spi_mmio *dwsmmio = platform_get_drvdata(pdev); 220 209 221 210 dw_spi_remove_host(&dwsmmio->dws); 211 + clk_disable_unprepare(dwsmmio->pclk); 222 212 clk_disable_unprepare(dwsmmio->clk); 223 213 224 214 return 0;
+6 -26
drivers/spi/spi-ep93xx.c
··· 28 28 #include <linux/platform_device.h> 29 29 #include <linux/sched.h> 30 30 #include <linux/scatterlist.h> 31 - #include <linux/gpio.h> 32 31 #include <linux/spi/spi.h> 33 32 34 33 #include <linux/platform_data/dma-ep93xx.h> ··· 675 676 if (!master) 676 677 return -ENOMEM; 677 678 679 + master->use_gpio_descriptors = true; 678 680 master->prepare_transfer_hardware = ep93xx_spi_prepare_hardware; 679 681 master->unprepare_transfer_hardware = ep93xx_spi_unprepare_hardware; 680 682 master->prepare_message = ep93xx_spi_prepare_message; ··· 683 683 master->bus_num = pdev->id; 684 684 master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 685 685 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 - } 686 + /* 687 + * The SPI core will count the number of GPIO descriptors to figure 688 + * out the number of chip selects available on the platform. 689 + */ 690 + master->num_chipselect = 0; 711 691 712 692 platform_set_drvdata(pdev, master); 713 693
+2
drivers/spi/spi-fsl-lib.h
··· 95 95 96 96 struct mpc8xxx_spi_probe_info { 97 97 struct fsl_spi_platform_data pdata; 98 + int ngpios; 98 99 int *gpios; 99 100 bool *alow_flags; 101 + __be32 __iomem *immr_spi_cs; 100 102 }; 101 103 102 104 extern u32 mpc8xxx_spi_tx_buf_u8(struct mpc8xxx_spi *mpc8xxx_spi);
+506 -63
drivers/spi/spi-fsl-lpspi.c
··· 8 8 #include <linux/clk.h> 9 9 #include <linux/completion.h> 10 10 #include <linux/delay.h> 11 + #include <linux/dmaengine.h> 12 + #include <linux/dma-mapping.h> 11 13 #include <linux/err.h> 14 + #include <linux/gpio.h> 12 15 #include <linux/interrupt.h> 13 16 #include <linux/io.h> 14 17 #include <linux/irq.h> ··· 19 16 #include <linux/module.h> 20 17 #include <linux/of.h> 21 18 #include <linux/of_device.h> 19 + #include <linux/of_gpio.h> 20 + #include <linux/pinctrl/consumer.h> 22 21 #include <linux/platform_device.h> 22 + #include <linux/platform_data/dma-imx.h> 23 + #include <linux/platform_data/spi-imx.h> 24 + #include <linux/pm_runtime.h> 23 25 #include <linux/slab.h> 24 26 #include <linux/spi/spi.h> 25 27 #include <linux/spi/spi_bitbang.h> 26 28 #include <linux/types.h> 27 29 28 30 #define DRIVER_NAME "fsl_lpspi" 31 + 32 + #define FSL_LPSPI_RPM_TIMEOUT 50 /* 50ms */ 33 + 34 + /* The maximum bytes that edma can transfer once.*/ 35 + #define FSL_LPSPI_MAX_EDMA_BYTES ((1 << 15) - 1) 29 36 30 37 /* i.MX7ULP LPSPI registers */ 31 38 #define IMX7ULP_VERID 0x0 ··· 70 57 #define IER_FCIE BIT(9) 71 58 #define IER_RDIE BIT(1) 72 59 #define IER_TDIE BIT(0) 60 + #define DER_RDDE BIT(1) 61 + #define DER_TDDE BIT(0) 73 62 #define CFGR1_PCSCFG BIT(27) 74 63 #define CFGR1_PINCFG (BIT(24)|BIT(25)) 75 64 #define CFGR1_PCSPOL BIT(8) ··· 99 84 struct fsl_lpspi_data { 100 85 struct device *dev; 101 86 void __iomem *base; 102 - struct clk *clk; 87 + unsigned long base_phys; 88 + struct clk *clk_ipg; 89 + struct clk *clk_per; 103 90 bool is_slave; 91 + bool is_first_byte; 104 92 105 93 void *rx_buf; 106 94 const void *tx_buf; ··· 119 101 struct completion xfer_done; 120 102 121 103 bool slave_aborted; 104 + 105 + /* DMA */ 106 + bool usedma; 107 + struct completion dma_rx_completion; 108 + struct completion dma_tx_completion; 109 + 110 + int chipselect[0]; 122 111 }; 123 112 124 113 static const struct of_device_id fsl_lpspi_dt_ids[] = { ··· 172 147 writel(enable, fsl_lpspi->base + IMX7ULP_IER); 173 148 } 174 149 150 + static int fsl_lpspi_bytes_per_word(const int bpw) 151 + { 152 + return DIV_ROUND_UP(bpw, BITS_PER_BYTE); 153 + } 154 + 155 + static bool fsl_lpspi_can_dma(struct spi_controller *controller, 156 + struct spi_device *spi, 157 + struct spi_transfer *transfer) 158 + { 159 + unsigned int bytes_per_word; 160 + 161 + if (!controller->dma_rx) 162 + return false; 163 + 164 + bytes_per_word = fsl_lpspi_bytes_per_word(transfer->bits_per_word); 165 + 166 + switch (bytes_per_word) 167 + { 168 + case 1: 169 + case 2: 170 + case 4: 171 + break; 172 + default: 173 + return false; 174 + } 175 + 176 + return true; 177 + } 178 + 175 179 static int lpspi_prepare_xfer_hardware(struct spi_controller *controller) 176 180 { 177 181 struct fsl_lpspi_data *fsl_lpspi = 178 182 spi_controller_get_devdata(controller); 183 + int ret; 179 184 180 - return clk_prepare_enable(fsl_lpspi->clk); 185 + ret = pm_runtime_get_sync(fsl_lpspi->dev); 186 + if (ret < 0) { 187 + dev_err(fsl_lpspi->dev, "failed to enable clock\n"); 188 + return ret; 189 + } 190 + 191 + return 0; 181 192 } 182 193 183 194 static int lpspi_unprepare_xfer_hardware(struct spi_controller *controller) ··· 221 160 struct fsl_lpspi_data *fsl_lpspi = 222 161 spi_controller_get_devdata(controller); 223 162 224 - clk_disable_unprepare(fsl_lpspi->clk); 163 + pm_runtime_mark_last_busy(fsl_lpspi->dev); 164 + pm_runtime_put_autosuspend(fsl_lpspi->dev); 165 + 166 + return 0; 167 + } 168 + 169 + static int fsl_lpspi_prepare_message(struct spi_controller *controller, 170 + struct spi_message *msg) 171 + { 172 + struct fsl_lpspi_data *fsl_lpspi = 173 + spi_controller_get_devdata(controller); 174 + struct spi_device *spi = msg->spi; 175 + int gpio = fsl_lpspi->chipselect[spi->chip_select]; 176 + 177 + if (gpio_is_valid(gpio)) 178 + gpio_direction_output(gpio, spi->mode & SPI_CS_HIGH ? 0 : 1); 225 179 226 180 return 0; 227 181 } ··· 273 197 fsl_lpspi->rx(fsl_lpspi); 274 198 } 275 199 276 - static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi, 277 - bool is_first_xfer) 200 + static void fsl_lpspi_set_cmd(struct fsl_lpspi_data *fsl_lpspi) 278 201 { 279 202 u32 temp = 0; 280 203 ··· 288 213 * For the first transfer, clear TCR_CONTC to assert SS. 289 214 * For subsequent transfer, set TCR_CONTC to keep SS asserted. 290 215 */ 291 - temp |= TCR_CONT; 292 - if (is_first_xfer) 293 - temp &= ~TCR_CONTC; 294 - else 295 - temp |= TCR_CONTC; 216 + if (!fsl_lpspi->usedma) { 217 + temp |= TCR_CONT; 218 + if (fsl_lpspi->is_first_byte) 219 + temp &= ~TCR_CONTC; 220 + else 221 + temp |= TCR_CONTC; 222 + } 296 223 } 297 224 writel(temp, fsl_lpspi->base + IMX7ULP_TCR); 298 225 ··· 305 228 { 306 229 u32 temp; 307 230 308 - temp = fsl_lpspi->watermark >> 1 | (fsl_lpspi->watermark >> 1) << 16; 231 + if (!fsl_lpspi->usedma) 232 + temp = fsl_lpspi->watermark >> 1 | 233 + (fsl_lpspi->watermark >> 1) << 16; 234 + else 235 + temp = fsl_lpspi->watermark >> 1; 309 236 310 237 writel(temp, fsl_lpspi->base + IMX7ULP_FCR); 311 238 ··· 322 241 unsigned int perclk_rate, scldiv; 323 242 u8 prescale; 324 243 325 - perclk_rate = clk_get_rate(fsl_lpspi->clk); 244 + perclk_rate = clk_get_rate(fsl_lpspi->clk_per); 245 + 246 + if (config.speed_hz > perclk_rate / 2) { 247 + dev_err(fsl_lpspi->dev, 248 + "per-clk should be at least two times of transfer speed"); 249 + return -EINVAL; 250 + } 251 + 326 252 for (prescale = 0; prescale < 8; prescale++) { 327 253 scldiv = perclk_rate / 328 254 (clkdivs[prescale] * config.speed_hz) - 2; ··· 345 257 writel(scldiv | (scldiv << 8) | ((scldiv >> 1) << 16), 346 258 fsl_lpspi->base + IMX7ULP_CCR); 347 259 348 - dev_dbg(fsl_lpspi->dev, "perclk=%d, speed=%d, prescale =%d, scldiv=%d\n", 260 + dev_dbg(fsl_lpspi->dev, "perclk=%d, speed=%d, prescale=%d, scldiv=%d\n", 349 261 perclk_rate, config.speed_hz, prescale, scldiv); 262 + 263 + return 0; 264 + } 265 + 266 + static int fsl_lpspi_dma_configure(struct spi_controller *controller) 267 + { 268 + int ret; 269 + enum dma_slave_buswidth buswidth; 270 + struct dma_slave_config rx = {}, tx = {}; 271 + struct fsl_lpspi_data *fsl_lpspi = 272 + spi_controller_get_devdata(controller); 273 + 274 + switch (fsl_lpspi_bytes_per_word(fsl_lpspi->config.bpw)) { 275 + case 4: 276 + buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; 277 + break; 278 + case 2: 279 + buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; 280 + break; 281 + case 1: 282 + buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; 283 + break; 284 + default: 285 + return -EINVAL; 286 + } 287 + 288 + tx.direction = DMA_MEM_TO_DEV; 289 + tx.dst_addr = fsl_lpspi->base_phys + IMX7ULP_TDR; 290 + tx.dst_addr_width = buswidth; 291 + tx.dst_maxburst = 1; 292 + ret = dmaengine_slave_config(controller->dma_tx, &tx); 293 + if (ret) { 294 + dev_err(fsl_lpspi->dev, "TX dma configuration failed with %d\n", 295 + ret); 296 + return ret; 297 + } 298 + 299 + rx.direction = DMA_DEV_TO_MEM; 300 + rx.src_addr = fsl_lpspi->base_phys + IMX7ULP_RDR; 301 + rx.src_addr_width = buswidth; 302 + rx.src_maxburst = 1; 303 + ret = dmaengine_slave_config(controller->dma_rx, &rx); 304 + if (ret) { 305 + dev_err(fsl_lpspi->dev, "RX dma configuration failed with %d\n", 306 + ret); 307 + return ret; 308 + } 350 309 351 310 return 0; 352 311 } ··· 423 288 temp |= CR_RRF | CR_RTF | CR_MEN; 424 289 writel(temp, fsl_lpspi->base + IMX7ULP_CR); 425 290 291 + temp = 0; 292 + if (fsl_lpspi->usedma) 293 + temp = DER_TDDE | DER_RDDE; 294 + writel(temp, fsl_lpspi->base + IMX7ULP_DER); 295 + 426 296 return 0; 427 297 } 428 298 429 - static void fsl_lpspi_setup_transfer(struct spi_device *spi, 299 + static int fsl_lpspi_setup_transfer(struct spi_controller *controller, 300 + struct spi_device *spi, 430 301 struct spi_transfer *t) 431 302 { 432 303 struct fsl_lpspi_data *fsl_lpspi = 433 304 spi_controller_get_devdata(spi->controller); 434 305 306 + if (t == NULL) 307 + return -EINVAL; 308 + 435 309 fsl_lpspi->config.mode = spi->mode; 436 - fsl_lpspi->config.bpw = t ? t->bits_per_word : spi->bits_per_word; 437 - fsl_lpspi->config.speed_hz = t ? t->speed_hz : spi->max_speed_hz; 310 + fsl_lpspi->config.bpw = t->bits_per_word; 311 + fsl_lpspi->config.speed_hz = t->speed_hz; 438 312 fsl_lpspi->config.chip_select = spi->chip_select; 439 313 440 314 if (!fsl_lpspi->config.speed_hz) ··· 468 324 else 469 325 fsl_lpspi->watermark = fsl_lpspi->txfifosize; 470 326 471 - fsl_lpspi_config(fsl_lpspi); 327 + if (fsl_lpspi_can_dma(controller, spi, t)) 328 + fsl_lpspi->usedma = 1; 329 + else 330 + fsl_lpspi->usedma = 0; 331 + 332 + return fsl_lpspi_config(fsl_lpspi); 472 333 } 473 334 474 335 static int fsl_lpspi_slave_abort(struct spi_controller *controller) ··· 482 333 spi_controller_get_devdata(controller); 483 334 484 335 fsl_lpspi->slave_aborted = true; 485 - complete(&fsl_lpspi->xfer_done); 336 + if (!fsl_lpspi->usedma) 337 + complete(&fsl_lpspi->xfer_done); 338 + else { 339 + complete(&fsl_lpspi->dma_tx_completion); 340 + complete(&fsl_lpspi->dma_rx_completion); 341 + } 342 + 486 343 return 0; 487 344 } 488 345 ··· 517 362 { 518 363 u32 temp; 519 364 520 - /* Disable all interrupt */ 521 - fsl_lpspi_intctrl(fsl_lpspi, 0); 365 + if (!fsl_lpspi->usedma) { 366 + /* Disable all interrupt */ 367 + fsl_lpspi_intctrl(fsl_lpspi, 0); 368 + } 522 369 523 370 /* W1C for all flags in SR */ 524 371 temp = 0x3F << 8; ··· 533 376 return 0; 534 377 } 535 378 536 - static int fsl_lpspi_transfer_one(struct spi_controller *controller, 537 - struct spi_device *spi, 379 + static void fsl_lpspi_dma_rx_callback(void *cookie) 380 + { 381 + struct fsl_lpspi_data *fsl_lpspi = (struct fsl_lpspi_data *)cookie; 382 + 383 + complete(&fsl_lpspi->dma_rx_completion); 384 + } 385 + 386 + static void fsl_lpspi_dma_tx_callback(void *cookie) 387 + { 388 + struct fsl_lpspi_data *fsl_lpspi = (struct fsl_lpspi_data *)cookie; 389 + 390 + complete(&fsl_lpspi->dma_tx_completion); 391 + } 392 + 393 + static int fsl_lpspi_calculate_timeout(struct fsl_lpspi_data *fsl_lpspi, 394 + int size) 395 + { 396 + unsigned long timeout = 0; 397 + 398 + /* Time with actual data transfer and CS change delay related to HW */ 399 + timeout = (8 + 4) * size / fsl_lpspi->config.speed_hz; 400 + 401 + /* Add extra second for scheduler related activities */ 402 + timeout += 1; 403 + 404 + /* Double calculated timeout */ 405 + return msecs_to_jiffies(2 * timeout * MSEC_PER_SEC); 406 + } 407 + 408 + static int fsl_lpspi_dma_transfer(struct spi_controller *controller, 409 + struct fsl_lpspi_data *fsl_lpspi, 410 + struct spi_transfer *transfer) 411 + { 412 + struct dma_async_tx_descriptor *desc_tx, *desc_rx; 413 + unsigned long transfer_timeout; 414 + unsigned long timeout; 415 + struct sg_table *tx = &transfer->tx_sg, *rx = &transfer->rx_sg; 416 + int ret; 417 + 418 + ret = fsl_lpspi_dma_configure(controller); 419 + if (ret) 420 + return ret; 421 + 422 + desc_rx = dmaengine_prep_slave_sg(controller->dma_rx, 423 + rx->sgl, rx->nents, DMA_DEV_TO_MEM, 424 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 425 + if (!desc_rx) 426 + return -EINVAL; 427 + 428 + desc_rx->callback = fsl_lpspi_dma_rx_callback; 429 + desc_rx->callback_param = (void *)fsl_lpspi; 430 + dmaengine_submit(desc_rx); 431 + reinit_completion(&fsl_lpspi->dma_rx_completion); 432 + dma_async_issue_pending(controller->dma_rx); 433 + 434 + desc_tx = dmaengine_prep_slave_sg(controller->dma_tx, 435 + tx->sgl, tx->nents, DMA_MEM_TO_DEV, 436 + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 437 + if (!desc_tx) { 438 + dmaengine_terminate_all(controller->dma_tx); 439 + return -EINVAL; 440 + } 441 + 442 + desc_tx->callback = fsl_lpspi_dma_tx_callback; 443 + desc_tx->callback_param = (void *)fsl_lpspi; 444 + dmaengine_submit(desc_tx); 445 + reinit_completion(&fsl_lpspi->dma_tx_completion); 446 + dma_async_issue_pending(controller->dma_tx); 447 + 448 + fsl_lpspi->slave_aborted = false; 449 + 450 + if (!fsl_lpspi->is_slave) { 451 + transfer_timeout = fsl_lpspi_calculate_timeout(fsl_lpspi, 452 + transfer->len); 453 + 454 + /* Wait eDMA to finish the data transfer.*/ 455 + timeout = wait_for_completion_timeout(&fsl_lpspi->dma_tx_completion, 456 + transfer_timeout); 457 + if (!timeout) { 458 + dev_err(fsl_lpspi->dev, "I/O Error in DMA TX\n"); 459 + dmaengine_terminate_all(controller->dma_tx); 460 + dmaengine_terminate_all(controller->dma_rx); 461 + fsl_lpspi_reset(fsl_lpspi); 462 + return -ETIMEDOUT; 463 + } 464 + 465 + timeout = wait_for_completion_timeout(&fsl_lpspi->dma_rx_completion, 466 + transfer_timeout); 467 + if (!timeout) { 468 + dev_err(fsl_lpspi->dev, "I/O Error in DMA RX\n"); 469 + dmaengine_terminate_all(controller->dma_tx); 470 + dmaengine_terminate_all(controller->dma_rx); 471 + fsl_lpspi_reset(fsl_lpspi); 472 + return -ETIMEDOUT; 473 + } 474 + } else { 475 + if (wait_for_completion_interruptible(&fsl_lpspi->dma_tx_completion) || 476 + fsl_lpspi->slave_aborted) { 477 + dev_dbg(fsl_lpspi->dev, 478 + "I/O Error in DMA TX interrupted\n"); 479 + dmaengine_terminate_all(controller->dma_tx); 480 + dmaengine_terminate_all(controller->dma_rx); 481 + fsl_lpspi_reset(fsl_lpspi); 482 + return -EINTR; 483 + } 484 + 485 + if (wait_for_completion_interruptible(&fsl_lpspi->dma_rx_completion) || 486 + fsl_lpspi->slave_aborted) { 487 + dev_dbg(fsl_lpspi->dev, 488 + "I/O Error in DMA RX interrupted\n"); 489 + dmaengine_terminate_all(controller->dma_tx); 490 + dmaengine_terminate_all(controller->dma_rx); 491 + fsl_lpspi_reset(fsl_lpspi); 492 + return -EINTR; 493 + } 494 + } 495 + 496 + fsl_lpspi_reset(fsl_lpspi); 497 + 498 + return 0; 499 + } 500 + 501 + static void fsl_lpspi_dma_exit(struct spi_controller *controller) 502 + { 503 + if (controller->dma_rx) { 504 + dma_release_channel(controller->dma_rx); 505 + controller->dma_rx = NULL; 506 + } 507 + 508 + if (controller->dma_tx) { 509 + dma_release_channel(controller->dma_tx); 510 + controller->dma_tx = NULL; 511 + } 512 + } 513 + 514 + static int fsl_lpspi_dma_init(struct device *dev, 515 + struct fsl_lpspi_data *fsl_lpspi, 516 + struct spi_controller *controller) 517 + { 518 + int ret; 519 + 520 + /* Prepare for TX DMA: */ 521 + controller->dma_tx = dma_request_slave_channel_reason(dev, "tx"); 522 + if (IS_ERR(controller->dma_tx)) { 523 + ret = PTR_ERR(controller->dma_tx); 524 + dev_dbg(dev, "can't get the TX DMA channel, error %d!\n", ret); 525 + controller->dma_tx = NULL; 526 + goto err; 527 + } 528 + 529 + /* Prepare for RX DMA: */ 530 + controller->dma_rx = dma_request_slave_channel_reason(dev, "rx"); 531 + if (IS_ERR(controller->dma_rx)) { 532 + ret = PTR_ERR(controller->dma_rx); 533 + dev_dbg(dev, "can't get the RX DMA channel, error %d\n", ret); 534 + controller->dma_rx = NULL; 535 + goto err; 536 + } 537 + 538 + init_completion(&fsl_lpspi->dma_rx_completion); 539 + init_completion(&fsl_lpspi->dma_tx_completion); 540 + controller->can_dma = fsl_lpspi_can_dma; 541 + controller->max_dma_len = FSL_LPSPI_MAX_EDMA_BYTES; 542 + 543 + return 0; 544 + err: 545 + fsl_lpspi_dma_exit(controller); 546 + return ret; 547 + } 548 + 549 + static int fsl_lpspi_pio_transfer(struct spi_controller *controller, 538 550 struct spi_transfer *t) 539 551 { 540 552 struct fsl_lpspi_data *fsl_lpspi = ··· 728 402 return 0; 729 403 } 730 404 731 - static int fsl_lpspi_transfer_one_msg(struct spi_controller *controller, 732 - struct spi_message *msg) 405 + static int fsl_lpspi_transfer_one(struct spi_controller *controller, 406 + struct spi_device *spi, 407 + struct spi_transfer *t) 733 408 { 734 409 struct fsl_lpspi_data *fsl_lpspi = 735 - spi_controller_get_devdata(controller); 736 - struct spi_device *spi = msg->spi; 737 - struct spi_transfer *xfer; 738 - bool is_first_xfer = true; 739 - int ret = 0; 410 + spi_controller_get_devdata(controller); 411 + int ret; 740 412 741 - msg->status = 0; 742 - msg->actual_length = 0; 413 + fsl_lpspi->is_first_byte = true; 414 + ret = fsl_lpspi_setup_transfer(controller, spi, t); 415 + if (ret < 0) 416 + return ret; 743 417 744 - list_for_each_entry(xfer, &msg->transfers, transfer_list) { 745 - fsl_lpspi_setup_transfer(spi, xfer); 746 - fsl_lpspi_set_cmd(fsl_lpspi, is_first_xfer); 418 + fsl_lpspi_set_cmd(fsl_lpspi); 419 + fsl_lpspi->is_first_byte = false; 747 420 748 - is_first_xfer = false; 421 + if (fsl_lpspi->usedma) 422 + ret = fsl_lpspi_dma_transfer(controller, fsl_lpspi, t); 423 + else 424 + ret = fsl_lpspi_pio_transfer(controller, t); 425 + if (ret < 0) 426 + return ret; 749 427 750 - ret = fsl_lpspi_transfer_one(controller, spi, xfer); 751 - if (ret < 0) 752 - goto complete; 753 - 754 - msg->actual_length += xfer->len; 755 - } 756 - 757 - complete: 758 - msg->status = ret; 759 - spi_finalize_current_message(controller); 760 - 761 - return ret; 428 + return 0; 762 429 } 763 430 764 431 static irqreturn_t fsl_lpspi_isr(int irq, void *dev_id) ··· 786 467 return IRQ_NONE; 787 468 } 788 469 470 + #ifdef CONFIG_PM 471 + static int fsl_lpspi_runtime_resume(struct device *dev) 472 + { 473 + struct spi_controller *controller = dev_get_drvdata(dev); 474 + struct fsl_lpspi_data *fsl_lpspi; 475 + int ret; 476 + 477 + fsl_lpspi = spi_controller_get_devdata(controller); 478 + 479 + ret = clk_prepare_enable(fsl_lpspi->clk_per); 480 + if (ret) 481 + return ret; 482 + 483 + ret = clk_prepare_enable(fsl_lpspi->clk_ipg); 484 + if (ret) { 485 + clk_disable_unprepare(fsl_lpspi->clk_per); 486 + return ret; 487 + } 488 + 489 + return 0; 490 + } 491 + 492 + static int fsl_lpspi_runtime_suspend(struct device *dev) 493 + { 494 + struct spi_controller *controller = dev_get_drvdata(dev); 495 + struct fsl_lpspi_data *fsl_lpspi; 496 + 497 + fsl_lpspi = spi_controller_get_devdata(controller); 498 + 499 + clk_disable_unprepare(fsl_lpspi->clk_per); 500 + clk_disable_unprepare(fsl_lpspi->clk_ipg); 501 + 502 + return 0; 503 + } 504 + #endif 505 + 506 + static int fsl_lpspi_init_rpm(struct fsl_lpspi_data *fsl_lpspi) 507 + { 508 + struct device *dev = fsl_lpspi->dev; 509 + 510 + pm_runtime_enable(dev); 511 + pm_runtime_set_autosuspend_delay(dev, FSL_LPSPI_RPM_TIMEOUT); 512 + pm_runtime_use_autosuspend(dev); 513 + 514 + return 0; 515 + } 516 + 789 517 static int fsl_lpspi_probe(struct platform_device *pdev) 790 518 { 519 + struct device_node *np = pdev->dev.of_node; 791 520 struct fsl_lpspi_data *fsl_lpspi; 792 521 struct spi_controller *controller; 522 + struct spi_imx_master *lpspi_platform_info = 523 + dev_get_platdata(&pdev->dev); 793 524 struct resource *res; 794 - int ret, irq; 525 + int i, ret, irq; 795 526 u32 temp; 527 + bool is_slave; 796 528 797 - if (of_property_read_bool((&pdev->dev)->of_node, "spi-slave")) 529 + is_slave = of_property_read_bool((&pdev->dev)->of_node, "spi-slave"); 530 + if (is_slave) 798 531 controller = spi_alloc_slave(&pdev->dev, 799 532 sizeof(struct fsl_lpspi_data)); 800 533 else ··· 858 487 859 488 platform_set_drvdata(pdev, controller); 860 489 861 - controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32); 862 - controller->bus_num = pdev->id; 863 - 864 490 fsl_lpspi = spi_controller_get_devdata(controller); 865 491 fsl_lpspi->dev = &pdev->dev; 866 - fsl_lpspi->is_slave = of_property_read_bool((&pdev->dev)->of_node, 867 - "spi-slave"); 492 + fsl_lpspi->is_slave = is_slave; 868 493 869 - controller->transfer_one_message = fsl_lpspi_transfer_one_msg; 494 + if (!fsl_lpspi->is_slave) { 495 + for (i = 0; i < controller->num_chipselect; i++) { 496 + int cs_gpio = of_get_named_gpio(np, "cs-gpios", i); 497 + 498 + if (!gpio_is_valid(cs_gpio) && lpspi_platform_info) 499 + cs_gpio = lpspi_platform_info->chipselect[i]; 500 + 501 + fsl_lpspi->chipselect[i] = cs_gpio; 502 + if (!gpio_is_valid(cs_gpio)) 503 + continue; 504 + 505 + ret = devm_gpio_request(&pdev->dev, 506 + fsl_lpspi->chipselect[i], 507 + DRIVER_NAME); 508 + if (ret) { 509 + dev_err(&pdev->dev, "can't get cs gpios\n"); 510 + goto out_controller_put; 511 + } 512 + } 513 + controller->cs_gpios = fsl_lpspi->chipselect; 514 + controller->prepare_message = fsl_lpspi_prepare_message; 515 + } 516 + 517 + controller->bits_per_word_mask = SPI_BPW_RANGE_MASK(8, 32); 518 + controller->transfer_one = fsl_lpspi_transfer_one; 870 519 controller->prepare_transfer_hardware = lpspi_prepare_xfer_hardware; 871 520 controller->unprepare_transfer_hardware = lpspi_unprepare_xfer_hardware; 872 521 controller->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; ··· 903 512 ret = PTR_ERR(fsl_lpspi->base); 904 513 goto out_controller_put; 905 514 } 515 + fsl_lpspi->base_phys = res->start; 906 516 907 517 irq = platform_get_irq(pdev, 0); 908 518 if (irq < 0) { ··· 918 526 goto out_controller_put; 919 527 } 920 528 921 - fsl_lpspi->clk = devm_clk_get(&pdev->dev, "ipg"); 922 - if (IS_ERR(fsl_lpspi->clk)) { 923 - ret = PTR_ERR(fsl_lpspi->clk); 529 + fsl_lpspi->clk_per = devm_clk_get(&pdev->dev, "per"); 530 + if (IS_ERR(fsl_lpspi->clk_per)) { 531 + ret = PTR_ERR(fsl_lpspi->clk_per); 924 532 goto out_controller_put; 925 533 } 926 534 927 - ret = clk_prepare_enable(fsl_lpspi->clk); 928 - if (ret) { 929 - dev_err(&pdev->dev, "can't enable lpspi clock, ret=%d\n", ret); 535 + fsl_lpspi->clk_ipg = devm_clk_get(&pdev->dev, "ipg"); 536 + if (IS_ERR(fsl_lpspi->clk_ipg)) { 537 + ret = PTR_ERR(fsl_lpspi->clk_ipg); 930 538 goto out_controller_put; 539 + } 540 + 541 + /* enable the clock */ 542 + ret = fsl_lpspi_init_rpm(fsl_lpspi); 543 + if (ret) 544 + goto out_controller_put; 545 + 546 + ret = pm_runtime_get_sync(fsl_lpspi->dev); 547 + if (ret < 0) { 548 + dev_err(fsl_lpspi->dev, "failed to enable clock\n"); 549 + return ret; 931 550 } 932 551 933 552 temp = readl(fsl_lpspi->base + IMX7ULP_PARAM); 934 553 fsl_lpspi->txfifosize = 1 << (temp & 0x0f); 935 554 fsl_lpspi->rxfifosize = 1 << ((temp >> 8) & 0x0f); 936 555 937 - clk_disable_unprepare(fsl_lpspi->clk); 556 + ret = fsl_lpspi_dma_init(&pdev->dev, fsl_lpspi, controller); 557 + if (ret == -EPROBE_DEFER) 558 + goto out_controller_put; 559 + 560 + if (ret < 0) 561 + dev_err(&pdev->dev, "dma setup error %d, use pio\n", ret); 938 562 939 563 ret = devm_spi_register_controller(&pdev->dev, controller); 940 564 if (ret < 0) { ··· 972 564 struct fsl_lpspi_data *fsl_lpspi = 973 565 spi_controller_get_devdata(controller); 974 566 975 - clk_disable_unprepare(fsl_lpspi->clk); 567 + pm_runtime_disable(fsl_lpspi->dev); 568 + 569 + spi_master_put(controller); 976 570 977 571 return 0; 978 572 } 573 + 574 + #ifdef CONFIG_PM_SLEEP 575 + static int fsl_lpspi_suspend(struct device *dev) 576 + { 577 + int ret; 578 + 579 + pinctrl_pm_select_sleep_state(dev); 580 + ret = pm_runtime_force_suspend(dev); 581 + return ret; 582 + } 583 + 584 + static int fsl_lpspi_resume(struct device *dev) 585 + { 586 + int ret; 587 + 588 + ret = pm_runtime_force_resume(dev); 589 + if (ret) { 590 + dev_err(dev, "Error in resume: %d\n", ret); 591 + return ret; 592 + } 593 + 594 + pinctrl_pm_select_default_state(dev); 595 + 596 + return 0; 597 + } 598 + #endif /* CONFIG_PM_SLEEP */ 599 + 600 + static const struct dev_pm_ops fsl_lpspi_pm_ops = { 601 + SET_RUNTIME_PM_OPS(fsl_lpspi_runtime_suspend, 602 + fsl_lpspi_runtime_resume, NULL) 603 + SET_SYSTEM_SLEEP_PM_OPS(fsl_lpspi_suspend, fsl_lpspi_resume) 604 + }; 979 605 980 606 static struct platform_driver fsl_lpspi_driver = { 981 607 .driver = { 982 608 .name = DRIVER_NAME, 983 609 .of_match_table = fsl_lpspi_dt_ids, 610 + .pm = &fsl_lpspi_pm_ops, 984 611 }, 985 612 .probe = fsl_lpspi_probe, 986 613 .remove = fsl_lpspi_remove,
+1 -1
drivers/spi/spi-fsl-qspi.c
··· 882 882 883 883 ctlr->dev.of_node = np; 884 884 885 - ret = spi_register_controller(ctlr); 885 + ret = devm_spi_register_controller(dev, ctlr); 886 886 if (ret) 887 887 goto err_destroy_mutex; 888 888
+64 -17
drivers/spi/spi-fsl-spi.c
··· 39 39 #include <linux/spi/spi_bitbang.h> 40 40 #include <linux/types.h> 41 41 42 + #ifdef CONFIG_FSL_SOC 43 + #include <sysdev/fsl_soc.h> 44 + #endif 45 + 46 + /* Specific to the MPC8306/MPC8309 */ 47 + #define IMMR_SPI_CS_OFFSET 0x14c 48 + #define SPI_BOOT_SEL_BIT 0x80000000 49 + 42 50 #include "spi-fsl-lib.h" 43 51 #include "spi-fsl-cpm.h" 44 52 #include "spi-fsl-spi.h" ··· 363 355 static int fsl_spi_do_one_msg(struct spi_master *master, 364 356 struct spi_message *m) 365 357 { 358 + struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(master); 366 359 struct spi_device *spi = m->spi; 367 360 struct spi_transfer *t, *first; 368 361 unsigned int cs_change; 369 362 const int nsecs = 50; 370 - int status; 363 + int status, last_bpw; 364 + 365 + /* 366 + * In CPU mode, optimize large byte transfers to use larger 367 + * bits_per_word values to reduce number of interrupts taken. 368 + */ 369 + if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) { 370 + list_for_each_entry(t, &m->transfers, transfer_list) { 371 + if (t->len < 256 || t->bits_per_word != 8) 372 + continue; 373 + if ((t->len & 3) == 0) 374 + t->bits_per_word = 32; 375 + else if ((t->len & 1) == 0) 376 + t->bits_per_word = 16; 377 + } 378 + } 371 379 372 380 /* Don't allow changes if CS is active */ 373 - first = list_first_entry(&m->transfers, struct spi_transfer, 374 - transfer_list); 381 + cs_change = 1; 375 382 list_for_each_entry(t, &m->transfers, transfer_list) { 376 - if ((first->bits_per_word != t->bits_per_word) || 377 - (first->speed_hz != t->speed_hz)) { 383 + if (cs_change) 384 + first = t; 385 + cs_change = t->cs_change; 386 + if (first->speed_hz != t->speed_hz) { 378 387 dev_err(&spi->dev, 379 - "bits_per_word/speed_hz should be same for the same SPI transfer\n"); 388 + "speed_hz cannot change while CS is active\n"); 380 389 return -EINVAL; 381 390 } 382 391 } 383 392 393 + last_bpw = -1; 384 394 cs_change = 1; 385 395 status = -EINVAL; 386 396 list_for_each_entry(t, &m->transfers, transfer_list) { 387 - if (t->bits_per_word || t->speed_hz) { 388 - if (cs_change) 389 - status = fsl_spi_setup_transfer(spi, t); 390 - if (status < 0) 391 - break; 392 - } 397 + if (cs_change || last_bpw != t->bits_per_word) 398 + status = fsl_spi_setup_transfer(spi, t); 399 + if (status < 0) 400 + break; 401 + last_bpw = t->bits_per_word; 393 402 394 403 if (cs_change) { 395 404 fsl_spi_chipselect(spi, BITBANG_CS_ACTIVE); ··· 726 701 struct fsl_spi_platform_data *pdata = dev_get_platdata(dev); 727 702 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata); 728 703 u16 cs = spi->chip_select; 729 - int gpio = pinfo->gpios[cs]; 730 - bool alow = pinfo->alow_flags[cs]; 731 704 732 - gpio_set_value(gpio, on ^ alow); 705 + if (cs < pinfo->ngpios) { 706 + int gpio = pinfo->gpios[cs]; 707 + bool alow = pinfo->alow_flags[cs]; 708 + 709 + gpio_set_value(gpio, on ^ alow); 710 + } else { 711 + if (WARN_ON_ONCE(cs > pinfo->ngpios || !pinfo->immr_spi_cs)) 712 + return; 713 + iowrite32be(on ? SPI_BOOT_SEL_BIT : 0, pinfo->immr_spi_cs); 714 + } 733 715 } 734 716 735 717 static int of_fsl_spi_get_chipselects(struct device *dev) ··· 744 712 struct device_node *np = dev->of_node; 745 713 struct fsl_spi_platform_data *pdata = dev_get_platdata(dev); 746 714 struct mpc8xxx_spi_probe_info *pinfo = to_of_pinfo(pdata); 715 + bool spisel_boot = IS_ENABLED(CONFIG_FSL_SOC) && 716 + of_property_read_bool(np, "fsl,spisel_boot"); 747 717 int ngpios; 748 718 int i = 0; 749 719 int ret; 750 720 751 721 ngpios = of_gpio_count(np); 752 - if (ngpios <= 0) { 722 + ngpios = max(ngpios, 0); 723 + if (ngpios == 0 && !spisel_boot) { 753 724 /* 754 725 * SPI w/o chip-select line. One SPI device is still permitted 755 726 * though. ··· 761 726 return 0; 762 727 } 763 728 729 + pinfo->ngpios = ngpios; 764 730 pinfo->gpios = kmalloc_array(ngpios, sizeof(*pinfo->gpios), 765 731 GFP_KERNEL); 766 732 if (!pinfo->gpios) ··· 805 769 } 806 770 } 807 771 808 - pdata->max_chipselect = ngpios; 772 + #if IS_ENABLED(CONFIG_FSL_SOC) 773 + if (spisel_boot) { 774 + pinfo->immr_spi_cs = ioremap(get_immrbase() + IMMR_SPI_CS_OFFSET, 4); 775 + if (!pinfo->immr_spi_cs) { 776 + ret = -ENOMEM; 777 + i = ngpios - 1; 778 + goto err_loop; 779 + } 780 + } 781 + #endif 782 + 783 + pdata->max_chipselect = ngpios + spisel_boot; 809 784 pdata->cs_control = fsl_spi_cs_control; 810 785 811 786 return 0;
+99 -135
drivers/spi/spi-gpio.c
··· 41 41 42 42 struct spi_gpio { 43 43 struct spi_bitbang bitbang; 44 - struct spi_gpio_platform_data pdata; 45 - struct platform_device *pdev; 46 44 struct gpio_desc *sck; 47 45 struct gpio_desc *miso; 48 46 struct gpio_desc *mosi; 49 47 struct gpio_desc **cs_gpios; 50 - bool has_cs; 51 48 }; 52 49 53 50 /*----------------------------------------------------------------------*/ ··· 90 93 bang = spi_master_get_devdata(spi->master); 91 94 spi_gpio = container_of(bang, struct spi_gpio, bitbang); 92 95 return spi_gpio; 93 - } 94 - 95 - static inline struct spi_gpio_platform_data *__pure 96 - spi_to_pdata(const struct spi_device *spi) 97 - { 98 - return &spi_to_spi_gpio(spi)->pdata; 99 96 } 100 97 101 98 /* These helpers are in turn called by the bitbang inlines */ ··· 214 223 gpiod_set_value_cansleep(spi_gpio->sck, spi->mode & SPI_CPOL); 215 224 216 225 /* Drive chip select line, if we have one */ 217 - if (spi_gpio->has_cs) { 226 + if (spi_gpio->cs_gpios) { 218 227 struct gpio_desc *cs = spi_gpio->cs_gpios[spi->chip_select]; 219 228 220 229 /* SPI chip selects are normally active-low */ ··· 232 241 * The CS GPIOs have already been 233 242 * initialized from the descriptor lookup. 234 243 */ 235 - cs = spi_gpio->cs_gpios[spi->chip_select]; 236 - if (!spi->controller_state && cs) 237 - status = gpiod_direction_output(cs, 238 - !(spi->mode & SPI_CS_HIGH)); 244 + if (spi_gpio->cs_gpios) { 245 + cs = spi_gpio->cs_gpios[spi->chip_select]; 246 + if (!spi->controller_state && cs) 247 + status = gpiod_direction_output(cs, 248 + !(spi->mode & SPI_CS_HIGH)); 249 + } 239 250 240 251 if (!status) 241 252 status = spi_bitbang_setup(spi); ··· 288 295 * floating signals. (A weak pulldown would save power too, but many 289 296 * drivers expect to see all-ones data as the no slave "response".) 290 297 */ 291 - static int spi_gpio_request(struct device *dev, 292 - struct spi_gpio *spi_gpio, 293 - unsigned int num_chipselects, 294 - u16 *mflags) 298 + static int spi_gpio_request(struct device *dev, struct spi_gpio *spi_gpio) 295 299 { 296 - int i; 297 - 298 300 spi_gpio->mosi = devm_gpiod_get_optional(dev, "mosi", GPIOD_OUT_LOW); 299 301 if (IS_ERR(spi_gpio->mosi)) 300 302 return PTR_ERR(spi_gpio->mosi); 301 - if (!spi_gpio->mosi) 302 - /* HW configuration without MOSI pin */ 303 - *mflags |= SPI_MASTER_NO_TX; 304 303 305 304 spi_gpio->miso = devm_gpiod_get_optional(dev, "miso", GPIOD_IN); 306 305 if (IS_ERR(spi_gpio->miso)) 307 306 return PTR_ERR(spi_gpio->miso); 308 - /* 309 - * No setting SPI_MASTER_NO_RX here - if there is only a MOSI 310 - * pin connected the host can still do RX by changing the 311 - * direction of the line. 312 - */ 313 307 314 308 spi_gpio->sck = devm_gpiod_get(dev, "sck", GPIOD_OUT_LOW); 315 309 if (IS_ERR(spi_gpio->sck)) 316 310 return PTR_ERR(spi_gpio->sck); 317 - 318 - for (i = 0; i < num_chipselects; i++) { 319 - spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", 320 - i, GPIOD_OUT_HIGH); 321 - if (IS_ERR(spi_gpio->cs_gpios[i])) 322 - return PTR_ERR(spi_gpio->cs_gpios[i]); 323 - } 324 311 325 312 return 0; 326 313 } ··· 312 339 }; 313 340 MODULE_DEVICE_TABLE(of, spi_gpio_dt_ids); 314 341 315 - static int spi_gpio_probe_dt(struct platform_device *pdev) 342 + static int spi_gpio_probe_dt(struct platform_device *pdev, 343 + struct spi_master *master) 316 344 { 317 - int ret; 318 - u32 tmp; 319 - struct spi_gpio_platform_data *pdata; 320 - struct device_node *np = pdev->dev.of_node; 321 - const struct of_device_id *of_id = 322 - of_match_device(spi_gpio_dt_ids, &pdev->dev); 345 + master->dev.of_node = pdev->dev.of_node; 346 + master->use_gpio_descriptors = true; 323 347 324 - if (!of_id) 325 - return 0; 326 - 327 - pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 328 - if (!pdata) 329 - return -ENOMEM; 330 - 331 - 332 - ret = of_property_read_u32(np, "num-chipselects", &tmp); 333 - if (ret < 0) { 334 - dev_err(&pdev->dev, "num-chipselects property not found\n"); 335 - goto error_free; 336 - } 337 - 338 - pdata->num_chipselect = tmp; 339 - pdev->dev.platform_data = pdata; 340 - 341 - return 1; 342 - 343 - error_free: 344 - devm_kfree(&pdev->dev, pdata); 345 - return ret; 348 + return 0; 346 349 } 347 350 #else 348 - static inline int spi_gpio_probe_dt(struct platform_device *pdev) 351 + static inline int spi_gpio_probe_dt(struct platform_device *pdev, 352 + struct spi_master *master) 349 353 { 350 354 return 0; 351 355 } 352 356 #endif 357 + 358 + static int spi_gpio_probe_pdata(struct platform_device *pdev, 359 + struct spi_master *master) 360 + { 361 + struct device *dev = &pdev->dev; 362 + struct spi_gpio_platform_data *pdata = dev_get_platdata(dev); 363 + struct spi_gpio *spi_gpio = spi_master_get_devdata(master); 364 + int i; 365 + 366 + #ifdef GENERIC_BITBANG 367 + if (!pdata || !pdata->num_chipselect) 368 + return -ENODEV; 369 + #endif 370 + /* 371 + * The master needs to think there is a chipselect even if not 372 + * connected 373 + */ 374 + master->num_chipselect = pdata->num_chipselect ?: 1; 375 + 376 + spi_gpio->cs_gpios = devm_kcalloc(dev, master->num_chipselect, 377 + sizeof(*spi_gpio->cs_gpios), 378 + GFP_KERNEL); 379 + if (!spi_gpio->cs_gpios) 380 + return -ENOMEM; 381 + 382 + for (i = 0; i < master->num_chipselect; i++) { 383 + spi_gpio->cs_gpios[i] = devm_gpiod_get_index(dev, "cs", i, 384 + GPIOD_OUT_HIGH); 385 + if (IS_ERR(spi_gpio->cs_gpios[i])) 386 + return PTR_ERR(spi_gpio->cs_gpios[i]); 387 + } 388 + 389 + return 0; 390 + } 391 + 392 + static void spi_gpio_put(void *data) 393 + { 394 + spi_master_put(data); 395 + } 353 396 354 397 static int spi_gpio_probe(struct platform_device *pdev) 355 398 { 356 399 int status; 357 400 struct spi_master *master; 358 401 struct spi_gpio *spi_gpio; 359 - struct spi_gpio_platform_data *pdata; 360 - u16 master_flags = 0; 361 - bool use_of = 0; 402 + struct device *dev = &pdev->dev; 403 + struct spi_bitbang *bb; 404 + const struct of_device_id *of_id; 362 405 363 - status = spi_gpio_probe_dt(pdev); 364 - if (status < 0) 365 - return status; 366 - if (status > 0) 367 - use_of = 1; 406 + of_id = of_match_device(spi_gpio_dt_ids, &pdev->dev); 368 407 369 - pdata = dev_get_platdata(&pdev->dev); 370 - #ifdef GENERIC_BITBANG 371 - if (!pdata || (!use_of && !pdata->num_chipselect)) 372 - return -ENODEV; 373 - #endif 374 - 375 - master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio)); 408 + master = spi_alloc_master(dev, sizeof(*spi_gpio)); 376 409 if (!master) 377 410 return -ENOMEM; 378 411 412 + status = devm_add_action_or_reset(&pdev->dev, spi_gpio_put, master); 413 + if (status) 414 + return status; 415 + 416 + if (of_id) 417 + status = spi_gpio_probe_dt(pdev, master); 418 + else 419 + status = spi_gpio_probe_pdata(pdev, master); 420 + 421 + if (status) 422 + return status; 423 + 379 424 spi_gpio = spi_master_get_devdata(master); 380 425 381 - spi_gpio->cs_gpios = devm_kcalloc(&pdev->dev, 382 - pdata->num_chipselect, 383 - sizeof(*spi_gpio->cs_gpios), 384 - GFP_KERNEL); 385 - if (!spi_gpio->cs_gpios) 386 - return -ENOMEM; 387 - 388 - platform_set_drvdata(pdev, spi_gpio); 389 - 390 - /* Determine if we have chip selects connected */ 391 - spi_gpio->has_cs = !!pdata->num_chipselect; 392 - 393 - spi_gpio->pdev = pdev; 394 - if (pdata) 395 - spi_gpio->pdata = *pdata; 396 - 397 - status = spi_gpio_request(&pdev->dev, spi_gpio, 398 - pdata->num_chipselect, &master_flags); 426 + status = spi_gpio_request(dev, spi_gpio); 399 427 if (status) 400 428 return status; 401 429 402 430 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32); 403 431 master->mode_bits = SPI_3WIRE | SPI_3WIRE_HIZ | SPI_CPHA | SPI_CPOL | 404 432 SPI_CS_HIGH; 405 - master->flags = master_flags; 433 + if (!spi_gpio->mosi) { 434 + /* HW configuration without MOSI pin 435 + * 436 + * No setting SPI_MASTER_NO_RX here - if there is only 437 + * a MOSI pin connected the host can still do RX by 438 + * changing the direction of the line. 439 + */ 440 + master->flags = SPI_MASTER_NO_TX; 441 + } 442 + 406 443 master->bus_num = pdev->id; 407 - /* The master needs to think there is a chipselect even if not connected */ 408 - master->num_chipselect = spi_gpio->has_cs ? pdata->num_chipselect : 1; 409 444 master->setup = spi_gpio_setup; 410 445 master->cleanup = spi_gpio_cleanup; 411 - #ifdef CONFIG_OF 412 - master->dev.of_node = pdev->dev.of_node; 413 - #endif 414 446 415 - spi_gpio->bitbang.master = master; 416 - spi_gpio->bitbang.chipselect = spi_gpio_chipselect; 417 - spi_gpio->bitbang.set_line_direction = spi_gpio_set_direction; 447 + bb = &spi_gpio->bitbang; 448 + bb->master = master; 449 + bb->chipselect = spi_gpio_chipselect; 450 + bb->set_line_direction = spi_gpio_set_direction; 418 451 419 - if ((master_flags & SPI_MASTER_NO_TX) == 0) { 420 - spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; 421 - spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; 422 - spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; 423 - spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; 452 + if (master->flags & SPI_MASTER_NO_TX) { 453 + bb->txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; 454 + bb->txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; 455 + bb->txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; 456 + bb->txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; 424 457 } else { 425 - spi_gpio->bitbang.txrx_word[SPI_MODE_0] = spi_gpio_spec_txrx_word_mode0; 426 - spi_gpio->bitbang.txrx_word[SPI_MODE_1] = spi_gpio_spec_txrx_word_mode1; 427 - spi_gpio->bitbang.txrx_word[SPI_MODE_2] = spi_gpio_spec_txrx_word_mode2; 428 - spi_gpio->bitbang.txrx_word[SPI_MODE_3] = spi_gpio_spec_txrx_word_mode3; 458 + bb->txrx_word[SPI_MODE_0] = spi_gpio_txrx_word_mode0; 459 + bb->txrx_word[SPI_MODE_1] = spi_gpio_txrx_word_mode1; 460 + bb->txrx_word[SPI_MODE_2] = spi_gpio_txrx_word_mode2; 461 + bb->txrx_word[SPI_MODE_3] = spi_gpio_txrx_word_mode3; 429 462 } 430 - spi_gpio->bitbang.setup_transfer = spi_bitbang_setup_transfer; 463 + bb->setup_transfer = spi_bitbang_setup_transfer; 431 464 432 - status = spi_bitbang_start(&spi_gpio->bitbang); 465 + status = spi_bitbang_init(&spi_gpio->bitbang); 433 466 if (status) 434 - spi_master_put(master); 467 + return status; 435 468 436 - return status; 437 - } 438 - 439 - static int spi_gpio_remove(struct platform_device *pdev) 440 - { 441 - struct spi_gpio *spi_gpio; 442 - 443 - spi_gpio = platform_get_drvdata(pdev); 444 - 445 - /* stop() unregisters child devices too */ 446 - spi_bitbang_stop(&spi_gpio->bitbang); 447 - 448 - spi_master_put(spi_gpio->bitbang.master); 449 - 450 - return 0; 469 + return devm_spi_register_master(&pdev->dev, spi_master_get(master)); 451 470 } 452 471 453 472 MODULE_ALIAS("platform:" DRIVER_NAME); ··· 450 485 .of_match_table = of_match_ptr(spi_gpio_dt_ids), 451 486 }, 452 487 .probe = spi_gpio_probe, 453 - .remove = spi_gpio_remove, 454 488 }; 455 489 module_platform_driver(spi_gpio_driver); 456 490
+7
drivers/spi/spi-imx.c
··· 28 28 29 29 #define DRIVER_NAME "spi_imx" 30 30 31 + static bool use_dma = true; 32 + module_param(use_dma, bool, 0644); 33 + MODULE_PARM_DESC(use_dma, "Enable usage of DMA when available (default)"); 34 + 31 35 #define MXC_CSPIRXDATA 0x00 32 36 #define MXC_CSPITXDATA 0x04 33 37 #define MXC_CSPICTRL 0x08 ··· 222 218 struct spi_transfer *transfer) 223 219 { 224 220 struct spi_imx_data *spi_imx = spi_master_get_devdata(master); 221 + 222 + if (!use_dma) 223 + return false; 225 224 226 225 if (!master->dma_rx) 227 226 return false;
+4 -4
drivers/spi/spi-mem.c
··· 135 135 return -ENOTSUPP; 136 136 } 137 137 138 - static bool spi_mem_default_supports_op(struct spi_mem *mem, 139 - const struct spi_mem_op *op) 138 + bool spi_mem_default_supports_op(struct spi_mem *mem, 139 + const struct spi_mem_op *op) 140 140 { 141 141 if (spi_check_buswidth_req(mem, op->cmd.buswidth, true)) 142 142 return false; ··· 622 622 EXPORT_SYMBOL_GPL(devm_spi_mem_dirmap_destroy); 623 623 624 624 /** 625 - * spi_mem_dirmap_dirmap_read() - Read data through a direct mapping 625 + * spi_mem_dirmap_read() - Read data through a direct mapping 626 626 * @desc: direct mapping descriptor 627 627 * @offs: offset to start reading from. Note that this is not an absolute 628 628 * offset, but the offset within the direct mapping which already has ··· 668 668 EXPORT_SYMBOL_GPL(spi_mem_dirmap_read); 669 669 670 670 /** 671 - * spi_mem_dirmap_dirmap_write() - Write data through a direct mapping 671 + * spi_mem_dirmap_write() - Write data through a direct mapping 672 672 * @desc: direct mapping descriptor 673 673 * @offs: offset to start writing from. Note that this is not an absolute 674 674 * offset, but the offset within the direct mapping which already has
+2 -4
drivers/spi/spi-mxic.c
··· 492 492 493 493 static int __maybe_unused mxic_spi_runtime_suspend(struct device *dev) 494 494 { 495 - struct platform_device *pdev = to_platform_device(dev); 496 - struct spi_master *master = platform_get_drvdata(pdev); 495 + struct spi_master *master = dev_get_drvdata(dev); 497 496 struct mxic_spi *mxic = spi_master_get_devdata(master); 498 497 499 498 mxic_spi_clk_disable(mxic); ··· 503 504 504 505 static int __maybe_unused mxic_spi_runtime_resume(struct device *dev) 505 506 { 506 - struct platform_device *pdev = to_platform_device(dev); 507 - struct spi_master *master = platform_get_drvdata(pdev); 507 + struct spi_master *master = dev_get_drvdata(dev); 508 508 struct mxic_spi *mxic = spi_master_get_devdata(master); 509 509 int ret; 510 510
+4
drivers/spi/spi-orion.c
··· 470 470 if (orion_spi_write_read_8bit(spi, &tx, &rx) < 0) 471 471 goto out; 472 472 count--; 473 + if (xfer->word_delay_usecs) 474 + udelay(xfer->word_delay_usecs); 473 475 } while (count); 474 476 } else if (word_len == 16) { 475 477 const u16 *tx = xfer->tx_buf; ··· 481 479 if (orion_spi_write_read_16bit(spi, &tx, &rx) < 0) 482 480 goto out; 483 481 count -= 2; 482 + if (xfer->word_delay_usecs) 483 + udelay(xfer->word_delay_usecs); 484 484 } while (count); 485 485 } 486 486
+3 -1
drivers/spi/spi-pxa2xx-dma.c
··· 239 239 u32 *threshold) 240 240 { 241 241 struct pxa2xx_spi_chip *chip_info = spi->controller_data; 242 + struct driver_data *drv_data = spi_controller_get_devdata(spi->controller); 243 + u32 dma_burst_size = drv_data->controller_info->dma_burst_size; 242 244 243 245 /* 244 246 * If the DMA burst size is given in chip_info we use that, 245 247 * otherwise we use the default. Also we use the default FIFO 246 248 * thresholds for now. 247 249 */ 248 - *burst_code = chip_info ? chip_info->dma_burst_size : 1; 250 + *burst_code = chip_info ? chip_info->dma_burst_size : dma_burst_size; 249 251 *threshold = SSCR1_RxTresh(RX_THRESH_DFLT) 250 252 | SSCR1_TxTresh(TX_THRESH_DFLT); 251 253
+4 -1
drivers/spi/spi-pxa2xx-pci.c
··· 5 5 */ 6 6 #include <linux/clk-provider.h> 7 7 #include <linux/module.h> 8 - #include <linux/of_device.h> 9 8 #include <linux/pci.h> 10 9 #include <linux/platform_device.h> 11 10 #include <linux/spi/pxa2xx_spi.h> ··· 33 34 bool (*dma_filter)(struct dma_chan *chan, void *param); 34 35 void *tx_param; 35 36 void *rx_param; 37 + 38 + int dma_burst_size; 36 39 37 40 int (*setup)(struct pci_dev *pdev, struct pxa_spi_info *c); 38 41 }; ··· 134 133 rx->dma_dev = &dma_dev->dev; 135 134 136 135 c->dma_filter = lpss_dma_filter; 136 + c->dma_burst_size = 8; 137 137 return 0; 138 138 } 139 139 ··· 225 223 spi_pdata.tx_param = c->tx_param; 226 224 spi_pdata.rx_param = c->rx_param; 227 225 spi_pdata.enable_dma = c->rx_param && c->tx_param; 226 + spi_pdata.dma_burst_size = c->dma_burst_size ? c->dma_burst_size : 1; 228 227 229 228 ssp = &spi_pdata.ssp; 230 229 ssp->phys_base = pci_resource_start(dev, 0);
+20 -10
drivers/spi/spi-pxa2xx.c
··· 929 929 { 930 930 struct driver_data *drv_data = spi_controller_get_devdata(controller); 931 931 struct spi_message *message = controller->cur_msg; 932 - struct chip_data *chip = spi_get_ctldata(message->spi); 932 + struct chip_data *chip = spi_get_ctldata(spi); 933 933 u32 dma_thresh = chip->dma_threshold; 934 934 u32 dma_burst = chip->dma_burst_size; 935 935 u32 change_mask = pxa2xx_spi_get_ssrc1_change_mask(drv_data); ··· 947 947 /* reject already-mapped transfers; PIO won't always work */ 948 948 if (message->is_dma_mapped 949 949 || transfer->rx_dma || transfer->tx_dma) { 950 - dev_err(&drv_data->pdev->dev, 950 + dev_err(&spi->dev, 951 951 "Mapped transfer length of %u is greater than %d\n", 952 952 transfer->len, MAX_DMA_LEN); 953 953 return -EINVAL; 954 954 } 955 955 956 956 /* warn ... we force this to PIO mode */ 957 - dev_warn_ratelimited(&message->spi->dev, 957 + dev_warn_ratelimited(&spi->dev, 958 958 "DMA disabled for transfer length %ld greater than %d\n", 959 959 (long)transfer->len, MAX_DMA_LEN); 960 960 } 961 961 962 962 /* Setup the transfer state based on the type of transfer */ 963 963 if (pxa2xx_spi_flush(drv_data) == 0) { 964 - dev_err(&drv_data->pdev->dev, "Flush failed\n"); 964 + dev_err(&spi->dev, "Flush failed\n"); 965 965 return -EIO; 966 966 } 967 967 drv_data->n_bytes = chip->n_bytes; ··· 1003 1003 */ 1004 1004 if (chip->enable_dma) { 1005 1005 if (pxa2xx_spi_set_dma_burst_and_threshold(chip, 1006 - message->spi, 1006 + spi, 1007 1007 bits, &dma_burst, 1008 1008 &dma_thresh)) 1009 - dev_warn_ratelimited(&message->spi->dev, 1009 + dev_warn_ratelimited(&spi->dev, 1010 1010 "DMA burst size reduced to match bits_per_word\n"); 1011 1011 } 1012 1012 1013 1013 dma_mapped = controller->can_dma && 1014 - controller->can_dma(controller, message->spi, transfer) && 1014 + controller->can_dma(controller, spi, transfer) && 1015 1015 controller->cur_msg_mapped; 1016 1016 if (dma_mapped) { 1017 1017 ··· 1039 1039 /* NOTE: PXA25x_SSP _could_ use external clocking ... */ 1040 1040 cr0 = pxa2xx_configure_sscr0(drv_data, clk_div, bits); 1041 1041 if (!pxa25x_ssp_comp(drv_data)) 1042 - dev_dbg(&message->spi->dev, "%u Hz actual, %s\n", 1042 + dev_dbg(&spi->dev, "%u Hz actual, %s\n", 1043 1043 controller->max_speed_hz 1044 1044 / (1 + ((cr0 & SSCR0_SCR(0xfff)) >> 8)), 1045 1045 dma_mapped ? "DMA" : "PIO"); 1046 1046 else 1047 - dev_dbg(&message->spi->dev, "%u Hz actual, %s\n", 1047 + dev_dbg(&spi->dev, "%u Hz actual, %s\n", 1048 1048 controller->max_speed_hz / 2 1049 1049 / (1 + ((cr0 & SSCR0_SCR(0x0ff)) >> 8)), 1050 1050 dma_mapped ? "DMA" : "PIO"); ··· 1337 1337 dev_warn(&spi->dev, 1338 1338 "in setup: DMA burst size reduced to match bits_per_word\n"); 1339 1339 } 1340 + dev_dbg(&spi->dev, 1341 + "in setup: DMA burst size set to %u\n", 1342 + chip->dma_burst_size); 1340 1343 } 1341 1344 1342 1345 switch (drv_data->ssp_type) { ··· 1458 1455 { PCI_VDEVICE(INTEL, 0xa32a), LPSS_CNL_SSP }, 1459 1456 { PCI_VDEVICE(INTEL, 0xa32b), LPSS_CNL_SSP }, 1460 1457 { PCI_VDEVICE(INTEL, 0xa37b), LPSS_CNL_SSP }, 1458 + /* CML-LP */ 1459 + { PCI_VDEVICE(INTEL, 0x02aa), LPSS_CNL_SSP }, 1460 + { PCI_VDEVICE(INTEL, 0x02ab), LPSS_CNL_SSP }, 1461 + { PCI_VDEVICE(INTEL, 0x02fb), LPSS_CNL_SSP }, 1461 1462 { }, 1462 1463 }; 1463 1464 ··· 1575 1568 pdata->is_slave = of_property_read_bool(pdev->dev.of_node, "spi-slave"); 1576 1569 pdata->num_chipselect = 1; 1577 1570 pdata->enable_dma = true; 1571 + pdata->dma_burst_size = 1; 1578 1572 1579 1573 return pdata; 1580 1574 } ··· 1704 1696 if (platform_info->enable_dma) { 1705 1697 status = pxa2xx_spi_dma_setup(drv_data); 1706 1698 if (status) { 1707 - dev_dbg(dev, "no DMA channels available, using PIO\n"); 1699 + dev_warn(dev, "no DMA channels available, using PIO\n"); 1708 1700 platform_info->enable_dma = false; 1709 1701 } else { 1710 1702 controller->can_dma = pxa2xx_spi_can_dma; ··· 1965 1957 platform_driver_unregister(&driver); 1966 1958 } 1967 1959 module_exit(pxa2xx_spi_exit); 1960 + 1961 + MODULE_SOFTDEP("pre: dw_dmac");
+112 -112
drivers/spi/spi-sh-msiof.c
··· 18 18 #include <linux/gpio/consumer.h> 19 19 #include <linux/interrupt.h> 20 20 #include <linux/io.h> 21 + #include <linux/iopoll.h> 21 22 #include <linux/kernel.h> 22 23 #include <linux/module.h> 23 24 #include <linux/of.h> ··· 83 82 #define RFDR 0x60 /* Receive FIFO Data Register */ 84 83 85 84 /* TMDR1 and RMDR1 */ 86 - #define MDR1_TRMD 0x80000000 /* Transfer Mode (1 = Master mode) */ 87 - #define MDR1_SYNCMD_MASK 0x30000000 /* SYNC Mode */ 88 - #define MDR1_SYNCMD_SPI 0x20000000 /* Level mode/SPI */ 89 - #define MDR1_SYNCMD_LR 0x30000000 /* L/R mode */ 90 - #define MDR1_SYNCAC_SHIFT 25 /* Sync Polarity (1 = Active-low) */ 91 - #define MDR1_BITLSB_SHIFT 24 /* MSB/LSB First (1 = LSB first) */ 92 - #define MDR1_DTDL_SHIFT 20 /* Data Pin Bit Delay for MSIOF_SYNC */ 93 - #define MDR1_SYNCDL_SHIFT 16 /* Frame Sync Signal Timing Delay */ 94 - #define MDR1_FLD_MASK 0x0000000c /* Frame Sync Signal Interval (0-3) */ 95 - #define MDR1_FLD_SHIFT 2 96 - #define MDR1_XXSTP 0x00000001 /* Transmission/Reception Stop on FIFO */ 85 + #define MDR1_TRMD BIT(31) /* Transfer Mode (1 = Master mode) */ 86 + #define MDR1_SYNCMD_MASK GENMASK(29, 28) /* SYNC Mode */ 87 + #define MDR1_SYNCMD_SPI (2 << 28)/* Level mode/SPI */ 88 + #define MDR1_SYNCMD_LR (3 << 28)/* L/R mode */ 89 + #define MDR1_SYNCAC_SHIFT 25 /* Sync Polarity (1 = Active-low) */ 90 + #define MDR1_BITLSB_SHIFT 24 /* MSB/LSB First (1 = LSB first) */ 91 + #define MDR1_DTDL_SHIFT 20 /* Data Pin Bit Delay for MSIOF_SYNC */ 92 + #define MDR1_SYNCDL_SHIFT 16 /* Frame Sync Signal Timing Delay */ 93 + #define MDR1_FLD_MASK GENMASK(3, 2) /* Frame Sync Signal Interval (0-3) */ 94 + #define MDR1_FLD_SHIFT 2 95 + #define MDR1_XXSTP BIT(0) /* Transmission/Reception Stop on FIFO */ 97 96 /* TMDR1 */ 98 - #define TMDR1_PCON 0x40000000 /* Transfer Signal Connection */ 99 - #define TMDR1_SYNCCH_MASK 0xc000000 /* Synchronization Signal Channel Select */ 100 - #define TMDR1_SYNCCH_SHIFT 26 /* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */ 97 + #define TMDR1_PCON BIT(30) /* Transfer Signal Connection */ 98 + #define TMDR1_SYNCCH_MASK GENMASK(27, 26) /* Sync Signal Channel Select */ 99 + #define TMDR1_SYNCCH_SHIFT 26 /* 0=MSIOF_SYNC, 1=MSIOF_SS1, 2=MSIOF_SS2 */ 101 100 102 101 /* TMDR2 and RMDR2 */ 103 102 #define MDR2_BITLEN1(i) (((i) - 1) << 24) /* Data Size (8-32 bits) */ 104 103 #define MDR2_WDLEN1(i) (((i) - 1) << 16) /* Word Count (1-64/256 (SH, A1))) */ 105 - #define MDR2_GRPMASK1 0x00000001 /* Group Output Mask 1 (SH, A1) */ 104 + #define MDR2_GRPMASK1 BIT(0) /* Group Output Mask 1 (SH, A1) */ 106 105 107 106 /* TSCR and RSCR */ 108 - #define SCR_BRPS_MASK 0x1f00 /* Prescaler Setting (1-32) */ 107 + #define SCR_BRPS_MASK GENMASK(12, 8) /* Prescaler Setting (1-32) */ 109 108 #define SCR_BRPS(i) (((i) - 1) << 8) 110 - #define SCR_BRDV_MASK 0x0007 /* Baud Rate Generator's Division Ratio */ 111 - #define SCR_BRDV_DIV_2 0x0000 112 - #define SCR_BRDV_DIV_4 0x0001 113 - #define SCR_BRDV_DIV_8 0x0002 114 - #define SCR_BRDV_DIV_16 0x0003 115 - #define SCR_BRDV_DIV_32 0x0004 116 - #define SCR_BRDV_DIV_1 0x0007 109 + #define SCR_BRDV_MASK GENMASK(2, 0) /* Baud Rate Generator's Division Ratio */ 110 + #define SCR_BRDV_DIV_2 0 111 + #define SCR_BRDV_DIV_4 1 112 + #define SCR_BRDV_DIV_8 2 113 + #define SCR_BRDV_DIV_16 3 114 + #define SCR_BRDV_DIV_32 4 115 + #define SCR_BRDV_DIV_1 7 117 116 118 117 /* CTR */ 119 - #define CTR_TSCKIZ_MASK 0xc0000000 /* Transmit Clock I/O Polarity Select */ 120 - #define CTR_TSCKIZ_SCK 0x80000000 /* Disable SCK when TX disabled */ 121 - #define CTR_TSCKIZ_POL_SHIFT 30 /* Transmit Clock Polarity */ 122 - #define CTR_RSCKIZ_MASK 0x30000000 /* Receive Clock Polarity Select */ 123 - #define CTR_RSCKIZ_SCK 0x20000000 /* Must match CTR_TSCKIZ_SCK */ 124 - #define CTR_RSCKIZ_POL_SHIFT 28 /* Receive Clock Polarity */ 125 - #define CTR_TEDG_SHIFT 27 /* Transmit Timing (1 = falling edge) */ 126 - #define CTR_REDG_SHIFT 26 /* Receive Timing (1 = falling edge) */ 127 - #define CTR_TXDIZ_MASK 0x00c00000 /* Pin Output When TX is Disabled */ 128 - #define CTR_TXDIZ_LOW 0x00000000 /* 0 */ 129 - #define CTR_TXDIZ_HIGH 0x00400000 /* 1 */ 130 - #define CTR_TXDIZ_HIZ 0x00800000 /* High-impedance */ 131 - #define CTR_TSCKE 0x00008000 /* Transmit Serial Clock Output Enable */ 132 - #define CTR_TFSE 0x00004000 /* Transmit Frame Sync Signal Output Enable */ 133 - #define CTR_TXE 0x00000200 /* Transmit Enable */ 134 - #define CTR_RXE 0x00000100 /* Receive Enable */ 118 + #define CTR_TSCKIZ_MASK GENMASK(31, 30) /* Transmit Clock I/O Polarity Select */ 119 + #define CTR_TSCKIZ_SCK BIT(31) /* Disable SCK when TX disabled */ 120 + #define CTR_TSCKIZ_POL_SHIFT 30 /* Transmit Clock Polarity */ 121 + #define CTR_RSCKIZ_MASK GENMASK(29, 28) /* Receive Clock Polarity Select */ 122 + #define CTR_RSCKIZ_SCK BIT(29) /* Must match CTR_TSCKIZ_SCK */ 123 + #define CTR_RSCKIZ_POL_SHIFT 28 /* Receive Clock Polarity */ 124 + #define CTR_TEDG_SHIFT 27 /* Transmit Timing (1 = falling edge) */ 125 + #define CTR_REDG_SHIFT 26 /* Receive Timing (1 = falling edge) */ 126 + #define CTR_TXDIZ_MASK GENMASK(23, 22) /* Pin Output When TX is Disabled */ 127 + #define CTR_TXDIZ_LOW (0 << 22) /* 0 */ 128 + #define CTR_TXDIZ_HIGH (1 << 22) /* 1 */ 129 + #define CTR_TXDIZ_HIZ (2 << 22) /* High-impedance */ 130 + #define CTR_TSCKE BIT(15) /* Transmit Serial Clock Output Enable */ 131 + #define CTR_TFSE BIT(14) /* Transmit Frame Sync Signal Output Enable */ 132 + #define CTR_TXE BIT(9) /* Transmit Enable */ 133 + #define CTR_RXE BIT(8) /* Receive Enable */ 134 + #define CTR_TXRST BIT(1) /* Transmit Reset */ 135 + #define CTR_RXRST BIT(0) /* Receive Reset */ 135 136 136 137 /* FCTR */ 137 - #define FCTR_TFWM_MASK 0xe0000000 /* Transmit FIFO Watermark */ 138 - #define FCTR_TFWM_64 0x00000000 /* Transfer Request when 64 empty stages */ 139 - #define FCTR_TFWM_32 0x20000000 /* Transfer Request when 32 empty stages */ 140 - #define FCTR_TFWM_24 0x40000000 /* Transfer Request when 24 empty stages */ 141 - #define FCTR_TFWM_16 0x60000000 /* Transfer Request when 16 empty stages */ 142 - #define FCTR_TFWM_12 0x80000000 /* Transfer Request when 12 empty stages */ 143 - #define FCTR_TFWM_8 0xa0000000 /* Transfer Request when 8 empty stages */ 144 - #define FCTR_TFWM_4 0xc0000000 /* Transfer Request when 4 empty stages */ 145 - #define FCTR_TFWM_1 0xe0000000 /* Transfer Request when 1 empty stage */ 146 - #define FCTR_TFUA_MASK 0x07f00000 /* Transmit FIFO Usable Area */ 147 - #define FCTR_TFUA_SHIFT 20 138 + #define FCTR_TFWM_MASK GENMASK(31, 29) /* Transmit FIFO Watermark */ 139 + #define FCTR_TFWM_64 (0 << 29) /* Transfer Request when 64 empty stages */ 140 + #define FCTR_TFWM_32 (1 << 29) /* Transfer Request when 32 empty stages */ 141 + #define FCTR_TFWM_24 (2 << 29) /* Transfer Request when 24 empty stages */ 142 + #define FCTR_TFWM_16 (3 << 29) /* Transfer Request when 16 empty stages */ 143 + #define FCTR_TFWM_12 (4 << 29) /* Transfer Request when 12 empty stages */ 144 + #define FCTR_TFWM_8 (5 << 29) /* Transfer Request when 8 empty stages */ 145 + #define FCTR_TFWM_4 (6 << 29) /* Transfer Request when 4 empty stages */ 146 + #define FCTR_TFWM_1 (7 << 29) /* Transfer Request when 1 empty stage */ 147 + #define FCTR_TFUA_MASK GENMASK(26, 20) /* Transmit FIFO Usable Area */ 148 + #define FCTR_TFUA_SHIFT 20 148 149 #define FCTR_TFUA(i) ((i) << FCTR_TFUA_SHIFT) 149 - #define FCTR_RFWM_MASK 0x0000e000 /* Receive FIFO Watermark */ 150 - #define FCTR_RFWM_1 0x00000000 /* Transfer Request when 1 valid stages */ 151 - #define FCTR_RFWM_4 0x00002000 /* Transfer Request when 4 valid stages */ 152 - #define FCTR_RFWM_8 0x00004000 /* Transfer Request when 8 valid stages */ 153 - #define FCTR_RFWM_16 0x00006000 /* Transfer Request when 16 valid stages */ 154 - #define FCTR_RFWM_32 0x00008000 /* Transfer Request when 32 valid stages */ 155 - #define FCTR_RFWM_64 0x0000a000 /* Transfer Request when 64 valid stages */ 156 - #define FCTR_RFWM_128 0x0000c000 /* Transfer Request when 128 valid stages */ 157 - #define FCTR_RFWM_256 0x0000e000 /* Transfer Request when 256 valid stages */ 158 - #define FCTR_RFUA_MASK 0x00001ff0 /* Receive FIFO Usable Area (0x40 = full) */ 159 - #define FCTR_RFUA_SHIFT 4 150 + #define FCTR_RFWM_MASK GENMASK(15, 13) /* Receive FIFO Watermark */ 151 + #define FCTR_RFWM_1 (0 << 13) /* Transfer Request when 1 valid stages */ 152 + #define FCTR_RFWM_4 (1 << 13) /* Transfer Request when 4 valid stages */ 153 + #define FCTR_RFWM_8 (2 << 13) /* Transfer Request when 8 valid stages */ 154 + #define FCTR_RFWM_16 (3 << 13) /* Transfer Request when 16 valid stages */ 155 + #define FCTR_RFWM_32 (4 << 13) /* Transfer Request when 32 valid stages */ 156 + #define FCTR_RFWM_64 (5 << 13) /* Transfer Request when 64 valid stages */ 157 + #define FCTR_RFWM_128 (6 << 13) /* Transfer Request when 128 valid stages */ 158 + #define FCTR_RFWM_256 (7 << 13) /* Transfer Request when 256 valid stages */ 159 + #define FCTR_RFUA_MASK GENMASK(12, 4) /* Receive FIFO Usable Area (0x40 = full) */ 160 + #define FCTR_RFUA_SHIFT 4 160 161 #define FCTR_RFUA(i) ((i) << FCTR_RFUA_SHIFT) 161 162 162 163 /* STR */ 163 - #define STR_TFEMP 0x20000000 /* Transmit FIFO Empty */ 164 - #define STR_TDREQ 0x10000000 /* Transmit Data Transfer Request */ 165 - #define STR_TEOF 0x00800000 /* Frame Transmission End */ 166 - #define STR_TFSERR 0x00200000 /* Transmit Frame Synchronization Error */ 167 - #define STR_TFOVF 0x00100000 /* Transmit FIFO Overflow */ 168 - #define STR_TFUDF 0x00080000 /* Transmit FIFO Underflow */ 169 - #define STR_RFFUL 0x00002000 /* Receive FIFO Full */ 170 - #define STR_RDREQ 0x00001000 /* Receive Data Transfer Request */ 171 - #define STR_REOF 0x00000080 /* Frame Reception End */ 172 - #define STR_RFSERR 0x00000020 /* Receive Frame Synchronization Error */ 173 - #define STR_RFUDF 0x00000010 /* Receive FIFO Underflow */ 174 - #define STR_RFOVF 0x00000008 /* Receive FIFO Overflow */ 164 + #define STR_TFEMP BIT(29) /* Transmit FIFO Empty */ 165 + #define STR_TDREQ BIT(28) /* Transmit Data Transfer Request */ 166 + #define STR_TEOF BIT(23) /* Frame Transmission End */ 167 + #define STR_TFSERR BIT(21) /* Transmit Frame Synchronization Error */ 168 + #define STR_TFOVF BIT(20) /* Transmit FIFO Overflow */ 169 + #define STR_TFUDF BIT(19) /* Transmit FIFO Underflow */ 170 + #define STR_RFFUL BIT(13) /* Receive FIFO Full */ 171 + #define STR_RDREQ BIT(12) /* Receive Data Transfer Request */ 172 + #define STR_REOF BIT(7) /* Frame Reception End */ 173 + #define STR_RFSERR BIT(5) /* Receive Frame Synchronization Error */ 174 + #define STR_RFUDF BIT(4) /* Receive FIFO Underflow */ 175 + #define STR_RFOVF BIT(3) /* Receive FIFO Overflow */ 175 176 176 177 /* IER */ 177 - #define IER_TDMAE 0x80000000 /* Transmit Data DMA Transfer Req. Enable */ 178 - #define IER_TFEMPE 0x20000000 /* Transmit FIFO Empty Enable */ 179 - #define IER_TDREQE 0x10000000 /* Transmit Data Transfer Request Enable */ 180 - #define IER_TEOFE 0x00800000 /* Frame Transmission End Enable */ 181 - #define IER_TFSERRE 0x00200000 /* Transmit Frame Sync Error Enable */ 182 - #define IER_TFOVFE 0x00100000 /* Transmit FIFO Overflow Enable */ 183 - #define IER_TFUDFE 0x00080000 /* Transmit FIFO Underflow Enable */ 184 - #define IER_RDMAE 0x00008000 /* Receive Data DMA Transfer Req. Enable */ 185 - #define IER_RFFULE 0x00002000 /* Receive FIFO Full Enable */ 186 - #define IER_RDREQE 0x00001000 /* Receive Data Transfer Request Enable */ 187 - #define IER_REOFE 0x00000080 /* Frame Reception End Enable */ 188 - #define IER_RFSERRE 0x00000020 /* Receive Frame Sync Error Enable */ 189 - #define IER_RFUDFE 0x00000010 /* Receive FIFO Underflow Enable */ 190 - #define IER_RFOVFE 0x00000008 /* Receive FIFO Overflow Enable */ 178 + #define IER_TDMAE BIT(31) /* Transmit Data DMA Transfer Req. Enable */ 179 + #define IER_TFEMPE BIT(29) /* Transmit FIFO Empty Enable */ 180 + #define IER_TDREQE BIT(28) /* Transmit Data Transfer Request Enable */ 181 + #define IER_TEOFE BIT(23) /* Frame Transmission End Enable */ 182 + #define IER_TFSERRE BIT(21) /* Transmit Frame Sync Error Enable */ 183 + #define IER_TFOVFE BIT(20) /* Transmit FIFO Overflow Enable */ 184 + #define IER_TFUDFE BIT(19) /* Transmit FIFO Underflow Enable */ 185 + #define IER_RDMAE BIT(15) /* Receive Data DMA Transfer Req. Enable */ 186 + #define IER_RFFULE BIT(13) /* Receive FIFO Full Enable */ 187 + #define IER_RDREQE BIT(12) /* Receive Data Transfer Request Enable */ 188 + #define IER_REOFE BIT(7) /* Frame Reception End Enable */ 189 + #define IER_RFSERRE BIT(5) /* Receive Frame Sync Error Enable */ 190 + #define IER_RFUDFE BIT(4) /* Receive FIFO Underflow Enable */ 191 + #define IER_RFOVFE BIT(3) /* Receive FIFO Overflow Enable */ 191 192 192 193 193 194 static u32 sh_msiof_read(struct sh_msiof_spi_priv *p, int reg_offs) ··· 222 219 { 223 220 u32 mask = clr | set; 224 221 u32 data; 225 - int k; 226 222 227 223 data = sh_msiof_read(p, CTR); 228 224 data &= ~clr; 229 225 data |= set; 230 226 sh_msiof_write(p, CTR, data); 231 227 232 - for (k = 100; k > 0; k--) { 233 - if ((sh_msiof_read(p, CTR) & mask) == set) 234 - break; 235 - 236 - udelay(10); 237 - } 238 - 239 - return k > 0 ? 0 : -ETIMEDOUT; 228 + return readl_poll_timeout_atomic(p->mapbase + CTR, data, 229 + (data & mask) == set, 10, 1000); 240 230 } 241 231 242 232 static irqreturn_t sh_msiof_spi_irq(int irq, void *data) ··· 241 245 complete(&p->done); 242 246 243 247 return IRQ_HANDLED; 248 + } 249 + 250 + static void sh_msiof_spi_reset_regs(struct sh_msiof_spi_priv *p) 251 + { 252 + u32 mask = CTR_TXRST | CTR_RXRST; 253 + u32 data; 254 + 255 + data = sh_msiof_read(p, CTR); 256 + data |= mask; 257 + sh_msiof_write(p, CTR, data); 258 + 259 + readl_poll_timeout_atomic(p->mapbase + CTR, data, !(data & mask), 1, 260 + 100); 244 261 } 245 262 246 263 static const u32 sh_msiof_spi_div_array[] = { ··· 549 540 550 541 static int sh_msiof_spi_setup(struct spi_device *spi) 551 542 { 552 - struct device_node *np = spi->controller->dev.of_node; 553 543 struct sh_msiof_spi_priv *p = 554 544 spi_controller_get_devdata(spi->controller); 555 545 u32 clr, set, tmp; 556 546 557 - if (!np) { 558 - /* 559 - * Use spi->controller_data for CS (same strategy as spi_gpio), 560 - * if any. otherwise let HW control CS 561 - */ 562 - spi->cs_gpio = (uintptr_t)spi->controller_data; 563 - } 564 - 565 - if (gpio_is_valid(spi->cs_gpio)) { 566 - gpio_direction_output(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); 567 - return 0; 568 - } 569 - 570 - if (spi_controller_is_slave(p->ctlr)) 547 + if (spi->cs_gpiod || spi_controller_is_slave(p->ctlr)) 571 548 return 0; 572 549 573 550 if (p->native_cs_inited && ··· 586 591 u32 ss, cs_high; 587 592 588 593 /* Configure pins before asserting CS */ 589 - if (gpio_is_valid(spi->cs_gpio)) { 594 + if (spi->cs_gpiod) { 590 595 ss = p->unused_ss; 591 596 cs_high = p->native_cs_high; 592 597 } else { ··· 921 926 bool swab; 922 927 int ret; 923 928 929 + /* reset registers */ 930 + sh_msiof_spi_reset_regs(p); 931 + 924 932 /* setup clocks (clock already enabled in chipselect()) */ 925 933 if (!spi_controller_is_slave(p->ctlr)) 926 934 sh_msiof_spi_set_clk_regs(p, clk_get_rate(p->clk), t->speed_hz); ··· 1142 1144 1143 1145 gpiod = devm_gpiod_get_index(dev, "cs", i, GPIOD_ASIS); 1144 1146 if (!IS_ERR(gpiod)) { 1147 + devm_gpiod_put(dev, gpiod); 1145 1148 cs_gpios++; 1146 1149 continue; 1147 1150 } ··· 1394 1395 ctlr->bits_per_word_mask = chipdata->bits_per_word_mask; 1395 1396 ctlr->auto_runtime_pm = true; 1396 1397 ctlr->transfer_one = sh_msiof_transfer_one; 1398 + ctlr->use_gpio_descriptors = true; 1397 1399 1398 1400 ret = sh_msiof_request_dma(p); 1399 1401 if (ret < 0)
+204 -23
drivers/spi/spi-stm32-qspi.c
··· 5 5 */ 6 6 #include <linux/bitfield.h> 7 7 #include <linux/clk.h> 8 + #include <linux/dmaengine.h> 9 + #include <linux/dma-mapping.h> 8 10 #include <linux/errno.h> 9 11 #include <linux/io.h> 10 12 #include <linux/iopoll.h> ··· 15 13 #include <linux/mutex.h> 16 14 #include <linux/of.h> 17 15 #include <linux/of_device.h> 16 + #include <linux/pinctrl/consumer.h> 18 17 #include <linux/platform_device.h> 19 18 #include <linux/reset.h> 20 19 #include <linux/sizes.h> ··· 86 83 #define STM32_FIFO_TIMEOUT_US 30000 87 84 #define STM32_BUSY_TIMEOUT_US 100000 88 85 #define STM32_ABT_TIMEOUT_US 100000 86 + #define STM32_COMP_TIMEOUT_MS 1000 89 87 90 88 struct stm32_qspi_flash { 91 89 struct stm32_qspi *qspi; ··· 96 92 97 93 struct stm32_qspi { 98 94 struct device *dev; 95 + struct spi_controller *ctrl; 96 + phys_addr_t phys_base; 99 97 void __iomem *io_base; 100 98 void __iomem *mm_base; 101 99 resource_size_t mm_size; ··· 106 100 struct stm32_qspi_flash flash[STM32_QSPI_MAX_NORCHIP]; 107 101 struct completion data_completion; 108 102 u32 fmode; 103 + 104 + struct dma_chan *dma_chtx; 105 + struct dma_chan *dma_chrx; 106 + struct completion dma_completion; 107 + 108 + u32 cr_reg; 109 + u32 dcr_reg; 109 110 110 111 /* 111 112 * to protect device configuration, could be different between ··· 189 176 return 0; 190 177 } 191 178 179 + static void stm32_qspi_dma_callback(void *arg) 180 + { 181 + struct completion *dma_completion = arg; 182 + 183 + complete(dma_completion); 184 + } 185 + 186 + static int stm32_qspi_tx_dma(struct stm32_qspi *qspi, 187 + const struct spi_mem_op *op) 188 + { 189 + struct dma_async_tx_descriptor *desc; 190 + enum dma_transfer_direction dma_dir; 191 + struct dma_chan *dma_ch; 192 + struct sg_table sgt; 193 + dma_cookie_t cookie; 194 + u32 cr, t_out; 195 + int err; 196 + 197 + if (op->data.dir == SPI_MEM_DATA_IN) { 198 + dma_dir = DMA_DEV_TO_MEM; 199 + dma_ch = qspi->dma_chrx; 200 + } else { 201 + dma_dir = DMA_MEM_TO_DEV; 202 + dma_ch = qspi->dma_chtx; 203 + } 204 + 205 + /* 206 + * spi_map_buf return -EINVAL if the buffer is not DMA-able 207 + * (DMA-able: in vmalloc | kmap | virt_addr_valid) 208 + */ 209 + err = spi_controller_dma_map_mem_op_data(qspi->ctrl, op, &sgt); 210 + if (err) 211 + return err; 212 + 213 + desc = dmaengine_prep_slave_sg(dma_ch, sgt.sgl, sgt.nents, 214 + dma_dir, DMA_PREP_INTERRUPT); 215 + if (!desc) { 216 + err = -ENOMEM; 217 + goto out_unmap; 218 + } 219 + 220 + cr = readl_relaxed(qspi->io_base + QSPI_CR); 221 + 222 + reinit_completion(&qspi->dma_completion); 223 + desc->callback = stm32_qspi_dma_callback; 224 + desc->callback_param = &qspi->dma_completion; 225 + cookie = dmaengine_submit(desc); 226 + err = dma_submit_error(cookie); 227 + if (err) 228 + goto out; 229 + 230 + dma_async_issue_pending(dma_ch); 231 + 232 + writel_relaxed(cr | CR_DMAEN, qspi->io_base + QSPI_CR); 233 + 234 + t_out = sgt.nents * STM32_COMP_TIMEOUT_MS; 235 + if (!wait_for_completion_interruptible_timeout(&qspi->dma_completion, 236 + msecs_to_jiffies(t_out))) 237 + err = -ETIMEDOUT; 238 + 239 + if (dma_async_is_tx_complete(dma_ch, cookie, 240 + NULL, NULL) != DMA_COMPLETE) 241 + err = -ETIMEDOUT; 242 + 243 + if (err) 244 + dmaengine_terminate_all(dma_ch); 245 + 246 + out: 247 + writel_relaxed(cr & ~CR_DMAEN, qspi->io_base + QSPI_CR); 248 + out_unmap: 249 + spi_controller_dma_unmap_mem_op_data(qspi->ctrl, op, &sgt); 250 + 251 + return err; 252 + } 253 + 192 254 static int stm32_qspi_tx(struct stm32_qspi *qspi, const struct spi_mem_op *op) 193 255 { 194 256 if (!op->data.nbytes) ··· 271 183 272 184 if (qspi->fmode == CCR_FMODE_MM) 273 185 return stm32_qspi_tx_mm(qspi, op); 186 + else if ((op->data.dir == SPI_MEM_DATA_IN && qspi->dma_chrx) || 187 + (op->data.dir == SPI_MEM_DATA_OUT && qspi->dma_chtx)) 188 + if (!stm32_qspi_tx_dma(qspi, op)) 189 + return 0; 274 190 275 191 return stm32_qspi_tx_poll(qspi, op); 276 192 } ··· 305 213 writel_relaxed(cr | CR_TCIE | CR_TEIE, qspi->io_base + QSPI_CR); 306 214 307 215 if (!wait_for_completion_interruptible_timeout(&qspi->data_completion, 308 - msecs_to_jiffies(1000))) { 216 + msecs_to_jiffies(STM32_COMP_TIMEOUT_MS))) { 309 217 err = -ETIMEDOUT; 310 218 } else { 311 219 sr = readl_relaxed(qspi->io_base + QSPI_SR); ··· 447 355 struct spi_controller *ctrl = spi->master; 448 356 struct stm32_qspi *qspi = spi_controller_get_devdata(ctrl); 449 357 struct stm32_qspi_flash *flash; 450 - u32 cr, presc; 358 + u32 presc; 451 359 452 360 if (ctrl->busy) 453 361 return -EBUSY; ··· 463 371 flash->presc = presc; 464 372 465 373 mutex_lock(&qspi->lock); 466 - cr = FIELD_PREP(CR_FTHRES_MASK, 3) | CR_SSHIFT | CR_EN; 467 - writel_relaxed(cr, qspi->io_base + QSPI_CR); 374 + qspi->cr_reg = FIELD_PREP(CR_FTHRES_MASK, 3) | CR_SSHIFT | CR_EN; 375 + writel_relaxed(qspi->cr_reg, qspi->io_base + QSPI_CR); 468 376 469 377 /* set dcr fsize to max address */ 470 - writel_relaxed(DCR_FSIZE_MASK, qspi->io_base + QSPI_DCR); 378 + qspi->dcr_reg = DCR_FSIZE_MASK; 379 + writel_relaxed(qspi->dcr_reg, qspi->io_base + QSPI_DCR); 471 380 mutex_unlock(&qspi->lock); 472 381 473 382 return 0; 383 + } 384 + 385 + static void stm32_qspi_dma_setup(struct stm32_qspi *qspi) 386 + { 387 + struct dma_slave_config dma_cfg; 388 + struct device *dev = qspi->dev; 389 + 390 + memset(&dma_cfg, 0, sizeof(dma_cfg)); 391 + 392 + dma_cfg.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 393 + dma_cfg.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE; 394 + dma_cfg.src_addr = qspi->phys_base + QSPI_DR; 395 + dma_cfg.dst_addr = qspi->phys_base + QSPI_DR; 396 + dma_cfg.src_maxburst = 4; 397 + dma_cfg.dst_maxburst = 4; 398 + 399 + qspi->dma_chrx = dma_request_slave_channel(dev, "rx"); 400 + if (qspi->dma_chrx) { 401 + if (dmaengine_slave_config(qspi->dma_chrx, &dma_cfg)) { 402 + dev_err(dev, "dma rx config failed\n"); 403 + dma_release_channel(qspi->dma_chrx); 404 + qspi->dma_chrx = NULL; 405 + } 406 + } 407 + 408 + qspi->dma_chtx = dma_request_slave_channel(dev, "tx"); 409 + if (qspi->dma_chtx) { 410 + if (dmaengine_slave_config(qspi->dma_chtx, &dma_cfg)) { 411 + dev_err(dev, "dma tx config failed\n"); 412 + dma_release_channel(qspi->dma_chtx); 413 + qspi->dma_chtx = NULL; 414 + } 415 + } 416 + 417 + init_completion(&qspi->dma_completion); 418 + } 419 + 420 + static void stm32_qspi_dma_free(struct stm32_qspi *qspi) 421 + { 422 + if (qspi->dma_chtx) 423 + dma_release_channel(qspi->dma_chtx); 424 + if (qspi->dma_chrx) 425 + dma_release_channel(qspi->dma_chrx); 474 426 } 475 427 476 428 /* ··· 529 393 { 530 394 /* disable qspi */ 531 395 writel_relaxed(0, qspi->io_base + QSPI_CR); 396 + stm32_qspi_dma_free(qspi); 532 397 mutex_destroy(&qspi->lock); 533 398 clk_disable_unprepare(qspi->clk); 399 + spi_master_put(qspi->ctrl); 534 400 } 535 401 536 402 static int stm32_qspi_probe(struct platform_device *pdev) ··· 549 411 return -ENOMEM; 550 412 551 413 qspi = spi_controller_get_devdata(ctrl); 414 + qspi->ctrl = ctrl; 552 415 553 416 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi"); 554 417 qspi->io_base = devm_ioremap_resource(dev, res); 555 - if (IS_ERR(qspi->io_base)) 556 - return PTR_ERR(qspi->io_base); 418 + if (IS_ERR(qspi->io_base)) { 419 + ret = PTR_ERR(qspi->io_base); 420 + goto err; 421 + } 422 + 423 + qspi->phys_base = res->start; 557 424 558 425 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "qspi_mm"); 559 426 qspi->mm_base = devm_ioremap_resource(dev, res); 560 - if (IS_ERR(qspi->mm_base)) 561 - return PTR_ERR(qspi->mm_base); 427 + if (IS_ERR(qspi->mm_base)) { 428 + ret = PTR_ERR(qspi->mm_base); 429 + goto err; 430 + } 562 431 563 432 qspi->mm_size = resource_size(res); 564 - if (qspi->mm_size > STM32_QSPI_MAX_MMAP_SZ) 565 - return -EINVAL; 433 + if (qspi->mm_size > STM32_QSPI_MAX_MMAP_SZ) { 434 + ret = -EINVAL; 435 + goto err; 436 + } 566 437 567 438 irq = platform_get_irq(pdev, 0); 439 + if (irq < 0) { 440 + if (irq != -EPROBE_DEFER) 441 + dev_err(dev, "IRQ error missing or invalid\n"); 442 + return irq; 443 + } 444 + 568 445 ret = devm_request_irq(dev, irq, stm32_qspi_irq, 0, 569 446 dev_name(dev), qspi); 570 447 if (ret) { 571 448 dev_err(dev, "failed to request irq\n"); 572 - return ret; 449 + goto err; 573 450 } 574 451 575 452 init_completion(&qspi->data_completion); 576 453 577 454 qspi->clk = devm_clk_get(dev, NULL); 578 - if (IS_ERR(qspi->clk)) 579 - return PTR_ERR(qspi->clk); 455 + if (IS_ERR(qspi->clk)) { 456 + ret = PTR_ERR(qspi->clk); 457 + goto err; 458 + } 580 459 581 460 qspi->clk_rate = clk_get_rate(qspi->clk); 582 - if (!qspi->clk_rate) 583 - return -EINVAL; 461 + if (!qspi->clk_rate) { 462 + ret = -EINVAL; 463 + goto err; 464 + } 584 465 585 466 ret = clk_prepare_enable(qspi->clk); 586 467 if (ret) { 587 468 dev_err(dev, "can not enable the clock\n"); 588 - return ret; 469 + goto err; 589 470 } 590 471 591 472 rstc = devm_reset_control_get_exclusive(dev, NULL); ··· 616 459 617 460 qspi->dev = dev; 618 461 platform_set_drvdata(pdev, qspi); 462 + stm32_qspi_dma_setup(qspi); 619 463 mutex_init(&qspi->lock); 620 464 621 465 ctrl->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD ··· 628 470 ctrl->dev.of_node = dev->of_node; 629 471 630 472 ret = devm_spi_register_master(dev, ctrl); 631 - if (ret) 632 - goto err_spi_register; 473 + if (!ret) 474 + return 0; 633 475 634 - return 0; 635 - 636 - err_spi_register: 476 + err: 637 477 stm32_qspi_release(qspi); 638 - 639 478 return ret; 640 479 } 641 480 ··· 643 488 stm32_qspi_release(qspi); 644 489 return 0; 645 490 } 491 + 492 + static int __maybe_unused stm32_qspi_suspend(struct device *dev) 493 + { 494 + struct stm32_qspi *qspi = dev_get_drvdata(dev); 495 + 496 + clk_disable_unprepare(qspi->clk); 497 + pinctrl_pm_select_sleep_state(dev); 498 + 499 + return 0; 500 + } 501 + 502 + static int __maybe_unused stm32_qspi_resume(struct device *dev) 503 + { 504 + struct stm32_qspi *qspi = dev_get_drvdata(dev); 505 + 506 + pinctrl_pm_select_default_state(dev); 507 + clk_prepare_enable(qspi->clk); 508 + 509 + writel_relaxed(qspi->cr_reg, qspi->io_base + QSPI_CR); 510 + writel_relaxed(qspi->dcr_reg, qspi->io_base + QSPI_DCR); 511 + 512 + return 0; 513 + } 514 + 515 + static SIMPLE_DEV_PM_OPS(stm32_qspi_pm_ops, stm32_qspi_suspend, stm32_qspi_resume); 646 516 647 517 static const struct of_device_id stm32_qspi_match[] = { 648 518 {.compatible = "st,stm32f469-qspi"}, ··· 681 501 .driver = { 682 502 .name = "stm32-qspi", 683 503 .of_match_table = stm32_qspi_match, 504 + .pm = &stm32_qspi_pm_ops, 684 505 }, 685 506 }; 686 507 module_platform_driver(stm32_qspi_driver);
+90 -7
drivers/spi/spi-tegra114.c
··· 149 149 150 150 #define SPI_TX_FIFO 0x108 151 151 #define SPI_RX_FIFO 0x188 152 + #define SPI_INTR_MASK 0x18c 153 + #define SPI_INTR_ALL_MASK (0x1fUL << 25) 152 154 #define MAX_CHIP_SELECT 4 153 155 #define SPI_FIFO_DEPTH 64 154 156 #define DATA_DIR_TX (1 << 0) ··· 162 160 #define RX_FIFO_FULL_COUNT_ZERO SPI_RX_FIFO_FULL_COUNT(0) 163 161 #define MAX_HOLD_CYCLES 16 164 162 #define SPI_DEFAULT_SPEED 25000000 163 + 164 + struct tegra_spi_soc_data { 165 + bool has_intr_mask_reg; 166 + }; 165 167 166 168 struct tegra_spi_data { 167 169 struct device *dev; ··· 217 211 u32 *tx_dma_buf; 218 212 dma_addr_t tx_dma_phys; 219 213 struct dma_async_tx_descriptor *tx_dma_desc; 214 + const struct tegra_spi_soc_data *soc_data; 220 215 }; 221 216 222 217 static int tegra_spi_runtime_suspend(struct device *dev); ··· 266 259 267 260 tspi->bytes_per_word = DIV_ROUND_UP(bits_per_word, 8); 268 261 269 - if (bits_per_word == 8 || bits_per_word == 16) { 262 + if ((bits_per_word == 8 || bits_per_word == 16 || 263 + bits_per_word == 32) && t->len > 3) { 270 264 tspi->is_packed = 1; 271 265 tspi->words_per_32bit = 32/bits_per_word; 272 266 } else { ··· 561 553 dma_burst = 8; 562 554 } 563 555 564 - if (tspi->cur_direction & DATA_DIR_TX) 565 - val |= SPI_IE_TX; 556 + if (!tspi->soc_data->has_intr_mask_reg) { 557 + if (tspi->cur_direction & DATA_DIR_TX) 558 + val |= SPI_IE_TX; 566 559 567 - if (tspi->cur_direction & DATA_DIR_RX) 568 - val |= SPI_IE_RX; 560 + if (tspi->cur_direction & DATA_DIR_RX) 561 + val |= SPI_IE_RX; 562 + } 569 563 570 564 tegra_spi_writel(tspi, val, SPI_DMA_CTL); 571 565 tspi->dma_control_reg = val; ··· 759 749 else if (req_mode == SPI_MODE_3) 760 750 command1 |= SPI_CONTROL_MODE_3; 761 751 752 + if (spi->mode & SPI_LSB_FIRST) 753 + command1 |= SPI_LSBIT_FE; 754 + else 755 + command1 &= ~SPI_LSBIT_FE; 756 + 757 + if (spi->mode & SPI_3WIRE) 758 + command1 |= SPI_BIDIROE; 759 + else 760 + command1 &= ~SPI_BIDIROE; 761 + 762 762 if (tspi->cs_control) { 763 763 if (tspi->cs_control != spi) 764 764 tegra_spi_writel(tspi, command1, SPI_COMMAND1); ··· 800 780 int ret; 801 781 802 782 total_fifo_words = tegra_spi_calculate_curr_xfer_param(spi, tspi, t); 783 + 784 + if (t->rx_nbits == SPI_NBITS_DUAL || t->tx_nbits == SPI_NBITS_DUAL) 785 + command1 |= SPI_BOTH_EN_BIT; 786 + else 787 + command1 &= ~SPI_BOTH_EN_BIT; 803 788 804 789 if (tspi->is_packed) 805 790 command1 |= SPI_PACKED; ··· 857 832 return ret; 858 833 } 859 834 835 + if (tspi->soc_data->has_intr_mask_reg) { 836 + val = tegra_spi_readl(tspi, SPI_INTR_MASK); 837 + val &= ~SPI_INTR_ALL_MASK; 838 + tegra_spi_writel(tspi, val, SPI_INTR_MASK); 839 + } 840 + 860 841 spin_lock_irqsave(&tspi->lock, flags); 861 842 val = tspi->def_command1_reg; 862 843 if (spi->mode & SPI_CS_HIGH) ··· 899 868 tspi->command1_reg &= ~SPI_CS_SW_VAL; 900 869 tegra_spi_writel(tspi, tspi->command1_reg, SPI_COMMAND1); 901 870 tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); 871 + } 872 + 873 + static void tegra_spi_dump_regs(struct tegra_spi_data *tspi) 874 + { 875 + dev_dbg(tspi->dev, "============ SPI REGISTER DUMP ============\n"); 876 + dev_dbg(tspi->dev, "Command1: 0x%08x | Command2: 0x%08x\n", 877 + tegra_spi_readl(tspi, SPI_COMMAND1), 878 + tegra_spi_readl(tspi, SPI_COMMAND2)); 879 + dev_dbg(tspi->dev, "DMA_CTL: 0x%08x | DMA_BLK: 0x%08x\n", 880 + tegra_spi_readl(tspi, SPI_DMA_CTL), 881 + tegra_spi_readl(tspi, SPI_DMA_BLK)); 882 + dev_dbg(tspi->dev, "TRANS_STAT: 0x%08x | FIFO_STATUS: 0x%08x\n", 883 + tegra_spi_readl(tspi, SPI_TRANS_STATUS), 884 + tegra_spi_readl(tspi, SPI_FIFO_STATUS)); 902 885 } 903 886 904 887 static int tegra_spi_transfer_one_message(struct spi_master *master, ··· 961 916 (tspi->cur_direction & DATA_DIR_RX)) 962 917 dmaengine_terminate_all(tspi->rx_dma_chan); 963 918 ret = -EIO; 919 + tegra_spi_dump_regs(tspi); 964 920 tegra_spi_flush_fifos(tspi); 965 921 reset_control_assert(tspi->rst); 966 922 udelay(2); ··· 972 926 if (tspi->tx_status || tspi->rx_status) { 973 927 dev_err(tspi->dev, "Error in Transfer\n"); 974 928 ret = -EIO; 929 + tegra_spi_dump_regs(tspi); 975 930 goto complete_xfer; 976 931 } 977 932 msg->actual_length += xfer->len; ··· 1014 967 tspi->status_reg); 1015 968 dev_err(tspi->dev, "CpuXfer 0x%08x:0x%08x\n", 1016 969 tspi->command1_reg, tspi->dma_control_reg); 970 + tegra_spi_dump_regs(tspi); 1017 971 tegra_spi_flush_fifos(tspi); 1018 972 complete(&tspi->xfer_completion); 1019 973 spin_unlock_irqrestore(&tspi->lock, flags); ··· 1089 1041 tspi->status_reg); 1090 1042 dev_err(tspi->dev, "DmaXfer 0x%08x:0x%08x\n", 1091 1043 tspi->command1_reg, tspi->dma_control_reg); 1044 + tegra_spi_dump_regs(tspi); 1092 1045 tegra_spi_flush_fifos(tspi); 1093 1046 complete(&tspi->xfer_completion); 1094 1047 spin_unlock_irqrestore(&tspi->lock, flags); ··· 1151 1102 return IRQ_WAKE_THREAD; 1152 1103 } 1153 1104 1105 + static struct tegra_spi_soc_data tegra114_spi_soc_data = { 1106 + .has_intr_mask_reg = false, 1107 + }; 1108 + 1109 + static struct tegra_spi_soc_data tegra124_spi_soc_data = { 1110 + .has_intr_mask_reg = false, 1111 + }; 1112 + 1113 + static struct tegra_spi_soc_data tegra210_spi_soc_data = { 1114 + .has_intr_mask_reg = true, 1115 + }; 1116 + 1154 1117 static const struct of_device_id tegra_spi_of_match[] = { 1155 - { .compatible = "nvidia,tegra114-spi", }, 1118 + { 1119 + .compatible = "nvidia,tegra114-spi", 1120 + .data = &tegra114_spi_soc_data, 1121 + }, { 1122 + .compatible = "nvidia,tegra124-spi", 1123 + .data = &tegra124_spi_soc_data, 1124 + }, { 1125 + .compatible = "nvidia,tegra210-spi", 1126 + .data = &tegra210_spi_soc_data, 1127 + }, 1156 1128 {} 1157 1129 }; 1158 1130 MODULE_DEVICE_TABLE(of, tegra_spi_of_match); ··· 1184 1114 struct tegra_spi_data *tspi; 1185 1115 struct resource *r; 1186 1116 int ret, spi_irq; 1117 + int bus_num; 1187 1118 1188 1119 master = spi_alloc_master(&pdev->dev, sizeof(*tspi)); 1189 1120 if (!master) { ··· 1199 1128 master->max_speed_hz = 25000000; /* 25MHz */ 1200 1129 1201 1130 /* the spi->mode bits understood by this driver: */ 1202 - master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH; 1131 + master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_CS_HIGH | SPI_LSB_FIRST | 1132 + SPI_TX_DUAL | SPI_RX_DUAL | SPI_3WIRE; 1133 + master->bits_per_word_mask = SPI_BPW_RANGE_MASK(4, 32); 1203 1134 master->setup = tegra_spi_setup; 1204 1135 master->transfer_one_message = tegra_spi_transfer_one_message; 1205 1136 master->num_chipselect = MAX_CHIP_SELECT; 1206 1137 master->auto_runtime_pm = true; 1138 + bus_num = of_alias_get_id(pdev->dev.of_node, "spi"); 1139 + if (bus_num >= 0) 1140 + master->bus_num = bus_num; 1207 1141 1208 1142 tspi->master = master; 1209 1143 tspi->dev = &pdev->dev; 1210 1144 spin_lock_init(&tspi->lock); 1145 + 1146 + tspi->soc_data = of_device_get_match_data(&pdev->dev); 1147 + if (!tspi->soc_data) { 1148 + dev_err(&pdev->dev, "unsupported tegra\n"); 1149 + ret = -ENODEV; 1150 + goto exit_free_master; 1151 + } 1211 1152 1212 1153 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 1213 1154 tspi->base = devm_ioremap_resource(&pdev->dev, r);
+761
drivers/spi/spi-zynq-qspi.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * Copyright (C) 2019 Xilinx, Inc. 4 + * 5 + * Author: Naga Sureshkumar Relli <nagasure@xilinx.com> 6 + */ 7 + 8 + #include <linux/clk.h> 9 + #include <linux/delay.h> 10 + #include <linux/gpio.h> 11 + #include <linux/interrupt.h> 12 + #include <linux/io.h> 13 + #include <linux/module.h> 14 + #include <linux/of_irq.h> 15 + #include <linux/of_address.h> 16 + #include <linux/platform_device.h> 17 + #include <linux/spi/spi.h> 18 + #include <linux/workqueue.h> 19 + #include <linux/spi/spi-mem.h> 20 + 21 + /* Register offset definitions */ 22 + #define ZYNQ_QSPI_CONFIG_OFFSET 0x00 /* Configuration Register, RW */ 23 + #define ZYNQ_QSPI_STATUS_OFFSET 0x04 /* Interrupt Status Register, RO */ 24 + #define ZYNQ_QSPI_IEN_OFFSET 0x08 /* Interrupt Enable Register, WO */ 25 + #define ZYNQ_QSPI_IDIS_OFFSET 0x0C /* Interrupt Disable Reg, WO */ 26 + #define ZYNQ_QSPI_IMASK_OFFSET 0x10 /* Interrupt Enabled Mask Reg,RO */ 27 + #define ZYNQ_QSPI_ENABLE_OFFSET 0x14 /* Enable/Disable Register, RW */ 28 + #define ZYNQ_QSPI_DELAY_OFFSET 0x18 /* Delay Register, RW */ 29 + #define ZYNQ_QSPI_TXD_00_00_OFFSET 0x1C /* Transmit 4-byte inst, WO */ 30 + #define ZYNQ_QSPI_TXD_00_01_OFFSET 0x80 /* Transmit 1-byte inst, WO */ 31 + #define ZYNQ_QSPI_TXD_00_10_OFFSET 0x84 /* Transmit 2-byte inst, WO */ 32 + #define ZYNQ_QSPI_TXD_00_11_OFFSET 0x88 /* Transmit 3-byte inst, WO */ 33 + #define ZYNQ_QSPI_RXD_OFFSET 0x20 /* Data Receive Register, RO */ 34 + #define ZYNQ_QSPI_SIC_OFFSET 0x24 /* Slave Idle Count Register, RW */ 35 + #define ZYNQ_QSPI_TX_THRESH_OFFSET 0x28 /* TX FIFO Watermark Reg, RW */ 36 + #define ZYNQ_QSPI_RX_THRESH_OFFSET 0x2C /* RX FIFO Watermark Reg, RW */ 37 + #define ZYNQ_QSPI_GPIO_OFFSET 0x30 /* GPIO Register, RW */ 38 + #define ZYNQ_QSPI_LINEAR_CFG_OFFSET 0xA0 /* Linear Adapter Config Ref, RW */ 39 + #define ZYNQ_QSPI_MOD_ID_OFFSET 0xFC /* Module ID Register, RO */ 40 + 41 + /* 42 + * QSPI Configuration Register bit Masks 43 + * 44 + * This register contains various control bits that effect the operation 45 + * of the QSPI controller 46 + */ 47 + #define ZYNQ_QSPI_CONFIG_IFMODE_MASK BIT(31) /* Flash Memory Interface */ 48 + #define ZYNQ_QSPI_CONFIG_MANSRT_MASK BIT(16) /* Manual TX Start */ 49 + #define ZYNQ_QSPI_CONFIG_MANSRTEN_MASK BIT(15) /* Enable Manual TX Mode */ 50 + #define ZYNQ_QSPI_CONFIG_SSFORCE_MASK BIT(14) /* Manual Chip Select */ 51 + #define ZYNQ_QSPI_CONFIG_BDRATE_MASK GENMASK(5, 3) /* Baud Rate Mask */ 52 + #define ZYNQ_QSPI_CONFIG_CPHA_MASK BIT(2) /* Clock Phase Control */ 53 + #define ZYNQ_QSPI_CONFIG_CPOL_MASK BIT(1) /* Clock Polarity Control */ 54 + #define ZYNQ_QSPI_CONFIG_SSCTRL_MASK BIT(10) /* Slave Select Mask */ 55 + #define ZYNQ_QSPI_CONFIG_FWIDTH_MASK GENMASK(7, 6) /* FIFO width */ 56 + #define ZYNQ_QSPI_CONFIG_MSTREN_MASK BIT(0) /* Master Mode */ 57 + 58 + /* 59 + * QSPI Configuration Register - Baud rate and slave select 60 + * 61 + * These are the values used in the calculation of baud rate divisor and 62 + * setting the slave select. 63 + */ 64 + #define ZYNQ_QSPI_BAUD_DIV_MAX GENMASK(2, 0) /* Baud rate maximum */ 65 + #define ZYNQ_QSPI_BAUD_DIV_SHIFT 3 /* Baud rate divisor shift in CR */ 66 + #define ZYNQ_QSPI_SS_SHIFT 10 /* Slave Select field shift in CR */ 67 + 68 + /* 69 + * QSPI Interrupt Registers bit Masks 70 + * 71 + * All the four interrupt registers (Status/Mask/Enable/Disable) have the same 72 + * bit definitions. 73 + */ 74 + #define ZYNQ_QSPI_IXR_RX_OVERFLOW_MASK BIT(0) /* QSPI RX FIFO Overflow */ 75 + #define ZYNQ_QSPI_IXR_TXNFULL_MASK BIT(2) /* QSPI TX FIFO Overflow */ 76 + #define ZYNQ_QSPI_IXR_TXFULL_MASK BIT(3) /* QSPI TX FIFO is full */ 77 + #define ZYNQ_QSPI_IXR_RXNEMTY_MASK BIT(4) /* QSPI RX FIFO Not Empty */ 78 + #define ZYNQ_QSPI_IXR_RXF_FULL_MASK BIT(5) /* QSPI RX FIFO is full */ 79 + #define ZYNQ_QSPI_IXR_TXF_UNDRFLOW_MASK BIT(6) /* QSPI TX FIFO Underflow */ 80 + #define ZYNQ_QSPI_IXR_ALL_MASK (ZYNQ_QSPI_IXR_RX_OVERFLOW_MASK | \ 81 + ZYNQ_QSPI_IXR_TXNFULL_MASK | \ 82 + ZYNQ_QSPI_IXR_TXFULL_MASK | \ 83 + ZYNQ_QSPI_IXR_RXNEMTY_MASK | \ 84 + ZYNQ_QSPI_IXR_RXF_FULL_MASK | \ 85 + ZYNQ_QSPI_IXR_TXF_UNDRFLOW_MASK) 86 + #define ZYNQ_QSPI_IXR_RXTX_MASK (ZYNQ_QSPI_IXR_TXNFULL_MASK | \ 87 + ZYNQ_QSPI_IXR_RXNEMTY_MASK) 88 + 89 + /* 90 + * QSPI Enable Register bit Masks 91 + * 92 + * This register is used to enable or disable the QSPI controller 93 + */ 94 + #define ZYNQ_QSPI_ENABLE_ENABLE_MASK BIT(0) /* QSPI Enable Bit Mask */ 95 + 96 + /* 97 + * QSPI Linear Configuration Register 98 + * 99 + * It is named Linear Configuration but it controls other modes when not in 100 + * linear mode also. 101 + */ 102 + #define ZYNQ_QSPI_LCFG_TWO_MEM_MASK BIT(30) /* LQSPI Two memories Mask */ 103 + #define ZYNQ_QSPI_LCFG_SEP_BUS_MASK BIT(29) /* LQSPI Separate bus Mask */ 104 + #define ZYNQ_QSPI_LCFG_U_PAGE_MASK BIT(28) /* LQSPI Upper Page Mask */ 105 + 106 + #define ZYNQ_QSPI_LCFG_DUMMY_SHIFT 8 107 + 108 + #define ZYNQ_QSPI_FAST_READ_QOUT_CODE 0x6B /* read instruction code */ 109 + #define ZYNQ_QSPI_FIFO_DEPTH 63 /* FIFO depth in words */ 110 + #define ZYNQ_QSPI_RX_THRESHOLD 32 /* Rx FIFO threshold level */ 111 + #define ZYNQ_QSPI_TX_THRESHOLD 1 /* Tx FIFO threshold level */ 112 + 113 + /* 114 + * The modebits configurable by the driver to make the SPI support different 115 + * data formats 116 + */ 117 + #define ZYNQ_QSPI_MODEBITS (SPI_CPOL | SPI_CPHA) 118 + 119 + /* Default number of chip selects */ 120 + #define ZYNQ_QSPI_DEFAULT_NUM_CS 1 121 + 122 + /** 123 + * struct zynq_qspi - Defines qspi driver instance 124 + * @regs: Virtual address of the QSPI controller registers 125 + * @refclk: Pointer to the peripheral clock 126 + * @pclk: Pointer to the APB clock 127 + * @irq: IRQ number 128 + * @txbuf: Pointer to the TX buffer 129 + * @rxbuf: Pointer to the RX buffer 130 + * @tx_bytes: Number of bytes left to transfer 131 + * @rx_bytes: Number of bytes left to receive 132 + * @data_completion: completion structure 133 + */ 134 + struct zynq_qspi { 135 + struct device *dev; 136 + void __iomem *regs; 137 + struct clk *refclk; 138 + struct clk *pclk; 139 + int irq; 140 + u8 *txbuf; 141 + u8 *rxbuf; 142 + int tx_bytes; 143 + int rx_bytes; 144 + struct completion data_completion; 145 + }; 146 + 147 + /* 148 + * Inline functions for the QSPI controller read/write 149 + */ 150 + static inline u32 zynq_qspi_read(struct zynq_qspi *xqspi, u32 offset) 151 + { 152 + return readl_relaxed(xqspi->regs + offset); 153 + } 154 + 155 + static inline void zynq_qspi_write(struct zynq_qspi *xqspi, u32 offset, 156 + u32 val) 157 + { 158 + writel_relaxed(val, xqspi->regs + offset); 159 + } 160 + 161 + /** 162 + * zynq_qspi_init_hw - Initialize the hardware 163 + * @xqspi: Pointer to the zynq_qspi structure 164 + * 165 + * The default settings of the QSPI controller's configurable parameters on 166 + * reset are 167 + * - Master mode 168 + * - Baud rate divisor is set to 2 169 + * - Tx threshold set to 1l Rx threshold set to 32 170 + * - Flash memory interface mode enabled 171 + * - Size of the word to be transferred as 8 bit 172 + * This function performs the following actions 173 + * - Disable and clear all the interrupts 174 + * - Enable manual slave select 175 + * - Enable manual start 176 + * - Deselect all the chip select lines 177 + * - Set the size of the word to be transferred as 32 bit 178 + * - Set the little endian mode of TX FIFO and 179 + * - Enable the QSPI controller 180 + */ 181 + static void zynq_qspi_init_hw(struct zynq_qspi *xqspi) 182 + { 183 + u32 config_reg; 184 + 185 + zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 0); 186 + zynq_qspi_write(xqspi, ZYNQ_QSPI_IDIS_OFFSET, ZYNQ_QSPI_IXR_ALL_MASK); 187 + 188 + /* Disable linear mode as the boot loader may have used it */ 189 + zynq_qspi_write(xqspi, ZYNQ_QSPI_LINEAR_CFG_OFFSET, 0); 190 + 191 + /* Clear the RX FIFO */ 192 + while (zynq_qspi_read(xqspi, ZYNQ_QSPI_STATUS_OFFSET) & 193 + ZYNQ_QSPI_IXR_RXNEMTY_MASK) 194 + zynq_qspi_read(xqspi, ZYNQ_QSPI_RXD_OFFSET); 195 + 196 + zynq_qspi_write(xqspi, ZYNQ_QSPI_STATUS_OFFSET, ZYNQ_QSPI_IXR_ALL_MASK); 197 + config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET); 198 + config_reg &= ~(ZYNQ_QSPI_CONFIG_MSTREN_MASK | 199 + ZYNQ_QSPI_CONFIG_CPOL_MASK | 200 + ZYNQ_QSPI_CONFIG_CPHA_MASK | 201 + ZYNQ_QSPI_CONFIG_BDRATE_MASK | 202 + ZYNQ_QSPI_CONFIG_SSFORCE_MASK | 203 + ZYNQ_QSPI_CONFIG_MANSRTEN_MASK | 204 + ZYNQ_QSPI_CONFIG_MANSRT_MASK); 205 + config_reg |= (ZYNQ_QSPI_CONFIG_MSTREN_MASK | 206 + ZYNQ_QSPI_CONFIG_SSFORCE_MASK | 207 + ZYNQ_QSPI_CONFIG_FWIDTH_MASK | 208 + ZYNQ_QSPI_CONFIG_IFMODE_MASK); 209 + zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg); 210 + 211 + zynq_qspi_write(xqspi, ZYNQ_QSPI_RX_THRESH_OFFSET, 212 + ZYNQ_QSPI_RX_THRESHOLD); 213 + zynq_qspi_write(xqspi, ZYNQ_QSPI_TX_THRESH_OFFSET, 214 + ZYNQ_QSPI_TX_THRESHOLD); 215 + 216 + zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 217 + ZYNQ_QSPI_ENABLE_ENABLE_MASK); 218 + } 219 + 220 + static bool zynq_qspi_supports_op(struct spi_mem *mem, 221 + const struct spi_mem_op *op) 222 + { 223 + if (!spi_mem_default_supports_op(mem, op)) 224 + return false; 225 + 226 + /* 227 + * The number of address bytes should be equal to or less than 3 bytes. 228 + */ 229 + if (op->addr.nbytes > 3) 230 + return false; 231 + 232 + return true; 233 + } 234 + 235 + /** 236 + * zynq_qspi_rxfifo_op - Read 1..4 bytes from RxFIFO to RX buffer 237 + * @xqspi: Pointer to the zynq_qspi structure 238 + * @size: Number of bytes to be read (1..4) 239 + */ 240 + static void zynq_qspi_rxfifo_op(struct zynq_qspi *xqspi, unsigned int size) 241 + { 242 + u32 data; 243 + 244 + data = zynq_qspi_read(xqspi, ZYNQ_QSPI_RXD_OFFSET); 245 + 246 + if (xqspi->rxbuf) { 247 + memcpy(xqspi->rxbuf, ((u8 *)&data) + 4 - size, size); 248 + xqspi->rxbuf += size; 249 + } 250 + 251 + xqspi->rx_bytes -= size; 252 + if (xqspi->rx_bytes < 0) 253 + xqspi->rx_bytes = 0; 254 + } 255 + 256 + /** 257 + * zynq_qspi_txfifo_op - Write 1..4 bytes from TX buffer to TxFIFO 258 + * @xqspi: Pointer to the zynq_qspi structure 259 + * @size: Number of bytes to be written (1..4) 260 + */ 261 + static void zynq_qspi_txfifo_op(struct zynq_qspi *xqspi, unsigned int size) 262 + { 263 + static const unsigned int offset[4] = { 264 + ZYNQ_QSPI_TXD_00_01_OFFSET, ZYNQ_QSPI_TXD_00_10_OFFSET, 265 + ZYNQ_QSPI_TXD_00_11_OFFSET, ZYNQ_QSPI_TXD_00_00_OFFSET }; 266 + u32 data; 267 + 268 + if (xqspi->txbuf) { 269 + data = 0xffffffff; 270 + memcpy(&data, xqspi->txbuf, size); 271 + xqspi->txbuf += size; 272 + } else { 273 + data = 0; 274 + } 275 + 276 + xqspi->tx_bytes -= size; 277 + zynq_qspi_write(xqspi, offset[size - 1], data); 278 + } 279 + 280 + /** 281 + * zynq_qspi_chipselect - Select or deselect the chip select line 282 + * @spi: Pointer to the spi_device structure 283 + * @assert: 1 for select or 0 for deselect the chip select line 284 + */ 285 + static void zynq_qspi_chipselect(struct spi_device *spi, bool assert) 286 + { 287 + struct spi_controller *ctrl = spi->master; 288 + struct zynq_qspi *xqspi = spi_controller_get_devdata(ctrl); 289 + u32 config_reg; 290 + 291 + config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET); 292 + if (assert) { 293 + /* Select the slave */ 294 + config_reg &= ~ZYNQ_QSPI_CONFIG_SSCTRL_MASK; 295 + config_reg |= (((~(BIT(spi->chip_select))) << 296 + ZYNQ_QSPI_SS_SHIFT) & 297 + ZYNQ_QSPI_CONFIG_SSCTRL_MASK); 298 + } else { 299 + config_reg |= ZYNQ_QSPI_CONFIG_SSCTRL_MASK; 300 + } 301 + 302 + zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg); 303 + } 304 + 305 + /** 306 + * zynq_qspi_config_op - Configure QSPI controller for specified transfer 307 + * @xqspi: Pointer to the zynq_qspi structure 308 + * @qspi: Pointer to the spi_device structure 309 + * 310 + * Sets the operational mode of QSPI controller for the next QSPI transfer and 311 + * sets the requested clock frequency. 312 + * 313 + * Return: 0 on success and -EINVAL on invalid input parameter 314 + * 315 + * Note: If the requested frequency is not an exact match with what can be 316 + * obtained using the prescalar value, the driver sets the clock frequency which 317 + * is lower than the requested frequency (maximum lower) for the transfer. If 318 + * the requested frequency is higher or lower than that is supported by the QSPI 319 + * controller the driver will set the highest or lowest frequency supported by 320 + * controller. 321 + */ 322 + static int zynq_qspi_config_op(struct zynq_qspi *xqspi, struct spi_device *spi) 323 + { 324 + u32 config_reg, baud_rate_val = 0; 325 + 326 + /* 327 + * Set the clock frequency 328 + * The baud rate divisor is not a direct mapping to the value written 329 + * into the configuration register (config_reg[5:3]) 330 + * i.e. 000 - divide by 2 331 + * 001 - divide by 4 332 + * ---------------- 333 + * 111 - divide by 256 334 + */ 335 + while ((baud_rate_val < ZYNQ_QSPI_BAUD_DIV_MAX) && 336 + (clk_get_rate(xqspi->refclk) / (2 << baud_rate_val)) > 337 + spi->max_speed_hz) 338 + baud_rate_val++; 339 + 340 + config_reg = zynq_qspi_read(xqspi, ZYNQ_QSPI_CONFIG_OFFSET); 341 + 342 + /* Set the QSPI clock phase and clock polarity */ 343 + config_reg &= (~ZYNQ_QSPI_CONFIG_CPHA_MASK) & 344 + (~ZYNQ_QSPI_CONFIG_CPOL_MASK); 345 + if (spi->mode & SPI_CPHA) 346 + config_reg |= ZYNQ_QSPI_CONFIG_CPHA_MASK; 347 + if (spi->mode & SPI_CPOL) 348 + config_reg |= ZYNQ_QSPI_CONFIG_CPOL_MASK; 349 + 350 + config_reg &= ~ZYNQ_QSPI_CONFIG_BDRATE_MASK; 351 + config_reg |= (baud_rate_val << ZYNQ_QSPI_BAUD_DIV_SHIFT); 352 + zynq_qspi_write(xqspi, ZYNQ_QSPI_CONFIG_OFFSET, config_reg); 353 + 354 + return 0; 355 + } 356 + 357 + /** 358 + * zynq_qspi_setup - Configure the QSPI controller 359 + * @spi: Pointer to the spi_device structure 360 + * 361 + * Sets the operational mode of QSPI controller for the next QSPI transfer, baud 362 + * rate and divisor value to setup the requested qspi clock. 363 + * 364 + * Return: 0 on success and error value on failure 365 + */ 366 + static int zynq_qspi_setup_op(struct spi_device *spi) 367 + { 368 + struct spi_controller *ctrl = spi->master; 369 + struct zynq_qspi *qspi = spi_controller_get_devdata(ctrl); 370 + 371 + if (ctrl->busy) 372 + return -EBUSY; 373 + 374 + clk_enable(qspi->refclk); 375 + clk_enable(qspi->pclk); 376 + zynq_qspi_write(qspi, ZYNQ_QSPI_ENABLE_OFFSET, 377 + ZYNQ_QSPI_ENABLE_ENABLE_MASK); 378 + 379 + return 0; 380 + } 381 + 382 + /** 383 + * zynq_qspi_write_op - Fills the TX FIFO with as many bytes as possible 384 + * @xqspi: Pointer to the zynq_qspi structure 385 + * @txcount: Maximum number of words to write 386 + * @txempty: Indicates that TxFIFO is empty 387 + */ 388 + static void zynq_qspi_write_op(struct zynq_qspi *xqspi, int txcount, 389 + bool txempty) 390 + { 391 + int count, len, k; 392 + 393 + len = xqspi->tx_bytes; 394 + if (len && len < 4) { 395 + /* 396 + * We must empty the TxFIFO between accesses to TXD0, 397 + * TXD1, TXD2, TXD3. 398 + */ 399 + if (txempty) 400 + zynq_qspi_txfifo_op(xqspi, len); 401 + 402 + return; 403 + } 404 + 405 + count = len / 4; 406 + if (count > txcount) 407 + count = txcount; 408 + 409 + if (xqspi->txbuf) { 410 + iowrite32_rep(xqspi->regs + ZYNQ_QSPI_TXD_00_00_OFFSET, 411 + xqspi->txbuf, count); 412 + xqspi->txbuf += count * 4; 413 + } else { 414 + for (k = 0; k < count; k++) 415 + writel_relaxed(0, xqspi->regs + 416 + ZYNQ_QSPI_TXD_00_00_OFFSET); 417 + } 418 + 419 + xqspi->tx_bytes -= count * 4; 420 + } 421 + 422 + /** 423 + * zynq_qspi_read_op - Drains the RX FIFO by as many bytes as possible 424 + * @xqspi: Pointer to the zynq_qspi structure 425 + * @rxcount: Maximum number of words to read 426 + */ 427 + static void zynq_qspi_read_op(struct zynq_qspi *xqspi, int rxcount) 428 + { 429 + int count, len, k; 430 + 431 + len = xqspi->rx_bytes - xqspi->tx_bytes; 432 + count = len / 4; 433 + if (count > rxcount) 434 + count = rxcount; 435 + if (xqspi->rxbuf) { 436 + ioread32_rep(xqspi->regs + ZYNQ_QSPI_RXD_OFFSET, 437 + xqspi->rxbuf, count); 438 + xqspi->rxbuf += count * 4; 439 + } else { 440 + for (k = 0; k < count; k++) 441 + readl_relaxed(xqspi->regs + ZYNQ_QSPI_RXD_OFFSET); 442 + } 443 + xqspi->rx_bytes -= count * 4; 444 + len -= count * 4; 445 + 446 + if (len && len < 4 && count < rxcount) 447 + zynq_qspi_rxfifo_op(xqspi, len); 448 + } 449 + 450 + /** 451 + * zynq_qspi_irq - Interrupt service routine of the QSPI controller 452 + * @irq: IRQ number 453 + * @dev_id: Pointer to the xqspi structure 454 + * 455 + * This function handles TX empty only. 456 + * On TX empty interrupt this function reads the received data from RX FIFO and 457 + * fills the TX FIFO if there is any data remaining to be transferred. 458 + * 459 + * Return: IRQ_HANDLED when interrupt is handled; IRQ_NONE otherwise. 460 + */ 461 + static irqreturn_t zynq_qspi_irq(int irq, void *dev_id) 462 + { 463 + u32 intr_status; 464 + bool txempty; 465 + struct zynq_qspi *xqspi = (struct zynq_qspi *)dev_id; 466 + 467 + intr_status = zynq_qspi_read(xqspi, ZYNQ_QSPI_STATUS_OFFSET); 468 + zynq_qspi_write(xqspi, ZYNQ_QSPI_STATUS_OFFSET, intr_status); 469 + 470 + if ((intr_status & ZYNQ_QSPI_IXR_TXNFULL_MASK) || 471 + (intr_status & ZYNQ_QSPI_IXR_RXNEMTY_MASK)) { 472 + /* 473 + * This bit is set when Tx FIFO has < THRESHOLD entries. 474 + * We have the THRESHOLD value set to 1, 475 + * so this bit indicates Tx FIFO is empty. 476 + */ 477 + txempty = !!(intr_status & ZYNQ_QSPI_IXR_TXNFULL_MASK); 478 + /* Read out the data from the RX FIFO */ 479 + zynq_qspi_read_op(xqspi, ZYNQ_QSPI_RX_THRESHOLD); 480 + if (xqspi->tx_bytes) { 481 + /* There is more data to send */ 482 + zynq_qspi_write_op(xqspi, ZYNQ_QSPI_RX_THRESHOLD, 483 + txempty); 484 + } else { 485 + /* 486 + * If transfer and receive is completed then only send 487 + * complete signal. 488 + */ 489 + if (!xqspi->rx_bytes) { 490 + zynq_qspi_write(xqspi, 491 + ZYNQ_QSPI_IDIS_OFFSET, 492 + ZYNQ_QSPI_IXR_RXTX_MASK); 493 + complete(&xqspi->data_completion); 494 + } 495 + } 496 + return IRQ_HANDLED; 497 + } 498 + 499 + return IRQ_NONE; 500 + } 501 + 502 + /** 503 + * zynq_qspi_exec_mem_op() - Initiates the QSPI transfer 504 + * @mem: the SPI memory 505 + * @op: the memory operation to execute 506 + * 507 + * Executes a memory operation. 508 + * 509 + * This function first selects the chip and starts the memory operation. 510 + * 511 + * Return: 0 in case of success, a negative error code otherwise. 512 + */ 513 + static int zynq_qspi_exec_mem_op(struct spi_mem *mem, 514 + const struct spi_mem_op *op) 515 + { 516 + struct zynq_qspi *xqspi = spi_controller_get_devdata(mem->spi->master); 517 + int err = 0, i; 518 + u8 *tmpbuf; 519 + 520 + dev_dbg(xqspi->dev, "cmd:%#x mode:%d.%d.%d.%d\n", 521 + op->cmd.opcode, op->cmd.buswidth, op->addr.buswidth, 522 + op->dummy.buswidth, op->data.buswidth); 523 + 524 + zynq_qspi_chipselect(mem->spi, true); 525 + zynq_qspi_config_op(xqspi, mem->spi); 526 + 527 + if (op->cmd.opcode) { 528 + reinit_completion(&xqspi->data_completion); 529 + xqspi->txbuf = (u8 *)&op->cmd.opcode; 530 + xqspi->rxbuf = NULL; 531 + xqspi->tx_bytes = sizeof(op->cmd.opcode); 532 + xqspi->rx_bytes = sizeof(op->cmd.opcode); 533 + zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true); 534 + zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET, 535 + ZYNQ_QSPI_IXR_RXTX_MASK); 536 + if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion, 537 + msecs_to_jiffies(1000))) 538 + err = -ETIMEDOUT; 539 + } 540 + 541 + if (op->addr.nbytes) { 542 + for (i = 0; i < op->addr.nbytes; i++) { 543 + xqspi->txbuf[i] = op->addr.val >> 544 + (8 * (op->addr.nbytes - i - 1)); 545 + } 546 + 547 + reinit_completion(&xqspi->data_completion); 548 + xqspi->rxbuf = NULL; 549 + xqspi->tx_bytes = op->addr.nbytes; 550 + xqspi->rx_bytes = op->addr.nbytes; 551 + zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true); 552 + zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET, 553 + ZYNQ_QSPI_IXR_RXTX_MASK); 554 + if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion, 555 + msecs_to_jiffies(1000))) 556 + err = -ETIMEDOUT; 557 + } 558 + 559 + if (op->dummy.nbytes) { 560 + tmpbuf = kzalloc(op->dummy.nbytes, GFP_KERNEL); 561 + memset(tmpbuf, 0xff, op->dummy.nbytes); 562 + reinit_completion(&xqspi->data_completion); 563 + xqspi->txbuf = tmpbuf; 564 + xqspi->rxbuf = NULL; 565 + xqspi->tx_bytes = op->dummy.nbytes; 566 + xqspi->rx_bytes = op->dummy.nbytes; 567 + zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true); 568 + zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET, 569 + ZYNQ_QSPI_IXR_RXTX_MASK); 570 + if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion, 571 + msecs_to_jiffies(1000))) 572 + err = -ETIMEDOUT; 573 + 574 + kfree(tmpbuf); 575 + } 576 + 577 + if (op->data.nbytes) { 578 + reinit_completion(&xqspi->data_completion); 579 + if (op->data.dir == SPI_MEM_DATA_OUT) { 580 + xqspi->txbuf = (u8 *)op->data.buf.out; 581 + xqspi->tx_bytes = op->data.nbytes; 582 + xqspi->rxbuf = NULL; 583 + xqspi->rx_bytes = op->data.nbytes; 584 + } else { 585 + xqspi->txbuf = NULL; 586 + xqspi->rxbuf = (u8 *)op->data.buf.in; 587 + xqspi->rx_bytes = op->data.nbytes; 588 + xqspi->tx_bytes = op->data.nbytes; 589 + } 590 + 591 + zynq_qspi_write_op(xqspi, ZYNQ_QSPI_FIFO_DEPTH, true); 592 + zynq_qspi_write(xqspi, ZYNQ_QSPI_IEN_OFFSET, 593 + ZYNQ_QSPI_IXR_RXTX_MASK); 594 + if (!wait_for_completion_interruptible_timeout(&xqspi->data_completion, 595 + msecs_to_jiffies(1000))) 596 + err = -ETIMEDOUT; 597 + } 598 + zynq_qspi_chipselect(mem->spi, false); 599 + 600 + return err; 601 + } 602 + 603 + static const struct spi_controller_mem_ops zynq_qspi_mem_ops = { 604 + .supports_op = zynq_qspi_supports_op, 605 + .exec_op = zynq_qspi_exec_mem_op, 606 + }; 607 + 608 + /** 609 + * zynq_qspi_probe - Probe method for the QSPI driver 610 + * @pdev: Pointer to the platform_device structure 611 + * 612 + * This function initializes the driver data structures and the hardware. 613 + * 614 + * Return: 0 on success and error value on failure 615 + */ 616 + static int zynq_qspi_probe(struct platform_device *pdev) 617 + { 618 + int ret = 0; 619 + struct spi_controller *ctlr; 620 + struct device *dev = &pdev->dev; 621 + struct device_node *np = dev->of_node; 622 + struct zynq_qspi *xqspi; 623 + struct resource *res; 624 + u32 num_cs; 625 + 626 + ctlr = spi_alloc_master(&pdev->dev, sizeof(*xqspi)); 627 + if (!ctlr) 628 + return -ENOMEM; 629 + 630 + xqspi = spi_controller_get_devdata(ctlr); 631 + xqspi->dev = dev; 632 + platform_set_drvdata(pdev, xqspi); 633 + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 634 + xqspi->regs = devm_ioremap_resource(&pdev->dev, res); 635 + if (IS_ERR(xqspi->regs)) { 636 + ret = PTR_ERR(xqspi->regs); 637 + goto remove_master; 638 + } 639 + 640 + xqspi->pclk = devm_clk_get(&pdev->dev, "pclk"); 641 + if (IS_ERR(xqspi->pclk)) { 642 + dev_err(&pdev->dev, "pclk clock not found.\n"); 643 + ret = PTR_ERR(xqspi->pclk); 644 + goto remove_master; 645 + } 646 + 647 + init_completion(&xqspi->data_completion); 648 + 649 + xqspi->refclk = devm_clk_get(&pdev->dev, "ref_clk"); 650 + if (IS_ERR(xqspi->refclk)) { 651 + dev_err(&pdev->dev, "ref_clk clock not found.\n"); 652 + ret = PTR_ERR(xqspi->refclk); 653 + goto remove_master; 654 + } 655 + 656 + ret = clk_prepare_enable(xqspi->pclk); 657 + if (ret) { 658 + dev_err(&pdev->dev, "Unable to enable APB clock.\n"); 659 + goto remove_master; 660 + } 661 + 662 + ret = clk_prepare_enable(xqspi->refclk); 663 + if (ret) { 664 + dev_err(&pdev->dev, "Unable to enable device clock.\n"); 665 + goto clk_dis_pclk; 666 + } 667 + 668 + /* QSPI controller initializations */ 669 + zynq_qspi_init_hw(xqspi); 670 + 671 + xqspi->irq = platform_get_irq(pdev, 0); 672 + if (xqspi->irq <= 0) { 673 + ret = -ENXIO; 674 + dev_err(&pdev->dev, "irq resource not found\n"); 675 + goto remove_master; 676 + } 677 + ret = devm_request_irq(&pdev->dev, xqspi->irq, zynq_qspi_irq, 678 + 0, pdev->name, xqspi); 679 + if (ret != 0) { 680 + ret = -ENXIO; 681 + dev_err(&pdev->dev, "request_irq failed\n"); 682 + goto remove_master; 683 + } 684 + 685 + ret = of_property_read_u32(np, "num-cs", 686 + &num_cs); 687 + if (ret < 0) 688 + ctlr->num_chipselect = ZYNQ_QSPI_DEFAULT_NUM_CS; 689 + else 690 + ctlr->num_chipselect = num_cs; 691 + 692 + ctlr->mode_bits = SPI_RX_DUAL | SPI_RX_QUAD | 693 + SPI_TX_DUAL | SPI_TX_QUAD; 694 + ctlr->mem_ops = &zynq_qspi_mem_ops; 695 + ctlr->setup = zynq_qspi_setup_op; 696 + ctlr->max_speed_hz = clk_get_rate(xqspi->refclk) / 2; 697 + ctlr->dev.of_node = np; 698 + ret = spi_register_controller(ctlr); 699 + if (ret) { 700 + dev_err(&pdev->dev, "spi_register_master failed\n"); 701 + goto clk_dis_all; 702 + } 703 + 704 + return ret; 705 + 706 + clk_dis_all: 707 + clk_disable_unprepare(xqspi->refclk); 708 + clk_dis_pclk: 709 + clk_disable_unprepare(xqspi->pclk); 710 + remove_master: 711 + spi_controller_put(ctlr); 712 + 713 + return ret; 714 + } 715 + 716 + /** 717 + * zynq_qspi_remove - Remove method for the QSPI driver 718 + * @pdev: Pointer to the platform_device structure 719 + * 720 + * This function is called if a device is physically removed from the system or 721 + * if the driver module is being unloaded. It frees all resources allocated to 722 + * the device. 723 + * 724 + * Return: 0 on success and error value on failure 725 + */ 726 + static int zynq_qspi_remove(struct platform_device *pdev) 727 + { 728 + struct zynq_qspi *xqspi = platform_get_drvdata(pdev); 729 + 730 + zynq_qspi_write(xqspi, ZYNQ_QSPI_ENABLE_OFFSET, 0); 731 + 732 + clk_disable_unprepare(xqspi->refclk); 733 + clk_disable_unprepare(xqspi->pclk); 734 + 735 + return 0; 736 + } 737 + 738 + static const struct of_device_id zynq_qspi_of_match[] = { 739 + { .compatible = "xlnx,zynq-qspi-1.0", }, 740 + { /* end of table */ } 741 + }; 742 + 743 + MODULE_DEVICE_TABLE(of, zynq_qspi_of_match); 744 + 745 + /* 746 + * zynq_qspi_driver - This structure defines the QSPI platform driver 747 + */ 748 + static struct platform_driver zynq_qspi_driver = { 749 + .probe = zynq_qspi_probe, 750 + .remove = zynq_qspi_remove, 751 + .driver = { 752 + .name = "zynq-qspi", 753 + .of_match_table = zynq_qspi_of_match, 754 + }, 755 + }; 756 + 757 + module_platform_driver(zynq_qspi_driver); 758 + 759 + MODULE_AUTHOR("Xilinx, Inc."); 760 + MODULE_DESCRIPTION("Xilinx Zynq QSPI driver"); 761 + MODULE_LICENSE("GPL");
+44 -28
drivers/spi/spi.c
··· 36 36 37 37 #define CREATE_TRACE_POINTS 38 38 #include <trace/events/spi.h> 39 + EXPORT_TRACEPOINT_SYMBOL(spi_transfer_start); 40 + EXPORT_TRACEPOINT_SYMBOL(spi_transfer_stop); 39 41 40 42 #include "internals.h" 41 43 ··· 1181 1179 if (msg->status && ctlr->handle_err) 1182 1180 ctlr->handle_err(ctlr, msg); 1183 1181 1184 - spi_res_release(ctlr, msg); 1185 - 1186 1182 spi_finalize_current_message(ctlr); 1183 + 1184 + spi_res_release(ctlr, msg); 1187 1185 1188 1186 return ret; 1189 1187 } ··· 2267 2265 { 2268 2266 struct device *dev = ctlr->dev.parent; 2269 2267 struct boardinfo *bi; 2270 - int status = -ENODEV; 2268 + int status; 2271 2269 int id, first_dynamic; 2272 2270 2273 2271 if (!dev) ··· 2280 2278 status = spi_controller_check_ops(ctlr); 2281 2279 if (status) 2282 2280 return status; 2283 - 2284 - if (!spi_controller_is_slave(ctlr)) { 2285 - if (ctlr->use_gpio_descriptors) { 2286 - status = spi_get_gpio_descs(ctlr); 2287 - if (status) 2288 - return status; 2289 - /* 2290 - * A controller using GPIO descriptors always 2291 - * supports SPI_CS_HIGH if need be. 2292 - */ 2293 - ctlr->mode_bits |= SPI_CS_HIGH; 2294 - } else { 2295 - /* Legacy code path for GPIOs from DT */ 2296 - status = of_spi_register_master(ctlr); 2297 - if (status) 2298 - return status; 2299 - } 2300 - } 2301 2281 2302 2282 /* even if it's just one always-selected device, there must 2303 2283 * be at least one chipselect ··· 2337 2353 * registration fails if the bus ID is in use. 2338 2354 */ 2339 2355 dev_set_name(&ctlr->dev, "spi%u", ctlr->bus_num); 2356 + 2357 + if (!spi_controller_is_slave(ctlr)) { 2358 + if (ctlr->use_gpio_descriptors) { 2359 + status = spi_get_gpio_descs(ctlr); 2360 + if (status) 2361 + return status; 2362 + /* 2363 + * A controller using GPIO descriptors always 2364 + * supports SPI_CS_HIGH if need be. 2365 + */ 2366 + ctlr->mode_bits |= SPI_CS_HIGH; 2367 + } else { 2368 + /* Legacy code path for GPIOs from DT */ 2369 + status = of_spi_register_master(ctlr); 2370 + if (status) 2371 + return status; 2372 + } 2373 + } 2374 + 2340 2375 status = device_add(&ctlr->dev); 2341 2376 if (status < 0) { 2342 2377 /* free bus id */ ··· 2788 2785 size_t offset; 2789 2786 size_t count, i; 2790 2787 2791 - /* warn once about this fact that we are splitting a transfer */ 2792 - dev_warn_once(&msg->spi->dev, 2793 - "spi_transfer of length %i exceed max length of %zu - needed to split transfers\n", 2794 - xfer->len, maxsize); 2795 - 2796 2788 /* calculate how many we have to replace */ 2797 2789 count = DIV_ROUND_UP(xfer->len, maxsize); 2798 2790 ··· 2945 2947 * so it is ignored here. 2946 2948 */ 2947 2949 bad_bits = spi->mode & ~(spi->controller->mode_bits | SPI_CS_WORD); 2950 + /* nothing prevents from working with active-high CS in case if it 2951 + * is driven by GPIO. 2952 + */ 2953 + if (gpio_is_valid(spi->cs_gpio)) 2954 + bad_bits &= ~SPI_CS_HIGH; 2948 2955 ugly_bits = bad_bits & 2949 2956 (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL | 2950 2957 SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL); ··· 2994 2991 return status; 2995 2992 } 2996 2993 EXPORT_SYMBOL_GPL(spi_setup); 2994 + 2995 + /** 2996 + * spi_set_cs_timing - configure CS setup, hold, and inactive delays 2997 + * @spi: the device that requires specific CS timing configuration 2998 + * @setup: CS setup time in terms of clock count 2999 + * @hold: CS hold time in terms of clock count 3000 + * @inactive_dly: CS inactive delay between transfers in terms of clock count 3001 + */ 3002 + void spi_set_cs_timing(struct spi_device *spi, u8 setup, u8 hold, 3003 + u8 inactive_dly) 3004 + { 3005 + if (spi->controller->set_cs_timing) 3006 + spi->controller->set_cs_timing(spi, setup, hold, inactive_dly); 3007 + } 3008 + EXPORT_SYMBOL_GPL(spi_set_cs_timing); 2997 3009 2998 3010 static int __spi_validate(struct spi_device *spi, struct spi_message *message) 2999 3011 { ··· 3084 3066 3085 3067 if (!xfer->speed_hz) 3086 3068 xfer->speed_hz = spi->max_speed_hz; 3087 - if (!xfer->speed_hz) 3088 - xfer->speed_hz = ctlr->max_speed_hz; 3089 3069 3090 3070 if (ctlr->max_speed_hz && xfer->speed_hz > ctlr->max_speed_hz) 3091 3071 xfer->speed_hz = ctlr->max_speed_hz;
+3 -1
drivers/spi/spidev.c
··· 276 276 k_tmp->bits_per_word = u_tmp->bits_per_word; 277 277 k_tmp->delay_usecs = u_tmp->delay_usecs; 278 278 k_tmp->speed_hz = u_tmp->speed_hz; 279 + k_tmp->word_delay_usecs = u_tmp->word_delay_usecs; 279 280 if (!k_tmp->speed_hz) 280 281 k_tmp->speed_hz = spidev->speed_hz; 281 282 #ifdef VERBOSE 282 283 dev_dbg(&spidev->spi->dev, 283 - " xfer len %u %s%s%s%dbits %u usec %uHz\n", 284 + " xfer len %u %s%s%s%dbits %u usec %u usec %uHz\n", 284 285 u_tmp->len, 285 286 u_tmp->rx_buf ? "rx " : "", 286 287 u_tmp->tx_buf ? "tx " : "", 287 288 u_tmp->cs_change ? "cs " : "", 288 289 u_tmp->bits_per_word ? : spidev->spi->bits_per_word, 289 290 u_tmp->delay_usecs, 291 + u_tmp->word_delay_usecs, 290 292 u_tmp->speed_hz ? : spidev->spi->max_speed_hz); 291 293 #endif 292 294 spi_message_add_tail(k_tmp, &msg);
-2
drivers/staging/Kconfig
··· 106 106 107 107 source "drivers/staging/mt7621-pinctrl/Kconfig" 108 108 109 - source "drivers/staging/mt7621-spi/Kconfig" 110 - 111 109 source "drivers/staging/mt7621-dma/Kconfig" 112 110 113 111 source "drivers/staging/ralink-gdma/Kconfig"
-1
drivers/staging/Makefile
··· 43 43 obj-$(CONFIG_PCI_MT7621) += mt7621-pci/ 44 44 obj-$(CONFIG_PCI_MT7621_PHY) += mt7621-pci-phy/ 45 45 obj-$(CONFIG_PINCTRL_RT2880) += mt7621-pinctrl/ 46 - obj-$(CONFIG_SPI_MT7621) += mt7621-spi/ 47 46 obj-$(CONFIG_SOC_MT7621) += mt7621-dma/ 48 47 obj-$(CONFIG_DMA_RALINK) += ralink-gdma/ 49 48 obj-$(CONFIG_MTK_MMC) += mt7621-mmc/
-6
drivers/staging/mt7621-spi/Kconfig
··· 1 - config SPI_MT7621 2 - tristate "MediaTek MT7621 SPI Controller" 3 - depends on RALINK 4 - help 5 - This selects a driver for the MediaTek MT7621 SPI Controller. 6 -
-1
drivers/staging/mt7621-spi/Makefile
··· 1 - obj-$(CONFIG_SPI_MT7621) += spi-mt7621.o
-5
drivers/staging/mt7621-spi/TODO
··· 1 - 2 - - general code review and clean up 3 - - ensure device-tree requirements are documented 4 - 5 - Cc: NeilBrown <neil@brown.name>
+41 -42
drivers/staging/mt7621-spi/spi-mt7621.c drivers/spi/spi-mt7621.c
··· 1 1 // SPDX-License-Identifier: GPL-2.0 2 - /* 3 - * spi-mt7621.c -- MediaTek MT7621 SPI controller driver 4 - * 5 - * Copyright (C) 2011 Sergiy <piratfm@gmail.com> 6 - * Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org> 7 - * Copyright (C) 2014-2015 Felix Fietkau <nbd@nbd.name> 8 - * 9 - * Some parts are based on spi-orion.c: 10 - * Author: Shadi Ammouri <shadi@marvell.com> 11 - * Copyright (C) 2007-2008 Marvell Ltd. 12 - */ 2 + // 3 + // spi-mt7621.c -- MediaTek MT7621 SPI controller driver 4 + // 5 + // Copyright (C) 2011 Sergiy <piratfm@gmail.com> 6 + // Copyright (C) 2011-2013 Gabor Juhos <juhosg@openwrt.org> 7 + // Copyright (C) 2014-2015 Felix Fietkau <nbd@nbd.name> 8 + // 9 + // Some parts are based on spi-orion.c: 10 + // Author: Shadi Ammouri <shadi@marvell.com> 11 + // Copyright (C) 2007-2008 Marvell Ltd. 13 12 14 13 #include <linux/clk.h> 15 14 #include <linux/delay.h> ··· 51 52 #define MT7621_LSB_FIRST BIT(3) 52 53 53 54 struct mt7621_spi { 54 - struct spi_master *master; 55 + struct spi_controller *master; 55 56 void __iomem *base; 56 57 unsigned int sys_freq; 57 58 unsigned int speed; ··· 63 64 64 65 static inline struct mt7621_spi *spidev_to_mt7621_spi(struct spi_device *spi) 65 66 { 66 - return spi_master_get_devdata(spi->master); 67 + return spi_controller_get_devdata(spi->master); 67 68 } 68 69 69 70 static inline u32 mt7621_spi_read(struct mt7621_spi *rs, u32 reg) ··· 76 77 iowrite32(val, rs->base + reg); 77 78 } 78 79 79 - static void mt7621_spi_reset(struct mt7621_spi *rs) 80 + static void mt7621_spi_set_cs(struct spi_device *spi, int enable) 80 81 { 81 - u32 master = mt7621_spi_read(rs, MT7621_SPI_MASTER); 82 + struct mt7621_spi *rs = spidev_to_mt7621_spi(spi); 83 + int cs = spi->chip_select; 84 + u32 polar = 0; 85 + u32 master; 82 86 83 87 /* 84 88 * Select SPI device 7, enable "more buffer mode" and disable 85 89 * full-duplex (only half-duplex really works on this chip 86 90 * reliably) 87 91 */ 92 + master = mt7621_spi_read(rs, MT7621_SPI_MASTER); 88 93 master |= MASTER_RS_SLAVE_SEL | MASTER_MORE_BUFMODE; 89 94 master &= ~MASTER_FULL_DUPLEX; 90 - 91 95 mt7621_spi_write(rs, MT7621_SPI_MASTER, master); 96 + 92 97 rs->pending_write = 0; 93 - } 94 98 95 - static void mt7621_spi_set_cs(struct spi_device *spi, int enable) 96 - { 97 - struct mt7621_spi *rs = spidev_to_mt7621_spi(spi); 98 - int cs = spi->chip_select; 99 - u32 polar = 0; 100 - 101 - mt7621_spi_reset(rs); 102 99 if (enable) 103 100 polar = BIT(cs); 104 101 mt7621_spi_write(rs, MT7621_SPI_POLAR, polar); ··· 158 163 static void mt7621_spi_read_half_duplex(struct mt7621_spi *rs, 159 164 int rx_len, u8 *buf) 160 165 { 166 + int tx_len; 167 + 161 168 /* 162 169 * Combine with any pending write, and perform one or more half-duplex 163 170 * transactions reading 'len' bytes. Data to be written is already in 164 171 * MT7621_SPI_DATA. 165 172 */ 166 - int tx_len = rs->pending_write; 167 - 173 + tx_len = rs->pending_write; 168 174 rs->pending_write = 0; 169 175 170 176 while (rx_len || tx_len) { ··· 205 209 static void mt7621_spi_write_half_duplex(struct mt7621_spi *rs, 206 210 int tx_len, const u8 *buf) 207 211 { 208 - int val = 0; 209 212 int len = rs->pending_write; 213 + int val = 0; 210 214 211 215 if (len & 3) { 212 216 val = mt7621_spi_read(rs, MT7621_SPI_OPCODE + (len & ~3)); ··· 234 238 } 235 239 tx_len -= 1; 236 240 } 241 + 237 242 if (len & 3) { 238 243 if (len < 4) { 239 244 val = swab32(val); ··· 242 245 } 243 246 mt7621_spi_write(rs, MT7621_SPI_OPCODE + (len & ~3), val); 244 247 } 248 + 245 249 rs->pending_write = len; 246 250 } 247 251 248 - static int mt7621_spi_transfer_one_message(struct spi_master *master, 252 + static int mt7621_spi_transfer_one_message(struct spi_controller *master, 249 253 struct spi_message *m) 250 254 { 251 - struct mt7621_spi *rs = spi_master_get_devdata(master); 255 + struct mt7621_spi *rs = spi_controller_get_devdata(master); 252 256 struct spi_device *spi = m->spi; 253 257 unsigned int speed = spi->max_speed_hz; 254 258 struct spi_transfer *t = NULL; ··· 266 268 goto msg_done; 267 269 } 268 270 271 + /* Assert CS */ 269 272 mt7621_spi_set_cs(spi, 1); 273 + 270 274 m->actual_length = 0; 271 275 list_for_each_entry(t, &m->transfers, transfer_list) { 272 276 if ((t->rx_buf) && (t->tx_buf)) { 273 - /* This controller will shift some extra data out 277 + /* 278 + * This controller will shift some extra data out 274 279 * of spi_opcode if (mosi_bit_cnt > 0) && 275 280 * (cmd_bit_cnt == 0). So the claimed full-duplex 276 281 * support is broken since we have no way to read ··· 288 287 } 289 288 m->actual_length += t->len; 290 289 } 291 - mt7621_spi_flush(rs); 292 290 291 + /* Flush data and deassert CS */ 292 + mt7621_spi_flush(rs); 293 293 mt7621_spi_set_cs(spi, 0); 294 294 295 295 msg_done: ··· 305 303 struct mt7621_spi *rs = spidev_to_mt7621_spi(spi); 306 304 307 305 if ((spi->max_speed_hz == 0) || 308 - (spi->max_speed_hz > (rs->sys_freq / 2))) 306 + (spi->max_speed_hz > (rs->sys_freq / 2))) 309 307 spi->max_speed_hz = (rs->sys_freq / 2); 310 308 311 309 if (spi->max_speed_hz < (rs->sys_freq / 4097)) { ··· 326 324 static int mt7621_spi_probe(struct platform_device *pdev) 327 325 { 328 326 const struct of_device_id *match; 329 - struct spi_master *master; 327 + struct spi_controller *master; 330 328 struct mt7621_spi *rs; 331 329 void __iomem *base; 332 330 struct resource *r; ··· 363 361 } 364 362 365 363 master->mode_bits = SPI_LSB_FIRST; 366 - 364 + master->flags = SPI_CONTROLLER_HALF_DUPLEX; 367 365 master->setup = mt7621_spi_setup; 368 366 master->transfer_one_message = mt7621_spi_transfer_one_message; 369 367 master->bits_per_word_mask = SPI_BPW_MASK(8); ··· 372 370 373 371 dev_set_drvdata(&pdev->dev, master); 374 372 375 - rs = spi_master_get_devdata(master); 373 + rs = spi_controller_get_devdata(master); 376 374 rs->base = base; 377 375 rs->clk = clk; 378 376 rs->master = master; ··· 387 385 return ret; 388 386 } 389 387 390 - mt7621_spi_reset(rs); 391 - 392 - return spi_register_master(master); 388 + return devm_spi_register_controller(&pdev->dev, master); 393 389 } 394 390 395 391 static int mt7621_spi_remove(struct platform_device *pdev) 396 392 { 397 - struct spi_master *master; 393 + struct spi_controller *master; 398 394 struct mt7621_spi *rs; 399 395 400 396 master = dev_get_drvdata(&pdev->dev); 401 - rs = spi_master_get_devdata(master); 397 + rs = spi_controller_get_devdata(master); 402 398 403 - clk_disable(rs->clk); 404 - spi_unregister_master(master); 399 + clk_disable_unprepare(rs->clk); 405 400 406 401 return 0; 407 402 }
-4
include/linux/platform_data/spi-ep93xx.h
··· 6 6 7 7 /** 8 8 * struct ep93xx_spi_info - EP93xx specific SPI descriptor 9 - * @chipselect: array of gpio numbers to use as chip selects 10 - * @num_chipselect: ARRAY_SIZE(chipselect) 11 9 * @use_dma: use DMA for the transfers 12 10 */ 13 11 struct ep93xx_spi_info { 14 - int *chipselect; 15 - int num_chipselect; 16 12 bool use_dma; 17 13 }; 18 14
+1
include/linux/spi/pxa2xx_spi.h
··· 25 25 struct pxa2xx_spi_controller { 26 26 u16 num_chipselect; 27 27 u8 enable_dma; 28 + u8 dma_burst_size; 28 29 bool is_slave; 29 30 30 31 /* DMA engine specific config */
+12
include/linux/spi/spi-mem.h
··· 295 295 void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr, 296 296 const struct spi_mem_op *op, 297 297 struct sg_table *sg); 298 + 299 + bool spi_mem_default_supports_op(struct spi_mem *mem, 300 + const struct spi_mem_op *op); 301 + 298 302 #else 299 303 static inline int 300 304 spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr, ··· 314 310 struct sg_table *sg) 315 311 { 316 312 } 313 + 314 + static inline 315 + bool spi_mem_default_supports_op(struct spi_mem *mem, 316 + const struct spi_mem_op *op) 317 + { 318 + return false; 319 + } 320 + 317 321 #endif /* CONFIG_SPI_MEM */ 318 322 319 323 int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op);
+19 -5
include/linux/spi/spi.h
··· 143 143 u32 max_speed_hz; 144 144 u8 chip_select; 145 145 u8 bits_per_word; 146 - u16 mode; 146 + u32 mode; 147 147 #define SPI_CPHA 0x01 /* clock phase */ 148 148 #define SPI_CPOL 0x02 /* clock polarity */ 149 149 #define SPI_MODE_0 (0|0) /* (original MicroWire) */ ··· 330 330 * must fail if an unrecognized or unsupported mode is requested. 331 331 * It's always safe to call this unless transfers are pending on 332 332 * the device whose settings are being modified. 333 + * @set_cs_timing: optional hook for SPI devices to request SPI master 334 + * controller for configuring specific CS setup time, hold time and inactive 335 + * delay interms of clock counts 333 336 * @transfer: adds a message to the controller's transfer queue. 334 337 * @cleanup: frees controller-specific state 335 338 * @can_dma: determine whether this controller supports DMA ··· 366 363 * @unprepare_transfer_hardware: there are currently no more messages on the 367 364 * queue so the subsystem notifies the driver that it may relax the 368 365 * hardware by issuing this call 366 + * 369 367 * @set_cs: set the logic level of the chip select line. May be called 370 368 * from interrupt context. 371 369 * @prepare_message: set up the controller to transfer a single message, ··· 443 439 u16 dma_alignment; 444 440 445 441 /* spi_device.mode flags understood by this controller driver */ 446 - u16 mode_bits; 442 + u32 mode_bits; 447 443 448 444 /* bitmask of supported bits_per_word for transfers */ 449 445 u32 bits_per_word_mask; 450 446 #define SPI_BPW_MASK(bits) BIT((bits) - 1) 451 - #define SPI_BIT_MASK(bits) (((bits) == 32) ? ~0U : (BIT(bits) - 1)) 452 - #define SPI_BPW_RANGE_MASK(min, max) (SPI_BIT_MASK(max) - SPI_BIT_MASK(min - 1)) 447 + #define SPI_BPW_RANGE_MASK(min, max) GENMASK((max) - 1, (min) - 1) 453 448 454 449 /* limits on transfer speed */ 455 450 u32 min_speed_hz; ··· 491 488 * which could break those transfers. 492 489 */ 493 490 int (*setup)(struct spi_device *spi); 491 + 492 + /* 493 + * set_cs_timing() method is for SPI controllers that supports 494 + * configuring CS timing. 495 + * 496 + * This hook allows SPI client drivers to request SPI controllers 497 + * to configure specific CS timing through spi_set_cs_timing() after 498 + * spi_setup(). 499 + */ 500 + void (*set_cs_timing)(struct spi_device *spi, u8 setup_clk_cycles, 501 + u8 hold_clk_cycles, u8 inactive_clk_cycles); 494 502 495 503 /* bidirectional bulk transfers 496 504 * ··· 1291 1277 /* mode becomes spi_device.mode, and is essential for chips 1292 1278 * where the default of SPI_CS_HIGH = 0 is wrong. 1293 1279 */ 1294 - u16 mode; 1280 + u32 mode; 1295 1281 1296 1282 /* ... may need additional spi_device chip config data here. 1297 1283 * avoid stuff protocol drivers can set; but include stuff
+1
include/linux/spi/spi_bitbang.h
··· 44 44 45 45 /* start or stop queue processing */ 46 46 extern int spi_bitbang_start(struct spi_bitbang *spi); 47 + extern int spi_bitbang_init(struct spi_bitbang *spi); 47 48 extern void spi_bitbang_stop(struct spi_bitbang *spi); 48 49 49 50 #endif /* __SPI_BITBANG_H */
+6 -4
include/trace/events/spi.h
··· 131 131 __field( struct spi_transfer *, xfer ) 132 132 __field( int, len ) 133 133 __dynamic_array(u8, rx_buf, 134 - spi_valid_rxbuf(msg, xfer) ? xfer->len : 0) 134 + spi_valid_rxbuf(msg, xfer) ? 135 + (xfer->len < 64 ? xfer->len : 64) : 0) 135 136 __dynamic_array(u8, tx_buf, 136 - spi_valid_txbuf(msg, xfer) ? xfer->len : 0) 137 + spi_valid_txbuf(msg, xfer) ? 138 + (xfer->len < 64 ? xfer->len : 64) : 0) 137 139 ), 138 140 139 141 TP_fast_assign( ··· 146 144 147 145 if (spi_valid_txbuf(msg, xfer)) 148 146 memcpy(__get_dynamic_array(tx_buf), 149 - xfer->tx_buf, xfer->len); 147 + xfer->tx_buf, __get_dynamic_array_len(tx_buf)); 150 148 151 149 if (spi_valid_rxbuf(msg, xfer)) 152 150 memcpy(__get_dynamic_array(rx_buf), 153 - xfer->rx_buf, xfer->len); 151 + xfer->rx_buf, __get_dynamic_array_len(rx_buf)); 154 152 ), 155 153 156 154 TP_printk("spi%d.%d %p len=%d tx=[%*phD] rx=[%*phD]",
+5 -1
include/uapi/linux/spi/spidev.h
··· 66 66 * @delay_usecs: If nonzero, how long to delay after the last bit transfer 67 67 * before optionally deselecting the device before the next transfer. 68 68 * @cs_change: True to deselect device before starting the next transfer. 69 + * @word_delay_usecs: If nonzero, how long to wait between words within one 70 + * transfer. This property needs explicit support in the SPI controller, 71 + * otherwise it is silently ignored. 69 72 * 70 73 * This structure is mapped directly to the kernel spi_transfer structure; 71 74 * the fields have the same meanings, except of course that the pointers ··· 103 100 __u8 cs_change; 104 101 __u8 tx_nbits; 105 102 __u8 rx_nbits; 106 - __u16 pad; 103 + __u8 word_delay_usecs; 104 + __u8 pad; 107 105 108 106 /* If the contents of 'struct spi_ioc_transfer' ever change 109 107 * incompatibly, then the ioctl number (currently 0) must change;
+11
sound/soc/codecs/adau1977-spi.c
··· 10 10 #include <linux/mod_devicetable.h> 11 11 #include <linux/module.h> 12 12 #include <linux/regmap.h> 13 + #include <linux/of.h> 14 + #include <linux/of_device.h> 13 15 #include <linux/spi/spi.h> 14 16 #include <sound/soc.h> 15 17 ··· 56 54 }; 57 55 MODULE_DEVICE_TABLE(spi, adau1977_spi_ids); 58 56 57 + static const struct of_device_id adau1977_spi_of_match[] = { 58 + { .compatible = "adi,adau1977" }, 59 + { .compatible = "adi,adau1978" }, 60 + { .compatible = "adi,adau1979" }, 61 + { }, 62 + }; 63 + MODULE_DEVICE_TABLE(of, adau1977_spi_of_match); 64 + 59 65 static struct spi_driver adau1977_spi_driver = { 60 66 .driver = { 61 67 .name = "adau1977", 68 + .of_match_table = of_match_ptr(adau1977_spi_of_match), 62 69 }, 63 70 .probe = adau1977_spi_probe, 64 71 .id_table = adau1977_spi_ids,