sc520_ssi.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * (C) Copyright 2002
  3. * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/io.h>
  25. #include <asm/arch/ssi.h>
  26. #include <asm/arch/sc520.h>
  27. int ssi_set_interface(int freq, int lsb_first, int inv_clock, int inv_phase)
  28. {
  29. u8 temp = 0;
  30. if (freq >= 8192)
  31. temp |= CTL_CLK_SEL_4;
  32. else if (freq >= 4096)
  33. temp |= CTL_CLK_SEL_8;
  34. else if (freq >= 2048)
  35. temp |= CTL_CLK_SEL_16;
  36. else if (freq >= 1024)
  37. temp |= CTL_CLK_SEL_32;
  38. else if (freq >= 512)
  39. temp |= CTL_CLK_SEL_64;
  40. else if (freq >= 256)
  41. temp |= CTL_CLK_SEL_128;
  42. else if (freq >= 128)
  43. temp |= CTL_CLK_SEL_256;
  44. else
  45. temp |= CTL_CLK_SEL_512;
  46. if (!lsb_first)
  47. temp |= MSBF_ENB;
  48. if (inv_clock)
  49. temp |= CLK_INV_ENB;
  50. if (inv_phase)
  51. temp |= PHS_INV_ENB;
  52. writeb(temp, &sc520_mmcr->ssictl);
  53. return 0;
  54. }
  55. u8 ssi_txrx_byte(u8 data)
  56. {
  57. writeb(data, &sc520_mmcr->ssixmit);
  58. while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
  59. ;
  60. writeb(SSICMD_CMD_SEL_XMITRCV, &sc520_mmcr->ssicmd);
  61. while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
  62. ;
  63. return readb(&sc520_mmcr->ssircv);
  64. }
  65. void ssi_tx_byte(u8 data)
  66. {
  67. writeb(data, &sc520_mmcr->ssixmit);
  68. while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
  69. ;
  70. writeb(SSICMD_CMD_SEL_XMIT, &sc520_mmcr->ssicmd);
  71. }
  72. u8 ssi_rx_byte(void)
  73. {
  74. while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
  75. ;
  76. writeb(SSICMD_CMD_SEL_RCV, &sc520_mmcr->ssicmd);
  77. while (readb(&sc520_mmcr->ssista) & SSISTA_BSY)
  78. ;
  79. return readb(&sc520_mmcr->ssircv);
  80. }