fpga.c 3.3 KB

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