dspi.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. *
  3. * (C) Copyright 2000-2003
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * Copyright (C) 2004-2008 Freescale Semiconductor, Inc.
  7. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <spi.h>
  29. #if defined(CONFIG_CF_DSPI)
  30. #include <asm/immap.h>
  31. void dspi_init(void)
  32. {
  33. volatile gpio_t *gpio = (gpio_t *) MMAP_GPIO;
  34. volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  35. gpio->par_dspi = GPIO_PAR_DSPI_PCS5_PCS5 | GPIO_PAR_DSPI_PCS2_PCS2 |
  36. GPIO_PAR_DSPI_PCS1_PCS1 | GPIO_PAR_DSPI_PCS0_PCS0 |
  37. GPIO_PAR_DSPI_SIN_SIN | GPIO_PAR_DSPI_SOUT_SOUT |
  38. GPIO_PAR_DSPI_SCK_SCK;
  39. dspi->dmcr = DSPI_DMCR_MSTR | DSPI_DMCR_CSIS7 | DSPI_DMCR_CSIS6 |
  40. DSPI_DMCR_CSIS5 | DSPI_DMCR_CSIS4 | DSPI_DMCR_CSIS3 |
  41. DSPI_DMCR_CSIS2 | DSPI_DMCR_CSIS1 | DSPI_DMCR_CSIS0 |
  42. DSPI_DMCR_CRXF | DSPI_DMCR_CTXF;
  43. dspi->dctar0 = DSPI_DCTAR_TRSZ(7) | DSPI_DCTAR_CPOL | DSPI_DCTAR_CPHA |
  44. DSPI_DCTAR_PCSSCK_1CLK | DSPI_DCTAR_PASC(0) |
  45. DSPI_DCTAR_PDT(0) | DSPI_DCTAR_CSSCK(0) |
  46. DSPI_DCTAR_ASC(0) | DSPI_DCTAR_PBR(0) |
  47. DSPI_DCTAR_DT(1) | DSPI_DCTAR_BR(1);
  48. }
  49. void dspi_tx(int chipsel, u8 attrib, u16 data)
  50. {
  51. volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  52. while ((dspi->dsr & 0x0000F000) >= 4) ;
  53. dspi->dtfr = (attrib << 24) | ((1 << chipsel) << 16) | data;
  54. }
  55. u16 dspi_rx(void)
  56. {
  57. volatile dspi_t *dspi = (dspi_t *) MMAP_DSPI;
  58. while ((dspi->dsr & 0x000000F0) == 0) ;
  59. return (dspi->drfr & 0xFFFF);
  60. }
  61. #endif /* CONFIG_HARD_SPI */