driver-avalon2.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2013 Con Kolivas <kernel@kolivas.org>
  3. * Copyright 2012-2014 Xiangfu <xiangfu@openmobilefree.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #ifndef _AVALON2_H_
  11. #define _AVALON2_H_
  12. #include "util.h"
  13. #include "fpgautils.h"
  14. #ifdef USE_AVALON2
  15. #define AVA2_MINER_THREADS 1
  16. #define AVA2_RESET_FAULT_DECISECONDS 10
  17. #define AVA2_IO_SPEED 115200
  18. #define AVA2_DEFAULT_MINERS 10
  19. #define AVA2_AVA3_MINERS 5
  20. #define AVA2_DEFAULT_MODULARS 4
  21. #define AVA2_PWM_MAX 0x3FF
  22. #define AVA2_DEFAULT_FAN_PWM 80 /* % */
  23. #define AVA2_DEFAULT_FAN_MIN 0
  24. #define AVA2_DEFAULT_FAN_MAX 100
  25. #define AVA2_DEFAULT_VOLTAGE 10000 /* V * 10000 */
  26. #define AVA2_DEFAULT_VOLTAGE_MIN 6000
  27. #define AVA2_DEFAULT_VOLTAGE_MAX 11000
  28. #define AVA2_DEFAULT_FREQUENCY 1500 /* In MH/s */
  29. #define AVA2_DEFAULT_FREQUENCY_MIN 300
  30. #define AVA2_DEFAULT_FREQUENCY_MAX 2000
  31. #define AVALON2_TEMP_OVERHEAT 88
  32. /* Avalon2 protocol package type */
  33. #define AVA2_H1 'A'
  34. #define AVA2_H2 'V'
  35. #define AVA2_P_COINBASE_SIZE (6 * 1024)
  36. #define AVA2_P_MERKLES_COUNT 20
  37. #define AVA2_P_COUNT 39
  38. #define AVA2_P_DATA_LEN (AVA2_P_COUNT - 7)
  39. #define AVA2_P_DETECT 10
  40. #define AVA2_P_STATIC 11
  41. #define AVA2_P_JOB_ID 12
  42. #define AVA2_P_COINBASE 13
  43. #define AVA2_P_MERKLES 14
  44. #define AVA2_P_HEADER 15
  45. #define AVA2_P_POLLING 16
  46. #define AVA2_P_TARGET 17
  47. #define AVA2_P_REQUIRE 18
  48. #define AVA2_P_SET 19
  49. #define AVA2_P_TEST 20
  50. #define AVA2_P_ACK 21
  51. #define AVA2_P_NAK 22
  52. #define AVA2_P_NONCE 23
  53. #define AVA2_P_STATUS 24
  54. #define AVA2_P_ACKDETECT 25
  55. #define AVA2_P_TEST_RET 26
  56. /* Avalon2 protocol package type */
  57. /* Avalon2/3 firmware prefix */
  58. #define AVA2_FW2_PREFIXSTR "20"
  59. #define AVA2_FW3_PREFIXSTR "33"
  60. #define AVA2_MM_VERNULL "NONE"
  61. #define AVA2_ID_AVA2 3255
  62. #define AVA2_ID_AVA3 3233
  63. #define AVA2_ID_AVAX 3200
  64. struct avalon2_pkg {
  65. uint8_t head[2];
  66. uint8_t type;
  67. uint8_t idx;
  68. uint8_t cnt;
  69. uint8_t data[32];
  70. uint8_t crc[2];
  71. };
  72. #define avalon2_ret avalon2_pkg
  73. struct avalon2_info {
  74. int fd;
  75. int baud;
  76. int set_frequency;
  77. int set_voltage;
  78. int get_voltage[AVA2_DEFAULT_MODULARS];
  79. int get_frequency[AVA2_DEFAULT_MODULARS];
  80. int power_good[AVA2_DEFAULT_MODULARS];
  81. int fan_pwm;
  82. int fan[2 * AVA2_DEFAULT_MODULARS];
  83. int temp[2 * AVA2_DEFAULT_MODULARS];
  84. int temp_max;
  85. int temp_history_count;
  86. int temp_history_index;
  87. int temp_sum;
  88. int temp_old;
  89. bool first;
  90. bool new_stratum;
  91. int pool_no;
  92. int diff;
  93. int local_works[AVA2_DEFAULT_MODULARS];
  94. int hw_works[AVA2_DEFAULT_MODULARS];
  95. int matching_work[AVA2_DEFAULT_MINERS * AVA2_DEFAULT_MODULARS];
  96. int local_work[AVA2_DEFAULT_MODULARS];
  97. int hw_work[AVA2_DEFAULT_MODULARS];
  98. int modulars[AVA2_DEFAULT_MODULARS];
  99. char mm_version[AVA2_DEFAULT_MODULARS][16];
  100. };
  101. #define AVA2_WRITE_SIZE (sizeof(struct avalon2_pkg))
  102. #define AVA2_READ_SIZE AVA2_WRITE_SIZE
  103. #define AVA2_GETS_OK 0
  104. #define AVA2_GETS_TIMEOUT -1
  105. #define AVA2_GETS_RESTART -2
  106. #define AVA2_GETS_ERROR -3
  107. #define AVA2_SEND_OK 0
  108. #define AVA2_SEND_ERROR -1
  109. #define avalon2_open(devpath, baud, purge) serial_open(devpath, baud, AVA2_RESET_FAULT_DECISECONDS, purge)
  110. #define avalon2_close(fd) close(fd)
  111. extern char *set_avalon2_fan(char *arg);
  112. extern char *set_avalon2_freq(char *arg);
  113. extern char *set_avalon2_voltage(char *arg);
  114. extern int opt_avalon2_overheat;
  115. #endif /* USE_AVALON2 */
  116. #endif /* _AVALON2_H_ */