aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/spi
diff options
context:
space:
mode:
authorDavid Brownell <dbrownell@users.sourceforge.net>2009-06-17 19:26:03 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2009-06-18 16:03:42 -0400
commit7d0771970c51e736758525dd71fb82dd036b823a (patch)
tree9ff72b89cd06cd67e0db681859606dd77f5cba80 /drivers/spi
parentb4bd2ababd20b6ecdd49cf96e39c875fbedd53af (diff)
spi: move common spi_setup() functionality into core
Start moving some spi_setup() functionality into the SPI core from the various spi_master controller drivers: - Make that function stop being an inline; - Move two common idioms from drivers into that new function: * Default bits_per_word to 8 if that field isn't set * Issue a standardized dev_dbg() message This is a net minor source code shrink, and supports enhancments found in some follow-up patches. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/spi')
-rw-r--r--drivers/spi/atmel_spi.c2
-rw-r--r--drivers/spi/au1550_spi.c2
-rw-r--r--drivers/spi/omap2_mcspi.c4
-rw-r--r--drivers/spi/omap_uwire.c2
-rw-r--r--drivers/spi/orion_spi.c3
-rw-r--r--drivers/spi/pxa2xx_spi.c11
-rw-r--r--drivers/spi/spi.c55
-rw-r--r--drivers/spi/spi_bfin5xx.c4
-rw-r--r--drivers/spi/spi_bitbang.c7
-rw-r--r--drivers/spi/spi_imx.c5
-rw-r--r--drivers/spi/spi_mpc83xx.c6
-rw-r--r--drivers/spi/spi_s3c24xx.c7
-rw-r--r--drivers/spi/spi_txx9.c2
-rw-r--r--drivers/spi/xilinx_spi.c6
14 files changed, 60 insertions, 56 deletions
diff --git a/drivers/spi/atmel_spi.c b/drivers/spi/atmel_spi.c
index 12e443cc4ac9..9f9ff3af72d7 100644
--- a/drivers/spi/atmel_spi.c
+++ b/drivers/spi/atmel_spi.c
@@ -555,8 +555,6 @@ static int atmel_spi_setup(struct spi_device *spi)
555 return -EINVAL; 555 return -EINVAL;
556 } 556 }
557 557
558 if (bits == 0)
559 bits = 8;
560 if (bits < 8 || bits > 16) { 558 if (bits < 8 || bits > 16) {
561 dev_dbg(&spi->dev, 559 dev_dbg(&spi->dev,
562 "setup: invalid bits_per_word %u (8 to 16)\n", 560 "setup: invalid bits_per_word %u (8 to 16)\n",
diff --git a/drivers/spi/au1550_spi.c b/drivers/spi/au1550_spi.c
index b02f25c702fd..6a407e60f05b 100644
--- a/drivers/spi/au1550_spi.c
+++ b/drivers/spi/au1550_spi.c
@@ -291,8 +291,6 @@ static int au1550_spi_setup(struct spi_device *spi)
291{ 291{
292 struct au1550_spi *hw = spi_master_get_devdata(spi->master); 292 struct au1550_spi *hw = spi_master_get_devdata(spi->master);
293 293
294 if (spi->bits_per_word == 0)
295 spi->bits_per_word = 8;
296 if (spi->bits_per_word < 4 || spi->bits_per_word > 24) { 294 if (spi->bits_per_word < 4 || spi->bits_per_word > 24) {
297 dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n", 295 dev_err(&spi->dev, "setup: invalid bits_per_word=%d\n",
298 spi->bits_per_word); 296 spi->bits_per_word);
diff --git a/drivers/spi/omap2_mcspi.c b/drivers/spi/omap2_mcspi.c
index d6d0c5d241ce..b4f3b753d0f4 100644
--- a/drivers/spi/omap2_mcspi.c
+++ b/drivers/spi/omap2_mcspi.c
@@ -619,9 +619,7 @@ static int omap2_mcspi_setup(struct spi_device *spi)
619 return -EINVAL; 619 return -EINVAL;
620 } 620 }
621 621
622 if (spi->bits_per_word == 0) 622 if (spi->bits_per_word < 4 || spi->bits_per_word > 32) {
623 spi->bits_per_word = 8;
624 else if (spi->bits_per_word < 4 || spi->bits_per_word > 32) {
625 dev_dbg(&spi->dev, "setup: unsupported %d bit words\n", 623 dev_dbg(&spi->dev, "setup: unsupported %d bit words\n",
626 spi->bits_per_word); 624 spi->bits_per_word);
627 return -EINVAL; 625 return -EINVAL;
diff --git a/drivers/spi/omap_uwire.c b/drivers/spi/omap_uwire.c
index fe8b9ac0ccef..747d29be45d5 100644
--- a/drivers/spi/omap_uwire.c
+++ b/drivers/spi/omap_uwire.c
@@ -339,8 +339,6 @@ static int uwire_setup_transfer(struct spi_device *spi, struct spi_transfer *t)
339 bits = spi->bits_per_word; 339 bits = spi->bits_per_word;
340 if (t != NULL && t->bits_per_word) 340 if (t != NULL && t->bits_per_word)
341 bits = t->bits_per_word; 341 bits = t->bits_per_word;
342 if (!bits)
343 bits = 8;
344 342
345 if (bits > 16) { 343 if (bits > 16) {
346 pr_debug("%s: wordsize %d?\n", dev_name(&spi->dev), bits); 344 pr_debug("%s: wordsize %d?\n", dev_name(&spi->dev), bits);
diff --git a/drivers/spi/orion_spi.c b/drivers/spi/orion_spi.c
index c8b0babdc2a6..6d5e33bb4b4a 100644
--- a/drivers/spi/orion_spi.c
+++ b/drivers/spi/orion_spi.c
@@ -369,9 +369,6 @@ static int orion_spi_setup(struct spi_device *spi)
369 orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG, 369 orion_spi_setbits(orion_spi, ORION_SPI_IF_CONFIG_REG,
370 (1 << 14)); 370 (1 << 14));
371 371
372 if (spi->bits_per_word == 0)
373 spi->bits_per_word = 8;
374
375 if ((spi->max_speed_hz == 0) 372 if ((spi->max_speed_hz == 0)
376 || (spi->max_speed_hz > orion_spi->max_speed)) 373 || (spi->max_speed_hz > orion_spi->max_speed))
377 spi->max_speed_hz = orion_spi->max_speed; 374 spi->max_speed_hz = orion_spi->max_speed;
diff --git a/drivers/spi/pxa2xx_spi.c b/drivers/spi/pxa2xx_spi.c
index 3f3c08c6ba4e..c7365e0b22dd 100644
--- a/drivers/spi/pxa2xx_spi.c
+++ b/drivers/spi/pxa2xx_spi.c
@@ -1236,9 +1236,6 @@ static int setup(struct spi_device *spi)
1236 uint tx_thres = TX_THRESH_DFLT; 1236 uint tx_thres = TX_THRESH_DFLT;
1237 uint rx_thres = RX_THRESH_DFLT; 1237 uint rx_thres = RX_THRESH_DFLT;
1238 1238
1239 if (!spi->bits_per_word)
1240 spi->bits_per_word = 8;
1241
1242 if (drv_data->ssp_type != PXA25x_SSP 1239 if (drv_data->ssp_type != PXA25x_SSP
1243 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) { 1240 && (spi->bits_per_word < 4 || spi->bits_per_word > 32)) {
1244 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d " 1241 dev_err(&spi->dev, "failed setup: ssp_type=%d, bits/wrd=%d "
@@ -1328,18 +1325,14 @@ static int setup(struct spi_device *spi)
1328 1325
1329 /* NOTE: PXA25x_SSP _could_ use external clocking ... */ 1326 /* NOTE: PXA25x_SSP _could_ use external clocking ... */
1330 if (drv_data->ssp_type != PXA25x_SSP) 1327 if (drv_data->ssp_type != PXA25x_SSP)
1331 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n", 1328 dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
1332 spi->bits_per_word,
1333 clk_get_rate(ssp->clk) 1329 clk_get_rate(ssp->clk)
1334 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)), 1330 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1335 spi->mode & 0x3,
1336 chip->enable_dma ? "DMA" : "PIO"); 1331 chip->enable_dma ? "DMA" : "PIO");
1337 else 1332 else
1338 dev_dbg(&spi->dev, "%d bits/word, %ld Hz, mode %d, %s\n", 1333 dev_dbg(&spi->dev, "%ld Hz actual, %s\n",
1339 spi->bits_per_word,
1340 clk_get_rate(ssp->clk) / 2 1334 clk_get_rate(ssp->clk) / 2
1341 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)), 1335 / (1 + ((chip->cr0 & SSCR0_SCR) >> 8)),
1342 spi->mode & 0x3,
1343 chip->enable_dma ? "DMA" : "PIO"); 1336 chip->enable_dma ? "DMA" : "PIO");
1344 1337
1345 if (spi->bits_per_word <= 8) { 1338 if (spi->bits_per_word <= 8) {
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 8eba98c8ed1e..0276bc37e255 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -265,7 +265,7 @@ int spi_add_device(struct spi_device *spi)
265 * normally rely on the device being setup. Devices 265 * normally rely on the device being setup. Devices
266 * using SPI_CS_HIGH can't coexist well otherwise... 266 * using SPI_CS_HIGH can't coexist well otherwise...
267 */ 267 */
268 status = spi->master->setup(spi); 268 status = spi_setup(spi);
269 if (status < 0) { 269 if (status < 0) {
270 dev_err(dev, "can't %s %s, status %d\n", 270 dev_err(dev, "can't %s %s, status %d\n",
271 "setup", dev_name(&spi->dev), status); 271 "setup", dev_name(&spi->dev), status);
@@ -583,6 +583,59 @@ EXPORT_SYMBOL_GPL(spi_busnum_to_master);
583 583
584/*-------------------------------------------------------------------------*/ 584/*-------------------------------------------------------------------------*/
585 585
586/* Core methods for SPI master protocol drivers. Some of the
587 * other core methods are currently defined as inline functions.
588 */
589
590/**
591 * spi_setup - setup SPI mode and clock rate
592 * @spi: the device whose settings are being modified
593 * Context: can sleep, and no requests are queued to the device
594 *
595 * SPI protocol drivers may need to update the transfer mode if the
596 * device doesn't work with its default. They may likewise need
597 * to update clock rates or word sizes from initial values. This function
598 * changes those settings, and must be called from a context that can sleep.
599 * Except for SPI_CS_HIGH, which takes effect immediately, the changes take
600 * effect the next time the device is selected and data is transferred to
601 * or from it. When this function returns, the spi device is deselected.
602 *
603 * Note that this call will fail if the protocol driver specifies an option
604 * that the underlying controller or its driver does not support. For
605 * example, not all hardware supports wire transfers using nine bit words,
606 * LSB-first wire encoding, or active-high chipselects.
607 */
608int spi_setup(struct spi_device *spi)
609{
610 int status;
611
612 if (!spi->bits_per_word)
613 spi->bits_per_word = 8;
614
615 status = spi->master->setup(spi);
616
617 dev_dbg(&spi->dev, "setup mode %d, %s%s%s%s"
618 "%u bits/w, %u Hz max --> %d\n",
619 (int) (spi->mode & (SPI_CPOL | SPI_CPHA)),
620 (spi->mode & SPI_CS_HIGH) ? "cs_high, " : "",
621 (spi->mode & SPI_LSB_FIRST) ? "lsb, " : "",
622 (spi->mode & SPI_3WIRE) ? "3wire, " : "",
623 (spi->mode & SPI_LOOP) ? "loopback, " : "",
624 spi->bits_per_word, spi->max_speed_hz,
625 status);
626
627 return status;
628}
629EXPORT_SYMBOL_GPL(spi_setup);
630
631
632/*-------------------------------------------------------------------------*/
633
634/* Utility methods for SPI master protocol drivers, layered on
635 * top of the core. Some other utility methods are defined as
636 * inline functions.
637 */
638
586static void spi_complete(void *arg) 639static void spi_complete(void *arg)
587{ 640{
588 complete(arg); 641 complete(arg);
diff --git a/drivers/spi/spi_bfin5xx.c b/drivers/spi/spi_bfin5xx.c
index 2e5fd0977334..d54058a903be 100644
--- a/drivers/spi/spi_bfin5xx.c
+++ b/drivers/spi/spi_bfin5xx.c
@@ -1016,10 +1016,6 @@ static int bfin_spi_setup(struct spi_device *spi)
1016 return -EINVAL; 1016 return -EINVAL;
1017 } 1017 }
1018 1018
1019 /* Zero (the default) here means 8 bits */
1020 if (!spi->bits_per_word)
1021 spi->bits_per_word = 8;
1022
1023 if (spi->bits_per_word != 8 && spi->bits_per_word != 16) 1019 if (spi->bits_per_word != 8 && spi->bits_per_word != 16)
1024 return -EINVAL; 1020 return -EINVAL;
1025 1021
diff --git a/drivers/spi/spi_bitbang.c b/drivers/spi/spi_bitbang.c
index 85e61f451218..855b0b06e625 100644
--- a/drivers/spi/spi_bitbang.c
+++ b/drivers/spi/spi_bitbang.c
@@ -201,9 +201,6 @@ int spi_bitbang_setup(struct spi_device *spi)
201 spi->controller_state = cs; 201 spi->controller_state = cs;
202 } 202 }
203 203
204 if (!spi->bits_per_word)
205 spi->bits_per_word = 8;
206
207 /* per-word shift register access, in hardware or bitbanging */ 204 /* per-word shift register access, in hardware or bitbanging */
208 cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)]; 205 cs->txrx_word = bitbang->txrx_word[spi->mode & (SPI_CPOL|SPI_CPHA)];
209 if (!cs->txrx_word) 206 if (!cs->txrx_word)
@@ -213,9 +210,7 @@ int spi_bitbang_setup(struct spi_device *spi)
213 if (retval < 0) 210 if (retval < 0)
214 return retval; 211 return retval;
215 212
216 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n", 213 dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs);
217 __func__, spi->mode & (SPI_CPOL | SPI_CPHA),
218 spi->bits_per_word, 2 * cs->nsecs);
219 214
220 /* NOTE we _need_ to call chipselect() early, ideally with adapter 215 /* NOTE we _need_ to call chipselect() early, ideally with adapter
221 * setup, unless the hardware defaults cooperate to avoid confusion 216 * setup, unless the hardware defaults cooperate to avoid confusion
diff --git a/drivers/spi/spi_imx.c b/drivers/spi/spi_imx.c
index 0671aeef5792..26d5ef06dbd9 100644
--- a/drivers/spi/spi_imx.c
+++ b/drivers/spi/spi_imx.c
@@ -1286,10 +1286,7 @@ static int setup(struct spi_device *spi)
1286 1286
1287 /* SPI word width */ 1287 /* SPI word width */
1288 tmp = spi->bits_per_word; 1288 tmp = spi->bits_per_word;
1289 if (tmp == 0) { 1289 if (tmp > 16) {
1290 tmp = 8;
1291 spi->bits_per_word = 8;
1292 } else if (tmp > 16) {
1293 status = -EINVAL; 1290 status = -EINVAL;
1294 dev_err(&spi->dev, 1291 dev_err(&spi->dev,
1295 "setup - " 1292 "setup - "
diff --git a/drivers/spi/spi_mpc83xx.c b/drivers/spi/spi_mpc83xx.c
index a32ccb44065e..0926a3e293e0 100644
--- a/drivers/spi/spi_mpc83xx.c
+++ b/drivers/spi/spi_mpc83xx.c
@@ -447,9 +447,6 @@ static int mpc83xx_spi_setup(struct spi_device *spi)
447 } 447 }
448 mpc83xx_spi = spi_master_get_devdata(spi->master); 448 mpc83xx_spi = spi_master_get_devdata(spi->master);
449 449
450 if (!spi->bits_per_word)
451 spi->bits_per_word = 8;
452
453 hw_mode = cs->hw_mode; /* Save orginal settings */ 450 hw_mode = cs->hw_mode; /* Save orginal settings */
454 cs->hw_mode = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode); 451 cs->hw_mode = mpc83xx_spi_read_reg(&mpc83xx_spi->base->mode);
455 /* mask out bits we are going to set */ 452 /* mask out bits we are going to set */
@@ -471,9 +468,6 @@ static int mpc83xx_spi_setup(struct spi_device *spi)
471 return retval; 468 return retval;
472 } 469 }
473 470
474 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u Hz\n",
475 __func__, spi->mode & (SPI_CPOL | SPI_CPHA),
476 spi->bits_per_word, spi->max_speed_hz);
477#if 0 /* Don't think this is needed */ 471#if 0 /* Don't think this is needed */
478 /* NOTE we _need_ to call chipselect() early, ideally with adapter 472 /* NOTE we _need_ to call chipselect() early, ideally with adapter
479 * setup, unless the hardware defaults cooperate to avoid confusion 473 * setup, unless the hardware defaults cooperate to avoid confusion
diff --git a/drivers/spi/spi_s3c24xx.c b/drivers/spi/spi_s3c24xx.c
index b3ebc1d0f85f..18a4c7f54380 100644
--- a/drivers/spi/spi_s3c24xx.c
+++ b/drivers/spi/spi_s3c24xx.c
@@ -153,9 +153,6 @@ static int s3c24xx_spi_setup(struct spi_device *spi)
153{ 153{
154 int ret; 154 int ret;
155 155
156 if (!spi->bits_per_word)
157 spi->bits_per_word = 8;
158
159 if (spi->mode & ~MODEBITS) { 156 if (spi->mode & ~MODEBITS) {
160 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n", 157 dev_dbg(&spi->dev, "setup: unsupported mode bits %x\n",
161 spi->mode & ~MODEBITS); 158 spi->mode & ~MODEBITS);
@@ -168,10 +165,6 @@ static int s3c24xx_spi_setup(struct spi_device *spi)
168 return ret; 165 return ret;
169 } 166 }
170 167
171 dev_dbg(&spi->dev, "%s: mode %d, %u bpw, %d hz\n",
172 __func__, spi->mode, spi->bits_per_word,
173 spi->max_speed_hz);
174
175 return 0; 168 return 0;
176} 169}
177 170
diff --git a/drivers/spi/spi_txx9.c b/drivers/spi/spi_txx9.c
index 29cbb065618a..8e36b2153d9a 100644
--- a/drivers/spi/spi_txx9.c
+++ b/drivers/spi/spi_txx9.c
@@ -126,7 +126,7 @@ static int txx9spi_setup(struct spi_device *spi)
126 || spi->max_speed_hz < c->min_speed_hz) 126 || spi->max_speed_hz < c->min_speed_hz)
127 return -EINVAL; 127 return -EINVAL;
128 128
129 bits_per_word = spi->bits_per_word ? : 8; 129 bits_per_word = spi->bits_per_word;
130 if (bits_per_word != 8 && bits_per_word != 16) 130 if (bits_per_word != 8 && bits_per_word != 16)
131 return -EINVAL; 131 return -EINVAL;
132 132
diff --git a/drivers/spi/xilinx_spi.c b/drivers/spi/xilinx_spi.c
index 494d3f756e29..2d7e6b81fb4a 100644
--- a/drivers/spi/xilinx_spi.c
+++ b/drivers/spi/xilinx_spi.c
@@ -170,9 +170,6 @@ static int xilinx_spi_setup(struct spi_device *spi)
170 xspi = spi_master_get_devdata(spi->master); 170 xspi = spi_master_get_devdata(spi->master);
171 bitbang = &xspi->bitbang; 171 bitbang = &xspi->bitbang;
172 172
173 if (!spi->bits_per_word)
174 spi->bits_per_word = 8;
175
176 if (spi->mode & ~MODEBITS) { 173 if (spi->mode & ~MODEBITS) {
177 dev_err(&spi->dev, "%s, unsupported mode bits %x\n", 174 dev_err(&spi->dev, "%s, unsupported mode bits %x\n",
178 __func__, spi->mode & ~MODEBITS); 175 __func__, spi->mode & ~MODEBITS);
@@ -183,9 +180,6 @@ static int xilinx_spi_setup(struct spi_device *spi)
183 if (retval < 0) 180 if (retval < 0)
184 return retval; 181 return retval;
185 182
186 dev_dbg(&spi->dev, "%s, mode %d, %u bits/w, %u nsec/bit\n",
187 __func__, spi->mode & MODEBITS, spi->bits_per_word, 0);
188
189 return 0; 183 return 0;
190} 184}
191 185