driver-bitfury.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2013 Con Kolivas
  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 "miner.h"
  11. #include "driver-bitfury.h"
  12. struct device_drv bitfury_drv;
  13. static void bitfury_open(struct cgpu_info *bitfury)
  14. {
  15. /* Magic open sequence */
  16. usb_transfer(bitfury, 0x21, 0x22, 0x0003, 0, C_BFO_OPEN);
  17. }
  18. static void bitfury_close(struct cgpu_info *bitfury)
  19. {
  20. /* Magic close sequence */
  21. usb_transfer(bitfury, 0x21, 0x22, 0, 0, C_BFO_CLOSE);
  22. }
  23. static bool bitfury_detect_one(struct libusb_device *dev, struct usb_find_devices *found)
  24. {
  25. struct cgpu_info *bitfury;
  26. char buf[512];
  27. int amount;
  28. bitfury = usb_alloc_cgpu(&bitfury_drv, 1);
  29. if (!usb_init(bitfury, dev, found)) {
  30. bitfury = usb_free_cgpu(bitfury);
  31. goto out;
  32. }
  33. applog(LOG_INFO, "%s%d: Found at %s", bitfury->drv->name,
  34. bitfury->device_id, bitfury->device_path);
  35. usb_buffer_enable(bitfury);
  36. bitfury_open(bitfury);
  37. usb_write(bitfury, "I", 1, &amount, C_BFO_REQINFO);
  38. usb_read(bitfury, buf, 14, &amount, C_BFO_GETINFO);
  39. if (amount != 14) {
  40. applog(LOG_WARNING, "%s%d: Getinfo received %d",
  41. bitfury->drv->name, bitfury->device_id, amount);
  42. goto out_close;
  43. }
  44. applog(LOG_INFO, "%s%d: Getinfo returned %s", bitfury->drv->name,
  45. bitfury->device_id, buf);
  46. //return true;
  47. out_close:
  48. bitfury_close(bitfury);
  49. out:
  50. return false;
  51. }
  52. static void bitfury_detect(void)
  53. {
  54. usb_detect(&bitfury_drv, bitfury_detect_one);
  55. }
  56. static bool bitfury_prepare(struct thr_info __maybe_unused *thr)
  57. {
  58. return false;
  59. }
  60. static bool bitfury_fill(struct cgpu_info __maybe_unused *bitfury)
  61. {
  62. return true;
  63. }
  64. static int64_t bitfury_scanhash(struct thr_info __maybe_unused *thr)
  65. {
  66. return 0;
  67. }
  68. static void bitfury_flush_work(struct cgpu_info __maybe_unused *bitfury)
  69. {
  70. }
  71. static struct api_data *bitfury_api_stats(struct cgpu_info __maybe_unused *cgpu)
  72. {
  73. return NULL;
  74. }
  75. static void get_bitfury_statline_before(char __maybe_unused *buf, size_t __maybe_unused bufsiz,
  76. struct cgpu_info __maybe_unused *bitfury)
  77. {
  78. }
  79. static void bitfury_init(struct cgpu_info __maybe_unused *bitfury)
  80. {
  81. }
  82. static void bitfury_shutdown(struct thr_info __maybe_unused *thr)
  83. {
  84. struct cgpu_info *bitfury = thr->cgpu;
  85. bitfury_close(bitfury);
  86. }
  87. /* Currently hardcoded to BF1 devices */
  88. struct device_drv bitfury_drv = {
  89. .drv_id = DRIVER_BITFURY,
  90. .dname = "bitfury",
  91. .name = "BFO",
  92. .drv_detect = bitfury_detect,
  93. .thread_prepare = bitfury_prepare,
  94. .hash_work = hash_queued_work,
  95. .queue_full = bitfury_fill,
  96. .scanwork = bitfury_scanhash,
  97. .flush_work = bitfury_flush_work,
  98. .get_api_stats = bitfury_api_stats,
  99. .get_statline_before = get_bitfury_statline_before,
  100. .reinit_device = bitfury_init,
  101. .thread_shutdown = bitfury_shutdown
  102. };