Skip to contentSkip to conversation

Staging: media: omap4iss: Use BIT() macro.

PATCH Superseded Sam Muhammed 3 participants 8 messages Mar 26, 2020 – Mar 30, 2020

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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)
)

---
 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   | 78 ++++++++++-----------
 drivers/staging/media/omap4iss/iss_video.h  | 16 ++---
 5 files changed, 63 insertions(+), 63 deletions(-)
drivers/staging/media/omap4iss/iss.c +2 -2
index 6fb60b58447a..baa1fa5d5c00 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..0c8a790c0ac7 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..1bdd4ecd900d 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 +39 -39

179 lines not on this page · raw message

drivers/staging/media/omap4iss/iss_video.h +8 -8
index 8b3dd92021e1..c0d021636224 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 35 lines · On Thu, 26 Mar 2020 17:02:47 -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;
@@

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

---
 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   | 78 ++++++++++-----------
 drivers/staging/media/omap4iss/iss_video.h  | 16 ++---
 5 files changed, 63 insertions(+), 63 deletions(-)
drivers/staging/media/omap4iss/iss.c +0 -0
index 6fb60b58447a..baa1fa5d5c00 100644

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

Quoted 5 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)

There's a reason why 1 << i is surrounded by parentheses, but it makes no sense to do that around a macro.

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

Quoted 9 lines
drivers/staging/media/omap4iss/iss.c +1 -1
 			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)

Same here.

Quoted 11 lines
drivers/staging/media/omap4iss/iss.c +0 -0
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");
drivers/staging/media/omap4iss/iss.h +0 -0
index b88f9529683c..0c8a790c0ac7 100644
@@ -50,20 +50,20 @@ enum iss_mem_resources {
 };
 
 enum iss_subclk_resource {

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

Quoted 10 lines
drivers/staging/media/omap4iss/iss.h +5 -5
-	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)),

Here, too.

Quoted 5 lines
drivers/staging/media/omap4iss/iss.h +0 -2
 };
 
 enum iss_isp_subclk_resource {
-	OMAP4_ISS_ISP_SUBCLK_BL		= (1 << 0),
-	OMAP4_ISS_ISP_SUBCLK_ISIF	= (1 << 1),

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

Quoted 10 lines
drivers/staging/media/omap4iss/iss.h +6 -4
-	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)),

And here.

Quoted 21 lines
drivers/staging/media/omap4iss/iss.h +0 -0
 };
 
 /*
drivers/staging/media/omap4iss/iss_csiphy.c +2 -2
index 96f2ce045138..1bdd4ecd900d 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

And here.

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

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..7adc944e1a5d 100644
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

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

Quoted 13 lines
drivers/staging/media/omap4iss/iss_regs.h +3 -3
 #define ISS_CLKCTRL					0x84
@@ -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)
-#define CSI2_SYSCONFIG_SOFT_RESET			(1 << 1)
-#define CSI2_SYSCONFIG_AUTO_IDLE			(1 << 0)
+#define CSI2_SYSCONFIG_SOFT_RESET			(BIT(1))
+#define CSI2_SYSCONFIG_AUTO_IDLE			(BIT(0))

Also no need for parentheses around BIT().

Quoted 67 lines
drivers/staging/media/omap4iss/iss_regs.h +17 -17
 #define CSI2_SYSSTATUS					0x14
 #define CSI2_SYSSTATUS_RESET_DONE			BIT(0)
@@ -119,37 +119,37 @@
 #define CSI2_CTRL_MFLAG_LEVH_SHIFT			20
 #define CSI2_CTRL_MFLAG_LEVL_MASK			(7 << 17)
 #define CSI2_CTRL_MFLAG_LEVL_SHIFT			17
-#define CSI2_CTRL_BURST_SIZE_EXPAND			(1 << 16)
-#define CSI2_CTRL_VP_CLK_EN				(1 << 15)
-#define CSI2_CTRL_NON_POSTED_WRITE			(1 << 13)
-#define CSI2_CTRL_VP_ONLY_EN				(1 << 11)
+#define CSI2_CTRL_BURST_SIZE_EXPAND			(BIT(16))
+#define CSI2_CTRL_VP_CLK_EN				(BIT(15))
+#define CSI2_CTRL_NON_POSTED_WRITE			(BIT(13))
+#define CSI2_CTRL_VP_ONLY_EN				(BIT(11))
 #define CSI2_CTRL_VP_OUT_CTRL_MASK			(3 << 8)
 #define CSI2_CTRL_VP_OUT_CTRL_SHIFT			8
-#define CSI2_CTRL_DBG_EN				(1 << 7)
+#define CSI2_CTRL_DBG_EN				(BIT(7))
 #define CSI2_CTRL_BURST_SIZE_MASK			(3 << 5)
-#define CSI2_CTRL_ENDIANNESS				(1 << 4)
-#define CSI2_CTRL_FRAME					(1 << 3)
-#define CSI2_CTRL_ECC_EN				(1 << 2)
-#define CSI2_CTRL_IF_EN					(1 << 0)
+#define CSI2_CTRL_ENDIANNESS				(BIT(4))
+#define CSI2_CTRL_FRAME					(BIT(3))
+#define CSI2_CTRL_ECC_EN				(BIT(2))
+#define CSI2_CTRL_IF_EN					(BIT(0))
 
 #define CSI2_DBG_H					0x44
 
 #define CSI2_COMPLEXIO_CFG				0x50
-#define CSI2_COMPLEXIO_CFG_RESET_CTRL			(1 << 30)
-#define CSI2_COMPLEXIO_CFG_RESET_DONE			(1 << 29)
+#define CSI2_COMPLEXIO_CFG_RESET_CTRL			(BIT(30))
+#define CSI2_COMPLEXIO_CFG_RESET_DONE			(BIT(29))
 #define CSI2_COMPLEXIO_CFG_PWD_CMD_MASK			(3 << 27)
 #define CSI2_COMPLEXIO_CFG_PWD_CMD_OFF			(0 << 27)
-#define CSI2_COMPLEXIO_CFG_PWD_CMD_ON			(1 << 27)
+#define CSI2_COMPLEXIO_CFG_PWD_CMD_ON			(BIT(27))
 #define CSI2_COMPLEXIO_CFG_PWD_CMD_ULP			(2 << 27)
 #define CSI2_COMPLEXIO_CFG_PWD_STATUS_MASK		(3 << 25)
 #define CSI2_COMPLEXIO_CFG_PWD_STATUS_OFF		(0 << 25)
-#define CSI2_COMPLEXIO_CFG_PWD_STATUS_ON		(1 << 25)
+#define CSI2_COMPLEXIO_CFG_PWD_STATUS_ON		(BIT(25))
 #define CSI2_COMPLEXIO_CFG_PWD_STATUS_ULP		(2 << 25)
-#define CSI2_COMPLEXIO_CFG_PWR_AUTO			(1 << 24)
-#define CSI2_COMPLEXIO_CFG_DATA_POL(i)			(1 << (((i) * 4) + 3))
+#define CSI2_COMPLEXIO_CFG_PWR_AUTO			(BIT(24))
+#define CSI2_COMPLEXIO_CFG_DATA_POL(i)			(BIT((((i) * 4) + 3)))
 #define CSI2_COMPLEXIO_CFG_DATA_POSITION_MASK(i)	(7 << ((i) * 4))
 #define CSI2_COMPLEXIO_CFG_DATA_POSITION_SHIFT(i)	((i) * 4)
-#define CSI2_COMPLEXIO_CFG_CLOCK_POL			(1 << 3)
+#define CSI2_COMPLEXIO_CFG_CLOCK_POL			(BIT(3))
 #define CSI2_COMPLEXIO_CFG_CLOCK_POSITION_MASK		(7 << 0)
 #define CSI2_COMPLEXIO_CFG_CLOCK_POSITION_SHIFT		0
 
@@ -218,7 +218,7 @@
 		(0x3 << CSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT)
 #define CSI2_CTX_CTRL2_VIRTUAL_ID_MASK			(3 << 11)
 #define CSI2_CTX_CTRL2_VIRTUAL_ID_SHIFT			11
-#define CSI2_CTX_CTRL2_DPCM_PRED			(1 << 10)
+#define CSI2_CTX_CTRL2_DPCM_PRED			(BIT(10))
 #define CSI2_CTX_CTRL2_FORMAT_MASK			(0x3ff << 0)
 #define CSI2_CTX_CTRL2_FORMAT_SHIFT			0
 

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

Quoted 5 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
@@ -259,9 +259,9 @@
 #define ISP5_SYSCONFIG					(0x0010)
 #define ISP5_SYSCONFIG_STANDBYMODE_MASK			(3 << 4)
 #define ISP5_SYSCONFIG_STANDBYMODE_FORCE		(0 << 4)
-#define ISP5_SYSCONFIG_STANDBYMODE_NO			(1 << 4)
+#define ISP5_SYSCONFIG_STANDBYMODE_NO			(BIT(4))

"Standby mode is forced by clearing 3 bits at index 4. Smart mode is set by setting 2 as value for those bits. No standby mode is an entirely different story: set bit 4 of ISP5_SYSCONFIG."

Quoted 125 lines
drivers/staging/media/omap4iss/iss_regs.h +17 -17
 #define ISP5_SYSCONFIG_STANDBYMODE_SMART		(2 << 4)
-#define ISP5_SYSCONFIG_SOFTRESET			(1 << 1)
+#define ISP5_SYSCONFIG_SOFTRESET			(BIT(1))
 
 #define ISP5_IRQSTATUS(i)				(0x0028 + (0x10 * (i)))
 #define ISP5_IRQENABLE_SET(i)				(0x002c + (0x10 * (i)))
@@ -315,14 +315,14 @@
 #define ISIF_MODESET					(0x0004)
 #define ISIF_MODESET_INPMOD_MASK			(3 << 12)
 #define ISIF_MODESET_INPMOD_RAW				(0 << 12)
-#define ISIF_MODESET_INPMOD_YCBCR16			(1 << 12)
+#define ISIF_MODESET_INPMOD_YCBCR16			(BIT(12))
 #define ISIF_MODESET_INPMOD_YCBCR8			(2 << 12)
 #define ISIF_MODESET_CCDW_MASK				(7 << 8)
 #define ISIF_MODESET_CCDW_2BIT				(2 << 8)
-#define ISIF_MODESET_CCDMD				(1 << 7)
-#define ISIF_MODESET_SWEN				(1 << 5)
-#define ISIF_MODESET_HDPOL				(1 << 3)
-#define ISIF_MODESET_VDPOL				(1 << 2)
+#define ISIF_MODESET_CCDMD				(BIT(7))
+#define ISIF_MODESET_SWEN				(BIT(5))
+#define ISIF_MODESET_HDPOL				(BIT(3))
+#define ISIF_MODESET_VDPOL				(BIT(2))
 
 #define ISIF_SPH					(0x0018)
 #define ISIF_SPH_MASK					(0x7fff)
@@ -345,19 +345,19 @@
 
 #define ISIF_CCOLP					(0x004c)
 #define ISIF_CCOLP_CP0_F0_R				(0 << 6)
-#define ISIF_CCOLP_CP0_F0_GR				(1 << 6)
+#define ISIF_CCOLP_CP0_F0_GR				(BIT(6))
 #define ISIF_CCOLP_CP0_F0_B				(3 << 6)
 #define ISIF_CCOLP_CP0_F0_GB				(2 << 6)
 #define ISIF_CCOLP_CP1_F0_R				(0 << 4)
-#define ISIF_CCOLP_CP1_F0_GR				(1 << 4)
+#define ISIF_CCOLP_CP1_F0_GR				(BIT(4))
 #define ISIF_CCOLP_CP1_F0_B				(3 << 4)
 #define ISIF_CCOLP_CP1_F0_GB				(2 << 4)
 #define ISIF_CCOLP_CP2_F0_R				(0 << 2)
-#define ISIF_CCOLP_CP2_F0_GR				(1 << 2)
+#define ISIF_CCOLP_CP2_F0_GR				(BIT(2))
 #define ISIF_CCOLP_CP2_F0_B				(3 << 2)
 #define ISIF_CCOLP_CP2_F0_GB				(2 << 2)
 #define ISIF_CCOLP_CP3_F0_R				(0 << 0)
-#define ISIF_CCOLP_CP3_F0_GR				(1 << 0)
+#define ISIF_CCOLP_CP3_F0_GR				(BIT(0))
 #define ISIF_CCOLP_CP3_F0_B				(3 << 0)
 #define ISIF_CCOLP_CP3_F0_GB				(2 << 0)
 
@@ -377,12 +377,12 @@
 #define IPIPEIF_CFG1					(0x0004)
 #define IPIPEIF_CFG1_INPSRC1_MASK			(3 << 14)
 #define IPIPEIF_CFG1_INPSRC1_VPORT_RAW			(0 << 14)
-#define IPIPEIF_CFG1_INPSRC1_SDRAM_RAW			(1 << 14)
+#define IPIPEIF_CFG1_INPSRC1_SDRAM_RAW			(BIT(14))
 #define IPIPEIF_CFG1_INPSRC1_ISIF_DARKFM		(2 << 14)
 #define IPIPEIF_CFG1_INPSRC1_SDRAM_YUV			(3 << 14)
 #define IPIPEIF_CFG1_INPSRC2_MASK			(3 << 2)
 #define IPIPEIF_CFG1_INPSRC2_ISIF			(0 << 2)
-#define IPIPEIF_CFG1_INPSRC2_SDRAM_RAW			(1 << 2)
+#define IPIPEIF_CFG1_INPSRC2_SDRAM_RAW			(BIT(2))
 #define IPIPEIF_CFG1_INPSRC2_ISIF_DARKFM		(2 << 2)
 #define IPIPEIF_CFG1_INPSRC2_SDRAM_YUV			(3 << 2)
 
@@ -406,25 +406,25 @@
 
 #define IPIPE_SRC_FMT					(0x0008)
 #define IPIPE_SRC_FMT_RAW2YUV				(0 << 0)
-#define IPIPE_SRC_FMT_RAW2RAW				(1 << 0)
+#define IPIPE_SRC_FMT_RAW2RAW				(BIT(0))
 #define IPIPE_SRC_FMT_RAW2STATS				(2 << 0)
 #define IPIPE_SRC_FMT_YUV2YUV				(3 << 0)
 
 #define IPIPE_SRC_COL					(0x000c)
 #define IPIPE_SRC_COL_OO_R				(0 << 6)
-#define IPIPE_SRC_COL_OO_GR				(1 << 6)
+#define IPIPE_SRC_COL_OO_GR				(BIT(6))
 #define IPIPE_SRC_COL_OO_B				(3 << 6)
 #define IPIPE_SRC_COL_OO_GB				(2 << 6)
 #define IPIPE_SRC_COL_OE_R				(0 << 4)
-#define IPIPE_SRC_COL_OE_GR				(1 << 4)
+#define IPIPE_SRC_COL_OE_GR				(BIT(4))
 #define IPIPE_SRC_COL_OE_B				(3 << 4)
 #define IPIPE_SRC_COL_OE_GB				(2 << 4)
 #define IPIPE_SRC_COL_EO_R				(0 << 2)
-#define IPIPE_SRC_COL_EO_GR				(1 << 2)
+#define IPIPE_SRC_COL_EO_GR				(BIT(2))
 #define IPIPE_SRC_COL_EO_B				(3 << 2)
 #define IPIPE_SRC_COL_EO_GB				(2 << 2)
 #define IPIPE_SRC_COL_EE_R				(0 << 0)
-#define IPIPE_SRC_COL_EE_GR				(1 << 0)
+#define IPIPE_SRC_COL_EE_GR				(BIT(0))
 #define IPIPE_SRC_COL_EE_B				(3 << 0)
 #define IPIPE_SRC_COL_EE_GB				(2 << 0)
 
drivers/staging/media/omap4iss/iss_video.h +6 -6
index 8b3dd92021e1..c0d021636224 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)),
 };
 
 /*

drivers/staging/media/omap4iss/iss_video.h struct iss_buffer { · line 126

Quoted 9 lines
drivers/staging/media/omap4iss/iss_video.h +2 -2
@@ -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)),
 };

No need for parentheses in all the hunks above.

Signature · 1 line
Stefano
#2 lore raw
Quoted 149 lines · Stefano Brivio
Quoted 35 lines · On Thu, 26 Mar 2020 17:02:47 -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;
@@

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

---
 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   | 78 ++++++++++-----------
 drivers/staging/media/omap4iss/iss_video.h  | 16 ++---
 5 files changed, 63 insertions(+), 63 deletions(-)
drivers/staging/media/omap4iss/iss.c +0 -0
index 6fb60b58447a..baa1fa5d5c00 100644

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

Quoted 5 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)

There's a reason why 1 << i is surrounded by parentheses, but it makes no sense to do that around a macro.

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

Quoted 9 lines
drivers/staging/media/omap4iss/iss.c +1 -1
 			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)

Same here.

Quoted 11 lines
drivers/staging/media/omap4iss/iss.c +0 -0
 			pr_cont("%s ", name[i]);
 	}
 	pr_cont("\n");
drivers/staging/media/omap4iss/iss.h +0 -0
index b88f9529683c..0c8a790c0ac7 100644
@@ -50,20 +50,20 @@ enum iss_mem_resources {
 };
 
 enum iss_subclk_resource {

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

Quoted 10 lines
drivers/staging/media/omap4iss/iss.h +5 -5
-	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)),

Here, too.

Quoted 5 lines
drivers/staging/media/omap4iss/iss.h +0 -2
 };
 
 enum iss_isp_subclk_resource {
-	OMAP4_ISS_ISP_SUBCLK_BL		= (1 << 0),
-	OMAP4_ISS_ISP_SUBCLK_ISIF	= (1 << 1),

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

Quoted 10 lines
drivers/staging/media/omap4iss/iss.h +6 -4
-	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)),

And here.

Quoted 21 lines
drivers/staging/media/omap4iss/iss.h +0 -0
 };
 
 /*
drivers/staging/media/omap4iss/iss_csiphy.c +2 -2
index 96f2ce045138..1bdd4ecd900d 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

And here.

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

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..7adc944e1a5d 100644
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

Quoted 5 lines

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

Oh, So defining BIT(2) totally changed the logic?

Quoted 82 lines

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

Quoted 13 lines
drivers/staging/media/omap4iss/iss_regs.h +3 -3
 #define ISS_CLKCTRL					0x84
@@ -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)
-#define CSI2_SYSCONFIG_SOFT_RESET			(1 << 1)
-#define CSI2_SYSCONFIG_AUTO_IDLE			(1 << 0)
+#define CSI2_SYSCONFIG_SOFT_RESET			(BIT(1))
+#define CSI2_SYSCONFIG_AUTO_IDLE			(BIT(0))

Also no need for parentheses around BIT().

Quoted 66 lines
drivers/staging/media/omap4iss/iss_regs.h +17 -17
 #define CSI2_SYSSTATUS					0x14
 #define CSI2_SYSSTATUS_RESET_DONE			BIT(0)
@@ -119,37 +119,37 @@
 #define CSI2_CTRL_MFLAG_LEVH_SHIFT			20
 #define CSI2_CTRL_MFLAG_LEVL_MASK			(7 << 17)
 #define CSI2_CTRL_MFLAG_LEVL_SHIFT			17
-#define CSI2_CTRL_BURST_SIZE_EXPAND			(1 << 16)
-#define CSI2_CTRL_VP_CLK_EN				(1 << 15)
-#define CSI2_CTRL_NON_POSTED_WRITE			(1 << 13)
-#define CSI2_CTRL_VP_ONLY_EN				(1 << 11)
+#define CSI2_CTRL_BURST_SIZE_EXPAND			(BIT(16))
+#define CSI2_CTRL_VP_CLK_EN				(BIT(15))
+#define CSI2_CTRL_NON_POSTED_WRITE			(BIT(13))
+#define CSI2_CTRL_VP_ONLY_EN				(BIT(11))
 #define CSI2_CTRL_VP_OUT_CTRL_MASK			(3 << 8)
 #define CSI2_CTRL_VP_OUT_CTRL_SHIFT			8
-#define CSI2_CTRL_DBG_EN				(1 << 7)
+#define CSI2_CTRL_DBG_EN				(BIT(7))
 #define CSI2_CTRL_BURST_SIZE_MASK			(3 << 5)
-#define CSI2_CTRL_ENDIANNESS				(1 << 4)
-#define CSI2_CTRL_FRAME					(1 << 3)
-#define CSI2_CTRL_ECC_EN				(1 << 2)
-#define CSI2_CTRL_IF_EN					(1 << 0)
+#define CSI2_CTRL_ENDIANNESS				(BIT(4))
+#define CSI2_CTRL_FRAME					(BIT(3))
+#define CSI2_CTRL_ECC_EN				(BIT(2))
+#define CSI2_CTRL_IF_EN					(BIT(0))
 
 #define CSI2_DBG_H					0x44
 
 #define CSI2_COMPLEXIO_CFG				0x50
-#define CSI2_COMPLEXIO_CFG_RESET_CTRL			(1 << 30)
-#define CSI2_COMPLEXIO_CFG_RESET_DONE			(1 << 29)
+#define CSI2_COMPLEXIO_CFG_RESET_CTRL			(BIT(30))
+#define CSI2_COMPLEXIO_CFG_RESET_DONE			(BIT(29))
 #define CSI2_COMPLEXIO_CFG_PWD_CMD_MASK			(3 << 27)
 #define CSI2_COMPLEXIO_CFG_PWD_CMD_OFF			(0 << 27)
-#define CSI2_COMPLEXIO_CFG_PWD_CMD_ON			(1 << 27)
+#define CSI2_COMPLEXIO_CFG_PWD_CMD_ON			(BIT(27))
 #define CSI2_COMPLEXIO_CFG_PWD_CMD_ULP			(2 << 27)
 #define CSI2_COMPLEXIO_CFG_PWD_STATUS_MASK		(3 << 25)
 #define CSI2_COMPLEXIO_CFG_PWD_STATUS_OFF		(0 << 25)
-#define CSI2_COMPLEXIO_CFG_PWD_STATUS_ON		(1 << 25)
+#define CSI2_COMPLEXIO_CFG_PWD_STATUS_ON		(BIT(25))
 #define CSI2_COMPLEXIO_CFG_PWD_STATUS_ULP		(2 << 25)
-#define CSI2_COMPLEXIO_CFG_PWR_AUTO			(1 << 24)
-#define CSI2_COMPLEXIO_CFG_DATA_POL(i)			(1 << (((i) * 4) + 3))
+#define CSI2_COMPLEXIO_CFG_PWR_AUTO			(BIT(24))
+#define CSI2_COMPLEXIO_CFG_DATA_POL(i)			(BIT((((i) * 4) + 3)))
 #define CSI2_COMPLEXIO_CFG_DATA_POSITION_MASK(i)	(7 << ((i) * 4))
 #define CSI2_COMPLEXIO_CFG_DATA_POSITION_SHIFT(i)	((i) * 4)
-#define CSI2_COMPLEXIO_CFG_CLOCK_POL			(1 << 3)
+#define CSI2_COMPLEXIO_CFG_CLOCK_POL			(BIT(3))
 #define CSI2_COMPLEXIO_CFG_CLOCK_POSITION_MASK		(7 << 0)
 #define CSI2_COMPLEXIO_CFG_CLOCK_POSITION_SHIFT		0
 
@@ -218,7 +218,7 @@
 		(0x3 << CSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT)
 #define CSI2_CTX_CTRL2_VIRTUAL_ID_MASK			(3 << 11)
 #define CSI2_CTX_CTRL2_VIRTUAL_ID_SHIFT			11
-#define CSI2_CTX_CTRL2_DPCM_PRED			(1 << 10)
+#define CSI2_CTX_CTRL2_DPCM_PRED			(BIT(10))
 #define CSI2_CTX_CTRL2_FORMAT_MASK			(0x3ff << 0)
 #define CSI2_CTX_CTRL2_FORMAT_SHIFT			0
 
Quoted 10 lines

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

Quoted 6 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
@@ -259,9 +259,9 @@
 #define ISP5_SYSCONFIG					(0x0010)
 #define ISP5_SYSCONFIG_STANDBYMODE_MASK			(3 << 4)
 #define ISP5_SYSCONFIG_STANDBYMODE_FORCE		(0 << 4)
-#define ISP5_SYSCONFIG_STANDBYMODE_NO			(1 << 4)
+#define ISP5_SYSCONFIG_STANDBYMODE_NO			(BIT(4))

"Standby mode is forced by clearing 3 bits at index 4. Smart mode is set by setting 2 as value for those bits. No standby mode is an entirely different story: set bit 4 of ISP5_SYSCONFIG."

Since iam a noob, i have this question, what's better, to leave (1 << 4) alone since it looks familiar between the rest,

or since BIT(4) already sets HIGH bit at bit 4, we better use the macro though it might look as an odd in the pattern?

Thanks for clarifying the code, much help to understand this a bit.

Quoted 127 lines
Quoted 127 lines
drivers/staging/media/omap4iss/iss_regs.h +17 -17
 #define ISP5_SYSCONFIG_STANDBYMODE_SMART		(2 << 4)
-#define ISP5_SYSCONFIG_SOFTRESET			(1 << 1)
+#define ISP5_SYSCONFIG_SOFTRESET			(BIT(1))
 
 #define ISP5_IRQSTATUS(i)				(0x0028 + (0x10 * (i)))
 #define ISP5_IRQENABLE_SET(i)				(0x002c + (0x10 * (i)))
@@ -315,14 +315,14 @@
 #define ISIF_MODESET					(0x0004)
 #define ISIF_MODESET_INPMOD_MASK			(3 << 12)
 #define ISIF_MODESET_INPMOD_RAW				(0 << 12)
-#define ISIF_MODESET_INPMOD_YCBCR16			(1 << 12)
+#define ISIF_MODESET_INPMOD_YCBCR16			(BIT(12))
 #define ISIF_MODESET_INPMOD_YCBCR8			(2 << 12)
 #define ISIF_MODESET_CCDW_MASK				(7 << 8)
 #define ISIF_MODESET_CCDW_2BIT				(2 << 8)
-#define ISIF_MODESET_CCDMD				(1 << 7)
-#define ISIF_MODESET_SWEN				(1 << 5)
-#define ISIF_MODESET_HDPOL				(1 << 3)
-#define ISIF_MODESET_VDPOL				(1 << 2)
+#define ISIF_MODESET_CCDMD				(BIT(7))
+#define ISIF_MODESET_SWEN				(BIT(5))
+#define ISIF_MODESET_HDPOL				(BIT(3))
+#define ISIF_MODESET_VDPOL				(BIT(2))
 
 #define ISIF_SPH					(0x0018)
 #define ISIF_SPH_MASK					(0x7fff)
@@ -345,19 +345,19 @@
 
 #define ISIF_CCOLP					(0x004c)
 #define ISIF_CCOLP_CP0_F0_R				(0 << 6)
-#define ISIF_CCOLP_CP0_F0_GR				(1 << 6)
+#define ISIF_CCOLP_CP0_F0_GR				(BIT(6))
 #define ISIF_CCOLP_CP0_F0_B				(3 << 6)
 #define ISIF_CCOLP_CP0_F0_GB				(2 << 6)
 #define ISIF_CCOLP_CP1_F0_R				(0 << 4)
-#define ISIF_CCOLP_CP1_F0_GR				(1 << 4)
+#define ISIF_CCOLP_CP1_F0_GR				(BIT(4))
 #define ISIF_CCOLP_CP1_F0_B				(3 << 4)
 #define ISIF_CCOLP_CP1_F0_GB				(2 << 4)
 #define ISIF_CCOLP_CP2_F0_R				(0 << 2)
-#define ISIF_CCOLP_CP2_F0_GR				(1 << 2)
+#define ISIF_CCOLP_CP2_F0_GR				(BIT(2))
 #define ISIF_CCOLP_CP2_F0_B				(3 << 2)
 #define ISIF_CCOLP_CP2_F0_GB				(2 << 2)
 #define ISIF_CCOLP_CP3_F0_R				(0 << 0)
-#define ISIF_CCOLP_CP3_F0_GR				(1 << 0)
+#define ISIF_CCOLP_CP3_F0_GR				(BIT(0))
 #define ISIF_CCOLP_CP3_F0_B				(3 << 0)
 #define ISIF_CCOLP_CP3_F0_GB				(2 << 0)
 
@@ -377,12 +377,12 @@
 #define IPIPEIF_CFG1					(0x0004)
 #define IPIPEIF_CFG1_INPSRC1_MASK			(3 << 14)
 #define IPIPEIF_CFG1_INPSRC1_VPORT_RAW			(0 << 14)
-#define IPIPEIF_CFG1_INPSRC1_SDRAM_RAW			(1 << 14)
+#define IPIPEIF_CFG1_INPSRC1_SDRAM_RAW			(BIT(14))
 #define IPIPEIF_CFG1_INPSRC1_ISIF_DARKFM		(2 << 14)
 #define IPIPEIF_CFG1_INPSRC1_SDRAM_YUV			(3 << 14)
 #define IPIPEIF_CFG1_INPSRC2_MASK			(3 << 2)
 #define IPIPEIF_CFG1_INPSRC2_ISIF			(0 << 2)
-#define IPIPEIF_CFG1_INPSRC2_SDRAM_RAW			(1 << 2)
+#define IPIPEIF_CFG1_INPSRC2_SDRAM_RAW			(BIT(2))
 #define IPIPEIF_CFG1_INPSRC2_ISIF_DARKFM		(2 << 2)
 #define IPIPEIF_CFG1_INPSRC2_SDRAM_YUV			(3 << 2)
 
@@ -406,25 +406,25 @@
 
 #define IPIPE_SRC_FMT					(0x0008)
 #define IPIPE_SRC_FMT_RAW2YUV				(0 << 0)
-#define IPIPE_SRC_FMT_RAW2RAW				(1 << 0)
+#define IPIPE_SRC_FMT_RAW2RAW				(BIT(0))
 #define IPIPE_SRC_FMT_RAW2STATS				(2 << 0)
 #define IPIPE_SRC_FMT_YUV2YUV				(3 << 0)
 
 #define IPIPE_SRC_COL					(0x000c)
 #define IPIPE_SRC_COL_OO_R				(0 << 6)
-#define IPIPE_SRC_COL_OO_GR				(1 << 6)
+#define IPIPE_SRC_COL_OO_GR				(BIT(6))
 #define IPIPE_SRC_COL_OO_B				(3 << 6)
 #define IPIPE_SRC_COL_OO_GB				(2 << 6)
 #define IPIPE_SRC_COL_OE_R				(0 << 4)
-#define IPIPE_SRC_COL_OE_GR				(1 << 4)
+#define IPIPE_SRC_COL_OE_GR				(BIT(4))
 #define IPIPE_SRC_COL_OE_B				(3 << 4)
 #define IPIPE_SRC_COL_OE_GB				(2 << 4)
 #define IPIPE_SRC_COL_EO_R				(0 << 2)
-#define IPIPE_SRC_COL_EO_GR				(1 << 2)
+#define IPIPE_SRC_COL_EO_GR				(BIT(2))
 #define IPIPE_SRC_COL_EO_B				(3 << 2)
 #define IPIPE_SRC_COL_EO_GB				(2 << 2)
 #define IPIPE_SRC_COL_EE_R				(0 << 0)
-#define IPIPE_SRC_COL_EE_GR				(1 << 0)
+#define IPIPE_SRC_COL_EE_GR				(BIT(0))
 #define IPIPE_SRC_COL_EE_B				(3 << 0)
 #define IPIPE_SRC_COL_EE_GB				(2 << 0)
 
drivers/staging/media/omap4iss/iss_video.h +6 -6
index 8b3dd92021e1..c0d021636224 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 {
 
Quoted 11 lines

drivers/staging/media/omap4iss/iss_video.h struct iss_buffer { · line 126

Quoted 8 lines
drivers/staging/media/omap4iss/iss_video.h +2 -2
 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)),
 };

No need for parentheses in all the hunks above.

Absolutely right.

Thank You!

Sam

#3 lore raw
Quoted 16 lines
Quoted 16 lines

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

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..7adc944e1a5d 100644
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

Quoted 7 lines
Quoted 5 lines

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

Oh, So defining BIT(2) totally changed the logic?

I'm not sure what you mean by "the logic". BIT is nice to use when there area a lot of 1 << X, because it makes clear which different its are relevant. When 1 << X is mixed with other things, it breaks the pattern to suddenly use BIT for one of them.

julia

#4 lore raw
Quoted 22 lines · Julia Lawall
Quoted 22 lines
Quoted 21 lines

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

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..7adc944e1a5d 100644
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

Quoted 6 lines
Quoted 1 line

Oh, So defining BIT(2) totally changed the logic?

I'm not sure what you mean by "the logic". BIT is nice to use when there area a lot of 1 << X, because it makes clear which different its are relevant. When 1 << X is mixed with other things, it breaks the pattern to suddenly use BIT for one of them.

I should have said "the implicit meaning".

Or as i questioned it's about the pattern to better leave it and choose the pattern over the change in cases like this?

Sam

Quoted 2 lines

julia

#5 lore raw
Quoted 30 lines · Sam Muhammed
Quoted 22 lines · Julia Lawall
Quoted 22 lines
Quoted 21 lines

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

Quoted 11 lines
drivers/staging/media/omap4iss/iss_regs.h +1 -1
index 09a7375c89ac..7adc944e1a5d 100644
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

Quoted 6 lines
Quoted 1 line

Oh, So defining BIT(2) totally changed the logic?

I'm not sure what you mean by "the logic". BIT is nice to use when there area a lot of 1 << X, because it makes clear which different its are relevant. When 1 << X is mixed with other things, it breaks the pattern to suddenly use BIT for one of them.

Quoted 4 lines

I should have said "the implicit meaning".

Or as i questioned it's about the pattern to better leave it and choose the pattern over the change in cases like this?

Yes, it's better to respect the local pattern.

julia

#6 lore raw
In reply to Sam Muhammed
Quoted 19 lines · On Mon, 30 Mar 2020 07:40:22 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 18 lines · Stefano Brivio

On Thu, 26 Mar 2020 17:02:47 -0400
Sam Muhammed <[email protected]> wrote:

[...]

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

Quoted 8 lines

+++ b/drivers/staging/media/omap4iss/iss_regs.h

drivers/staging/media/omap4iss/iss_regs.h +1 -1
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)  

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

Quoted 6 lines
Quoted 4 lines

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

Oh, So defining BIT(2) totally changed the logic?

No, it has no functional effect. And I also don't care too much about "the pattern" here -- I would just recommend that you practice actually reading code stuff before you change it :) So:

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?

Quoted 11 lines

[...]

Quoted 3 lines

Also no need for parentheses around BIT().

[...]

Quoted 4 lines

"Standby mode is forced by clearing 3 bits at index 4. Smart mode is set by setting 2 as value for those bits. No standby mode is an entirely different story: set bit 4 of ISP5_SYSCONFIG."

Quoted 5 lines

Since iam a noob, i have this question, what's better, to leave (1 << 4) alone since it looks familiar between the rest,

or since BIT(4) already sets HIGH bit at bit 4, we better use the macro though it might look as an odd in the pattern?

Same here, I'm not exceedingly interested in the pattern or how it looks like -- with your change, it would still work, but it would make no sense.

Quoted 1 line

Thanks for clarifying the code, much help to understand this a bit.

Sorry, that's why I quoted my "explanation": that's how one would read it after your change.

That is, the "No standby mode is an entirely different story" part is how one would read the code after your change, and... it's wrong! :)

Signature · 1 line
Stefano
#7 lore raw
Quoted 84 lines · Stefano Brivio
Quoted 19 lines · On Mon, 30 Mar 2020 07:40:22 -0400 Sam Muhammed <[email protected]> wrote:
Quoted 18 lines · Stefano Brivio

On Thu, 26 Mar 2020 17:02:47 -0400
Sam Muhammed <[email protected]> wrote:

[...]

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

Quoted 8 lines

+++ b/drivers/staging/media/omap4iss/iss_regs.h

drivers/staging/media/omap4iss/iss_regs.h +1 -1
@@ -38,7 +38,7 @@
 #define ISS_CTRL_CLK_DIV_MASK				(3 << 4)
 #define ISS_CTRL_INPUT_SEL_MASK				(3 << 2)
 #define ISS_CTRL_INPUT_SEL_CSI2A			(0 << 2)
-#define ISS_CTRL_INPUT_SEL_CSI2B			(1 << 2)
+#define ISS_CTRL_INPUT_SEL_CSI2B			(BIT(2))
 #define ISS_CTRL_SYNC_DETECT_VS_RAISING			(3 << 0)  

The existing code is saying: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected, and 1 means CSI2B is selected.

Quoted 6 lines
Quoted 4 lines

You're changing it to: there are three bits to select the input, starting from bit number 2. For those three bits, 0 means the CSI2A input is selected. CSI2B is a special case, though: register bit 2 needs to be set.

Oh, So defining BIT(2) totally changed the logic?

No, it has no functional effect. And I also don't care too much about "the pattern" here -- I would just recommend that you practice actually reading code stuff before you change it :) So:

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)
Quoted 7 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?

The difference is somehow clear now, Thanks for clarifying!

Quoted 17 lines
Quoted 11 lines

[...]

Quoted 3 lines

Also no need for parentheses around BIT().

[...]

Quoted 4 lines

"Standby mode is forced by clearing 3 bits at index 4. Smart mode is set by setting 2 as value for those bits. No standby mode is an entirely different story: set bit 4 of ISP5_SYSCONFIG."

Quoted 5 lines

Since iam a noob, i have this question, what's better, to leave (1 << 4) alone since it looks familiar between the rest,

or since BIT(4) already sets HIGH bit at bit 4, we better use the macro though it might look as an odd in the pattern?

Quoted 9 lines

Same here, I'm not exceedingly interested in the pattern or how it looks like -- with your change, it would still work, but it would make no sense.

Quoted 1 line

Thanks for clarifying the code, much help to understand this a bit.

Sorry, that's why I quoted my "explanation": that's how one would read it after your change.

Well, That's a different perspective that i needed to test the change, that it's not enough to just _build it_ and i'am afraid i would never have this perspective in mind since iam only making minor changes, and some implications of these changes are not visible to me until it's pointed out.

I guess that's why i send a patch and wait for review :)

Quoted 3 lines

That is, the "No standby mode is an entirely different story" part is how one would read the code after your change, and... it's wrong! :)

Thank You.

Sam