<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.pine64.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kgmt0</id>
	<title>PINE64 - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.pine64.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kgmt0"/>
	<link rel="alternate" type="text/html" href="https://wiki.pine64.org/wiki/Special:Contributions/Kgmt0"/>
	<updated>2026-04-20T17:52:52Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.37.1</generator>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13230</id>
		<title>PinePhone Pro/IMX258 Camera Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13230"/>
		<updated>2022-06-29T18:29:29Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: /* Megi saves the day */ Fix ffmpeg command for front camera example&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Pinephone Pro's rear camera is a Sony IMX258. The camera driver is present upstream, and at least [https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro Manjaro's kernel] (downstream of Megi's) enables the driver. The camera does not seem to work; this page catalogs work on figuring out why.&lt;br /&gt;
&lt;br /&gt;
== Initial status ==&lt;br /&gt;
&lt;br /&gt;
What do we see in dmesg?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
imx258 1-001a: supply vana not found, using dummy regulator&lt;br /&gt;
imx258 1-001a: supply vdig not found, using dummy regulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the kernel loads the driver, which is something.&lt;br /&gt;
&lt;br /&gt;
Are these errors bad/fatal? Inspecting the [https://github.com/megous/linux/blob/orange-pi-5.17/drivers/media/i2c/imx258.c source] shows us that these supplies are defined in the &amp;lt;code&amp;gt;imx258_supply_names&amp;lt;/code&amp;gt; array, and &amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt; to set them up.&lt;br /&gt;
&amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; checks the return code from &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt;, emitting a fatal &amp;quot;Failed to get supplies&amp;quot; message if the return code is negative (indicating failure). Since we don't see this message (or any others from the driver), it looks like it loads successfully!&lt;br /&gt;
&lt;br /&gt;
=== How can we test the camera? ===&lt;br /&gt;
&lt;br /&gt;
==== Megapixels ====&lt;br /&gt;
&lt;br /&gt;
[https://gitlab.com/postmarketOS/megapixels Megapixels] requires a per-device file to configure cameras. This one isn't complete (most of its numbers are complete nonsense), but it should let us see what happens when Megapixels tries to access the camera:&lt;br /&gt;
&amp;lt;code&amp;gt;pine64,pinephone-pro.ini&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[device]&lt;br /&gt;
make=PINE64&lt;br /&gt;
model=PinePhone Pro&lt;br /&gt;
&lt;br /&gt;
[rear]&lt;br /&gt;
driver=imx258&lt;br /&gt;
media-driver=rkisp1&lt;br /&gt;
capture-width=4208&lt;br /&gt;
capture-height=3118&lt;br /&gt;
capture-rate=60&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
preview-width=1280&lt;br /&gt;
preview-height=960&lt;br /&gt;
preview-rate=60&lt;br /&gt;
#preview-fmt=BGGR8&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
rotate=90&lt;br /&gt;
mirrored=true&lt;br /&gt;
focallength=2.6&lt;br /&gt;
cropfactor=12.7&lt;br /&gt;
fnumber=2.8&lt;br /&gt;
flash-display=true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This segfaulted Megapixels for me. After patching some trivial segfaults, I get fatal GTK4 issues and other tangential problems. Let's try something else.&lt;br /&gt;
&lt;br /&gt;
==== Manually setting up a camera pipeline ====&lt;br /&gt;
&lt;br /&gt;
We can roughly follow [https://www.kernel.org/doc/html/latest/admin-guide/media/rkisp1.html this guide]. Doing so gives us the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=800,height=600,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--verbose&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Careful readers will note that this is setting the camera up with a low resolution compared to what the sensor can do. For some reason I can't get the rkisp1 node to configure its sink pad with the maximum resolution of the sensor (4208x3118). Instead, it sets itself to 4032x3024. This mismatch is forbidden and causes v4l2 to give us EPIPE when we try to enable the stream. Using the lower resolution gets us further--the last command (which attempts to save a single frame of video) gives output like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VIDIOC_QUERYCAP: ok&lt;br /&gt;
		VIDIOC_REQBUFS returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_STREAMON returned 0 (Success)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But then it just hangs there indefinitely.&lt;br /&gt;
&lt;br /&gt;
Running under strace, we see the program stuck in an ioctl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ioctl(3, VIDIOC_DQBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/vidioc-qbuf.html VIDIOC_DQBUF] corresponds to dequeuing a buffer once it has been filled with an image by the v4l2 device. Apparently, the device never gives us back a captured frame.&lt;br /&gt;
&lt;br /&gt;
=== Now what? ===&lt;br /&gt;
&lt;br /&gt;
==== Does i2c work at all? ====&lt;br /&gt;
&lt;br /&gt;
The camera driver uses i2c; we can see the camera [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts#L890-L914 in the .dts] to determine that it's on i2c bus 1, address 0x1a.&lt;br /&gt;
&lt;br /&gt;
The imx258 is controlled over i2c, and sends image data over MIPI. The first step is to see if the i2c control is working.&lt;br /&gt;
&lt;br /&gt;
Looking back at the driver, it seems we should see errors in dmesg if i2c communication fails. The driver checks the chip id in its probe function, which uses i2c, so we can conclude that i2c gets set up properly initially. Does it keep working?&lt;br /&gt;
&lt;br /&gt;
==== Does i2c keep working? (FTrace) ====&lt;br /&gt;
&lt;br /&gt;
We can see if other functions that use i2c produce errors--for example, when we run our &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command, we expect that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; will get called, and this function also writes a load of registers over i2c.&lt;br /&gt;
&lt;br /&gt;
Build and install a kernel with CONFIG_FTRACE (not hard, but outside the scope of this write-up) and enable function graph tracing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo su&lt;br /&gt;
# cd /sys/kernel/debug/tracing&lt;br /&gt;
# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
# cat available_filter_functions | grep -E 'rkisp|imx258|v4l2' | awk '{print $1}' &amp;gt; set_graph_function&lt;br /&gt;
# echo 'vm_map_pages,__iommu_map,iommu_map_sg_atomic,rk_iommu_map,__alloc_pages,dma_alloc_attrs,dma_mmap_attrs,__vm_map_pages,vb2_mmap,clk_e,able,schedule_timeout,clk_disable,regmap_write,schedule,__i2c_tra,sfer,i2c_tra,sfer_buffer_flags,dma_free_attrs' | tr , '\n' &amp;gt; set_graph_notrace&lt;br /&gt;
# tee trace_pipe &amp;gt; ~/function-trace.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in another terminal session, run the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command again. We end up with a bunch (but hopefully not *too* much) of output in our first terminal and the &amp;lt;code&amp;gt;~/function-trace.log&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
A quick grep shows that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; is indeed called, so '''i2c is working properly'''.&lt;br /&gt;
&lt;br /&gt;
=== If i2c works, what doesn't? ===&lt;br /&gt;
&lt;br /&gt;
Our program that asks for a video frame is still hung! We ask the camera to start streaming frames, it presumably does, but the v4l2 stack never tells us a frame has finished. Doing some digging in the v4l2 stack (and the rkisp1 driver), we find out that rkisp1 is notified about frame status via interrupts.&lt;br /&gt;
&lt;br /&gt;
Perhaps the hardware is never actually emitting the interrupt that signals a frame being finished. Indeed, grepping our FTrace log shows that &amp;lt;code&amp;gt;rkisp1_isr&amp;lt;/code&amp;gt; is never called. A quick look at &amp;lt;code&amp;gt;/proc/interrupts&amp;lt;/code&amp;gt; shows that '''the only interrupt associated with the isp has never triggered''' (0 count on every CPU):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# head -n1 /proc/interrupts; grep isp /proc/interrupts&lt;br /&gt;
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       &lt;br /&gt;
 57:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu, rkisp1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; debugfs info ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; driver keeps some [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h#L335-L363 error/debug counters] in debugfs, which can be viewed at &amp;lt;code&amp;gt;/sys/kernel/debug/ff910000.isp0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sadly, the only one of these that comes up nonzero is &amp;lt;code&amp;gt;sp_stop_timeout&amp;lt;/code&amp;gt; (&amp;quot;upon stream stop, the capture waits 1 second for the isr to stop the stream. This param is incremented in case of timeout&amp;quot;). I observe it to increment once per time I terminate the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command. This tells us what we already know: interrupts are not firing, but it also tells us that we aren't hitting any other errors that rkisp1 knows about.&lt;br /&gt;
&lt;br /&gt;
== Next steps ==&lt;br /&gt;
&lt;br /&gt;
Where do we go from here? I don't know--something may be wrong with the way the .dts specifies interrupts, some kind of firmware/GIC (the rk3399's interrupt controller) configuration issue, or something else. It would be good to try to determine:&lt;br /&gt;
&lt;br /&gt;
* Whether the MIPI lines actually show traffic, if someone has a logic analyzer and a dissected PPP.&lt;br /&gt;
* Whether the DMA of frames to memory actually happens, regardless of (lack of) emission of the interrupt that tells us when said DMA finishes a frame.&lt;br /&gt;
* Whether the regulator messages we see during boot are actually significant. I don't know enough about the Linux regulator framework to say whether these being not-found means power is not correctly supplied, or if Linux just isn't being properly informed of the power supply requirements for precise tracking/power-saving when the camera is off.&lt;br /&gt;
&lt;br /&gt;
== Megi saves the day ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; you might be interested in this https://megous.com/dl/tmp/0ae6ba03a17a3d53.png&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; https://megous.com/git/linux/tag/?h=orange-pi-5.18-20220521-1759&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turns out, the .dts had the wrong ISP connected to the sensor! This is fixed in [https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9 this commit], which is included in kernel version 5.18 or newer.&lt;br /&gt;
&lt;br /&gt;
With a sufficiently new kernel, the following should produce an image (&amp;lt;code&amp;gt;frame.jpg&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;imx258 1-001a&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:2 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, you can take a photo from the front camera with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 [fmt:SBGGR10_1X10/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':0 [fmt:SBGGR10_1X10/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':2 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':0 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':1 [fmt:YUYV8_2X8/1632x1224]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1632x1224 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, the isp exposes 2 devices nodes, and the nodes have separate topologies with a different sensor attached to each. In this situation, you may need to reference the isp using the correct device node for the commands to work.&lt;br /&gt;
&lt;br /&gt;
=== What's left? ===&lt;br /&gt;
&lt;br /&gt;
* libcamera and megapixels still don't work. Megapixels appears to need support for debayering YUYV, and both appear to be configuring the rkisp1 pipeline wrong.&lt;br /&gt;
* The images captured are pretty green and seem to have two pixels of garbage at their bottom edge. rkisp1 supports auto white-balance (AWB) using the params/stats pads, and libcamera has some smarts that may hook these up properly. In the meantime, raw images can be postprocessed to improve white balance and exposure.&lt;br /&gt;
&lt;br /&gt;
== Useful links == &lt;br /&gt;
&lt;br /&gt;
* [https://files.pine64.org/doc/PinePhonePro/PinephonePro-Schematic-V1.0-20211127.pdf Pinephone Pro Schematic]&lt;br /&gt;
* [https://blog.krybot.com/a?ID=01650-cea27a80-a1ab-4da1-9cb5-3945be91e3e1 Background on the GIC]&lt;br /&gt;
* [https://elinux.org/images/9/94/ISP-presentation.pdf Background on the rkisp1 ISP]&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13187</id>
		<title>PinePhone Pro/IMX258 Camera Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13187"/>
		<updated>2022-06-14T00:56:11Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: /* Megi saves the day */ DTS patch is now included in 5.18&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Pinephone Pro's rear camera is a Sony IMX258. The camera driver is present upstream, and at least [https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro Manjaro's kernel] (downstream of Megi's) enables the driver. The camera does not seem to work; this page catalogs work on figuring out why.&lt;br /&gt;
&lt;br /&gt;
== Initial status ==&lt;br /&gt;
&lt;br /&gt;
What do we see in dmesg?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
imx258 1-001a: supply vana not found, using dummy regulator&lt;br /&gt;
imx258 1-001a: supply vdig not found, using dummy regulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the kernel loads the driver, which is something.&lt;br /&gt;
&lt;br /&gt;
Are these errors bad/fatal? Inspecting the [https://github.com/megous/linux/blob/orange-pi-5.17/drivers/media/i2c/imx258.c source] shows us that these supplies are defined in the &amp;lt;code&amp;gt;imx258_supply_names&amp;lt;/code&amp;gt; array, and &amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt; to set them up.&lt;br /&gt;
&amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; checks the return code from &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt;, emitting a fatal &amp;quot;Failed to get supplies&amp;quot; message if the return code is negative (indicating failure). Since we don't see this message (or any others from the driver), it looks like it loads successfully!&lt;br /&gt;
&lt;br /&gt;
=== How can we test the camera? ===&lt;br /&gt;
&lt;br /&gt;
==== Megapixels ====&lt;br /&gt;
&lt;br /&gt;
[https://gitlab.com/postmarketOS/megapixels Megapixels] requires a per-device file to configure cameras. This one isn't complete (most of its numbers are complete nonsense), but it should let us see what happens when Megapixels tries to access the camera:&lt;br /&gt;
&amp;lt;code&amp;gt;pine64,pinephone-pro.ini&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[device]&lt;br /&gt;
make=PINE64&lt;br /&gt;
model=PinePhone Pro&lt;br /&gt;
&lt;br /&gt;
[rear]&lt;br /&gt;
driver=imx258&lt;br /&gt;
media-driver=rkisp1&lt;br /&gt;
capture-width=4208&lt;br /&gt;
capture-height=3118&lt;br /&gt;
capture-rate=60&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
preview-width=1280&lt;br /&gt;
preview-height=960&lt;br /&gt;
preview-rate=60&lt;br /&gt;
#preview-fmt=BGGR8&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
rotate=90&lt;br /&gt;
mirrored=true&lt;br /&gt;
focallength=2.6&lt;br /&gt;
cropfactor=12.7&lt;br /&gt;
fnumber=2.8&lt;br /&gt;
flash-display=true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This segfaulted Megapixels for me. After patching some trivial segfaults, I get fatal GTK4 issues and other tangential problems. Let's try something else.&lt;br /&gt;
&lt;br /&gt;
==== Manually setting up a camera pipeline ====&lt;br /&gt;
&lt;br /&gt;
We can roughly follow [https://www.kernel.org/doc/html/latest/admin-guide/media/rkisp1.html this guide]. Doing so gives us the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=800,height=600,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--verbose&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Careful readers will note that this is setting the camera up with a low resolution compared to what the sensor can do. For some reason I can't get the rkisp1 node to configure its sink pad with the maximum resolution of the sensor (4208x3118). Instead, it sets itself to 4032x3024. This mismatch is forbidden and causes v4l2 to give us EPIPE when we try to enable the stream. Using the lower resolution gets us further--the last command (which attempts to save a single frame of video) gives output like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VIDIOC_QUERYCAP: ok&lt;br /&gt;
		VIDIOC_REQBUFS returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_STREAMON returned 0 (Success)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But then it just hangs there indefinitely.&lt;br /&gt;
&lt;br /&gt;
Running under strace, we see the program stuck in an ioctl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ioctl(3, VIDIOC_DQBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/vidioc-qbuf.html VIDIOC_DQBUF] corresponds to dequeuing a buffer once it has been filled with an image by the v4l2 device. Apparently, the device never gives us back a captured frame.&lt;br /&gt;
&lt;br /&gt;
=== Now what? ===&lt;br /&gt;
&lt;br /&gt;
==== Does i2c work at all? ====&lt;br /&gt;
&lt;br /&gt;
The camera driver uses i2c; we can see the camera [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts#L890-L914 in the .dts] to determine that it's on i2c bus 1, address 0x1a.&lt;br /&gt;
&lt;br /&gt;
The imx258 is controlled over i2c, and sends image data over MIPI. The first step is to see if the i2c control is working.&lt;br /&gt;
&lt;br /&gt;
Looking back at the driver, it seems we should see errors in dmesg if i2c communication fails. The driver checks the chip id in its probe function, which uses i2c, so we can conclude that i2c gets set up properly initially. Does it keep working?&lt;br /&gt;
&lt;br /&gt;
==== Does i2c keep working? (FTrace) ====&lt;br /&gt;
&lt;br /&gt;
We can see if other functions that use i2c produce errors--for example, when we run our &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command, we expect that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; will get called, and this function also writes a load of registers over i2c.&lt;br /&gt;
&lt;br /&gt;
Build and install a kernel with CONFIG_FTRACE (not hard, but outside the scope of this write-up) and enable function graph tracing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo su&lt;br /&gt;
# cd /sys/kernel/debug/tracing&lt;br /&gt;
# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
# cat available_filter_functions | grep -E 'rkisp|imx258|v4l2' | awk '{print $1}' &amp;gt; set_graph_function&lt;br /&gt;
# echo 'vm_map_pages,__iommu_map,iommu_map_sg_atomic,rk_iommu_map,__alloc_pages,dma_alloc_attrs,dma_mmap_attrs,__vm_map_pages,vb2_mmap,clk_e,able,schedule_timeout,clk_disable,regmap_write,schedule,__i2c_tra,sfer,i2c_tra,sfer_buffer_flags,dma_free_attrs' | tr , '\n' &amp;gt; set_graph_notrace&lt;br /&gt;
# tee trace_pipe &amp;gt; ~/function-trace.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in another terminal session, run the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command again. We end up with a bunch (but hopefully not *too* much) of output in our first terminal and the &amp;lt;code&amp;gt;~/function-trace.log&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
A quick grep shows that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; is indeed called, so '''i2c is working properly'''.&lt;br /&gt;
&lt;br /&gt;
=== If i2c works, what doesn't? ===&lt;br /&gt;
&lt;br /&gt;
Our program that asks for a video frame is still hung! We ask the camera to start streaming frames, it presumably does, but the v4l2 stack never tells us a frame has finished. Doing some digging in the v4l2 stack (and the rkisp1 driver), we find out that rkisp1 is notified about frame status via interrupts.&lt;br /&gt;
&lt;br /&gt;
Perhaps the hardware is never actually emitting the interrupt that signals a frame being finished. Indeed, grepping our FTrace log shows that &amp;lt;code&amp;gt;rkisp1_isr&amp;lt;/code&amp;gt; is never called. A quick look at &amp;lt;code&amp;gt;/proc/interrupts&amp;lt;/code&amp;gt; shows that '''the only interrupt associated with the isp has never triggered''' (0 count on every CPU):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# head -n1 /proc/interrupts; grep isp /proc/interrupts&lt;br /&gt;
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       &lt;br /&gt;
 57:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu, rkisp1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; debugfs info ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; driver keeps some [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h#L335-L363 error/debug counters] in debugfs, which can be viewed at &amp;lt;code&amp;gt;/sys/kernel/debug/ff910000.isp0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sadly, the only one of these that comes up nonzero is &amp;lt;code&amp;gt;sp_stop_timeout&amp;lt;/code&amp;gt; (&amp;quot;upon stream stop, the capture waits 1 second for the isr to stop the stream. This param is incremented in case of timeout&amp;quot;). I observe it to increment once per time I terminate the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command. This tells us what we already know: interrupts are not firing, but it also tells us that we aren't hitting any other errors that rkisp1 knows about.&lt;br /&gt;
&lt;br /&gt;
== Next steps ==&lt;br /&gt;
&lt;br /&gt;
Where do we go from here? I don't know--something may be wrong with the way the .dts specifies interrupts, some kind of firmware/GIC (the rk3399's interrupt controller) configuration issue, or something else. It would be good to try to determine:&lt;br /&gt;
&lt;br /&gt;
* Whether the MIPI lines actually show traffic, if someone has a logic analyzer and a dissected PPP.&lt;br /&gt;
* Whether the DMA of frames to memory actually happens, regardless of (lack of) emission of the interrupt that tells us when said DMA finishes a frame.&lt;br /&gt;
* Whether the regulator messages we see during boot are actually significant. I don't know enough about the Linux regulator framework to say whether these being not-found means power is not correctly supplied, or if Linux just isn't being properly informed of the power supply requirements for precise tracking/power-saving when the camera is off.&lt;br /&gt;
&lt;br /&gt;
== Megi saves the day ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; you might be interested in this https://megous.com/dl/tmp/0ae6ba03a17a3d53.png&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; https://megous.com/git/linux/tag/?h=orange-pi-5.18-20220521-1759&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turns out, the .dts had the wrong ISP connected to the sensor! This is fixed in [https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9 this commit], which is included in kernel version 5.18 or newer.&lt;br /&gt;
&lt;br /&gt;
With a sufficiently new kernel, the following should produce an image (&amp;lt;code&amp;gt;frame.jpg&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;imx258 1-001a&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:2 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, you can take a photo from the front camera with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 [fmt:SBGGR10_1X10/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':0 [fmt:SBGGR10_1X10/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':2 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':0 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':1 [fmt:YUYV8_2X8/1632x1224]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, the isp exposes 2 devices nodes, and the nodes have separate topologies with a different sensor attached to each. In this situation, you may need to reference the isp using the correct device node for the commands to work.&lt;br /&gt;
&lt;br /&gt;
=== What's left? ===&lt;br /&gt;
&lt;br /&gt;
* libcamera and megapixels still don't work. Megapixels appears to need support for debayering YUYV, and both appear to be configuring the rkisp1 pipeline wrong.&lt;br /&gt;
* The images captured are pretty green and seem to have two pixels of garbage at their bottom edge. rkisp1 supports auto white-balance (AWB) using the params/stats pads, and libcamera has some smarts that may hook these up properly. In the meantime, raw images can be postprocessed to improve white balance and exposure.&lt;br /&gt;
&lt;br /&gt;
== Useful links == &lt;br /&gt;
&lt;br /&gt;
* [https://files.pine64.org/doc/PinePhonePro/PinephonePro-Schematic-V1.0-20211127.pdf Pinephone Pro Schematic]&lt;br /&gt;
* [https://blog.krybot.com/a?ID=01650-cea27a80-a1ab-4da1-9cb5-3945be91e3e1 Background on the GIC]&lt;br /&gt;
* [https://elinux.org/images/9/94/ISP-presentation.pdf Background on the rkisp1 ISP]&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13186</id>
		<title>PinePhone Pro/IMX258 Camera Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13186"/>
		<updated>2022-06-13T17:07:10Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: /* Megi saves the day */ Remove excess empty line&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Pinephone Pro's rear camera is a Sony IMX258. The camera driver is present upstream, and at least [https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro Manjaro's kernel] (downstream of Megi's) enables the driver. The camera does not seem to work; this page catalogs work on figuring out why.&lt;br /&gt;
&lt;br /&gt;
== Initial status ==&lt;br /&gt;
&lt;br /&gt;
What do we see in dmesg?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
imx258 1-001a: supply vana not found, using dummy regulator&lt;br /&gt;
imx258 1-001a: supply vdig not found, using dummy regulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the kernel loads the driver, which is something.&lt;br /&gt;
&lt;br /&gt;
Are these errors bad/fatal? Inspecting the [https://github.com/megous/linux/blob/orange-pi-5.17/drivers/media/i2c/imx258.c source] shows us that these supplies are defined in the &amp;lt;code&amp;gt;imx258_supply_names&amp;lt;/code&amp;gt; array, and &amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt; to set them up.&lt;br /&gt;
&amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; checks the return code from &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt;, emitting a fatal &amp;quot;Failed to get supplies&amp;quot; message if the return code is negative (indicating failure). Since we don't see this message (or any others from the driver), it looks like it loads successfully!&lt;br /&gt;
&lt;br /&gt;
=== How can we test the camera? ===&lt;br /&gt;
&lt;br /&gt;
==== Megapixels ====&lt;br /&gt;
&lt;br /&gt;
[https://gitlab.com/postmarketOS/megapixels Megapixels] requires a per-device file to configure cameras. This one isn't complete (most of its numbers are complete nonsense), but it should let us see what happens when Megapixels tries to access the camera:&lt;br /&gt;
&amp;lt;code&amp;gt;pine64,pinephone-pro.ini&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[device]&lt;br /&gt;
make=PINE64&lt;br /&gt;
model=PinePhone Pro&lt;br /&gt;
&lt;br /&gt;
[rear]&lt;br /&gt;
driver=imx258&lt;br /&gt;
media-driver=rkisp1&lt;br /&gt;
capture-width=4208&lt;br /&gt;
capture-height=3118&lt;br /&gt;
capture-rate=60&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
preview-width=1280&lt;br /&gt;
preview-height=960&lt;br /&gt;
preview-rate=60&lt;br /&gt;
#preview-fmt=BGGR8&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
rotate=90&lt;br /&gt;
mirrored=true&lt;br /&gt;
focallength=2.6&lt;br /&gt;
cropfactor=12.7&lt;br /&gt;
fnumber=2.8&lt;br /&gt;
flash-display=true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This segfaulted Megapixels for me. After patching some trivial segfaults, I get fatal GTK4 issues and other tangential problems. Let's try something else.&lt;br /&gt;
&lt;br /&gt;
==== Manually setting up a camera pipeline ====&lt;br /&gt;
&lt;br /&gt;
We can roughly follow [https://www.kernel.org/doc/html/latest/admin-guide/media/rkisp1.html this guide]. Doing so gives us the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=800,height=600,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--verbose&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Careful readers will note that this is setting the camera up with a low resolution compared to what the sensor can do. For some reason I can't get the rkisp1 node to configure its sink pad with the maximum resolution of the sensor (4208x3118). Instead, it sets itself to 4032x3024. This mismatch is forbidden and causes v4l2 to give us EPIPE when we try to enable the stream. Using the lower resolution gets us further--the last command (which attempts to save a single frame of video) gives output like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VIDIOC_QUERYCAP: ok&lt;br /&gt;
		VIDIOC_REQBUFS returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_STREAMON returned 0 (Success)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But then it just hangs there indefinitely.&lt;br /&gt;
&lt;br /&gt;
Running under strace, we see the program stuck in an ioctl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ioctl(3, VIDIOC_DQBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/vidioc-qbuf.html VIDIOC_DQBUF] corresponds to dequeuing a buffer once it has been filled with an image by the v4l2 device. Apparently, the device never gives us back a captured frame.&lt;br /&gt;
&lt;br /&gt;
=== Now what? ===&lt;br /&gt;
&lt;br /&gt;
==== Does i2c work at all? ====&lt;br /&gt;
&lt;br /&gt;
The camera driver uses i2c; we can see the camera [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts#L890-L914 in the .dts] to determine that it's on i2c bus 1, address 0x1a.&lt;br /&gt;
&lt;br /&gt;
The imx258 is controlled over i2c, and sends image data over MIPI. The first step is to see if the i2c control is working.&lt;br /&gt;
&lt;br /&gt;
Looking back at the driver, it seems we should see errors in dmesg if i2c communication fails. The driver checks the chip id in its probe function, which uses i2c, so we can conclude that i2c gets set up properly initially. Does it keep working?&lt;br /&gt;
&lt;br /&gt;
==== Does i2c keep working? (FTrace) ====&lt;br /&gt;
&lt;br /&gt;
We can see if other functions that use i2c produce errors--for example, when we run our &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command, we expect that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; will get called, and this function also writes a load of registers over i2c.&lt;br /&gt;
&lt;br /&gt;
Build and install a kernel with CONFIG_FTRACE (not hard, but outside the scope of this write-up) and enable function graph tracing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo su&lt;br /&gt;
# cd /sys/kernel/debug/tracing&lt;br /&gt;
# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
# cat available_filter_functions | grep -E 'rkisp|imx258|v4l2' | awk '{print $1}' &amp;gt; set_graph_function&lt;br /&gt;
# echo 'vm_map_pages,__iommu_map,iommu_map_sg_atomic,rk_iommu_map,__alloc_pages,dma_alloc_attrs,dma_mmap_attrs,__vm_map_pages,vb2_mmap,clk_e,able,schedule_timeout,clk_disable,regmap_write,schedule,__i2c_tra,sfer,i2c_tra,sfer_buffer_flags,dma_free_attrs' | tr , '\n' &amp;gt; set_graph_notrace&lt;br /&gt;
# tee trace_pipe &amp;gt; ~/function-trace.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in another terminal session, run the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command again. We end up with a bunch (but hopefully not *too* much) of output in our first terminal and the &amp;lt;code&amp;gt;~/function-trace.log&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
A quick grep shows that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; is indeed called, so '''i2c is working properly'''.&lt;br /&gt;
&lt;br /&gt;
=== If i2c works, what doesn't? ===&lt;br /&gt;
&lt;br /&gt;
Our program that asks for a video frame is still hung! We ask the camera to start streaming frames, it presumably does, but the v4l2 stack never tells us a frame has finished. Doing some digging in the v4l2 stack (and the rkisp1 driver), we find out that rkisp1 is notified about frame status via interrupts.&lt;br /&gt;
&lt;br /&gt;
Perhaps the hardware is never actually emitting the interrupt that signals a frame being finished. Indeed, grepping our FTrace log shows that &amp;lt;code&amp;gt;rkisp1_isr&amp;lt;/code&amp;gt; is never called. A quick look at &amp;lt;code&amp;gt;/proc/interrupts&amp;lt;/code&amp;gt; shows that '''the only interrupt associated with the isp has never triggered''' (0 count on every CPU):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# head -n1 /proc/interrupts; grep isp /proc/interrupts&lt;br /&gt;
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       &lt;br /&gt;
 57:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu, rkisp1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; debugfs info ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; driver keeps some [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h#L335-L363 error/debug counters] in debugfs, which can be viewed at &amp;lt;code&amp;gt;/sys/kernel/debug/ff910000.isp0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sadly, the only one of these that comes up nonzero is &amp;lt;code&amp;gt;sp_stop_timeout&amp;lt;/code&amp;gt; (&amp;quot;upon stream stop, the capture waits 1 second for the isr to stop the stream. This param is incremented in case of timeout&amp;quot;). I observe it to increment once per time I terminate the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command. This tells us what we already know: interrupts are not firing, but it also tells us that we aren't hitting any other errors that rkisp1 knows about.&lt;br /&gt;
&lt;br /&gt;
== Next steps ==&lt;br /&gt;
&lt;br /&gt;
Where do we go from here? I don't know--something may be wrong with the way the .dts specifies interrupts, some kind of firmware/GIC (the rk3399's interrupt controller) configuration issue, or something else. It would be good to try to determine:&lt;br /&gt;
&lt;br /&gt;
* Whether the MIPI lines actually show traffic, if someone has a logic analyzer and a dissected PPP.&lt;br /&gt;
* Whether the DMA of frames to memory actually happens, regardless of (lack of) emission of the interrupt that tells us when said DMA finishes a frame.&lt;br /&gt;
* Whether the regulator messages we see during boot are actually significant. I don't know enough about the Linux regulator framework to say whether these being not-found means power is not correctly supplied, or if Linux just isn't being properly informed of the power supply requirements for precise tracking/power-saving when the camera is off.&lt;br /&gt;
&lt;br /&gt;
== Megi saves the day ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; you might be interested in this https://megous.com/dl/tmp/0ae6ba03a17a3d53.png&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; https://megous.com/git/linux/tag/?h=orange-pi-5.18-20220521-1759&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turns out, the .dts had the wrong ISP connected to the sensor!&lt;br /&gt;
&lt;br /&gt;
Apply [https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9 this commit] ([https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9.patch patch]) to your kernel tree, rebuild, and reinstall. Now, the following should produce an image (&amp;lt;code&amp;gt;frame.jpg&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;imx258 1-001a&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:2 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, you can take a photo from the front camera with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 [fmt:SBGGR10_1X10/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':0 [fmt:SBGGR10_1X10/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':2 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':0 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':1 [fmt:YUYV8_2X8/1632x1224]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, the isp exposes 2 devices nodes, and the nodes have separate topologies with a different sensor attached to each. In this situation, you may need to reference the isp using the correct device node for the commands to work.&lt;br /&gt;
&lt;br /&gt;
=== What's left? ===&lt;br /&gt;
&lt;br /&gt;
* libcamera and megapixels still don't work. Megapixels appears to need support for debayering YUYV, and both appear to be configuring the rkisp1 pipeline wrong.&lt;br /&gt;
* The images captured are pretty green and seem to have two pixels of garbage at their bottom edge. rkisp1 supports auto white-balance (AWB) using the params/stats pads, and libcamera has some smarts that may hook these up properly. In the meantime, raw images can be postprocessed to improve white balance and exposure.&lt;br /&gt;
&lt;br /&gt;
== Useful links == &lt;br /&gt;
&lt;br /&gt;
* [https://files.pine64.org/doc/PinePhonePro/PinephonePro-Schematic-V1.0-20211127.pdf Pinephone Pro Schematic]&lt;br /&gt;
* [https://blog.krybot.com/a?ID=01650-cea27a80-a1ab-4da1-9cb5-3945be91e3e1 Background on the GIC]&lt;br /&gt;
* [https://elinux.org/images/9/94/ISP-presentation.pdf Background on the rkisp1 ISP]&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13185</id>
		<title>PinePhone Pro/IMX258 Camera Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13185"/>
		<updated>2022-06-13T17:04:48Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: /* Megi saves the day */ Fix typo in the commands for front camera&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Pinephone Pro's rear camera is a Sony IMX258. The camera driver is present upstream, and at least [https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro Manjaro's kernel] (downstream of Megi's) enables the driver. The camera does not seem to work; this page catalogs work on figuring out why.&lt;br /&gt;
&lt;br /&gt;
== Initial status ==&lt;br /&gt;
&lt;br /&gt;
What do we see in dmesg?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
imx258 1-001a: supply vana not found, using dummy regulator&lt;br /&gt;
imx258 1-001a: supply vdig not found, using dummy regulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the kernel loads the driver, which is something.&lt;br /&gt;
&lt;br /&gt;
Are these errors bad/fatal? Inspecting the [https://github.com/megous/linux/blob/orange-pi-5.17/drivers/media/i2c/imx258.c source] shows us that these supplies are defined in the &amp;lt;code&amp;gt;imx258_supply_names&amp;lt;/code&amp;gt; array, and &amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt; to set them up.&lt;br /&gt;
&amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; checks the return code from &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt;, emitting a fatal &amp;quot;Failed to get supplies&amp;quot; message if the return code is negative (indicating failure). Since we don't see this message (or any others from the driver), it looks like it loads successfully!&lt;br /&gt;
&lt;br /&gt;
=== How can we test the camera? ===&lt;br /&gt;
&lt;br /&gt;
==== Megapixels ====&lt;br /&gt;
&lt;br /&gt;
[https://gitlab.com/postmarketOS/megapixels Megapixels] requires a per-device file to configure cameras. This one isn't complete (most of its numbers are complete nonsense), but it should let us see what happens when Megapixels tries to access the camera:&lt;br /&gt;
&amp;lt;code&amp;gt;pine64,pinephone-pro.ini&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[device]&lt;br /&gt;
make=PINE64&lt;br /&gt;
model=PinePhone Pro&lt;br /&gt;
&lt;br /&gt;
[rear]&lt;br /&gt;
driver=imx258&lt;br /&gt;
media-driver=rkisp1&lt;br /&gt;
capture-width=4208&lt;br /&gt;
capture-height=3118&lt;br /&gt;
capture-rate=60&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
preview-width=1280&lt;br /&gt;
preview-height=960&lt;br /&gt;
preview-rate=60&lt;br /&gt;
#preview-fmt=BGGR8&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
rotate=90&lt;br /&gt;
mirrored=true&lt;br /&gt;
focallength=2.6&lt;br /&gt;
cropfactor=12.7&lt;br /&gt;
fnumber=2.8&lt;br /&gt;
flash-display=true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This segfaulted Megapixels for me. After patching some trivial segfaults, I get fatal GTK4 issues and other tangential problems. Let's try something else.&lt;br /&gt;
&lt;br /&gt;
==== Manually setting up a camera pipeline ====&lt;br /&gt;
&lt;br /&gt;
We can roughly follow [https://www.kernel.org/doc/html/latest/admin-guide/media/rkisp1.html this guide]. Doing so gives us the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=800,height=600,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--verbose&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Careful readers will note that this is setting the camera up with a low resolution compared to what the sensor can do. For some reason I can't get the rkisp1 node to configure its sink pad with the maximum resolution of the sensor (4208x3118). Instead, it sets itself to 4032x3024. This mismatch is forbidden and causes v4l2 to give us EPIPE when we try to enable the stream. Using the lower resolution gets us further--the last command (which attempts to save a single frame of video) gives output like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VIDIOC_QUERYCAP: ok&lt;br /&gt;
		VIDIOC_REQBUFS returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_STREAMON returned 0 (Success)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But then it just hangs there indefinitely.&lt;br /&gt;
&lt;br /&gt;
Running under strace, we see the program stuck in an ioctl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ioctl(3, VIDIOC_DQBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/vidioc-qbuf.html VIDIOC_DQBUF] corresponds to dequeuing a buffer once it has been filled with an image by the v4l2 device. Apparently, the device never gives us back a captured frame.&lt;br /&gt;
&lt;br /&gt;
=== Now what? ===&lt;br /&gt;
&lt;br /&gt;
==== Does i2c work at all? ====&lt;br /&gt;
&lt;br /&gt;
The camera driver uses i2c; we can see the camera [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts#L890-L914 in the .dts] to determine that it's on i2c bus 1, address 0x1a.&lt;br /&gt;
&lt;br /&gt;
The imx258 is controlled over i2c, and sends image data over MIPI. The first step is to see if the i2c control is working.&lt;br /&gt;
&lt;br /&gt;
Looking back at the driver, it seems we should see errors in dmesg if i2c communication fails. The driver checks the chip id in its probe function, which uses i2c, so we can conclude that i2c gets set up properly initially. Does it keep working?&lt;br /&gt;
&lt;br /&gt;
==== Does i2c keep working? (FTrace) ====&lt;br /&gt;
&lt;br /&gt;
We can see if other functions that use i2c produce errors--for example, when we run our &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command, we expect that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; will get called, and this function also writes a load of registers over i2c.&lt;br /&gt;
&lt;br /&gt;
Build and install a kernel with CONFIG_FTRACE (not hard, but outside the scope of this write-up) and enable function graph tracing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo su&lt;br /&gt;
# cd /sys/kernel/debug/tracing&lt;br /&gt;
# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
# cat available_filter_functions | grep -E 'rkisp|imx258|v4l2' | awk '{print $1}' &amp;gt; set_graph_function&lt;br /&gt;
# echo 'vm_map_pages,__iommu_map,iommu_map_sg_atomic,rk_iommu_map,__alloc_pages,dma_alloc_attrs,dma_mmap_attrs,__vm_map_pages,vb2_mmap,clk_e,able,schedule_timeout,clk_disable,regmap_write,schedule,__i2c_tra,sfer,i2c_tra,sfer_buffer_flags,dma_free_attrs' | tr , '\n' &amp;gt; set_graph_notrace&lt;br /&gt;
# tee trace_pipe &amp;gt; ~/function-trace.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in another terminal session, run the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command again. We end up with a bunch (but hopefully not *too* much) of output in our first terminal and the &amp;lt;code&amp;gt;~/function-trace.log&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
A quick grep shows that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; is indeed called, so '''i2c is working properly'''.&lt;br /&gt;
&lt;br /&gt;
=== If i2c works, what doesn't? ===&lt;br /&gt;
&lt;br /&gt;
Our program that asks for a video frame is still hung! We ask the camera to start streaming frames, it presumably does, but the v4l2 stack never tells us a frame has finished. Doing some digging in the v4l2 stack (and the rkisp1 driver), we find out that rkisp1 is notified about frame status via interrupts.&lt;br /&gt;
&lt;br /&gt;
Perhaps the hardware is never actually emitting the interrupt that signals a frame being finished. Indeed, grepping our FTrace log shows that &amp;lt;code&amp;gt;rkisp1_isr&amp;lt;/code&amp;gt; is never called. A quick look at &amp;lt;code&amp;gt;/proc/interrupts&amp;lt;/code&amp;gt; shows that '''the only interrupt associated with the isp has never triggered''' (0 count on every CPU):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# head -n1 /proc/interrupts; grep isp /proc/interrupts&lt;br /&gt;
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       &lt;br /&gt;
 57:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu, rkisp1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; debugfs info ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; driver keeps some [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h#L335-L363 error/debug counters] in debugfs, which can be viewed at &amp;lt;code&amp;gt;/sys/kernel/debug/ff910000.isp0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sadly, the only one of these that comes up nonzero is &amp;lt;code&amp;gt;sp_stop_timeout&amp;lt;/code&amp;gt; (&amp;quot;upon stream stop, the capture waits 1 second for the isr to stop the stream. This param is incremented in case of timeout&amp;quot;). I observe it to increment once per time I terminate the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command. This tells us what we already know: interrupts are not firing, but it also tells us that we aren't hitting any other errors that rkisp1 knows about.&lt;br /&gt;
&lt;br /&gt;
== Next steps ==&lt;br /&gt;
&lt;br /&gt;
Where do we go from here? I don't know--something may be wrong with the way the .dts specifies interrupts, some kind of firmware/GIC (the rk3399's interrupt controller) configuration issue, or something else. It would be good to try to determine:&lt;br /&gt;
&lt;br /&gt;
* Whether the MIPI lines actually show traffic, if someone has a logic analyzer and a dissected PPP.&lt;br /&gt;
* Whether the DMA of frames to memory actually happens, regardless of (lack of) emission of the interrupt that tells us when said DMA finishes a frame.&lt;br /&gt;
* Whether the regulator messages we see during boot are actually significant. I don't know enough about the Linux regulator framework to say whether these being not-found means power is not correctly supplied, or if Linux just isn't being properly informed of the power supply requirements for precise tracking/power-saving when the camera is off.&lt;br /&gt;
&lt;br /&gt;
== Megi saves the day ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; you might be interested in this https://megous.com/dl/tmp/0ae6ba03a17a3d53.png&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; https://megous.com/git/linux/tag/?h=orange-pi-5.18-20220521-1759&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turns out, the .dts had the wrong ISP connected to the sensor!&lt;br /&gt;
&lt;br /&gt;
Apply [https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9 this commit] ([https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9.patch patch]) to your kernel tree, rebuild, and reinstall. Now, the following should produce an image (&amp;lt;code&amp;gt;frame.jpg&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;imx258 1-001a&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:2 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, you can take a photo from the front camera with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 [fmt:SBGGR10_1X10/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':0 [fmt:SBGGR10_1X10/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':2 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':0 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':1 [fmt:YUYV8_2X8/1632x1224]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, the isp exposes 2 devices nodes, and the nodes have separate topologies with a different sensor attached to each. In this situation, you may need to reference the isp using the correct device node for the commands to work.&lt;br /&gt;
&lt;br /&gt;
=== What's left? ===&lt;br /&gt;
&lt;br /&gt;
* libcamera and megapixels still don't work. Megapixels appears to need support for debayering YUYV, and both appear to be configuring the rkisp1 pipeline wrong.&lt;br /&gt;
* The images captured are pretty green and seem to have two pixels of garbage at their bottom edge. rkisp1 supports auto white-balance (AWB) using the params/stats pads, and libcamera has some smarts that may hook these up properly. In the meantime, raw images can be postprocessed to improve white balance and exposure.&lt;br /&gt;
&lt;br /&gt;
== Useful links == &lt;br /&gt;
&lt;br /&gt;
* [https://files.pine64.org/doc/PinePhonePro/PinephonePro-Schematic-V1.0-20211127.pdf Pinephone Pro Schematic]&lt;br /&gt;
* [https://blog.krybot.com/a?ID=01650-cea27a80-a1ab-4da1-9cb5-3945be91e3e1 Background on the GIC]&lt;br /&gt;
* [https://elinux.org/images/9/94/ISP-presentation.pdf Background on the rkisp1 ISP]&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13184</id>
		<title>PinePhone Pro/IMX258 Camera Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13184"/>
		<updated>2022-06-13T17:01:59Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: /* Megi saves the day */ Add info about the case where the isp has 2 device nodes&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Pinephone Pro's rear camera is a Sony IMX258. The camera driver is present upstream, and at least [https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro Manjaro's kernel] (downstream of Megi's) enables the driver. The camera does not seem to work; this page catalogs work on figuring out why.&lt;br /&gt;
&lt;br /&gt;
== Initial status ==&lt;br /&gt;
&lt;br /&gt;
What do we see in dmesg?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
imx258 1-001a: supply vana not found, using dummy regulator&lt;br /&gt;
imx258 1-001a: supply vdig not found, using dummy regulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the kernel loads the driver, which is something.&lt;br /&gt;
&lt;br /&gt;
Are these errors bad/fatal? Inspecting the [https://github.com/megous/linux/blob/orange-pi-5.17/drivers/media/i2c/imx258.c source] shows us that these supplies are defined in the &amp;lt;code&amp;gt;imx258_supply_names&amp;lt;/code&amp;gt; array, and &amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt; to set them up.&lt;br /&gt;
&amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; checks the return code from &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt;, emitting a fatal &amp;quot;Failed to get supplies&amp;quot; message if the return code is negative (indicating failure). Since we don't see this message (or any others from the driver), it looks like it loads successfully!&lt;br /&gt;
&lt;br /&gt;
=== How can we test the camera? ===&lt;br /&gt;
&lt;br /&gt;
==== Megapixels ====&lt;br /&gt;
&lt;br /&gt;
[https://gitlab.com/postmarketOS/megapixels Megapixels] requires a per-device file to configure cameras. This one isn't complete (most of its numbers are complete nonsense), but it should let us see what happens when Megapixels tries to access the camera:&lt;br /&gt;
&amp;lt;code&amp;gt;pine64,pinephone-pro.ini&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[device]&lt;br /&gt;
make=PINE64&lt;br /&gt;
model=PinePhone Pro&lt;br /&gt;
&lt;br /&gt;
[rear]&lt;br /&gt;
driver=imx258&lt;br /&gt;
media-driver=rkisp1&lt;br /&gt;
capture-width=4208&lt;br /&gt;
capture-height=3118&lt;br /&gt;
capture-rate=60&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
preview-width=1280&lt;br /&gt;
preview-height=960&lt;br /&gt;
preview-rate=60&lt;br /&gt;
#preview-fmt=BGGR8&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
rotate=90&lt;br /&gt;
mirrored=true&lt;br /&gt;
focallength=2.6&lt;br /&gt;
cropfactor=12.7&lt;br /&gt;
fnumber=2.8&lt;br /&gt;
flash-display=true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This segfaulted Megapixels for me. After patching some trivial segfaults, I get fatal GTK4 issues and other tangential problems. Let's try something else.&lt;br /&gt;
&lt;br /&gt;
==== Manually setting up a camera pipeline ====&lt;br /&gt;
&lt;br /&gt;
We can roughly follow [https://www.kernel.org/doc/html/latest/admin-guide/media/rkisp1.html this guide]. Doing so gives us the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=800,height=600,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--verbose&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Careful readers will note that this is setting the camera up with a low resolution compared to what the sensor can do. For some reason I can't get the rkisp1 node to configure its sink pad with the maximum resolution of the sensor (4208x3118). Instead, it sets itself to 4032x3024. This mismatch is forbidden and causes v4l2 to give us EPIPE when we try to enable the stream. Using the lower resolution gets us further--the last command (which attempts to save a single frame of video) gives output like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VIDIOC_QUERYCAP: ok&lt;br /&gt;
		VIDIOC_REQBUFS returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_STREAMON returned 0 (Success)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But then it just hangs there indefinitely.&lt;br /&gt;
&lt;br /&gt;
Running under strace, we see the program stuck in an ioctl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ioctl(3, VIDIOC_DQBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/vidioc-qbuf.html VIDIOC_DQBUF] corresponds to dequeuing a buffer once it has been filled with an image by the v4l2 device. Apparently, the device never gives us back a captured frame.&lt;br /&gt;
&lt;br /&gt;
=== Now what? ===&lt;br /&gt;
&lt;br /&gt;
==== Does i2c work at all? ====&lt;br /&gt;
&lt;br /&gt;
The camera driver uses i2c; we can see the camera [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts#L890-L914 in the .dts] to determine that it's on i2c bus 1, address 0x1a.&lt;br /&gt;
&lt;br /&gt;
The imx258 is controlled over i2c, and sends image data over MIPI. The first step is to see if the i2c control is working.&lt;br /&gt;
&lt;br /&gt;
Looking back at the driver, it seems we should see errors in dmesg if i2c communication fails. The driver checks the chip id in its probe function, which uses i2c, so we can conclude that i2c gets set up properly initially. Does it keep working?&lt;br /&gt;
&lt;br /&gt;
==== Does i2c keep working? (FTrace) ====&lt;br /&gt;
&lt;br /&gt;
We can see if other functions that use i2c produce errors--for example, when we run our &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command, we expect that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; will get called, and this function also writes a load of registers over i2c.&lt;br /&gt;
&lt;br /&gt;
Build and install a kernel with CONFIG_FTRACE (not hard, but outside the scope of this write-up) and enable function graph tracing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo su&lt;br /&gt;
# cd /sys/kernel/debug/tracing&lt;br /&gt;
# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
# cat available_filter_functions | grep -E 'rkisp|imx258|v4l2' | awk '{print $1}' &amp;gt; set_graph_function&lt;br /&gt;
# echo 'vm_map_pages,__iommu_map,iommu_map_sg_atomic,rk_iommu_map,__alloc_pages,dma_alloc_attrs,dma_mmap_attrs,__vm_map_pages,vb2_mmap,clk_e,able,schedule_timeout,clk_disable,regmap_write,schedule,__i2c_tra,sfer,i2c_tra,sfer_buffer_flags,dma_free_attrs' | tr , '\n' &amp;gt; set_graph_notrace&lt;br /&gt;
# tee trace_pipe &amp;gt; ~/function-trace.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in another terminal session, run the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command again. We end up with a bunch (but hopefully not *too* much) of output in our first terminal and the &amp;lt;code&amp;gt;~/function-trace.log&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
A quick grep shows that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; is indeed called, so '''i2c is working properly'''.&lt;br /&gt;
&lt;br /&gt;
=== If i2c works, what doesn't? ===&lt;br /&gt;
&lt;br /&gt;
Our program that asks for a video frame is still hung! We ask the camera to start streaming frames, it presumably does, but the v4l2 stack never tells us a frame has finished. Doing some digging in the v4l2 stack (and the rkisp1 driver), we find out that rkisp1 is notified about frame status via interrupts.&lt;br /&gt;
&lt;br /&gt;
Perhaps the hardware is never actually emitting the interrupt that signals a frame being finished. Indeed, grepping our FTrace log shows that &amp;lt;code&amp;gt;rkisp1_isr&amp;lt;/code&amp;gt; is never called. A quick look at &amp;lt;code&amp;gt;/proc/interrupts&amp;lt;/code&amp;gt; shows that '''the only interrupt associated with the isp has never triggered''' (0 count on every CPU):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# head -n1 /proc/interrupts; grep isp /proc/interrupts&lt;br /&gt;
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       &lt;br /&gt;
 57:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu, rkisp1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; debugfs info ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; driver keeps some [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h#L335-L363 error/debug counters] in debugfs, which can be viewed at &amp;lt;code&amp;gt;/sys/kernel/debug/ff910000.isp0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sadly, the only one of these that comes up nonzero is &amp;lt;code&amp;gt;sp_stop_timeout&amp;lt;/code&amp;gt; (&amp;quot;upon stream stop, the capture waits 1 second for the isr to stop the stream. This param is incremented in case of timeout&amp;quot;). I observe it to increment once per time I terminate the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command. This tells us what we already know: interrupts are not firing, but it also tells us that we aren't hitting any other errors that rkisp1 knows about.&lt;br /&gt;
&lt;br /&gt;
== Next steps ==&lt;br /&gt;
&lt;br /&gt;
Where do we go from here? I don't know--something may be wrong with the way the .dts specifies interrupts, some kind of firmware/GIC (the rk3399's interrupt controller) configuration issue, or something else. It would be good to try to determine:&lt;br /&gt;
&lt;br /&gt;
* Whether the MIPI lines actually show traffic, if someone has a logic analyzer and a dissected PPP.&lt;br /&gt;
* Whether the DMA of frames to memory actually happens, regardless of (lack of) emission of the interrupt that tells us when said DMA finishes a frame.&lt;br /&gt;
* Whether the regulator messages we see during boot are actually significant. I don't know enough about the Linux regulator framework to say whether these being not-found means power is not correctly supplied, or if Linux just isn't being properly informed of the power supply requirements for precise tracking/power-saving when the camera is off.&lt;br /&gt;
&lt;br /&gt;
== Megi saves the day ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; you might be interested in this https://megous.com/dl/tmp/0ae6ba03a17a3d53.png&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; https://megous.com/git/linux/tag/?h=orange-pi-5.18-20220521-1759&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turns out, the .dts had the wrong ISP connected to the sensor!&lt;br /&gt;
&lt;br /&gt;
Apply [https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9 this commit] ([https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9.patch patch]) to your kernel tree, rebuild, and reinstall. Now, the following should produce an image (&amp;lt;code&amp;gt;frame.jpg&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;imx258 1-001a&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:2 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, you can take a photo from the front camera with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 [fmt:SBGGR10_1X10/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':0 [fmt:SBGGR10_1X10/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':2 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':0 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':1 [fmt:YUYV8_2X8/1632x1224]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In some cases, the isp exposes 2 devices nodes, and the nodes have separate topologies with a different sensor attached to each. In this situation, you may need to reference the isp using the correct device node for the commands to work.&lt;br /&gt;
&lt;br /&gt;
=== What's left? ===&lt;br /&gt;
&lt;br /&gt;
* libcamera and megapixels still don't work. Megapixels appears to need support for debayering YUYV, and both appear to be configuring the rkisp1 pipeline wrong.&lt;br /&gt;
* The images captured are pretty green and seem to have two pixels of garbage at their bottom edge. rkisp1 supports auto white-balance (AWB) using the params/stats pads, and libcamera has some smarts that may hook these up properly. In the meantime, raw images can be postprocessed to improve white balance and exposure.&lt;br /&gt;
&lt;br /&gt;
== Useful links == &lt;br /&gt;
&lt;br /&gt;
* [https://files.pine64.org/doc/PinePhonePro/PinephonePro-Schematic-V1.0-20211127.pdf Pinephone Pro Schematic]&lt;br /&gt;
* [https://blog.krybot.com/a?ID=01650-cea27a80-a1ab-4da1-9cb5-3945be91e3e1 Background on the GIC]&lt;br /&gt;
* [https://elinux.org/images/9/94/ISP-presentation.pdf Background on the rkisp1 ISP]&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13183</id>
		<title>PinePhone Pro/IMX258 Camera Debugging</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro/IMX258_Camera_Debugging&amp;diff=13183"/>
		<updated>2022-06-13T16:48:31Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: /* Megi saves the day */ Add commands for front camera&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Under construction}}&lt;br /&gt;
&lt;br /&gt;
== Background ==&lt;br /&gt;
&lt;br /&gt;
The Pinephone Pro's rear camera is a Sony IMX258. The camera driver is present upstream, and at least [https://gitlab.manjaro.org/manjaro-arm/packages/core/linux-pinephonepro Manjaro's kernel] (downstream of Megi's) enables the driver. The camera does not seem to work; this page catalogs work on figuring out why.&lt;br /&gt;
&lt;br /&gt;
== Initial status ==&lt;br /&gt;
&lt;br /&gt;
What do we see in dmesg?&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
imx258 1-001a: supply vana not found, using dummy regulator&lt;br /&gt;
imx258 1-001a: supply vdig not found, using dummy regulator&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This tells us the kernel loads the driver, which is something.&lt;br /&gt;
&lt;br /&gt;
Are these errors bad/fatal? Inspecting the [https://github.com/megous/linux/blob/orange-pi-5.17/drivers/media/i2c/imx258.c source] shows us that these supplies are defined in the &amp;lt;code&amp;gt;imx258_supply_names&amp;lt;/code&amp;gt; array, and &amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; calls &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt; to set them up.&lt;br /&gt;
&amp;lt;code&amp;gt;imx258_probe&amp;lt;/code&amp;gt; checks the return code from &amp;lt;code&amp;gt;devm_regulator_bulk_get&amp;lt;/code&amp;gt;, emitting a fatal &amp;quot;Failed to get supplies&amp;quot; message if the return code is negative (indicating failure). Since we don't see this message (or any others from the driver), it looks like it loads successfully!&lt;br /&gt;
&lt;br /&gt;
=== How can we test the camera? ===&lt;br /&gt;
&lt;br /&gt;
==== Megapixels ====&lt;br /&gt;
&lt;br /&gt;
[https://gitlab.com/postmarketOS/megapixels Megapixels] requires a per-device file to configure cameras. This one isn't complete (most of its numbers are complete nonsense), but it should let us see what happens when Megapixels tries to access the camera:&lt;br /&gt;
&amp;lt;code&amp;gt;pine64,pinephone-pro.ini&amp;lt;/code&amp;gt;:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[device]&lt;br /&gt;
make=PINE64&lt;br /&gt;
model=PinePhone Pro&lt;br /&gt;
&lt;br /&gt;
[rear]&lt;br /&gt;
driver=imx258&lt;br /&gt;
media-driver=rkisp1&lt;br /&gt;
capture-width=4208&lt;br /&gt;
capture-height=3118&lt;br /&gt;
capture-rate=60&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
preview-width=1280&lt;br /&gt;
preview-height=960&lt;br /&gt;
preview-rate=60&lt;br /&gt;
#preview-fmt=BGGR8&lt;br /&gt;
capture-fmt=GRBG10P&lt;br /&gt;
rotate=90&lt;br /&gt;
mirrored=true&lt;br /&gt;
focallength=2.6&lt;br /&gt;
cropfactor=12.7&lt;br /&gt;
fnumber=2.8&lt;br /&gt;
flash-display=true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This segfaulted Megapixels for me. After patching some trivial segfaults, I get fatal GTK4 issues and other tangential problems. Let's try something else.&lt;br /&gt;
&lt;br /&gt;
==== Manually setting up a camera pipeline ====&lt;br /&gt;
&lt;br /&gt;
We can roughly follow [https://www.kernel.org/doc/html/latest/admin-guide/media/rkisp1.html this guide]. Doing so gives us the following commands:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=800,height=600,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--verbose&amp;quot;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Careful readers will note that this is setting the camera up with a low resolution compared to what the sensor can do. For some reason I can't get the rkisp1 node to configure its sink pad with the maximum resolution of the sensor (4208x3118). Instead, it sets itself to 4032x3024. This mismatch is forbidden and causes v4l2 to give us EPIPE when we try to enable the stream. Using the lower resolution gets us further--the last command (which attempts to save a single frame of video) gives output like this:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
VIDIOC_QUERYCAP: ok&lt;br /&gt;
		VIDIOC_REQBUFS returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QUERYBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_QBUF returned 0 (Success)&lt;br /&gt;
		VIDIOC_STREAMON returned 0 (Success)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
But then it just hangs there indefinitely.&lt;br /&gt;
&lt;br /&gt;
Running under strace, we see the program stuck in an ioctl:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
ioctl(3, VIDIOC_DQBUF, {type=V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[https://www.kernel.org/doc/html/v4.13/media/uapi/v4l/vidioc-qbuf.html VIDIOC_DQBUF] corresponds to dequeuing a buffer once it has been filled with an image by the v4l2 device. Apparently, the device never gives us back a captured frame.&lt;br /&gt;
&lt;br /&gt;
=== Now what? ===&lt;br /&gt;
&lt;br /&gt;
==== Does i2c work at all? ====&lt;br /&gt;
&lt;br /&gt;
The camera driver uses i2c; we can see the camera [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/arch/arm64/boot/dts/rockchip/rk3399-pinephone-pro.dts#L890-L914 in the .dts] to determine that it's on i2c bus 1, address 0x1a.&lt;br /&gt;
&lt;br /&gt;
The imx258 is controlled over i2c, and sends image data over MIPI. The first step is to see if the i2c control is working.&lt;br /&gt;
&lt;br /&gt;
Looking back at the driver, it seems we should see errors in dmesg if i2c communication fails. The driver checks the chip id in its probe function, which uses i2c, so we can conclude that i2c gets set up properly initially. Does it keep working?&lt;br /&gt;
&lt;br /&gt;
==== Does i2c keep working? (FTrace) ====&lt;br /&gt;
&lt;br /&gt;
We can see if other functions that use i2c produce errors--for example, when we run our &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command, we expect that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; will get called, and this function also writes a load of registers over i2c.&lt;br /&gt;
&lt;br /&gt;
Build and install a kernel with CONFIG_FTRACE (not hard, but outside the scope of this write-up) and enable function graph tracing:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
$ sudo su&lt;br /&gt;
# cd /sys/kernel/debug/tracing&lt;br /&gt;
# echo function_graph &amp;gt; current_tracer&lt;br /&gt;
# cat available_filter_functions | grep -E 'rkisp|imx258|v4l2' | awk '{print $1}' &amp;gt; set_graph_function&lt;br /&gt;
# echo 'vm_map_pages,__iommu_map,iommu_map_sg_atomic,rk_iommu_map,__alloc_pages,dma_alloc_attrs,dma_mmap_attrs,__vm_map_pages,vb2_mmap,clk_e,able,schedule_timeout,clk_disable,regmap_write,schedule,__i2c_tra,sfer,i2c_tra,sfer_buffer_flags,dma_free_attrs' | tr , '\n' &amp;gt; set_graph_notrace&lt;br /&gt;
# tee trace_pipe &amp;gt; ~/function-trace.log&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now, in another terminal session, run the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command again. We end up with a bunch (but hopefully not *too* much) of output in our first terminal and the &amp;lt;code&amp;gt;~/function-trace.log&amp;lt;/code&amp;gt; file.&lt;br /&gt;
&lt;br /&gt;
A quick grep shows that &amp;lt;code&amp;gt;imx258_start_streaming&amp;lt;/code&amp;gt; is indeed called, so '''i2c is working properly'''.&lt;br /&gt;
&lt;br /&gt;
=== If i2c works, what doesn't? ===&lt;br /&gt;
&lt;br /&gt;
Our program that asks for a video frame is still hung! We ask the camera to start streaming frames, it presumably does, but the v4l2 stack never tells us a frame has finished. Doing some digging in the v4l2 stack (and the rkisp1 driver), we find out that rkisp1 is notified about frame status via interrupts.&lt;br /&gt;
&lt;br /&gt;
Perhaps the hardware is never actually emitting the interrupt that signals a frame being finished. Indeed, grepping our FTrace log shows that &amp;lt;code&amp;gt;rkisp1_isr&amp;lt;/code&amp;gt; is never called. A quick look at &amp;lt;code&amp;gt;/proc/interrupts&amp;lt;/code&amp;gt; shows that '''the only interrupt associated with the isp has never triggered''' (0 count on every CPU):&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# head -n1 /proc/interrupts; grep isp /proc/interrupts&lt;br /&gt;
           CPU0       CPU1       CPU2       CPU3       CPU4       CPU5       &lt;br /&gt;
 57:          0          0          0          0          0          0     GICv3  75 Level     ff914000.iommu, rkisp1&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; debugfs info ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;rkisp1&amp;lt;/code&amp;gt; driver keeps some [https://github.com/megous/linux/blob/c5af9f4f874a66b65c73c450b79f6a86b1b46332/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h#L335-L363 error/debug counters] in debugfs, which can be viewed at &amp;lt;code&amp;gt;/sys/kernel/debug/ff910000.isp0&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Sadly, the only one of these that comes up nonzero is &amp;lt;code&amp;gt;sp_stop_timeout&amp;lt;/code&amp;gt; (&amp;quot;upon stream stop, the capture waits 1 second for the isr to stop the stream. This param is incremented in case of timeout&amp;quot;). I observe it to increment once per time I terminate the &amp;lt;code&amp;gt;&amp;quot;v4l2-ctl&amp;quot; ... &amp;quot;--stream-mmap&amp;quot;&amp;lt;/code&amp;gt; command. This tells us what we already know: interrupts are not firing, but it also tells us that we aren't hitting any other errors that rkisp1 knows about.&lt;br /&gt;
&lt;br /&gt;
== Next steps ==&lt;br /&gt;
&lt;br /&gt;
Where do we go from here? I don't know--something may be wrong with the way the .dts specifies interrupts, some kind of firmware/GIC (the rk3399's interrupt controller) configuration issue, or something else. It would be good to try to determine:&lt;br /&gt;
&lt;br /&gt;
* Whether the MIPI lines actually show traffic, if someone has a logic analyzer and a dissected PPP.&lt;br /&gt;
* Whether the DMA of frames to memory actually happens, regardless of (lack of) emission of the interrupt that tells us when said DMA finishes a frame.&lt;br /&gt;
* Whether the regulator messages we see during boot are actually significant. I don't know enough about the Linux regulator framework to say whether these being not-found means power is not correctly supplied, or if Linux just isn't being properly informed of the power supply requirements for precise tracking/power-saving when the camera is off.&lt;br /&gt;
&lt;br /&gt;
== Megi saves the day ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; you might be interested in this https://megous.com/dl/tmp/0ae6ba03a17a3d53.png&lt;br /&gt;
[I] &amp;lt;megi&amp;gt; https://megous.com/git/linux/tag/?h=orange-pi-5.18-20220521-1759&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Turns out, the .dts had the wrong ISP connected to the sensor!&lt;br /&gt;
&lt;br /&gt;
Apply [https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9 this commit] ([https://github.com/megous/linux/commit/9afd884f8b36121fb6097e77b6d35fe46ab48ad9.patch patch]) to your kernel tree, rebuild, and reinstall. Now, the following should produce an image (&amp;lt;code&amp;gt;frame.jpg&amp;lt;/code&amp;gt;):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;imx258 1-001a&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'imx258 1-001a':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:0 [fmt:SGRBG10_1X10/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_isp&amp;quot;:2 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; '&amp;quot;rkisp1_resizer_selfpath&amp;quot;:0 [fmt:YUYV8_2X8/1048x780 crop:(0,0)/1048x780]'&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1048,height=780,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Similarly, you can take a photo from the front camera with the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;-r&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 [fmt:SBGGR10_1X10/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'m00_f_ov8858 1-0036':0 -&amp;gt; 'rkisp1_isp':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;-l&amp;quot; &amp;quot;'rkisp1_isp':2 -&amp;gt; 'rkisp1_resizer_selfpath':0 [1]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':0 [fmt:SBGGR10_1X10/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_isp':2 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':0 [fmt:YUYV8_2X8/1632x1224 crop:(0,0)/1632x1224]&amp;quot;&lt;br /&gt;
&amp;quot;media-ctl&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;pltform:rkisp1&amp;quot; &amp;quot;--set-v4l2&amp;quot; &amp;quot;'rkisp1_resizer_selfpath':1 [fmt:YUYV8_2X8/1632x1224]&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;-v&amp;quot; &amp;quot;width=1632,height=1224,pixelformat=422P&amp;quot;&lt;br /&gt;
&amp;quot;v4l2-ctl&amp;quot; &amp;quot;-z&amp;quot; &amp;quot;platform:rkisp1&amp;quot; &amp;quot;-d&amp;quot; &amp;quot;rkisp1_selfpath&amp;quot; &amp;quot;--stream-mmap&amp;quot; &amp;quot;--stream-count&amp;quot; &amp;quot;1&amp;quot; &amp;quot;--stream-to=frame.raw&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ffmpeg -y -s:v 1048x780 -pix_fmt yuv422p -i frame.raw frame.jpg&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== What's left? ===&lt;br /&gt;
&lt;br /&gt;
* libcamera and megapixels still don't work. Megapixels appears to need support for debayering YUYV, and both appear to be configuring the rkisp1 pipeline wrong.&lt;br /&gt;
* The images captured are pretty green and seem to have two pixels of garbage at their bottom edge. rkisp1 supports auto white-balance (AWB) using the params/stats pads, and libcamera has some smarts that may hook these up properly. In the meantime, raw images can be postprocessed to improve white balance and exposure.&lt;br /&gt;
&lt;br /&gt;
== Useful links == &lt;br /&gt;
&lt;br /&gt;
* [https://files.pine64.org/doc/PinePhonePro/PinephonePro-Schematic-V1.0-20211127.pdf Pinephone Pro Schematic]&lt;br /&gt;
* [https://blog.krybot.com/a?ID=01650-cea27a80-a1ab-4da1-9cb5-3945be91e3e1 Background on the GIC]&lt;br /&gt;
* [https://elinux.org/images/9/94/ISP-presentation.pdf Background on the rkisp1 ISP]&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
	<entry>
		<id>https://wiki.pine64.org/index.php?title=PinePhone_Pro_Software_State&amp;diff=13182</id>
		<title>PinePhone Pro Software State</title>
		<link rel="alternate" type="text/html" href="https://wiki.pine64.org/index.php?title=PinePhone_Pro_Software_State&amp;diff=13182"/>
		<updated>2022-06-13T16:31:37Z</updated>

		<summary type="html">&lt;p&gt;Kgmt0: Update front camera status&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Presently the PinePhone Pro Explorer Edition is aimed at '''Linux developers with an extensive knowledge of embedded systems and/or experience with mobile Linux'''. It will take time for all the PinePhone Pro’s functionality to reach software parity with the original PinePhone and for mobile operating systems, in more general, to reach a higher degree of maturity.&lt;br /&gt;
&lt;br /&gt;
Bear in mind that the software for these smartphones is still in a very early stage, with most of the software being in alpha or beta state. That's especially also the case for scalability of applications, their availability and practicability, any hardware function implementations and the firmware. The software is provided as is. There is no warranty for the software, not even for merchantability or fitness for a particular purpose.&lt;br /&gt;
&lt;br /&gt;
The following table lists the feature functionality status of the unaltered pre-installed factory image of the current shipping batch and as comparison an up-to-date reference image (no responsibility is accepted for the accuracy of this information, the list is provided and updated by the community). If you have any questions regarding the current state of the software or of specific features working, please don't hesitate to ask in the [[Main Page#Community and Support|community chat]] '''before buying the device''':&lt;br /&gt;
&lt;br /&gt;
* Discord: ''#pinephone'' under https://discord.gg/pine64&lt;br /&gt;
* IRC: ''#pinephone'' on ''irc.pine64.org''. Note: please consider Matrix, Discord or Telegram due to the volatile nature of IRC&lt;br /&gt;
* Matrix: https://app.element.io/#/room/#pinephone:matrix.org&lt;br /&gt;
* Telegram: https://t.me/pinephone&lt;br /&gt;
&lt;br /&gt;
{{Hint|The software is '''written by the community''', any contributions towards the community projects are greatly appreciated! Please see &amp;quot;[[How to Contribute]]&amp;quot; to learn about how to contribute to the software projects and &amp;quot;[[Where to Report Bugs]]&amp;quot; to learn about where to report bugs.}}&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable plainrowheaders&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Functionality&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;min-width: 260px;&amp;quot;  | Component&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 120px;&amp;quot; | Status (factory)¹&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; style=&amp;quot;width: 120px;&amp;quot; | Status (updated)²&lt;br /&gt;
! scope=&amp;quot;col&amp;quot; | Notes&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot; | Bootloader&lt;br /&gt;
| &amp;lt;code&amp;gt;U-Boot&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Critical bugs&lt;br /&gt;
| Some critical software bugs currently not fixed yet: A drained battery causes U-Boot to bootloop (cause is known and currently being worked on);&amp;lt;sup&amp;gt;[[PinePhone_Pro#The battery is fully drained|Workaround]]&amp;lt;/sup&amp;gt; Occasionally the eMMC fails to initialize&amp;lt;sup&amp;gt;[https://gitlab.com/postmarketOS/pmaports/-/issues/1424 Report]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;SPI&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Unfinished&lt;br /&gt;
| SPI memory is currently empty in the Explorer Edition batch, a corrupted installation on the eMMC has a higher boot priority than a fresh microSD card installation, leading to a involved recovery procedure&amp;lt;sup&amp;gt;[https://tow-boot.org/ Planned]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Boot GUI&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not implemented&lt;br /&gt;
| Currently there is no graphical boot selection implemented&amp;lt;sup&amp;gt;[https://tow-boot.org/ Possibly planned]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;3&amp;quot; | Operating System&lt;br /&gt;
| &amp;lt;code&amp;gt;Stability&amp;lt;/code&amp;gt;&lt;br /&gt;
| style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Critical bugs&lt;br /&gt;
| style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| The pre-flashed and outdated operating system on the eMMC often gets corrupted after updating&amp;lt;sup&amp;gt;[https://forum.pine64.org/showthread.php?tid=15950 Example]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Suspend&amp;lt;/code&amp;gt;&lt;br /&gt;
| style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not working&lt;br /&gt;
| style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | Experimental&lt;br /&gt;
| '''Without suspend the phone will drain very fast!''' Suspend only available in specific more recent images&amp;lt;sup&amp;gt;[https://www.pine64.org/2022/03/15/march-update-introducing-the-quartzpro64/ News]&amp;lt;/sup&amp;gt; Audio is often higher pitched after waking up from suspend due to a bug&amp;lt;sup&amp;gt;[https://github.com/dreemurrs-embedded/Pine64-Arch/issues/381 Report]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Updates&amp;lt;/code&amp;gt;&lt;br /&gt;
| style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Critical bugs&lt;br /&gt;
| style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| The pre-flashed and outdated operating system on the eMMC often gets corrupted after updating&amp;lt;sup&amp;gt;[https://forum.pine64.org/showthread.php?tid=15950 Example]&amp;lt;/sup&amp;gt;; Pacman database lock preventing updates&amp;lt;sup&amp;gt;[https://wiki.archlinux.org/title/pacman#%22Failed_to_init_transaction_(unable_to_lock_database)%22_error Solution]&amp;lt;/sup&amp;gt;; Keyring bug&amp;lt;sup&amp;gt;[Solution is to run &amp;quot;pinephonepro-post-install&amp;quot; script as root]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;5&amp;quot; | Modem&lt;br /&gt;
| &amp;lt;code&amp;gt;General&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Critical bugs&lt;br /&gt;
| The modem crashes frequently&amp;lt;sup&amp;gt;[https://gitlab.manjaro.org/manjaro-arm/issues/pinephone/phosh/-/issues/147 Report]&amp;lt;/sup&amp;gt;&amp;lt;sup&amp;gt;[https://gitlab.com/mobian1/devices/eg25-manager/-/issues/15 Report]&amp;lt;/sup&amp;gt;&amp;lt;sup&amp;gt;[https://github.com/Biktorgj/pinephone_modem_sdk Alternative firmware]&amp;lt;/sup&amp;gt;; Slow wakeup&amp;lt;sup&amp;gt;[https://gitlab.com/mobian1/devices/eg25-manager/-/issues/34 Report]&amp;lt;/sup&amp;gt;; Some carriers blocking specific TANs in their network&amp;lt;sup&amp;gt;[[PinePhone Carrier Support]]&amp;lt;/sup&amp;gt;; '''Note:''' Proprietary firmware&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Phone&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| The modem crashes frequently, which can lead to missed calls&amp;lt;sup&amp;gt;[https://gitlab.manjaro.org/manjaro-arm/issues/pinephone/phosh/-/issues/147 Report]&amp;lt;/sup&amp;gt;&amp;lt;sup&amp;gt;[https://gitlab.com/mobian1/devices/eg25-manager/-/issues/15 Report]&amp;lt;/sup&amp;gt;&amp;lt;sup&amp;gt;[https://github.com/Biktorgj/pinephone_modem_sdk Alternative firmware]&amp;lt;/sup&amp;gt;; bad call audio quality&amp;lt;sup&amp;gt;[https://gitlab.manjaro.org/manjaro-arm/issues/pinephone/phosh/-/issues/249 Report]&amp;lt;/sup&amp;gt;;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;SMS&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| SMS functionality is expected to work. In certain cases the functionality might be blocked by a clogged modem&amp;lt;sup&amp;gt;[https://gitlab.manjaro.org/manjaro-arm/issues/pinephone/phosh/-/issues/203 Report]&amp;lt;/sup&amp;gt;; Some bugs&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;MMS&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| MMS functionality is integrated into the application &amp;quot;Spacebar&amp;quot;, some bugs remaining and expected&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Push notifications&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not implemented&lt;br /&gt;
| Receiving push notifications while the phone is suspended is not implemented&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;12&amp;quot; | Components&lt;br /&gt;
| &amp;lt;code&amp;gt;LCD&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| Under certain circumstances it is difficult to wake up the screen&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Touch&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Rear camera&amp;lt;/code&amp;gt;&lt;br /&gt;
| style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not working&lt;br /&gt;
| style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| Camera works with DTS fix; userspace still needs to do some catching up (see [[PinePhone Pro/IMX258 Camera Debugging|debugging article]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Front camera&amp;lt;/code&amp;gt;&lt;br /&gt;
| style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not working&lt;br /&gt;
| style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| Camera works with DTS fix; userspace still needs to do some catching up (see [[PinePhone Pro/IMX258 Camera Debugging|debugging article]])&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Camera flash&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| (tested on Manjaro; at &amp;lt;code&amp;gt;/sys/class/leds/white:flash&amp;lt;/code&amp;gt;)&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;WiFi&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| WiFi is expected to work. Some remaining tasks, such as &amp;quot;monitor mode&amp;quot;. '''Note:''' Proprietary firmware&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Bluetooth&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| Bluetooth not necessarily working for calls yet due to missing audio routing&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;; Bluetooth in general dodgy under Pulseaudio.&amp;lt;sup&amp;gt;[https://wiki.archlinux.org/title/bluetooth_headset#Headset_via_Pipewire Info]&amp;lt;/sup&amp;gt; '''Note:''' Proprietary firmware&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;GNSS/GPS&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| aGPS to be implemented&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;; long loading times to get a GPS fix&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;; No preinstalled application&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Sensors&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| &amp;quot;3 Axis Magnetometer&amp;quot; (&amp;lt;code&amp;gt;lis3mdl&amp;lt;/code&amp;gt;): Not present in hardware (it's an alternative chip to &amp;lt;code&amp;gt;af8133j&amp;lt;/code&amp;gt; due to component shortages)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;Geo Magnetic Sensor&amp;quot; (&amp;lt;code&amp;gt;af8133j&amp;lt;/code&amp;gt;): Working (tested on Manjaro, at &amp;lt;code&amp;gt;/sys/bus/i2c/devices/4-001c/iio:device1&amp;lt;/code&amp;gt;)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;Accelerometer / Gyroscope&amp;quot; (&amp;lt;code&amp;gt;mpu6500&amp;lt;/code&amp;gt;): Working (tested on Manjaro, at &amp;lt;code&amp;gt;/sys/bus/i2c/devices/4-0068/iio:device2&amp;lt;/code&amp;gt;)&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;quot;Ambient light / Proximity&amp;quot; (&amp;lt;code&amp;gt;stk3311&amp;lt;/code&amp;gt;): Not working (tested on Manjaro 5.17.6-2 kernel; IRQ issues)&lt;br /&gt;
&amp;lt;div class=&amp;quot;toccolours mw-collapsible mw-collapsed&amp;quot; style=&amp;quot;overflow:auto;&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;div style=&amp;quot;font-weight:bold;line-height:1.6;&amp;quot;&amp;gt;stk3311 dmesg excerpt&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;div class=&amp;quot;mw-collapsible-content&amp;quot;&amp;gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
[    9.406478] genirq: Failed to request resources for stk3310_event (irq 99) on irqchip rockchip_gpio_irq&lt;br /&gt;
[    9.407380] stk3310 3-0048: request irq 99 failed&lt;br /&gt;
[    9.408360] stk3310: probe of 3-0048 failed with error -5&lt;br /&gt;
&amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Vibration motor&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Notification LED&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buttons&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightGreen; text-align:center;&amp;quot; | Working&lt;br /&gt;
| Power buttons and volume buttons are working.&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;5&amp;quot; | Accessory compatibility, spare parts&lt;br /&gt;
| &amp;lt;code&amp;gt;Keyboard Add-on&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | WIP and critical hardware issue&lt;br /&gt;
| The keyboard add-on compatibility is work-in-progress. '''Hardware issue: USB-C port of the phone must not be used while the current keyboard revision is connected'''&amp;lt;sup&amp;gt;[[PinePhone_(Pro)_Keyboard#Safety|Warning]]&amp;lt;/sup&amp;gt;; Top row symbols not implemented as designed&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;; Keyboard hot-plugging not supported&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;; Battery state not exposed in the pre-flashed operating system state&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;; general driver bugs&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;LoRa Add-on&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not implemented&lt;br /&gt;
| No software support implemented&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Qi Wireless Charging Add-on&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | WIP&lt;br /&gt;
| Wireless charging with the add-on case is expected to work to some degree. Certain software functionality and a driver is currently missing&amp;lt;sup&amp;gt;[Citation]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Fingerprint Reader Add-on&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not implemented&lt;br /&gt;
| No software support implemented&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Spare parts&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:lightcoral; text-align:center;&amp;quot; | Not available yet&lt;br /&gt;
| Spare parts currently not available yet in the store.&amp;lt;sup&amp;gt;[https://pine64.com/product-category/smartphone-spare-parts/ Store]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! scope=&amp;quot;row&amp;quot; rowspan=&amp;quot;1&amp;quot; | Software notes&lt;br /&gt;
| &amp;lt;code&amp;gt;Waydroid&amp;lt;/code&amp;gt;&lt;br /&gt;
| colspan=&amp;quot;2&amp;quot; style=&amp;quot;background:LightYellow; text-align:center;&amp;quot; | Software rendering only&lt;br /&gt;
| Waydroid is an Android container used to run Android applications. Currently can only be started using software rendering due to a bug&amp;lt;sup&amp;gt;[https://github.com/waydroid/waydroid/issues/291 Report]&amp;lt;/sup&amp;gt;&amp;lt;sup&amp;gt;[https://gitlab.freedesktop.org/mesa/mesa/-/issues/5928 Report]&amp;lt;/sup&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
¹ Status of the features at the time of the last factory installation without updates&lt;br /&gt;
&lt;br /&gt;
² Status of the features with an up-to-date reference image&lt;/div&gt;</summary>
		<author><name>Kgmt0</name></author>
	</entry>
</feed>