driver-erupter.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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 "miner.h"
  12. #include "fpgautils.h"
  13. #include "icarus-common.h"
  14. #define ERUPTER_IO_SPEED 115200
  15. #define ERUPTER_HASH_TIME 0.0000000029761
  16. BFG_REGISTER_DRIVER(erupter_drv)
  17. BFG_REGISTER_DRIVER(erupter_drv_emerald)
  18. static bool _erupter_detect_one(const char *devpath, struct device_drv *drv)
  19. {
  20. struct ICARUS_INFO *info = calloc(1, sizeof(struct ICARUS_INFO));
  21. if (unlikely(!info))
  22. quit(1, "Failed to malloc ICARUS_INFO");
  23. *info = (struct ICARUS_INFO){
  24. .baud = ERUPTER_IO_SPEED,
  25. .Hs = ERUPTER_HASH_TIME,
  26. .timing_mode = MODE_DEFAULT,
  27. .continue_search = true,
  28. };
  29. if (!icarus_detect_custom(devpath, drv, info)) {
  30. free(info);
  31. return false;
  32. }
  33. return true;
  34. }
  35. static bool erupter_emerald_detect_one(const char *devpath)
  36. {
  37. // For detection via BEE:*
  38. return _erupter_detect_one(devpath, &erupter_drv_emerald);
  39. }
  40. static bool erupter_detect_one(const char *devpath)
  41. {
  42. struct device_drv *drv = &erupter_drv;
  43. // For autodetection
  44. if (unlikely(detectone_meta_info.product && strstr(detectone_meta_info.product, "Emerald")))
  45. drv = &erupter_drv_emerald;
  46. return _erupter_detect_one(devpath, drv);
  47. }
  48. static int erupter_emerald_detect_auto(void)
  49. {
  50. return serial_autodetect(erupter_emerald_detect_one, "Block", "Erupter", "Emerald");
  51. }
  52. static int erupter_detect_auto(void)
  53. {
  54. return serial_autodetect(erupter_detect_one, "Block", "Erupter");
  55. }
  56. static void erupter_drv_init();
  57. static void erupter_detect()
  58. {
  59. erupter_drv_init();
  60. // Actual serial detection is handled by Icarus driver
  61. serial_detect_auto_byname(&erupter_drv, erupter_detect_one, erupter_detect_auto);
  62. serial_detect_auto_byname(&erupter_drv_emerald, erupter_emerald_detect_one, erupter_emerald_detect_auto);
  63. }
  64. static bool erupter_identify(struct cgpu_info *erupter)
  65. {
  66. struct thr_info *thr = erupter->thr[0];
  67. struct icarus_state *state = thr->cgpu_data;
  68. state->identify = true;
  69. return true;
  70. }
  71. static void erupter_drv_init()
  72. {
  73. erupter_drv = icarus_drv;
  74. erupter_drv.dname = "erupter";
  75. erupter_drv.name = "BES";
  76. erupter_drv.drv_detect = erupter_detect;
  77. erupter_drv.identify_device = erupter_identify;
  78. erupter_drv_emerald = erupter_drv;
  79. erupter_drv_emerald.name = "BEE";
  80. }
  81. struct device_drv erupter_drv = {
  82. // Needed to get to erupter_drv_init at all
  83. .drv_detect = erupter_detect,
  84. };
  85. struct device_drv erupter_drv_emerald;