Repository navigation
xm: clock the XM530V200's sensor before probing it - #302
Conversation
Nothing clocks the sensor on an XM530V200 (or XM550V200, the same die) before the ISP daemon does: the vendor's daemon muxes the MCLK pad and starts the sensor PLL just before its first probe, and OpenIPC's U-Boot and module loader leave both off. An unclocked sensor answers no address, so ipcinfo -s printed nothing and every bus timed out. hal_enable_sensor_clock now muxes GPIO37 to MCLK (0x10020094 = 0x82) and starts the sensor PLL (0x20000010/0x14) and its divider (0x20000044) with the vendor's probe-time values. hal_cleanup restores each register it changed, and nothing is touched while the clock is running (a streaming pipeline). XM533, XM535 and XM232 are left as they were. Tested on an XM550V200 board with an SC2336, OpenIPC firmware: stock ipcinfo -s prints nothing; this one prints sc2336, and ipctool reports SmartSens SC2336 on bus 0 at 0x60. Afterwards the pad, the PLL and the divider read what they held before. With the clock already running, nothing is written. ipcinfo (shared, -Os): +452 bytes with all vendors, +0 with none.
PR Summary by Qodoxm: clock the XM530V200's sensor before probing it
AI Description
Merge Risk
|
Code Review by Qodo
1.
|
The XM550V200 board has a second SC2336 at 0x64. Its clock leaves on GPIO236 (0x100203b0 = 0x88), not GPIO37, and it takes the divider's high half (0x20000044 = 0x0d620d62 already enables both). Both pads are now muxed. The review's points: - A running PLL is another owner's: nothing at all is touched, pads included (a running PLL with GPIO37 elsewhere used to be remuxed). - A register is remembered only once it has been read; if any read or write in the setup fails, everything done so far is put back and the probe goes on unclocked. - Each undo records what was left in the register (the PLL's final 0x810a8000 after its staged writes). Cleanup restores only a register that still reads that, so an owner who changed it since keeps it. - The clock lock (0x20000000) is put back as found after each write, not forced to 0, and only system controller writes go through it. - Not every way out of the probe passed a hal_cleanup(): the SPI probe, a bus that opened for the arm and not for the probe, and a sweep that ends on an empty bus. getsensorid() now runs one on its way out whenever it armed (never when it did not, so a restore owed to someone else is not spent); each HAL's cleanup is a no-op once spent. ipcinfo (shared, -Os) against master: +704 bytes with all vendors, +52 with none.
ipcinfo grew 1146 bytes (IPCHW_VENDORS=all) with the clock setup, over the 1024-byte budget. The PLL program and both MCLK pads are now one table walked by one loop, with what each first write found kept beside it, in place of a poke helper and its three-word undo records. The behaviour is unchanged: nothing is touched while the PLL runs, a failed read or write puts back everything done so far, cleanup restores only a register that still reads what was left in it, and the lock register is put back as found. ipcinfo (CI's measure): +962 bytes with all vendors, +104 with none. Rechecked on the XM550V200 board: ipcinfo -s and ipctool find the SC2336, the registers read as before afterwards, and a running clock is left as it was.
On an XM530V200 (or XM550V200, the same die) running OpenIPC,
ipcinfo -sprints nothing. Every I2C read on all three buses times out.Cause. The sensors have no MCLK. On the vendor firmware, the ISP daemon muxes the MCLK pads and starts the sensor PLL just before its first probe. OpenIPC's U-Boot and module loader leave all of it off, and an unclocked sensor answers no address.
Fix. Same pattern as Anyka:
hal_enable_sensor_clocksets up the clocks before the probe, andhal_cleanupputs back what it changed.0x20000010/0x140x810a8000/0x20b600000x200000440x0d620d620x100200940x820x100203b00x88The values are the vendor's probe-time ones: the first PLL program of the SC2336 tuning.
Ownership:
0x810a8000, after the staged writes.0x20000000is restored as found after each write, and only system-controller writes go through it.Cleanup on every exit. Some probe exits skipped
hal_cleanup: the SPI probe, a bus that opened for the arm and not for the probe, and a sweep ending on an empty bus.getsensorid()now runs one on its way out whenever it armed, and never when it did not, so a restore owed to someone else is not spent. Every HAL's cleanup is a no-op once spent.Only
XM530V200is covered. XM533, XM535 and XM232 are left as they were until measured.Tested on hardware (XM550V200 board with two SC2336, OpenIPC
xm530v200_lite):0x44gated, that half's sensor goes silent.ipcinfo -sprints nothing; this one printssc2336, andipctoolreports SmartSens SC2336 on bus 0 at 0x60. Afterwards the registers read what they held before. With the clock already running, nothing was written.Native tests: all 17
build/*_testpass.ipcinfo size (the CI check, on its toolchain): +962 bytes with all vendors, +104 with none, inside the 1024-byte budget. The clock setup is one table walked by one loop.