From 53c53492ee33fa3c7488c93817f8142c275eb2e5 Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:14:20 +0000 Subject: [PATCH 1/3] xm: clock the XM530V200's sensor before probing it 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. --- CLAUDE.md | 9 +++++++ src/hal/xm.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 82 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index 4531103..1260a04 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -230,6 +230,15 @@ reset/power-down GPIOs the device tree names for the camera node, and `hal_cleanup` puts back exactly what it changed. It touches nothing when the clock is already running, which is a pipeline streaming. +The XM530V200 (and the XM550V200, the same die) is the same story: nothing +clocks the sensor before the ISP daemon does, and OpenIPC's U-Boot leaves the +clock off. `hal_enable_sensor_clock` muxes GPIO37 to MCLK (`0x10020094` = +`0x82`) and starts the sensor PLL (`0x20000010`/`0x14`) and its divider +(`0x20000044`) with the vendor's probe-time values; each of the three was +needed on an XM550V200 board. Same rule: nothing is touched while the clock +runs, and `hal_cleanup` puts back what was changed. The other V200 chips +(XM533, XM535, XM232) are left alone until measured. + `ipcinfo` is in every camera image and the size check holds it to 1 KiB of growth per PR, so it carries the least that works, behind `#ifndef STANDALONE_LIBRARY` for the rest. It starts the CIS clock and takes diff --git a/src/hal/xm.c b/src/hal/xm.c index 27a7aaf..d38b84d 100644 --- a/src/hal/xm.c +++ b/src/hal/xm.c @@ -126,7 +126,78 @@ int xm_sensor_write_register(int fd, unsigned char i2c_addr, return 0; } -static void xm_hal_cleanup() { restore_printk(); } +/* The XM530V200's sensor clock (the XM550V200 is the same die and kernel). + * Nothing starts it before the ISP does: the vendor's ISP daemon muxes the + * MCLK pad and runs the sensor PLL just before its first probe, and OpenIPC's + * U-Boot and module loader leave both off, so an unclocked sensor answers no + * address on any bus. Measured on an XM550V200 board with an SC2336: the pad, + * the PLL and the PLL's divider are each needed. The values are the vendor's + * probe-time ones (the SC2336 tuning's first PLL program). */ +#define XM_V200_SYS 0x20000000 /* 1 unlocks the clock registers */ +#define XM_V200_SNS_PLL 0x20000010 /* bits 31 and 24: running */ +#define XM_V200_SNS_PLL_FRAC 0x20000014 +#define XM_V200_SNS_DIV 0x20000044 +#define XM_V200_MCLK_PAD 0x10020094 /* GPIO37: 0x82 is MCLK out */ +#define XM_V200_PLL_ON 0x81000000 + +static struct { + uint32_t addr, val; +} xm_undo[4]; +static int xm_undo_n; + +static void xm_v200_clk_write(uint32_t addr, uint32_t val) { + uint32_t v = 1; + + mem_reg(XM_V200_SYS, &v, OP_WRITE); + mem_reg(addr, &val, OP_WRITE); + v = 0; + mem_reg(XM_V200_SYS, &v, OP_WRITE); +} + +/* The first write of a register, remembering what it held. */ +static void xm_v200_poke(uint32_t addr, uint32_t val) { + xm_undo[xm_undo_n].addr = addr; + mem_reg(addr, &xm_undo[xm_undo_n++].val, OP_READ); + xm_v200_clk_write(addr, val); +} + +static void xm_v200_enable_sensor_clock() { + uint32_t pad, pll; + + if (xm_undo_n || strcmp(chip_name, "XM530V200") || + !mem_reg(XM_V200_MCLK_PAD, &pad, OP_READ) || + !mem_reg(XM_V200_SNS_PLL, &pll, OP_READ)) + return; + /* running: leave it to whoever runs it */ + if (pad == 0x82 && (pll & XM_V200_PLL_ON) == XM_V200_PLL_ON) + return; + + /* The probe calls hal_cleanup() only after it has opened the bus, so a + * clock started for a bus that will not open would never be stopped. */ + int fd = open_i2c_sensor_fd(i2c_adapter_nr); + if (fd < 0) + return; + close_sensor_fd(fd); + + if ((pll & XM_V200_PLL_ON) != XM_V200_PLL_ON) { + xm_v200_poke(XM_V200_SNS_PLL, 0x010a8000); + xm_v200_poke(XM_V200_SNS_PLL_FRAC, 0x20b60000); + xm_v200_poke(XM_V200_SNS_DIV, 0x0d620d62); + xm_v200_clk_write(XM_V200_SNS_PLL, 0x800a8000); + xm_v200_clk_write(XM_V200_SNS_PLL, 0x810a8000); + } + if (pad != 0x82) + xm_v200_poke(XM_V200_MCLK_PAD, 0x82); + usleep(20000); +} + +static void xm_hal_cleanup() { + while (xm_undo_n) { + xm_undo_n--; + xm_v200_clk_write(xm_undo[xm_undo_n].addr, xm_undo[xm_undo_n].val); + } + restore_printk(); +} void setup_hal_xm() { open_i2c_sensor_fd = xm_open_sensor_fd; @@ -137,6 +208,7 @@ void setup_hal_xm() { if (xm_is_v200(chip_name)) { open_i2c_sensor_fd = xm_v200_open_sensor_fd; possible_i2c_addrs = xm_v200_possible_i2c_addrs; + hal_enable_sensor_clock = xm_v200_enable_sensor_clock; } hal_cleanup = xm_hal_cleanup; #ifndef STANDALONE_LIBRARY From 46ac5b896d4a8709490c8bdb00693ed333643c14 Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:39:15 +0000 Subject: [PATCH 2/3] xm: clock both V200 sensors; own only what was left as written 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. --- CLAUDE.md | 21 ++++++--- src/hal/xm.c | 125 ++++++++++++++++++++++++++++++++------------------ src/sensors.c | 14 +++++- 3 files changed, 108 insertions(+), 52 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 1260a04..895280b 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -231,13 +231,20 @@ reset/power-down GPIOs the device tree names for the camera node, and clock is already running, which is a pipeline streaming. The XM530V200 (and the XM550V200, the same die) is the same story: nothing -clocks the sensor before the ISP daemon does, and OpenIPC's U-Boot leaves the -clock off. `hal_enable_sensor_clock` muxes GPIO37 to MCLK (`0x10020094` = -`0x82`) and starts the sensor PLL (`0x20000010`/`0x14`) and its divider -(`0x20000044`) with the vendor's probe-time values; each of the three was -needed on an XM550V200 board. Same rule: nothing is touched while the clock -runs, and `hal_cleanup` puts back what was changed. The other V200 chips -(XM533, XM535, XM232) are left alone until measured. +clocks the sensors before the ISP daemon does, and OpenIPC's U-Boot leaves the +clock off. `hal_enable_sensor_clock` starts the sensor PLL (`0x20000010`/`0x14`) +and its divider (`0x20000044`: low half MCLK0, high half MCLK1) with the +vendor's probe-time values, and muxes each sensor's MCLK pad: GPIO37 +(`0x10020094` = `0x82`) for the sensor at 0x60, GPIO236 (`0x100203b0` = +`0x88`) for the one at 0x64. All were needed on a two-sensor XM550V200 board. +A running PLL is someone else's and nothing is touched; otherwise each +register is remembered with what it held and what was left in it, and +`hal_cleanup` restores only a register that still reads what was left. The +other V200 chips (XM533, XM535, XM232) are left alone until measured. + +Not every way out of the probe passes a `hal_cleanup` (the SPI probe, a bus +that opened for the arm and not for the probe, a sweep ending on an empty +bus), so `getsensorid()` runs one on its way out whenever it armed. `ipcinfo` is in every camera image and the size check holds it to 1 KiB of growth per PR, so it carries the least that works, behind diff --git a/src/hal/xm.c b/src/hal/xm.c index d38b84d..88d5d36 100644 --- a/src/hal/xm.c +++ b/src/hal/xm.c @@ -126,76 +126,113 @@ int xm_sensor_write_register(int fd, unsigned char i2c_addr, return 0; } -/* The XM530V200's sensor clock (the XM550V200 is the same die and kernel). - * Nothing starts it before the ISP does: the vendor's ISP daemon muxes the - * MCLK pad and runs the sensor PLL just before its first probe, and OpenIPC's +/* The XM530V200's sensor clocks (the XM550V200 is the same die and kernel). + * Nothing starts them before the ISP does: the vendor's ISP daemon muxes the + * MCLK pads and runs the sensor PLL just before its first probe, and OpenIPC's * U-Boot and module loader leave both off, so an unclocked sensor answers no - * address on any bus. Measured on an XM550V200 board with an SC2336: the pad, - * the PLL and the PLL's divider are each needed. The values are the vendor's - * probe-time ones (the SC2336 tuning's first PLL program). */ -#define XM_V200_SYS 0x20000000 /* 1 unlocks the clock registers */ -#define XM_V200_SNS_PLL 0x20000010 /* bits 31 and 24: running */ -#define XM_V200_SNS_PLL_FRAC 0x20000014 -#define XM_V200_SNS_DIV 0x20000044 -#define XM_V200_MCLK_PAD 0x10020094 /* GPIO37: 0x82 is MCLK out */ + * address on any bus. Measured on an XM550V200 board with two SC2336s: the + * PLL, its divider (low half MCLK0, high half MCLK1) and each sensor's pad are + * all needed. The values are the vendor's probe-time ones (the SC2336 tuning's + * first PLL program). + * + * Ownership: a running PLL belongs to whoever started it, and nothing is + * touched then. Otherwise every register written is remembered with what it + * held and what was left in it, and cleanup puts back only a register that + * still reads what was left -- one changed since has another owner. */ +#define XM_V200_SYS 0x20000000 /* bit 0 unlocks the clock registers */ +#define XM_V200_SNS_PLL 0x20000010 /* bits 31 and 24: running */ #define XM_V200_PLL_ON 0x81000000 +#define XM_V200_PLL_RUN 0x810a8000 -static struct { +static const struct { uint32_t addr, val; -} xm_undo[4]; -static int xm_undo_n; +} xm_v200_pads[] = { + {0x10020094, 0x82}, /* GPIO37: MCLK0, the sensor at 0x60 */ + {0x100203b0, 0x88}, /* GPIO236: MCLK1, the sensor at 0x64 */ +}; -static void xm_v200_clk_write(uint32_t addr, uint32_t val) { - uint32_t v = 1; +static struct { + uint32_t addr, was, left; +} xm_undo[5]; +static int xm_undo_n; - mem_reg(XM_V200_SYS, &v, OP_WRITE); - mem_reg(addr, &val, OP_WRITE); - v = 0; - mem_reg(XM_V200_SYS, &v, OP_WRITE); +/* One write; the system controller's go through its lock, which is put back + * as it was found. */ +static bool xm_v200_write(uint32_t addr, uint32_t val) { + uint32_t lock, unlock = 1; + + if ((addr & 0xfff00000) != XM_V200_SYS) + return mem_reg(addr, &val, OP_WRITE); + if (!mem_reg(XM_V200_SYS, &lock, OP_READ)) + return false; + bool ok = mem_reg(XM_V200_SYS, &unlock, OP_WRITE) && + mem_reg(addr, &val, OP_WRITE); + mem_reg(XM_V200_SYS, &lock, OP_WRITE); + return ok; } -/* The first write of a register, remembering what it held. */ -static void xm_v200_poke(uint32_t addr, uint32_t val) { +/* The first write of a register: remembered only once it has been read. */ +static bool xm_v200_poke(uint32_t addr, uint32_t val, uint32_t left) { + uint32_t was; + + if (!mem_reg(addr, &was, OP_READ) || !xm_v200_write(addr, val)) + return false; xm_undo[xm_undo_n].addr = addr; - mem_reg(addr, &xm_undo[xm_undo_n++].val, OP_READ); - xm_v200_clk_write(addr, val); + xm_undo[xm_undo_n].was = was; + xm_undo[xm_undo_n++].left = left; + return true; +} + +/* Put back what was changed: all of it when setup failed half way, else only + * registers that still hold what was left in them. */ +static void xm_v200_undo(bool all) { + while (xm_undo_n) { + uint32_t now; + + xm_undo_n--; + if (all || (mem_reg(xm_undo[xm_undo_n].addr, &now, OP_READ) && + now == xm_undo[xm_undo_n].left)) + xm_v200_write(xm_undo[xm_undo_n].addr, xm_undo[xm_undo_n].was); + } } static void xm_v200_enable_sensor_clock() { - uint32_t pad, pll; + uint32_t pll; if (xm_undo_n || strcmp(chip_name, "XM530V200") || - !mem_reg(XM_V200_MCLK_PAD, &pad, OP_READ) || - !mem_reg(XM_V200_SNS_PLL, &pll, OP_READ)) - return; - /* running: leave it to whoever runs it */ - if (pad == 0x82 && (pll & XM_V200_PLL_ON) == XM_V200_PLL_ON) + !mem_reg(XM_V200_SNS_PLL, &pll, OP_READ) || + (pll & XM_V200_PLL_ON) == XM_V200_PLL_ON) return; - /* The probe calls hal_cleanup() only after it has opened the bus, so a - * clock started for a bus that will not open would never be stopped. */ + /* A clock started for a bus that will not open is stopped by + * getsensorid() on its way out. */ int fd = open_i2c_sensor_fd(i2c_adapter_nr); if (fd < 0) return; close_sensor_fd(fd); - if ((pll & XM_V200_PLL_ON) != XM_V200_PLL_ON) { - xm_v200_poke(XM_V200_SNS_PLL, 0x010a8000); - xm_v200_poke(XM_V200_SNS_PLL_FRAC, 0x20b60000); - xm_v200_poke(XM_V200_SNS_DIV, 0x0d620d62); - xm_v200_clk_write(XM_V200_SNS_PLL, 0x800a8000); - xm_v200_clk_write(XM_V200_SNS_PLL, 0x810a8000); + bool ok = xm_v200_poke(XM_V200_SNS_PLL, 0x010a8000, XM_V200_PLL_RUN) && + xm_v200_poke(0x20000014, 0x20b60000, 0x20b60000) && + xm_v200_poke(0x20000044, 0x0d620d62, 0x0d620d62) && + xm_v200_write(XM_V200_SNS_PLL, 0x800a8000) && + xm_v200_write(XM_V200_SNS_PLL, XM_V200_PLL_RUN); + for (size_t i = 0; ok && i < ARRCNT(xm_v200_pads); i++) { + uint32_t pad; + + ok = mem_reg(xm_v200_pads[i].addr, &pad, OP_READ) && + (pad == xm_v200_pads[i].val || + xm_v200_poke(xm_v200_pads[i].addr, xm_v200_pads[i].val, + xm_v200_pads[i].val)); + } + if (!ok) { + xm_v200_undo(true); + return; } - if (pad != 0x82) - xm_v200_poke(XM_V200_MCLK_PAD, 0x82); usleep(20000); } static void xm_hal_cleanup() { - while (xm_undo_n) { - xm_undo_n--; - xm_v200_clk_write(xm_undo[xm_undo_n].addr, xm_undo[xm_undo_n].val); - } + xm_v200_undo(false); restore_printk(); } diff --git a/src/sensors.c b/src/sensors.c index 30e765d..d46b542 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -1565,7 +1565,10 @@ static bool i2c_bus_openable(int adapter_nr, dev_t *dev) { * rather than unconditional: it undoes an ungate this process performed and * nothing else, so it no longer fights the sweep, nor a consumer whose * pipeline is streaming while we probe (OpenIPC/firmware#2439). */ +static bool sensor_armed; + static void arm_sensor_clock(void) { + sensor_armed = true; if (hal_enable_sensor_clock) hal_enable_sensor_clock(); } @@ -1657,9 +1660,18 @@ static bool probe_sensor(sensor_ctx_t *ctx) { * console, and not every way out of it passes a * hal_cleanup(): a bus that opens and then has no sensor on it, for one. The * console comes back here, on every path, for a consumer that lives on after - * the probe -- majestic does, and it ran with the console off all along. */ + * the probe -- majestic does, and it ran with the console off all along. + * + * So does what an arm switched on: the SPI probe, a bus that opened for the + * arm and not for the probe, and a sweep that ends on an empty bus all return + * without a cleanup. Only after an arm, which a probe that never got a chip + * name did not make; after a cleanup that ran this is a no-op, each undo + * being spent. */ bool getsensorid(sensor_ctx_t *ctx) { + sensor_armed = false; bool found = probe_sensor(ctx); + if (sensor_armed && hal_cleanup) + hal_cleanup(); restore_printk(); return found; } From 861ffdde0e0ad2b27565fe31813f88551899adb6 Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 1 Dec 2026 17:41:17 +0000 Subject: [PATCH 3/3] xm: the V200 clock setup as one table, under ipcinfo's size budget 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. --- src/hal/xm.c | 84 ++++++++++++++++++++++------------------------------ 1 file changed, 35 insertions(+), 49 deletions(-) diff --git a/src/hal/xm.c b/src/hal/xm.c index 88d5d36..7c5bfb7 100644 --- a/src/hal/xm.c +++ b/src/hal/xm.c @@ -139,67 +139,59 @@ int xm_sensor_write_register(int fd, unsigned char i2c_addr, * touched then. Otherwise every register written is remembered with what it * held and what was left in it, and cleanup puts back only a register that * still reads what was left -- one changed since has another owner. */ -#define XM_V200_SYS 0x20000000 /* bit 0 unlocks the clock registers */ -#define XM_V200_SNS_PLL 0x20000010 /* bits 31 and 24: running */ +#define XM_V200_SYS 0x20000000 /* bit 0 unlocks the clock registers */ +#define XM_V200_SNS_PLL 0x20000010 /* bits 31 and 24: running */ #define XM_V200_PLL_ON 0x81000000 -#define XM_V200_PLL_RUN 0x810a8000 +/* In order. A nonzero left is a first write, remembered with what the register + * held; zero is a step of the PLL's staged start. */ static const struct { - uint32_t addr, val; -} xm_v200_pads[] = { - {0x10020094, 0x82}, /* GPIO37: MCLK0, the sensor at 0x60 */ - {0x100203b0, 0x88}, /* GPIO236: MCLK1, the sensor at 0x64 */ + uint32_t addr, val, left; +} xm_v200_clk[] = { + {XM_V200_SNS_PLL, 0x010a8000, 0x810a8000}, + {0x20000014, 0x20b60000, 0x20b60000}, + {0x20000044, 0x0d620d62, 0x0d620d62}, /* low half MCLK0, high MCLK1 */ + {XM_V200_SNS_PLL, 0x800a8000, 0}, + {XM_V200_SNS_PLL, 0x810a8000, 0}, + {0x10020094, 0x82, 0x82}, /* GPIO37: MCLK0, the sensor at 0x60 */ + {0x100203b0, 0x88, 0x88}, /* GPIO236: MCLK1, at 0x64 */ }; - -static struct { - uint32_t addr, was, left; -} xm_undo[5]; -static int xm_undo_n; +static uint32_t xm_was[ARRCNT(xm_v200_clk)]; +static unsigned xm_done; /* entries applied */ /* One write; the system controller's go through its lock, which is put back * as it was found. */ static bool xm_v200_write(uint32_t addr, uint32_t val) { uint32_t lock, unlock = 1; + bool ok; if ((addr & 0xfff00000) != XM_V200_SYS) return mem_reg(addr, &val, OP_WRITE); if (!mem_reg(XM_V200_SYS, &lock, OP_READ)) return false; - bool ok = mem_reg(XM_V200_SYS, &unlock, OP_WRITE) && - mem_reg(addr, &val, OP_WRITE); + ok = mem_reg(XM_V200_SYS, &unlock, OP_WRITE) && + mem_reg(addr, &val, OP_WRITE); mem_reg(XM_V200_SYS, &lock, OP_WRITE); return ok; } -/* The first write of a register: remembered only once it has been read. */ -static bool xm_v200_poke(uint32_t addr, uint32_t val, uint32_t left) { - uint32_t was; - - if (!mem_reg(addr, &was, OP_READ) || !xm_v200_write(addr, val)) - return false; - xm_undo[xm_undo_n].addr = addr; - xm_undo[xm_undo_n].was = was; - xm_undo[xm_undo_n++].left = left; - return true; -} - /* Put back what was changed: all of it when setup failed half way, else only * registers that still hold what was left in them. */ static void xm_v200_undo(bool all) { - while (xm_undo_n) { - uint32_t now; + while (xm_done) { + uint32_t now, i = --xm_done; - xm_undo_n--; - if (all || (mem_reg(xm_undo[xm_undo_n].addr, &now, OP_READ) && - now == xm_undo[xm_undo_n].left)) - xm_v200_write(xm_undo[xm_undo_n].addr, xm_undo[xm_undo_n].was); + if (xm_v200_clk[i].left && + (all || (mem_reg(xm_v200_clk[i].addr, &now, OP_READ) && + now == xm_v200_clk[i].left))) + xm_v200_write(xm_v200_clk[i].addr, xm_was[i]); } } static void xm_v200_enable_sensor_clock() { uint32_t pll; - if (xm_undo_n || strcmp(chip_name, "XM530V200") || + if (xm_done || strcmp(chip_name, "XM530V200") || !mem_reg(XM_V200_SNS_PLL, &pll, OP_READ) || (pll & XM_V200_PLL_ON) == XM_V200_PLL_ON) return; @@ -211,22 +203,16 @@ static void xm_v200_enable_sensor_clock() { return; close_sensor_fd(fd); - bool ok = xm_v200_poke(XM_V200_SNS_PLL, 0x010a8000, XM_V200_PLL_RUN) && - xm_v200_poke(0x20000014, 0x20b60000, 0x20b60000) && - xm_v200_poke(0x20000044, 0x0d620d62, 0x0d620d62) && - xm_v200_write(XM_V200_SNS_PLL, 0x800a8000) && - xm_v200_write(XM_V200_SNS_PLL, XM_V200_PLL_RUN); - for (size_t i = 0; ok && i < ARRCNT(xm_v200_pads); i++) { - uint32_t pad; - - ok = mem_reg(xm_v200_pads[i].addr, &pad, OP_READ) && - (pad == xm_v200_pads[i].val || - xm_v200_poke(xm_v200_pads[i].addr, xm_v200_pads[i].val, - xm_v200_pads[i].val)); - } - if (!ok) { - xm_v200_undo(true); - return; + while (xm_done < ARRCNT(xm_v200_clk)) { + unsigned i = xm_done; + + if ((xm_v200_clk[i].left && + !mem_reg(xm_v200_clk[i].addr, &xm_was[i], OP_READ)) || + !xm_v200_write(xm_v200_clk[i].addr, xm_v200_clk[i].val)) { + xm_v200_undo(true); + return; + } + xm_done++; } usleep(20000); }