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