[PATCH v2 06/14] drm/tidss: dispc: Get rid of FLD_MOD

Maxime Ripard posted 14 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v2 06/14] drm/tidss: dispc: Get rid of FLD_MOD
Posted by Maxime Ripard 1 month, 2 weeks ago
The FLD_MOD function is an equivalent to what FIELD_MODIFY + GENMASK
provide, so let's drop it and switch to the latter.

Signed-off-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/tidss/tidss_dispc.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/tidss/tidss_dispc.c b/drivers/gpu/drm/tidss/tidss_dispc.c
index 50d5eda0670e6e090d05af6a2c05e5b88f28c322..fef56aed3f6edb6630d079f354821ada5fad327d 100644
--- a/drivers/gpu/drm/tidss/tidss_dispc.c
+++ b/drivers/gpu/drm/tidss/tidss_dispc.c
@@ -607,29 +607,21 @@ void tidss_disable_oldi(struct tidss_device *tidss, u32 hw_videoport)
 /*
  * TRM gives bitfields as start:end, where start is the higher bit
  * number. For example 7:0
  */
 
-#define FLD_MOD(orig, val, start, end)					\
-	({								\
-		int _start = (start), _end = (end);			\
-		u32 _masked_val = (orig) & ~GENMASK(_start, _end);	\
-		u32 _new_val = _masked_val | FIELD_PREP(GENMASK(_start, _end), (val)); \
-		_new_val;						\
-	})
-
 #define REG_GET(dispc, idx, start, end)					\
 	((u32)FIELD_GET(GENMASK((start), (end)),			\
 			dispc_read((dispc), (idx))))
 
 #define REG_FLD_MOD(dispc, idx, val, start, end)			\
 	({								\
 		struct dispc_device *_dispc = (dispc);			\
 		u32 _idx = (idx);					\
-		u32 _curr = dispc_read(_dispc, _idx);			\
-		u32 _new = FLD_MOD(_curr, (val), (start), (end));	\
-		dispc_write(_dispc, _idx, _new);			\
+		u32 _reg = dispc_read(_dispc, _idx);			\
+		FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
+		dispc_write(_dispc, _idx, _reg);			\
 	})
 
 #define VID_REG_GET(dispc, hw_plane, idx, start, end)			\
 	((u32)FIELD_GET(GENMASK((start), (end)),			\
 			dispc_vid_read((dispc), (hw_plane), (idx))))
@@ -637,13 +629,13 @@ void tidss_disable_oldi(struct tidss_device *tidss, u32 hw_videoport)
 #define VID_REG_FLD_MOD(dispc, hw_plane, idx, val, start, end)		\
 	({								\
 		struct dispc_device *_dispc = (dispc);			\
 		u32 _hw_plane = (hw_plane);				\
 		u32 _idx = (idx);					\
-		u32 _curr = dispc_vid_read(_dispc, _hw_plane, _idx);	\
-		u32 _new = FLD_MOD(_curr, (val), (start), (end));	\
-		dispc_vid_write(_dispc, _hw_plane, _idx, _new);		\
+		u32 _reg = dispc_vid_read(_dispc, _hw_plane, _idx);	\
+		FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
+		dispc_vid_write(_dispc, _hw_plane, _idx, _reg);		\
 	})
 
 #define VP_REG_GET(dispc, vp, idx, start, end)				\
 	((u32)FIELD_GET(GENMASK((start), (end)),			\
 			dispc_vp_read((dispc), (vp), (idx))))
@@ -651,23 +643,23 @@ void tidss_disable_oldi(struct tidss_device *tidss, u32 hw_videoport)
 #define VP_REG_FLD_MOD(dispc, vp, idx, val, start, end)			\
 	({								\
 		struct dispc_device *_dispc = (dispc);			\
 		u32 _vp = (vp);						\
 		u32 _idx = (idx);					\
-		u32 _curr = dispc_vp_read(_dispc, _vp, _idx);		\
-		u32 _new = FLD_MOD(_curr, (val), (start), (end));	\
-		dispc_vp_write(_dispc, _vp, _idx, _new);		\
+		u32 _reg = dispc_vp_read(_dispc, _vp, _idx);		\
+		FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
+		dispc_vp_write(_dispc, _vp, _idx, _reg);		\
 	})
 
 #define OVR_REG_FLD_MOD(dispc, ovr, idx, val, start, end)		\
 	({								\
 		struct dispc_device *_dispc = (dispc);			\
-		u32 _ovr = (ovr);						\
+		u32 _ovr = (ovr);					\
 		u32 _idx = (idx);					\
-		u32 _curr = dispc_ovr_read(_dispc, _ovr, _idx);		\
-		u32 _new = FLD_MOD(_curr, (val), (start), (end));	\
-		dispc_ovr_write(_dispc, _ovr, _idx, _new);		\
+		u32 _reg = dispc_ovr_read(_dispc, _ovr, _idx);		\
+		FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
+		dispc_ovr_write(_dispc, _ovr, _idx, _reg);		\
 	})
 
 static dispc_irq_t dispc_vp_irq_from_raw(u32 stat, u32 hw_videoport)
 {
 	dispc_irq_t vp_stat = 0;
@@ -1160,11 +1152,11 @@ static void dispc_enable_am65x_oldi(struct dispc_device *dispc, u32 hw_videoport
 		dev_warn(dispc->dev, "%s: %d port width not supported\n",
 			 __func__, fmt->data_width);
 
 	oldi_cfg |= BIT(7); /* DEPOL */
 
-	oldi_cfg = FLD_MOD(oldi_cfg, fmt->am65x_oldi_mode_reg_val, 3, 1);
+	FIELD_MODIFY(GENMASK(3, 1), &oldi_cfg, fmt->am65x_oldi_mode_reg_val);
 
 	oldi_cfg |= BIT(12); /* SOFTRST */
 
 	oldi_cfg |= BIT(0); /* ENABLE */
 

-- 
2.50.1
Re: [PATCH v2 06/14] drm/tidss: dispc: Get rid of FLD_MOD
Posted by kernel test robot 1 month, 1 week ago
Hi Maxime,

kernel test robot noticed the following build errors:

[auto build test ERROR on fbb0210d25fde20027f86a6ca9eee75630b5ac2b]

url:    https://github.com/intel-lab-lkp/linux/commits/Maxime-Ripard/drm-tidss-dispc-Remove-unused-OVR_REG_GET/20250820-220945
base:   fbb0210d25fde20027f86a6ca9eee75630b5ac2b
patch link:    https://lore.kernel.org/r/20250820-drm-tidss-field-api-v2-6-43cab671c648%40kernel.org
patch subject: [PATCH v2 06/14] drm/tidss: dispc: Get rid of FLD_MOD
config: xtensa-randconfig-001-20250821 (https://download.01.org/0day-ci/archive/20250821/202508212351.neQpMO5p-lkp@intel.com/config)
compiler: xtensa-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250821/202508212351.neQpMO5p-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508212351.neQpMO5p-lkp@intel.com/

All errors (new ones prefixed by >>):

   drivers/gpu/drm/tidss/tidss_dispc.c: In function 'dispc_set_num_datalines':
>> drivers/gpu/drm/tidss/tidss_dispc.c:649:17: error: implicit declaration of function 'FIELD_MODIFY' [-Werror=implicit-function-declaration]
     649 |                 FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));    \
         |                 ^~~~~~~~~~~~
   drivers/gpu/drm/tidss/tidss_dispc.c:1134:9: note: in expansion of macro 'VP_REG_FLD_MOD'
    1134 |         VP_REG_FLD_MOD(dispc, hw_videoport, DISPC_VP_CONTROL, v, 10, 8);
         |         ^~~~~~~~~~~~~~
   drivers/gpu/drm/tidss/tidss_dispc.c: In function 'dispc_vp_enable':
   drivers/gpu/drm/tidss/tidss_dispc.c:1219:24: error: implicit declaration of function 'FIELD_PREP' [-Werror=implicit-function-declaration]
    1219 |                        FIELD_PREP(GENMASK(7, 0), hsw - 1) |
         |                        ^~~~~~~~~~
   drivers/gpu/drm/tidss/tidss_dispc.c: In function 'dispc_vp_go_busy':
   drivers/gpu/drm/tidss/tidss_dispc.c:640:15: error: implicit declaration of function 'FIELD_GET' [-Werror=implicit-function-declaration]
     640 |         ((u32)FIELD_GET(GENMASK((start), (end)),                        \
         |               ^~~~~~~~~
   drivers/gpu/drm/tidss/tidss_dispc.c:1280:16: note: in expansion of macro 'VP_REG_GET'
    1280 |         return VP_REG_GET(dispc, hw_videoport, DISPC_VP_CONTROL, 5, 5);
         |                ^~~~~~~~~~
   cc1: some warnings being treated as errors


vim +/FIELD_MODIFY +649 drivers/gpu/drm/tidss/tidss_dispc.c

   606	
   607	/*
   608	 * TRM gives bitfields as start:end, where start is the higher bit
   609	 * number. For example 7:0
   610	 */
   611	
   612	#define REG_GET(dispc, idx, start, end)					\
   613		((u32)FIELD_GET(GENMASK((start), (end)),			\
   614				dispc_read((dispc), (idx))))
   615	
   616	#define REG_FLD_MOD(dispc, idx, val, start, end)			\
   617		({								\
   618			struct dispc_device *_dispc = (dispc);			\
   619			u32 _idx = (idx);					\
   620			u32 _reg = dispc_read(_dispc, _idx);			\
   621			FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
   622			dispc_write(_dispc, _idx, _reg);			\
   623		})
   624	
   625	#define VID_REG_GET(dispc, hw_plane, idx, start, end)			\
   626		((u32)FIELD_GET(GENMASK((start), (end)),			\
   627				dispc_vid_read((dispc), (hw_plane), (idx))))
   628	
   629	#define VID_REG_FLD_MOD(dispc, hw_plane, idx, val, start, end)		\
   630		({								\
   631			struct dispc_device *_dispc = (dispc);			\
   632			u32 _hw_plane = (hw_plane);				\
   633			u32 _idx = (idx);					\
   634			u32 _reg = dispc_vid_read(_dispc, _hw_plane, _idx);	\
   635			FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
   636			dispc_vid_write(_dispc, _hw_plane, _idx, _reg);		\
   637		})
   638	
   639	#define VP_REG_GET(dispc, vp, idx, start, end)				\
   640		((u32)FIELD_GET(GENMASK((start), (end)),			\
   641				dispc_vp_read((dispc), (vp), (idx))))
   642	
   643	#define VP_REG_FLD_MOD(dispc, vp, idx, val, start, end)			\
   644		({								\
   645			struct dispc_device *_dispc = (dispc);			\
   646			u32 _vp = (vp);						\
   647			u32 _idx = (idx);					\
   648			u32 _reg = dispc_vp_read(_dispc, _vp, _idx);		\
 > 649			FIELD_MODIFY(GENMASK((start), (end)), &_reg, (val));	\
   650			dispc_vp_write(_dispc, _vp, _idx, _reg);		\
   651		})
   652	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki