I'm trying to configure a GPIO pin on an SoC running Linux (Jetson Orin Nano), but there's no API provided to set things like pull resistors, so we have to look up the physical addresses of the control registers and write to them directly.
In order to do this, we can use busybox to read and write memory-mapped I/O. The first thing I did was try out some examples. According to "https://docs.nvidia.com/jetson/archives/r35.3.1/DeveloperGuide/text/HR/JetsonModuleAdaptationAndBringUp/JetsonAgxOrinSeries.html?highlight=switch#identifying-the-gpio-number", I should be able to run the command "busybox devmem 0x02430070" in order to read the configuration state of pin "MCLK05: SOC_GPIO33: PQ6".
Unfortunately, it reads only 0xffffffff. In fact, for absolutely any address I provide, it always reads back 0xffffffff. I even tried writing my own program that mmaps /dev/mem, but I get exactly the same result. The mmap call succeeds (it would fail if I were not running as root), but accessing memory fails.
I checked dmesg, and whenever I try to perform any access to memory mapped through /dev/mem, I get a kernel error like this:
[98089.048787] CPU:0, Error: cbb-fabric@0x13a00000, irq=25
[98089.054186] **************************************
[98089.059112] CPU:0, Error:cbb-fabric, Errmon:2
[98089.063596] Error Code : TIMEOUT_ERR
[98089.069159] Error Code : TIMEOUT_ERR
[98089.073188] MASTER_ID : CCPLEX
[98089.076684] Address : 0x2340068
[98089.080275] Cache : 0x0 -- Device Non-Bufferable
[98089.085466] Protection : 0x2 -- Unprivileged, Non-Secure, Data Access
[98089.092444] Access_Type : Read
[98089.095933] Access_ID : 0x17
[98089.095934] Fabric : cbb-fabric
[98089.102828] Slave_Id : 0x35
[98089.106051] Burst_length : 0x0
[98089.109539] Burst_type : 0x1
[98089.112854] Beat_size : 0x2
[98089.116072] VQC : 0x0
[98089.118848] GRPSEC : 0x7e
[98089.121895] FALCONSEC : 0x0
[98089.125114] **************************************
[98089.130151] ------------[ cut here ]------------
[98089.130170] WARNING: CPU: 0 PID: 13354 at drivers/soc/tegra/cbb/tegra234-cbb.c:577 tegra234_cbb_isr+0x130/0x170
[98089.140534] Modules linked in: fuse nvidia_modeset(O) xt_conntrack xt_MASQUERADE nf_conntrack_netlink nfnetlink xt_addrtype iptable_filter iptable_nat nf_nat nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c br_netfilter lzo_rle lzo_compress zram overlay ramoops reed_solomon bnep snd_soc_tegra186_asrc snd_soc_tegra210_iqc aes_ce_blk snd_soc_tegra186_dspk snd_soc_tegra210_ope snd_soc_tegra186_arad crypto_simd snd_soc_tegra210_mvc cryptd snd_soc_tegra210_dmic rtk_btusb snd_soc_tegra210_afc aes_ce_cipher snd_soc_tegra210_amx snd_soc_tegra210_adx ghash_ce btusb sha2_ce btrtl snd_soc_tegra210_mixer snd_soc_tegra210_i2s snd_soc_tegra210_admaif sha256_arm64 rtl8822ce snd_soc_tegra210_adsp snd_soc_tegra210_sfc btbcm sha1_ce snd_soc_tegra_pcm snd_soc_tegra_machine_driver btintel r8168 snd_soc_tegra_utils fusb301 snd_hda_codec_hdmi snd_soc_simple_card_utils snd_soc_spdif_tx r8169 snd_hda_tegra cfg80211 snd_soc_tegra210_ahub nvadsp realtek snd_hda_codec tegra210_adma userspace_alert
[98089.140661] tegra_bpmp_thermal snd_hda_core nv_imx219 nvidia(O) spi_tegra114 binfmt_misc loop ina3221 pwm_fan nvgpu nvmap spidev ip_tables x_tables [last unloaded: mtd]
[98089.140696] CPU: 0 PID: 13354 Comm: busybox Tainted: G W O 5.10.104-tegra #1
[98089.140698] Hardware name: Unknown NVIDIA Orin NX Developer Kit/NVIDIA Orin NX Developer Kit, BIOS 3.0-32616947 02/21/2023
[98089.140701] pstate: 60400089 (nZCv daIf +PAN -UAO -TCO BTYPE=--)
[98089.140704] pc : tegra234_cbb_isr+0x130/0x170
[98089.140706] lr : tegra234_cbb_isr+0x10c/0x170
[98089.140707] sp : ffff800010003e10
[98089.140708] x29: ffff800010003e10 x28: ffff20b08026ab80
[98089.140711] x27: 0000000000000001 x26: 0000000000000080
[98089.140714] x25: ffffa2a2d36f9ed0 x24: ffffa2a2d404be40
[98089.140717] x23: ffffa2a2d39e7000 x22: 0000000000000019
[98089.140720] x21: ffffa2a2d3e6ef20 x20: 0000000000000002
[98089.140723] x19: ffffa2a2d3e6ef10 x18: 0000000000000010
[98089.140726] x17: 0000000000000000 x16: ffffa2a2d1fe3210
[98089.140728] x15: ffff20b08026b0f0 x14: ffffffffffffffff
[98089.140731] x13: ffff800090003917 x12: ffff80001000391f
[98089.140734] x11: 0101010101010101 x10: 7f7f7f7f7f7f7f7f
[98089.140736] x9 : ffff800010003c30 x8 : 2a2a2a2a2a2a2a2a
[98089.140739] x7 : 2a2a2a2a2a2a2a09 x6 : c0000000ffffefff
[98089.140742] x5 : ffff20b1b1bb2958 x4 : ffffa2a2d3cf7968
[98089.140744] x3 : 0000000000000000 x2 : ffffa2a2d217e170
[98089.140747] x1 : ffff20b08026ab80 x0 : 0000000100010000
[98089.140751] Call trace:
[98089.140753] tegra234_cbb_isr+0x130/0x170
[98089.140761] __handle_irq_event_percpu+0x68/0x2a0
[98089.140763] handle_irq_event_percpu+0x40/0xa0
[98089.140766] handle_irq_event+0x50/0xf0
[98089.140768] handle_fasteoi_irq+0xc0/0x170
[98089.140772] generic_handle_irq+0x40/0x60
[98089.140775] __handle_domain_irq+0x70/0xd0
[98089.140778] gic_handle_irq+0x68/0x134
[98089.140779] el1_irq+0xd0/0x180
[98089.140787] el0_ia+0x50/0xb0
[98089.140788] el0_sync_handler+0x90/0xb0
[98089.140790] el0_sync+0x16c/0x180
[98089.140793] ---[ end trace 71009e79516be4c4 ]---
For reference, I have posted to Nvidia's developer forum at "https://forums.developer.nvidia.com/t/trying-to-configure-gpio-pin-direction-busybox-devmem-returns-0xffffffff-for-all-addresses/256819", but I have a feeling that this is well outside of the sort of thing I'm going to get help on there.
If anyone can give me some clues to make headway on this, that would be fantastic. Thanks!