driver-avalon4.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 _AVALON4_H_
  11. #define _AVALON4_H_
  12. #include "util.h"
  13. #ifdef USE_AVALON4
  14. #define AVA4_DEFAULT_FAN_MIN 5 /* % */
  15. #define AVA4_DEFAULT_FAN_MAX 85
  16. /* Percentage required to make sure fan starts spinning, then we can go down */
  17. #define AVA4_DEFAULT_FAN_START 15
  18. #define AVA4_DEFAULT_TEMP_TARGET 42
  19. #define AVA4_DEFAULT_TEMP_OVERHEAT 65
  20. #define AVA4_DEFAULT_VOLTAGE_MIN 4000
  21. #define AVA4_DEFAULT_VOLTAGE_MAX 9000
  22. #define AVA4_DEFAULT_FREQUENCY_MIN 100
  23. #define AVA4_DEFAULT_FREQUENCY_MAX 1000
  24. #define AVA4_DEFAULT_MODULARS 64
  25. #define AVA4_DEFAULT_MINERS 10
  26. #define AVA4_DEFAULT_ASIC_COUNT 4
  27. #define AVA4_DEFAULT_VOLTAGE 6875
  28. #define AVA4_DEFAULT_FREQUENCY 200
  29. #define AVA4_DEFAULT_POLLING_DELAY 20 /* ms */
  30. #define AVA4_DH_INC 0.03
  31. #define AVA4_DH_DEC 0.001
  32. #define AVA4_PWM_MAX 0x3FF
  33. #define AVA4_AUC_VER_LEN 12 /* Version length: 12 (AUC-YYYYMMDD) */
  34. #define AVA4_AUC_SPEED 400000
  35. #define AVA4_AUC_XDELAY 9600 /* 4800 = 1ms in AUC (11U14) */
  36. #define AVA4_AUC_P_SIZE 64
  37. /* Avalon4 protocol package type from MM protocol.h
  38. * https://github.com/Canaan-Creative/MM/blob/avalon4/firmware/protocol.h */
  39. #define AVA4_MM_VER_LEN 15
  40. #define AVA4_MM_DNA_LEN 8
  41. #define AVA4_H1 'C'
  42. #define AVA4_H2 'N'
  43. #define AVA4_P_COINBASE_SIZE (6 * 1024 + 64)
  44. #define AVA4_P_MERKLES_COUNT 30
  45. #define AVA4_P_COUNT 40
  46. #define AVA4_P_DATA_LEN 32
  47. /* Broadcase with block iic_write*/
  48. #define AVA4_P_DETECT 0x10
  49. /* Broadcase With non-block iic_write*/
  50. #define AVA4_P_STATIC 0x11
  51. #define AVA4_P_JOB_ID 0x12
  52. #define AVA4_P_COINBASE 0x13
  53. #define AVA4_P_MERKLES 0x14
  54. #define AVA4_P_HEADER 0x15
  55. #define AVA4_P_TARGET 0x16
  56. /* Broadcase or Address */
  57. #define AVA4_P_SET 0x20
  58. #define AVA4_P_FINISH 0x21
  59. /* Have to with I2C address */
  60. #define AVA4_P_POLLING 0x30
  61. #define AVA4_P_REQUIRE 0x31
  62. #define AVA4_P_TEST 0x32
  63. /* Back to host */
  64. #define AVA4_P_ACKDETECT 0x40
  65. #define AVA4_P_STATUS 0x41
  66. #define AVA4_P_NONCE 0x42
  67. #define AVA4_P_TEST_RET 0x43
  68. #define AVA4_MODULE_BROADCAST 0
  69. /* Endof Avalon4 protocol package type */
  70. #define AVA4_MM40_PREFIXSTR "40"
  71. #define AVA4_MM41_PREFIXSTR "41"
  72. #define AVA4_MM_VERNULL "NONE"
  73. #define AVA4_TYPE_MM40 40
  74. #define AVA4_TYPE_MM41 41
  75. #define AVA4_TYPE_NULL 00
  76. #define AVA4_IIC_RESET 0xa0
  77. #define AVA4_IIC_INIT 0xa1
  78. #define AVA4_IIC_DEINIT 0xa2
  79. #define AVA4_IIC_XFER 0xa5
  80. #define AVA4_IIC_INFO 0xa6
  81. struct avalon4_pkg {
  82. uint8_t head[2];
  83. uint8_t type;
  84. uint8_t opt;
  85. uint8_t idx;
  86. uint8_t cnt;
  87. uint8_t data[32];
  88. uint8_t crc[2];
  89. };
  90. #define avalon4_ret avalon4_pkg
  91. struct avalon4_info {
  92. cglock_t update_lock;
  93. int polling_first;
  94. int polling_err_cnt[AVA4_DEFAULT_MODULARS];
  95. int xfer_err_cnt;
  96. int pool_no;
  97. struct pool pool0;
  98. struct pool pool1;
  99. struct pool pool2;
  100. struct timeval last_fan;
  101. struct timeval last_stratum;
  102. char auc_version[AVA4_AUC_VER_LEN + 1];
  103. int auc_speed;
  104. int auc_xdelay;
  105. int auc_temp;
  106. int mm_count;
  107. int set_frequency[3];
  108. int set_voltage[AVA4_DEFAULT_MODULARS];
  109. int set_voltage_broadcat;
  110. int mod_type[AVA4_DEFAULT_MODULARS];
  111. bool enable[AVA4_DEFAULT_MODULARS];
  112. struct timeval elapsed[AVA4_DEFAULT_MODULARS];
  113. char mm_version[AVA4_DEFAULT_MODULARS][AVA4_MM_VER_LEN + 1];
  114. uint8_t mm_dna[AVA4_DEFAULT_MODULARS][AVA4_MM_DNA_LEN + 1];
  115. int get_voltage[AVA4_DEFAULT_MODULARS];
  116. int get_frequency[AVA4_DEFAULT_MODULARS];
  117. int power_good[AVA4_DEFAULT_MODULARS];
  118. int fan_pct[AVA4_DEFAULT_MODULARS];
  119. int fan[AVA4_DEFAULT_MODULARS];
  120. int temp[AVA4_DEFAULT_MODULARS];
  121. int led_red[AVA4_DEFAULT_MODULARS];
  122. uint64_t local_works[AVA4_DEFAULT_MODULARS];
  123. uint64_t hw_works[AVA4_DEFAULT_MODULARS];
  124. uint32_t local_work[AVA4_DEFAULT_MODULARS];
  125. uint32_t hw_work[AVA4_DEFAULT_MODULARS];
  126. uint32_t lw5[AVA4_DEFAULT_MODULARS][6];
  127. uint32_t hw5[AVA4_DEFAULT_MODULARS][6];
  128. int i_1m;
  129. struct timeval last_5m;
  130. struct timeval last_1m;
  131. int matching_work[AVA4_DEFAULT_MODULARS][AVA4_DEFAULT_MINERS];
  132. int chipmatching_work[AVA4_DEFAULT_MODULARS][AVA4_DEFAULT_MINERS][4];
  133. };
  134. struct avalon4_iic_info {
  135. uint8_t iic_op;
  136. union {
  137. uint32_t aucParam[2];
  138. uint8_t slave_addr;
  139. } iic_param;
  140. };
  141. #define AVA4_WRITE_SIZE (sizeof(struct avalon4_pkg))
  142. #define AVA4_READ_SIZE AVA4_WRITE_SIZE
  143. #define AVA4_SEND_OK 0
  144. #define AVA4_SEND_ERROR -1
  145. extern char *set_avalon4_fan(char *arg);
  146. extern char *set_avalon4_temp(char *arg);
  147. extern char *set_avalon4_freq(char *arg);
  148. extern char *set_avalon4_voltage(char *arg);
  149. extern bool opt_avalon4_autov;
  150. extern int opt_avalon4_temp_target;
  151. extern int opt_avalon4_overheat;
  152. extern int opt_avalon4_polling_delay;
  153. extern int opt_avalon4_aucspeed;
  154. extern int opt_avalon4_aucxdelay;
  155. extern int opt_avalon4_ntime_offset;
  156. #endif /* USE_AVALON4 */
  157. #endif /* _AVALON4_H_ */