All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hans Verkuil <hverkuil@xs4all.nl>
To: Todor Tomov <todor.tomov@linaro.org>,
	mchehab@kernel.org, hans.verkuil@cisco.com,
	javier@osg.samsung.com, s.nawrocki@samsung.com,
	sakari.ailus@iki.fi, linux-media@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v3 12/23] media: camms: Add core files
Date: Wed, 19 Jul 2017 12:44:17 +0200	[thread overview]
Message-ID: <4b06c0d5-ef9c-e5af-7db2-735bebd227e8@xs4all.nl> (raw)
In-Reply-To: <1500287629-23703-13-git-send-email-todor.tomov@linaro.org>

Hi Todor,

Just one comment:

On 17/07/17 12:33, Todor Tomov wrote:
> These files implement the platform driver code.
> 
> Signed-off-by: Todor Tomov <todor.tomov@linaro.org>
> ---
>  drivers/media/platform/qcom/camss-8x16/camss.c | 705 +++++++++++++++++++++++++
>  drivers/media/platform/qcom/camss-8x16/camss.h |  97 ++++
>  2 files changed, 802 insertions(+)
>  create mode 100644 drivers/media/platform/qcom/camss-8x16/camss.c
>  create mode 100644 drivers/media/platform/qcom/camss-8x16/camss.h
> 
> diff --git a/drivers/media/platform/qcom/camss-8x16/camss.c b/drivers/media/platform/qcom/camss-8x16/camss.c
> new file mode 100644
> index 0000000..097d4ec
> --- /dev/null
> +++ b/drivers/media/platform/qcom/camss-8x16/camss.c
> @@ -0,0 +1,705 @@
> +/*
> + * camss.c
> + *
> + * Qualcomm MSM Camera Subsystem - Core
> + *
> + * Copyright (c) 2015, The Linux Foundation. All rights reserved.
> + * Copyright (C) 2015-2017 Linaro Ltd.
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 and
> + * only version 2 as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +#include <linux/clk.h>
> +#include <linux/media-bus-format.h>
> +#include <linux/media.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/of.h>
> +#include <linux/of_graph.h>
> +#include <linux/slab.h>
> +#include <linux/videodev2.h>
> +
> +#include <media/media-device.h>
> +#include <media/v4l2-async.h>
> +#include <media/v4l2-device.h>
> +#include <media/v4l2-mc.h>
> +#include <media/v4l2-fwnode.h>
> +
> +#include "camss.h"
> +
> +static const struct resources csiphy_res[] = {
> +	/* CSIPHY0 */
> +	{
> +		.regulator = { NULL },
> +		.clock = { "camss_top_ahb", "ispif_ahb",
> +			   "camss_ahb", "csiphy0_timer" },
> +		.clock_rate = { 0, 0, 0, 200000000 },
> +		.reg = { "csiphy0", "csiphy0_clk_mux" },
> +		.interrupt = { "csiphy0" }
> +	},
> +
> +	/* CSIPHY1 */
> +	{
> +		.regulator = { NULL },
> +		.clock = { "camss_top_ahb", "ispif_ahb",
> +			   "camss_ahb", "csiphy1_timer" },
> +		.clock_rate = { 0, 0, 0, 200000000 },
> +		.reg = { "csiphy1", "csiphy1_clk_mux" },
> +		.interrupt = { "csiphy1" }
> +	}
> +};
> +
> +static const struct resources csid_res[] = {
> +	/* CSID0 */
> +	{
> +		.regulator = { "vdda" },
> +		.clock = { "camss_top_ahb", "ispif_ahb",
> +			   "csi0_ahb", "camss_ahb",
> +			   "csi0", "csi0_phy", "csi0_pix", "csi0_rdi" },
> +		.clock_rate = { 0, 0, 0, 0, 200000000, 0, 0, 0 },
> +		.reg = { "csid0" },
> +		.interrupt = { "csid0" }
> +	},
> +
> +	/* CSID1 */
> +	{
> +		.regulator = { "vdda" },
> +		.clock = { "camss_top_ahb", "ispif_ahb",
> +			   "csi1_ahb", "camss_ahb",
> +			   "csi1", "csi1_phy", "csi1_pix", "csi1_rdi" },
> +		.clock_rate = { 0, 0, 0, 0, 200000000, 0, 0, 0 },
> +		.reg = { "csid1" },
> +		.interrupt = { "csid1" }
> +	},
> +};
> +
> +static const struct resources_ispif ispif_res = {
> +	/* ISPIF */
> +	.clock = { "camss_top_ahb", "camss_ahb", "ispif_ahb",
> +		   "csi0", "csi0_pix", "csi0_rdi",
> +		   "csi1", "csi1_pix", "csi1_rdi" },
> +	.clock_for_reset = { "camss_vfe_vfe", "camss_csi_vfe" },
> +	.reg = { "ispif", "csi_clk_mux" },
> +	.interrupt = "ispif"
> +
> +};
> +
> +static const struct resources vfe_res = {
> +	/* VFE0 */
> +	.regulator = { NULL },
> +	.clock = { "camss_top_ahb", "camss_vfe_vfe", "camss_csi_vfe",
> +		   "iface", "bus", "camss_ahb" },
> +	.clock_rate = { 0, 320000000, 0, 0, 0, 0, 0, 0 },
> +	.reg = { "vfe0" },
> +	.interrupt = { "vfe0" }
> +};
> +
> +/*
> + * camss_enable_clocks - Enable multiple clocks
> + * @nclocks: Number of clocks in clock array
> + * @clock: Clock array
> + * @dev: Device
> + *
> + * Return 0 on success or a negative error code otherwise
> + */
> +int camss_enable_clocks(int nclocks, struct clk **clock, struct device *dev)
> +{
> +	int ret;
> +	int i;
> +
> +	for (i = 0; i < nclocks; i++) {
> +		ret = clk_prepare_enable(clock[i]);
> +		if (ret) {
> +			dev_err(dev, "clock enable failed: %d\n", ret);
> +			goto error;
> +		}
> +	}
> +
> +	return 0;
> +
> +error:
> +	for (i--; i >= 0; i--)
> +		clk_disable_unprepare(clock[i]);
> +
> +	return ret;
> +}
> +
> +/*
> + * camss_disable_clocks - Disable multiple clocks
> + * @nclocks: Number of clocks in clock array
> + * @clock: Clock array
> + */
> +void camss_disable_clocks(int nclocks, struct clk **clock)
> +{
> +	int i;
> +
> +	for (i = nclocks - 1; i >= 0; i--)
> +		clk_disable_unprepare(clock[i]);
> +}
> +
> +/*
> + * camss_find_sensor - Find a linked media entity which represents a sensor
> + * @entity: Media entity to start searching from
> + *
> + * Return a pointer to sensor media entity or NULL if not found
> + */
> +static struct media_entity *camss_find_sensor(struct media_entity *entity)
> +{
> +	struct media_pad *pad;
> +
> +	while (1) {
> +		pad = &entity->pads[0];
> +		if (!(pad->flags & MEDIA_PAD_FL_SINK))
> +			return NULL;
> +
> +		pad = media_entity_remote_pad(pad);
> +		if (!pad || !is_media_entity_v4l2_subdev(pad->entity))
> +			return NULL;
> +
> +		entity = pad->entity;
> +
> +		if (entity->function == MEDIA_ENT_F_CAM_SENSOR)
> +			return entity;
> +	}
> +}
> +
> +/*
> + * camss_get_pixel_clock - Get pixel clock rate from sensor
> + * @entity: Media entity in the current pipeline
> + * @pixel_clock: Received pixel clock value
> + *
> + * Return 0 on success or a negative error code otherwise
> + */
> +int camss_get_pixel_clock(struct media_entity *entity, u32 *pixel_clock)
> +{
> +	struct media_entity *sensor;
> +	struct v4l2_subdev *subdev;
> +	struct v4l2_ext_controls ctrls = { { 0 } };
> +	struct v4l2_ext_control ctrl = { 0 };
> +	int ret;
> +
> +	sensor = camss_find_sensor(entity);
> +	if (!sensor)
> +		return -ENODEV;
> +
> +	subdev = media_entity_to_v4l2_subdev(sensor);
> +
> +	ctrl.id = V4L2_CID_PIXEL_RATE;
> +
> +	ctrls.count = 1;
> +	ctrls.controls = &ctrl;
> +
> +	ret = v4l2_g_ext_ctrls(subdev->ctrl_handler, &ctrls);

Don't use v4l2_g_ext_ctrls for this, it is not meant for use in drivers.
Instead do this:

	struct v4l2_ctrl *ctrl = v4l2_ctrl_find(subdev->ctrl_handler, V4L2_CID_PIXEL_RATE);

	if (ctrl == NULL)
		return -EINVAL;  // or some other error code

	*pixel_clock = v4l2_ctrl_g_ctrl_int64(ctrl);

> +	if (ret < 0)
> +		return ret;
> +
> +	*pixel_clock = ctrl.value64;
> +
> +	return 0;
> +}

Regards,

	Hans

  reply	other threads:[~2017-07-19 10:44 UTC|newest]

Thread overview: 60+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-17 10:33 [PATCH v3 00/23] Qualcomm 8x16 Camera Subsystem driver Todor Tomov
2017-07-17 10:33 ` [PATCH v3 01/23] [media] media: Make parameter of media_entity_remote_pad() const Todor Tomov
2017-07-17 10:33 ` [PATCH v3 02/23] [media] v4l2-mediabus: Add helper functions Todor Tomov
2017-07-17 10:33 ` [PATCH v3 03/23] v4l: Add packed Bayer raw12 pixel formats Todor Tomov
2017-07-17 10:33 ` [PATCH v3 04/23] dt-bindings: media: Binding document for Qualcomm Camera subsystem driver Todor Tomov
2017-07-20 10:13   ` Sakari Ailus
     [not found]     ` <20170720101345.eovx5ovuxr7sqpea-S+BSfZ9RZZmRSg0ZkenSGLdO1Tsj/99ntUK59QYPAWc@public.gmane.org>
2017-08-04 11:54       ` Todor Tomov
2017-08-04 11:54         ` Todor Tomov
     [not found]         ` <1dc5ab4d-5171-c6df-4300-2abcd0e5483b-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org>
2017-08-05  8:19           ` Sakari Ailus
2017-08-05  8:19             ` Sakari Ailus
2017-07-20 10:15   ` Sakari Ailus
2017-07-24 16:43   ` Rob Herring
2017-07-17 10:33 ` [PATCH v3 05/23] MAINTAINERS: Add " Todor Tomov
2017-07-17 10:33 ` [PATCH v3 06/23] doc: media/v4l-drivers: Add Qualcomm Camera Subsystem driver document Todor Tomov
2017-07-17 10:33 ` [PATCH v3 07/23] media: camss: Add CSIPHY files Todor Tomov
2017-07-20 12:15   ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 08/23] media: camss: Add CSID files Todor Tomov
2017-07-20 14:13   ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 09/23] media: camss: Add ISPIF files Todor Tomov
2017-07-20 14:51   ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 10/23] media: camss: Add VFE files Todor Tomov
2017-07-20 14:59   ` Sakari Ailus
2017-07-25 14:02     ` Todor Tomov
2017-08-04 18:02       ` Sakari Ailus
2017-08-07  6:49         ` Todor Tomov
2017-07-17 10:33 ` [PATCH v3 11/23] media: camss: Add files which handle the video device nodes Todor Tomov
2017-07-17 10:33 ` [PATCH v3 12/23] media: camms: Add core files Todor Tomov
2017-07-19 10:44   ` Hans Verkuil [this message]
2017-07-17 10:33 ` [PATCH v3 13/23] media: camss: Enable building Todor Tomov
2017-07-19 13:17   ` kbuild test robot
2017-07-19 13:17     ` kbuild test robot
2017-07-17 10:33 ` [PATCH v3 14/23] camss: vfe: Format conversion support using PIX interface Todor Tomov
2017-07-20 15:11   ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 15/23] doc: media/v4l-drivers: Qualcomm Camera Subsystem - PIX Interface Todor Tomov
2017-07-20 15:13   ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 16/23] camss: vfe: Support for frame padding Todor Tomov
2017-07-20 15:17   ` Sakari Ailus
2018-09-03 15:38     ` Todor Tomov
2018-09-13 15:04       ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 17/23] camss: vfe: Add interface for scaling Todor Tomov
2017-07-20 15:20   ` Sakari Ailus
2017-07-25 15:36     ` Todor Tomov
2017-08-04 17:59       ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 18/23] camss: vfe: Configure scaler module in VFE Todor Tomov
2017-07-17 10:33 ` [PATCH v3 19/23] camss: vfe: Add interface for cropping Todor Tomov
2017-07-17 10:33 ` [PATCH v3 20/23] camss: vfe: Configure crop module in VFE Todor Tomov
2017-07-17 10:33 ` [PATCH v3 21/23] doc: media/v4l-drivers: Qualcomm Camera Subsystem - Scale and crop Todor Tomov
2017-07-17 10:33 ` [PATCH v3 22/23] camss: Use optimal clock frequency rates Todor Tomov
2017-07-19 15:59   ` kbuild test robot
2017-07-19 15:59     ` kbuild test robot
2017-07-21  7:55     ` Todor Tomov
2017-07-21  7:55       ` Todor Tomov
2017-07-21  7:55       ` Todor Tomov
2017-07-20 15:23   ` Sakari Ailus
2017-07-17 10:33 ` [PATCH v3 23/23] doc: media/v4l-drivers: Qualcomm Camera Subsystem - Media graph Todor Tomov
2017-07-19 10:54 ` [PATCH v3 00/23] Qualcomm 8x16 Camera Subsystem driver Hans Verkuil
2017-07-21  7:39   ` Todor Tomov
2017-07-31  9:20   ` Hans Verkuil
2017-07-20 15:25 ` Sakari Ailus
2017-07-21  7:50   ` Todor Tomov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4b06c0d5-ef9c-e5af-7db2-735bebd227e8@xs4all.nl \
    --to=hverkuil@xs4all.nl \
    --cc=hans.verkuil@cisco.com \
    --cc=javier@osg.samsung.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=s.nawrocki@samsung.com \
    --cc=sakari.ailus@iki.fi \
    --cc=todor.tomov@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.