Repository navigation
media: i2c: onsemi LC898129 lens driver (Pixel 9a main camera focus) - #213
Conversation
|
Thanks for this, and for keeping it to the focus part: writing one register, One thing before I merge:
Smaller points, none blocking:
The board's lens node can go into #164 or follow it, whichever W4HO-ham |
The LC898129 is a microcontroller that drives a camera module's focus and optical image stabilisation actuators and holds the module's calibration memory, over I2C with 16-bit register addresses and 32-bit values. The Google Pixel 9a's main camera module has one. It shares the module's supplies and reset with the image sensor, so the sensor powers it while streaming through its lens-focus property. The supplies follow the stock device tree's actuator node: the I/O supply, the actuator driver's VM and its analogue VDDA. All are optional, since the sensor already switches them; listed, they only keep the rails counted. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: cbm <omarchy-mobile@kloot.lu>
The Pixel 9a's main camera focuses through an LC898129, which also runs the module's optical image stabilisation. Add a V4L2 lens subdev for its focus part only, so libcamera's contrast autofocus can drive it like the other focus drivers. The controller shares the module's supplies and reset with the sensor and answers only while the sensor is powered, so, as for the SEM1215SA, it is powered through runtime PM only: the sensor driver holds its lens-focus device while streaming. Power-up waits until the controller answers a read of its servo mode (0xf010), up to 200 ms, then moves the lens to the control's value. There is no public datasheet or driver for the part. The register numbers and the form of a move were found by disassembling Google's camera HAL for the Pixel 9a: the LC898129 actuator code in liblyric_hwl.so, from the com.google.pixel.camera.hal APEX on the vendor partition of factory image BP3A.250905.014. That code reads 0xf010 and 0x0548 and writes 0xf01a with 0x0002 in the upper half and the target in the lower half. No code was copied. What the registers do, the usable range and the direction were worked out on the phone, by reading registers and writing 0xf01a alone while measuring the picture's sharpness. After power-up the controller runs its focus servo by itself (0xf010 reads 7) and holds the lens at 0x0fff in the focus target register, 0xf01a. A move writes 0x0002 in the upper half of 0xf01a and the target in the lower half. On the phone the corrected Hall position (0x0548, upper half) followed the target's low 12 bits linearly over the whole stroke, from -16379 at 0 to 16381 at 4095, and was the same going up and down; setting bits above those also moved the picture in other ways, so the driver keeps to 0-4095. Register 0 is the near end and 4095 the far end, so the control counts the other way round: higher values focus closer, as V4L2_CID_FOCUS_ABSOLUTE expects. Its default, 0, is where the controller parks the lens itself. Only 0xf01a is written. The OIS and the calibration memory are left alone, so the control spans the whole stroke rather than the module's calibrated infinity-to-macro range. debug_position logs the Hall position read back after each move. Tested on a Pixel 9a with 7.3.0-rc6-omamobile-push1-ge8d722982099, on top of the camera device tree of linux-omarchy-mobile#164, whose lc898129.c is this commit's (blob 50cce3a): while the main camera streams, focus_absolute 0, 1024, 2048, 3072, 4095, 2048, 0 settle at a Hall position of 16371, 8179, -7, -8197, -16383, -4 and 16369, and the lens is runtime-suspended again after the stream. libcamera's contrast autofocus (simple pipeline, soft ISP) sweeps the range in 8 coarse steps, then finely around the peak, and settles there; in omacam it brings a subject at about 25 cm into focus. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: cbm <omarchy-mobile@kloot.lu>
9881255 to
910304e
Compare
|
Thanks for the careful read. Force-pushed:
On the lens node: whatever W4HO-ham prefers. I can send it as a small follow-up once #164 lands. |
|
Thanks for working through all of these. The provenance paragraph is I checked the rest on my side:
The gate passes merged onto today's |
A V4L2 lens driver for the Pixel 9a's main camera focus, so libcamera's contrast autofocus can drive it, as on the Pixel 7 Pro (announced in omarchy-mobile#28).
The main module's focus and OIS controller is an onsemi LC898129 (stock
act-nessie/ois-nessie) at0x24on the main camera's bus. It shares the S5KGN8's supplies and reset and only answers while the sensor is powered, so it works like the SEM1215SA: runtime PM only, taken bys5kgn1throughlens-focuswhile streaming.dt-bindings: media: i2c: add onsemi LC898129: the binding. Supplies optional: the sensor powers the module.media: i2c: add an onsemi LC898129 lens driver:V4L2_CID_FOCUS_ABSOLUTE0-4095, higher = closer. It writes only the focus target (0xf01a=0x0002xxxx). The OIS and calibration memory are never written. The commit message has the measurements: the Hall read-back follows the low 12 bits of the target linearly, and 0 is the near end.Not in this PR: the board's lens node. The 9a's camera nodes are still in #164, so the node can't go on
omamobileyet. It is four lines, inzumapro-tegu.dtsnext tocam_main:plus
lens-focus = <&main_lens>;incam_main. It can go into #164, or into a follow-up once #164 is in, whichever you and @W4HO-ham prefer.Tested on a Pixel 9a, kernel
7.3.0-rc6-omamobile-push1-gd00d9fd2272f(a local build:omamobile+ #178, #103 and #164's camera device tree, these two commits and the lens node above):lc898129 3-0024), shows up as a lens subdev, and powers up with the sensor;debug_position), and sharpness changes steadily with it;Afin the S5KGN8 tuning file (companion omarchy-mobile PR), omacam's contrast autofocus settles on a subject at about 25 cm in a little over a second, and a full-size photo (3000x3992) is sharp.tools/kernel-pr-check --build OUT --merge origin/omamobile: merge, sign-off, prefix, policy anddt_binding_checkpass, and checkpatch--stricthas no errors. Its two warnings are the MAINTAINERS question for the new files, as for sem1215. The W=1 build oflc898129.cis clean (no warnings). On this laptop it neededbcfortimeconst.h, so I ran it by hand with that one header generated in the kbuild container.The changes were written with an AI assistant (Claude). I tested them on my phone and signed them off.
🤖 Generated with Claude Code