raspberrypi-native.cfg 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # SPDX-License-Identifier: GPL-2.0-or-later
  2. # Config for Raspberry Pi used as a bitbang adapter.
  3. # https://www.raspberrypi.com/documentation/computers/raspberry-pi.html
  4. # Supports all models with 40-pin or 26-pin GPIO connector up to Raspberry Pi 4 B
  5. # also supports Raspberry Pi Zero, Zero W and Zero 2 W.
  6. # Adapter speed calibration is computed from cpufreq/scaling_max_freq.
  7. # Adjusts automatically if CPU is overclocked.
  8. adapter driver bcm2835gpio
  9. proc read_file { name } {
  10. if {[catch {open $name r} fd]} {
  11. return ""
  12. }
  13. set result [read $fd]
  14. close $fd
  15. return $result
  16. }
  17. proc measure_clock {} {
  18. set result [exec vcgencmd measure_clock arm]
  19. set clock_hz [lindex [split $result "="] 1]
  20. expr { $clock_hz / 1000 }
  21. }
  22. proc get_max_cpu_clock { default } {
  23. set clock [read_file /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq]
  24. if { $clock > 100000 } {
  25. return $clock
  26. }
  27. # cpufreq not available. As the last resort try Broadcom's proprietary utility
  28. if {![catch measure_clock clock] && $clock > 100000} {
  29. return $clock
  30. }
  31. echo "WARNING: Host CPU clock unknown."
  32. echo "WARNING: Using the highest possible value $default kHz as a safe default."
  33. echo "WARNING: Expect JTAG/SWD clock significantly slower than requested."
  34. return $default
  35. }
  36. set compat [read_file /proc/device-tree/compatible]
  37. set clocks_per_timing_loop 4
  38. if {[string match *bcm2711* $compat]} {
  39. set speed_offset 52
  40. } elseif {[string match *bcm2837* $compat] || [string match *bcm2710* $compat]} {
  41. set speed_offset 34
  42. } elseif {[string match *bcm2836* $compat] || [string match *bcm2709* $compat]} {
  43. set speed_offset 36
  44. } elseif {[string match *bcm2835* $compat] || [string match *bcm2708* $compat]} {
  45. set clocks_per_timing_loop 6
  46. set speed_offset 32
  47. } else {
  48. set speed_offset 32
  49. echo "WARNING: Unknown type of the host SoC. Expect JTAG/SWD clock slower than requested."
  50. }
  51. set clock [get_max_cpu_clock 2000000]
  52. set speed_coeff [expr { $clock / $clocks_per_timing_loop }]
  53. # Transition delay calculation: SPEED_COEFF/khz - SPEED_OFFSET
  54. # The coefficients depend on system clock and CPU frequency scaling.
  55. bcm2835gpio speed_coeffs $speed_coeff $speed_offset
  56. source [find interface/raspberrypi-gpio-connector.cfg]