dscore.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. * dscore.h
  3. *
  4. * Copyright (c) 2004 Evgeniy Polyakov <johnpol@2ka.mipt.ru>
  5. *
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #ifndef __DSCORE_H
  22. #define __DSCORE_H
  23. #include <linux/usb.h>
  24. #include <asm/atomic.h>
  25. /* COMMAND TYPE CODES */
  26. #define CONTROL_CMD 0x00
  27. #define COMM_CMD 0x01
  28. #define MODE_CMD 0x02
  29. /* CONTROL COMMAND CODES */
  30. #define CTL_RESET_DEVICE 0x0000
  31. #define CTL_START_EXE 0x0001
  32. #define CTL_RESUME_EXE 0x0002
  33. #define CTL_HALT_EXE_IDLE 0x0003
  34. #define CTL_HALT_EXE_DONE 0x0004
  35. #define CTL_FLUSH_COMM_CMDS 0x0007
  36. #define CTL_FLUSH_RCV_BUFFER 0x0008
  37. #define CTL_FLUSH_XMT_BUFFER 0x0009
  38. #define CTL_GET_COMM_CMDS 0x000A
  39. /* MODE COMMAND CODES */
  40. #define MOD_PULSE_EN 0x0000
  41. #define MOD_SPEED_CHANGE_EN 0x0001
  42. #define MOD_1WIRE_SPEED 0x0002
  43. #define MOD_STRONG_PU_DURATION 0x0003
  44. #define MOD_PULLDOWN_SLEWRATE 0x0004
  45. #define MOD_PROG_PULSE_DURATION 0x0005
  46. #define MOD_WRITE1_LOWTIME 0x0006
  47. #define MOD_DSOW0_TREC 0x0007
  48. /* COMMUNICATION COMMAND CODES */
  49. #define COMM_ERROR_ESCAPE 0x0601
  50. #define COMM_SET_DURATION 0x0012
  51. #define COMM_BIT_IO 0x0020
  52. #define COMM_PULSE 0x0030
  53. #define COMM_1_WIRE_RESET 0x0042
  54. #define COMM_BYTE_IO 0x0052
  55. #define COMM_MATCH_ACCESS 0x0064
  56. #define COMM_BLOCK_IO 0x0074
  57. #define COMM_READ_STRAIGHT 0x0080
  58. #define COMM_DO_RELEASE 0x6092
  59. #define COMM_SET_PATH 0x00A2
  60. #define COMM_WRITE_SRAM_PAGE 0x00B2
  61. #define COMM_WRITE_EPROM 0x00C4
  62. #define COMM_READ_CRC_PROT_PAGE 0x00D4
  63. #define COMM_READ_REDIRECT_PAGE_CRC 0x21E4
  64. #define COMM_SEARCH_ACCESS 0x00F4
  65. /* Communication command bits */
  66. #define COMM_TYPE 0x0008
  67. #define COMM_SE 0x0008
  68. #define COMM_D 0x0008
  69. #define COMM_Z 0x0008
  70. #define COMM_CH 0x0008
  71. #define COMM_SM 0x0008
  72. #define COMM_R 0x0008
  73. #define COMM_IM 0x0001
  74. #define COMM_PS 0x4000
  75. #define COMM_PST 0x4000
  76. #define COMM_CIB 0x4000
  77. #define COMM_RTS 0x4000
  78. #define COMM_DT 0x2000
  79. #define COMM_SPU 0x1000
  80. #define COMM_F 0x0800
  81. #define COMM_NTP 0x0400
  82. #define COMM_ICP 0x0200
  83. #define COMM_RST 0x0100
  84. #define PULSE_PROG 0x01
  85. #define PULSE_SPUE 0x02
  86. #define BRANCH_MAIN 0xCC
  87. #define BRANCH_AUX 0x33
  88. /*
  89. * Duration of the strong pull-up pulse in milliseconds.
  90. */
  91. #define PULLUP_PULSE_DURATION 750
  92. /* Status flags */
  93. #define ST_SPUA 0x01 /* Strong Pull-up is active */
  94. #define ST_PRGA 0x02 /* 12V programming pulse is being generated */
  95. #define ST_12VP 0x04 /* external 12V programming voltage is present */
  96. #define ST_PMOD 0x08 /* DS2490 powered from USB and external sources */
  97. #define ST_HALT 0x10 /* DS2490 is currently halted */
  98. #define ST_IDLE 0x20 /* DS2490 is currently idle */
  99. #define ST_EPOF 0x80
  100. #define SPEED_NORMAL 0x00
  101. #define SPEED_FLEXIBLE 0x01
  102. #define SPEED_OVERDRIVE 0x02
  103. #define NUM_EP 4
  104. #define EP_CONTROL 0
  105. #define EP_STATUS 1
  106. #define EP_DATA_OUT 2
  107. #define EP_DATA_IN 3
  108. struct ds_device
  109. {
  110. struct usb_device *udev;
  111. struct usb_interface *intf;
  112. int ep[NUM_EP];
  113. atomic_t refcnt;
  114. };
  115. struct ds_status
  116. {
  117. u8 enable;
  118. u8 speed;
  119. u8 pullup_dur;
  120. u8 ppuls_dur;
  121. u8 pulldown_slew;
  122. u8 write1_time;
  123. u8 write0_time;
  124. u8 reserved0;
  125. u8 status;
  126. u8 command0;
  127. u8 command1;
  128. u8 command_buffer_status;
  129. u8 data_out_buffer_status;
  130. u8 data_in_buffer_status;
  131. u8 reserved1;
  132. u8 reserved2;
  133. };
  134. int ds_touch_bit(struct ds_device *, u8, u8 *);
  135. int ds_read_byte(struct ds_device *, u8 *);
  136. int ds_read_bit(struct ds_device *, u8 *);
  137. int ds_write_byte(struct ds_device *, u8);
  138. int ds_write_bit(struct ds_device *, u8);
  139. int ds_reset(struct ds_device *, struct ds_status *);
  140. struct ds_device * ds_get_device(void);
  141. void ds_put_device(struct ds_device *);
  142. int ds_write_block(struct ds_device *, u8 *, int);
  143. int ds_read_block(struct ds_device *, u8 *, int);
  144. #endif /* __DSCORE_H */