Skip to contentSkip to conversation

Staging: media: omap4iss: Use BIT() macro

PATCH In review Sam Muhammed 3 participants 9 messages Mar 31, 2020 – Apr 5, 2020

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 Staging: media: omap4iss: Use BIT() macro

Use BIT() across the driver, since bit masking
is better be done using the BIT macro.
Change is done using this coccinelle script:

@bit@
@@
BIT(...)

@depends on bit@
expression E;
constant c;
@@

(
-(1 << E)
+BIT(E)
|
-(1 << c)
+BIT(c)
)

---
Change in v2:
- removed unneeded parentheses around BIT,
they are not needed.
- reverted two hunks in iss_reg.h, using BIT
in both places makes the code confusing to
understand.
Changes suggested by Stefano Brivio.

 drivers/staging/media/omap4iss/iss.c        |  4 +-
 drivers/staging/media/omap4iss/iss.h        | 22 +++----
 drivers/staging/media/omap4iss/iss_csiphy.c |  6 +-
 drivers/staging/media/omap4iss/iss_regs.h   | 72 ++++++++++-----------
 drivers/staging/media/omap4iss/iss_video.h  | 16 ++---
 5 files changed, 60 insertions(+), 60 deletions(-)
drivers/staging/media/omap4iss/iss.c +2 -2
index 6fb60b58447a..2dc5c1bb34f9 100644
@@ -243,7 +243,7 @@ static void iss_isr_dbg(struct iss_device *iss, u32 irqstatus)
 	dev_dbg(iss->dev, "ISS IRQ: ");
 
 	for (i = 0; i < ARRAY_SIZE(name); i++) {
-		if ((1 << i) & irqstatus)
+		if (BIT(i) & irqstatus)
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");
@@ -290,7 +290,7 @@ static void iss_isp_isr_dbg(struct iss_device *iss, u32 irqstatus)
 	dev_dbg(iss->dev, "ISP IRQ: ");
 
 	for (i = 0; i < ARRAY_SIZE(name); i++) {
-		if ((1 << i) & irqstatus)
+		if (BIT(i) & irqstatus)
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");
drivers/staging/media/omap4iss/iss.h +11 -11
index b88f9529683c..70371461b5be 100644
@@ -50,20 +50,20 @@ enum iss_mem_resources {
 };
 
 enum iss_subclk_resource {
-	OMAP4_ISS_SUBCLK_SIMCOP		= (1 << 0),
-	OMAP4_ISS_SUBCLK_ISP		= (1 << 1),
-	OMAP4_ISS_SUBCLK_CSI2_A		= (1 << 2),
-	OMAP4_ISS_SUBCLK_CSI2_B		= (1 << 3),
-	OMAP4_ISS_SUBCLK_CCP2		= (1 << 4),
+	OMAP4_ISS_SUBCLK_SIMCOP		= BIT(0),
+	OMAP4_ISS_SUBCLK_ISP		= BIT(1),
+	OMAP4_ISS_SUBCLK_CSI2_A		= BIT(2),
+	OMAP4_ISS_SUBCLK_CSI2_B		= BIT(3),
+	OMAP4_ISS_SUBCLK_CCP2		= BIT(4),
 };
 
 enum iss_isp_subclk_resource {
-	OMAP4_ISS_ISP_SUBCLK_BL		= (1 << 0),
-	OMAP4_ISS_ISP_SUBCLK_ISIF	= (1 << 1),
-	OMAP4_ISS_ISP_SUBCLK_H3A	= (1 << 2),
-	OMAP4_ISS_ISP_SUBCLK_RSZ	= (1 << 3),
-	OMAP4_ISS_ISP_SUBCLK_IPIPE	= (1 << 4),
-	OMAP4_ISS_ISP_SUBCLK_IPIPEIF	= (1 << 5),
+	OMAP4_ISS_ISP_SUBCLK_BL		= BIT(0),
+	OMAP4_ISS_ISP_SUBCLK_ISIF	= BIT(1),
+	OMAP4_ISS_ISP_SUBCLK_H3A	= BIT(2),
+	OMAP4_ISS_ISP_SUBCLK_RSZ	= BIT(3),
+	OMAP4_ISS_ISP_SUBCLK_IPIPE	= BIT(4),
+	OMAP4_ISS_ISP_SUBCLK_IPIPEIF	= BIT(5),
 };
 
 /*
drivers/staging/media/omap4iss/iss_csiphy.c +3 -3
index 96f2ce045138..e2cad0a31098 100644
@@ -179,10 +179,10 @@ int omap4iss_csiphy_config(struct iss_device *iss,
 		    lanes->data[i].pos > (csi2->phy->max_data_lanes + 1))
 			return -EINVAL;
 
-		if (used_lanes & (1 << lanes->data[i].pos))
+		if (used_lanes & BIT(lanes->data[i].pos))
 			return -EINVAL;
 
-		used_lanes |= 1 << lanes->data[i].pos;
+		used_lanes |= BIT(lanes->data[i].pos);
 		csi2->phy->used_data_lanes++;
 	}
 
@@ -190,7 +190,7 @@ int omap4iss_csiphy_config(struct iss_device *iss,
 	    lanes->clk.pos > (csi2->phy->max_data_lanes + 1))
 		return -EINVAL;
 
-	if (lanes->clk.pos == 0 || used_lanes & (1 << lanes->clk.pos))
+	if (lanes->clk.pos == 0 || used_lanes & BIT(lanes->clk.pos))
 		return -EINVAL;
 
 	csi2_ddrclk_khz = pipe->external_rate / 1000
drivers/staging/media/omap4iss/iss_regs.h +36 -36

160 lines not on this page · raw message

drivers/staging/media/omap4iss/iss_video.h +8 -8
index 8b3dd92021e1..230a73d2cbdc 100644
@@ -56,17 +56,17 @@ enum iss_pipeline_state {
 	/* The stream has been started on the input video node. */
 	ISS_PIPELINE_STREAM_INPUT = 1,
 	/* The stream has been started on the output video node. */
-	ISS_PIPELINE_STREAM_OUTPUT = (1 << 1),
+	ISS_PIPELINE_STREAM_OUTPUT = BIT(1),
 	/* At least one buffer is queued on the input video node. */
-	ISS_PIPELINE_QUEUE_INPUT = (1 << 2),
+	ISS_PIPELINE_QUEUE_INPUT = BIT(2),
 	/* At least one buffer is queued on the output video node. */
-	ISS_PIPELINE_QUEUE_OUTPUT = (1 << 3),
+	ISS_PIPELINE_QUEUE_OUTPUT = BIT(3),
 	/* The input entity is idle, ready to be started. */
-	ISS_PIPELINE_IDLE_INPUT = (1 << 4),
+	ISS_PIPELINE_IDLE_INPUT = BIT(4),
 	/* The output entity is idle, ready to be started. */
-	ISS_PIPELINE_IDLE_OUTPUT = (1 << 5),
+	ISS_PIPELINE_IDLE_OUTPUT = BIT(5),
 	/* The pipeline is currently streaming. */
-	ISS_PIPELINE_STREAM = (1 << 6),
+	ISS_PIPELINE_STREAM = BIT(6),
 };
 
 /*
@@ -120,9 +120,9 @@ struct iss_buffer {
 
 enum iss_video_dmaqueue_flags {
 	/* Set if DMA queue becomes empty when ISS_PIPELINE_STREAM_CONTINUOUS */
-	ISS_VIDEO_DMAQUEUE_UNDERRUN = (1 << 0),
+	ISS_VIDEO_DMAQUEUE_UNDERRUN = BIT(0),
 	/* Set when queuing buffer to an empty DMA queue */
-	ISS_VIDEO_DMAQUEUE_QUEUED = (1 << 1),
+	ISS_VIDEO_DMAQUEUE_QUEUED = BIT(1),
 };
 
 #define iss_video_dmaqueue_flags_clr(video)	\

---
2.20.1

#1 lore raw
Quoted 43 lines · On Tue, 31 Mar 2020 18:58:17 -0400 Sam Muhammed <[email protected]> wrote:

Use BIT() across the driver, since bit masking
is better be done using the BIT macro.
Change is done using this coccinelle script:

@bit@
@@
BIT(...)

@depends on bit@
expression E;
constant c;
@@

(

(quoted diff) +1 -1
-(1 << E)
+BIT(E)

|

(quoted diff) +1 -1
-(1 << c)
+BIT(c)

)

---
Change in v2:
- removed unneeded parentheses around BIT,
they are not needed.
- reverted two hunks in iss_reg.h, using BIT
in both places makes the code confusing to
understand.
Changes suggested by Stefano Brivio.

 drivers/staging/media/omap4iss/iss.c        |  4 +-
 drivers/staging/media/omap4iss/iss.h        | 22 +++----
 drivers/staging/media/omap4iss/iss_csiphy.c |  6 +-
 drivers/staging/media/omap4iss/iss_regs.h   | 72 ++++++++++-----------
 drivers/staging/media/omap4iss/iss_video.h  | 16 ++---
 5 files changed, 60 insertions(+), 60 deletions(-)
drivers/staging/media/omap4iss/iss.c +0 -0
index 6fb60b58447a..2dc5c1bb34f9 100644

drivers/staging/media/omap4iss/iss.c static void iss_isr_dbg(struct iss_device *iss, u32 irqstatus) · line 249

Quoted 8 lines
drivers/staging/media/omap4iss/iss.c +1 -1
@@ -243,7 +243,7 @@ static void iss_isr_dbg(struct iss_device *iss, u32 irqstatus)
 	dev_dbg(iss->dev, "ISS IRQ: ");
 
 	for (i = 0; i < ARRAY_SIZE(name); i++) {
-		if ((1 << i) & irqstatus)
+		if (BIT(i) & irqstatus)
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");

Fine.

drivers/staging/media/omap4iss/iss.c static void iss_isp_isr_dbg(struct iss_device *iss, u32 irqstatus) · line 296

Quoted 9 lines
drivers/staging/media/omap4iss/iss.c +1 -1
@@ -290,7 +290,7 @@ static void iss_isp_isr_dbg(struct iss_device *iss, u32 irqstatus)
 	dev_dbg(iss->dev, "ISP IRQ: ");
 
 	for (i = 0; i < ARRAY_SIZE(name); i++) {
-		if ((1 << i) & irqstatus)
+		if (BIT(i) & irqstatus)
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");

Fine.

Quoted 26 lines
drivers/staging/media/omap4iss/iss.h +5 -10
index b88f9529683c..70371461b5be 100644
@@ -50,20 +50,20 @@ enum iss_mem_resources {
 };
 
 enum iss_subclk_resource {
-	OMAP4_ISS_SUBCLK_SIMCOP		= (1 << 0),
-	OMAP4_ISS_SUBCLK_ISP		= (1 << 1),
-	OMAP4_ISS_SUBCLK_CSI2_A		= (1 << 2),
-	OMAP4_ISS_SUBCLK_CSI2_B		= (1 << 3),
-	OMAP4_ISS_SUBCLK_CCP2		= (1 << 4),
+	OMAP4_ISS_SUBCLK_SIMCOP		= BIT(0),
+	OMAP4_ISS_SUBCLK_ISP		= BIT(1),
+	OMAP4_ISS_SUBCLK_CSI2_A		= BIT(2),
+	OMAP4_ISS_SUBCLK_CSI2_B		= BIT(3),
+	OMAP4_ISS_SUBCLK_CCP2		= BIT(4),
 };
 
 enum iss_isp_subclk_resource {
-	OMAP4_ISS_ISP_SUBCLK_BL		= (1 << 0),
-	OMAP4_ISS_ISP_SUBCLK_ISIF	= (1 << 1),
-	OMAP4_ISS_ISP_SUBCLK_H3A	= (1 << 2),
-	OMAP4_ISS_ISP_SUBCLK_RSZ	= (1 << 3),
-	OMAP4_ISS_ISP_SUBCLK_IPIPE	= (1 << 4),

drivers/staging/media/omap4iss/iss.h enum iss_mem_resources { · line 69

Quoted 10 lines
drivers/staging/media/omap4iss/iss.h +6 -1
-	OMAP4_ISS_ISP_SUBCLK_IPIPEIF	= (1 << 5),
+	OMAP4_ISS_ISP_SUBCLK_BL		= BIT(0),
+	OMAP4_ISS_ISP_SUBCLK_ISIF	= BIT(1),
+	OMAP4_ISS_ISP_SUBCLK_H3A	= BIT(2),
+	OMAP4_ISS_ISP_SUBCLK_RSZ	= BIT(3),
+	OMAP4_ISS_ISP_SUBCLK_IPIPE	= BIT(4),
+	OMAP4_ISS_ISP_SUBCLK_IPIPEIF	= BIT(5),
 };
 
 /*

Nice.

Quoted 18 lines
drivers/staging/media/omap4iss/iss_csiphy.c +2 -2
index 96f2ce045138..e2cad0a31098 100644
@@ -179,10 +179,10 @@ int omap4iss_csiphy_config(struct iss_device *iss,
 		    lanes->data[i].pos > (csi2->phy->max_data_lanes + 1))
 			return -EINVAL;
 
-		if (used_lanes & (1 << lanes->data[i].pos))
+		if (used_lanes & BIT(lanes->data[i].pos))
 			return -EINVAL;
 
-		used_lanes |= 1 << lanes->data[i].pos;
+		used_lanes |= BIT(lanes->data[i].pos);
 		csi2->phy->used_data_lanes++;
 	}
 

drivers/staging/media/omap4iss/iss_csiphy.c int omap4iss_csiphy_config(struct iss_device *iss, · line 196

Quoted 8 lines
drivers/staging/media/omap4iss/iss_csiphy.c +1 -1
@@ -190,7 +190,7 @@ int omap4iss_csiphy_config(struct iss_device *iss,
 	    lanes->clk.pos > (csi2->phy->max_data_lanes + 1))
 		return -EINVAL;
 
-	if (lanes->clk.pos == 0 || used_lanes & (1 << lanes->clk.pos))
+	if (lanes->clk.pos == 0 || used_lanes & BIT(lanes->clk.pos))
 		return -EINVAL;
 
 	csi2_ddrclk_khz = pipe->external_rate / 1000

So far so good.

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..85c6fefeb13a 100644
@@ -93,10 +93,10 @@
 #define CSI2_SYSCONFIG					0x10
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)

Nope (and many other snippets like this below). This is a region starting at bit 12. You can write 0, 1, 2, or 3. That doesn't make bit number 12 any special.

It's a 1 written into this region starting at bit 12. It's not bit 12. For the compiler it's the same. For humans, and for hardware design, it's definitely not.

Now, going back to your "somehow" understanding my table... why "somehow"? :) Please tell me what's not clear, instead.

Signature · 1 line
Stefano
#2 lore raw
Quoted 137 lines · Stefano Brivio
Quoted 43 lines · On Tue, 31 Mar 2020 18:58:17 -0400 Sam Muhammed <[email protected]> wrote:

Use BIT() across the driver, since bit masking
is better be done using the BIT macro.
Change is done using this coccinelle script:

@bit@
@@
BIT(...)

@depends on bit@
expression E;
constant c;
@@

(

(quoted diff) +1 -1
-(1 << E)
+BIT(E)

|

(quoted diff) +1 -1
-(1 << c)
+BIT(c)

)

---
Change in v2:
- removed unneeded parentheses around BIT,
they are not needed.
- reverted two hunks in iss_reg.h, using BIT
in both places makes the code confusing to
understand.
Changes suggested by Stefano Brivio.

 drivers/staging/media/omap4iss/iss.c        |  4 +-
 drivers/staging/media/omap4iss/iss.h        | 22 +++----
 drivers/staging/media/omap4iss/iss_csiphy.c |  6 +-
 drivers/staging/media/omap4iss/iss_regs.h   | 72 ++++++++++-----------
 drivers/staging/media/omap4iss/iss_video.h  | 16 ++---
 5 files changed, 60 insertions(+), 60 deletions(-)
drivers/staging/media/omap4iss/iss.c +0 -0
index 6fb60b58447a..2dc5c1bb34f9 100644

drivers/staging/media/omap4iss/iss.c static void iss_isr_dbg(struct iss_device *iss, u32 irqstatus) · line 249

Quoted 8 lines
drivers/staging/media/omap4iss/iss.c +1 -1
@@ -243,7 +243,7 @@ static void iss_isr_dbg(struct iss_device *iss, u32 irqstatus)
 	dev_dbg(iss->dev, "ISS IRQ: ");
 
 	for (i = 0; i < ARRAY_SIZE(name); i++) {
-		if ((1 << i) & irqstatus)
+		if (BIT(i) & irqstatus)
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");

Fine.

drivers/staging/media/omap4iss/iss.c static void iss_isp_isr_dbg(struct iss_device *iss, u32 irqstatus) · line 296

Quoted 9 lines
drivers/staging/media/omap4iss/iss.c +1 -1
@@ -290,7 +290,7 @@ static void iss_isp_isr_dbg(struct iss_device *iss, u32 irqstatus)
 	dev_dbg(iss->dev, "ISP IRQ: ");
 
 	for (i = 0; i < ARRAY_SIZE(name); i++) {
-		if ((1 << i) & irqstatus)
+		if (BIT(i) & irqstatus)
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");

Fine.

Quoted 26 lines
drivers/staging/media/omap4iss/iss.h +5 -10
index b88f9529683c..70371461b5be 100644
@@ -50,20 +50,20 @@ enum iss_mem_resources {
 };
 
 enum iss_subclk_resource {
-	OMAP4_ISS_SUBCLK_SIMCOP		= (1 << 0),
-	OMAP4_ISS_SUBCLK_ISP		= (1 << 1),
-	OMAP4_ISS_SUBCLK_CSI2_A		= (1 << 2),
-	OMAP4_ISS_SUBCLK_CSI2_B		= (1 << 3),
-	OMAP4_ISS_SUBCLK_CCP2		= (1 << 4),
+	OMAP4_ISS_SUBCLK_SIMCOP		= BIT(0),
+	OMAP4_ISS_SUBCLK_ISP		= BIT(1),
+	OMAP4_ISS_SUBCLK_CSI2_A		= BIT(2),
+	OMAP4_ISS_SUBCLK_CSI2_B		= BIT(3),
+	OMAP4_ISS_SUBCLK_CCP2		= BIT(4),
 };
 
 enum iss_isp_subclk_resource {
-	OMAP4_ISS_ISP_SUBCLK_BL		= (1 << 0),
-	OMAP4_ISS_ISP_SUBCLK_ISIF	= (1 << 1),
-	OMAP4_ISS_ISP_SUBCLK_H3A	= (1 << 2),
-	OMAP4_ISS_ISP_SUBCLK_RSZ	= (1 << 3),
-	OMAP4_ISS_ISP_SUBCLK_IPIPE	= (1 << 4),

drivers/staging/media/omap4iss/iss.h enum iss_mem_resources { · line 69

Quoted 10 lines
drivers/staging/media/omap4iss/iss.h +6 -1
-	OMAP4_ISS_ISP_SUBCLK_IPIPEIF	= (1 << 5),
+	OMAP4_ISS_ISP_SUBCLK_BL		= BIT(0),
+	OMAP4_ISS_ISP_SUBCLK_ISIF	= BIT(1),
+	OMAP4_ISS_ISP_SUBCLK_H3A	= BIT(2),
+	OMAP4_ISS_ISP_SUBCLK_RSZ	= BIT(3),
+	OMAP4_ISS_ISP_SUBCLK_IPIPE	= BIT(4),
+	OMAP4_ISS_ISP_SUBCLK_IPIPEIF	= BIT(5),
 };
 
 /*

Nice.

Quoted 18 lines
drivers/staging/media/omap4iss/iss_csiphy.c +2 -2
index 96f2ce045138..e2cad0a31098 100644
@@ -179,10 +179,10 @@ int omap4iss_csiphy_config(struct iss_device *iss,
 		    lanes->data[i].pos > (csi2->phy->max_data_lanes + 1))
 			return -EINVAL;
 
-		if (used_lanes & (1 << lanes->data[i].pos))
+		if (used_lanes & BIT(lanes->data[i].pos))
 			return -EINVAL;
 
-		used_lanes |= 1 << lanes->data[i].pos;
+		used_lanes |= BIT(lanes->data[i].pos);
 		csi2->phy->used_data_lanes++;
 	}
 

drivers/staging/media/omap4iss/iss_csiphy.c int omap4iss_csiphy_config(struct iss_device *iss, · line 196

Quoted 8 lines
drivers/staging/media/omap4iss/iss_csiphy.c +1 -1
@@ -190,7 +190,7 @@ int omap4iss_csiphy_config(struct iss_device *iss,
 	    lanes->clk.pos > (csi2->phy->max_data_lanes + 1))
 		return -EINVAL;
 
-	if (lanes->clk.pos == 0 || used_lanes & (1 << lanes->clk.pos))
+	if (lanes->clk.pos == 0 || used_lanes & BIT(lanes->clk.pos))
 		return -EINVAL;
 
 	csi2_ddrclk_khz = pipe->external_rate / 1000

So far so good.

Quoted 12 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..85c6fefeb13a 100644
@@ -93,10 +93,10 @@
 #define CSI2_SYSCONFIG					0x10
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

So i'am just going to interpret this hunk as i understand it and
please correct me.

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
	shift binary 3 by 12: "write 3 starting at bit 12"
		0011 ---- ---- ----		
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
	"write 0 at bit 12"
		0000 ---- ---- ----
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
	"shift binary 1 by 12": "write 1 at bit 12"
		0001 ---- ---- ----
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
	"shift binary 1 by 12": _isn't this what BIT() does?_
		0001 ---- ---- ----

now i dont understand what you meant by "That doesn't make bit 12 any special", does that assume that iam wrong with what BIT() is defined for?

#define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)
	"shift binary 2 by 12": write 2 at bit 12
		0010 ---- ---- ----

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

for your previous explanation: _quoting_ :

1. #define ISS_CTRL 0x80

        "we have a register at 0x80"
        https://en.wikipedia.org/wiki/Hardware_register

2. how big is it? Datasheet tells you, but before you even look for it:
#define ISS_CTRL_CLK_DIV_MASK (3 << 4)
"at least 7 bits"

   #define ISS_CLKCTRL                                     0x84
   #define ISS_CLKCTRL_VPORT2_CLK                          BIT(30)
        "probably they are all the same size, might be 32 bits"

3. picture it:

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|

(might be bigger, not too important)

4. #define ISS_CTRL_INPUT_SEL_MASK (3 << 2)

        "these bits define the input selection [whatever it is]":

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                       2^1 + 2^0 = 3
                                                   ^----(3 << 2)

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0   = 0
                                                    ^----(0 << 2)
   #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
        "to select input CSI2B [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  1 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  + 2^0  = 1
                                                    ^----(1 << 2)

Now, that's how the current #defines work. I think they are actually intuitive (you could use the GENMASK() macro, but I think the difference is not that big).

With your change:

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0  =  0
                                                    ^----(0 << 2)

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?
++++
now right at this point i got an overlapped definition of BIT() this expansion/explanation of BIT(2) in my mind got translated to:

     SetBit(register,bit) => (register|=(1<<bit))

NOT
shift binary 1 by 2
++++

Basically i forgot about this patch and i'am more into clearing this confusion because i'am definitely missing something thats very basic and probably have a wrong understanding of something.

Thank You,
Sam

Quoted 11 lines

Nope (and many other snippets like this below). This is a region starting at bit 12. You can write 0, 1, 2, or 3. That doesn't make bit number 12 any special.

It's a 1 written into this region starting at bit 12. It's not bit 12. For the compiler it's the same. For humans, and for hardware design, it's definitely not.

Now, going back to your "somehow" understanding my table... why "somehow"? :) Please tell me what's not clear, instead.

#3 lore raw

Hi Sam,

Quoted 34 lines · On Sat, 04 Apr 2020 01:33:09 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 2 lines · Stefano Brivio

On Tue, 31 Mar 2020 18:58:17 -0400
Sam Muhammed <[email protected]> wrote:

[...]

Quoted 12 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..85c6fefeb13a 100644
@@ -93,10 +93,10 @@
 #define CSI2_SYSCONFIG					0x10
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)  

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

So i'am just going to interpret this hunk as i understand it and
please correct me.

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
	shift binary 3 by 12: "write 3 starting at bit 12"
		0011 ---- ---- ----		
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
	"write 0 at bit 12"
		0000 ---- ---- ----
Quoted 6 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
	"shift binary 1 by 12": "write 1 at bit 12"
		0001 ---- ---- ----
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
	"shift binary 1 by 12": _isn't this what BIT() does?_
		0001 ---- ---- ----

This is the key perhaps: it is what BIT() does. And it's not what you should be... thinking of doing. Even though the result is clearly the same.

BIT() is used to set a single bit. You need to write *some* bits, here. That "some" is 2: you can write 0, 1, 2, 3, to this region. It's not 1.

Now, if you _write_ 1, you need to _set_ one bit, so coincidentally BIT() works too.

Suppose you have a tray to make ice cubes. You use one, and put the whole thing back in the freezer. Before you do that, it is your duty towards the society to fill it completely with water.

After you use one ice cube, it might look like this:

1 2 3 4
.----.----.----.----.

 |xxxx|xxxx|xxxx|xxxx|
 |----|----|----|----|
 |xxxx|xxxx|    |xxxx|

'----'----'----'----'
5 6 7 8

so we have two ways to express what you have to do:

a. fill hole number 7
b. refill the whole thing

a. will do the job just like b., but b. is how you would most naturally describe the operation. Especially because sometimes you take two ice cubes, sometimes three.

Quoted 3 lines

now i dont understand what you meant by "That doesn't make bit 12 any special", does that assume that iam wrong with what BIT() is defined for?

Yes, in some sense. BIT() is used to operate on a single bit: the difference is between:

a. set bit 12
b. write a number to bit region from 12 to 13

if the number from b. is 1, then a. is equivalent.

But right above and below this #define you have defines for 0 << 12, 2 << 12, 3 << 12. And 1 << 12 is not a special case.

Quoted 73 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)
	"shift binary 2 by 12": write 2 at bit 12
		0010 ---- ---- ----

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

for your previous explanation: _quoting_ :

1. #define ISS_CTRL 0x80

        "we have a register at 0x80"
        https://en.wikipedia.org/wiki/Hardware_register

2. how big is it? Datasheet tells you, but before you even look for it:

   #define ISS_CTRL_CLK_DIV_MASK                          (3 << 4)
        "at least 7 bits"

   #define ISS_CLKCTRL                                     0x84
   #define ISS_CLKCTRL_VPORT2_CLK                          BIT(30)
        "probably they are all the same size, might be 32 bits"

3. picture it:

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|

(might be bigger, not too important)

4. #define ISS_CTRL_INPUT_SEL_MASK (3 << 2)

        "these bits define the input selection [whatever it is]":

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                       2^1 + 2^0 = 3
                                                   ^----(3 << 2)

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0   = 0
                                                    ^----(0 << 2)
   #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
        "to select input CSI2B [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  1 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  + 2^0  = 1
                                                    ^----(1 << 2)

Now, that's how the current #defines work. I think they are actually intuitive (you could use the GENMASK() macro, but I think the difference is not that big).

With your change:

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0  =  0
                                                    ^----(0 << 2)

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?
++++
now right at this point i got an overlapped definition of BIT() this expansion/explanation of BIT(2) in my mind got translated to:

Quoted 4 lines
     SetBit(register,bit) => (register|=(1<<bit))

NOT
shift binary 1 by 2
++++

Yes, it's also about this. But from your example above:

      SetBit(register,bit) => (register|=(1<<bit))

you need to distinguish when you're operating on a bit *array* or a generic group of bit regions. That is, it's:

      SetBit(register,bit) => (register|=(n<<bit))

where 'n' happens to be 1, sometimes. It's not always '1' by design.

Let's take a driver operating a lamp that has three LEDs inside: it might work like this:

#define CTRL_REGISTER 0x5 /* a generic 8-bit register */
#define RED_ON BIT(0)
#define GREEN_ON BIT(1)
#define BLUE_ON BIT(2)

those are single bits, and consistently so, so using BIT() is fine.

Now, the lamp can be on, off, blink slow or fast. In the same register, you have 2 bits (starting from bit 4) controlling that: 0 means "off", 1 means "blink slow", 2 means "blink fast", 3 means "on":

#define MODE_OFF (0 << 4)
#define MODE_SLOW (1 << 4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

this is a natural way of describing things. Suppose you do, instead:

#define MODE_OFF (0 << 4)
#define MODE_SLOW BIT(4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

the compiler won't judge you, but I will. Why is the "slow" mode special? This makes the "slow" mode look like it's a binary option, but it's not.

Quoted 3 lines

Basically i forgot about this patch and i'am more into clearing this confusion because i'am definitely missing something thats very basic and probably have a wrong understanding of something.

Thanks for sticking with this, I appreciate that you're trying to figure out what I'm saying. Is it a bit clearer now?

Signature · 1 line
Stefano
#4 lore raw
Quoted 200 lines · Stefano Brivio

Hi Sam,

Quoted 34 lines · On Sat, 04 Apr 2020 01:33:09 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 2 lines · Stefano Brivio

On Tue, 31 Mar 2020 18:58:17 -0400
Sam Muhammed <[email protected]> wrote:

[...]

Quoted 12 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..85c6fefeb13a 100644
@@ -93,10 +93,10 @@
 #define CSI2_SYSCONFIG					0x10
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)  

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

So i'am just going to interpret this hunk as i understand it and
please correct me.

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
	shift binary 3 by 12: "write 3 starting at bit 12"
		0011 ---- ---- ----		
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
	"write 0 at bit 12"
		0000 ---- ---- ----
Quoted 6 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
	"shift binary 1 by 12": "write 1 at bit 12"
		0001 ---- ---- ----
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
	"shift binary 1 by 12": _isn't this what BIT() does?_
		0001 ---- ---- ----

This is the key perhaps: it is what BIT() does. And it's not what you should be... thinking of doing. Even though the result is clearly the same.

BIT() is used to set a single bit. You need to write *some* bits, here. That "some" is 2: you can write 0, 1, 2, 3, to this region. It's not 1.

Now, if you _write_ 1, you need to _set_ one bit, so coincidentally BIT() works too.

Suppose you have a tray to make ice cubes. You use one, and put the whole thing back in the freezer. Before you do that, it is your duty towards the society to fill it completely with water.

After you use one ice cube, it might look like this:

1 2 3 4
.----.----.----.----.

 |xxxx|xxxx|xxxx|xxxx|
 |----|----|----|----|
 |xxxx|xxxx|    |xxxx|

'----'----'----'----'
5 6 7 8

so we have two ways to express what you have to do:

a. fill hole number 7
b. refill the whole thing

a. will do the job just like b., but b. is how you would most naturally describe the operation. Especially because sometimes you take two ice cubes, sometimes three.

Quoted 3 lines

now i dont understand what you meant by "That doesn't make bit 12 any special", does that assume that iam wrong with what BIT() is defined for?

Yes, in some sense. BIT() is used to operate on a single bit: the difference is between:

a. set bit 12
b. write a number to bit region from 12 to 13

if the number from b. is 1, then a. is equivalent.

But right above and below this #define you have defines for 0 << 12, 2 << 12, 3 << 12. And 1 << 12 is not a special case.

Quoted 73 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)
	"shift binary 2 by 12": write 2 at bit 12
		0010 ---- ---- ----

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

for your previous explanation: _quoting_ :

1. #define ISS_CTRL 0x80

        "we have a register at 0x80"
        https://en.wikipedia.org/wiki/Hardware_register

2. how big is it? Datasheet tells you, but before you even look for it:

   #define ISS_CTRL_CLK_DIV_MASK                          (3 << 4)
        "at least 7 bits"

   #define ISS_CLKCTRL                                     0x84
   #define ISS_CLKCTRL_VPORT2_CLK                          BIT(30)
        "probably they are all the same size, might be 32 bits"

3. picture it:

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|

(might be bigger, not too important)

4. #define ISS_CTRL_INPUT_SEL_MASK (3 << 2)

        "these bits define the input selection [whatever it is]":

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                       2^1 + 2^0 = 3
                                                   ^----(3 << 2)

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0   = 0
                                                    ^----(0 << 2)
   #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
        "to select input CSI2B [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  1 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  + 2^0  = 1
                                                    ^----(1 << 2)

Now, that's how the current #defines work. I think they are actually intuitive (you could use the GENMASK() macro, but I think the difference is not that big).

With your change:

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0  =  0
                                                    ^----(0 << 2)

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?
++++
now right at this point i got an overlapped definition of BIT() this expansion/explanation of BIT(2) in my mind got translated to:

Quoted 4 lines
     SetBit(register,bit) => (register|=(1<<bit))

NOT
shift binary 1 by 2
++++

Yes, it's also about this. But from your example above:

      SetBit(register,bit) => (register|=(1<<bit))

you need to distinguish when you're operating on a bit *array* or a generic group of bit regions. That is, it's:

      SetBit(register,bit) => (register|=(n<<bit))

where 'n' happens to be 1, sometimes. It's not always '1' by design.

Let's take a driver operating a lamp that has three LEDs inside: it might work like this:

#define CTRL_REGISTER 0x5 /* a generic 8-bit register */
#define RED_ON BIT(0)
#define GREEN_ON BIT(1)
#define BLUE_ON BIT(2)

those are single bits, and consistently so, so using BIT() is fine.

Now, the lamp can be on, off, blink slow or fast. In the same register, you have 2 bits (starting from bit 4) controlling that: 0 means "off", 1 means "blink slow", 2 means "blink fast", 3 means "on":

#define MODE_OFF (0 << 4)
#define MODE_SLOW (1 << 4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

Quoted 7 lines

this is a natural way of describing things. Suppose you do, instead:

#define MODE_OFF (0 << 4)
#define MODE_SLOW BIT(4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

I guess that is a great example:
So if the operations are on a single bit being toggled on, BIT() is welcome to be used.

But when the operations involve a region of bits being toggled on/off i should stick to the typical way of bit manipulation even if there happens to be an operation that requires only one bit to be set.

++++
My thoughts were: _quoting your example_
#define RED_ON BIT(0)
#define GREEN_ON BIT(1) => 0001

#define BLUE_ON BIT(2) => 0010
This does set bit 2, but affected the rest
"so it was a _lame_ way of saying that there is a region of bits being manipulated though only one of them is set" :D

++++
so when it came to:

    #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
         "to select input CSI2B [whatever it is]", we need:
         |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ 0 _|_ 1 _|_ b1 _|_ b0 _|
                                        ^^     ^^  | << shift by 2
                                         0  + 2^0  = 1
                                                     ^----(1 << 2)

*my brain* --> yes, makes sense

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?

"my brain" --> why b3 is not 0 now?

shouldn't BIT(2) == 1*2^2 == 4 == 0100 ??
So i saw it like:
lets mask b2 to be set regardless of the rest
so if b3 was set, it will still be set next to setting b2.
so the meaning of BIT(2) got twisted up.

That why i got lost between these two:

      SetBit(register,bit) => (register|=(1<<bit))

AND
shift binary 1 by 2

I guess that was a twisted thought?? but now i can say it like _after going through this conversation_, that:

we are operating on a region of n bits starting from bit x, don't act like we're operating on a single bit by choosing BIT(y) over (1 << y).
++++

Quoted 11 lines

the compiler won't judge you, but I will. Why is the "slow" mode special? This makes the "slow" mode look like it's a binary option, but it's not.

Quoted 3 lines

Basically i forgot about this patch and i'am more into clearing this confusion because i'am definitely missing something thats very basic and probably have a wrong understanding of something.

Thanks for sticking with this, I appreciate that you're trying to figure out what I'm saying. Is it a bit clearer now?

Thank You,
I guess i got it right this time? have i??

Sam

#5 lore raw
Quoted 222 lines · On Sat, 04 Apr 2020 15:32:23 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 200 lines · Stefano Brivio

Hi Sam,

Quoted 34 lines · On Sat, 04 Apr 2020 01:33:09 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 2 lines · Stefano Brivio

On Tue, 31 Mar 2020 18:58:17 -0400
Sam Muhammed <[email protected]> wrote:

[...]

Quoted 12 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..85c6fefeb13a 100644
@@ -93,10 +93,10 @@
 #define CSI2_SYSCONFIG					0x10
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)    

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

So i'am just going to interpret this hunk as i understand it and
please correct me.

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
	shift binary 3 by 12: "write 3 starting at bit 12"
		0011 ---- ---- ----		
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
	"write 0 at bit 12"
		0000 ---- ---- ----
Quoted 6 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
	"shift binary 1 by 12": "write 1 at bit 12"
		0001 ---- ---- ----
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
	"shift binary 1 by 12": _isn't this what BIT() does?_
		0001 ---- ---- ----  

This is the key perhaps: it is what BIT() does. And it's not what you should be... thinking of doing. Even though the result is clearly the same.

BIT() is used to set a single bit. You need to write *some* bits, here. That "some" is 2: you can write 0, 1, 2, 3, to this region. It's not 1.

Now, if you _write_ 1, you need to _set_ one bit, so coincidentally BIT() works too.

Suppose you have a tray to make ice cubes. You use one, and put the whole thing back in the freezer. Before you do that, it is your duty towards the society to fill it completely with water.

After you use one ice cube, it might look like this:

1 2 3 4
.----.----.----.----.

 |xxxx|xxxx|xxxx|xxxx|
 |----|----|----|----|
 |xxxx|xxxx|    |xxxx|

'----'----'----'----'
5 6 7 8

so we have two ways to express what you have to do:

a. fill hole number 7
b. refill the whole thing

a. will do the job just like b., but b. is how you would most naturally describe the operation. Especially because sometimes you take two ice cubes, sometimes three.

Quoted 3 lines

now i dont understand what you meant by "That doesn't make bit 12 any special", does that assume that iam wrong with what BIT() is defined for?

Yes, in some sense. BIT() is used to operate on a single bit: the difference is between:

a. set bit 12
b. write a number to bit region from 12 to 13

if the number from b. is 1, then a. is equivalent.

But right above and below this #define you have defines for 0 << 12, 2 << 12, 3 << 12. And 1 << 12 is not a special case.

Quoted 73 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)
	"shift binary 2 by 12": write 2 at bit 12
		0010 ---- ---- ----

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

for your previous explanation: _quoting_ :

1. #define ISS_CTRL 0x80

        "we have a register at 0x80"
        https://en.wikipedia.org/wiki/Hardware_register

2. how big is it? Datasheet tells you, but before you even look for it:

   #define ISS_CTRL_CLK_DIV_MASK                          (3 << 4)
        "at least 7 bits"

   #define ISS_CLKCTRL                                     0x84
   #define ISS_CLKCTRL_VPORT2_CLK                          BIT(30)
        "probably they are all the same size, might be 32 bits"

3. picture it:

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|

(might be bigger, not too important)

4. #define ISS_CTRL_INPUT_SEL_MASK (3 << 2)

        "these bits define the input selection [whatever it is]":

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                       2^1 + 2^0 = 3
                                                   ^----(3 << 2)

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0   = 0
                                                    ^----(0 << 2)
   #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
        "to select input CSI2B [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  1 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  + 2^0  = 1
                                                    ^----(1 << 2)

Now, that's how the current #defines work. I think they are actually intuitive (you could use the GENMASK() macro, but I think the difference is not that big).

With your change:

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0  =  0
                                                    ^----(0 << 2)

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?
++++
now right at this point i got an overlapped definition of BIT() this expansion/explanation of BIT(2) in my mind got translated to:

Quoted 4 lines
     SetBit(register,bit) => (register|=(1<<bit))

NOT
shift binary 1 by 2
++++

Yes, it's also about this. But from your example above:

      SetBit(register,bit) => (register|=(1<<bit))

you need to distinguish when you're operating on a bit *array* or a generic group of bit regions. That is, it's:

      SetBit(register,bit) => (register|=(n<<bit))

where 'n' happens to be 1, sometimes. It's not always '1' by design.

Let's take a driver operating a lamp that has three LEDs inside: it might work like this:

#define CTRL_REGISTER 0x5 /* a generic 8-bit register */
#define RED_ON BIT(0)
#define GREEN_ON BIT(1)
#define BLUE_ON BIT(2)

those are single bits, and consistently so, so using BIT() is fine.

Now, the lamp can be on, off, blink slow or fast. In the same register, you have 2 bits (starting from bit 4) controlling that: 0 means "off", 1 means "blink slow", 2 means "blink fast", 3 means "on":

#define MODE_OFF (0 << 4)
#define MODE_SLOW (1 << 4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

Quoted 7 lines

this is a natural way of describing things. Suppose you do, instead:

#define MODE_OFF (0 << 4)
#define MODE_SLOW BIT(4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

I guess that is a great example:
So if the operations are on a single bit being toggled on, BIT() is welcome to be used.

But when the operations involve a region of bits being toggled on/off i should stick to the typical way of bit manipulation even if there happens to be an operation that requires only one bit to be set.

++++
My thoughts were: _quoting your example_
#define RED_ON BIT(0)
#define GREEN_ON BIT(1) => 0001

Quoted 4 lines

#define BLUE_ON BIT(2) => 0010
This does set bit 2, but affected the rest
"so it was a _lame_ way of saying that there is a region of bits being manipulated though only one of them is set" :D

Well, yes, I see what you mean. Two things here:

1. you don't know if my lamp can have more than one colour switched on at the same time. But it's irrelevant for the purposes of the data
representation: it's still one bit per colour. Other bits might need to be cleared, and in that case it might be convenient to have:

	#define COLOUR_MASK		(RED_ON | GREEN_ON | BLUE_ON)

or, somewhat less appropriately:

	#define COLOUR_MASK		GENMASK(0, 2)

but that's a "meta" operation you do on a set of homogeneous bits, so it's a completely separated fact.

2. most likely, you would need to write the register as a whole, so you read, then set or clear bits, then write -- this means essentially that you write all the bits at a time, yes. But this is not conceptually relevant, it's an implementation detail.

Quoted 10 lines

++++
so when it came to:

    #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
         "to select input CSI2B [whatever it is]", we need:
         |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ 0 _|_ 1 _|_ b1 _|_ b0 _|
                                        ^^     ^^  | << shift by 2
                                         0  + 2^0  = 1
                                                     ^----(1 << 2)

*my brain* --> yes, makes sense

Quoted 8 lines

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?

"my brain" --> why b3 is not 0 now?

That's what I would ask, too. Yeah, sure, it will be, but BIT() is deceiving in this sense.

Quoted 8 lines

shouldn't BIT(2) == 1*2^2 == 4 == 0100 ??
So i saw it like:
lets mask b2 to be set regardless of the rest
so if b3 was set, it will still be set next to setting b2.
so the meaning of BIT(2) got twisted up.

That why i got lost between these two:

      SetBit(register,bit) => (register|=(1<<bit))
Quoted 8 lines

AND
shift binary 1 by 2

I guess that was a twisted thought?? but now i can say it like _after going through this conversation_, that:

we are operating on a region of n bits starting from bit x, don't act like we're operating on a single bit by choosing BIT(y) over (1 << y).

Yes, makes sense to me.

Quoted 10 lines

++++

Quoted 8 lines

the compiler won't judge you, but I will. Why is the "slow" mode special? This makes the "slow" mode look like it's a binary option, but it's not.

Quoted 3 lines

Basically i forgot about this patch and i'am more into clearing this confusion because i'am definitely missing something thats very basic and probably have a wrong understanding of something.

Quoted 6 lines
Quoted 3 lines

Thanks for sticking with this, I appreciate that you're trying to figure out what I'm saying. Is it a bit clearer now?

Thank You,
I guess i got it right this time? have i??

I think so! :) Or use Julia's example, I think it's equivalent to mine and it can't fail.

Signature · 1 line
Stefano
#6 lore raw
Quoted 304 lines · Stefano Brivio
Quoted 222 lines · On Sat, 04 Apr 2020 15:32:23 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 200 lines · Stefano Brivio

Hi Sam,

Quoted 34 lines · On Sat, 04 Apr 2020 01:33:09 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 2 lines · Stefano Brivio

On Tue, 31 Mar 2020 18:58:17 -0400
Sam Muhammed <[email protected]> wrote:

[...]

Quoted 12 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..85c6fefeb13a 100644
@@ -93,10 +93,10 @@
 #define CSI2_SYSCONFIG					0x10
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)    

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

So i'am just going to interpret this hunk as i understand it and
please correct me.

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK		(3 << 12)
	shift binary 3 by 12: "write 3 starting at bit 12"
		0011 ---- ---- ----		
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE		(0 << 12)
	"write 0 at bit 12"
		0000 ---- ---- ----
Quoted 6 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
	"shift binary 1 by 12": "write 1 at bit 12"
		0001 ---- ---- ----
#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
	"shift binary 1 by 12": _isn't this what BIT() does?_
		0001 ---- ---- ----  

This is the key perhaps: it is what BIT() does. And it's not what you should be... thinking of doing. Even though the result is clearly the same.

BIT() is used to set a single bit. You need to write *some* bits, here. That "some" is 2: you can write 0, 1, 2, 3, to this region. It's not 1.

Now, if you _write_ 1, you need to _set_ one bit, so coincidentally BIT() works too.

Suppose you have a tray to make ice cubes. You use one, and put the whole thing back in the freezer. Before you do that, it is your duty towards the society to fill it completely with water.

After you use one ice cube, it might look like this:

1 2 3 4
.----.----.----.----.

 |xxxx|xxxx|xxxx|xxxx|
 |----|----|----|----|
 |xxxx|xxxx|    |xxxx|

'----'----'----'----'
5 6 7 8

so we have two ways to express what you have to do:

a. fill hole number 7
b. refill the whole thing

a. will do the job just like b., but b. is how you would most naturally describe the operation. Especially because sometimes you take two ice cubes, sometimes three.

Quoted 3 lines

now i dont understand what you meant by "That doesn't make bit 12 any special", does that assume that iam wrong with what BIT() is defined for?

Yes, in some sense. BIT() is used to operate on a single bit: the difference is between:

a. set bit 12
b. write a number to bit region from 12 to 13

if the number from b. is 1, then a. is equivalent.

But right above and below this #define you have defines for 0 << 12, 2 << 12, 3 << 12. And 1 << 12 is not a special case.

Quoted 73 lines
#define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)
	"shift binary 2 by 12": write 2 at bit 12
		0010 ---- ---- ----

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

for your previous explanation: _quoting_ :

1. #define ISS_CTRL 0x80

        "we have a register at 0x80"
        https://en.wikipedia.org/wiki/Hardware_register

2. how big is it? Datasheet tells you, but before you even look for it:

   #define ISS_CTRL_CLK_DIV_MASK                          (3 << 4)
        "at least 7 bits"

   #define ISS_CLKCTRL                                     0x84
   #define ISS_CLKCTRL_VPORT2_CLK                          BIT(30)
        "probably they are all the same size, might be 32 bits"

3. picture it:

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|

(might be bigger, not too important)

4. #define ISS_CTRL_INPUT_SEL_MASK (3 << 2)

        "these bits define the input selection [whatever it is]":

        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ b2 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                       2^1 + 2^0 = 3
                                                   ^----(3 << 2)

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0   = 0
                                                    ^----(0 << 2)
   #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
        "to select input CSI2B [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  1 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  + 2^0  = 1
                                                    ^----(1 << 2)

Now, that's how the current #defines work. I think they are actually intuitive (you could use the GENMASK() macro, but I think the difference is not that big).

With your change:

5. #define ISS_CTRL_INPUT_SEL_CSI2A (0 << 2)

        "to select input CSI2A [whatever it is]", we need:
        |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_  0 _|_  0 _|_ b1 _|_ b0 _|
                                       ^^     ^^  | << shift by 2
                                        0  +  0  =  0
                                                    ^----(0 << 2)

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?
++++
now right at this point i got an overlapped definition of BIT() this expansion/explanation of BIT(2) in my mind got translated to:

Quoted 4 lines
     SetBit(register,bit) => (register|=(1<<bit))

NOT
shift binary 1 by 2
++++

Yes, it's also about this. But from your example above:

      SetBit(register,bit) => (register|=(1<<bit))

you need to distinguish when you're operating on a bit *array* or a generic group of bit regions. That is, it's:

      SetBit(register,bit) => (register|=(n<<bit))

where 'n' happens to be 1, sometimes. It's not always '1' by design.

Let's take a driver operating a lamp that has three LEDs inside: it might work like this:

#define CTRL_REGISTER 0x5 /* a generic 8-bit register */
#define RED_ON BIT(0)
#define GREEN_ON BIT(1)
#define BLUE_ON BIT(2)

those are single bits, and consistently so, so using BIT() is fine.

Now, the lamp can be on, off, blink slow or fast. In the same register, you have 2 bits (starting from bit 4) controlling that: 0 means "off", 1 means "blink slow", 2 means "blink fast", 3 means "on":

#define MODE_OFF (0 << 4)
#define MODE_SLOW (1 << 4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

Quoted 7 lines

this is a natural way of describing things. Suppose you do, instead:

#define MODE_OFF (0 << 4)
#define MODE_SLOW BIT(4)
#define MODE_FAST (2 << 4)
#define MODE_ON (3 << 4)

I guess that is a great example:
So if the operations are on a single bit being toggled on, BIT() is welcome to be used.

But when the operations involve a region of bits being toggled on/off i should stick to the typical way of bit manipulation even if there happens to be an operation that requires only one bit to be set.

++++
My thoughts were: _quoting your example_
#define RED_ON BIT(0)
#define GREEN_ON BIT(1) => 0001

Quoted 4 lines

#define BLUE_ON BIT(2) => 0010
This does set bit 2, but affected the rest
"so it was a _lame_ way of saying that there is a region of bits being manipulated though only one of them is set" :D

Well, yes, I see what you mean. Two things here:

1. you don't know if my lamp can have more than one colour switched on at the same time. But it's irrelevant for the purposes of the data
representation: it's still one bit per colour. Other bits might need to be cleared, and in that case it might be convenient to have:

	#define COLOUR_MASK		(RED_ON | GREEN_ON | BLUE_ON)

or, somewhat less appropriately:

	#define COLOUR_MASK		GENMASK(0, 2)

but that's a "meta" operation you do on a set of homogeneous bits, so it's a completely separated fact.

2. most likely, you would need to write the register as a whole, so you read, then set or clear bits, then write -- this means essentially that you write all the bits at a time, yes. But this is not conceptually relevant, it's an implementation detail.

Quoted 10 lines

++++
so when it came to:

    #define ISS_CTRL_INPUT_SEL_CSI2B                     (1 << 2)
         "to select input CSI2B [whatever it is]", we need:
         |_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ 0 _|_ 1 _|_ b1 _|_ b0 _|
                                        ^^     ^^  | << shift by 2
                                         0  + 2^0  = 1
                                                     ^----(1 << 2)

*my brain* --> yes, makes sense

Quoted 8 lines

#define ISS_CTRL_INPUT_SEL_CSI2B BIT(2)
"to select input CSI2B [whatever it is]", we need:
|_ b7 _|_ b6 _|_ b5 _|_ b4 _|_ b3 _|_ 1 _|_ b1 _|_ b0 _|
^
' this bit set.
What, why? How is this related with the rest?

"my brain" --> why b3 is not 0 now?

That's what I would ask, too. Yeah, sure, it will be, but BIT() is deceiving in this sense.

Quoted 8 lines

shouldn't BIT(2) == 1*2^2 == 4 == 0100 ??
So i saw it like:
lets mask b2 to be set regardless of the rest
so if b3 was set, it will still be set next to setting b2.
so the meaning of BIT(2) got twisted up.

That why i got lost between these two:

      SetBit(register,bit) => (register|=(1<<bit))
Quoted 8 lines

AND
shift binary 1 by 2

I guess that was a twisted thought?? but now i can say it like _after going through this conversation_, that:

we are operating on a region of n bits starting from bit x, don't act like we're operating on a single bit by choosing BIT(y) over (1 << y).

Yes, makes sense to me.

Quoted 14 lines

++++

Quoted 11 lines

the compiler won't judge you, but I will. Why is the "slow" mode special? This makes the "slow" mode look like it's a binary option, but it's not.

Quoted 3 lines

Basically i forgot about this patch and i'am more into clearing this confusion because i'am definitely missing something thats very basic and probably have a wrong understanding of something.

Thanks for sticking with this, I appreciate that you're trying to figure out what I'm saying. Is it a bit clearer now?

Quoted 6 lines
Quoted 2 lines

Thank You,
I guess i got it right this time? have i??

I think so! :) Or use Julia's example, I think it's equivalent to mine and it can't fail.

Alright, Great, I'll check for a 3rd revision then.

Thank You.

Sam

#7 lore raw
In reply to Sam Muhammed
Quoted 10 lines
Quoted 6 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 5 lines

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK (3 << 12)
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE (0 << 12)

drivers/staging/media/omap4iss/iss_regs.h +1 -1
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

In the original code you have a bunch of things shifted to the left by 12 bits. 3 0 1 and 2. They all look the same, and one can think about a little region of bits some of which can be on and some of which can be off. If you put BIT(12) in one case you don't see that.

For example, if you had

1 + 100
2 + 100
3 + 100
104
5 + 100

How easy is it to check that you have a sequence of 5 numbers? It's really easy to add a single digit integer to 100, but probably you had to think just a little extra bit when you came to 104, because it's not following the same pattern.

julia

#8 lore raw
Quoted 16 lines · Julia Lawall
Quoted 10 lines
Quoted 6 lines

drivers/staging/media/omap4iss/iss_regs.h line 97

Quoted 5 lines

#define CSI2_SYSCONFIG_MSTANDBY_MODE_MASK (3 << 12)
#define CSI2_SYSCONFIG_MSTANDBY_MODE_FORCE (0 << 12)

drivers/staging/media/omap4iss/iss_regs.h +1 -1
-#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			(1 << 12)
+#define CSI2_SYSCONFIG_MSTANDBY_MODE_NO			BIT(12)
 #define CSI2_SYSCONFIG_MSTANDBY_MODE_SMART		(2 << 12)

Hi Stefano,
honestly i'am confused about how is there a difference between BIT(x) and (1 << x)

In the original code you have a bunch of things shifted to the left by 12 bits. 3 0 1 and 2. They all look the same, and one can think about a little region of bits some of which can be on and some of which can be off. If you put BIT(12) in one case you don't see that.

Quoted 8 lines

For example, if you had

1 + 100
2 + 100
3 + 100
104
5 + 100

Thank you Julia!
this is what i thought of with using the word _pattern_ now its easier to say in other words:

"we are manipulating a number of bits, if there happened to be an operation where a single bit is set that doesn't kill the fact that _a number of bits_ are being manipulated and that you could use BIT for this instance" -> i mean i shouldn't use BIT here

on the other hand:
when there is a behaviour that involves manipulating a single bit only for all operations, BIT() in functional and meaningful.

I think it's clear for me now ヽ(´▽`)/

Quoted 6 lines

How easy is it to check that you have a sequence of 5 numbers? It's really easy to add a single digit integer to 100, but probably you had to think just a little extra bit when you came to 104, because it's not following the same pattern.

julia

Thank You
Sam