Browse Source

jingtian: Decode extra temperature bytes in read_reg

Luke Dashjr 11 years ago
parent
commit
cd7b8083e2
3 changed files with 26 additions and 2 deletions
  1. 0 1
      driver-aan.c
  2. 1 0
      driver-aan.h
  3. 25 1
      driver-jingtian.c

+ 0 - 1
driver-aan.c

@@ -294,7 +294,6 @@ void aan_queue_flush(struct thr_info * const thr)
 	// TODO
 }
 
-static
 struct cgpu_info *aan_proc_for_chipid(struct cgpu_info * const dev, const int chipid)
 {
 	struct cgpu_info *proc = dev;

+ 1 - 0
driver-aan.h

@@ -37,6 +37,7 @@ extern bool aan_read_reg_direct(struct spi_port *, uint8_t chip, void *out_buf,
 extern bool aan_init(struct thr_info *);
 extern bool aan_queue_append(struct thr_info *, struct work *);
 extern void aan_queue_flush(struct thr_info *);
+extern struct cgpu_info *aan_proc_for_chipid(struct cgpu_info *, int chipid);
 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 *);

+ 25 - 1
driver-jingtian.c

@@ -28,6 +28,8 @@ static const int jingtian_cs_gpio[] = {14, 15, 18};
 static const int jingtian_max_cs = 1 << (sizeof(jingtian_cs_gpio) / sizeof(*jingtian_cs_gpio));
 static const uint8_t jingtian_pre_header[] = {0xb5, 0xb5};
 
+#define JINGTIAN_REGISTER_EXTRA_SIZE  2
+
 BFG_REGISTER_DRIVER(jingtian_drv)
 
 static
@@ -79,10 +81,31 @@ void jingtian_precmd(struct spi_port * const spi)
 	spi_emit_buf(spi, jingtian_pre_header, sizeof(jingtian_pre_header));
 }
 
+static
+bool jingtian_read_reg(struct spi_port * const spi, const uint8_t chip, void * const out_buf, const struct timeval * const tvp_timeout)
+{
+	if (!aan_read_reg_direct(spi, chip, out_buf, tvp_timeout))
+		return false;
+	
+	spi_emit_nop(spi, JINGTIAN_REGISTER_EXTRA_SIZE);
+	if (!spi_txrx(spi))
+		applogr(false, LOG_DEBUG, "%s: %s failed", __func__, "spi_txrx");
+	
+	struct cgpu_info * const dev = spi->cgpu;
+	if (unlikely(!dev))
+		return true;
+	struct cgpu_info * const proc = aan_proc_for_chipid(dev, chip);
+	
+	uint8_t * const rx = spi_getrxbuf(spi);
+	proc->temp = upk_u16be(rx, 0);
+	
+	return true;
+}
+
 static
 struct aan_hooks jingtian_hooks = {
 	.precmd = jingtian_precmd,
-	.read_reg = aan_read_reg_direct,
+	.read_reg = jingtian_read_reg,
 };
 
 static
@@ -151,6 +174,7 @@ bool jingtian_detect_one(const char * const devpath)
 			.device_path = strdup(devpath),
 			.set_device_funcs = aan_set_device_funcs,
 		};
+		spi_a[i]->cgpu = cgpu;
 		add_cgpu_slave(cgpu, prev_cgpu);
 		prev_cgpu = cgpu;
 		found += chips;