diff options
author | Brian Niebuhr <bniebuhr@efjohnson.com> | 2010-08-19 02:45:22 -0400 |
---|---|---|
committer | Sekhar Nori <nsekhar@ti.com> | 2010-11-18 08:08:26 -0500 |
commit | 25f33512f6ae7e37d7b3d353d57d4d6d066033ce (patch) | |
tree | 2c458d56e07f842c78fd31f7e13a28fe1b7a9361 /drivers/spi/davinci_spi.c | |
parent | 53a31b07c5aea4001bbb36ddd5ef2addffc7ccbd (diff) |
spi: davinci: consolidate setup of SPIFMTn in one function
Consolidate the setup of SPIFMTn register under
davinci_spi_setup_transfer() simplifying the code
and avoiding unnecessary reads and writes to the
register.
The two inline functions {set|clear}_fmt_bits() can
be eliminated because of this.
Signed-off-by: Brian Niebuhr <bniebuhr@efjohnson.com>
Tested-By: Michael Williamson <michael.williamson@criticallink.com>
Signed-off-by: Sekhar Nori <nsekhar@ti.com>
Diffstat (limited to 'drivers/spi/davinci_spi.c')
-rw-r--r-- | drivers/spi/davinci_spi.c | 154 |
1 files changed, 49 insertions, 105 deletions
diff --git a/drivers/spi/davinci_spi.c b/drivers/spi/davinci_spi.c index d4320f784070..34b28fe2d327 100644 --- a/drivers/spi/davinci_spi.c +++ b/drivers/spi/davinci_spi.c | |||
@@ -52,7 +52,6 @@ | |||
52 | #define SPIFMT_ODD_PARITY_MASK BIT(23) | 52 | #define SPIFMT_ODD_PARITY_MASK BIT(23) |
53 | #define SPIFMT_WDELAY_MASK 0x3f000000u | 53 | #define SPIFMT_WDELAY_MASK 0x3f000000u |
54 | #define SPIFMT_WDELAY_SHIFT 24 | 54 | #define SPIFMT_WDELAY_SHIFT 24 |
55 | #define SPIFMT_CHARLEN_MASK 0x0000001Fu | ||
56 | #define SPIFMT_PRESCALE_SHIFT 8 | 55 | #define SPIFMT_PRESCALE_SHIFT 8 |
57 | 56 | ||
58 | 57 | ||
@@ -212,16 +211,6 @@ static inline void clear_io_bits(void __iomem *addr, u32 bits) | |||
212 | iowrite32(v, addr); | 211 | iowrite32(v, addr); |
213 | } | 212 | } |
214 | 213 | ||
215 | static inline void set_fmt_bits(void __iomem *addr, u32 bits, int cs_num) | ||
216 | { | ||
217 | set_io_bits(addr + SPIFMT0 + (0x4 * cs_num), bits); | ||
218 | } | ||
219 | |||
220 | static inline void clear_fmt_bits(void __iomem *addr, u32 bits, int cs_num) | ||
221 | { | ||
222 | clear_io_bits(addr + SPIFMT0 + (0x4 * cs_num), bits); | ||
223 | } | ||
224 | |||
225 | static void davinci_spi_set_dma_req(const struct spi_device *spi, int enable) | 214 | static void davinci_spi_set_dma_req(const struct spi_device *spi, int enable) |
226 | { | 215 | { |
227 | struct davinci_spi *davinci_spi = spi_master_get_devdata(spi->master); | 216 | struct davinci_spi *davinci_spi = spi_master_get_devdata(spi->master); |
@@ -306,10 +295,14 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, | |||
306 | { | 295 | { |
307 | 296 | ||
308 | struct davinci_spi *davinci_spi; | 297 | struct davinci_spi *davinci_spi; |
298 | struct davinci_spi_config *spicfg; | ||
309 | u8 bits_per_word = 0; | 299 | u8 bits_per_word = 0; |
310 | u32 hz = 0, prescale = 0; | 300 | u32 hz = 0, spifmt = 0, prescale = 0; |
311 | 301 | ||
312 | davinci_spi = spi_master_get_devdata(spi->master); | 302 | davinci_spi = spi_master_get_devdata(spi->master); |
303 | spicfg = (struct davinci_spi_config *)spi->controller_data; | ||
304 | if (!spicfg) | ||
305 | spicfg = &davinci_spi_default_cfg; | ||
313 | 306 | ||
314 | if (t) { | 307 | if (t) { |
315 | bits_per_word = t->bits_per_word; | 308 | bits_per_word = t->bits_per_word; |
@@ -338,18 +331,55 @@ static int davinci_spi_setup_transfer(struct spi_device *spi, | |||
338 | if (!hz) | 331 | if (!hz) |
339 | hz = spi->max_speed_hz; | 332 | hz = spi->max_speed_hz; |
340 | 333 | ||
334 | /* Set up SPIFMTn register, unique to this chipselect. */ | ||
335 | |||
341 | prescale = davinci_spi_get_prescale(davinci_spi, hz); | 336 | prescale = davinci_spi_get_prescale(davinci_spi, hz); |
342 | if (prescale < 0) | 337 | if (prescale < 0) |
343 | return prescale; | 338 | return prescale; |
344 | 339 | ||
345 | clear_fmt_bits(davinci_spi->base, SPIFMT_CHARLEN_MASK, | 340 | spifmt = (prescale << SPIFMT_PRESCALE_SHIFT) | (bits_per_word & 0x1f); |
346 | spi->chip_select); | 341 | |
347 | set_fmt_bits(davinci_spi->base, bits_per_word & 0x1f, | 342 | if (spi->mode & SPI_LSB_FIRST) |
348 | spi->chip_select); | 343 | spifmt |= SPIFMT_SHIFTDIR_MASK; |
344 | |||
345 | if (spi->mode & SPI_CPOL) | ||
346 | spifmt |= SPIFMT_POLARITY_MASK; | ||
347 | |||
348 | if (!(spi->mode & SPI_CPHA)) | ||
349 | spifmt |= SPIFMT_PHASE_MASK; | ||
350 | |||
351 | /* | ||
352 | * Version 1 hardware supports two basic SPI modes: | ||
353 | * - Standard SPI mode uses 4 pins, with chipselect | ||
354 | * - 3 pin SPI is a 4 pin variant without CS (SPI_NO_CS) | ||
355 | * (distinct from SPI_3WIRE, with just one data wire; | ||
356 | * or similar variants without MOSI or without MISO) | ||
357 | * | ||
358 | * Version 2 hardware supports an optional handshaking signal, | ||
359 | * so it can support two more modes: | ||
360 | * - 5 pin SPI variant is standard SPI plus SPI_READY | ||
361 | * - 4 pin with enable is (SPI_READY | SPI_NO_CS) | ||
362 | */ | ||
363 | |||
364 | if (davinci_spi->version == SPI_VERSION_2) { | ||
365 | |||
366 | spifmt |= ((spicfg->wdelay << SPIFMT_WDELAY_SHIFT) | ||
367 | & SPIFMT_WDELAY_MASK); | ||
349 | 368 | ||
350 | clear_fmt_bits(davinci_spi->base, 0x0000ff00, spi->chip_select); | 369 | if (spicfg->odd_parity) |
351 | set_fmt_bits(davinci_spi->base, | 370 | spifmt |= SPIFMT_ODD_PARITY_MASK; |
352 | prescale << SPIFMT_PRESCALE_SHIFT, spi->chip_select); | 371 | |
372 | if (spicfg->parity_enable) | ||
373 | spifmt |= SPIFMT_PARITYENA_MASK; | ||
374 | |||
375 | if (spicfg->timer_disable) | ||
376 | spifmt |= SPIFMT_DISTIMER_MASK; | ||
377 | |||
378 | if (spi->mode & SPI_READY) | ||
379 | spifmt |= SPIFMT_WAITENA_MASK; | ||
380 | } | ||
381 | |||
382 | iowrite32(spifmt, davinci_spi->base + SPIFMT0); | ||
353 | 383 | ||
354 | return 0; | 384 | return 0; |
355 | } | 385 | } |
@@ -436,12 +466,8 @@ static int davinci_spi_setup(struct spi_device *spi) | |||
436 | int retval; | 466 | int retval; |
437 | struct davinci_spi *davinci_spi; | 467 | struct davinci_spi *davinci_spi; |
438 | struct davinci_spi_dma *davinci_spi_dma; | 468 | struct davinci_spi_dma *davinci_spi_dma; |
439 | struct davinci_spi_config *spicfg; | ||
440 | 469 | ||
441 | davinci_spi = spi_master_get_devdata(spi->master); | 470 | davinci_spi = spi_master_get_devdata(spi->master); |
442 | spicfg = (struct davinci_spi_config *)spi->controller_data; | ||
443 | if (!spicfg) | ||
444 | spicfg = &davinci_spi_default_cfg; | ||
445 | 471 | ||
446 | /* if bits per word length is zero then set it default 8 */ | 472 | /* if bits per word length is zero then set it default 8 */ |
447 | if (!spi->bits_per_word) | 473 | if (!spi->bits_per_word) |
@@ -460,88 +486,6 @@ static int davinci_spi_setup(struct spi_device *spi) | |||
460 | } | 486 | } |
461 | } | 487 | } |
462 | 488 | ||
463 | /* | ||
464 | * Set up SPIFMTn register, unique to this chipselect. | ||
465 | * | ||
466 | * NOTE: we could do all of these with one write. Also, some | ||
467 | * of the "version 2" features are found in chips that don't | ||
468 | * support all of them... | ||
469 | */ | ||
470 | if (spi->mode & SPI_LSB_FIRST) | ||
471 | set_fmt_bits(davinci_spi->base, SPIFMT_SHIFTDIR_MASK, | ||
472 | spi->chip_select); | ||
473 | else | ||
474 | clear_fmt_bits(davinci_spi->base, SPIFMT_SHIFTDIR_MASK, | ||
475 | spi->chip_select); | ||
476 | |||
477 | if (spi->mode & SPI_CPOL) | ||
478 | set_fmt_bits(davinci_spi->base, SPIFMT_POLARITY_MASK, | ||
479 | spi->chip_select); | ||
480 | else | ||
481 | clear_fmt_bits(davinci_spi->base, SPIFMT_POLARITY_MASK, | ||
482 | spi->chip_select); | ||
483 | |||
484 | if (!(spi->mode & SPI_CPHA)) | ||
485 | set_fmt_bits(davinci_spi->base, SPIFMT_PHASE_MASK, | ||
486 | spi->chip_select); | ||
487 | else | ||
488 | clear_fmt_bits(davinci_spi->base, SPIFMT_PHASE_MASK, | ||
489 | spi->chip_select); | ||
490 | |||
491 | /* | ||
492 | * Version 1 hardware supports two basic SPI modes: | ||
493 | * - Standard SPI mode uses 4 pins, with chipselect | ||
494 | * - 3 pin SPI is a 4 pin variant without CS (SPI_NO_CS) | ||
495 | * (distinct from SPI_3WIRE, with just one data wire; | ||
496 | * or similar variants without MOSI or without MISO) | ||
497 | * | ||
498 | * Version 2 hardware supports an optional handshaking signal, | ||
499 | * so it can support two more modes: | ||
500 | * - 5 pin SPI variant is standard SPI plus SPI_READY | ||
501 | * - 4 pin with enable is (SPI_READY | SPI_NO_CS) | ||
502 | */ | ||
503 | |||
504 | if (davinci_spi->version == SPI_VERSION_2) { | ||
505 | |||
506 | clear_fmt_bits(davinci_spi->base, SPIFMT_WDELAY_MASK, | ||
507 | spi->chip_select); | ||
508 | set_fmt_bits(davinci_spi->base, | ||
509 | (spicfg->wdelay << SPIFMT_WDELAY_SHIFT) & | ||
510 | SPIFMT_WDELAY_MASK, spi->chip_select); | ||
511 | |||
512 | if (spicfg->odd_parity) | ||
513 | set_fmt_bits(davinci_spi->base, SPIFMT_ODD_PARITY_MASK, | ||
514 | spi->chip_select); | ||
515 | else | ||
516 | clear_fmt_bits(davinci_spi->base, | ||
517 | SPIFMT_ODD_PARITY_MASK, | ||
518 | spi->chip_select); | ||
519 | |||
520 | if (spicfg->parity_enable) | ||
521 | set_fmt_bits(davinci_spi->base, SPIFMT_PARITYENA_MASK, | ||
522 | spi->chip_select); | ||
523 | else | ||
524 | clear_fmt_bits(davinci_spi->base, SPIFMT_PARITYENA_MASK, | ||
525 | spi->chip_select); | ||
526 | |||
527 | if (spicfg->timer_disable) | ||
528 | set_fmt_bits(davinci_spi->base, SPIFMT_DISTIMER_MASK, | ||
529 | spi->chip_select); | ||
530 | else | ||
531 | clear_fmt_bits(davinci_spi->base, SPIFMT_DISTIMER_MASK, | ||
532 | spi->chip_select); | ||
533 | |||
534 | if (spi->mode & SPI_READY) | ||
535 | set_fmt_bits(davinci_spi->base, | ||
536 | SPIFMT_WAITENA_MASK, | ||
537 | spi->chip_select); | ||
538 | else | ||
539 | clear_fmt_bits(davinci_spi->base, | ||
540 | SPIFMT_WAITENA_MASK, | ||
541 | spi->chip_select); | ||
542 | |||
543 | } | ||
544 | |||
545 | retval = davinci_spi_setup_transfer(spi, NULL); | 489 | retval = davinci_spi_setup_transfer(spi, NULL); |
546 | 490 | ||
547 | return retval; | 491 | return retval; |