This commit is contained in:
david rice
2026-04-20 13:48:24 +01:00
parent 3d98cbf31d
commit 712a42ecb7
2 changed files with 134 additions and 95 deletions

View File

@@ -24,6 +24,12 @@ REGISTER_COMMANDS = [
"memtool md -l 0x32e100b4+0x0c", # DSIM_PHYTIMING / PHYTIMING1 / PHYTIMING2
]
# ---------------------------------------------------------------------------
# SN65DSI83 I2C configuration
# ---------------------------------------------------------------------------
SN65_I2C_BUS = 2 # i2c-2 on i.MX 8M Mini — change if bridge is on a different bus
SN65_I2C_ADDR = 0x2C # SN65DSI83 fixed 7-bit I2C address
# Known Samsung DSIM register names (base 0x32E10000, i.MX 8M Mini)
_DSIM_NAMES = {
0x32e10004: "DSIM_STATUS",
@@ -118,5 +124,58 @@ def get_registers():
}), 200
def _i2c_read_byte(bus: int, addr: int, reg: int) -> int | None:
"""Read one byte from an I2C device using i2cget. Returns None on failure."""
try:
result = subprocess.run(
["i2cget", "-y", str(bus), f"0x{addr:02x}", f"0x{reg:02x}"],
capture_output=True, text=True, timeout=3
)
if result.returncode == 0:
return int(result.stdout.strip(), 16)
except Exception:
pass
return None
@app.route("/sn65_registers", methods=["GET"])
def get_sn65_registers():
"""Read SN65DSI83 CSR 0x0A (PLL/CLK status) and 0xE5 (error flags) via I2C."""
csr_0a = _i2c_read_byte(SN65_I2C_BUS, SN65_I2C_ADDR, 0x0A)
csr_e5 = _i2c_read_byte(SN65_I2C_BUS, SN65_I2C_ADDR, 0xE5)
regs = {}
errors = []
if csr_0a is not None:
regs["csr_0a"] = {
"value": f"0x{csr_0a:02x}",
"pll_lock": bool(csr_0a & 0x80), # bit 7: PLL_EN_STAT (powered + locked)
"clk_det": bool(csr_0a & 0x40), # bit 6: high-speed CLK lane detected
}
else:
errors.append("CSR 0x0A: i2cget failed")
if csr_e5 is not None:
regs["csr_e5"] = {
"value": f"0x{csr_e5:02x}",
"pll_unlock": bool(csr_e5 & 0x01), # default=1 at reset; must clear after init
"cha_sot_bit_err": bool(csr_e5 & 0x04),
"cha_llp_err": bool(csr_e5 & 0x08), # SoT/EoT/lane-merge error
"cha_ecc_err": bool(csr_e5 & 0x10),
"cha_lp_err": bool(csr_e5 & 0x20),
"cha_crc_err": bool(csr_e5 & 0x40),
}
else:
errors.append("CSR 0xE5: i2cget failed")
return jsonify({
"i2c_bus": SN65_I2C_BUS,
"i2c_addr": f"0x{SN65_I2C_ADDR:02x}",
"registers": regs,
"errors": errors if errors else None,
}), 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000)