Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 | /* * Copyright 2013 Red Hat Inc. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Ben Skeggs */ #define T_TIMEOUT 2200000 #define T_RISEFALL 1000 #define T_HOLD 5000 #ifdef INCLUDE_PROC process(PROC_I2C_, #i2c_init, #i2c_recv) #endif /****************************************************************************** * I2C_ data segment *****************************************************************************/ #ifdef INCLUDE_DATA i2c_scl_map: .b32 NV_PPWR_OUTPUT_I2C_0_SCL .b32 NV_PPWR_OUTPUT_I2C_1_SCL .b32 NV_PPWR_OUTPUT_I2C_2_SCL .b32 NV_PPWR_OUTPUT_I2C_3_SCL .b32 NV_PPWR_OUTPUT_I2C_4_SCL .b32 NV_PPWR_OUTPUT_I2C_5_SCL .b32 NV_PPWR_OUTPUT_I2C_6_SCL .b32 NV_PPWR_OUTPUT_I2C_7_SCL .b32 NV_PPWR_OUTPUT_I2C_8_SCL .b32 NV_PPWR_OUTPUT_I2C_9_SCL i2c_sda_map: .b32 NV_PPWR_OUTPUT_I2C_0_SDA .b32 NV_PPWR_OUTPUT_I2C_1_SDA .b32 NV_PPWR_OUTPUT_I2C_2_SDA .b32 NV_PPWR_OUTPUT_I2C_3_SDA .b32 NV_PPWR_OUTPUT_I2C_4_SDA .b32 NV_PPWR_OUTPUT_I2C_5_SDA .b32 NV_PPWR_OUTPUT_I2C_6_SDA .b32 NV_PPWR_OUTPUT_I2C_7_SDA .b32 NV_PPWR_OUTPUT_I2C_8_SDA .b32 NV_PPWR_OUTPUT_I2C_9_SDA #if NVKM_PPWR_CHIPSET < GF119 i2c_ctrl: .b32 0x00e138 .b32 0x00e150 .b32 0x00e168 .b32 0x00e180 .b32 0x00e254 .b32 0x00e274 .b32 0x00e764 .b32 0x00e780 .b32 0x00e79c .b32 0x00e7b8 #endif #endif /****************************************************************************** * I2C_ code segment *****************************************************************************/ #ifdef INCLUDE_CODE // $r3 - value // $r2 - sda line // $r1 - scl line // $r0 - zero i2c_drive_scl: cmp b32 $r3 0 bra e #i2c_drive_scl_lo nv_iowr(NV_PPWR_OUTPUT_SET, $r1) ret i2c_drive_scl_lo: nv_iowr(NV_PPWR_OUTPUT_CLR, $r1) ret i2c_drive_sda: cmp b32 $r3 0 bra e #i2c_drive_sda_lo nv_iowr(NV_PPWR_OUTPUT_SET, $r2) ret i2c_drive_sda_lo: nv_iowr(NV_PPWR_OUTPUT_CLR, $r2) ret i2c_sense_scl: bclr $flags $p1 nv_iord($r3, NV_PPWR_INPUT) and $r3 $r1 bra z #i2c_sense_scl_done bset $flags $p1 i2c_sense_scl_done: ret i2c_sense_sda: bclr $flags $p1 nv_iord($r3, NV_PPWR_INPUT) and $r3 $r2 bra z #i2c_sense_sda_done bset $flags $p1 i2c_sense_sda_done: ret #define i2c_drive_scl(v) /* */ mov $r3 (v) /* */ call(i2c_drive_scl) #define i2c_drive_sda(v) /* */ mov $r3 (v) /* */ call(i2c_drive_sda) #define i2c_sense_scl() /* */ call(i2c_sense_scl) #define i2c_sense_sda() /* */ call(i2c_sense_sda) #define i2c_delay(v) /* */ mov $r14 (v) /* */ call(nsec) #define i2c_trace_init() /* */ imm32($r6, 0x10000000) /* */ sub b32 $r7 $r6 1 /* */ #define i2c_trace_down() /* */ shr b32 $r6 4 /* */ push $r5 /* */ shl b32 $r5 $r6 4 /* */ sub b32 $r5 $r6 /* */ not b32 $r5 /* */ and $r7 $r5 /* */ pop $r5 /* */ #define i2c_trace_exit() /* */ shl b32 $r6 4 /* */ #define i2c_trace_next() /* */ add b32 $r7 $r6 /* */ #define i2c_trace_call(func) /* */ i2c_trace_next() /* */ i2c_trace_down() /* */ call(func) /* */ i2c_trace_exit() /* */ i2c_raise_scl: push $r4 mov $r4 (T_TIMEOUT / T_RISEFALL) i2c_drive_scl(1) i2c_raise_scl_wait: i2c_delay(T_RISEFALL) i2c_sense_scl() bra $p1 #i2c_raise_scl_done sub b32 $r4 1 bra nz #i2c_raise_scl_wait i2c_raise_scl_done: pop $r4 ret i2c_start: i2c_sense_scl() bra not $p1 #i2c_start_rep i2c_sense_sda() bra not $p1 #i2c_start_rep bra #i2c_start_send i2c_start_rep: i2c_drive_scl(0) i2c_drive_sda(1) i2c_trace_call(i2c_raise_scl) bra not $p1 #i2c_start_out i2c_start_send: i2c_drive_sda(0) i2c_delay(T_HOLD) i2c_drive_scl(0) i2c_delay(T_HOLD) i2c_start_out: ret i2c_stop: i2c_drive_scl(0) i2c_drive_sda(0) i2c_delay(T_RISEFALL) i2c_drive_scl(1) i2c_delay(T_HOLD) i2c_drive_sda(1) i2c_delay(T_HOLD) ret // $r3 - value // $r2 - sda line // $r1 - scl line // $r0 - zero i2c_bitw: call(i2c_drive_sda) i2c_delay(T_RISEFALL) i2c_trace_call(i2c_raise_scl) bra not $p1 #i2c_bitw_out i2c_delay(T_HOLD) i2c_drive_scl(0) i2c_delay(T_HOLD) i2c_bitw_out: ret // $r3 - value (out) // $r2 - sda line // $r1 - scl line // $r0 - zero i2c_bitr: i2c_drive_sda(1) i2c_delay(T_RISEFALL) i2c_trace_call(i2c_raise_scl) bra not $p1 #i2c_bitr_done i2c_sense_sda() i2c_drive_scl(0) i2c_delay(T_HOLD) xbit $r3 $flags $p1 bset $flags $p1 i2c_bitr_done: ret i2c_get_byte: mov $r5 0 mov $r4 8 i2c_get_byte_next: shl b32 $r5 1 i2c_trace_call(i2c_bitr) bra not $p1 #i2c_get_byte_done or $r5 $r3 sub b32 $r4 1 bra nz #i2c_get_byte_next mov $r3 1 i2c_trace_call(i2c_bitw) i2c_get_byte_done: ret i2c_put_byte: mov $r4 8 i2c_put_byte_next: sub b32 $r4 1 xbit $r3 $r5 $r4 i2c_trace_call(i2c_bitw) bra not $p1 #i2c_put_byte_done cmp b32 $r4 0 bra ne #i2c_put_byte_next i2c_trace_call(i2c_bitr) bra not $p1 #i2c_put_byte_done i2c_trace_next() cmp b32 $r3 1 bra ne #i2c_put_byte_done bclr $flags $p1 // nack i2c_put_byte_done: ret i2c_addr: i2c_trace_call(i2c_start) bra not $p1 #i2c_addr_done extr $r3 $r12 I2C__MSG_DATA0_ADDR shl b32 $r3 1 or $r5 $r3 i2c_trace_call(i2c_put_byte) i2c_addr_done: ret i2c_acquire_addr: extr $r14 $r12 I2C__MSG_DATA0_PORT #if NVKM_PPWR_CHIPSET < GF119 shl b32 $r14 2 add b32 $r14 #i2c_ctrl ld b32 $r14 D[$r14] #else shl b32 $r14 5 add b32 $r14 0x00d014 #endif ret i2c_acquire: call(i2c_acquire_addr) call(rd32) bset $r13 3 call(wr32) ret i2c_release: call(i2c_acquire_addr) call(rd32) bclr $r13 3 call(wr32) ret // description // // $r15 - current (i2c) // $r14 - sender process name // $r13 - message // $r12 - data0 // $r11 - data1 // $r0 - zero i2c_recv: bclr $flags $p1 extr $r1 $r12 I2C__MSG_DATA0_PORT shl b32 $r1 2 cmp b32 $r1 (#i2c_sda_map - #i2c_scl_map) bra ge #i2c_recv_done add b32 $r3 $r1 #i2c_sda_map ld b32 $r2 D[$r3] add b32 $r3 $r1 #i2c_scl_map ld b32 $r1 D[$r3] bset $flags $p2 push $r13 push $r14 push $r13 i2c_trace_init() i2c_trace_call(i2c_acquire) pop $r13 cmp b32 $r13 I2C__MSG_RD08 bra ne #i2c_recv_not_rd08 mov $r5 0 i2c_trace_call(i2c_addr) bra not $p1 #i2c_recv_done extr $r5 $r12 I2C__MSG_DATA0_RD08_REG i2c_trace_call(i2c_put_byte) bra not $p1 #i2c_recv_done mov $r5 1 i2c_trace_call(i2c_addr) bra not $p1 #i2c_recv_done i2c_trace_call(i2c_get_byte) bra not $p1 #i2c_recv_done ins $r11 $r5 I2C__MSG_DATA1_RD08_VAL i2c_trace_call(i2c_stop) mov b32 $r11 $r5 clear b32 $r7 bra #i2c_recv_done i2c_recv_not_rd08: cmp b32 $r13 I2C__MSG_WR08 bra ne #i2c_recv_not_wr08 mov $r5 0 call(i2c_addr) bra not $p1 #i2c_recv_done extr $r5 $r12 I2C__MSG_DATA0_WR08_REG call(i2c_put_byte) bra not $p1 #i2c_recv_done mov $r5 0 call(i2c_addr) bra not $p1 #i2c_recv_done extr $r5 $r11 I2C__MSG_DATA1_WR08_VAL call(i2c_put_byte) bra not $p1 #i2c_recv_done call(i2c_stop) clear b32 $r7 extr $r5 $r12 I2C__MSG_DATA0_WR08_SYNC bra nz #i2c_recv_done bclr $flags $p2 bra #i2c_recv_done i2c_recv_not_wr08: i2c_recv_done: extr $r14 $r12 I2C__MSG_DATA0_PORT call(i2c_release) pop $r14 pop $r13 bra not $p2 #i2c_recv_exit mov b32 $r12 $r7 call(send) i2c_recv_exit: ret // description // // $r15 - current (i2c) // $r0 - zero i2c_init: ret #endif |