dm_compat.h 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762
  1. #ifndef _DM_COMPAT_H_
  2. #define _DM_COMPAT_H_
  3. #include "miner.h"
  4. #include <linux/i2c-dev.h>
  5. #include <linux/i2c.h>
  6. #include <asm/ioctls.h>
  7. #include <sys/stat.h>
  8. #include <fcntl.h>
  9. #include <unistd.h>
  10. #include <sys/ioctl.h>
  11. #include <sys/mman.h>
  12. #include <ctype.h>
  13. #include <limits.h>
  14. #include <linux/watchdog.h>
  15. #include <stdio.h>
  16. #include <stdint.h>
  17. #include <stdbool.h>
  18. #include <pthread.h>
  19. #include <linux/spi/spidev.h>
  20. #include <linux/types.h>
  21. #define NUMARGS(...) ((int)(sizeof((int[]){(int)__VA_ARGS__})/sizeof(int)))
  22. #define FSCANF(STREAM, FORMAT, ...) \
  23. do { \
  24. if (unlikely(fscanf((STREAM), (FORMAT), __VA_ARGS__) != NUMARGS(__VA_ARGS__))) { \
  25. applog(LOG_ERR, "Failed to fscanf %d args from %s %s line %d", \
  26. NUMARGS(__VA_ARGS__), __FILE__, __func__, __LINE__); \
  27. } \
  28. } while (0)
  29. #define FREAD(PTR, SIZE, NMEMB, STREAM) \
  30. do { \
  31. if (unlikely(fread((PTR), (SIZE), (NMEMB), (STREAM)) != NMEMB)) \
  32. applog(LOG_ERR, "Failed to fread size %d nmemb %d from %s %s line %d", \
  33. (SIZE), (NMEMB), __FILE__, __func__, __LINE__); \
  34. } while (0)
  35. #define FWRITE(PTR, SIZE, NMEMB, STREAM) \
  36. do { \
  37. if (unlikely(fwrite((PTR), (SIZE), (NMEMB), (STREAM)) != NMEMB)) \
  38. applog(LOG_ERR, "Failed to fwrite size %d nmemb %d from %s %s line %d", \
  39. (SIZE), (NMEMB), __FILE__, __func__, __LINE__); \
  40. } while (0)
  41. #define WRITE(FILDES, BUF, NBYTE) \
  42. do { \
  43. int ret = write((FILDES), (BUF), (NBYTE)); \
  44. if (unlikely(ret != (int)(NBYTE))) { \
  45. if (ret == -1) { \
  46. applog(LOG_ERR, "Failed to write size %d from %s %s line %d with errno %d:%s", \
  47. (NBYTE), __FILE__, __func__, __LINE__, errno, strerror(errno)); \
  48. } else { \
  49. applog(LOG_WARNING, "Failed to write size %d from %s %s line %d", \
  50. (NBYTE), __FILE__, __func__, __LINE__); \
  51. } \
  52. } \
  53. } while (0)
  54. #define READ(FILDES, BUF, NBYTE) \
  55. do { \
  56. int ret = read((FILDES), (BUF), (NBYTE)); \
  57. if (unlikely(ret != (int)(NBYTE))) { \
  58. if (ret == -1) { \
  59. applog(LOG_ERR, "Failed to read size %d from %s %s line %d with errno %d:%s", \
  60. (NBYTE), __FILE__, __func__, __LINE__, errno, strerror(errno)); \
  61. } else { \
  62. applog(LOG_WARNING, "Failed to read size %d from %s %s line %d", \
  63. (NBYTE), __FILE__, __func__, __LINE__); \
  64. } \
  65. } \
  66. } while (0)
  67. /* MCOMPAT_CHAIN */
  68. typedef struct MCOMPAT_CHAIN_TAG{
  69. //
  70. bool (*power_on)(unsigned char);
  71. //
  72. bool (*power_down)(unsigned char);
  73. //
  74. bool (*hw_reset)(unsigned char);
  75. //
  76. bool (*power_on_all)(void);
  77. //
  78. bool (*power_down_all)(void);
  79. }MCOMPAT_CHAIN_T;
  80. void init_mcompat_chain(void);
  81. void exit_mcompat_chain(void);
  82. void register_mcompat_chain(MCOMPAT_CHAIN_T * ops);
  83. bool mcompat_chain_power_on(unsigned char chain_id);
  84. bool mcompat_chain_power_down(unsigned char chain_id);
  85. bool mcompat_chain_hw_reset(unsigned char chain_id);
  86. /* MCOMPAT_FAN */
  87. extern int g_temp_hi_thr;
  88. extern int g_temp_lo_thr;
  89. extern int g_temp_start_thr;
  90. extern int g_dangerous_temp;
  91. extern int g_work_temp;
  92. typedef struct {
  93. int final_temp_avg;
  94. int final_temp_hi;
  95. int final_temp_lo;
  96. int temp_highest[3];
  97. int temp_lowest[3];
  98. }mcompat_temp_s;
  99. typedef struct {
  100. int temp_hi_thr;
  101. int temp_lo_thr;
  102. int temp_start_thr;
  103. int dangerous_stat_temp;
  104. int work_temp;
  105. int default_fan_speed;
  106. }mcompat_temp_config_s;
  107. typedef struct {
  108. int fd;
  109. int last_valid_temp;
  110. int speed;
  111. int last_fan_speed;
  112. int last_fan_temp;
  113. mcompat_temp_s * mcompat_temp;
  114. int temp_average;
  115. int temp_highest;
  116. int temp_lowest;
  117. }mcompat_fan_temp_s;
  118. extern void mcompat_fan_temp_init(unsigned char fan_id,mcompat_temp_config_s temp_config);
  119. extern void mcompat_fan_speed_set(unsigned char fan_id, int speed);
  120. extern void mcompat_fan_speed_update_hub(mcompat_fan_temp_s *fan_temp);
  121. /* MCOMPAT_CMD */
  122. typedef struct MCOMPAT_CMD_TAG{
  123. //
  124. void (*set_speed)(unsigned char, int);
  125. //
  126. bool (*cmd_reset)(unsigned char, unsigned char, unsigned char *, unsigned char *);
  127. //
  128. int (*cmd_bist_start)(unsigned char, unsigned char);
  129. //
  130. bool (*cmd_bist_collect)(unsigned char, unsigned char);
  131. //
  132. bool (*cmd_bist_fix)(unsigned char, unsigned char);
  133. //
  134. bool (*cmd_write_register)(unsigned char, unsigned char, unsigned char *, int);
  135. //
  136. bool (*cmd_read_register)(unsigned char, unsigned char, unsigned char *, int);
  137. //
  138. bool (*cmd_read_write_reg0d)(unsigned char, unsigned char, unsigned char *, int, unsigned char *);
  139. //
  140. bool (*cmd_write_job)(unsigned char, unsigned char, unsigned char *, int);
  141. //
  142. bool (*cmd_read_result)(unsigned char, unsigned char, unsigned char *, int);
  143. //
  144. bool (*cmd_auto_nonce)(unsigned char, int, int);
  145. //
  146. bool (*cmd_read_nonce)(unsigned char, unsigned char *, int);
  147. bool (*cmd_get_temp)(mcompat_fan_temp_s *temp_ctrl);
  148. }MCOMPAT_CMD_T;
  149. void init_mcompat_cmd(void);
  150. void exit_mcompat_cmd(void);
  151. void register_mcompat_cmd(MCOMPAT_CMD_T * cmd_ops_p);
  152. /* MCOMPAT_GPIO */
  153. typedef struct MCOMPAT_GPIO_TAG{
  154. //
  155. void (*set_power_en)(unsigned char, int);
  156. //
  157. void (*set_start_en)(unsigned char, int);
  158. //
  159. bool (*set_reset)(unsigned char, int);
  160. //
  161. void (*set_led)(unsigned char, int);
  162. //
  163. int (*get_plug)(unsigned char);
  164. //
  165. bool (*set_vid)(unsigned char, int);
  166. //
  167. void (*set_green_led)(int mode);
  168. //
  169. void (*set_red_led)(int mode);
  170. //
  171. int (*get_button)(void);
  172. }MCOMPAT_GPIO_T;
  173. void init_mcompat_gpio(void);
  174. void exit_mcompat_gpio(void);
  175. void register_mcompat_gpio(MCOMPAT_GPIO_T * ops);
  176. /* MCOMPAT_GPIO_I2C */
  177. #define _SCL_PIN (0)
  178. #define _SDA_PIN (1)
  179. void mcompat_gpio_i2c_init(void);
  180. void mcompat_gpio_i2c_deinit(void);
  181. void mcompat_gpio_i2c_send_byte(uint8_t data);
  182. uint8_t mcompat_gpio_i2c_recv_byte(void);
  183. bool mcompat_gpio_i2c_send_buf(uint8_t *buf, uint8_t buf_len, uint8_t dev_addr, uint16_t reg_addr);
  184. bool mcompat_gpio_i2c_recv_buf(uint8_t *buf, uint8_t buf_len, uint8_t dev_addr, uint16_t reg_addr);
  185. /* MCOMPAT_PWM */
  186. typedef struct MCOMPAT_PWM_TAG{
  187. //
  188. void (*set_pwm)(unsigned char, int, int);
  189. }MCOMPAT_PWM_T;
  190. void init_mcompat_pwm(void);
  191. void exit_mcompat_pwm(void);
  192. void register_mcompat_pwm(MCOMPAT_PWM_T * ops);
  193. /* MCOMPAT_TEMP */
  194. typedef struct _c_temp
  195. {
  196. short tmp_lo; // lowest temperature
  197. short tmp_hi; // highest temperature
  198. short tmp_avg; // average temperature
  199. bool optimal; // temp considered in optimal range
  200. } c_temp;
  201. extern int mcompat_temp_to_centigrade(int temp);
  202. extern bool mcompat_get_chain_temp(unsigned char chain_id, c_temp *chain_tmp);
  203. extern void mcompat_get_chip_temp(int chain_id, int *chip_temp);
  204. /* MCOMPAT_WATCHDOG */
  205. #define MCOMPAT_WATCHDOG_DEV ("/dev/watchdog0")
  206. void mcompat_watchdog_keep_alive(void);
  207. void mcompat_watchdog_open(void);
  208. void mcompat_watchdog_set_timeout(int timeout);
  209. void mcompat_watchdog_close(void);
  210. /* MCOMPAT_LIB */
  211. #define MCOMPAT_LIB_MINER_TYPE_FILE ("/tmp/type")
  212. #define MCOMPAT_LIB_HARDWARE_VERSION_FILE ("/tmp/hwver")
  213. #define MCOMPAT_LIB_HARDWARE_VERSION_G9 (9)
  214. #define MCOMPAT_LIB_HARDWARE_VERSION_G19 (19)
  215. #define MCOMPAT_LIB_HARDWARE_VERSION_ERR (-1)
  216. #define MCOMPAT_LIB_MINER_TYPE_T1 (1)
  217. #define MCOMPAT_LIB_MINER_TYPE_T2 (2)
  218. #define MCOMPAT_LIB_MINER_TYPE_T3 (3)
  219. #define MCOMPAT_LIB_MINER_TYPE_T4 (4)
  220. #define MCOMPAT_LIB_MINER_TYPE_D11 (5)
  221. #define MCOMPAT_LIB_MINER_TYPE_D12 (6)
  222. #define MCOMPAT_LIB_MINER_TYPE_ERR (-1)
  223. #define MCOMPAT_LIB_VID_VID_TYPE (0)
  224. #define MCOMPAT_LIB_VID_GPIO_I2C_TYPE (1)
  225. #define MCOMPAT_LIB_VID_UART_TYPE (2)
  226. #define MCOMPAT_LIB_VID_I2C_TYPE (3)
  227. #define MCOMPAT_LIB_VID_ERR_TYPE (-1)
  228. #define REG_LENGTH (12)
  229. #define VID_MAX (31)
  230. #define VID_MIN (0)
  231. int mcompat_get_shell_cmd_rst(char *cmd, char *result, int size);
  232. int misc_call_api(char *command, char *host, short int port);
  233. bool misc_tcp_is_ok(char *host, short int port);
  234. char *misc_trim(char *str);
  235. int misc_get_board_version(void);
  236. int misc_get_miner_type(void);
  237. int misc_get_vid_type(void);
  238. void misc_system(const char *cmd, char *rst_buf, int buf_size);
  239. void mcompat_configure_tvsensor(int chain_id, int chip_id, bool is_tsensor);
  240. void mcompat_cfg_tsadc_divider(int chain_id,unsigned int pll_clk);
  241. void mcompat_get_chip_volt(int chain_id, int *chip_volt);
  242. int mcompat_find_chain_vid(int chain_id, int chip_num, int vid_start, double volt_target);
  243. double mcompat_get_average_volt(int *volt, int size);
  244. /* MCOMPAT_DRV */
  245. #define PLATFORM_ZYNQ_SPI_G9 (0x01)
  246. #define PLATFORM_ZYNQ_SPI_G19 (0x02)
  247. #define PLATFORM_ZYNQ_HUB_G9 (0x03)
  248. #define PLATFORM_ZYNQ_HUB_G19 (0x04)
  249. #define PLATFORM_SOC (0x10)
  250. #define PLATFORM_ORANGE_PI (0x20)
  251. #define SPI_SPEED_390K (0)
  252. #define SPI_SPEED_781K (1)
  253. #define SPI_SPEED_1562K (2)
  254. #define SPI_SPEED_3125K (3)
  255. #define SPI_SPEED_6250K (4)
  256. #define SPI_SPEED_9960K (5)
  257. #define MCOMPAT_LOG_DEBUG (1)
  258. #define MCOMPAT_LOG_INFO (2)
  259. #define MCOMPAT_LOG_NOTICE (3)
  260. #define MCOMPAT_LOG_WARNING (4)
  261. #define MCOMPAT_LOG_ERR (5)
  262. #define MCOMPAT_LOG_CRIT (6)
  263. #define MCOMPAT_LOG_ALERT (7)
  264. #define MCOMPAT_LOG_EMERG (8)
  265. extern void sys_platform_debug_init(int debug_level);
  266. extern bool sys_platform_init(int platform, int miner_type, int chain_num, int chip_num);
  267. extern bool sys_platform_exit();
  268. extern bool mcompat_set_spi_speed(unsigned char chain_id, int index);
  269. extern bool mcompat_cmd_reset(unsigned char chain_id, unsigned char chip_id, unsigned char *in, unsigned char *out);
  270. extern int mcompat_cmd_bist_start(unsigned char chain_id, unsigned char chip_id);
  271. extern bool mcompat_cmd_bist_collect(unsigned char chain_id, unsigned char chip_id);
  272. extern bool mcompat_cmd_bist_fix(unsigned char chain_id, unsigned char chip_id);
  273. extern bool mcompat_cmd_write_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  274. extern bool mcompat_cmd_read_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  275. extern bool mcompat_cmd_read_write_reg0d(unsigned char chain_id, unsigned char chip_id, unsigned char *in, int len, unsigned char *out);
  276. extern bool mcompat_cmd_read_result(unsigned char chain_id, unsigned char chip_id, unsigned char *res, int len);
  277. extern bool mcompat_cmd_write_job(unsigned char chain_id, unsigned char chip_id, unsigned char *job, int len);
  278. extern bool mcompat_cmd_auto_nonce(unsigned char chain_id, int mode, int len);
  279. extern bool mcompat_cmd_read_nonce(unsigned char chain_id, unsigned char *res, int len);
  280. extern bool mcompat_cmd_get_temp(mcompat_fan_temp_s * fan_temp);
  281. extern bool mcompat_get_chain_temp(unsigned char chain_id, c_temp *chain_tmp);
  282. extern void mcompat_set_power_en(unsigned char chain_id, int val);
  283. extern void mcompat_set_start_en(unsigned char chain_id, int val);
  284. extern bool mcompat_set_reset(unsigned char chain_id, int val);
  285. extern void mcompat_set_led(unsigned char chain_id, int val);
  286. extern bool mcompat_set_vid(unsigned char chain_id, int val);
  287. extern bool mcompat_set_vid_by_step(unsigned char chain_id, int start_vid, int target_vid);
  288. extern void mcompat_set_pwm(unsigned char fan_id, int frequency, int duty);
  289. extern int mcompat_get_plug(unsigned char chain_id);
  290. extern int mcompat_get_button(void);
  291. extern void mcompat_set_green_led(int mode);
  292. extern void mcompat_set_red_led(int mode);
  293. extern bool mcompat_chain_power_on(unsigned char chain_id);
  294. extern bool mcompat_chain_power_down(unsigned char chain_id);
  295. extern bool mcompat_chain_hw_reset(unsigned char chain_id);
  296. extern bool mcompat_chain_power_on_all(void);
  297. extern bool mcompat_chain_power_down_all(void);
  298. #define MCOMPAT_CONFIG_MAX_CHAIN_NUM (8)
  299. #define MCOMPAT_CONFIG_MAX_CHIP_NUM (80)
  300. #define MCOMPAT_CONFIG_MAX_JOB_LEN (92)
  301. #define MCOMPAT_CONFIG_MAX_CMD_LENGTH (256)
  302. #define MAGIC_NUM (100)
  303. #define CMD_BIST_START (0x01)
  304. #define CMD_BIST_COLLECT (0x0b)
  305. #define CMD_BIST_FIX (0x03)
  306. #define CMD_RESET (0x04)
  307. #define CMD_RESETBC (0x05)
  308. #define CMD_WRITE_JOB (0x07)
  309. #define CMD_WRITE_JOB_T1 (0x0c)
  310. #define CMD_READ_RESULT (0x08)
  311. #define CMD_WRITE_REG (0x09)
  312. #define CMD_READ_REG (0x0a)
  313. #define CMD_WRITE_REG0d (0x0d)
  314. #define CMD_POWER_ON (0x02)
  315. #define CMD_POWER_OFF (0x06)
  316. #define CMD_POWER_RESET (0x0c)
  317. #define RESP_READ_REG (0x1a)
  318. #define CMD_ADDR_BROADCAST (0x00)
  319. #define CMD_HL (2)
  320. #define CMD_RESET_DL (4)
  321. #define CMD_RESET_TL (CMD_HL + CMD_RESET_DL)
  322. #define ASIC_MCOMPAT_FAN_PWM_STEP (5)
  323. #define ASIC_MCOMPAT_FAN_PWM_DUTY_MAX (100)
  324. #define ASIC_MCOMPAT_FAN_PWM_FREQ_TARGET (20000)
  325. #define ASIC_MCOMPAT_FAN_PWM_FREQ (20000)
  326. #define FAN_CNT ( 2 )
  327. #define ASIC_MCOMPAT_FAN_TEMP_MAX_THRESHOLD (100)
  328. #define ASIC_MCOMPAT_FAN_TEMP_UP_THRESHOLD (55)
  329. #define ASIC_MCOMPAT_FAN_TEMP_DOWN_THRESHOLD (35)
  330. #define MCOMPAT_VID_UART_PATH ("/dev/ttyPS1")
  331. #define MCOMPAT_CONFIG_CMD_MAX_LEN (MCOMPAT_CONFIG_MAX_JOB_LEN + MCOMPAT_CONFIG_MAX_CHAIN_NUM * 2 * 2)
  332. #define MCOMPAT_CONFIG_CMD_RST_MAX_LEN (MCOMPAT_CONFIG_CMD_MAX_LEN)
  333. /* SPI */
  334. #define MCOMPAT_CONFIG_SPI_DEFAULT_CS_LINE (0)
  335. #define MCOMPAT_CONFIG_SPI_DEFAULT_MODE (SPI_MODE_1)
  336. #define MCOMPAT_CONFIG_SPI_DEFAULT_SPEED (1500000)
  337. #define MCOMPAT_CONFIG_SPI_DEFAULT_BITS_PER_WORD (8)
  338. /* GPIO */
  339. #define MCOMPAT_CONFIG_CHAIN0_POWER_EN_GPIO (872)
  340. #define MCOMPAT_CONFIG_CHAIN1_POWER_EN_GPIO (873)
  341. #define MCOMPAT_CONFIG_CHAIN2_POWER_EN_GPIO (874)
  342. #define MCOMPAT_CONFIG_CHAIN3_POWER_EN_GPIO (875)
  343. #define MCOMPAT_CONFIG_CHAIN4_POWER_EN_GPIO (876)
  344. #define MCOMPAT_CONFIG_CHAIN5_POWER_EN_GPIO (877)
  345. #define MCOMPAT_CONFIG_CHAIN6_POWER_EN_GPIO (878)
  346. #define MCOMPAT_CONFIG_CHAIN7_POWER_EN_GPIO (879)
  347. #define MCOMPAT_CONFIG_CHAIN0_START_EN_GPIO (854)
  348. #define MCOMPAT_CONFIG_CHAIN1_START_EN_GPIO (856)
  349. #define MCOMPAT_CONFIG_CHAIN2_START_EN_GPIO (858)
  350. #define MCOMPAT_CONFIG_CHAIN3_START_EN_GPIO (860)
  351. #define MCOMPAT_CONFIG_CHAIN4_START_EN_GPIO (862)
  352. #define MCOMPAT_CONFIG_CHAIN5_START_EN_GPIO (864)
  353. #define MCOMPAT_CONFIG_CHAIN6_START_EN_GPIO (866)
  354. #define MCOMPAT_CONFIG_CHAIN7_START_EN_GPIO (868)
  355. #define MCOMPAT_CONFIG_CHAIN0_RESET_GPIO (855)
  356. #define MCOMPAT_CONFIG_CHAIN1_RESET_GPIO (857)
  357. #define MCOMPAT_CONFIG_CHAIN2_RESET_GPIO (859)
  358. #define MCOMPAT_CONFIG_CHAIN3_RESET_GPIO (861)
  359. #define MCOMPAT_CONFIG_CHAIN4_RESET_GPIO (863)
  360. #define MCOMPAT_CONFIG_CHAIN5_RESET_GPIO (865)
  361. #define MCOMPAT_CONFIG_CHAIN6_RESET_GPIO (867)
  362. #define MCOMPAT_CONFIG_CHAIN7_RESET_GPIO (869)
  363. #define MCOMPAT_CONFIG_CHAIN0_LED_GPIO (881)
  364. #define MCOMPAT_CONFIG_CHAIN1_LED_GPIO (882)
  365. #define MCOMPAT_CONFIG_CHAIN2_LED_GPIO (883)
  366. #define MCOMPAT_CONFIG_CHAIN3_LED_GPIO (884)
  367. #define MCOMPAT_CONFIG_CHAIN4_LED_GPIO (885)
  368. #define MCOMPAT_CONFIG_CHAIN5_LED_GPIO (886)
  369. #define MCOMPAT_CONFIG_CHAIN6_LED_GPIO (887)
  370. #define MCOMPAT_CONFIG_CHAIN7_LED_GPIO (888)
  371. #define MCOMPAT_CONFIG_CHAIN0_PLUG_GPIO (896)
  372. #define MCOMPAT_CONFIG_CHAIN1_PLUG_GPIO (897)
  373. #define MCOMPAT_CONFIG_CHAIN2_PLUG_GPIO (898)
  374. #define MCOMPAT_CONFIG_CHAIN3_PLUG_GPIO (899)
  375. #define MCOMPAT_CONFIG_CHAIN4_PLUG_GPIO (900)
  376. #define MCOMPAT_CONFIG_CHAIN5_PLUG_GPIO (901)
  377. #define MCOMPAT_CONFIG_CHAIN6_PLUG_GPIO (902)
  378. #define MCOMPAT_CONFIG_CHAIN7_PLUG_GPIO (903)
  379. #define MCOMPAT_CONFIG_B9_GPIO (906 + 51)
  380. #define MCOMPAT_CONFIG_A10_GPIO (906 + 37)
  381. extern int g_platform;
  382. extern int g_miner_type;
  383. extern int g_chain_num;
  384. extern int g_chip_num;
  385. /* ZYNQ_GPIO */
  386. extern void zynq_gpio_init(int pin, int dir);
  387. extern void zynq_gpio_exit(int pin);
  388. extern int zynq_gpio_read(int pin);
  389. /* ZYNQ_PWM */
  390. #define SYSFS_PWM_DEV ("/dev/pwmgen0.0")
  391. #define IOCTL_SET_PWM_FREQ(x) _IOR(MAGIC_NUM, (2*x), char *)
  392. #define IOCTL_SET_PWM_DUTY(x) _IOR(MAGIC_NUM, (2*x+1), char *)
  393. extern void zynq_set_pwm(unsigned char fan_id, int frequency, int duty);
  394. extern int zynq_gpio_g19_vid_set(int chain_id, int level);
  395. /* ZYNQ_SPI */
  396. typedef struct ZYNQ_SPI_TAG{
  397. int fd;
  398. pthread_mutex_t lock;
  399. }ZYNQ_SPI_T;
  400. void zynq_spi_init(ZYNQ_SPI_T *spi, int bus);
  401. void zynq_spi_exit(ZYNQ_SPI_T *spi);
  402. void zynq_spi_read(ZYNQ_SPI_T *spi, uint8_t *rxbuf, int len);
  403. void zynq_spi_write(ZYNQ_SPI_T *spi, uint8_t *txbuf, int len);
  404. void zynq_set_spi_speed(int speed);
  405. /* ZYNQ_VID */
  406. #define SYSFS_VID_DEV ("/dev/vidgen0.0")
  407. #define IOCTL_SET_VAL_0 _IOR(MAGIC_NUM, 0, char *)
  408. #define IOCTL_SET_VALUE_0 _IOR(MAGIC_NUM, 0, char *)
  409. #define IOCTL_SET_CHAIN_0 _IOR(MAGIC_NUM, 1, char *)
  410. typedef struct ZYNQ_VID_TAG{
  411. int fd;
  412. pthread_mutex_t lock;
  413. }ZYNQ_VID_T;
  414. extern int zynq_gpio_g9_vid_set(int level);
  415. extern int zynq_gpio_g19_vid_set(int chain_id, int level);
  416. /* HUB_HARDWARE */
  417. #define _MAX_MEM_RANGE (0x10000)
  418. void hub_hardware_init(void);
  419. void hub_hardware_deinit(void);
  420. /* HUB_VID */
  421. #define I2C_DEVICE_NAME "/dev/i2c-0"
  422. #define I2C_SLAVE_ADDR 0x01
  423. bool hub_set_vid(uint8_t chan_id, int vol);
  424. bool set_timeout_on_i2c(int time);
  425. /* DRV_HUB */
  426. #define PAGE_SIZE ((size_t)getpagesize())*2
  427. #define PAGE_MASK ((uint32_t) (long)~(PAGE_SIZE - 1))
  428. /* Definition for CPU ID */
  429. #define XPAR_CPU_ID 0
  430. /* Definitions for peripheral PS7_CORTEXA9_0 */
  431. #define XPAR_PS7_CORTEXA9_0_CPU_CLK_FREQ_HZ 666666687
  432. /******************************************************************/
  433. /* Canonical definitions for peripheral PS7_CORTEXA9_0 */
  434. #define XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ 666666687
  435. /******************************************************************/
  436. #define STDIN_BASEADDRESS 0xE0001000
  437. #define STDOUT_BASEADDRESS 0xE0001000
  438. /******************************************************************/
  439. /* Definitions for peripheral PS7_DDR_0 */
  440. #define XPAR_PS7_DDR_0_S_AXI_BASEADDR 0x00100000
  441. #define XPAR_PS7_DDR_0_S_AXI_HIGHADDR 0x1FFFFFFF
  442. /******************************************************************/
  443. /* Definitions for driver DEVCFG */
  444. #define XPAR_XDCFG_NUM_INSTANCES 1
  445. /* Definitions for peripheral PS7_DEV_CFG_0 */
  446. #define XPAR_PS7_DEV_CFG_0_DEVICE_ID 0
  447. #define XPAR_PS7_DEV_CFG_0_BASEADDR 0xF8007000
  448. #define XPAR_PS7_DEV_CFG_0_HIGHADDR 0xF80070FF
  449. /******************************************************************/
  450. /* Canonical definitions for peripheral PS7_DEV_CFG_0 */
  451. #define XPAR_XDCFG_0_DEVICE_ID XPAR_PS7_DEV_CFG_0_DEVICE_ID
  452. #define XPAR_XDCFG_0_BASEADDR 0xF8007000
  453. #define XPAR_XDCFG_0_HIGHADDR 0xF80070FF
  454. /******************************************************************/
  455. /* Definitions for driver DMAPS */
  456. #define XPAR_XDMAPS_NUM_INSTANCES 2
  457. /* Definitions for peripheral PS7_DMA_NS */
  458. #define XPAR_PS7_DMA_NS_DEVICE_ID 0
  459. #define XPAR_PS7_DMA_NS_BASEADDR 0xF8004000
  460. #define XPAR_PS7_DMA_NS_HIGHADDR 0xF8004FFF
  461. /* Definitions for peripheral PS7_DMA_S */
  462. #define XPAR_PS7_DMA_S_DEVICE_ID 1
  463. #define XPAR_PS7_DMA_S_BASEADDR 0xF8003000
  464. #define XPAR_PS7_DMA_S_HIGHADDR 0xF8003FFF
  465. /******************************************************************/
  466. /* Canonical definitions for peripheral PS7_DMA_NS */
  467. #define XPAR_XDMAPS_0_DEVICE_ID XPAR_PS7_DMA_NS_DEVICE_ID
  468. #define XPAR_XDMAPS_0_BASEADDR 0xF8004000
  469. #define XPAR_XDMAPS_0_HIGHADDR 0xF8004FFF
  470. /* Canonical definitions for peripheral PS7_DMA_S */
  471. #define XPAR_XDMAPS_1_DEVICE_ID XPAR_PS7_DMA_S_DEVICE_ID
  472. #define XPAR_XDMAPS_1_BASEADDR 0xF8003000
  473. #define XPAR_XDMAPS_1_HIGHADDR 0xF8003FFF
  474. /******************************************************************/
  475. /* Definitions for driver EMACPS */
  476. #define XPAR_XEMACPS_NUM_INSTANCES 1
  477. /* Definitions for peripheral PS7_ETHERNET_0 */
  478. #define XPAR_PS7_ETHERNET_0_DEVICE_ID 0
  479. #define XPAR_PS7_ETHERNET_0_BASEADDR 0xE000B000
  480. #define XPAR_PS7_ETHERNET_0_HIGHADDR 0xE000BFFF
  481. #define XPAR_PS7_ETHERNET_0_ENET_CLK_FREQ_HZ 125000000
  482. #define XPAR_PS7_ETHERNET_0_ENET_SLCR_1000MBPS_DIV0 1
  483. #define XPAR_PS7_ETHERNET_0_ENET_SLCR_1000MBPS_DIV1 1
  484. #define XPAR_PS7_ETHERNET_0_ENET_SLCR_100MBPS_DIV0 1
  485. #define XPAR_PS7_ETHERNET_0_ENET_SLCR_100MBPS_DIV1 5
  486. #define XPAR_PS7_ETHERNET_0_ENET_SLCR_10MBPS_DIV0 1
  487. #define XPAR_PS7_ETHERNET_0_ENET_SLCR_10MBPS_DIV1 50
  488. /******************************************************************/
  489. /* Canonical definitions for peripheral PS7_ETHERNET_0 */
  490. #define XPAR_XEMACPS_0_DEVICE_ID XPAR_PS7_ETHERNET_0_DEVICE_ID
  491. #define XPAR_XEMACPS_0_BASEADDR 0xE000B000
  492. #define XPAR_XEMACPS_0_HIGHADDR 0xE000BFFF
  493. #define XPAR_XEMACPS_0_ENET_CLK_FREQ_HZ 125000000
  494. #define XPAR_XEMACPS_0_ENET_SLCR_1000Mbps_DIV0 1
  495. #define XPAR_XEMACPS_0_ENET_SLCR_1000Mbps_DIV1 1
  496. #define XPAR_XEMACPS_0_ENET_SLCR_100Mbps_DIV0 1
  497. #define XPAR_XEMACPS_0_ENET_SLCR_100Mbps_DIV1 5
  498. #define XPAR_XEMACPS_0_ENET_SLCR_10Mbps_DIV0 1
  499. #define XPAR_XEMACPS_0_ENET_SLCR_10Mbps_DIV1 50
  500. /******************************************************************/
  501. /* Definitions for driver FANS_CTRL */
  502. #define XPAR_FANS_CTRL_NUM_INSTANCES 1
  503. /* Definitions for peripheral FANS_CTRL_0 */
  504. #define XPAR_FANS_CTRL_0_DEVICE_ID 0
  505. #define XPAR_FANS_CTRL_0_S00_AXI_BASEADDR 0x43C00000
  506. #define XPAR_FANS_CTRL_0_S00_AXI_HIGHADDR 0x43C0FFFF
  507. /******************************************************************/
  508. /* Definitions for peripheral PS7_AFI_0 */
  509. #define XPAR_PS7_AFI_0_S_AXI_BASEADDR 0xF8008000
  510. #define XPAR_PS7_AFI_0_S_AXI_HIGHADDR 0xF8008FFF
  511. /* Definitions for peripheral PS7_AFI_1 */
  512. #define XPAR_PS7_AFI_1_S_AXI_BASEADDR 0xF8009000
  513. #define XPAR_PS7_AFI_1_S_AXI_HIGHADDR 0xF8009FFF
  514. /* Definitions for peripheral PS7_AFI_2 */
  515. #define XPAR_PS7_AFI_2_S_AXI_BASEADDR 0xF800A000
  516. #define XPAR_PS7_AFI_2_S_AXI_HIGHADDR 0xF800AFFF
  517. /* Definitions for peripheral PS7_AFI_3 */
  518. #define XPAR_PS7_AFI_3_S_AXI_BASEADDR 0xF800B000
  519. #define XPAR_PS7_AFI_3_S_AXI_HIGHADDR 0xF800BFFF
  520. /* Definitions for peripheral PS7_DDRC_0 */
  521. #define XPAR_PS7_DDRC_0_S_AXI_BASEADDR 0xF8006000
  522. #define XPAR_PS7_DDRC_0_S_AXI_HIGHADDR 0xF8006FFF
  523. /* Definitions for peripheral PS7_GLOBALTIMER_0 */
  524. #define XPAR_PS7_GLOBALTIMER_0_S_AXI_BASEADDR 0xF8F00200
  525. #define XPAR_PS7_GLOBALTIMER_0_S_AXI_HIGHADDR 0xF8F002FF
  526. /* Definitions for peripheral PS7_GPV_0 */
  527. #define XPAR_PS7_GPV_0_S_AXI_BASEADDR 0xF8900000
  528. #define XPAR_PS7_GPV_0_S_AXI_HIGHADDR 0xF89FFFFF
  529. /* Definitions for peripheral PS7_INTC_DIST_0 */
  530. #define XPAR_PS7_INTC_DIST_0_S_AXI_BASEADDR 0xF8F01000
  531. #define XPAR_PS7_INTC_DIST_0_S_AXI_HIGHADDR 0xF8F01FFF
  532. /* Definitions for peripheral PS7_IOP_BUS_CONFIG_0 */
  533. #define XPAR_PS7_IOP_BUS_CONFIG_0_S_AXI_BASEADDR 0xE0200000
  534. #define XPAR_PS7_IOP_BUS_CONFIG_0_S_AXI_HIGHADDR 0xE0200FFF
  535. /* Definitions for peripheral PS7_L2CACHEC_0 */
  536. #define XPAR_PS7_L2CACHEC_0_S_AXI_BASEADDR 0xF8F02000
  537. #define XPAR_PS7_L2CACHEC_0_S_AXI_HIGHADDR 0xF8F02FFF
  538. /* Definitions for peripheral PS7_OCMC_0 */
  539. #define XPAR_PS7_OCMC_0_S_AXI_BASEADDR 0xF800C000
  540. #define XPAR_PS7_OCMC_0_S_AXI_HIGHADDR 0xF800CFFF
  541. /* Definitions for peripheral PS7_PL310_0 */
  542. #define XPAR_PS7_PL310_0_S_AXI_BASEADDR 0xF8F02000
  543. #define XPAR_PS7_PL310_0_S_AXI_HIGHADDR 0xF8F02FFF
  544. /* Definitions for peripheral PS7_PMU_0 */
  545. #define XPAR_PS7_PMU_0_S_AXI_BASEADDR 0xF8891000
  546. #define XPAR_PS7_PMU_0_S_AXI_HIGHADDR 0xF8891FFF
  547. #define XPAR_PS7_PMU_0_PMU1_S_AXI_BASEADDR 0xF8893000
  548. #define XPAR_PS7_PMU_0_PMU1_S_AXI_HIGHADDR 0xF8893FFF
  549. /* Definitions for peripheral PS7_RAM_0 */
  550. #define XPAR_PS7_RAM_0_S_AXI_BASEADDR 0x00000000
  551. #define XPAR_PS7_RAM_0_S_AXI_HIGHADDR 0x0003FFFF
  552. /* Definitions for peripheral PS7_RAM_1 */
  553. #define XPAR_PS7_RAM_1_S_AXI_BASEADDR 0xFFFC0000
  554. #define XPAR_PS7_RAM_1_S_AXI_HIGHADDR 0xFFFFFFFF
  555. /* Definitions for peripheral PS7_SCUC_0 */
  556. #define XPAR_PS7_SCUC_0_S_AXI_BASEADDR 0xF8F00000
  557. #define XPAR_PS7_SCUC_0_S_AXI_HIGHADDR 0xF8F000FC
  558. /* Definitions for peripheral PS7_SLCR_0 */
  559. #define XPAR_PS7_SLCR_0_S_AXI_BASEADDR 0xF8000000
  560. #define XPAR_PS7_SLCR_0_S_AXI_HIGHADDR 0xF8000FFF
  561. /* Definitions for peripheral PS7_SMCC_0 */
  562. #define XPAR_PS7_SMCC_0_S_AXI_BASEADDR 0xE000E000
  563. #define XPAR_PS7_SMCC_0_S_AXI_HIGHADDR 0xE100EFFF
  564. /******************************************************************/
  565. /* Definitions for driver GPIOPS */
  566. #define XPAR_XGPIOPS_NUM_INSTANCES 1
  567. /* Definitions for peripheral PS7_GPIO_0 */
  568. #define XPAR_PS7_GPIO_0_DEVICE_ID 0
  569. #define XPAR_PS7_GPIO_0_BASEADDR 0xE000A000
  570. #define XPAR_PS7_GPIO_0_HIGHADDR 0xE000AFFF
  571. /******************************************************************/
  572. /* Canonical definitions for peripheral PS7_GPIO_0 */
  573. #define XPAR_XGPIOPS_0_DEVICE_ID XPAR_PS7_GPIO_0_DEVICE_ID
  574. #define XPAR_XGPIOPS_0_BASEADDR 0xE000A000
  575. #define XPAR_XGPIOPS_0_HIGHADDR 0xE000AFFF
  576. /******************************************************************/
  577. /* Definitions for driver MCOMPAT_SPI_WRAPPER */
  578. #define XPAR_MCOMPAT_SPI_WRAPPER_NUM_INSTANCES 1
  579. /* Definitions for peripheral MCOMPAT_SPI_WRAPPER_0 */
  580. #define XPAR_MCOMPAT_SPI_WRAPPER_0_DEVICE_ID 0
  581. #define XPAR_MCOMPAT_SPI_WRAPPER_0_S00_AXI_BASEADDR 0x43C30000
  582. #define XPAR_MCOMPAT_SPI_WRAPPER_0_S00_AXI_HIGHADDR 0x43C3FFFF
  583. /******************************************************************/
  584. /* Definitions for driver NANDPS */
  585. #define XPAR_XNANDPS_NUM_INSTANCES 1
  586. /* Definitions for peripheral PS7_NAND_0 */
  587. #define XPAR_PS7_NAND_0_DEVICE_ID 0
  588. #define XPAR_PS7_NAND_0_BASEADDR 0xE1000000
  589. #define XPAR_PS7_NAND_0_HIGHADDR 0xE1000FFF
  590. #define XPAR_PS7_NAND_0_NAND_CLK_FREQ_HZ 100000000
  591. #define XPAR_PS7_NAND_0_SMC_BASEADDR 0xE000E000
  592. #define XPAR_PS7_NAND_0_NAND_WIDTH 8
  593. /******************************************************************/
  594. /* Canonical definitions for peripheral PS7_NAND_0 */
  595. #define XPAR_XNANDPS_0_DEVICE_ID XPAR_PS7_NAND_0_DEVICE_ID
  596. #define XPAR_XNANDPS_0_CPU_BASEADDR 0xE1000000
  597. #define XPAR_XNANDPS_0_CPU_HIGHADDR 0xE1000FFF
  598. #define XPAR_XNANDPS_0_NAND_CLK_FREQ_HZ 100000000
  599. #define XPAR_XNANDPS_0_SMC_BASEADDR 0xE000E000
  600. #define XPAR_XNANDPS_0_NAND_WIDTH 8
  601. /******************************************************************/
  602. /* Definitions for driver READ_DNA */
  603. #define XPAR_READ_DNA_NUM_INSTANCES 1
  604. /* Definitions for peripheral READ_DNA_0 */
  605. #define XPAR_READ_DNA_0_DEVICE_ID 0
  606. #define XPAR_READ_DNA_0_S00_AXI_BASEADDR 0x43C20000
  607. #define XPAR_READ_DNA_0_S00_AXI_HIGHADDR 0x43C2FFFF
  608. /******************************************************************/
  609. /* Definitions for driver SCUGIC */
  610. #define XPAR_XSCUGIC_NUM_INSTANCES 1U
  611. /* Definitions for peripheral PS7_SCUGIC_0 */
  612. #define XPAR_PS7_SCUGIC_0_DEVICE_ID 0U
  613. #define XPAR_PS7_SCUGIC_0_BASEADDR 0xF8F00100U
  614. #define XPAR_PS7_SCUGIC_0_HIGHADDR 0xF8F001FFU
  615. #define XPAR_PS7_SCUGIC_0_DIST_BASEADDR 0xF8F01000U
  616. /******************************************************************/
  617. /* Canonical definitions for peripheral PS7_SCUGIC_0 */
  618. #define XPAR_SCUGIC_0_DEVICE_ID 0U
  619. #define XPAR_SCUGIC_0_CPU_BASEADDR 0xF8F00100U
  620. #define XPAR_SCUGIC_0_CPU_HIGHADDR 0xF8F001FFU
  621. #define XPAR_SCUGIC_0_DIST_BASEADDR 0xF8F01000U
  622. /******************************************************************/
  623. /* Definitions for driver SCUTIMER */
  624. #define XPAR_XSCUTIMER_NUM_INSTANCES 1
  625. /* Definitions for peripheral PS7_SCUTIMER_0 */
  626. #define XPAR_PS7_SCUTIMER_0_DEVICE_ID 0
  627. #define XPAR_PS7_SCUTIMER_0_BASEADDR 0xF8F00600
  628. #define XPAR_PS7_SCUTIMER_0_HIGHADDR 0xF8F0061F
  629. /******************************************************************/
  630. /* Canonical definitions for peripheral PS7_SCUTIMER_0 */
  631. #define XPAR_XSCUTIMER_0_DEVICE_ID XPAR_PS7_SCUTIMER_0_DEVICE_ID
  632. #define XPAR_XSCUTIMER_0_BASEADDR 0xF8F00600
  633. #define XPAR_XSCUTIMER_0_HIGHADDR 0xF8F0061F
  634. /******************************************************************/
  635. /* Definitions for driver SCUWDT */
  636. #define XPAR_XSCUWDT_NUM_INSTANCES 1
  637. /* Definitions for peripheral PS7_SCUWDT_0 */
  638. #define XPAR_PS7_SCUWDT_0_DEVICE_ID 0
  639. #define XPAR_PS7_SCUWDT_0_BASEADDR 0xF8F00620
  640. #define XPAR_PS7_SCUWDT_0_HIGHADDR 0xF8F006FF
  641. /******************************************************************/
  642. /* Canonical definitions for peripheral PS7_SCUWDT_0 */
  643. #define XPAR_SCUWDT_0_DEVICE_ID XPAR_PS7_SCUWDT_0_DEVICE_ID
  644. #define XPAR_SCUWDT_0_BASEADDR 0xF8F00620
  645. #define XPAR_SCUWDT_0_HIGHADDR 0xF8F006FF
  646. /******************************************************************/
  647. /* Definitions for driver SDPS */
  648. #define XPAR_XSDPS_NUM_INSTANCES 1
  649. /* Definitions for peripheral PS7_SD_0 */
  650. #define XPAR_PS7_SD_0_DEVICE_ID 0
  651. #define XPAR_PS7_SD_0_BASEADDR 0xE0100000
  652. #define XPAR_PS7_SD_0_HIGHADDR 0xE0100FFF
  653. #define XPAR_PS7_SD_0_SDIO_CLK_FREQ_HZ 100000000
  654. #define XPAR_PS7_SD_0_HAS_CD 0
  655. #define XPAR_PS7_SD_0_HAS_WP 0
  656. #define XPAR_PS7_SD_0_BUS_WIDTH 0
  657. #define XPAR_PS7_SD_0_MIO_BANK 0
  658. #define XPAR_PS7_SD_0_HAS_EMIO 0
  659. /******************************************************************/
  660. /* Canonical definitions for peripheral PS7_SD_0 */
  661. #define XPAR_XSDPS_0_DEVICE_ID XPAR_PS7_SD_0_DEVICE_ID
  662. #define XPAR_XSDPS_0_BASEADDR 0xE0100000
  663. #define XPAR_XSDPS_0_HIGHADDR 0xE0100FFF
  664. #define XPAR_XSDPS_0_SDIO_CLK_FREQ_HZ 100000000
  665. #define XPAR_XSDPS_0_HAS_CD 0
  666. #define XPAR_XSDPS_0_HAS_WP 0
  667. #define XPAR_XSDPS_0_BUS_WIDTH 0
  668. #define XPAR_XSDPS_0_MIO_BANK 0
  669. #define XPAR_XSDPS_0_HAS_EMIO 0
  670. /******************************************************************/
  671. /* Definitions for driver UARTPS */
  672. #define XPAR_XUARTPS_NUM_INSTANCES 1
  673. /* Definitions for peripheral PS7_UART_1 */
  674. #define XPAR_PS7_UART_1_DEVICE_ID 0
  675. #define XPAR_PS7_UART_1_BASEADDR 0xE0001000
  676. #define XPAR_PS7_UART_1_HIGHADDR 0xE0001FFF
  677. #define XPAR_PS7_UART_1_UART_CLK_FREQ_HZ 100000000
  678. #define XPAR_PS7_UART_1_HAS_MODEM 0
  679. /******************************************************************/
  680. /* Canonical definitions for peripheral PS7_UART_1 */
  681. #define XPAR_XUARTPS_0_DEVICE_ID XPAR_PS7_UART_1_DEVICE_ID
  682. #define XPAR_XUARTPS_0_BASEADDR 0xE0001000
  683. #define XPAR_XUARTPS_0_HIGHADDR 0xE0001FFF
  684. #define XPAR_XUARTPS_0_UART_CLK_FREQ_HZ 100000000
  685. #define XPAR_XUARTPS_0_HAS_MODEM 0
  686. /******************************************************************/
  687. /* Definitions for driver USBPS */
  688. #define XPAR_XUSBPS_NUM_INSTANCES 1
  689. /* Definitions for peripheral PS7_USB_0 */
  690. #define XPAR_PS7_USB_0_DEVICE_ID 0
  691. #define XPAR_PS7_USB_0_BASEADDR 0xE0002000
  692. #define XPAR_PS7_USB_0_HIGHADDR 0xE0002FFF
  693. /******************************************************************/
  694. /* Canonical definitions for peripheral PS7_USB_0 */
  695. #define XPAR_XUSBPS_0_DEVICE_ID XPAR_PS7_USB_0_DEVICE_ID
  696. #define XPAR_XUSBPS_0_BASEADDR 0xE0002000
  697. #define XPAR_XUSBPS_0_HIGHADDR 0xE0002FFF
  698. /******************************************************************/
  699. /* Definitions for driver VID_LED_BUZZER_CTRL */
  700. #define XPAR_VID_LED_BUZZER_CTRL_NUM_INSTANCES 1
  701. /* Definitions for peripheral VID_LED_BUZZER_CTRL_0 */
  702. #define XPAR_VID_LED_BUZZER_CTRL_0_DEVICE_ID 0
  703. #define XPAR_VID_LED_BUZZER_CTRL_0_S00_AXI_BASEADDR 0x43C10000
  704. #define XPAR_VID_LED_BUZZER_CTRL_0_S00_AXI_HIGHADDR 0x43C1FFFF
  705. /******************************************************************/
  706. /* Definitions for driver XADCPS */
  707. #define XPAR_XADCPS_NUM_INSTANCES 1
  708. /* Definitions for peripheral PS7_XADC_0 */
  709. #define XPAR_PS7_XADC_0_DEVICE_ID 0
  710. #define XPAR_PS7_XADC_0_BASEADDR 0xF8007100
  711. #define XPAR_PS7_XADC_0_HIGHADDR 0xF8007120
  712. /******************************************************************/
  713. /* Canonical definitions for peripheral PS7_XADC_0 */
  714. #define XPAR_XADCPS_0_DEVICE_ID XPAR_PS7_XADC_0_DEVICE_ID
  715. #define XPAR_XADCPS_0_BASEADDR 0xF8007100
  716. #define XPAR_XADCPS_0_HIGHADDR 0xF8007120
  717. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG0_OFFSET 0
  718. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG1_OFFSET 4
  719. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG2_OFFSET 8
  720. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG3_OFFSET 12
  721. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG4_OFFSET 16
  722. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG5_OFFSET 20
  723. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG6_OFFSET 24
  724. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG7_OFFSET 28
  725. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG8_OFFSET 32
  726. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG9_OFFSET 36
  727. #define VID_LED_BUZZER_CTRL_S00_AXI_SLV_REG10_OFFSET 40
  728. #define FANS_CTRL_S00_AXI_SLV_REG0_OFFSET 0
  729. #define FANS_CTRL_S00_AXI_SLV_REG1_OFFSET 4
  730. #define FANS_CTRL_S00_AXI_SLV_REG2_OFFSET 8
  731. #define FANS_CTRL_S00_AXI_SLV_REG3_OFFSET 12
  732. #define FANS_CTRL_S00_AXI_SLV_REG4_OFFSET 16
  733. #define FANS_CTRL_S00_AXI_SLV_REG5_OFFSET 20
  734. #define FANS_CTRL_S00_AXI_SLV_REG6_OFFSET 24
  735. #define FANS_CTRL_S00_AXI_SLV_REG7_OFFSET 28
  736. #define FANS_CTRL_S00_AXI_SLV_REG8_OFFSET 32
  737. #define FANS_CTRL_S00_AXI_SLV_REG9_OFFSET 36
  738. #define FANS_CTRL_S00_AXI_SLV_REG10_OFFSET 40
  739. #define FANS_CTRL_S00_AXI_SLV_REG11_OFFSET 44
  740. #define AUTO_CMD0A_REG0_ADDR 0x0160
  741. #define AUTO_CMD0A_REG1_ADDR 0x0164
  742. #define AUTO_CMD0A_REG2_ADDR 0x0168
  743. #define AUTO_CMD0A_REG3_ADDR 0x016c
  744. #define AUTO_CMD0A_REG4_ADDR 0x0170
  745. #define AUTO_CMD0A_REG5_ADDR 0x0174
  746. #define AUTO_CMD0A_REG6_ADDR 0x0178
  747. #define AUTO_CMD0A_REG7_ADDR 0x017c
  748. #define LED_ON 0
  749. #define LED_OFF 1
  750. #define LED_BLING_ON 2
  751. #define LED_BLING_OFF 3
  752. #define SPI_RESET_REG 0x1200
  753. #define SPI_BASEADDR_GAP 0x200
  754. #define SPI_AXIBASE 0x43C30000
  755. #define XST_SUCCESS 0L
  756. #define XST_FAILURE 1L
  757. #define XST_DEVICE_NOT_FOUND 2L
  758. #define XST_DEVICE_BLOCK_NOT_FOUND 3L
  759. #define XST_INVALID_VERSION 4L
  760. #define XST_DEVICE_IS_STARTED 5L
  761. #define XST_DEVICE_IS_STOPPED 6L
  762. #define XST_FIFO_ERROR 7L
  763. #define XST_CRC_ERROR 8L
  764. #define MAIN_CFG_REG0_ADDR 0x00
  765. #define MAIN_CFG_REG1_ADDR 0x04
  766. #define MAIN_CFG_REG2_ADDR 0x08
  767. #define MAIN_CFG_REG3_ADDR 0x0c
  768. #define CMD_CTRL_REG0_ADDR 0x10
  769. #define CMD_CTRL_REG1_ADDR 0x14
  770. #define CMD_CTRL_REG2_ADDR 0x18
  771. #define CMD_CTRL_REG3_ADDR 0x1c
  772. #define CMD_READ_REG0_ADDR 0x20
  773. #define CMD_READ_REG1_ADDR 0x24
  774. #define CMD_READ_REG2_ADDR 0x28
  775. #define CMD_READ_REG3_ADDR 0x2c
  776. #define CMD_READ_REG4_ADDR 0x30
  777. #define CMD_READ_REG5_ADDR 0x34
  778. #define CMD_READ_REG6_ADDR 0x38
  779. #define CMD_READ_REG7_ADDR 0x3c
  780. #define CMD_READ_REG8_ADDR 0x40
  781. #define CMD_READ_REG9_ADDR 0x44
  782. #define CMD_READ_REGA_ADDR 0x48
  783. #define CMD_READ_REGB_ADDR 0x4c
  784. #define CMD_READ_REGC_ADDR 0x50
  785. #define CMD_READ_REGD_ADDR 0x54
  786. #define CMD_READ_REGE_ADDR 0x58
  787. #define CMD_READ_REGF_ADDR 0x5c
  788. #define CMD_WRITE_HEAD_ADDR 0x60
  789. #define CMD_WRITE_REG01_ADDR 0x64
  790. #define CMD_WRITE_REG02_ADDR 0x68
  791. #define CMD_WRITE_REG03_ADDR 0x6c
  792. #define CMD_WRITE_REG04_ADDR 0x70
  793. #define CMD_WRITE_REG05_ADDR 0x74
  794. #define CMD_WRITE_REG06_ADDR 0x78
  795. #define CMD_WRITE_REG07_ADDR 0x7c
  796. #define CMD_WRITE_REG08_ADDR 0x80
  797. #define CMD_WRITE_REG09_ADDR 0x84
  798. #define CMD_WRITE_REG0A_ADDR 0x88
  799. #define CMD_WRITE_REG0B_ADDR 0x8c
  800. #define CMD_WRITE_REG0C_ADDR 0x90
  801. #define CMD_WRITE_REG0D_ADDR 0x94
  802. #define CMD_WRITE_REG0E_ADDR 0x98
  803. #define CMD_WRITE_REG0F_ADDR 0x9c
  804. #define CMD_WRITE_REG10_ADDR 0xa0
  805. #define CMD_WRITE_REG11_ADDR 0xa4
  806. #define CMD_WRITE_REG12_ADDR 0xa8
  807. #define CMD_WRITE_REG13_ADDR 0xac
  808. #define CMD_WRITE_REG14_ADDR 0xb0
  809. #define CMD_WRITE_REG15_ADDR 0xb4
  810. #define CMD_WRITE_REG16_ADDR 0xb8
  811. #define CMD_WRITE_REG17_ADDR 0xbc
  812. #define CMD_WRITE_REG18_ADDR 0xc0
  813. #define CMD_WRITE_REG19_ADDR 0xc4
  814. #define CMD_WRITE_REG1A_ADDR 0xc8
  815. #define CMD_WRITE_REG1B_ADDR 0xcc
  816. #define CMD_WRITE_REG1C_ADDR 0xd0
  817. #define CMD_WRITE_REG1D_ADDR 0xd4
  818. #define CMD_WRITE_REG1E_ADDR 0xd8
  819. #define CMD_WRITE_REG1F_ADDR 0xdc
  820. #define CMD_WRITE_REG20_ADDR 0xe0
  821. #define CMD_WRITE_REG21_ADDR 0xe4
  822. #define CMD_WRITE_REG22_ADDR 0xe8
  823. #define CMD_WRITE_REG23_ADDR 0xec
  824. #define CMD_WRITE_REG24_ADDR 0xf0
  825. #define CMD_WRITE_REG25_ADDR 0xf4
  826. #define CMD_WRITE_REG26_ADDR 0xf8
  827. #define CMD_WRITE_REG27_ADDR 0xfc
  828. #define SPI_BUFFER_SIZE 170
  829. #define SPI_TX_BUF_SIZE (((CMD_WRITE_REG27_ADDR-CMD_WRITE_HEAD_ADDR) / 4) + 1) * 2
  830. #define SPI_RX_BUF_SIZE (((CMD_READ_REGF_ADDR-CMD_READ_REG0_ADDR) / 4) + 1) * 2
  831. #define CHK_HY 0x00000080
  832. #define CHK_H1 0x00000040
  833. #define CHK_LN 0x00000020
  834. #define CHK_CMD 0x00000004
  835. #define CHK_ID 0x00000008
  836. #define SPI_BYPASS_EN 0x00001000
  837. #define SPI_BYPASS_END 0x00002000
  838. #define REORDER16(arg) ((uint16_t)(arg<<8 | arg>>8))
  839. #define SYSTEM_LINUX
  840. void hub_init(void);
  841. void hub_deinit(void);
  842. int Xil_SPI_In32(uint32_t phyaddr);
  843. void Xil_SPI_Out32(uint32_t phyaddr, uint32_t val);
  844. extern bool rece_queue_has_nonce(uint8_t spi_id, uint32_t timeout_us);
  845. extern void read_nonce_buffer(uint8_t spi_id, uint8_t* buf8, uint32_t len_cfg);
  846. extern int send_job_queue(uint8_t spi_id, uint8_t* tx_buf8, uint8_t* rx_buf8, uint32_t len_cfg, uint32_t last_job);
  847. extern int do_spi_cmd(uint8_t spi_id, uint8_t* tx_buf8, uint8_t* rx_buf8, uint32_t len_cfg);
  848. int hub_spi_init(uint8_t spi_id, uint8_t chip_num);
  849. void hub_spi_reset(uint8_t spi_id);
  850. void hub_spi_clean_chain(uint32_t spi_id);
  851. void hub_set_spi_speed(uint8_t spi_id, int select);
  852. void hub_set_power_en(uint8_t chain_id, int value);
  853. void hub_set_start_en(uint8_t chain_id, int value);
  854. bool hub_set_reset(uint8_t chain_id, int value);
  855. void hub_set_led(uint8_t chain_id, int mode);
  856. bool hub_set_vid(uint8_t chain_id, int vid);
  857. void hub_set_vid_vid(uint8_t chain_id, int vid);
  858. void hub_set_vid_uart_select(uint8_t spi_id);
  859. void hub_set_pwm(uint8_t fan_id, int frequency, int duty);
  860. int hub_get_plug(uint8_t chain_id);
  861. void hub_set_green_led(int mode);
  862. void hub_set_red_led(int mode);
  863. int hub_get_button(void);
  864. int enable_auto_nonce(uint8_t chain_id, uint16_t cmd08_cmd, uint32_t len_cfg);
  865. int disable_auto_nonce(uint8_t chain_id);
  866. void enable_auto_cmd0a(uint8_t spi_id, uint32_t threshold, uint32_t msb, uint32_t lsb, uint32_t large_en, uint32_t mode );//mode : 1 only cmd0a;0 cmd08 follows cmd0a
  867. void disable_auto_cmd0a(uint8_t spi_id, uint32_t threshold, uint32_t msb, uint32_t lsb, uint32_t large_en, uint32_t mode );//mode : 1 only cmd0a;0 cmd08 follows cmd0a
  868. void init_hub_gpio(void);
  869. //#define XPAR_MCOMPAT_PERIPHERAL_0_S00_AXI_BASEADDR 0x43C00000
  870. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG0_OFFSET 0
  871. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG1_OFFSET 4
  872. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG2_OFFSET 8
  873. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG3_OFFSET 12
  874. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG4_OFFSET 16
  875. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG5_OFFSET 20
  876. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG6_OFFSET 24
  877. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG7_OFFSET 28
  878. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG8_OFFSET 32
  879. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG9_OFFSET 36
  880. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG10_OFFSET 40
  881. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG11_OFFSET 44
  882. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG12_OFFSET 48
  883. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG13_OFFSET 52
  884. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG14_OFFSET 56
  885. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG15_OFFSET 60
  886. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG16_OFFSET 64
  887. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG17_OFFSET 68
  888. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG18_OFFSET 72
  889. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG19_OFFSET 76
  890. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG20_OFFSET 80
  891. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG21_OFFSET 84
  892. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG22_OFFSET 88
  893. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG23_OFFSET 92
  894. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG24_OFFSET 96
  895. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG25_OFFSET 100
  896. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG26_OFFSET 104
  897. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG27_OFFSET 108
  898. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG28_OFFSET 112
  899. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG29_OFFSET 116
  900. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG30_OFFSET 120
  901. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG31_OFFSET 124
  902. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG32_OFFSET 128
  903. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG33_OFFSET 132
  904. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG34_OFFSET 136
  905. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG35_OFFSET 140
  906. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG36_OFFSET 144
  907. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG37_OFFSET 148
  908. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG38_OFFSET 152
  909. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG39_OFFSET 156
  910. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG40_OFFSET 160
  911. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG41_OFFSET 164
  912. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG42_OFFSET 168
  913. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG43_OFFSET 172
  914. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG44_OFFSET 176
  915. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG45_OFFSET 180
  916. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG46_OFFSET 184
  917. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG47_OFFSET 188
  918. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG48_OFFSET 192
  919. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG49_OFFSET 196
  920. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG50_OFFSET 200
  921. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG51_OFFSET 204
  922. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG52_OFFSET 208
  923. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG53_OFFSET 212
  924. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG54_OFFSET 216
  925. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG55_OFFSET 220
  926. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG56_OFFSET 224
  927. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG57_OFFSET 228
  928. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG58_OFFSET 232
  929. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG59_OFFSET 236
  930. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG60_OFFSET 240
  931. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG61_OFFSET 244
  932. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG62_OFFSET 248
  933. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG63_OFFSET 252
  934. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG64_OFFSET 256
  935. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG65_OFFSET 260
  936. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG66_OFFSET 264
  937. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG67_OFFSET 268
  938. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG68_OFFSET 272
  939. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG69_OFFSET 276
  940. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG70_OFFSET 280
  941. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG71_OFFSET 284
  942. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG72_OFFSET 288
  943. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG73_OFFSET 292
  944. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG74_OFFSET 296
  945. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG75_OFFSET 300
  946. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG76_OFFSET 304
  947. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG77_OFFSET 308
  948. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG78_OFFSET 312
  949. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG79_OFFSET 316
  950. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG80_OFFSET 320
  951. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG81_OFFSET 324
  952. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG82_OFFSET 328
  953. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG83_OFFSET 332
  954. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG84_OFFSET 336
  955. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG85_OFFSET 340
  956. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG86_OFFSET 344
  957. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG87_OFFSET 348
  958. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG88_OFFSET 352
  959. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG89_OFFSET 356
  960. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG90_OFFSET 360
  961. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG91_OFFSET 364
  962. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG92_OFFSET 368
  963. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG93_OFFSET 372
  964. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG94_OFFSET 376
  965. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG95_OFFSET 380
  966. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG96_OFFSET 384
  967. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG97_OFFSET 388
  968. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG98_OFFSET 392
  969. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG99_OFFSET 396
  970. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG100_OFFSET 400
  971. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG101_OFFSET 404
  972. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG102_OFFSET 408
  973. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG103_OFFSET 412
  974. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG104_OFFSET 416
  975. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG105_OFFSET 420
  976. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG106_OFFSET 424
  977. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG107_OFFSET 428
  978. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG108_OFFSET 432
  979. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG109_OFFSET 436
  980. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG110_OFFSET 440
  981. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG111_OFFSET 444
  982. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG112_OFFSET 448
  983. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG113_OFFSET 452
  984. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG114_OFFSET 456
  985. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG115_OFFSET 460
  986. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG116_OFFSET 464
  987. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG117_OFFSET 468
  988. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG118_OFFSET 472
  989. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG119_OFFSET 476
  990. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG120_OFFSET 480
  991. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG121_OFFSET 484
  992. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG122_OFFSET 488
  993. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG123_OFFSET 492
  994. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG124_OFFSET 496
  995. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG125_OFFSET 500
  996. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG126_OFFSET 504
  997. #define MCOMPAT_PERIPHERAL_S00_AXI_SLV_REG127_OFFSET 508
  998. /* DRV_OPI */
  999. #define AX_CMD_SYNC_HEAD 0xA55A
  1000. #define CUSTOM_SYNC_HEAD 0x6996
  1001. #define OPI_SPI_TIMEOUT 100
  1002. #define OPI_STATUS_SUC 0
  1003. #define OPI_STATUS_EOR 1
  1004. #define OPI_SET_POWER_EN (0x11)
  1005. #define OPI_SET_STARR_EN (0x12)
  1006. #define OPI_SET_RESET (0x13)
  1007. #define OPI_SET_LED (0x14)
  1008. #define OPI_GET_PLUG (0x15)
  1009. #define OPI_SET_VID (0x16)
  1010. #define OPI_SET_PWM (0x17)
  1011. #define OPI_SET_SPI_SPEED (0x18)
  1012. #define OPI_POWER_ON (0x21)
  1013. #define OPI_POWER_DOWN (0x22)
  1014. #define OPI_POWER_RESET (0x23)
  1015. #define OPI_HI_BYTE(a) ((uint8_t)(((a) >> 8) & 0xff))
  1016. #define OPI_LO_BYTE(a) ((uint8_t)(((a) >> 0) & 0xff))
  1017. #define OPI_MAKE_WORD(a, b) (uint16_t)((((a) & 0xff) << 8) | (( (a) & 0xff) << 0))
  1018. bool opi_spi_read_write(uint8_t chain_id, uint8_t *txbuf, uint8_t *rxbuf, int len);
  1019. bool opi_send_command(uint8_t chain_id, uint8_t cmd, uint8_t chip_id, uint8_t *buff, int len);
  1020. bool opi_poll_result(uint8_t chain_id, uint8_t cmd, uint8_t chip_id, uint8_t *buff, int len);
  1021. void opi_set_power_en(unsigned char chain_id, int val);
  1022. void opi_set_start_en(unsigned char chain_id, int val);
  1023. bool opi_set_reset(unsigned char chain_id, int val);
  1024. void opi_set_led(unsigned char chain_id, int val);
  1025. int opi_get_plug(unsigned char chain_id);
  1026. bool opi_set_vid(unsigned char chain_id, int vid);
  1027. void opi_set_pwm(unsigned char fan_id, int frequency, int duty);
  1028. bool opi_chain_power_on(unsigned char chain_id);
  1029. bool opi_chain_power_down(unsigned char chain_id);
  1030. bool opi_chain_hw_reset(unsigned char chain_id);
  1031. bool opi_chain_power_on_all(void);
  1032. bool opi_chain_power_down_all(void);
  1033. void opi_set_spi_speed(unsigned char chain_id, int index);
  1034. /* DRV_SPI */
  1035. void spi_send_data(ZYNQ_SPI_T *spi, unsigned char *buf, int len);
  1036. void spi_recv_data(ZYNQ_SPI_T *spi, unsigned char *buf, int len);
  1037. void spi_send_data_in_word(ZYNQ_SPI_T *spi, unsigned char *buf, int len);
  1038. void spi_recv_data_in_word(ZYNQ_SPI_T *spi, unsigned char *buf, int len);
  1039. bool spi_send_command(ZYNQ_SPI_T *spi, unsigned char cmd, unsigned char chip_id, unsigned char *buff, int len);
  1040. bool spi_poll_result(ZYNQ_SPI_T *spi, unsigned char cmd, unsigned char chip_id, unsigned char *buff, int len);
  1041. void init_spi_gpio(int chain_num);
  1042. void exit_spi_gpio(int chain_num);
  1043. void spi_set_power_en(unsigned char chain_id, int val);
  1044. void spi_set_start_en(unsigned char chain_id, int val);
  1045. bool spi_set_reset(unsigned char chain_id, int val);
  1046. void spi_set_led(unsigned char chain_id, int val);
  1047. bool spi_set_vid(unsigned char chain_id, int vid);
  1048. int spi_get_plug(unsigned char chain_id);
  1049. void spi_set_spi_speed(unsigned char chain_id, int index);
  1050. /* DRV_ZYNQ */
  1051. bool zynq_chain_power_on(unsigned char chain_id);
  1052. bool zynq_chain_power_down(unsigned char chain_id);
  1053. bool zynq_chain_hw_reset(unsigned char chain_id);
  1054. bool zynq_chain_power_on_all(void);
  1055. bool zynq_chain_power_down_all(void);
  1056. /* HUB_CMD */
  1057. bool init_hub_cmd(int chain_num, int chip_num);
  1058. bool exit_hub_cmd(int chain_num);
  1059. bool hub_cmd_reset(unsigned char chain_id, unsigned char chip_id, unsigned char *in, unsigned char *out);
  1060. int hub_cmd_bist_start(unsigned char chain_id, unsigned char chip_id);
  1061. bool hub_cmd_bist_collect(unsigned char chain_id, unsigned char chip_id);
  1062. bool hub_cmd_bist_fix(unsigned char chain_id, unsigned char chip_id);
  1063. bool hub_cmd_write_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  1064. bool hub_cmd_read_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  1065. bool hub_cmd_read_write_reg0d(unsigned char chain_id, unsigned char chip_id, unsigned char *in, int len, unsigned char *out);
  1066. bool hub_cmd_read_result(unsigned char chain_id, unsigned char chip_id, unsigned char *res, int len);
  1067. bool hub_cmd_write_job(unsigned char chain_id, unsigned char chip_id, unsigned char *job, int len);
  1068. bool hub_cmd_auto_nonce(unsigned char chain_id, int mode, int len);
  1069. bool hub_cmd_read_nonce(unsigned char chain_id, unsigned char *res, int len);
  1070. //bool hub_cmd_get_temp(mcompat_fan_temp_s *fan_temp_ctrl);
  1071. bool hub_get_chain_temp(unsigned char chain_id, short tmp_hi, short tmp_lo, short tmp_avg);
  1072. /* OPI_CMD */
  1073. bool init_opi_cmd(void);
  1074. bool exit_opi_cmd(void);
  1075. bool opi_cmd_reset(unsigned char chain_id, unsigned char chip_id, unsigned char *in, unsigned char *out);
  1076. int opi_cmd_bist_start(unsigned char chain_id, unsigned char chip_id);
  1077. bool opi_cmd_bist_collect(unsigned char chain_id, unsigned char chip_id);
  1078. bool opi_cmd_bist_fix(unsigned char chain_id, unsigned char chip_id);
  1079. bool opi_cmd_write_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  1080. bool opi_cmd_read_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  1081. bool opi_cmd_read_write_reg0d(unsigned char chain_id, unsigned char chip_id, unsigned char *in, int len, unsigned char *out);
  1082. bool opi_cmd_read_result(unsigned char chain_id, unsigned char chip_id, unsigned char *res, int len);
  1083. bool opi_cmd_write_job(unsigned char chain_id, unsigned char chip_id, unsigned char *job, int len);
  1084. /* SPI_CMD */
  1085. bool init_spi_cmd(int chain_num);
  1086. bool exit_spi_cmd(int chain_num);
  1087. bool spi_cmd_reset(unsigned char chain_id, unsigned char chip_id, unsigned char *in, unsigned char *out);
  1088. int spi_cmd_bist_start(unsigned char chain_id, unsigned char chip_id);
  1089. bool spi_cmd_bist_collect(unsigned char chain_id, unsigned char chip_id);
  1090. bool spi_cmd_bist_fix(unsigned char chain_id, unsigned char chip_id);
  1091. bool spi_cmd_write_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  1092. bool spi_cmd_read_register(unsigned char chain_id, unsigned char chip_id, unsigned char *reg, int len);
  1093. bool spi_cmd_read_write_reg0d(unsigned char chain_id, unsigned char chip_id, unsigned char *in, int len, unsigned char *out);
  1094. bool spi_cmd_read_result(unsigned char chain_id, unsigned char chip_id, unsigned char *res, int len);
  1095. bool spi_cmd_write_job(unsigned char chain_id, unsigned char chip_id, unsigned char *job, int len);
  1096. /* UTIL */
  1097. unsigned short CRC16_2(unsigned char* pchMsg, unsigned short wDataLen);
  1098. /* OPI_H3 */
  1099. #define SW_PORTC_IO_BASE 0x01c20800
  1100. #define GPIO_BANK(pin) ((pin) >> 5)
  1101. #define GPIO_CFG_INDEX(pin) (((pin) & 0x1F) >> 3)
  1102. #define GPIO_CFG_OFFSET(pin) ((((pin) & 0x1F) & 0x7) << 2)
  1103. #define GPIO_NUM(pin) ((pin) & 0x1F)
  1104. #define GPIO_PUL_INDEX(pin) (((pin) & 0x1F )>> 4)
  1105. #define GPIO_PUL_OFFSET(pin) (((pin) & 0x0F) << 1)
  1106. struct sunxi_gpio {
  1107. unsigned int cfg[4];
  1108. unsigned int dat;
  1109. unsigned int drv[2];
  1110. unsigned int pull[2];
  1111. };
  1112. struct sunxi_gpio_int {
  1113. unsigned int cfg[3];
  1114. unsigned int ctl;
  1115. unsigned int sta;
  1116. unsigned int deb;
  1117. };
  1118. struct sunxi_gpio_reg {
  1119. struct sunxi_gpio gpio_bank[9];
  1120. unsigned char res[0xbc];
  1121. struct sunxi_gpio_int gpio_int;
  1122. };
  1123. typedef struct
  1124. {
  1125. uint8_t mode;
  1126. uint8_t bits;
  1127. uint32_t speed;
  1128. uint16_t delay;
  1129. } spi_config_t;
  1130. #define PA12 12
  1131. #define PA11 11
  1132. #define PA6 6
  1133. #define PA0 0
  1134. #define PA1 1
  1135. #define PA3 3
  1136. #define PC0 64
  1137. #define PC1 65
  1138. #define PC2 66
  1139. #define PA19 19
  1140. #define PA7 7
  1141. #define PA8 8
  1142. #define PA9 9
  1143. #define PA10 10
  1144. #define PA20 20
  1145. #define PA13 13
  1146. #define PA14 14
  1147. #define PD14 110
  1148. #define PC4 68
  1149. #define PC7 71
  1150. #define PA2 2
  1151. #define PC3 67
  1152. #define PA21 21
  1153. #define PA18 18
  1154. #define PG8 200
  1155. #define PG9 201
  1156. #define PG6 198
  1157. #define PG7 199
  1158. #define PA15 15
  1159. #define PL10 362
  1160. #define PL3 355
  1161. #define _3 12
  1162. #define _5 11
  1163. #define _7 6
  1164. #define _8 13
  1165. #define _10 14
  1166. #define _11 0
  1167. #define _12 110
  1168. #define _13 1
  1169. #define _15 3
  1170. #define _16 68
  1171. #define _18 71
  1172. #define _19 64
  1173. #define _21 65
  1174. #define _22 2
  1175. #define _23 66
  1176. #define _24 67
  1177. #define _26 21
  1178. #define _27 19
  1179. #define _28 18
  1180. #define _29 7
  1181. #define _31 8
  1182. #define _32 200
  1183. #define _33 9
  1184. #define _35 10
  1185. #define _36 201
  1186. #define _37 20
  1187. #define _38 198
  1188. #define _40 199
  1189. #define STATUS_LED 15
  1190. #define POWER_LED 362
  1191. #define POWER_KEY 355
  1192. #define HIGH 1
  1193. #define LOW 0
  1194. #define INPUT 0
  1195. #define OUTPUT 1
  1196. #define PUTDOWM 2
  1197. #define PUTUP 1
  1198. int gpio_init(void);
  1199. int gpio_setcfg(unsigned int pin, unsigned int p1);
  1200. int gpio_getcfg(unsigned int pin);
  1201. int gpio_output(unsigned int pin, unsigned int p1);
  1202. int gpio_pullup(unsigned int pin, unsigned int p1);
  1203. int gpio_input(unsigned int pin);
  1204. int i2c_open(char *dev, uint8_t address);
  1205. int i2c_close(int fd);
  1206. int i2c_send(int fd, uint8_t *buf, uint8_t num_bytes);
  1207. int i2c_read(int fd, uint8_t *buf, uint8_t num_bytes);
  1208. int spi_open(char *dev, spi_config_t config);
  1209. int spi_close(int fd);
  1210. int spi_xfer(int fd, uint8_t *tx_buf, uint8_t tx_len, uint8_t *rx_buf, uint8_t rx_len);
  1211. int spi_read(int fd, uint8_t *rx_buf, uint8_t rx_len);
  1212. int spi_write(int fd, uint8_t *tx_buffer, uint8_t tx_len);
  1213. void delay(unsigned int howLong);
  1214. /* OPI_SPI */
  1215. #define PIN_SPI_A0 _11
  1216. #define PIN_SPI_A1 _12
  1217. #define PIN_SPI_A2 _13
  1218. #define PIN_SPI_E1 _22
  1219. #define SPI_DEVICE_TEMPLATE "/dev/spidev%d.%d"
  1220. #define DEFAULT_SPI_BUS 1
  1221. #define DEFAULT_SPI_CS_LINE 0
  1222. #define DEFAULT_SPI_MODE SPI_MODE_1
  1223. #define DEFAULT_SPI_BITS_PER_WORD 16
  1224. #define DEFAULT_SPI_SPEED 1500000
  1225. #define DEFAULT_SPI_DELAY_USECS 0
  1226. struct spi_config {
  1227. int bus;
  1228. int cs_line;
  1229. uint8_t mode;
  1230. uint32_t speed;
  1231. uint8_t bits;
  1232. uint16_t delay;
  1233. };
  1234. struct spi_ctx {
  1235. int fd;
  1236. int power_en;
  1237. int start_en;
  1238. int reset;
  1239. int led;
  1240. int plug;
  1241. int id;
  1242. struct spi_config config;
  1243. };
  1244. void opi_spi_init(void);
  1245. void opi_spi_exit(void);
  1246. //void opi_set_spi_speed(uint32_t speed);
  1247. bool opi_spi_transfer(uint8_t id, uint16_t *txbuf, uint16_t *rxbuf, int len);
  1248. #endif /* _DM_COMPAT_H_ */