diff mbox series

[v3,15/15] media: qcom: camss: Comment CSID dt_id field

Message ID 20230823104444.1954663-16-bryan.odonoghue@linaro.org
State Superseded
Headers show
Series [v3,01/15] media: qcom: camss: Amalgamate struct resource with struct resource_ispif | expand

Commit Message

Bryan O'Donoghue Aug. 23, 2023, 10:44 a.m. UTC
Digging into the documentation we find that the DT_ID bitfield is used to
map the six bit DT to a two bit ID code. This value is concatenated to the
VC bitfield to create a CID value. DT_ID is the two least significant bits
of CID and VC the most significant bits.

Originally we set dt_id = vc * 4 in and then subsequently set dt_id = vc.

commit 3c4ed72a16bc ("media: camss: sm8250: Virtual channels for CSID")
silently fixed the multiplication by four which would give a better
value for the generated CID without mentioning what was being done or why.

Next up I haplessly changed the value back to "dt_id = vc * 4" since there
didn't appear to be any logic behind it.

Hans asked what the change was for and I honestly couldn't remember the
provenance of it, so I dug in.

Link: https://lore.kernel.org/linux-arm-msm/edd4bf9b-0e1b-883c-1a4d-50f4102c3924@xs4all.nl/

Add a comment so the next hapless programmer doesn't make this same
mistake.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 drivers/media/platform/qcom/camss/camss-csid-gen2.c | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Konrad Dybcio Aug. 26, 2023, 10:18 a.m. UTC | #1
On 23.08.2023 12:44, Bryan O'Donoghue wrote:
> Digging into the documentation we find that the DT_ID bitfield is used to
> map the six bit DT to a two bit ID code. This value is concatenated to the
> VC bitfield to create a CID value. DT_ID is the two least significant bits
> of CID and VC the most significant bits.
> 
> Originally we set dt_id = vc * 4 in and then subsequently set dt_id = vc.
> 
> commit 3c4ed72a16bc ("media: camss: sm8250: Virtual channels for CSID")
> silently fixed the multiplication by four which would give a better
> value for the generated CID without mentioning what was being done or why.
> 
> Next up I haplessly changed the value back to "dt_id = vc * 4" since there
> didn't appear to be any logic behind it.
> 
> Hans asked what the change was for and I honestly couldn't remember the
> provenance of it, so I dug in.
> 
> Link: https://lore.kernel.org/linux-arm-msm/edd4bf9b-0e1b-883c-1a4d-50f4102c3924@xs4all.nl/
> 
> Add a comment so the next hapless programmer doesn't make this same
> mistake.
> 
> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>  drivers/media/platform/qcom/camss/camss-csid-gen2.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen2.c b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
> index 6ba2b10326444..cee50fc87e9de 100644
> --- a/drivers/media/platform/qcom/camss/camss-csid-gen2.c
> +++ b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
> @@ -352,6 +352,11 @@ static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 vc)
>  		phy_sel = csid->phy.csiphy_id;
>  
>  	if (enable) {
> +		/*
> +		 * A value caled 'CID' gets generated internal to CAMSS logic
> +		 * which is a concatenation of [vc:6 | dt_id:2] hence we reuse
> +		 * the least significant two bits of the VC to 'stuff' the CID value.
> +		 */
>  		u8 dt_id = vc;
And where are you discarding the non-2-lsb?

Konrad
Bryan O'Donoghue Aug. 28, 2023, 3:34 p.m. UTC | #2
On 26/08/2023 11:18, Konrad Dybcio wrote:
>> +		/*
>> +		 * A value caled 'CID' gets generated internal to CAMSS logic
>> +		 * which is a concatenation of [vc:6 | dt_id:2] hence we reuse
>> +		 * the least significant two bits of the VC to 'stuff' the CID value.
>> +		 */
>>   		u8 dt_id = vc;
> And where are you discarding the non-2-lsb?

At the assignment of dt_id

vc:6
dt_id:2

=>

cid:8 = [vc:6 | dt_id:2]
vc == 00110110
cid = [110110 | 10]

I have no more information what CID is or how the bitfield is populated 
than I have already indicated in the comment/commit log.

---
bod
Konrad Dybcio Aug. 28, 2023, 3:38 p.m. UTC | #3
On 28.08.2023 17:34, Bryan O'Donoghue wrote:
> On 26/08/2023 11:18, Konrad Dybcio wrote:
>>> +        /*
>>> +         * A value caled 'CID' gets generated internal to CAMSS logic
>>> +         * which is a concatenation of [vc:6 | dt_id:2] hence we reuse
>>> +         * the least significant two bits of the VC to 'stuff' the CID value.
>>> +         */
>>>           u8 dt_id = vc;
>> And where are you discarding the non-2-lsb?
> 
> At the assignment of dt_id
> 
> vc:6
> dt_id:2
> 
> =>
> 
> cid:8 = [vc:6 | dt_id:2]
> vc == 00110110
> cid = [110110 | 10]
> 
> I have no more information what CID is or how the bitfield is populated than I have already indicated in the comment/commit log.
> 
OK so you're discarding the 2 lsb of the [vc:6|dt_id:2]

however

the way I read the comment would suggest that you're taking
vc[6:2]

Konrad
Bryan O'Donoghue Aug. 28, 2023, 3:43 p.m. UTC | #4
On 28/08/2023 16:38, Konrad Dybcio wrote:
> On 28.08.2023 17:34, Bryan O'Donoghue wrote:
>> On 26/08/2023 11:18, Konrad Dybcio wrote:
>>>> +        /*
>>>> +         * A value caled 'CID' gets generated internal to CAMSS logic
>>>> +         * which is a concatenation of [vc:6 | dt_id:2] hence we reuse
>>>> +         * the least significant two bits of the VC to 'stuff' the CID value.
>>>> +         */
>>>>            u8 dt_id = vc;
>>> And where are you discarding the non-2-lsb?
>>
>> At the assignment of dt_id
>>
>> vc:6
>> dt_id:2
>>
>> =>
>>
>> cid:8 = [vc:6 | dt_id:2]
>> vc == 00110110
>> cid = [110110 | 10]
>>
>> I have no more information what CID is or how the bitfield is populated than I have already indicated in the comment/commit log.
>>
> OK so you're discarding the 2 lsb of the [vc:6|dt_id:2]
> 
> however
> 
> the way I read the comment would suggest that you're taking
> vc[6:2]
> 
> Konrad

Fair enough, obvs the comment needs work so.

---
bod
diff mbox series

Patch

diff --git a/drivers/media/platform/qcom/camss/camss-csid-gen2.c b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
index 6ba2b10326444..cee50fc87e9de 100644
--- a/drivers/media/platform/qcom/camss/camss-csid-gen2.c
+++ b/drivers/media/platform/qcom/camss/camss-csid-gen2.c
@@ -352,6 +352,11 @@  static void __csid_configure_stream(struct csid_device *csid, u8 enable, u8 vc)
 		phy_sel = csid->phy.csiphy_id;
 
 	if (enable) {
+		/*
+		 * A value caled 'CID' gets generated internal to CAMSS logic
+		 * which is a concatenation of [vc:6 | dt_id:2] hence we reuse
+		 * the least significant two bits of the VC to 'stuff' the CID value.
+		 */
 		u8 dt_id = vc;
 
 		if (tg->enabled) {