aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2009-10-12 12:49:24 -0400
committerKumar Gala <galak@kernel.crashing.org>2009-11-11 22:43:23 -0500
commita35c1710956f7aef06f58d22d343d7b948fbc272 (patch)
treefc026a45ac6ccf28aa8d4e153835b850a1cab70a /drivers/spi
parent783058fd582a1d8afbbf1d4e9b7918614a4550ff (diff)
spi_mpc8xxx: Factor out SPI mode change steps into a call
We'll add more steps soon, so get rid of the duplication. Signed-off-by: Anton Vorontsov <avorontsov@ru.mvista.com> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/spi_mpc8xxx.c56
1 files changed, 24 insertions, 32 deletions
diff --git a/drivers/spi/spi_mpc8xxx.c b/drivers/spi/spi_mpc8xxx.c
index 518671b8afe..4b119eaf4e6 100644
--- a/drivers/spi/spi_mpc8xxx.c
+++ b/drivers/spi/spi_mpc8xxx.c
@@ -155,6 +155,26 @@ MPC83XX_SPI_TX_BUF(u8)
155MPC83XX_SPI_TX_BUF(u16) 155MPC83XX_SPI_TX_BUF(u16)
156MPC83XX_SPI_TX_BUF(u32) 156MPC83XX_SPI_TX_BUF(u32)
157 157
158static void mpc8xxx_spi_change_mode(struct spi_device *spi)
159{
160 struct mpc8xxx_spi *mspi = spi_master_get_devdata(spi->master);
161 struct spi_mpc8xxx_cs *cs = spi->controller_state;
162 __be32 __iomem *mode = &mspi->base->mode;
163 unsigned long flags;
164
165 if (cs->hw_mode == mpc8xxx_spi_read_reg(mode))
166 return;
167
168 /* Turn off IRQs locally to minimize time that SPI is disabled. */
169 local_irq_save(flags);
170
171 /* Turn off SPI unit prior changing mode */
172 mpc8xxx_spi_write_reg(mode, cs->hw_mode & ~SPMODE_ENABLE);
173 mpc8xxx_spi_write_reg(mode, cs->hw_mode);
174
175 local_irq_restore(flags);
176}
177
158static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value) 178static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
159{ 179{
160 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master); 180 struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
@@ -168,27 +188,13 @@ static void mpc8xxx_spi_chipselect(struct spi_device *spi, int value)
168 } 188 }
169 189
170 if (value == BITBANG_CS_ACTIVE) { 190 if (value == BITBANG_CS_ACTIVE) {
171 u32 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode);
172
173 mpc8xxx_spi->rx_shift = cs->rx_shift; 191 mpc8xxx_spi->rx_shift = cs->rx_shift;
174 mpc8xxx_spi->tx_shift = cs->tx_shift; 192 mpc8xxx_spi->tx_shift = cs->tx_shift;
175 mpc8xxx_spi->get_rx = cs->get_rx; 193 mpc8xxx_spi->get_rx = cs->get_rx;
176 mpc8xxx_spi->get_tx = cs->get_tx; 194 mpc8xxx_spi->get_tx = cs->get_tx;
177 195
178 if (cs->hw_mode != regval) { 196 mpc8xxx_spi_change_mode(spi);
179 unsigned long flags; 197
180 __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
181
182 regval = cs->hw_mode;
183 /* Turn off IRQs locally to minimize time that
184 * SPI is disabled
185 */
186 local_irq_save(flags);
187 /* Turn off SPI unit prior changing mode */
188 mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
189 mpc8xxx_spi_write_reg(mode, regval);
190 local_irq_restore(flags);
191 }
192 if (pdata->cs_control) 198 if (pdata->cs_control)
193 pdata->cs_control(spi, pol); 199 pdata->cs_control(spi, pol);
194 } 200 }
@@ -198,7 +204,6 @@ static
198int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t) 204int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
199{ 205{
200 struct mpc8xxx_spi *mpc8xxx_spi; 206 struct mpc8xxx_spi *mpc8xxx_spi;
201 u32 regval;
202 u8 bits_per_word, pm; 207 u8 bits_per_word, pm;
203 u32 hz; 208 u32 hz;
204 struct spi_mpc8xxx_cs *cs = spi->controller_state; 209 struct spi_mpc8xxx_cs *cs = spi->controller_state;
@@ -286,21 +291,8 @@ int mpc8xxx_spi_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
286 pm--; 291 pm--;
287 292
288 cs->hw_mode |= SPMODE_PM(pm); 293 cs->hw_mode |= SPMODE_PM(pm);
289 regval = mpc8xxx_spi_read_reg(&mpc8xxx_spi->base->mode); 294
290 if (cs->hw_mode != regval) { 295 mpc8xxx_spi_change_mode(spi);
291 unsigned long flags;
292 __be32 __iomem *mode = &mpc8xxx_spi->base->mode;
293
294 regval = cs->hw_mode;
295 /* Turn off IRQs locally to minimize time
296 * that SPI is disabled
297 */
298 local_irq_save(flags);
299 /* Turn off SPI unit prior changing mode */
300 mpc8xxx_spi_write_reg(mode, regval & ~SPMODE_ENABLE);
301 mpc8xxx_spi_write_reg(mode, regval);
302 local_irq_restore(flags);
303 }
304 return 0; 296 return 0;
305} 297}
306 298