driver-knc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  1. /*
  2. * Copyright 2013 Luke Dashjr
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the Free
  6. * Software Foundation; either version 3 of the License, or (at your option)
  7. * any later version. See COPYING for more details.
  8. */
  9. #include "config.h"
  10. #include <stdbool.h>
  11. #include <stddef.h>
  12. #include <stdint.h>
  13. #include <sys/ioctl.h>
  14. #include <sys/types.h>
  15. #include <sys/stat.h>
  16. #include <fcntl.h>
  17. #include <math.h>
  18. #ifdef HAVE_LINUX_I2C_DEV_USER_H
  19. #include <linux/i2c-dev-user.h>
  20. #else
  21. #include <linux/i2c-dev.h>
  22. #endif
  23. #include <linux/spi/spidev.h>
  24. #include <uthash.h>
  25. #include "deviceapi.h"
  26. #include "logging.h"
  27. #include "miner.h"
  28. #include "spidevc.h"
  29. #define KNC_POLL_INTERVAL_US 10000
  30. #define KNC_SPI_SPEED 3000000
  31. #define KNC_SPI_DELAY 0
  32. #define KNC_SPI_MODE (SPI_CPHA | SPI_CPOL | SPI_CS_HIGH)
  33. #define KNC_SPI_BITS 8
  34. static const char * const i2cpath = "/dev/i2c-2";
  35. #define KNC_I2C_TEMPLATE "/dev/i2c-%d"
  36. enum knc_request_cmd {
  37. KNC_REQ_SUBMIT_WORK = 2,
  38. KNC_REQ_FLUSH_QUEUE = 3,
  39. };
  40. enum knc_reply_type {
  41. KNC_REPLY_NONCE_FOUND = 1,
  42. KNC_REPLY_WORK_DONE = 2,
  43. };
  44. struct device_drv knc_drv;
  45. struct knc_device {
  46. int i2c;
  47. struct spi_port *spi;
  48. struct cgpu_info *cgpu;
  49. bool need_flush;
  50. struct work *workqueue;
  51. int workqueue_size;
  52. int workqueue_max;
  53. int next_id;
  54. struct work *devicework;
  55. };
  56. struct knc_core {
  57. int asicno;
  58. int coreno;
  59. float volt;
  60. float current;
  61. };
  62. static
  63. bool knc_detect_one(const char *devpath)
  64. {
  65. static struct cgpu_info *prev_cgpu = NULL;
  66. struct cgpu_info *cgpu;
  67. int i;
  68. const int fd = open(i2cpath, O_RDWR);
  69. char *leftover = NULL;
  70. const int i2cslave = strtol(devpath, &leftover, 0);
  71. uint8_t buf[0x20];
  72. if (leftover && leftover[0])
  73. return false;
  74. if (unlikely(fd == -1))
  75. {
  76. applog(LOG_DEBUG, "%s: Failed to open %s", __func__, i2cpath);
  77. return false;
  78. }
  79. if (ioctl(fd, I2C_SLAVE, i2cslave))
  80. {
  81. close(fd);
  82. applog(LOG_DEBUG, "%s: Failed to select i2c slave 0x%x",
  83. __func__, i2cslave);
  84. return false;
  85. }
  86. i = i2c_smbus_read_i2c_block_data(fd, 0, 0x20, buf);
  87. close(fd);
  88. if (-1 == i)
  89. {
  90. applog(LOG_DEBUG, "%s: 0x%x: Failed to read i2c block data",
  91. __func__, i2cslave);
  92. return false;
  93. }
  94. for (i = 0; ; ++i)
  95. {
  96. if (buf[i] == 3)
  97. break;
  98. if (i == 0x1f)
  99. return false;
  100. }
  101. cgpu = malloc(sizeof(*cgpu));
  102. *cgpu = (struct cgpu_info){
  103. .drv = &knc_drv,
  104. .device_path = strdup(devpath),
  105. .deven = DEV_ENABLED,
  106. .procs = 192,
  107. .threads = prev_cgpu ? 0 : 1,
  108. };
  109. const bool rv = add_cgpu_slave(cgpu, prev_cgpu);
  110. prev_cgpu = cgpu;
  111. return rv;
  112. }
  113. static int knc_detect_auto(void)
  114. {
  115. const int first = 0x20, last = 0x26;
  116. char devpath[4];
  117. int found = 0, i;
  118. for (i = first; i <= last; ++i)
  119. {
  120. sprintf(devpath, "%d", i);
  121. if (knc_detect_one(devpath))
  122. ++found;
  123. }
  124. return found;
  125. }
  126. static void knc_detect(void)
  127. {
  128. generic_detect(&knc_drv, knc_detect_one, knc_detect_auto, GDF_REQUIRE_DNAME | GDF_DEFAULT_NOAUTO);
  129. }
  130. static
  131. bool knc_spi_open(const char *repr, struct spi_port * const spi)
  132. {
  133. const char * const spipath = "/dev/spidev1.0";
  134. const int fd = open(spipath, O_RDWR);
  135. const uint8_t lsbfirst = 0;
  136. if (fd == -1)
  137. return false;
  138. if (ioctl(fd, SPI_IOC_WR_MODE , &spi->mode )) goto fail;
  139. if (ioctl(fd, SPI_IOC_WR_LSB_FIRST , &lsbfirst )) goto fail;
  140. if (ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &spi->bits )) goto fail;
  141. if (ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ , &spi->speed)) goto fail;
  142. spi->fd = fd;
  143. return true;
  144. fail:
  145. close(fd);
  146. spi->fd = -1;
  147. applog(LOG_WARNING, "%s: Failed to open %s", repr, spipath);
  148. return false;
  149. }
  150. static
  151. bool knc_spi_txrx(struct spi_port * const spi)
  152. {
  153. const void * const wrbuf = spi_gettxbuf(spi);
  154. void * const rdbuf = spi_getrxbuf(spi);
  155. const size_t bufsz = spi_getbufsz(spi);
  156. const int fd = spi->fd;
  157. struct spi_ioc_transfer xf = {
  158. .tx_buf = (uintptr_t) wrbuf,
  159. .rx_buf = (uintptr_t) rdbuf,
  160. .len = bufsz,
  161. .delay_usecs = spi->delay,
  162. .speed_hz = spi->speed,
  163. .bits_per_word = spi->bits,
  164. };
  165. return (ioctl(fd, SPI_IOC_MESSAGE(1), &xf) > 0);
  166. }
  167. static
  168. void knc_clean_flush(struct spi_port * const spi)
  169. {
  170. const uint8_t flushcmd = KNC_REQ_FLUSH_QUEUE << 4;
  171. const size_t spi_req_sz = 0x1000;
  172. spi_clear_buf(spi);
  173. spi_emit_buf(spi, &flushcmd, 1);
  174. spi_emit_nop(spi, spi_req_sz - spi_getbufsz(spi));
  175. applog(LOG_DEBUG, "%s: Issuing flush command to clear out device queues", knc_drv.dname);
  176. spi_txrx(spi);
  177. }
  178. static
  179. bool knc_init(struct thr_info * const thr)
  180. {
  181. const int max_cores = 192;
  182. struct thr_info *mythr;
  183. struct cgpu_info * const cgpu = thr->cgpu, *proc;
  184. struct knc_device *knc;
  185. struct knc_core *knccore;
  186. struct spi_port *spi;
  187. const int i2c = open(i2cpath, O_RDWR);
  188. int i2cslave, i, j;
  189. uint8_t buf[0x20];
  190. if (unlikely(i2c == -1))
  191. {
  192. applog(LOG_DEBUG, "%s: Failed to open %s", __func__, i2cpath);
  193. return false;
  194. }
  195. knc = malloc(sizeof(*knc));
  196. for (proc = cgpu; proc; )
  197. {
  198. if (proc->device != proc)
  199. {
  200. applog(LOG_WARNING, "%"PRIpreprv": Extra processor?", proc->proc_repr);
  201. continue;
  202. }
  203. i2cslave = atoi(proc->device_path);
  204. if (ioctl(i2c, I2C_SLAVE, i2cslave))
  205. {
  206. applog(LOG_DEBUG, "%s: Failed to select i2c slave 0x%x",
  207. __func__, i2cslave);
  208. return false;
  209. }
  210. for (i = 0; i < max_cores; i += 0x20)
  211. {
  212. i2c_smbus_read_i2c_block_data(i2c, i, 0x20, buf);
  213. for (j = 0; j < 0x20; ++j)
  214. {
  215. mythr = proc->thr[0];
  216. mythr->cgpu_data = knccore = malloc(sizeof(*knccore));
  217. *knccore = (struct knc_core){
  218. .asicno = i2cslave - 0x20,
  219. .coreno = i + j,
  220. };
  221. if (proc != cgpu)
  222. mythr->queue_full = true;
  223. proc->device_data = knc;
  224. if (buf[j] != 3)
  225. proc->deven = DEV_DISABLED;
  226. proc = proc->next_proc;
  227. if ((!proc) || proc->device == proc)
  228. goto nomorecores;
  229. }
  230. }
  231. nomorecores: ;
  232. }
  233. spi = malloc(sizeof(*spi));
  234. *knc = (struct knc_device){
  235. .i2c = i2c,
  236. .spi = spi,
  237. .cgpu = cgpu,
  238. .workqueue_max = 1,
  239. };
  240. *spi = (struct spi_port){
  241. .txrx = knc_spi_txrx,
  242. .cgpu = cgpu,
  243. .repr = knc_drv.dname,
  244. .logprio = LOG_ERR,
  245. .speed = KNC_SPI_SPEED,
  246. .delay = KNC_SPI_DELAY,
  247. .mode = KNC_SPI_MODE,
  248. .bits = KNC_SPI_BITS,
  249. };
  250. if (!knc_spi_open(cgpu->dev_repr, spi))
  251. return false;
  252. knc_clean_flush(spi);
  253. timer_set_now(&thr->tv_poll);
  254. return true;
  255. }
  256. static
  257. void knc_remove_local_queue(struct knc_device * const knc, struct work * const work)
  258. {
  259. DL_DELETE(knc->workqueue, work);
  260. free_work(work);
  261. --knc->workqueue_size;
  262. }
  263. static
  264. void knc_prune_local_queue(struct thr_info *thr)
  265. {
  266. struct cgpu_info * const cgpu = thr->cgpu;
  267. struct knc_device * const knc = cgpu->device_data;
  268. struct work *work, *tmp;
  269. DL_FOREACH_SAFE(knc->workqueue, work, tmp)
  270. {
  271. if (stale_work(work, false))
  272. knc_remove_local_queue(knc, work);
  273. }
  274. thr->queue_full = (knc->workqueue_size >= knc->workqueue_max);
  275. }
  276. static
  277. bool knc_queue_append(struct thr_info * const thr, struct work * const work)
  278. {
  279. struct cgpu_info * const cgpu = thr->cgpu;
  280. struct knc_device * const knc = cgpu->device_data;
  281. if (knc->workqueue_size >= knc->workqueue_max)
  282. {
  283. knc_prune_local_queue(thr);
  284. if (thr->queue_full)
  285. return false;
  286. }
  287. DL_APPEND(knc->workqueue, work);
  288. ++knc->workqueue_size;
  289. thr->queue_full = (knc->workqueue_size >= knc->workqueue_max);
  290. if (thr->queue_full)
  291. knc_prune_local_queue(thr);
  292. return true;
  293. }
  294. #define HASH_LAST_ADDED(head, out) \
  295. (out = (head) ? (ELMT_FROM_HH((head)->hh.tbl, (head)->hh.tbl->tail)) : NULL)
  296. static
  297. void knc_queue_flush(struct thr_info * const thr)
  298. {
  299. struct cgpu_info * const cgpu = thr->cgpu;
  300. struct knc_device * const knc = cgpu->device_data;
  301. struct work *work, *tmp;
  302. if (knc->cgpu != cgpu)
  303. return;
  304. DL_FOREACH_SAFE(knc->workqueue, work, tmp)
  305. {
  306. knc_remove_local_queue(knc, work);
  307. }
  308. thr->queue_full = false;
  309. HASH_LAST_ADDED(knc->devicework, work);
  310. if (work && stale_work(work, true))
  311. {
  312. knc->need_flush = true;
  313. timer_set_now(&thr->tv_poll);
  314. }
  315. }
  316. static inline
  317. uint16_t get_u16be(const void * const p)
  318. {
  319. const uint8_t * const b = p;
  320. return (((uint16_t)b[0]) << 8) | b[1];
  321. }
  322. static inline
  323. uint32_t get_u32be(const void * const p)
  324. {
  325. const uint8_t * const b = p;
  326. return (((uint32_t)b[0]) << 0x18)
  327. | (((uint32_t)b[1]) << 0x10)
  328. | (((uint32_t)b[2]) << 8)
  329. | b[3];
  330. }
  331. static
  332. void knc_poll(struct thr_info * const thr)
  333. {
  334. struct thr_info *mythr;
  335. struct cgpu_info * const cgpu = thr->cgpu, *proc;
  336. struct knc_device * const knc = cgpu->device_data;
  337. struct spi_port * const spi = knc->spi;
  338. struct knc_core *knccore;
  339. struct work *work, *tmp;
  340. uint8_t buf[0x30], *rxbuf;
  341. int works_sent = 0, asicno, i;
  342. uint16_t workaccept;
  343. int workid = knc->next_id;
  344. uint32_t nonce, coreno;
  345. size_t spi_req_sz = 0x1000;
  346. unsigned long delay_usecs = KNC_POLL_INTERVAL_US;
  347. knc_prune_local_queue(thr);
  348. spi_clear_buf(spi);
  349. if (knc->need_flush)
  350. {
  351. applog(LOG_NOTICE, "%s: Abandoning stale searches to restart", knc_drv.dname);
  352. buf[0] = KNC_REQ_FLUSH_QUEUE << 4;
  353. spi_emit_buf(spi, buf, sizeof(buf));
  354. }
  355. DL_FOREACH(knc->workqueue, work)
  356. {
  357. buf[0] = KNC_REQ_SUBMIT_WORK << 4;
  358. buf[1] = 0;
  359. buf[2] = (workid >> 8) & 0x7f;
  360. buf[3] = workid & 0xff;
  361. for (i = 0; i < 0x20; ++i)
  362. buf[4 + i] = work->midstate[0x1f - i];
  363. for (i = 0; i < 0xc; ++i)
  364. buf[0x24 + i] = work->data[0x4b - i];
  365. spi_emit_buf(spi, buf, sizeof(buf));
  366. ++works_sent;
  367. ++workid;
  368. }
  369. spi_emit_nop(spi, spi_req_sz - spi_getbufsz(spi));
  370. spi_txrx(spi);
  371. rxbuf = spi_getrxbuf(spi);
  372. if (rxbuf[3] & 1)
  373. applog(LOG_DEBUG, "%s: Receive buffer overflow reported", knc_drv.dname);
  374. workaccept = get_u16be(&rxbuf[6]);
  375. applog(LOG_DEBUG, "%s: %lu/%d jobs accepted to queue (max=%d)",
  376. knc_drv.dname, (unsigned long)workaccept, works_sent, knc->workqueue_max);
  377. while (true)
  378. {
  379. rxbuf += 0xc;
  380. spi_req_sz -= 0xc;
  381. if (spi_req_sz < 0xc)
  382. break;
  383. const int rtype = rxbuf[0] >> 6;
  384. if (rtype && opt_debug)
  385. {
  386. char x[(0xc * 2) + 1];
  387. bin2hex(x, rxbuf, 0xc);
  388. applog(LOG_DEBUG, "%s: RECV: %s", knc_drv.dname, x);
  389. }
  390. if (rtype != KNC_REPLY_NONCE_FOUND && rtype != KNC_REPLY_WORK_DONE)
  391. continue;
  392. asicno = (rxbuf[0] & 0x38) >> 3;
  393. coreno = get_u32be(&rxbuf[8]);
  394. proc = cgpu;
  395. while (true)
  396. {
  397. knccore = proc->thr[0]->cgpu_data;
  398. if (knccore->asicno == asicno)
  399. break;
  400. do {
  401. proc = proc->next_proc;
  402. } while(proc != proc->device);
  403. }
  404. for (i = 0; i < coreno; ++i)
  405. proc = proc->next_proc;
  406. mythr = proc->thr[0];
  407. i = get_u16be(&rxbuf[2]);
  408. HASH_FIND_INT(knc->devicework, &i, work);
  409. if (!work)
  410. {
  411. const char * const msgtype = (rtype == KNC_REPLY_NONCE_FOUND) ? "nonce found" : "work done";
  412. applog(LOG_WARNING, "%"PRIpreprv": Got %s message about unknown work 0x%04x",
  413. proc->proc_repr, msgtype, i);
  414. if (KNC_REPLY_NONCE_FOUND == rtype)
  415. {
  416. nonce = get_u32be(&rxbuf[4]);
  417. nonce = le32toh(nonce);
  418. inc_hw_errors2(mythr, NULL, &nonce);
  419. }
  420. else
  421. inc_hw_errors2(mythr, NULL, NULL);
  422. continue;
  423. }
  424. switch (rtype)
  425. {
  426. case KNC_REPLY_NONCE_FOUND:
  427. nonce = get_u32be(&rxbuf[4]);
  428. nonce = le32toh(nonce);
  429. submit_nonce(mythr, work, nonce);
  430. break;
  431. case KNC_REPLY_WORK_DONE:
  432. HASH_DEL(knc->devicework, work);
  433. free_work(work);
  434. hashes_done2(mythr, 0x100000000, NULL);
  435. break;
  436. }
  437. }
  438. if (knc->need_flush)
  439. {
  440. knc->need_flush = false;
  441. HASH_ITER(hh, knc->devicework, work, tmp)
  442. {
  443. HASH_DEL(knc->devicework, work);
  444. free_work(work);
  445. }
  446. delay_usecs = 0;
  447. }
  448. if (workaccept)
  449. {
  450. if (workaccept >= knc->workqueue_max)
  451. {
  452. knc->workqueue_max = workaccept;
  453. delay_usecs = 0;
  454. }
  455. DL_FOREACH_SAFE(knc->workqueue, work, tmp)
  456. {
  457. --knc->workqueue_size;
  458. DL_DELETE(knc->workqueue, work);
  459. work->device_id = knc->next_id++ & 0x7fff;
  460. HASH_ADD_INT(knc->devicework, device_id, work);
  461. if (!--workaccept)
  462. break;
  463. }
  464. thr->queue_full = (knc->workqueue_size >= knc->workqueue_max);
  465. }
  466. timer_set_delay_from_now(&thr->tv_poll, delay_usecs);
  467. }
  468. static
  469. bool _knc_core_setstatus(struct thr_info * const thr, uint8_t val)
  470. {
  471. struct cgpu_info * const proc = thr->cgpu;
  472. struct knc_device * const knc = proc->device_data;
  473. struct knc_core * const knccore = thr->cgpu_data;
  474. const int i2c = knc->i2c;
  475. const int i2cslave = 0x20 + knccore->asicno;
  476. if (ioctl(i2c, I2C_SLAVE, i2cslave))
  477. {
  478. applog(LOG_DEBUG, "%"PRIpreprv": %s: Failed to select i2c slave 0x%x",
  479. proc->proc_repr, __func__, i2cslave);
  480. return false;
  481. }
  482. return (-1 != i2c_smbus_write_byte_data(i2c, knccore->coreno, val));
  483. }
  484. static
  485. void knc_core_disable(struct thr_info * const thr)
  486. {
  487. _knc_core_setstatus(thr, 0);
  488. }
  489. static
  490. void knc_core_enable(struct thr_info * const thr)
  491. {
  492. _knc_core_setstatus(thr, 1);
  493. }
  494. static
  495. float knc_dcdc_decode_5_11(uint16_t raw)
  496. {
  497. if (raw == 0)
  498. return 0.0;
  499. int dcdc_vin_exp = (raw & 0xf800) >> 11;
  500. float dcdc_vin_man = raw & 0x07ff;
  501. if (dcdc_vin_exp >= 16)
  502. dcdc_vin_exp = -32 + dcdc_vin_exp;
  503. float dcdc_vin = dcdc_vin_man * exp2(dcdc_vin_exp);
  504. return dcdc_vin;
  505. }
  506. static
  507. bool knc_get_stats(struct cgpu_info * const cgpu)
  508. {
  509. if (cgpu->device != cgpu)
  510. return true;
  511. struct thr_info *thr = cgpu->thr[0];
  512. struct knc_core *knccore = thr->cgpu_data;
  513. struct cgpu_info *proc;
  514. const int i2cdev = knccore->asicno + 3;
  515. const int i2cslave_temp = 0x48;
  516. const int i2cslave_dcdc[] = {0x10, 0x12, 0x14, 0x17};
  517. int die, i;
  518. int i2c;
  519. int32_t rawtemp, rawvolt, rawcurrent;
  520. float temp, volt, current;
  521. bool rv = false;
  522. char i2cpath[sizeof(KNC_I2C_TEMPLATE)];
  523. sprintf(i2cpath, KNC_I2C_TEMPLATE, i2cdev);
  524. i2c = open(i2cpath, O_RDWR);
  525. if (i2c == -1)
  526. {
  527. applog(LOG_DEBUG, "%s: %s: Failed to open %s",
  528. cgpu->dev_repr, __func__, i2cpath);
  529. return false;
  530. }
  531. if (ioctl(i2c, I2C_SLAVE, i2cslave_temp))
  532. {
  533. applog(LOG_DEBUG, "%s: %s: Failed to select i2c slave 0x%x",
  534. cgpu->dev_repr, __func__, i2cslave_temp);
  535. goto out;
  536. }
  537. rawtemp = i2c_smbus_read_word_data(i2c, 0);
  538. if (rawtemp == -1)
  539. goto out;
  540. temp = ((float)(rawtemp & 0xff));
  541. if (rawtemp & 0x8000)
  542. temp += 0.5;
  543. /* DCDC i2c slaves are on 0x10 + [0-7]
  544. 8 DCDC boards have all populated
  545. 4 DCDC boards only have 0,2,4,7 populated
  546. Only 0,2,4,7 are used
  547. Each DCDC powers one die in the chip, each die has 48 cores
  548. Datasheet at http://www.lineagepower.com/oem/pdf/MDT040A0X.pdf
  549. */
  550. for (proc = cgpu, i = 0; proc && proc->device == cgpu; proc = proc->next_proc, ++i)
  551. {
  552. thr = proc->thr[0];
  553. knccore = thr->cgpu_data;
  554. die = i / 0x30;
  555. if (0 == i % 0x30)
  556. {
  557. if (ioctl(i2c, I2C_SLAVE, i2cslave_dcdc[die]))
  558. {
  559. applog(LOG_DEBUG, "%s: %s: Failed to select i2c slave 0x%x",
  560. cgpu->dev_repr, __func__, i2cslave_dcdc[die]);
  561. goto out;
  562. }
  563. rawvolt = i2c_smbus_read_word_data(i2c, 0x8b); // VOUT
  564. if (rawvolt == -1)
  565. goto out;
  566. rawcurrent = i2c_smbus_read_word_data(i2c, 0x8c); // IOUT
  567. if (rawcurrent == -1)
  568. goto out;
  569. volt = (float)rawvolt * exp2(-10);
  570. current = (float)knc_dcdc_decode_5_11(rawcurrent);
  571. applog(LOG_DEBUG, "%s: die %d %6.3fV %5.2fA",
  572. cgpu->dev_repr, die, volt, current);
  573. }
  574. proc->temp = temp;
  575. knccore->volt = volt;
  576. knccore->current = current;
  577. }
  578. rv = true;
  579. out:
  580. close(i2c);
  581. return rv;
  582. }
  583. struct device_drv knc_drv = {
  584. .dname = "knc",
  585. .name = "KNC",
  586. .drv_detect = knc_detect,
  587. .thread_init = knc_init,
  588. .thread_disable = knc_core_disable,
  589. .thread_enable = knc_core_enable,
  590. .minerloop = minerloop_queue,
  591. .queue_append = knc_queue_append,
  592. .queue_flush = knc_queue_flush,
  593. .poll = knc_poll,
  594. .get_stats = knc_get_stats,
  595. };