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

spi/spi-fsl-spi: Move setting non-zero tx and rx shifts to a function accessed by a function pointer

Acked-by: Anton Vorontsov <anton@enomsg.org>
Signed-off-by: Andreas Larsson <andreas@gaisler.com>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>

authored by

Andreas Larsson and committed by
Grant Likely
b48c4e3c f482cd0f

+36 -20
+5
drivers/spi/spi-fsl-lib.h
··· 69 69 70 70 unsigned int flags; 71 71 72 + #ifdef CONFIG_SPI_FSL_SPI 73 + void (*set_shifts)(u32 *rx_shift, u32 *tx_shift, 74 + int bits_per_word, int msb_first); 75 + #endif 76 + 72 77 struct workqueue_struct *workqueue; 73 78 struct work_struct work; 74 79
+31 -20
drivers/spi/spi-fsl-spi.c
··· 91 91 } 92 92 } 93 93 94 + static void fsl_spi_qe_cpu_set_shifts(u32 *rx_shift, u32 *tx_shift, 95 + int bits_per_word, int msb_first) 96 + { 97 + *rx_shift = 0; 98 + *tx_shift = 0; 99 + if (msb_first) { 100 + if (bits_per_word <= 8) { 101 + *rx_shift = 16; 102 + *tx_shift = 24; 103 + } else if (bits_per_word <= 16) { 104 + *rx_shift = 16; 105 + *tx_shift = 16; 106 + } 107 + } else { 108 + if (bits_per_word <= 8) 109 + *rx_shift = 8; 110 + } 111 + } 112 + 94 113 static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs, 95 114 struct spi_device *spi, 96 115 struct mpc8xxx_spi *mpc8xxx_spi, ··· 120 101 if (bits_per_word <= 8) { 121 102 cs->get_rx = mpc8xxx_spi_rx_buf_u8; 122 103 cs->get_tx = mpc8xxx_spi_tx_buf_u8; 123 - if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) { 124 - cs->rx_shift = 16; 125 - cs->tx_shift = 24; 126 - } 127 104 } else if (bits_per_word <= 16) { 128 105 cs->get_rx = mpc8xxx_spi_rx_buf_u16; 129 106 cs->get_tx = mpc8xxx_spi_tx_buf_u16; 130 - if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) { 131 - cs->rx_shift = 16; 132 - cs->tx_shift = 16; 133 - } 134 107 } else if (bits_per_word <= 32) { 135 108 cs->get_rx = mpc8xxx_spi_rx_buf_u32; 136 109 cs->get_tx = mpc8xxx_spi_tx_buf_u32; 137 110 } else 138 111 return -EINVAL; 139 112 140 - if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE && 141 - spi->mode & SPI_LSB_FIRST) { 142 - cs->tx_shift = 0; 143 - if (bits_per_word <= 8) 144 - cs->rx_shift = 8; 145 - else 146 - cs->rx_shift = 0; 147 - } 113 + if (mpc8xxx_spi->set_shifts) 114 + mpc8xxx_spi->set_shifts(&cs->rx_shift, &cs->tx_shift, 115 + bits_per_word, 116 + !(spi->mode & SPI_LSB_FIRST)); 117 + 148 118 mpc8xxx_spi->rx_shift = cs->rx_shift; 149 119 mpc8xxx_spi->tx_shift = cs->tx_shift; 150 120 mpc8xxx_spi->get_rx = cs->get_rx; ··· 495 487 if (ret) 496 488 goto err_cpm_init; 497 489 498 - if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) { 499 - mpc8xxx_spi->rx_shift = 16; 500 - mpc8xxx_spi->tx_shift = 24; 501 - } 490 + if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) 491 + mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts; 492 + 493 + if (mpc8xxx_spi->set_shifts) 494 + /* 8 bits per word and MSB first */ 495 + mpc8xxx_spi->set_shifts(&mpc8xxx_spi->rx_shift, 496 + &mpc8xxx_spi->tx_shift, 8, 1); 502 497 503 498 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem)); 504 499 if (mpc8xxx_spi->reg_base == NULL) {