aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi/spi-fsl-spi.c
diff options
context:
space:
mode:
authorAndreas Larsson <andreas@gaisler.com>2013-02-15 10:52:23 -0500
committerGrant Likely <grant.likely@secretlab.ca>2013-04-07 05:07:55 -0400
commitb48c4e3c944e8c52dcb0f477e9d80da045c7cab4 (patch)
treeeff07b425dbacd77730328b7ca8cdd69670ea052 /drivers/spi/spi-fsl-spi.c
parentf482cd0ff506cd74c75edceec4b737c46c60cb12 (diff)
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>
Diffstat (limited to 'drivers/spi/spi-fsl-spi.c')
-rw-r--r--drivers/spi/spi-fsl-spi.c51
1 files changed, 31 insertions, 20 deletions
diff --git a/drivers/spi/spi-fsl-spi.c b/drivers/spi/spi-fsl-spi.c
index 1569f7defc73..aba00fd0791f 100644
--- a/drivers/spi/spi-fsl-spi.c
+++ b/drivers/spi/spi-fsl-spi.c
@@ -91,6 +91,25 @@ static void fsl_spi_chipselect(struct spi_device *spi, int value)
91 } 91 }
92} 92}
93 93
94static 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
94static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs, 113static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs,
95 struct spi_device *spi, 114 struct spi_device *spi,
96 struct mpc8xxx_spi *mpc8xxx_spi, 115 struct mpc8xxx_spi *mpc8xxx_spi,
@@ -101,31 +120,20 @@ static int mspi_apply_cpu_mode_quirks(struct spi_mpc8xxx_cs *cs,
101 if (bits_per_word <= 8) { 120 if (bits_per_word <= 8) {
102 cs->get_rx = mpc8xxx_spi_rx_buf_u8; 121 cs->get_rx = mpc8xxx_spi_rx_buf_u8;
103 cs->get_tx = mpc8xxx_spi_tx_buf_u8; 122 cs->get_tx = mpc8xxx_spi_tx_buf_u8;
104 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
105 cs->rx_shift = 16;
106 cs->tx_shift = 24;
107 }
108 } else if (bits_per_word <= 16) { 123 } else if (bits_per_word <= 16) {
109 cs->get_rx = mpc8xxx_spi_rx_buf_u16; 124 cs->get_rx = mpc8xxx_spi_rx_buf_u16;
110 cs->get_tx = mpc8xxx_spi_tx_buf_u16; 125 cs->get_tx = mpc8xxx_spi_tx_buf_u16;
111 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) {
112 cs->rx_shift = 16;
113 cs->tx_shift = 16;
114 }
115 } else if (bits_per_word <= 32) { 126 } else if (bits_per_word <= 32) {
116 cs->get_rx = mpc8xxx_spi_rx_buf_u32; 127 cs->get_rx = mpc8xxx_spi_rx_buf_u32;
117 cs->get_tx = mpc8xxx_spi_tx_buf_u32; 128 cs->get_tx = mpc8xxx_spi_tx_buf_u32;
118 } else 129 } else
119 return -EINVAL; 130 return -EINVAL;
120 131
121 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE && 132 if (mpc8xxx_spi->set_shifts)
122 spi->mode & SPI_LSB_FIRST) { 133 mpc8xxx_spi->set_shifts(&cs->rx_shift, &cs->tx_shift,
123 cs->tx_shift = 0; 134 bits_per_word,
124 if (bits_per_word <= 8) 135 !(spi->mode & SPI_LSB_FIRST));
125 cs->rx_shift = 8; 136
126 else
127 cs->rx_shift = 0;
128 }
129 mpc8xxx_spi->rx_shift = cs->rx_shift; 137 mpc8xxx_spi->rx_shift = cs->rx_shift;
130 mpc8xxx_spi->tx_shift = cs->tx_shift; 138 mpc8xxx_spi->tx_shift = cs->tx_shift;
131 mpc8xxx_spi->get_rx = cs->get_rx; 139 mpc8xxx_spi->get_rx = cs->get_rx;
@@ -487,10 +495,13 @@ static struct spi_master * fsl_spi_probe(struct device *dev,
487 if (ret) 495 if (ret)
488 goto err_cpm_init; 496 goto err_cpm_init;
489 497
490 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE) { 498 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)
491 mpc8xxx_spi->rx_shift = 16; 499 mpc8xxx_spi->set_shifts = fsl_spi_qe_cpu_set_shifts;
492 mpc8xxx_spi->tx_shift = 24; 500
493 } 501 if (mpc8xxx_spi->set_shifts)
502 /* 8 bits per word and MSB first */
503 mpc8xxx_spi->set_shifts(&mpc8xxx_spi->rx_shift,
504 &mpc8xxx_spi->tx_shift, 8, 1);
494 505
495 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem)); 506 mpc8xxx_spi->reg_base = ioremap(mem->start, resource_size(mem));
496 if (mpc8xxx_spi->reg_base == NULL) { 507 if (mpc8xxx_spi->reg_base == NULL) {