fpga.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright (C) 2000 David J. Mckay (david.mckay@st.com)
  3. *
  4. * May be copied or modified under the terms of the GNU General Public
  5. * License. See linux/COPYING for more information.
  6. *
  7. * This file handles programming up the Altera Flex10K that interfaces to
  8. * the Galileo, and does the PS/2 keyboard and mouse
  9. *
  10. */
  11. #include <linux/config.h>
  12. #include <linux/kernel.h>
  13. #include <linux/smp.h>
  14. #include <linux/smp_lock.h>
  15. #include <linux/init.h>
  16. #include <linux/errno.h>
  17. #include <linux/pci.h>
  18. #include <linux/delay.h>
  19. #include <asm/overdriver/gt64111.h>
  20. #include <asm/overdrive/overdrive.h>
  21. #include <asm/overdrive/fpga.h>
  22. #define FPGA_NotConfigHigh() (*FPGA_ControlReg) = (*FPGA_ControlReg) | ENABLE_FPGA_BIT
  23. #define FPGA_NotConfigLow() (*FPGA_ControlReg) = (*FPGA_ControlReg) & RESET_FPGA_MASK
  24. /* I need to find out what (if any) the real delay factor here is */
  25. /* The delay is definately not critical */
  26. #define long_delay() {int i;for(i=0;i<10000;i++);}
  27. #define short_delay() {int i;for(i=0;i<100;i++);}
  28. static void __init program_overdrive_fpga(const unsigned char *fpgacode,
  29. int size)
  30. {
  31. int timeout = 0;
  32. int i, j;
  33. unsigned char b;
  34. static volatile unsigned char *FPGA_ControlReg =
  35. (volatile unsigned char *) (OVERDRIVE_CTRL);
  36. static volatile unsigned char *FPGA_ProgramReg =
  37. (volatile unsigned char *) (FPGA_DCLK_ADDRESS);
  38. printk("FPGA: Commencing FPGA Programming\n");
  39. /* The PCI reset but MUST be low when programming the FPGA !!! */
  40. b = (*FPGA_ControlReg) & RESET_PCI_MASK;
  41. (*FPGA_ControlReg) = b;
  42. /* Prepare FPGA to program */
  43. FPGA_NotConfigHigh();
  44. long_delay();
  45. FPGA_NotConfigLow();
  46. short_delay();
  47. while ((*FPGA_ProgramReg & FPGA_NOT_STATUS) != 0) {
  48. printk("FPGA: Waiting for NotStatus to go Low ... \n");
  49. }
  50. FPGA_NotConfigHigh();
  51. /* Wait for FPGA "ready to be programmed" signal */
  52. printk("FPGA: Waiting for NotStatus to go high (FPGA ready)... \n");
  53. for (timeout = 0;
  54. (((*FPGA_ProgramReg & FPGA_NOT_STATUS) == 0)
  55. && (timeout < FPGA_TIMEOUT)); timeout++);
  56. /* Check if timeout condition occured - i.e. an error */
  57. if (timeout == FPGA_TIMEOUT) {
  58. printk
  59. ("FPGA: Failed to program - Timeout waiting for notSTATUS to go high\n");
  60. return;
  61. }
  62. printk("FPGA: Copying data to FPGA ... %d bytes\n", size);
  63. /* Copy array to FPGA - bit at a time */
  64. for (i = 0; i < size; i++) {
  65. volatile unsigned w = 0;
  66. for (j = 0; j < 8; j++) {
  67. *FPGA_ProgramReg = (fpgacode[i] >> j) & 0x01;
  68. short_delay();
  69. }
  70. if ((i & 0x3ff) == 0) {
  71. printk(".");
  72. }
  73. }
  74. /* Waiting for CONFDONE to go high - means the program is complete */
  75. for (timeout = 0;
  76. (((*FPGA_ProgramReg & FPGA_CONFDONE) == 0)
  77. && (timeout < FPGA_TIMEOUT)); timeout++) {
  78. *FPGA_ProgramReg = 0x0;
  79. long_delay();
  80. }
  81. if (timeout == FPGA_TIMEOUT) {
  82. printk
  83. ("FPGA: Failed to program - Timeout waiting for CONFDONE to go high\n");
  84. return;
  85. } else { /* Clock another 10 times - gets the device into a working state */
  86. for (i = 0; i < 10; i++) {
  87. *FPGA_ProgramReg = 0x0;
  88. short_delay();
  89. }
  90. }
  91. printk("FPGA: Programming complete\n");
  92. }
  93. static const unsigned char __init fpgacode[] = {
  94. #include "./overdrive.ttf" /* Code from maxplus2 compiler */
  95. , 0, 0
  96. };
  97. int __init init_overdrive_fpga(void)
  98. {
  99. program_overdrive_fpga(fpgacode, sizeof(fpgacode));
  100. return 0;
  101. }