driver-avalon2.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * Copyright 2013-2014 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_MODULARS 4
  19. #define AVA2_PWM_MAX 0x3FF
  20. #define AVA2_DEFAULT_FAN_PWM 15 /* % */
  21. #define AVA2_DEFAULT_FAN_MIN 10
  22. #define AVA2_DEFAULT_FAN_MAX 85
  23. #define AVALON2_TEMP_OVERHEAT 98
  24. #define AVALON2_DEFAULT_POLLING_DELAY 20 /* ms */
  25. #define AVA2_DEFAULT_VOLTAGE_MIN 6000
  26. #define AVA2_DEFAULT_VOLTAGE_MAX 11000
  27. #define AVA2_DEFAULT_FREQUENCY_MIN 300
  28. #define AVA2_DEFAULT_FREQUENCY_MAX 2000
  29. /* Avalon2 default values */
  30. #define AVA2_DEFAULT_MINERS 10
  31. #define AVA2_DEFAULT_VOLTAGE 10000 /* v * 10000 */
  32. #define AVA2_DEFAULT_FREQUENCY 1500 /* In MHs */
  33. /* Avalon3 default values */
  34. #define AVA2_AVA3_MINERS 5
  35. #define AVA2_AVA3_VOLTAGE 6660 /* 0.666v */
  36. #define AVA2_AVA3_FREQUENCY 450 /* MHz * 11.8 = MHs: 450MHz means ~5.3GHs */
  37. /* Avalon2 protocol package type */
  38. #define AVA2_H1 'A'
  39. #define AVA2_H2 'V'
  40. #define AVA2_P_COINBASE_SIZE (6 * 1024)
  41. #define AVA2_P_MERKLES_COUNT 20
  42. #define AVA2_P_COUNT 39
  43. #define AVA2_P_DATA_LEN (AVA2_P_COUNT - 7)
  44. #define AVA2_P_DETECT 10
  45. #define AVA2_P_STATIC 11
  46. #define AVA2_P_JOB_ID 12
  47. #define AVA2_P_COINBASE 13
  48. #define AVA2_P_MERKLES 14
  49. #define AVA2_P_HEADER 15
  50. #define AVA2_P_POLLING 16
  51. #define AVA2_P_TARGET 17
  52. #define AVA2_P_REQUIRE 18
  53. #define AVA2_P_SET 19
  54. #define AVA2_P_TEST 20
  55. #define AVA2_P_ACK 21
  56. #define AVA2_P_NAK 22
  57. #define AVA2_P_NONCE 23
  58. #define AVA2_P_STATUS 24
  59. #define AVA2_P_ACKDETECT 25
  60. #define AVA2_P_TEST_RET 26
  61. /* Avalon2 protocol package type */
  62. /* Avalon2/3 firmware prefix */
  63. #define AVA2_FW2_PREFIXSTR "20"
  64. #define AVA2_FW3_PREFIXSTR "33"
  65. #define AVA2_MM_VERNULL "NONE"
  66. #define AVA2_ID_AVA2 3255
  67. #define AVA2_ID_AVA3 3233
  68. #define AVA2_ID_AVAX 3200
  69. enum avalon2_fan_fixed {
  70. FAN_FIXED,
  71. FAN_AUTO,
  72. };
  73. struct avalon2_pkg {
  74. uint8_t head[2];
  75. uint8_t type;
  76. uint8_t idx;
  77. uint8_t cnt;
  78. uint8_t data[32];
  79. uint8_t crc[2];
  80. };
  81. #define avalon2_ret avalon2_pkg
  82. struct avalon2_info {
  83. struct timeval last_stratum;
  84. struct pool pool;
  85. int pool_no;
  86. int modulars[AVA2_DEFAULT_MODULARS];
  87. char mm_version[AVA2_DEFAULT_MODULARS][16];
  88. int dev_type[AVA2_DEFAULT_MODULARS];
  89. bool enable[AVA2_DEFAULT_MODULARS];
  90. int set_frequency;
  91. int set_voltage;
  92. int get_voltage[AVA2_DEFAULT_MODULARS];
  93. int get_frequency[AVA2_DEFAULT_MODULARS];
  94. int power_good[AVA2_DEFAULT_MODULARS];
  95. int fan_pwm;
  96. int fan_pct;
  97. int temp_max;
  98. int fan[2 * AVA2_DEFAULT_MODULARS];
  99. int temp[2 * AVA2_DEFAULT_MODULARS];
  100. int local_works[AVA2_DEFAULT_MODULARS];
  101. int hw_works[AVA2_DEFAULT_MODULARS];
  102. int local_work[AVA2_DEFAULT_MODULARS];
  103. int hw_work[AVA2_DEFAULT_MODULARS];
  104. int matching_work[AVA2_DEFAULT_MINERS * AVA2_DEFAULT_MODULARS];
  105. int led_red[AVA2_DEFAULT_MODULARS];
  106. bool failing;
  107. };
  108. #define AVA2_WRITE_SIZE (sizeof(struct avalon2_pkg))
  109. #define AVA2_READ_SIZE AVA2_WRITE_SIZE
  110. #define AVA2_GETS_OK 0
  111. #define AVA2_GETS_TIMEOUT -1
  112. #define AVA2_GETS_RESTART -2
  113. #define AVA2_GETS_ERROR -3
  114. #define AVA2_SEND_OK 0
  115. #define AVA2_SEND_ERROR -1
  116. #define avalon2_open(devpath, baud, purge) serial_open(devpath, baud, AVA2_RESET_FAULT_DECISECONDS, purge)
  117. #define avalon2_close(fd) close(fd)
  118. extern char *set_avalon2_fan(char *arg);
  119. extern char *set_avalon2_freq(char *arg);
  120. extern char *set_avalon2_voltage(char *arg);
  121. extern char *set_avalon2_fixed_speed(enum avalon2_fan_fixed *f);
  122. extern enum avalon2_fan_fixed opt_avalon2_fan_fixed;
  123. extern int opt_avalon2_overheat;
  124. extern int opt_avalon2_polling_delay;
  125. #endif /* USE_AVALON2 */
  126. #endif /* _AVALON2_H_ */