Browse Source

aan: Include current frequency in RPC status

Luke Dashjr 11 years ago
parent
commit
11a5ef526a
3 changed files with 24 additions and 6 deletions
  1. 18 5
      driver-aan.c
  2. 4 1
      driver-aan.h
  3. 2 0
      driver-jingtian.c

+ 18 - 5
driver-aan.c

@@ -309,7 +309,7 @@ bool aan_init(struct thr_info * const master_thr)
 		*chip = (struct aan_chip_data){
 			.chipid = ++chipid,
 			.desired_nonce_pdiff = AAN_DEFAULT_NONCE_PDIFF,
-			.pllreg = 0x87a9,  // 850 MHz
+			.desired_pllreg = 0x87a9,  // 850 MHz
 		};
 	}
 	master_thr->tv_poll = tv_now;
@@ -529,15 +529,16 @@ badjob:
 			continue;
 		}
 		const uint16_t pllreg = upk_u16be(reg, 0);
-		if (pllreg != chip->pllreg)
+		chip->current_pllreg = pllreg;
+		if (pllreg != chip->desired_pllreg)
 		{
 			// Wait for chip to idle before changing register
 			if (!(reg[3] & 3))
 			{
-				applog(LOG_DEBUG, "%"PRIpreprv": Asserting PLL change: %04x->%04x", proc->proc_repr, pllreg, chip->pllreg);
+				applog(LOG_DEBUG, "%"PRIpreprv": Asserting PLL change: %04x->%04x", proc->proc_repr, pllreg, chip->desired_pllreg);
 				uint8_t regset[AAN_REGISTER_SIZE];
 				memcpy(&regset[2], &reg[2], AAN_REGISTER_SIZE - 2);
-				pk_u16be(regset, 0, chip->pllreg);
+				pk_u16be(regset, 0, chip->desired_pllreg);
 				aan_spi_cmd_send(spi, AAN_WRITE_REG, chip->chipid, regset, AAN_REGISTER_SIZE);
 			}
 		}
@@ -591,7 +592,7 @@ const char *aan_set_clock(struct cgpu_info * const proc, const char * const optn
 	if (nv <= 0 || nv > AAN_MAX_FREQ)
 		return "Invalid clock frequency";
 	
-	chip->pllreg = aan_freq2pll(nv);
+	chip->desired_pllreg = aan_freq2pll(nv);
 	
 	return NULL;
 }
@@ -610,6 +611,18 @@ const char *aan_set_diff(struct cgpu_info * const proc, const char * const optna
 	return NULL;
 }
 
+struct api_data *aan_api_device_status(struct cgpu_info * const proc)
+{
+	struct thr_info * const thr = proc->thr[0];
+	struct aan_chip_data * const chip = thr->cgpu_data;
+	struct api_data *root = NULL;
+	
+	double mhz = aan_pll2freq(chip->current_pllreg);
+	root = api_add_freq(root, "Frequency", &mhz, true);
+	
+	return root;
+}
+
 const struct bfg_set_device_definition aan_set_device_funcs[] = {
 	{"clock", aan_set_clock, "clock frequency (MHz)"},
 	{"diff", aan_set_diff, "desired nonce difficulty"},

+ 4 - 1
driver-aan.h

@@ -30,7 +30,8 @@ struct aan_chip_data {
 	struct work *works[AAN_MAX_JOBID];
 	float desired_nonce_pdiff;
 	float current_nonce_pdiff;
-	uint16_t pllreg;
+	uint16_t desired_pllreg;
+	uint16_t current_pllreg;
 };
 
 extern int aan_detect_spi(int *out_chipcount, struct spi_port * const *spi_a, int spi_n);
@@ -44,4 +45,6 @@ extern void aan_poll(struct thr_info *);
 extern const char *aan_set_diff(struct cgpu_info *, const char *optname, const char *newvalue, char *replybuf, enum bfg_set_device_replytype *);
 extern const struct bfg_set_device_definition aan_set_device_funcs[];
 
+extern struct api_data *aan_api_device_status(struct cgpu_info *);
+
 #endif

+ 2 - 0
driver-jingtian.c

@@ -231,4 +231,6 @@ struct device_drv jingtian_drv = {
 	.queue_append = aan_queue_append,
 	.queue_flush = aan_queue_flush,
 	.poll = aan_poll,
+	
+	.get_api_extra_device_status = aan_api_device_status,
 };