Browse Source

bitmain: Make reg_data optional for S4 and S5, calculating it from clock

Luke Dashjr 10 years ago
parent
commit
9829ab7ec1
3 changed files with 32 additions and 0 deletions
  1. 3 0
      README.ASIC
  2. 21 0
      driver-bitmain.c
  3. 8 0
      driver-bitmain.h

+ 3 - 0
README.ASIC

@@ -19,6 +19,9 @@ at runtime with a series of --set options. For example:
 -S bitmain:auto --set btm:model=S5 --set btm:layout=32:8 --set btm:timeout=3
 -S bitmain:auto --set btm:model=S5 --set btm:layout=32:8 --set btm:timeout=3
 --set btm:clock=350 --set btm:reg_data=0d82 --set btm:voltage=x0725
 --set btm:clock=350 --set btm:reg_data=0d82 --set btm:voltage=x0725
 
 
+Note that reg_data is optional for S4 and S5 and will be calculated from clock
+if not provided.
+
 The meaning of each of these options are not documented individually at this
 The meaning of each of these options are not documented individually at this
 time, but can be determined from the stock cgminer's options. You want to look
 time, but can be determined from the stock cgminer's options. You want to look
 at the "bitmain-options" from the command line, and the "bitmain-freq" and
 at the "bitmain-options" from the command line, and the "bitmain-freq" and

+ 21 - 0
driver-bitmain.c

@@ -1365,6 +1365,18 @@ static bool bitmain_detect_one(const char * devpath)
 	
 	
 	if (!info->packet_max_work)
 	if (!info->packet_max_work)
 		return_via_applog(shin, , LOG_ERR, "%s: Device not configured (did you forget --set bitmain:model=S5 ?)", bitmain_drv.dname);
 		return_via_applog(shin, , LOG_ERR, "%s: Device not configured (did you forget --set bitmain:model=S5 ?)", bitmain_drv.dname);
+	
+	if (!(upk_u32be(info->reg_data, 0))) {
+		switch (info->chip_type) {
+			case BMC_BM1382:
+			case BMC_BM1384:
+				if (bm1382_freq_to_reg_data(info->reg_data, info->frequency))
+					break;
+				// fall thru if it failed
+			default:
+				return_via_applog(shin, , LOG_ERR, "%s: Device not configured (did you forget --set bitmain:reg_data=x???? ?)", bitmain_drv.dname);
+		}
+	}
 
 
 	if (!btm_init(bitmain, devpath))
 	if (!btm_init(bitmain, devpath))
 		goto shin;
 		goto shin;
@@ -1801,21 +1813,30 @@ unknown_model:
 	if (endptr[0] && !isspace(endptr[0]))
 	if (endptr[0] && !isspace(endptr[0]))
 		goto unknown_model;
 		goto unknown_model;
 	
 	
+	info->chip_type = BMC_UNKNOWN;
 	switch (Sn) {
 	switch (Sn) {
 		case 1:
 		case 1:
+			info->chip_type = BMC_BM1380;
 			bitmain_set_packet_max_work(dev, 8);
 			bitmain_set_packet_max_work(dev, 8);
 			info->packet_max_nonce = 8;
 			info->packet_max_nonce = 8;
 			break;
 			break;
 		case 2:
 		case 2:
+			info->chip_type = BMC_BM1380;
 			bitmain_set_packet_max_work(dev, 0x40);
 			bitmain_set_packet_max_work(dev, 0x40);
 			info->packet_max_nonce = 0x80;
 			info->packet_max_nonce = 0x80;
 			break;
 			break;
 		case 3:
 		case 3:
+			info->chip_type = BMC_BM1382;
 			bitmain_set_packet_max_work(dev, 8);
 			bitmain_set_packet_max_work(dev, 8);
 			info->packet_max_nonce = 0x80;
 			info->packet_max_nonce = 0x80;
 			break;
 			break;
 		case 4:
 		case 4:
+			info->chip_type = BMC_BM1382;
+			bitmain_set_packet_max_work(dev, 0x40);
+			info->packet_max_nonce = 0x80;
+			break;
 		case 5:
 		case 5:
+			info->chip_type = BMC_BM1384;
 			bitmain_set_packet_max_work(dev, 0x40);
 			bitmain_set_packet_max_work(dev, 0x40);
 			info->packet_max_nonce = 0x80;
 			info->packet_max_nonce = 0x80;
 			break;
 			break;

+ 8 - 0
driver-bitmain.h

@@ -165,10 +165,18 @@ struct bitmain_rxnonce_data {
 	uint16_t crc;
 	uint16_t crc;
 } __attribute__((packed, aligned(4)));
 } __attribute__((packed, aligned(4)));
 
 
+enum bitmain_chip {
+	BMC_UNKNOWN,
+	BMC_BM1380,
+	BMC_BM1382,
+	BMC_BM1384,
+};
+
 struct bitmain_info {
 struct bitmain_info {
 	void *device_curl;
 	void *device_curl;
 	SOCKETTYPE curl_sock;
 	SOCKETTYPE curl_sock;
 	
 	
+	enum bitmain_chip chip_type;
 	int chain_num;
 	int chain_num;
 	int asic_num;
 	int asic_num;
 	int chain_asic_num[BITMAIN_MAX_CHAIN_NUM];
 	int chain_asic_num[BITMAIN_MAX_CHAIN_NUM];