From 2140b6c8cea7bd76c865edbad5beb0e6c305d11f Mon Sep 17 00:00:00 2001 From: Gerben Jan Dijkman Date: Tue, 27 Jun 2023 13:13:22 +0200 Subject: [PATCH] Added PPP patches --- ...851d49e4f8a9ef196eb0887cef428ba56c6.patch} | 2 +- ...662a484c0887d29f11a1284f85ff34d0248.patch} | 212 +++++++++--------- ...07dd65452db159eb961b7ff27b8424cffc7.patch} | 2 +- ....6.1.ebuild => megapixels-1.6.1-r1.ebuild} | 6 +- 4 files changed, 113 insertions(+), 109 deletions(-) rename media-video/megapixels/files/{06230f3a02cffdf8b683f85cb32fc256d73615d9.patch => 432d3851d49e4f8a9ef196eb0887cef428ba56c6.patch} (91%) rename media-video/megapixels/files/{d8b35bc223989cb165ba1b0716ab9f0ca9c43e53.patch => 8103e662a484c0887d29f11a1284f85ff34d0248.patch} (86%) rename media-video/megapixels/files/{27a1e606d680295e0b4caceadf74ff5857ac16b2.patch => af01107dd65452db159eb961b7ff27b8424cffc7.patch} (98%) rename media-video/megapixels/{megapixels-1.6.1.ebuild => megapixels-1.6.1-r1.ebuild} (84%) diff --git a/media-video/megapixels/files/06230f3a02cffdf8b683f85cb32fc256d73615d9.patch b/media-video/megapixels/files/432d3851d49e4f8a9ef196eb0887cef428ba56c6.patch similarity index 91% rename from media-video/megapixels/files/06230f3a02cffdf8b683f85cb32fc256d73615d9.patch rename to media-video/megapixels/files/432d3851d49e4f8a9ef196eb0887cef428ba56c6.patch index 4a2a949..65e0acc 100644 --- a/media-video/megapixels/files/06230f3a02cffdf8b683f85cb32fc256d73615d9.patch +++ b/media-video/megapixels/files/432d3851d49e4f8a9ef196eb0887cef428ba56c6.patch @@ -1,4 +1,4 @@ -From 06230f3a02cffdf8b683f85cb32fc256d73615d9 Mon Sep 17 00:00:00 2001 +From 432d3851d49e4f8a9ef196eb0887cef428ba56c6 Mon Sep 17 00:00:00 2001 From: kgmt0 Date: Sat, 2 Jul 2022 12:15:22 +0700 Subject: [PATCH] device: Make mp_device_setup_link() support non-zero pad diff --git a/media-video/megapixels/files/d8b35bc223989cb165ba1b0716ab9f0ca9c43e53.patch b/media-video/megapixels/files/8103e662a484c0887d29f11a1284f85ff34d0248.patch similarity index 86% rename from media-video/megapixels/files/d8b35bc223989cb165ba1b0716ab9f0ca9c43e53.patch rename to media-video/megapixels/files/8103e662a484c0887d29f11a1284f85ff34d0248.patch index 6d7bc6d..543ac5a 100644 --- a/media-video/megapixels/files/d8b35bc223989cb165ba1b0716ab9f0ca9c43e53.patch +++ b/media-video/megapixels/files/8103e662a484c0887d29f11a1284f85ff34d0248.patch @@ -1,26 +1,21 @@ -From d8b35bc223989cb165ba1b0716ab9f0ca9c43e53 Mon Sep 17 00:00:00 2001 +From 8103e662a484c0887d29f11a1284f85ff34d0248 Mon Sep 17 00:00:00 2001 From: kgmt0 Date: Thu, 1 Dec 2022 00:13:27 -0600 Subject: [PATCH] WIP: Support Pinephone Pro Both cameras work now but the quality is very poor. -The config file format is extended to include 2 new options -"media-formats" and "media-crops" that can be used to set formats and -crops on a per-pad basis. These are needed to initialize Pinephone Pro's -media controller. - -Tested with Linux 6.0.8-1 from Arch Linux ARM (linux-megi). +Tested with Linux 6.1.12-1 from Arch Linux ARM (linux-megi). --- config/motorola,osprey.ini | 1 + config/pine64,pinephone-pro.ini | 49 +++++++++ config/xiaomi,scorpio.ini | 1 + meson.build | 1 + - src/camera.c | 10 +- - src/device.c | 101 ++++++++++++++++++ - src/device.h | 14 +++ - src/io_pipeline.c | 184 ++++++++++++++++++++------------ - 8 files changed, 288 insertions(+), 73 deletions(-) + src/camera.c | 8 +- + src/device.c | 118 ++++++++++++++++++++++ + src/device.h | 15 +++ + src/io_pipeline.c | 173 +++++++++++++++++++------------- + 8 files changed, 296 insertions(+), 70 deletions(-) create mode 100644 config/pine64,pinephone-pro.ini diff --git a/config/motorola,osprey.ini b/config/motorola,osprey.ini @@ -34,7 +29,7 @@ index ab8990d..5809a8e 100644 +media-formats=msm_csiphy0:1:RGGB10P:4096:2304,msm_csid0:0:RGGB10P:4096:2304,msm_csid0:1:RGGB10P:4096:2304,msm_ispif0:0:RGGB10P:4096:2304,msm_ispif0:1:RGGB10P:4096:2304,msm_vfe0_rdi0:0:RGGB10P:4096:2304 diff --git a/config/pine64,pinephone-pro.ini b/config/pine64,pinephone-pro.ini new file mode 100644 -index 0000000..bd5cfcd +index 0000000..b7a2dcd --- /dev/null +++ b/config/pine64,pinephone-pro.ini @@ -0,0 +1,49 @@ @@ -68,7 +63,7 @@ index 0000000..bd5cfcd +media-crops=rkisp1_isp:0:0:0:1048:780,rkisp1_isp:2:0:0:1048:780,rkisp1_resizer_mainpath:0:0:0:1048:768 + +[front] -+driver=m00_f_ov8858 1-0036 ++driver=ov8858 +media-driver=rkisp1 +capture-width=3264 +capture-height=2448 @@ -84,8 +79,8 @@ index 0000000..bd5cfcd +cropfactor=12.7 +fnumber=2.4 +flash-display=true -+media-links=m00_f_ov8858 1-0036:0->rkisp1_csi:0,rkisp1_csi:1->rkisp1_isp:0,rkisp1_isp:2->rkisp1_resizer_mainpath:0,rkisp1_resizer_mainpath:1->rkisp1_mainpath:0 -+media-formats=m00_f_ov8858 1-0036:0:BGGR10P:3264:2448,rkisp1_csi:0:BGGR10P:3264:2448,rkisp1_isp:0:BGGR10P:3264:2448,rkisp1_isp:2:BGGR8:3264:2448,rkisp1_resizer_mainpath:0:BGGR8:3264:2448,rkisp1_resizer_mainpath:1:BGGR8:3264:2448 ++media-links=ov8858:0->rkisp1_csi:0,rkisp1_csi:1->rkisp1_isp:0,rkisp1_isp:2->rkisp1_resizer_mainpath:0,rkisp1_resizer_mainpath:1->rkisp1_mainpath:0 ++media-formats=ov8858:0:BGGR10P:3264:2448,rkisp1_csi:0:BGGR10P:3264:2448,rkisp1_isp:0:BGGR10P:3264:2448,rkisp1_isp:2:BGGR8:3264:2448,rkisp1_resizer_mainpath:0:BGGR8:3264:2448,rkisp1_resizer_mainpath:1:BGGR8:3264:2448 +media-crops=rkisp1_isp:0:0:0:3264:2448,rkisp1_isp:2:0:0:3264:2448,rkisp1_resizer_mainpath:0:0:0:3264:768 diff --git a/config/xiaomi,scorpio.ini b/config/xiaomi,scorpio.ini index cce6d49..14b7f29 100644 @@ -97,7 +92,7 @@ index cce6d49..14b7f29 100644 media-links=imx318 3-001a:0->msm_csiphy0:0,msm_csiphy0:1->msm_csid0:0,msm_csid0:1->msm_ispif0:0,msm_ispif0:1->msm_vfe0_rdi0:0 +media-formats=imx318 3-001a:0:RGGB10P:3840:2160,msm_csiphy0:0:RGGB10P:3840:2160,msm_csiphy0:1:RGGB10P:3840:2160,msm_csid0:0:RGGB10P:3840:2160,msm_csid0:1:RGGB10P:3840:2160,msm_ispif0:0:RGGB10P:3840:2160,msm_ispif0:1:RGGB10P:3840:2160,msm_vfe0_rdi0:0:RGGB10P:3840:2160 diff --git a/meson.build b/meson.build -index 3b98f19..d53dec9 100644 +index a9b9b4e..adc2359 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,7 @@ install_data( @@ -109,28 +104,26 @@ index 3b98f19..d53dec9 100644 'config/xiaomi,scorpio.ini', ], diff --git a/src/camera.c b/src/camera.c -index 9a08f56..7368189 100644 +index 5519bbd..588c164 100644 --- a/src/camera.c +++ b/src/camera.c -@@ -305,11 +305,11 @@ mp_camera_set_mode(MPCamera *camera, MPMode *mode) +@@ -327,8 +327,12 @@ mp_camera_set_mode(MPCamera *camera, MPMode *mode) } // Update the mode - mode->pixel_format = - mp_pixel_format_from_v4l_bus_code(fmt.format.code); -- mode->frame_interval = interval.interval; -- mode->width = fmt.format.width; -- mode->height = fmt.format.height; ++ ++ // TODO: Some how the format gets changed to YUYV if this isn't ++ // commented out. + //mode->pixel_format = + // mp_pixel_format_from_v4l_bus_code(fmt.format.code); -+ //mode->frame_interval = interval.interval; -+ //mode->width = fmt.format.width; -+ //mode->height = fmt.format.height; - } - - // Set the mode for the video device ++ + mode->frame_interval = interval.interval; + mode->width = fmt.format.width; + mode->height = fmt.format.height; diff --git a/src/device.c b/src/device.c -index 9e2db00..1161861 100644 +index 9e2db00..09e711b 100644 --- a/src/device.c +++ b/src/device.c @@ -8,6 +8,8 @@ @@ -142,7 +135,54 @@ index 9e2db00..1161861 100644 bool mp_find_device_path(struct media_v2_intf_devnode devnode, char *path, int length) -@@ -183,6 +185,25 @@ mp_device_setup_entity_link(MPDevice *device, +@@ -73,6 +75,46 @@ xioctl(int fd, int request, void *arg) + return r; + } + ++static int ++mp_device_get_fd_by_name(const MPDevice *device, const char *driver_name) ++{ ++ struct media_entity_desc desc = {}; ++ ++ desc.id |= MEDIA_ENT_ID_FLAG_NEXT; ++ ++ while(true) { ++ desc.id |= MEDIA_ENT_ID_FLAG_NEXT; ++ if(xioctl(device->fd, MEDIA_IOC_ENUM_ENTITIES, &desc) == -1) { ++ errno_printerr("MEDIA_IOC_ENUM_ENTITIES"); ++ return -1; ++ } ++ ++ if(strncmp(desc.name, driver_name, 32) == 0) { ++ const uint32_t major = desc.dev.major; ++ const uint32_t minor = desc.dev.minor; ++ char path[256]; ++ int rc = snprintf(path, 256, "/dev/char/%u:%u", major, minor); ++ ++ return rc > 0 ? open(path, O_RDWR) : -1; ++ } ++ } ++ ++ return -1; ++} ++ ++static bool ++mp_xioctl(const MPDevice *device, const char *driver_name, unsigned long request, void *argp) ++{ ++ int fd = mp_device_get_fd_by_name(device, driver_name); ++ ++ if(fd < 0) ++ { ++ printf("ERROR: device with driver name %s not found\n", driver_name); ++ } ++ ++ return fd >= 0 && xioctl(fd, request, argp) != -1; ++} ++ + MPDevice * + mp_device_find(const char *driver_name, const char *dev_name) + { +@@ -183,6 +225,42 @@ mp_device_setup_entity_link(MPDevice *device, return true; } @@ -164,11 +204,28 @@ index 9e2db00..1161861 100644 + cfg->target_port, + enable); +} ++ ++void ++mp_device_setup_media_link_pad_crop(MPDevice *device, ++ const struct mp_media_crop_config *crop) ++{ ++ struct v4l2_subdev_crop v4l2_crop = {}; ++ v4l2_crop.pad = crop->pad; ++ v4l2_crop.which = V4L2_SUBDEV_FORMAT_ACTIVE; ++ v4l2_crop.rect.top = crop->top; ++ v4l2_crop.rect.left = crop->left; ++ v4l2_crop.rect.width = crop->width; ++ v4l2_crop.rect.height = crop->height; ++ ++ if(!mp_xioctl(device, crop->name, VIDIOC_SUBDEV_S_CROP, &v4l2_crop)) { ++ errno_printerr("VIDIOC_SUBDEV_S_CROP"); ++ } ++} + bool mp_device_setup_link(MPDevice *device, uint32_t source_pad_id, -@@ -237,6 +258,73 @@ mp_entity_pad_set_format(MPDevice *device, +@@ -237,6 +315,46 @@ mp_entity_pad_set_format(MPDevice *device, return true; } @@ -211,59 +268,12 @@ index 9e2db00..1161861 100644 + + return true; +} -+ -+int -+mp_device_get_fd_by_name(const MPDevice *device, const char *driver_name) -+{ -+ struct media_entity_desc desc = {}; -+ -+ desc.id |= MEDIA_ENT_ID_FLAG_NEXT; -+ -+ while(true) { -+ desc.id |= MEDIA_ENT_ID_FLAG_NEXT; -+ if(xioctl(device->fd, MEDIA_IOC_ENUM_ENTITIES, &desc) == -1) { -+ errno_printerr("MEDIA_IOC_ENUM_ENTITIES"); -+ return -1; -+ } -+ -+ if(strncmp(desc.name, driver_name, 32) == 0) { -+ const uint32_t major = desc.dev.major; -+ const uint32_t minor = desc.dev.minor; -+ char path[256]; -+ int rc = snprintf(path, 256, "/dev/char/%u:%u", major, minor); -+ -+ return rc > 0 ? open(path, O_RDWR) : -1; -+ } -+ } -+ -+ return -1; -+} + const struct media_v2_entity * mp_device_find_entity(const MPDevice *device, const char *driver_name) { -@@ -263,6 +351,19 @@ mp_device_find_entity_type(const MPDevice *device, const uint32_t type) - return NULL; - } - -+bool -+mp_xioctl(const MPDevice *device, const char *driver_name, unsigned long request, void *argp) -+{ -+ int fd = mp_device_get_fd_by_name(device, driver_name); -+ -+ if(fd < 0) -+ { -+ printf("ERROR: device with driver name %s not found\n", driver_name); -+ } -+ -+ return fd >= 0 && xioctl(fd, request, argp) != -1; -+} -+ - const struct media_device_info * - mp_device_get_info(const MPDevice *device) - { diff --git a/src/device.h b/src/device.h -index 1894c67..b324e1a 100644 +index 1894c67..c9b3477 100644 --- a/src/device.h +++ b/src/device.h @@ -1,6 +1,7 @@ @@ -285,12 +295,10 @@ index 1894c67..b324e1a 100644 bool mp_device_setup_link(MPDevice *device, uint32_t source_pad_id, uint32_t sink_pad_id, -@@ -36,6 +41,15 @@ bool mp_entity_pad_set_format(MPDevice *device, +@@ -36,6 +41,13 @@ bool mp_entity_pad_set_format(MPDevice *device, uint32_t pad, MPMode *mode); -+bool mp_xioctl(const MPDevice *device, const char *driver_name, unsigned long request, void *argp); -+ +bool mp_device_setup_link_by_name(MPDevice *device, + const char *source_entity_name, + uint32_t source_pad_index, @@ -301,8 +309,15 @@ index 1894c67..b324e1a 100644 const struct media_device_info *mp_device_get_info(const MPDevice *device); const struct media_v2_entity *mp_device_find_entity(const MPDevice *device, const char *driver_name); +@@ -81,3 +93,6 @@ MPDevice *mp_device_list_remove(MPDeviceList **device_list); + MPDevice *mp_device_list_get(const MPDeviceList *device_list); + const char *mp_device_list_get_path(const MPDeviceList *device_list); + MPDeviceList *mp_device_list_next(const MPDeviceList *device_list); ++ ++void mp_device_setup_media_link_pad_crop(MPDevice *device, ++ const struct mp_media_crop_config *crop); diff --git a/src/io_pipeline.c b/src/io_pipeline.c -index 8434420..598118f 100644 +index e9f80c2..135b344 100644 --- a/src/io_pipeline.c +++ b/src/io_pipeline.c @@ -47,7 +47,8 @@ struct camera_info { @@ -315,11 +330,10 @@ index 8434420..598118f 100644 // int gain_ctrl; }; -@@ -100,30 +101,52 @@ static bool want_focus = false; +@@ -100,30 +101,41 @@ static bool want_focus = false; static MPPipeline *pipeline; static GSource *capture_source; -+// TODO: move to device.c +static void +mp_setup_media_link_pad_crops(struct device_info *dev_info, + const struct mp_media_crop_config media_crops[], @@ -327,17 +341,7 @@ index 8434420..598118f 100644 +{ + for(int i = 0; i < num_media_crops; i++) { + const struct mp_media_crop_config *crop = media_crops + i; -+ struct v4l2_subdev_crop v4l2_crop = {}; -+ v4l2_crop.pad = crop->pad; -+ v4l2_crop.which = V4L2_SUBDEV_FORMAT_ACTIVE; -+ v4l2_crop.rect.top = crop->top; -+ v4l2_crop.rect.left = crop->left; -+ v4l2_crop.rect.width = crop->width; -+ v4l2_crop.rect.height = crop->height; -+ -+ if(!mp_xioctl(dev_info->device, crop->name, VIDIOC_SUBDEV_S_CROP, &v4l2_crop)) { -+ //errno_printerr("VIDIOC_SUBDEV_S_CROP"); -+ } ++ mp_device_setup_media_link_pad_crop(dev_info->device, crop); + } +} + @@ -389,7 +393,7 @@ index 8434420..598118f 100644 } } -@@ -191,6 +214,9 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config) +@@ -224,6 +236,9 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config) struct device_info *dev_info = &devices[device_index]; info->device_index = device_index; @@ -399,7 +403,7 @@ index 8434420..598118f 100644 const struct media_v2_entity *entity = mp_device_find_entity(dev_info->device, config->dev_name); -@@ -205,11 +231,33 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config) +@@ -238,11 +253,33 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config) info->pad_id = pad->id; @@ -438,7 +442,7 @@ index 8434420..598118f 100644 const struct media_v2_interface *interface = mp_device_find_entity_interface(dev_info->device, -@@ -234,11 +282,14 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config) +@@ -269,11 +306,14 @@ setup_camera(MPDeviceList **device_list, const struct mp_camera_config *config) // the ov5640 driver where it won't allow setting the preview // format initially. MPMode mode = config->capture_mode; @@ -457,7 +461,7 @@ index 8434420..598118f 100644 mp_camera_set_mode(info->camera, &mode); // Trigger continuous auto focus if the sensor supports it -@@ -400,9 +451,12 @@ capture(MPPipeline *pipeline, const void *data) +@@ -435,9 +475,12 @@ capture(MPPipeline *pipeline, const void *data) mode = camera->capture_mode; if (camera->num_media_links) mp_setup_media_link_pad_formats(dev_info, @@ -473,7 +477,7 @@ index 8434420..598118f 100644 mp_camera_set_mode(info->camera, &mode); just_switched_mode = true; -@@ -569,9 +623,13 @@ on_frame(MPBuffer buffer, void *_data) +@@ -604,9 +647,13 @@ on_frame(MPBuffer buffer, void *_data) if (camera->num_media_links) mp_setup_media_link_pad_formats( dev_info, @@ -490,7 +494,7 @@ index 8434420..598118f 100644 mp_camera_set_mode(info->camera, &mode); just_switched_mode = true; -@@ -587,25 +645,6 @@ on_frame(MPBuffer buffer, void *_data) +@@ -622,25 +669,6 @@ on_frame(MPBuffer buffer, void *_data) } } @@ -516,7 +520,7 @@ index 8434420..598118f 100644 static void update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state) { -@@ -629,8 +668,8 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state) +@@ -664,8 +692,8 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state) // Disable media links for (int i = 0; i < camera->num_media_links; i++) @@ -527,7 +531,7 @@ index 8434420..598118f 100644 } if (capture_source) { -@@ -644,23 +683,32 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state) +@@ -679,23 +707,32 @@ update_state(MPPipeline *pipeline, const struct mp_io_pipeline_state *state) struct camera_info *info = &cameras[camera->index]; struct device_info *dev_info = &devices[info->device_index]; diff --git a/media-video/megapixels/files/27a1e606d680295e0b4caceadf74ff5857ac16b2.patch b/media-video/megapixels/files/af01107dd65452db159eb961b7ff27b8424cffc7.patch similarity index 98% rename from media-video/megapixels/files/27a1e606d680295e0b4caceadf74ff5857ac16b2.patch rename to media-video/megapixels/files/af01107dd65452db159eb961b7ff27b8424cffc7.patch index f8ce7a7..1e9b74c 100644 --- a/media-video/megapixels/files/27a1e606d680295e0b4caceadf74ff5857ac16b2.patch +++ b/media-video/megapixels/files/af01107dd65452db159eb961b7ff27b8424cffc7.patch @@ -1,4 +1,4 @@ -From 27a1e606d680295e0b4caceadf74ff5857ac16b2 Mon Sep 17 00:00:00 2001 +From af01107dd65452db159eb961b7ff27b8424cffc7 Mon Sep 17 00:00:00 2001 From: kgmt0 Date: Thu, 1 Dec 2022 00:09:27 -0600 Subject: [PATCH] Add media-formats and media-crops to the config file format diff --git a/media-video/megapixels/megapixels-1.6.1.ebuild b/media-video/megapixels/megapixels-1.6.1-r1.ebuild similarity index 84% rename from media-video/megapixels/megapixels-1.6.1.ebuild rename to media-video/megapixels/megapixels-1.6.1-r1.ebuild index 5ce5357..7e8d468 100755 --- a/media-video/megapixels/megapixels-1.6.1.ebuild +++ b/media-video/megapixels/megapixels-1.6.1-r1.ebuild @@ -29,9 +29,9 @@ RDEPEND="${DEPEND}" BDEPEND="" PATCHES=( - "${FILESDIR}"/06230f3a02cffdf8b683f85cb32fc256d73615d9.patch - "${FILESDIR}"/27a1e606d680295e0b4caceadf74ff5857ac16b2.patch - "${FILESDIR}"/d8b35bc223989cb165ba1b0716ab9f0ca9c43e53.patch + "${FILESDIR}"/8103e662a484c0887d29f11a1284f85ff34d0248.patch + "${FILESDIR}"/af01107dd65452db159eb961b7ff27b8424cffc7.patch + "${FILESDIR}"/432d3851d49e4f8a9ef196eb0887cef428ba56c6.patch ) src_configure() {