tsif.txt 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. TSIF driver serves piece of hardware found in Qualcomm MSM's.
  2. It deals with Digital Mobile Broadcast.
  3. If you are dealing with Qualcomm MSM that have relevant piece of hardware,
  4. read on.
  5. There are various Digital Mobile Broadcast (DMB) systems developed to receive
  6. audio and/or television broadcast programs by Mobile Station Modem (MSM).
  7. (in simplified words - cellular phone)
  8. All of these systems have similar architecture. They use radio link which
  9. is different from primary handset link and hence use the additional antenna.
  10. RF signal from the broadcast tuner goes to de-modulator.
  11. Regardless of actual tuner and de-modulator, all systems present
  12. ITU-T H.222.0 (also known as MPEG2) Transport Stream (HTS)
  13. to the Mobile Station Modem (MSM).
  14. TSIF stands for Transport Stream Interface;
  15. this is hardware block in MSM that receives HTS signal from the de-modulator.
  16. TSIF use serial interface with de-modulator;
  17. it buffers data received in internal registers.
  18. TSIF support data copying from its internal registers to the RAM
  19. with the Data Mover (DM).
  20. TSIF driver prevent MSM from sleeping while TSIF hardware is active.
  21. To achieve this, driver holds wake lock.
  22. For access to TSIF data, TSIF driver provides kernel API
  23. that may be used by another kernel module. As example for API usage,
  24. simple TSIF chardev adapter provided. It provides character device
  25. /dev/tsif0. This device may be opened by single process at a time.
  26. When read, it provides TS stream.
  27. Quick start:
  28. ### copy modules to the target
  29. adb push msm_tsif.ko /data/local/tmp/
  30. adb push tsif_chrdev.ko /data/local/tmp/
  31. ### Load modules on the target:
  32. adb shell mount -t debugfs debugfs /sys/kernel/debug
  33. adb shell insmod /data/local/tmp/msm_tsif.ko
  34. adb shell insmod /data/local/tmp/tsif_chrdev.ko
  35. ### Run capture:
  36. adb shell cat /dev/tsif0 > /data/local/tmp/tsif.dump
  37. # tests:
  38. adb shell mount -t debugfs debugfs /sys/kernel/debug
  39. adb shell rmmod tsif_chrdev
  40. adb shell rmmod msm_tsif
  41. adb shell insmod /data/local/tmp/msm_tsif.ko
  42. adb shell insmod /data/local/tmp/tsif_chrdev.ko
  43. adb shell 'echo 60 > /sys/devices/platform/msm_tsif.0/time_limit'
  44. adb shell 'echo "16 * 8" > /sys/devices/platform/msm_tsif.0/buf_config'
  45. # separate xterm:
  46. watch adb shell cat /sys/devices/platform/msm_tsif.0/stats
  47. # separate xterm:
  48. watch adb shell cat /sys/kernel/debug/msm_tsif.0/dma
  49. # separate xterm:
  50. adb shell dd if=/dev/tsif0 of=/dev/null
  51. Mode of operation
  52. TSIF hardware have 2 modes of operation: mode1 and mode 2.
  53. They differ in serial interface signals. Mode used should match demodulator
  54. chip interface.
  55. In addition to these 2 modes of operation, TSIF driver have pseudo-mode 3
  56. that means "debug mode" where all operation controlled through debug interfaces.
  57. Client configure TSIF mode of operation using tsif_set_mode().
  58. Alternatively, mode of operation may be configured using device attribute file:
  59. echo 1 > /sys/devices/platform/msm_tsif.0/mode
  60. Time limit
  61. TSIF driver maintains time limit value. Its value corresponds
  62. to the TSIF_TIME_LIMIT register in TSIF hardware.
  63. Value in ticks of tsif_ref_clk. If time between the end of previous
  64. packet and end of current one exceeds this value, timeout status reported
  65. for the current TSIF packet.
  66. Client configure TSIF time limit using tsif_set_time_limit().
  67. Alternatively, time limit may be configured using device attribute file:
  68. echo 100 > /sys/devices/platform/msm_tsif.0/time_limit
  69. TSIF packet format
  70. TSIF driver uses 192 byte packets; where first 188 packets is HTS packet;
  71. last 4 bytes consists of :
  72. 3 bytes TTS in bytes 188..190; and status byte ib byte 191.
  73. Status byte contains the following fields:
  74. Bit Name Comment
  75. 0 Valid Always set to 1 to indicate valid HTS packet and status.
  76. If set to 0, this packet is not valid and should be ignored
  77. 1 First packet When set, indicates 1-st packet of a new stream or
  78. 1-st valid packet after one or more packets were lost.
  79. 2 Overflow When set, indicates overflow condition in TSIF hardware;
  80. one or more packets were lost. Current packet is valid.
  81. 3 Error Indicates the tsif_error signal status
  82. 4 Null Indicates the tsif_null signal status
  83. 5 Reserved Don't care
  84. 6 Timeout Indicates the 1-st packet after timeout.
  85. First packet flag will also be set.
  86. Debug facilities
  87. TSIF driver provides extensive debugging facilities to assist debug both
  88. TSIF input and TSIF client interfaces. 2 mechanisms used:
  89. Device attribute, accessible through usual /sys hierarchy under
  90. /sys/devices/platform/msm_tsif.0, provides status and statistics information.
  91. Debugfs exposes more hardware and software details. In order to use debugfs,
  92. one need to mount it:
  93. adb shell mount -t debugfs debugfs /sys/kernel/debug
  94. When debugfs mounted, TSIF entries may be found under
  95. /sys/kernel/debug/msm_tsif.0
  96. Register access
  97. All TSIF hardware registers accessible through debugfs.
  98. $ adb shell ls -l /sys/kernel/debug/msm_tsif.0
  99. -r--r--r-- root root 0 1980-01-07 16:15 dma
  100. --w------- root root 0 1980-01-07 16:15 action
  101. -r--r--r-- root root 0 1980-01-07 16:15 gpios
  102. -r-------- root root 0 1980-01-07 16:15 data_port
  103. -r--r--r-- root root 0 1980-01-07 16:15 test_current
  104. -rw-r--r-- root root 0 1980-01-07 16:15 test_export
  105. --w------- root root 0 1980-01-07 16:15 test_reset
  106. -rw-r--r-- root root 0 1980-01-07 16:15 test_mode
  107. -rw-r--r-- root root 0 1980-01-07 16:15 test_ctl
  108. -rw-r--r-- root root 0 1980-01-07 16:15 lpbk_data
  109. -rw-r--r-- root root 0 1980-01-07 16:15 lpbk_flags
  110. -rw-r--r-- root root 0 1980-01-07 16:15 clk_ref
  111. -rw-r--r-- root root 0 1980-01-07 16:15 time_limit
  112. -rw-r--r-- root root 0 1980-01-07 16:15 sts_ctl
  113. TSIF clocks are off when TSIF is not running.
  114. To control TSIF through low level register access, it should be set to the
  115. mode 3 ("debug"); in addition, TSIF start/stop actions may be executed using
  116. debugfs action file:
  117. adb shell 'echo open > /sys/kernel/debug/msm_tsif.0/action'
  118. Possible actions are "open" and "close".
  119. DMA activity
  120. DMA activity may be queried using debugfs dma file:
  121. $ adb shell cat /sys/kernel/debug/msm_tsif.0/dma
  122. ri 16 | wi 24 | dmwi 40 | [ 24]{ 32} [ 32]{ 40}
  123. This file provides ri/wi/dmwi indexes
  124. (dmwi is for Data Mover write index - index for first location where
  125. next DMA may be scheduled);
  126. and 2 Data Mover transfer tasks, each in [wi] {next_wi} format.
  127. Here, wi is index DMA is scheduled for; next_wi is where driver's
  128. wi will be set after DMA completion.
  129. Driver status
  130. Driver status available through stats device attribute:
  131. $ adb shell cat /sys/devices/platform/msm_tsif.0/stats
  132. Device msm_tsif.0
  133. Mode = 1
  134. Time limit = 60
  135. State running
  136. Client = bf036f68
  137. Pkt/Buf = 64
  138. Pkt/chunk = 8
  139. --statistics--
  140. Rx chunks = 3288898
  141. Overflow = 4606
  142. Lost sync = 0
  143. Timeout = 1
  144. DMA error = 0
  145. Soft drop = 0
  146. IFI = 48
  147. --debug--
  148. GLBL_CLK_ENA = 0x637dfe23
  149. ROW_RESET = 0x000008c1
  150. CLK_HALT_STATEB = 0xde6d80ff
  151. TV_NS_REG = 0xf8e00b44
  152. TSIF_NS_REG = 0x00000b40
  153. GPIO
  154. Current GPIO values may be read using debugfs gpio file:
  155. $ adb shell cat /sys/kernel/debug/msm_tsif.0/gpios
  156. tsif_clk: 0
  157. tsif_en: 0
  158. tsif_data: 0
  159. tsif_sync: 0
  160. In normal regime, signals changed too fast for this facility to provide
  161. change by change log; it should be seen as random time capture.
  162. When debugging TSIF input connectivity, it may be helpful to run
  163. watch -d adb shell cat /sys/kernel/debug/msm_tsif.0/gpios
  164. to see if input ever changes. If nothing changes at all; it is indication
  165. for mis-configured input.
  166. Another tip: in case of wire connection between components, one may connect
  167. TSIF input pin to logical 1 instead of actual signal source,
  168. to verify this is the pin required.
  169. Inter frame interval
  170. To estimate incoming bit rate, TSIF driver measure average time interval
  171. between packets. Interval measured in tsif_ref_clk ticks. Actually, TSIF
  172. gets TTS from 1-st and last packets in chunk and use this time to calculate
  173. inter frame interval.
  174. Inter frame interval available as part of device statistics.
  175. Tip: to measure tsif_ref_clk frequency, this approach may be used:
  176. adb shell cat /sys/kernel/debug/msm_tsif.0/clk_ref; sleep 10; adb shell cat /sys/kernel/debug/msm_tsif.0/clk_ref
  177. 0x8db70ec8
  178. 0x8dc6974b
  179. Then, calculate (0x8dc6974b - 0x8db70ec8)/10 that is 101798.7 Hz