ide-cf.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * CF IDE addon card code
  3. *
  4. * Enter bugs at http://blackfin.uclinux.org/
  5. *
  6. * Copyright (c) 2005-2009 Analog Devices Inc.
  7. *
  8. * Licensed under the GPL-2 or later.
  9. */
  10. #include <common.h>
  11. #include <config.h>
  12. #include <asm/blackfin.h>
  13. void cf_outb(unsigned char val, volatile unsigned char *addr)
  14. {
  15. /* "ETHERNET" means the expansion memory banks */
  16. swap_to(ETHERNET);
  17. *addr = val;
  18. SSYNC();
  19. swap_to(FLASH);
  20. }
  21. unsigned char cf_inb(volatile unsigned char *addr)
  22. {
  23. unsigned char c;
  24. swap_to(ETHERNET);
  25. c = *addr;
  26. SSYNC();
  27. swap_to(FLASH);
  28. return c;
  29. }
  30. void cf_insw(unsigned short *sect_buf, unsigned short *addr, int words)
  31. {
  32. int i;
  33. swap_to(ETHERNET);
  34. for (i = 0; i < words; i++) {
  35. *(sect_buf + i) = *addr;
  36. SSYNC();
  37. }
  38. swap_to(FLASH);
  39. }
  40. void cf_outsw(unsigned short *addr, unsigned short *sect_buf, int words)
  41. {
  42. int i;
  43. swap_to(ETHERNET);
  44. for (i = 0; i < words; i++) {
  45. *addr = *(sect_buf + i);
  46. SSYNC();
  47. }
  48. swap_to(FLASH);
  49. }
  50. /* Definitions used in Compact Flash Boot support */
  51. #define FIO_EDGE_CF_BITS 0x0000
  52. #define FIO_POLAR_CF_BITS 0x0000
  53. #define FIO_EDGE_BITS 0x1E0
  54. #define FIO_POLAR_BITS 0x160
  55. /* Compact flash status bits in status register */
  56. #define CF_STAT_BITS 0x00000060
  57. void cf_ide_init(void)
  58. {
  59. int i, cf_stat;
  60. /* Check whether CF card is inserted */
  61. bfin_write_FIO_EDGE(FIO_EDGE_CF_BITS);
  62. bfin_write_FIO_POLAR(FIO_POLAR_CF_BITS);
  63. for (i = 0; i < 0x300; i++)
  64. asm volatile("nop;");
  65. cf_stat = bfin_read_FIO_FLAG_S() & CF_STAT_BITS;
  66. bfin_write_FIO_EDGE(FIO_EDGE_BITS);
  67. bfin_write_FIO_POLAR(FIO_POLAR_BITS);
  68. if (!cf_stat) {
  69. for (i = 0; i < 0x3000; i++)
  70. asm volatile("nop;");
  71. ide_init();
  72. }
  73. }