Skip to content

Upstream Unicam driver - #3688

Merged
pelwell merged 20 commits into
raspberrypi:rpi-5.4.yfrom
6by9:rpi-5.4.y-unicam
Jun 26, 2020
Merged

pelwell merged 20 commits into
raspberrypi:rpi-5.4.yfrom
6by9:rpi-5.4.y-unicam

Conversation

@6by9

@6by9 6by9 commented Jun 23, 2020

Copy link
Copy Markdown
Contributor

Whilst not merged, this takes the upstream Unicam driver, backports it to 5.4, and includes any of our fixes since then, and those raised by upstream. With those patches squashed it should be a reasonable v3.
It is dependent on another upstream patchset that hasn't been merged yet for dynamically changing the number of active CSI data lanes being used, so that has been backported as well.

DT has changed slightly, so those are all fixed up as well.

@6by9

6by9 commented Jun 23, 2020

Copy link
Copy Markdown
Contributor Author

@davidplowman @naushir Please test. It's working for me with TC358743, but I haven't tried the camera modules and libcamera.

@pinchartl Hopefully a good next step for v3.
Drop caa8557 and you could still upstream it without the dependency on Jacopo's patchset.

Now on to the ISP driver and vc-sm-cma....

@naushir

naushir commented Jun 24, 2020

Copy link
Copy Markdown
Contributor

Looks to be working fine for me in libcamera.

Jacopo Mondi and others added 15 commits June 26, 2020 15:19
Upstream https://patchwork.linuxtv.org/patch/64669/

Introduce two new pad operations to allow retrieving and configuring the
media bus parameters on a subdevice pad.

The newly introduced operations aims to replace the s/g_mbus_config video
operations, which have been on their way for deprecation since a long
time.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64669/

Move the existing users of the g_mbus_config video operation to use the
newly introduced get_mbus_config pad operations.

All the ported drivers report a static media bus configuration and do no
support s_mbus_config so the operation implementation has not changed.

Bridge drivers needs to call the new pad operation and will receive an
-ENOICTLCMD when calling the old g_mbus_config video operation

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64674/

Use the new get_mbus_config and set_mbus_config pad operations in place
of the video operations currently in use.

Compared to other drivers where the same conversion has been performed,
ov6650 proved to be a bit more tricky, as the existing g_mbus_config
implementation did not report the currently applied configuration but
the set of all possible configuration options.

Adapt the driver to support the semantic of the two newly introduced
operations:
- get_mbus_config reports the current media bus configuration
- set_mbus_config applies only changes explicitly requested and updates
  the provided cfg parameter to report what has actually been applied to
  the hardware.

Compile-tested only.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64671/

Move the PXA camera driver to use the new set_mbus_config pad operation.
For this platform the change is not only cosmetic, as the pxa driver is
currently the only driver in mainline to make use of the g_mbus_config
and s_mbus_config video operations.

The existing driver semantic is the following:
- Collect all supported mbus config flags from the remote end
- Match them with the supported PXA mbus configuration flags
- If the remote subdevice allows multiple options for for VSYNC, HSYNC
  and PCLK polarity, use platform data requested settings

The semantic of the new get_mbus_config and set_mbus_config differs from
the corresponding video ops, particularly in the fact get_mbus_config
reports the current mbus configuration and not the set of supported
configuration options, with set_mbus_config always reporting the actual
mbus configuration applied to the remote subdevice.

Adapt the driver to perform the following
- Set the remote subdevice mbus configuration according to the PXA
  platform data preferences.
- If the applied configuration differs from the requested one (i.e. the
  remote subdevice does not allow changing one setting) make sure that
  - The remote end does not claim for DATA_ACTIVE_LOW, which seems not
    supported by the platform
  - The bus mastering roles match

While at there remove a few checks performed on the media bus
configuration at get_format() time as they do not belong there.

Compile-tested only.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64670/

With all sensor and platform drivers now converted to use the new
get_mbus_config and set_mbus_config pad operations, remove the
deprecated video operations g_mbus_config and s_mbus_config.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64672/

Update the TODO entry that mentioned a potential use case for the now
removed g_mbus_config video operation.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64673/

When outputting SD-Core output through the TXA MIPI CSI-2 interface,
the number of enabled data lanes should be reduced in order to guarantee
that the two video formats produced by the SD-Core (480i and 576i)
generate a MIPI CSI-2 link clock frequency compatible with the MIPI D-PHY
specifications.

Limit the number of enabled data lanes to 2, which is guaranteed to
support 480i and 576i formats.

Cache the number of enabled data lanes to be able to report it through
the new get_mbus_config operation.

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64676/

Implement the newly introduced get_mbus_config operation to report the
number of currently used data lanes on the MIPI CSI-2 interface.

Reviewed-by: Kieran Bingham <kieran.bingham+renesas@ideasonboard.com>
Reviewed-by: Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
Upstream https://patchwork.linuxtv.org/patch/64675/

Use the newly introduced get_mbus_config() subdevice pad operation to
retrieve the remote subdevice MIPI CSI-2 bus configuration and configure
the number of active data lanes accordingly.

In order to be able to call the remote subdevice operation cache the
index of the remote pad connected to the single CSI-2 input port.

Signed-off-by: Jacopo Mondi <jacopo+renesas@jmondi.org>
About to be replaced by the upstream version.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Upsstream are renaming VFL_TYPE_GRABBER to VFL_TYPE_VIDEO.
To make backporting the upstream Unicam driver easier, add an
extra enum entry (same as VFL_TYPE_GRABBER) to match that.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Add a driver for the Unicam camera receiver block on BCM283x processors.
Compared to the bcm2835-camera driver present in staging, this driver
handles the Unicam block only (CSI-2 receiver), and doesn't depend on
the VC4 firmware running on the VPU.

The commit is made up of a series of changes cherry-picked from the
rpi-5.4.y branch of https://github.com/raspberrypi/linux/ with
additional enhancements, forward-ported to the mainline kernel.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Naushir Patuck <naush@raspberrypi.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reported-by: kbuild test robot <lkp@intel.com>
Use the get_mbus_config pad subdev call to allow a source to use
fewer than the number of CSI2 lanes defined in device tree.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
From when bringing up the driver, there was a check in the isr
to ignore interrupts (claiming them handled) should the driver
not be streaming.

The VPU now will not register a camera driver if it finds a
CSI2 node enabled in device tree, therefore this flawed check is
redundant.

raspberrypi#3602

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Jacko Dirks <jdirks.linuxdev@gmail.com>
@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Rebased. Now just checking the disable_ioctl calls for metadata nodes.

@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Were you expecting to lose "media: bcm2835-unicam: Retain packing information on G_FMT" and "media: bcm2835-unicam: change minimum number of vb2_queue buffers to 1" around the time of the rebase?

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Were you expecting to lose "media: bcm2835-unicam: Retain packing information on G_FMT" and "media: bcm2835-unicam: change minimum number of vb2_queue buffers to 1" around the time of the rebase?

No :-(
Time to retrieve them.

@6by9
6by9 force-pushed the rpi-5.4.y-unicam branch from c1af659 to bcbc72f Compare June 26, 2020 14:59
@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

OK, retrieved the two missing commits, and added one to use memset instead of ={0}.
Apologies if I've introduced a build error here - my laptop is creaking in the heat, and probably wants a reboot too.

@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Did you not want to use = {}; (note the lack of a 0), since it is the most common way to initialise a structure to zero in the kernel?
Otherwise this looks good, and there are no build errors (or new warnings).

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Up to you over = {}; vs memset. This is a downstream only patch so makes little difference in the grand scheme of things.

Give me a chance to check up on those disable_ioctl calls as it'd be nice to merge all changes in this one PR.

Anything else from @naushir?

@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

I'd prefer = {}; because it's one fewer line to read and one fewer line to contain mistakes.

I'll wait for the nod re: merging.

@6by9
6by9 force-pushed the rpi-5.4.y-unicam branch from bcbc72f to e736a0e Compare June 26, 2020 16:33
6by9 and others added 5 commits June 26, 2020 17:37
Updates the driver based on the upstream review comments from
Hans Verkuil at https://patchwork.linuxtv.org/patch/63531/

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
The change to retrieve the pixel format always on g_fmt didn't
check whether the native or unpacked version of the format
had been requested, and always returned the packed one.
Correct this so that the packing setting is retained whereever
possible.

Fixes "9d59e89 media: bcm2835-unicam: Re-fetch mbus code from subdev
on a g_fmt call"

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Since the unicam driver was modified to write to a dummy buffer when no
user-supplied buffer is available, it can now write to and return a
buffer even when there's only a single one. Enable this by changing the
min_buffers_needed in the vb2_queue; it will be useful for enabling
still captures without allocating more memory than absolutely necessary.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
The upstreamed Unicam driver uses a dt property to denote how many
lanes are supported by the receiver peripheral, independent of
the number of lanes that the sensor wants to use. It also doesn't
check the remote endpoint config for the number of lanes as that
isn't the accepted way of doing things.

Update the base DT for the brcm,num-data-lanes property, and the
overlays to define the desired number of lanes at both ends of
the link.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Older gcc versions object to = { 0 } initialisation if the first
elemtn in the structure is a substructure.

Use = { } to avoid this compiler warning.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
@6by9
6by9 force-pushed the rpi-5.4.y-unicam branch from e736a0e to 1aac77d Compare June 26, 2020 16:38
@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Updated with = { };

We do need the disable_ioctl calls as both video and metadata nodes are type VFL_TYPE_[VIDEO|GRABBER] (it got renamed), and the core disabling of ioctls is based on that type. We want to disable them based on whether the source subdev supports the relevant subdev API call or not, so our struct of ops always contains the superset of all of them.

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

I'm all happy now.

@pelwell
pelwell merged commit d433143 into raspberrypi:rpi-5.4.y Jun 26, 2020
@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Just in time for the weekend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants