driver-erupter.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 "icarus-common.h"
  13. #include "lowlevel.h"
  14. #include "lowl-vcom.h"
  15. #define ERUPTER_IO_SPEED 115200
  16. #define ERUPTER_HASH_TIME 0.0000000029761
  17. BFG_REGISTER_DRIVER(erupter_drv)
  18. BFG_REGISTER_DRIVER(erupter_drv_emerald)
  19. static bool _erupter_detect_one(const char *devpath, struct device_drv *drv)
  20. {
  21. struct ICARUS_INFO *info = calloc(1, sizeof(struct ICARUS_INFO));
  22. if (unlikely(!info))
  23. quit(1, "Failed to malloc ICARUS_INFO");
  24. *info = (struct ICARUS_INFO){
  25. .baud = ERUPTER_IO_SPEED,
  26. .Hs = ERUPTER_HASH_TIME,
  27. .timing_mode = MODE_DEFAULT,
  28. .continue_search = true,
  29. };
  30. if (!icarus_detect_custom(devpath, drv, info)) {
  31. free(info);
  32. return false;
  33. }
  34. return true;
  35. }
  36. static
  37. bool erupter_emerald_lowl_match(const struct lowlevel_device_info * const info)
  38. {
  39. return lowlevel_match_product(info, "Block", "Erupter", "Emerald");
  40. }
  41. static bool erupter_emerald_detect_one(const char *devpath)
  42. {
  43. // For detection via BEE:*
  44. return _erupter_detect_one(devpath, &erupter_drv_emerald);
  45. }
  46. static
  47. bool erupter_emerald_lowl_probe(const struct lowlevel_device_info * const info)
  48. {
  49. return vcom_lowl_probe_wrapper(info, erupter_emerald_detect_one);
  50. }
  51. static
  52. bool erupter_lowl_match(const struct lowlevel_device_info * const info)
  53. {
  54. return lowlevel_match_lowlproduct(info, &lowl_vcom, "Block", "Erupter");
  55. }
  56. static bool erupter_detect_one(const char *devpath)
  57. {
  58. struct device_drv *drv = &erupter_drv;
  59. // For autodetection
  60. if (unlikely(detectone_meta_info.product && strstr(detectone_meta_info.product, "Emerald")))
  61. drv = &erupter_drv_emerald;
  62. return _erupter_detect_one(devpath, drv);
  63. }
  64. static
  65. bool erupter_lowl_probe(const struct lowlevel_device_info * const info)
  66. {
  67. return vcom_lowl_probe_wrapper(info, erupter_detect_one);
  68. }
  69. static bool erupter_identify(struct cgpu_info *erupter)
  70. {
  71. struct thr_info *thr = erupter->thr[0];
  72. struct icarus_state *state = thr->cgpu_data;
  73. state->identify = true;
  74. return true;
  75. }
  76. static void erupter_drv_init()
  77. {
  78. erupter_drv = icarus_drv;
  79. erupter_drv.dname = "erupter";
  80. erupter_drv.name = "BES";
  81. erupter_drv.lowl_match = erupter_lowl_match;
  82. erupter_drv.lowl_probe = erupter_lowl_probe;
  83. erupter_drv.identify_device = erupter_identify;
  84. erupter_drv.probe_priority = -120;
  85. erupter_drv_emerald = erupter_drv;
  86. erupter_drv_emerald.name = "BEE";
  87. erupter_drv.lowl_match = erupter_emerald_lowl_match;
  88. erupter_drv.lowl_probe = erupter_emerald_lowl_probe;
  89. erupter_drv_emerald.probe_priority = -119;
  90. }
  91. struct device_drv erupter_drv = {
  92. .drv_init = erupter_drv_init,
  93. };
  94. struct device_drv erupter_drv_emerald = {
  95. .drv_init = erupter_drv_init,
  96. };