From: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
To: Wenmeng Liu <quic_wenmliu@quicinc.com>,
Robert Foss <rfoss@kernel.org>, Todor Tomov <todor.too@gmail.com>,
Mauro Carvalho Chehab <mchehab@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org,
linux-arm-msm@vger.kernel.org
Subject: Re: [PATCH v2 2/3] media: qcom: camss: Add link support for TPG common
Date: Thu, 17 Jul 2025 13:56:47 +0100 [thread overview]
Message-ID: <3f838ee3-af25-4cf5-afcb-823ba68f0f43@linaro.org> (raw)
In-Reply-To: <20250717-lemans_tpg-v2-2-a2538659349c@quicinc.com>
On 17/07/2025 04:20, Wenmeng Liu wrote:
> TPG is connected to the csid as an entity, the link
> needs to be adapted.
>
> Signed-off-by: Wenmeng Liu <quic_wenmliu@quicinc.com>
> ---
> drivers/media/platform/qcom/camss/camss-csid.c | 44 +++++++++++++++++-----
> drivers/media/platform/qcom/camss/camss.c | 52 ++++++++++++++++++++++++++
> 2 files changed, 87 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/media/platform/qcom/camss/camss-csid.c b/drivers/media/platform/qcom/camss/camss-csid.c
> index 5284b5857368c37c202cd89dad6ae8042b637537..1ee4c4cc61cb32ce731dd8123522cc729d1ae3bb 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid.c
> +++ b/drivers/media/platform/qcom/camss/camss-csid.c
> @@ -1226,6 +1226,23 @@ void msm_csid_get_csid_id(struct media_entity *entity, u8 *id)
> *id = csid->id;
> }
>
> +/*
> + * csid_get_csiphy_tpg_lane_assign - Calculate lane assign by tpg lane num
> + * @num - tpg lane num
> + *
> + * Return lane assign
> + */
> +static u32 csid_get_csiphy_tpg_lane_assign(int num)
> +{
> + u32 lane_assign = 0;
> + int i;
> +
> + for (i = (num - 1); i >= 0; i--)
> + lane_assign |= i << (i * 4);
> +
> + return lane_assign;
> +}
Are you actually supporting different # of lanes feeding into the CSID ?
If so you need to show how, if not drop dead code.
> +
> /*
> * csid_get_lane_assign - Calculate CSI2 lane assign configuration parameter
> * @lane_cfg - CSI2 lane configuration
> @@ -1266,6 +1283,7 @@ static int csid_link_setup(struct media_entity *entity,
> struct csid_device *csid;
> struct csiphy_device *csiphy;
> struct csiphy_lanes_cfg *lane_cfg;
> + struct tpg_device *tpg;
>
> sd = media_entity_to_v4l2_subdev(entity);
> csid = v4l2_get_subdevdata(sd);
> @@ -1277,18 +1295,26 @@ static int csid_link_setup(struct media_entity *entity,
> return -EBUSY;
>
> sd = media_entity_to_v4l2_subdev(remote->entity);
> - csiphy = v4l2_get_subdevdata(sd);
> + if (strnstr(sd->name, MSM_TPG_NAME, strlen(MSM_TPG_NAME))) {
> + tpg = v4l2_get_subdevdata(sd);
If you need a flag add an "is_tpg" or otherwise encode a property into
the csiphy device.
I can imagine needing to differentiate between CSIPHY and TPG numerous
times and we shouldn't be doing string comparisons for that.
>
> - /* If a sensor is not linked to CSIPHY */
> - /* do no allow a link from CSIPHY to CSID */
> - if (!csiphy->cfg.csi2)
> - return -EPERM;
> + csid->phy.lane_cnt = tpg->res->lane_cnt;
The lane counts are fixed in the config so surely the assign_lane is
redundant - you could literally call the same function in the CSIPHY.
So bigger question since alot of this code is copy/paste from CSIPHY -
why are we not reusing the code in camss-csiphy.c - either by extending
that file - i.e. adding TPG inside of that file or by exporting
functions from that file into camss-tpg.c ?
Either way I'd like to reduce code duplication.
> + csid->phy.csiphy_id = tpg->id;
> + csid->phy.lane_assign = csid_get_csiphy_tpg_lane_assign(csid->phy.lane_cnt);
> + } else {
> + csiphy = v4l2_get_subdevdata(sd);
> +
> + /* If a sensor is not linked to CSIPHY */
> + /* do no allow a link from CSIPHY to CSID */
> + if (!csiphy->cfg.csi2)
> + return -EPERM;
>
> - csid->phy.csiphy_id = csiphy->id;
> + csid->phy.csiphy_id = csiphy->id;
>
> - lane_cfg = &csiphy->cfg.csi2->lane_cfg;
> - csid->phy.lane_cnt = lane_cfg->num_data;
> - csid->phy.lane_assign = csid_get_lane_assign(lane_cfg);
> + lane_cfg = &csiphy->cfg.csi2->lane_cfg;
> + csid->phy.lane_cnt = lane_cfg->num_data;
> + csid->phy.lane_assign = csid_get_lane_assign(lane_cfg);
> + }
> }
> /* Decide which virtual channels to enable based on which source pads are enabled */
> if (local->flags & MEDIA_PAD_FL_SOURCE) {
> diff --git a/drivers/media/platform/qcom/camss/camss.c b/drivers/media/platform/qcom/camss/camss.c
> index af5c9326736f9c8576816c91b73ad3e1d3a49dbf..34f71039038e881ced9c9f06bd70915b5c5f610f 100644
> --- a/drivers/media/platform/qcom/camss/camss.c
> +++ b/drivers/media/platform/qcom/camss/camss.c
> @@ -3913,6 +3913,19 @@ static int camss_init_subdevices(struct camss *camss)
> }
> }
>
> + if (camss->tpg) {
> + for (i = 0; i < camss->res->tpg_num; i++) {
> + ret = msm_tpg_subdev_init(camss, &camss->tpg[i],
> + &res->tpg_res[i], i);
> + if (ret < 0) {
> + dev_err(camss->dev,
> + "Failed to init tpg%d sub-device: %d\n",
> + i, ret);
> + return ret;
> + }
> + }
> + }
OK so what I'd like is the thinking on why TPG is its own camss-tpg.c
and its own device, instead of a property of the CSIPHY.
I can lay out some of the arguments for/against that spring to mind.
Separate for:
Cleaner code ?
Less logical change ?
Fewer clocks/ISR stuff to handle ?
Separate against:
Code duplication
Data structure duplication
I'd like you to explain your reasoning for the design choice, either in
the cover letter or inline as a response.
BTW its not criticism, I'm trying to get clear in my head your thinking
and also to prompt you to think about doing it the other way and to
justify the design choice to yourself and others or to change to a
different design choice, if that makes sense.
Part of me says "yes TPG should be its own device" another part of me
says "but it is so similar to CSIPHY" - either way I'd like to reduce
code duplication to something approaching nil.
---
bod
next prev parent reply other threads:[~2025-07-17 12:56 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-17 3:20 [PATCH v2 0/3] media: qcom: camss: Add sa8775p camss TPG support Wenmeng Liu
2025-07-17 3:20 ` [PATCH v2 1/3] media: qcom: camss: Add support for TPG common Wenmeng Liu
2025-07-17 12:42 ` Bryan O'Donoghue
2025-08-15 8:52 ` Wenmeng Liu
2025-08-15 12:12 ` Bryan O'Donoghue
2025-07-17 12:43 ` Konrad Dybcio
2025-07-17 3:20 ` [PATCH v2 2/3] media: qcom: camss: Add link " Wenmeng Liu
2025-07-17 12:52 ` Konrad Dybcio
2025-07-17 12:56 ` Bryan O'Donoghue [this message]
2025-07-17 3:20 ` [PATCH v2 3/3] media: qcom: camss: tpg: Add TPG support for SA8775P Wenmeng Liu
2025-07-17 12:54 ` Konrad Dybcio
2025-07-17 12:59 ` Bryan O'Donoghue
2025-07-17 12:34 ` [PATCH v2 0/3] media: qcom: camss: Add sa8775p camss TPG support Konrad Dybcio
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=3f838ee3-af25-4cf5-afcb-823ba68f0f43@linaro.org \
--to=bryan.odonoghue@linaro.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@kernel.org \
--cc=quic_wenmliu@quicinc.com \
--cc=rfoss@kernel.org \
--cc=todor.too@gmail.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®