OSDN Git Service

tomoyo/tomoyo-test1.git
20 months agomedia: atomisp: Convert to videobuf2
Hans de Goede [Sat, 8 Oct 2022 16:39:32 +0000 (17:39 +0100)]
media: atomisp: Convert to videobuf2

Convert atomisp to use videobuf2.

This fixes mmap not working and in general moving over to
the more modern videobuf2 is a good plan.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Add ia_css_frame_get_info() helper
Hans de Goede [Fri, 14 Oct 2022 16:13:41 +0000 (17:13 +0100)]
media: atomisp: Add ia_css_frame_get_info() helper

Several places rely on the [frame_]info member being the first member of
struct ia_css_frame, so that &frame->info will yield NULL when frame is
NULL (some places already explicitly check for a NULL frame pointer but
not nearly all).

For videobuf2 support the vb2_v4l2_buffer struct needs to be embedded
in the frame struct and it needs to be the first member. Breaking the
assumption that &frame->info will yield NULL when frame is NULL.

Add a ia_css_frame_get_info() helper to return either the ia_css_frame_info
struct embedded in the frame, or NULL when the frame pointer is NULL and
use this in places where a ia_css_frame_info ptr or NULL is expected.

To make sure that we catch all uses of the info field this patch also
renames the info field to frame_info.

This is a preparation patch for converting the driver to videobuf2.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Use new atomisp_flush_video_pipe() helper in atomisp_streamoff()
Hans de Goede [Sat, 8 Oct 2022 15:27:26 +0000 (16:27 +0100)]
media: atomisp: Use new atomisp_flush_video_pipe() helper in atomisp_streamoff()

Use the new atomisp_flush_video_pipe() helper instead of open-coding it.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Add an index helper variable to atomisp_buf_done()
Hans de Goede [Sat, 8 Oct 2022 15:20:09 +0000 (16:20 +0100)]
media: atomisp: Add an index helper variable to atomisp_buf_done()

With the videobuf2 conversion accessing the index of a frame is going
to become more involved and writing this out each time is undesired.

Add an 'i' helper variable for the index and assing this once as
preparation for the videobuf2 conversion.

This also makes use of the new rules wrt max line-lengths in the kernel
to avoid breaking up a bunch of lines. Not breaking these lines results
in better readable code (IMHO).

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Also track buffers in a list when submitted to the ISP
Hans de Goede [Sat, 8 Oct 2022 15:08:08 +0000 (16:08 +0100)]
media: atomisp: Also track buffers in a list when submitted to the ISP

Instead of using an integer to keep count of how many buffers have
been handed over to the ISP (buffers_in_css) move buffers handed
over to the ISP to a new buffers_in_css list_head so that we can
easily loop over them.

This removes the need for atomisp_flush_video_pipe() to loop over
all buffers and then (ab)use the state to figure out if they
were handed over to the ISP.

Since the buffers are now always on a list when owned by the driver
this also allows the buffer_done path on flush vs normal completion
to be unified (both now need a list_del()) and this common code can
now be factored out into a new atomisp_buffer_done() helper.

This is a preparation patch for moving the driver over to
the videobuf2 framework.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Remove unused atomisp_buffers_queued[_pipe] functions
Hans de Goede [Fri, 7 Oct 2022 18:27:09 +0000 (19:27 +0100)]
media: atomisp: Remove unused atomisp_buffers_queued[_pipe] functions

The atomisp_buffers_queued[_pipe] functions are not used anywhere,
remove them.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: On streamoff wait for buffers owned by the CSS to be given back
Hans de Goede [Fri, 30 Sep 2022 19:05:44 +0000 (20:05 +0100)]
media: atomisp: On streamoff wait for buffers owned by the CSS to be given back

There is no guarantee that when we stop the pipeline all buffers owned
by the CSS are cleanly returned to the videobuf queue.

This is a problem with videobuf2 which will complain loudly when not
all buffers have been returned after the streamoff() queue op has
returned.

And this also allows removing a WARN() in the continuous mode path.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Make atomisp_q_video_buffers_to_css() static
Hans de Goede [Fri, 30 Sep 2022 15:54:27 +0000 (16:54 +0100)]
media: atomisp: Make atomisp_q_video_buffers_to_css() static

atomisp_q_video_buffers_to_css() is only used insidd atomisp_fops.c, make
it static.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Add ia_css_frame_init_from_info() function
Hans de Goede [Mon, 26 Sep 2022 19:43:54 +0000 (20:43 +0100)]
media: atomisp: Add ia_css_frame_init_from_info() function

Add a function to initialize (rather then alloc/create) a
ia_css_frame struct based on an ia_css_frame_info struct.

This is a preparation patch for adding videobuf2 support.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atomisp: Add hmm_create_from_vmalloc_buf() function
Hans de Goede [Mon, 26 Sep 2022 17:45:46 +0000 (18:45 +0100)]
media: atomisp: Add hmm_create_from_vmalloc_buf() function

Add a new hmm creating function to create a vmm object from a vmalloc-ed
kernel buffer. This is a preparation patch for adding videobuf2 (and
working MMAP mode) support.

Reviewed-by: Andy Shevchenko <andy@kernel.org>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: imon: fix a race condition in send_packet()
Gautam Menghani [Wed, 19 Oct 2022 05:02:14 +0000 (06:02 +0100)]
media: imon: fix a race condition in send_packet()

The function send_packet() has a race condition as follows:

func send_packet()
{
    // do work
    call usb_submit_urb()
    mutex_unlock()
    wait_for_event_interruptible()  <-- lock gone
    mutex_lock()
}

func vfd_write()
{
    mutex_lock()
    call send_packet()  <- prev call is not completed
    mutex_unlock()
}

When the mutex is unlocked and the function send_packet() waits for the
call to complete, vfd_write() can start another call, which leads to the
"URB submitted while active" warning in usb_submit_urb().
Fix this by removing the mutex_unlock() call in send_packet() and using
mutex_lock_interruptible().

Link: https://syzkaller.appspot.com/bug?id=e378e6a51fbe6c5cc43e34f131cc9a315ef0337e
Fixes: 21677cfc562a ("V4L/DVB: ir-core: add imon driver")
Reported-by: syzbot+0c3cb6dc05fbbdc3ad66@syzkaller.appspotmail.com
Signed-off-by: Gautam Menghani <gautammenghani201@gmail.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: ir-spi: silence no spi_device_id warnings
Wei Yongjun [Thu, 22 Sep 2022 08:37:03 +0000 (09:37 +0100)]
media: ir-spi: silence no spi_device_id warnings

SPI devices use the spi_device_id for module autoloading even on
systems using device tree, after commit 5fa6863ba692 ("spi: Check
we have a spi_device_id for each DT compatible"), kernel warns as
follows since the spi_device_id is missing:

SPI driver ir-spi has no spi_device_id for ir-spi-led

Add spi_device_id entries to silence the warning, and ensure driver
module autoloading works.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agoMerge tag 'br-v6.2g' of git://linuxtv.org/hverkuil/media_tree into media_stage
Mauro Carvalho Chehab [Fri, 25 Nov 2022 07:55:03 +0000 (07:55 +0000)]
Merge tag 'br-v6.2g' of git://linuxtv.org/hverkuil/media_tree into media_stage

Despite being big, the changes here are trivial: they just change the
probing method for I2C. So, apply it as a merge.

Tag branch

* tag 'br-v6.2g' of git://linuxtv.org/hverkuil/media_tree: (96 commits)
  media: v4l2-core/tuner-core: Convert to i2c's .probe_new()
  media: usb: go7007: s2250-board: Convert to i2c's .probe_new()
  media: tuners/tua9001: Convert to i2c's .probe_new()
  media: tuners/tda18250: Convert to i2c's .probe_new()
  media: tuners/tda18212: Convert to i2c's .probe_new()
  media: tuners/qm1d1c0042: Convert to i2c's .probe_new()
  media: tuners/qm1d1b0004: Convert to i2c's .probe_new()
  media: tuners/mxl301rf: Convert to i2c's .probe_new()
  media: tuners/mt2060: Convert to i2c's .probe_new()
  media: tuners/m88rs6000t: Convert to i2c's .probe_new()
  media: tuners/fc2580: Convert to i2c's .probe_new()
  media: tuners/e4000: Convert to i2c's .probe_new()
  media: vidtv: Convert to i2c's .probe_new()
  media: radio/tef6862: Convert to i2c's .probe_new()
  media: radio/saa7706h: Convert to i2c's .probe_new()
  media: radio/radio-tea5764: Convert to i2c's .probe_new()
  media: i2c/wm8775: Convert to i2c's .probe_new()
  media: i2c/wm8739: Convert to i2c's .probe_new()
  media: i2c/vs6624: Convert to i2c's .probe_new()
  media: i2c/vpx3220: Convert to i2c's .probe_new()
  ...

Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atmel: atmel-isc: move to staging
Eugen Hristev [Mon, 7 Nov 2022 14:18:18 +0000 (14:18 +0000)]
media: atmel: atmel-isc: move to staging

The Atmel ISC driver is not compliant with media controller specification.
In order to evolve this driver, it has to move to media controller, to
support enhanced features and future products which embed it.
The move to media controller involves several changes which are
not backwards compatible with the current usability of the driver.

The best example is the way the format is propagated from the top video
driver /dev/videoX down to the sensor.

In a simple configuration sensor ==> isc , the isc just calls subdev s_fmt
and controls the sensor directly. This is achieved by having a lot of code
inside the driver that will query the subdev at probe time and make a list
of formats which are usable.
Basically the user has nothing to configure, as the isc will handle
everything at the top level. This is an easy way to capture, but also comes
with the drawback of lack of flexibility.
In a more complicated pipeline
sensor ==> controller 1 ==> controller 2 ==> isc
this will not be achievable, as controller 1 and controller 2 might be
media-controller configurable, and will not propagate the formats down to
the sensor.

After discussions with the media maintainers, the decision is to move
Atmel ISC to staging as-is, to keep the Kconfig symbols and the users
to the driver in staging. Thus, all the existing users of the non
media-controller paradigm will continue to be happy and use the old config
way.

The new driver was added in the media subsystem with a different
symbol, with the conversion to media controller done, and new users
of the driver will be able to use all the new features.

This patch is merely a file move to staging, not affecting any of the
users.

The exported symbols had to be renamed to atmel_* to avoid duplication with
the new Microchip ISC driver.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: microchip: microchip-isc: move media_pipeline_* to (un)prepare cb
Eugen Hristev [Mon, 7 Nov 2022 14:18:17 +0000 (14:18 +0000)]
media: microchip: microchip-isc: move media_pipeline_* to (un)prepare cb

Move the media_pipeline_start/stop calls from start/stop streaming to
the new prepare_streaming and unprepare_streaming callbacks.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: microchip: microchip-isc: implement media controller
Eugen Hristev [Mon, 7 Nov 2022 14:18:16 +0000 (14:18 +0000)]
media: microchip: microchip-isc: implement media controller

As a top MC video driver, the microchip-isc should not propagate the format
to the subdevice, it should rather check at start_streaming() time if the
subdev is properly configured with a compatible format.
Removed the whole format finding logic, and reworked the format
verification at start_streaming time, such that the ISC will return an
error if the subdevice is not properly configured.
To achieve this, media_pipeline_start is called and a link_validate
callback is created to check the formats.
With this being done, the module parameter 'sensor_preferred' makes no
sense anymore. The ISC should not decide which format the sensor is using.
The ISC should only cope with the situation and inform userspace if the
streaming is possible in the current configuration.
The redesign of the format propagation has also risen the question of the
enumfmt callback. If enumfmt is called with an mbus_code, the enumfmt
handler should only return the formats that are supported for this
mbus_code. Otherwise, the enumfmt will report all the formats that the ISC
could output.
With this rework, the dynamic list of user formats is removed. It makes no
more sense to identify at complete time which formats the sensor could
emit, and add those into a separate dynamic list.
The ISC will start with a simple preconfigured default format, and at
link validate time, decide whether it can use the format that is
configured on the sink or not.
>From now on, the driver also advertises the IO_MC capability.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: microchip: microchip-isc: prepare for media controller support
Eugen Hristev [Mon, 7 Nov 2022 14:18:15 +0000 (14:18 +0000)]
media: microchip: microchip-isc: prepare for media controller support

Prepare the support for media-controller.
This means that the capabilities of the driver have changed and now it's
capable of media controller operations.
The driver will register its media device, and add the video entity to this
media device. The subdevices are registered to the same media device.
The ISC will have a base entity which is auto-detected as
microchip_isc_base.
It will also register a subdevice that allows cropping of the incoming
frame to the maximum frame size supported by the ISC.
The ISC will create a link between the subdevice that is asynchronously
registered and the microchip_isc_scaler entity.
Then, the microchip_isc_scaler and microchip_isc_base are connected
through another link.
This patch does not change the previous capability of the driver, the
fact that the format is still being propagated from the top video node
down to the sensor.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: microchip: add ISC driver as Microchip ISC
Eugen Hristev [Mon, 7 Nov 2022 14:18:14 +0000 (14:18 +0000)]
media: microchip: add ISC driver as Microchip ISC

The Atmel ISC driver will be moved to staging to support old users that
are not using the media controller paradigm.
The ISC driver was converted to media controller in the public patch
series:

https://lore.kernel.org/lkml/20220503095127.48710-1-eugen.hristev@microchip.com/T/#m2c320fa8153c01379a1c35b1d90a00903949513a

However the conversion cannot be done directly as it would affect existing
users by breaking the old way of configuration for sama5d2 platforms.

After discussions with the media maintainers, the decision is to move
Atmel ISC to staging as-is, to keep the Kconfig symbols and the users
to the driver in staging. Thus, all the existing users of the non
media-controller paradigm will continue to be happy and use the old config
way.

The converted driver would support both sama5d2 and sama7g5 platforms with
media controller paradigm, but it requires userspace configuration of the
pipeline for all the pipeline modules.

In a simple configuration sensor ==> isc , the old isc driver used to call
subdev s_fmt and control the sensor directly.
This was achieved by having a lot of code inside the driver that was
querying the subdev at probe time and made a list of formats which are
usable.
Basically the user had nothing to configure, as the isc would handle
everything at the top level. This was an easy way to capture, but also came
with the drawback of lack of flexibility.
In a more complicated pipeline
 sensor ==> controller 1 ==> controller 2 ==> isc
this would not be achievable, as controller 1 and controller 2 might be
media-controller configurable, and will not propagate the formats down to
the sensor.
The new driver Microchip ISC would solve all these problems and exposes pads
entities and links to userspace.
For the ease of tracking, the patches that convert to media controller come
on top of this patch that simply readds the driver to the new location under
the new Kconfig symbols.

To differentiate between the old driver and the new driver, I have renamed
the new driver to Microchip ISC, renaming the Kconfig symbols as well, and
all the mentions inside the driver.
The only thing that remains common is the file
include/linux/atmel-isc-media.h which is the ABI for the v4l2 custom
controls that the ISC exposes.
This file is used by both driver, so I kept it as-is.
To further avoid confusion all files have been renamed and all functions
named isc_* as well.
The exported symbols have been renamed with added microchip_ prefix, to
avoid symbol duplication with the old driver, and to avoid confusion.
Other than that, I have fixed small checkpatch issues when readding the
driver.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: atmel: move microchip_csi2dc to dedicated microchip platform
Eugen Hristev [Mon, 7 Nov 2022 14:18:13 +0000 (14:18 +0000)]
media: atmel: move microchip_csi2dc to dedicated microchip platform

The Atmel ISC will be moved to staging thus the atmel platform will only
have the ISI driver.
The new media-controller converted ISC driver will be placed inside a
dedicated microchip platform directory.
It is then natural to have the microchip-csi2dc moved to this new platform
directory.
The next step is to add the Microchip ISC driver to the new platform
directory and reside together with the Microchip CSI2DC driver.

Signed-off-by: Eugen Hristev <eugen.hristev@microchip.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: vb2/au0828: move the v4l_vb2q_enable_media_source to the au0828 driver
Hans Verkuil [Wed, 22 Jun 2022 09:31:45 +0000 (10:31 +0100)]
media: vb2/au0828: move the v4l_vb2q_enable_media_source to the au0828 driver

With the new prepare_streaming op it is possible to move the ugly
v4l_vb2q_enable_media_source() call in vb2_core_streamon to the
driver. It was called incorrectly in vb2 as well: it was only
called if sufficient buffers were queued at STREAMON time, but not
if more buffers were queued later. This was not an issue with the
au0828 driver since it never set min_buffers_needed.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: vb2: add (un)prepare_streaming queue ops
Hans Verkuil [Wed, 22 Jun 2022 09:31:44 +0000 (10:31 +0100)]
media: vb2: add (un)prepare_streaming queue ops

When userspace called VIDIOC_STREAMON, then you want to claim any streaming
resources needed and validate the video pipeline. Waiting for
start_streaming to be called is too late, since that can be postponed
until the required minimum of buffers is queued.

So add a prepare_streaming op (optional) that can be used for that
purpose, and a matching unprepare_streaming op (optional) that can
release any claimed resources. The unprepare_streaming op is called
when VIDIOC_STREAMOFF is called and q->streaming is 1, or when the
filehandle is closed while q->streaming is 1.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: admin-guide: cec.rst
Hans Verkuil [Tue, 27 Sep 2022 08:43:11 +0000 (09:43 +0100)]
media: admin-guide: cec.rst

Document administration details about CEC devices. This was formerly
documented in a cec-status.txt I kept on my website, but this really
belongs here as an admin guide.

Updated the original cec-status.txt, and converted it to .rst.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: staging: media: sunxi: cedrus: make vb2_ops struct definition const
Ian Cowan [Sun, 13 Nov 2022 01:47:03 +0000 (01:47 +0000)]
media: staging: media: sunxi: cedrus: make vb2_ops struct definition const

This cleans up a checkstyle warning where the vb2_ops struct definitions
should be const.

Signed-off-by: Ian Cowan <ian@linux.cowan.aero>
Reviewed-by: Samuel Holland <samuel@sholland.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: amphion: Fix error handling in vpu_driver_init()
Yuan Can [Fri, 11 Nov 2022 06:09:26 +0000 (06:09 +0000)]
media: amphion: Fix error handling in vpu_driver_init()

A problem about modprobe amphion-vpu failed is triggered with the
following log given:

 [ 2208.634841] Error: Driver 'amphion-vpu' is already registered, aborting...
 modprobe: ERROR: could not insert 'amphion_vpu': Device or resource busy

The reason is that vpu_driver_init() returns vpu_core_driver_init()
directly without checking its return value, if vpu_core_driver_init()
failed, it returns without unregister amphion_vpu_driver, resulting the
amphion-vpu can never be installed later.
A simple call graph is shown as below:

 vpu_driver_init()
   platform_driver_register() # register amphion_vpu_driver
   vpu_core_driver_init()
     platform_driver_register()
       driver_register()
         bus_add_driver()
           dev = kzalloc(...) # OOM happened
   # return without unregister amphion_vpu_driver

Fix by unregister amphion_vpu_driver when vpu_core_driver_init() returns
error.

Fixes: b50a64fc54af ("media: amphion: add amphion vpu device driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Reviewed-by: ming_qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: platform: exynos4-is: Fix error handling in fimc_md_init()
Yuan Can [Fri, 11 Nov 2022 06:08:53 +0000 (06:08 +0000)]
media: platform: exynos4-is: Fix error handling in fimc_md_init()

A problem about modprobe s5p_fimc failed is triggered with the
following log given:

 [  272.075275] Error: Driver 'exynos4-fimc' is already registered, aborting...
 modprobe: ERROR: could not insert 's5p_fimc': Device or resource busy

The reason is that fimc_md_init() returns platform_driver_register()
directly without checking its return value, if platform_driver_register()
failed, it returns without unregister fimc_driver, resulting the
s5p_fimc can never be installed later.
A simple call graph is shown as below:

 fimc_md_init()
   fimc_register_driver() # register fimc_driver
   platform_driver_register()
     platform_driver_register()
       driver_register()
         bus_add_driver()
           dev = kzalloc(...) # OOM happened
   # return without unregister fimc_driver

Fix by unregister fimc_driver when platform_driver_register() returns
error.

Fixes: d3953223b090 ("[media] s5p-fimc: Add the media device driver")
Signed-off-by: Yuan Can <yuancan@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: mtk-jpegdec: add missing destroy_workqueue()
Yang Yingliang [Thu, 10 Nov 2022 15:05:59 +0000 (15:05 +0000)]
media: mtk-jpegdec: add missing destroy_workqueue()

destroy_workqueue() needs be called to when driver is
unloading, fix it by using devm_add_action_or_reset()
to make workqueuedevice-managed.

Fixes: dedc21500334 ("media: mtk-jpegdec: add jpeg decode worker interface")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: aspeed: Use v4l2_dbg to replace v4l2_warn to avoid log spam
Jammy Huang [Thu, 10 Nov 2022 09:56:11 +0000 (09:56 +0000)]
media: aspeed: Use v4l2_dbg to replace v4l2_warn to avoid log spam

If the host is powered off, there will be many warning log. To avoid the
log spam in this condition, replace v4l2_warn with v4l2_dbg.

Signed-off-by: Jammy Huang <jammy_huang@aspeedtech.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: solo6x10: fix possible memory leak in solo_sysfs_init()
Yang Yingliang [Thu, 10 Nov 2022 08:24:23 +0000 (08:24 +0000)]
media: solo6x10: fix possible memory leak in solo_sysfs_init()

If device_register() returns error in solo_sysfs_init(), the
name allocated by dev_set_name() need be freed. As comment of
device_register() says, it should use put_device() to give up
the reference in the error path. So fix this by calling
put_device(), then the name can be freed in kobject_cleanup().

Fixes: dcae5dacbce5 ("[media] solo6x10: sync to latest code from Bluecherry's git repo")
Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: cedrus: Relax HEVC SPS restrictions
Jernej Skrabec [Wed, 9 Nov 2022 18:23:09 +0000 (18:23 +0000)]
media: cedrus: Relax HEVC SPS restrictions

Testing reference video TSUNEQBD_A_MAIN10_Technicolor_2 has show that
Cedrus is capable of decoding frames with different chroma and luma bit
depths.

Relax restrictions so only highest depth is checked.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: cedrus: h265: Support decoding 10-bit frames
Jernej Skrabec [Wed, 9 Nov 2022 18:23:08 +0000 (18:23 +0000)]
media: cedrus: h265: Support decoding 10-bit frames

10-bit frames needs extra buffer space when 8-bit capture format is
used. Use previously prepared infrastructure to adjust buffer size.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: cedrus: Adjust buffer size based on codec
Jernej Skrabec [Wed, 9 Nov 2022 18:23:07 +0000 (18:23 +0000)]
media: cedrus: Adjust buffer size based on codec

In some cases decoding engine needs extra space in capture buffers. This
is the case for decoding 10-bit HEVC frames into 8-bit capture format.
This commit only adds infrastructure for such cases.

Signed-off-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: s5p-mfc: Optimisation of code to remove error message
Aakarsh Jain [Wed, 9 Nov 2022 03:53:48 +0000 (03:53 +0000)]
media: s5p-mfc: Optimisation of code to remove error message

Already error number provision is present for block failing, while
requesting for DMA consistent memory allocation.
So removing error message line from the block as recommended
by scripts/checkpatch.pl.

Signed-off-by: Aakarsh Jain <aakarsh.jain@samsung.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: s5p-mfc:fix usage of Block comment alignment
Aakarsh Jain [Wed, 9 Nov 2022 03:53:47 +0000 (03:53 +0000)]
media: s5p-mfc:fix usage of Block comment alignment

Fix usage of block comment alignment in drivers/media/platform/samsung/
s5p-mfc/s5p_mfc.c as recommended by scripts/checkpatch.pl.

Signed-off-by: Aakarsh Jain <aakarsh.jain@samsung.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: s5p-mfc: fix usage of symbolic permissions to octal
Aakarsh Jain [Wed, 9 Nov 2022 03:53:46 +0000 (03:53 +0000)]
media: s5p-mfc: fix usage of symbolic permissions to octal

Change symbolic permissions to octal equivalent as recommended
by scripts/checkpatch.pl in drivers/media/platform/samsung/
s5p-mfc/s5p_mfc.c.

Signed-off-by: Aakarsh Jain <aakarsh.jain@samsung.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: vidtv: Fix use-after-free in vidtv_bridge_dvb_init()
Chen Zhongjin [Tue, 8 Nov 2022 07:06:30 +0000 (07:06 +0000)]
media: vidtv: Fix use-after-free in vidtv_bridge_dvb_init()

KASAN reports a use-after-free:
BUG: KASAN: use-after-free in dvb_dmxdev_release+0x4d5/0x5d0 [dvb_core]
Call Trace:
 ...
 dvb_dmxdev_release+0x4d5/0x5d0 [dvb_core]
 vidtv_bridge_probe+0x7bf/0xa40 [dvb_vidtv_bridge]
 platform_probe+0xb6/0x170
 ...
Allocated by task 1238:
 ...
 dvb_register_device+0x1a7/0xa70 [dvb_core]
 dvb_dmxdev_init+0x2af/0x4a0 [dvb_core]
 vidtv_bridge_probe+0x766/0xa40 [dvb_vidtv_bridge]
 ...
Freed by task 1238:
 dvb_register_device+0x6d2/0xa70 [dvb_core]
 dvb_dmxdev_init+0x2af/0x4a0 [dvb_core]
 vidtv_bridge_probe+0x766/0xa40 [dvb_vidtv_bridge]
 ...

It is because the error handling in vidtv_bridge_dvb_init() is wrong.

First, vidtv_bridge_dmx(dev)_init() will clean themselves when fail, but
goto fail_dmx(_dev): calls release functions again, which causes
use-after-free.

Also, in fail_fe, fail_tuner_probe and fail_demod_probe, j = i will cause
out-of-bound when i finished its loop (i == NUM_FE). And the loop
releasing is wrong, although now NUM_FE is 1 so it won't cause problem.

Fix this by correctly releasing everything.

Fixes: f90cf6079bf6 ("media: vidtv: add a bridge driver")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: staging: media: meson: vdec: use min() for comparison and assignment
Deepak R Varma [Mon, 7 Nov 2022 19:11:21 +0000 (19:11 +0000)]
media: staging: media: meson: vdec: use min() for comparison and assignment

Use of standard min() helper macro is preferred over using ternary
operator for logical evaluation and value assignment. This issue is
identified by coccicheck using the minmax.cocci file.

Signed-off-by: Deepak R Varma <drv@mailo.com>
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: visl: add virtual stateless decoder driver
Daniel Almeida [Sat, 5 Nov 2022 13:58:42 +0000 (13:58 +0000)]
media: visl: add virtual stateless decoder driver

A virtual stateless device for stateless uAPI development purposes.

This tool's objective is to help the development and testing of
userspace applications that use the V4L2 stateless API to decode media.

A userspace implementation can use visl to run a decoding loop even when
no hardware is available or when the kernel uAPI for the codec has not
been upstreamed yet. This can reveal bugs at an early stage.

This driver can also trace the contents of the V4L2 controls submitted
to it.  It can also dump the contents of the vb2 buffers through a
debugfs interface. This is in many ways similar to the tracing
infrastructure available for other popular encode/decode APIs out there
and can help develop a userspace application by using another (working)
one as a reference.

Note that no actual decoding of video frames is performed by visl. The
V4L2 test pattern generator is used to write various debug information
to the capture buffers instead.

Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: amphion: apply vb2_queue_error instead of setting manually
Ming Qian [Tue, 1 Nov 2022 08:04:53 +0000 (08:04 +0000)]
media: amphion: apply vb2_queue_error instead of setting manually

vb2_queue_error is help to set the error of vb2_queue,
don't need to set it manually

Fixes: 3cd084519c6f ("media: amphion: add vpu v4l2 m2m support")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: amphion: add lock around vdec_g_fmt
Ming Qian [Tue, 1 Nov 2022 08:04:20 +0000 (08:04 +0000)]
media: amphion: add lock around vdec_g_fmt

the capture format may be changed when
sequence header is parsed,
it may be read and write in the same time,
add lock around vdec_g_fmt to synchronize it

Fixes: 6de8d628df6e ("media: amphion: add v4l2 m2m vpu decoder stateful driver")
Signed-off-by: Ming Qian <ming.qian@nxp.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: vimc: Fix wrong function called when vimc_init() fails
Chen Zhongjin [Thu, 10 Nov 2022 07:26:33 +0000 (07:26 +0000)]
media: vimc: Fix wrong function called when vimc_init() fails

In vimc_init(), when platform_driver_register(&vimc_pdrv) fails,
platform_driver_unregister(&vimc_pdrv) is wrongly called rather than
platform_device_unregister(&vimc_pdev), which causes kernel warning:

 Unexpected driver unregister!
 WARNING: CPU: 1 PID: 14517 at drivers/base/driver.c:270 driver_unregister+0x8f/0xb0
 RIP: 0010:driver_unregister+0x8f/0xb0
 Call Trace:
  <TASK>
  vimc_init+0x7d/0x1000 [vimc]
  do_one_initcall+0xd0/0x4e0
  do_init_module+0x1cf/0x6b0
  load_module+0x65c2/0x7820

Fixes: 4a29b7090749 ("[media] vimc: Subdevices as modules")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add support for hooking to the isp devices
Paul Kocialkowski [Thu, 3 Nov 2022 16:37:17 +0000 (16:37 +0000)]
media: sun6i-csi: Add support for hooking to the isp devices

In order to use the isp and csi together, both devices need to be
parented to the same v4l2 and media devices. We use the isp as
top-level device and let the csi code hook to its v4l2 and media
devices when async subdev registration takes place.

As a result v4l2/media device setup is only called when the ISP
is missing and the capture device is registered after the devices
are hooked. The bridge subdev and its notifier are registered
without any device when the ISP is available. Top-level pointers
for the devices are introduced to either redirect to the hooked ones
(isp available) or the registered ones (isp missing).

Also keep track of whether the capture node was setup or not to
avoid cleaning up resources when it wasn't.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Detect the availability of the ISP
Paul Kocialkowski [Thu, 3 Nov 2022 16:37:16 +0000 (16:37 +0000)]
media: sun6i-csi: Detect the availability of the ISP

Add a helper to detect whether the ISP is available and connected
and store the indication in the driver-specific device structure.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: MAINTAINERS: Add entry for the Allwinner A31 ISP driver
Paul Kocialkowski [Thu, 3 Nov 2022 16:37:15 +0000 (16:37 +0000)]
media: MAINTAINERS: Add entry for the Allwinner A31 ISP driver

Add myself as maintainer of the Allwinner A31 ISP media driver.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: staging: media: Add support for the Allwinner A31 ISP
Paul Kocialkowski [Thu, 3 Nov 2022 16:37:14 +0000 (16:37 +0000)]
media: staging: media: Add support for the Allwinner A31 ISP

Some Allwinner platforms come with an Image Signal Processor, which
supports various features in order to enhance and transform data
received by image sensors into good-looking pictures. In most cases,
the data is raw bayer, which gets internally converted to RGB and
finally YUV, which is what the hardware produces.

This driver supports ISPs that are similar to the A31 ISP, which was
the first standalone ISP found in Allwinner platforms. Simpler ISP
blocks were found in the A10 and A20, where they are tied to a CSI
controller. Newer generations of Allwinner SoCs (starting with the
H6, H616, etc) come with a new camera subsystem and revised ISP.
Even though these previous and next-generation ISPs are somewhat
similar to the A31 ISP, they have enough significant differences to
be out of the scope of this driver.

While the ISP supports many features, including 3A and many
enhancement blocks, this implementation is limited to the following:
- V3s (V3/S3) platform support;
- Bayer media bus formats as input;
- Semi-planar YUV (NV12/NV21) as output;
- Debayering with per-component gain and offset configuration;
- 2D noise filtering with configurable coefficients.

Since many features are missing from the associated uAPI, the driver
is aimed to integrate staging until all features are properly
described.

On the technical side, it uses the v4l2 and media controller APIs,
with a video node for capture, a processor subdev and a video node
for parameters submission. A specific uAPI structure and associated
v4l2 meta format are used to configure parameters of the supported
modules.

One particular thing about the hardware is that configuration for
module registers needs to be stored in a DMA buffer and gets copied
to actual registers by the hardware at the next vsync, when instructed
by a flag. This is handled by the "state" mechanism in the driver.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: dt-bindings: media: sun6i-a31-csi: Add internal output port to the ISP
Paul Kocialkowski [Thu, 3 Nov 2022 16:37:13 +0000 (16:37 +0000)]
media: dt-bindings: media: sun6i-a31-csi: Add internal output port to the ISP

Some Allwinner devices come with an Image Signal Processor (ISP) that
allows processing camera data to produce good-looking images,
especially from raw bayer representations.

The ISP does not have a dedicated capture path: it is fed directly by
one of the CSI controllers, which can be selected at run-time.

Represent this possibility as a graph connection between the CSI
controller and the ISP in the device-tree bindings.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: dt-bindings: media: Add Allwinner A31 ISP bindings documentation
Paul Kocialkowski [Thu, 3 Nov 2022 16:37:12 +0000 (16:37 +0000)]
media: dt-bindings: media: Add Allwinner A31 ISP bindings documentation

This introduces YAML bindings documentation for the Allwinner A31 Image
Signal Processor (ISP).

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: MAINTAINERS: Add myself as sun6i-csi maintainer and rename/move entry
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:13 +0000 (16:31 +0000)]
media: MAINTAINERS: Add myself as sun6i-csi maintainer and rename/move entry

Given the substantial rework of the driver that I carried out and the
knowledge acquired about the hardware along the way, make myself a
maintainer of the sun6i-csi driver.

Also rename and move the entry while at it since the driver is not
specific to the V3s.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Request a shared interrupt
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:12 +0000 (16:31 +0000)]
media: sun6i-csi: Request a shared interrupt

Request our interrupt shared since it is typically shared with the isp
block. The interrupt routine looks good to go for shared irq.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add extra checks to the interrupt routine
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:11 +0000 (16:31 +0000)]
media: sun6i-csi: Add extra checks to the interrupt routine

Check against the enabled bits and make sure capture is running before
serving an interrupt, to add extra safety in the process.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Only configure capture when streaming
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:10 +0000 (16:31 +0000)]
media: sun6i-csi: Only configure capture when streaming

Add a streaming element to the capture state structure to know if the
capture device is used or not. Only configure things related to output
when streaming, including the output format, irq, state (dma buffer)
and window configuration registers.

After this change, it becomes possible to use the bridge without the
capture device, which will be the case in the isp media flow.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add support for MIPI CSI-2 to the bridge code
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:09 +0000 (16:31 +0000)]
media: sun6i-csi: Add support for MIPI CSI-2 to the bridge code

Introduce MIPI CSI-2 support to the bridge with a new port, source
and hardware configuration helper.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Cleanup headers and includes, update copyright lines
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:08 +0000 (16:31 +0000)]
media: sun6i-csi: Cleanup headers and includes, update copyright lines

Cleanup includes, update copyright lines and some cosmetic changes.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Rename the capture video device to sun6i-csi-capture
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:07 +0000 (16:31 +0000)]
media: sun6i-csi: Rename the capture video device to sun6i-csi-capture

Now that the driver is properly split between bridge and capture,
rename the video device to highlight its role and be in line with
the bridge entity naming.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Move hardware control to the bridge
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:06 +0000 (16:31 +0000)]
media: sun6i-csi: Move hardware control to the bridge

In order to support the isp workflow, we need to be able to configure
the hardware from the bridge when the capture device is not used.

As a result, move all hardware configuration calls from capture to
the bridge. Only the window configuration part (which is specific
to using capture) remains there.

This effectively opens the way for hooking the bridge to the
isp in the future.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Get bridge subdev directly in capture stream ops
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:05 +0000 (16:31 +0000)]
media: sun6i-csi: Get bridge subdev directly in capture stream ops

The remote subdev connected to the capture video device is always
our bridge, so get the bridge subdev directly instead of using a
dedicated helper (which is removed by this commit).

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Implement capture link validation with logic
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:03 +0000 (16:31 +0000)]
media: sun6i-csi: Implement capture link validation with logic

Rework the capture link validate implementation with actual logic that
reflects the possibilities of the device instead of the combinatory helper
functions, using the added match list helper
sun6i_csi_is_format_supported() when needed. Remove the previous dedicated
helper.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Configure registers from format tables
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:02 +0000 (16:31 +0000)]
media: sun6i-csi: Configure registers from format tables

Switch over to using the static format table descriptions to configure
registers. Rework the hardware configuration helpers to leverage
information from the format structures and benefit from their logic.
Remove the previous dedicated helpers.

The intention is to make the interaction between the different formats
and the hardware side more visible and clear.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Introduce capture format structure, list and helper
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:01 +0000 (16:31 +0000)]
media: sun6i-csi: Introduce capture format structure, list and helper

Add a table that describes each pixel format and associated output
register configuration with necessary tweaks. It will be used later on
to configure the hardware.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Introduce bridge format structure, list and helper
Paul Kocialkowski [Thu, 3 Nov 2022 16:31:00 +0000 (16:31 +0000)]
media: sun6i-csi: Introduce bridge format structure, list and helper

Introduce a more informative format list for the bridge, with
information about how to configure the input. This separation will
later be useful when using the bridge standalone (without capture)
for the isp workflow.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Tidy capture configure code
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:59 +0000 (16:30 +0000)]
media: sun6i-csi: Tidy capture configure code

Some misc code cleanups and preparation for upcoming changes.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Get mbus code from bridge instead of storing it
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:58 +0000 (16:30 +0000)]
media: sun6i-csi: Get mbus code from bridge instead of storing it

Another instance of removing a duplicated variable and using common
helpers instead.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add bridge dimensions and format helpers
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:57 +0000 (16:30 +0000)]
media: sun6i-csi: Add bridge dimensions and format helpers

Introduce new helpers to ease getting information about the bridge.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Remove custom format helper and rework configure
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:56 +0000 (16:30 +0000)]
media: sun6i-csi: Remove custom format helper and rework configure

Remove the custom sun6i_csi_get_bpp helper in favor of common v4l2
infrastructure and rework the related window configuration code.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Rework capture format management with helper
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:55 +0000 (16:30 +0000)]
media: sun6i-csi: Rework capture format management with helper

Remove the need for local copies of the v4l2 format and add a common
helper to prepare a format compatible with the driver, using the
relevant v4l2 helpers.

Report a raw colorspace for bayer-encoded pixel formats instead of SRGB.
Also cleanup the size bound defines while at it.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Move register configuration to capture
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:54 +0000 (16:30 +0000)]
media: sun6i-csi: Move register configuration to capture

Continue moving things over to capture in tidy helpers.
Also take the occasion to remove the config struct, which is
unwelcome redundancy and use the capture helpers instead.

The code is only adapted to reflect the removal of the config
structure. No functional change intended.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Move power management to runtime pm in capture
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:53 +0000 (16:30 +0000)]
media: sun6i-csi: Move power management to runtime pm in capture

Let's just enable the module when we start using it (at stream on)
and benefit from runtime pm instead of enabling it at first open.

Also reorder the call to v4l2_pipeline_pm_get.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Split stream sequences and irq code in capture
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:52 +0000 (16:30 +0000)]
media: sun6i-csi: Split stream sequences and irq code in capture

Create minimal helpers that split the enable/disable flow, which will
make it easier to move control over to the bridge later on.

Generally speaking the goal is to move register configuration to
the capture code and later split it with the bridge code.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Implement address configuration without indirection
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:51 +0000 (16:30 +0000)]
media: sun6i-csi: Implement address configuration without indirection

Instead of calculating the planar_offset at one point and using it
later in a dedicated function, reimplement address configuration
with v4l2 format info in the buffer_configure function.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add dimensions and format helpers to capture
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:50 +0000 (16:30 +0000)]
media: sun6i-csi: Add dimensions and format helpers to capture

Define and export useful helpers to access dimensions and pixel format.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Rework register definitions, invert misleading fields
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:49 +0000 (16:30 +0000)]
media: sun6i-csi: Rework register definitions, invert misleading fields

This cleans up the register definitions a bit, adds a prefix, remove masks.
Registers are now fully defined, some additional fields were added when
needed. New format definitions are added for future use.

Some fields are wrongly defined (inverted) in Allwinner literature
(e.g. field vs frame prefixes), which is quite misleading. They are
now corrected to reflect their actual behavior.

This should only be a cosmetic commit. No functional change intended.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add capture state using vsync for page flip
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:48 +0000 (16:30 +0000)]
media: sun6i-csi: Add capture state using vsync for page flip

The current implementation requires up to 3 buffers to properly
implement page flipping without losing frames: one is configured
before the video stream is started, one just after that and page
flipping is synchronized to the frame done interrupt. The comment in
the code mentions that "CSI will lookup the next dma buffer for next
frame before the current frame done IRQ triggered".

Based on observations of the CSI unit behavior, it seems that the
buffer DMA address is sampled when the frame scan begins (in addition
to starting the stream), which corresponds to the vblank interrupt
that hits just before the frame-done interrupt of the previous frame.

As a result, the address configured at the frame done interrupt is not
actually used for the next frame but for the one after that.

This proposal changes the page flipping sync point to the vsync
interrupt, which allows the DMA address to be sampled for the next
frame instead and allows operating with only two buffers.

In addition to the change in the sync point, the code is refactored
to introduce a notion of state that clarifies tracking of the buffers
with tidy functions.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Rename sun6i_video to sun6i_csi_capture
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:47 +0000 (16:30 +0000)]
media: sun6i-csi: Rename sun6i_video to sun6i_csi_capture

In an effort to distinguish between the core csi engine (to be
represented as the bridge) and the dma engine (the capture video
device), rename the video component to capture, with the appropriate
prefix. No functional change intended.

[Sakari Ailus: fix wrong variable issue (video -> capture) missed in patch]

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Reviewed-by: Maxime Ripard <maxime@cerno.tech>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: sun6i-csi: Add bridge v4l2 subdev with port management
Paul Kocialkowski [Thu, 3 Nov 2022 16:30:46 +0000 (16:30 +0000)]
media: sun6i-csi: Add bridge v4l2 subdev with port management

Introduce a bridge v4l2 subdev to prepare for separation between the
processing part (bridge) and the dma engine, which is required to
properly support ths isp workflow later on.

Currently the bridge just manages fwnode mapping to media pads,
using an async notifier (which was previously in the main code).
The s_stream video op just forwards to the connected v4l2 subdev
(sensor or MIPI CSI-2 bridge).

The video capture device is now registered after the bridge and
attaches to it with a media link.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Acked-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Support event handlers
Dave Stevenson [Fri, 28 Oct 2022 16:09:02 +0000 (17:09 +0100)]
media: i2c: ov9282: Support event handlers

As noted in the headers for V4L2_SUBDEV_FL_HAS_EVENTS,
"controls can send events, thus drivers exposing controls
should set this flag".

This driver exposes controls, but didn't reflect that it
could generate events. Correct this, and add the default
event handler functions.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Add support for 8bit readout
Dave Stevenson [Fri, 28 Oct 2022 16:09:01 +0000 (17:09 +0100)]
media: i2c: ov9282: Add support for 8bit readout

The sensor supports 8 or 10 bit readout modes, but the
driver only supported 10 bit.

Add 8 bit readout.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Add support for 1280x800 and 640x400 modes
Dave Stevenson [Fri, 28 Oct 2022 16:09:00 +0000 (17:09 +0100)]
media: i2c: ov9282: Add support for 1280x800 and 640x400 modes

Adds register settings for additional modes.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Add selection API calls for cropping info
Dave Stevenson [Fri, 28 Oct 2022 16:08:59 +0000 (17:08 +0100)]
media: i2c: ov9282: Add selection API calls for cropping info

As required by libcamera, add the relevant cropping targets
to report which portion of the sensor is being read out in
any mode.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Make V4L2_CID_HBLANK r/w
Dave Stevenson [Fri, 28 Oct 2022 16:08:58 +0000 (17:08 +0100)]
media: i2c: ov9282: Make V4L2_CID_HBLANK r/w

There's no reason why HBLANK has to be read-only as it
only changes the TIMING_HTS register in the sensor.

Remove the READ_ONLY flag, and add the relevant handling
for it.

The minimum value also varies based on whether continuous clock
mode is being used or not, so allow hblank_min to depend on
that.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Add HFLIP and VFLIP support
Dave Stevenson [Fri, 28 Oct 2022 16:08:57 +0000 (17:08 +0100)]
media: i2c: ov9282: Add HFLIP and VFLIP support

Adds support for V4L2_CID_HFLIP and V4L2_CID_VFLIP to allow
flipping the image.

The driver previously enabled H & V flips in the register table,
therefore the controls default to the same settings to avoid
changing the behaviour.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Action CID_VBLANK when set.
Dave Stevenson [Fri, 28 Oct 2022 16:08:56 +0000 (17:08 +0100)]
media: i2c: ov9282: Action CID_VBLANK when set.

Programming the sensor with TIMING_VTS (aka LPFR) was done
when triggered by a change in exposure or gain, but not
when V4L2_CID_VBLANK was changed. Dynamic frame rate
changes could therefore not be achieved.

Separate out programming TIMING_VTS so that it is triggered
by set_ctrl(V4L2_CID_VBLANK)

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Add the properties from fwnode
Dave Stevenson [Fri, 28 Oct 2022 16:08:55 +0000 (17:08 +0100)]
media: i2c: ov9282: Add the properties from fwnode

Use v4l2_ctrl_new_fwnode_properties to add V4L2_CID_CAMERA_ORIENTATION
and V4L2_CID_CAMERA_SENSOR_ROTATION.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Add selection for CSI2 clock mode
Dave Stevenson [Fri, 28 Oct 2022 16:08:54 +0000 (17:08 +0100)]
media: i2c: ov9282: Add selection for CSI2 clock mode

The sensor supports either having the CSI2 clock lane free
running, or gated when there is no packet to transmit.
The driver only selected gated (non-continuous) clock mode.

Add code to allow fwnode to configure whether the clock is
gated or free running.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Reduce vblank_min values based on testing
Dave Stevenson [Fri, 28 Oct 2022 16:08:53 +0000 (17:08 +0100)]
media: i2c: ov9282: Reduce vblank_min values based on testing

The configured vblank_min setting of 151 (meaning VTS of
720 + 151 = 871) is far higher than the setting that works on
the sensor, and there are no obvious restrictions stated in the
datasheet.

Reduce the vblank_min to allow for faster frame rates.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Correct HTS register for configured pixel rate
Dave Stevenson [Fri, 28 Oct 2022 16:08:52 +0000 (17:08 +0100)]
media: i2c: ov9282: Correct HTS register for configured pixel rate

The calculations from pixel rate, width+hblank, and height+vblank
do not give the correct framerate - it's half the speed it should
be.

The datasheet lists the default for the TIMING_HTS registers (0x380c/d)
as being 0x2d8 (728) which is less than the width of the image, so
the units clearly can't be pixels.
If TIMING_HTS is considered to be units of 2-pixels, then the
resulting value of 0x5b0 (1456) makes all the calculations correct.

This driver is reporting an HBLANK value of 250, with an image width
of 1280, so TIMING_HTS is 1530 (0x5fa) pixels. However it was also
setting the register to 0x5fa, thereby not taking into account it
being units of 2-pixels.

Correct the register value to 0x2fd so that all the timing calculations
give the correct results.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Support more than 1 mode.
Dave Stevenson [Fri, 28 Oct 2022 16:08:51 +0000 (17:08 +0100)]
media: i2c: ov9282: Support more than 1 mode.

The driver currently has multiple assumptions that there is
only one supported mode.

Convert supported_mode to an array, and fix up all references
to correctly look at that array.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Remove pixel rate from mode definition
Dave Stevenson [Fri, 28 Oct 2022 16:08:50 +0000 (17:08 +0100)]
media: i2c: ov9282: Remove pixel rate from mode definition

The pixel rate is determined by the PLL setup in the common
registers, not by the mode specific registers, therefore
remove it from the mode definition and define it for all modes.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Remove format code from the mode
Dave Stevenson [Fri, 28 Oct 2022 16:08:49 +0000 (17:08 +0100)]
media: i2c: ov9282: Remove format code from the mode

The format code is independent of mode, and each mode could
support both Y10 and Y8, so disassociate the code from the
mode.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Split registers into common and mode specific
Dave Stevenson [Fri, 28 Oct 2022 16:08:48 +0000 (17:08 +0100)]
media: i2c: ov9282: Split registers into common and mode specific

Currently only one mode is supported, so all registers were
dropped in one list.
In preparation for adding more modes, split out the common registers
from those which configure the mode.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov9282: Remove duplication of registers
Dave Stevenson [Fri, 28 Oct 2022 16:08:47 +0000 (17:08 +0100)]
media: i2c: ov9282: Remove duplication of registers

TIMING_VTS (registers 0x380e/f), EXPOSURE (registers
0x3500/1/2), and GAIN (0x3509) are all set from
ov9282_update_exp_gain as part of the control handler,
therefore they do not need to be in the main list of
registers.

Remove them.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov5645: Call ov5645_entity_init_cfg() before registering the subdev
Lad Prabhakar [Mon, 31 Oct 2022 23:22:02 +0000 (23:22 +0000)]
media: i2c: ov5645: Call ov5645_entity_init_cfg() before registering the subdev

Make sure we call ov5645_entity_init_cfg() before registering the subdev
to make sure default formats are set up.

Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov5645: Make sure to call PM functions
Lad Prabhakar [Mon, 31 Oct 2022 23:22:01 +0000 (23:22 +0000)]
media: i2c: ov5645: Make sure to call PM functions

Make sure we call the PM functions while s_stream(0) even in case of
errors in the code flow.

v4l2-core takes care of warning the user so no need to add a warning
message in the driver.

Suggested-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov5645: Drop empty comment
Lad Prabhakar [Mon, 31 Oct 2022 23:22:00 +0000 (23:22 +0000)]
media: i2c: ov5645: Drop empty comment

Drop empty multiline comment.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: ov5645: Use runtime PM
Lad Prabhakar [Mon, 31 Oct 2022 23:21:59 +0000 (23:21 +0000)]
media: i2c: ov5645: Use runtime PM

Switch to using runtime PM for power management.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: dt-bindings: ov5645: Convert OV5645 binding to a schema
Lad Prabhakar [Mon, 31 Oct 2022 23:21:58 +0000 (23:21 +0000)]
media: dt-bindings: ov5645: Convert OV5645 binding to a schema

Convert the simple OV5645 Device Tree binding to json-schema.

The previous binding marked the below properties as required which was a
driver requirement and not the device requirement so just drop them from
the required list during the conversion.
- clock-frequency
- enable-gpios
- reset-gpios

Also drop the "clock-names" property as we have a single clock source for
the sensor and the driver has been updated to drop the clk referencing by
name.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: arm64: dts: renesas: aistarvision-mipi-adapter-2.1: Drop clock-names property
Lad Prabhakar [Mon, 31 Oct 2022 23:21:57 +0000 (23:21 +0000)]
media: arm64: dts: renesas: aistarvision-mipi-adapter-2.1: Drop clock-names property

Now that the driver has been updated to drop fetching the clk reference by
name we no longer need the clock-names property in the ov5645 sensor node.

This is in preparation for removal for clock-names property from the DT
binding.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: ARM: dts: imx6qdl-wandboard: Drop clock-names property
Lad Prabhakar [Mon, 31 Oct 2022 23:21:56 +0000 (23:21 +0000)]
media: ARM: dts: imx6qdl-wandboard: Drop clock-names property

Now that the driver has been updated to drop fetching the clk reference by
name we no longer need the clock-names property in the ov5645 sensor node.

This is in preparation for removal for clock-names property from the DT
binding.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Acked-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: ARM: dts: imx6qdl-pico: Drop clock-names property
Lad Prabhakar [Mon, 31 Oct 2022 23:21:55 +0000 (23:21 +0000)]
media: ARM: dts: imx6qdl-pico: Drop clock-names property

Now that the driver has been updated to drop fetching the clk reference by
name we no longer need the clock-names property in the ov5645 sensor node.

This is in preparation for removal for clock-names property from the
DT binding.

Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com>
Acked-by: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: imx412: Add new compatible strings
Bryan O'Donoghue [Fri, 14 Oct 2022 18:04:17 +0000 (19:04 +0100)]
media: i2c: imx412: Add new compatible strings

The Sony imx577 uses the same silicon enabling reference code in the
available examples provided as the imx412.

Add in compatible strings to enable and differentiate the parts.

Cc: sakari.ailus@iki.fi
Cc: dave.stevenson@raspberrypi.com
Cc: jacopo@jmondi.org
Cc: "Paul J. Murphy" <paul.j.murphy@intel.com>
Cc: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: i2c: imx412: Assign v4l2 device subname based on compat string
Bryan O'Donoghue [Fri, 14 Oct 2022 18:04:16 +0000 (19:04 +0100)]
media: i2c: imx412: Assign v4l2 device subname based on compat string

imx412 and imx577 return the same chip-id when interrogated via i2c.
I've confirmed this myself by

Sakari suggested we should add a new compat which should be reflected in
the name of the media entity

https://patchwork.kernel.org/project/linux-media/patch/20220607134057.2427663-3-bryan.odonoghue@linaro.org/#24894500

Set up the .data parameter of of_device_id to pass a string which
we use to set the media entity name. Once done we can add in imx577 as a
compatible chips with the media names reflecting the directed compat string.

Cc: sakari.ailus@iki.fi
Cc: dave.stevenson@raspberrypi.com
Cc: jacopo@jmondi.org
Cc: "Paul J. Murphy" <paul.j.murphy@intel.com>
Cc: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
20 months agomedia: dt-bindings: imx412: Extend compatible strings
Bryan O'Donoghue [Fri, 14 Oct 2022 18:04:15 +0000 (19:04 +0100)]
media: dt-bindings: imx412: Extend compatible strings

Add compatible bindings for imx577 which uses the same silicon enabling
reference code from Sony in the available examples provided.

Cc: sakari.ailus@iki.fi
Cc: dave.stevenson@raspberrypi.com
Cc: jacopo@jmondi.org
Cc: "Paul J. Murphy" <paul.j.murphy@intel.com>
Cc: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
Cc: Rob Herring <robh+dt@kernel.org>
Cc: Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>
Cc: devicetree@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
Acked-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>