diff mbox series

media: rkisp1: Add and use rkisp1_has_feature() macro

Message ID 20220719222432.4356-1-laurent.pinchart@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series media: rkisp1: Add and use rkisp1_has_feature() macro | expand

Commit Message

Laurent Pinchart July 19, 2022, 10:24 p.m. UTC
Simplify feature tests with a macro that shortens lines.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Sending to the correct mailing list this time, sorry for the noise.
---
 .../media/platform/rockchip/rkisp1/rkisp1-common.h |  3 +++
 .../media/platform/rockchip/rkisp1/rkisp1-dev.c    | 14 +++++++-------
 2 files changed, 10 insertions(+), 7 deletions(-)

Comments

Paul Elder July 20, 2022, 10:12 a.m. UTC | #1
Hi Laurent,

On Wed, Jul 20, 2022 at 01:24:32AM +0300, Laurent Pinchart wrote:
> Simplify feature tests with a macro that shortens lines.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>

> ---
> Sending to the correct mailing list this time, sorry for the noise.
> ---
>  .../media/platform/rockchip/rkisp1/rkisp1-common.h |  3 +++
>  .../media/platform/rockchip/rkisp1/rkisp1-dev.c    | 14 +++++++-------
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
> index 8056997d5c29..0aae802464ac 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
> @@ -111,6 +111,9 @@ enum rkisp1_feature {
>  	RKISP1_FEATURE_MIPI_CSI2 = BIT(0),
>  };
>  
> +#define rkisp1_has_feature(rkisp1, feature) \
> +	((rkisp1)->info->features & RKISP1_FEATURE_##feature)
> +
>  /*
>   * struct rkisp1_info - Model-specific ISP Information
>   *
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
> index f2475c6235ea..e348d8c86861 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
> @@ -206,7 +206,7 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
>  		switch (reg) {
>  		case 0:
>  			/* MIPI CSI-2 port */
> -			if (!(rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)) {
> +			if (!rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>  				dev_err(rkisp1->dev,
>  					"internal CSI must be available for port 0\n");
>  				ret = -EINVAL;
> @@ -338,7 +338,7 @@ static int rkisp1_create_links(struct rkisp1_device *rkisp1)
>  	unsigned int i;
>  	int ret;
>  
> -	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
> +	if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>  		/* Link the CSI receiver to the ISP. */
>  		ret = media_create_pad_link(&rkisp1->csi.sd.entity,
>  					    RKISP1_CSI_PAD_SRC,
> @@ -390,7 +390,7 @@ static int rkisp1_create_links(struct rkisp1_device *rkisp1)
>  
>  static void rkisp1_entities_unregister(struct rkisp1_device *rkisp1)
>  {
> -	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
> +	if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
>  		rkisp1_csi_unregister(rkisp1);
>  	rkisp1_params_unregister(rkisp1);
>  	rkisp1_stats_unregister(rkisp1);
> @@ -423,7 +423,7 @@ static int rkisp1_entities_register(struct rkisp1_device *rkisp1)
>  	if (ret)
>  		goto error;
>  
> -	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
> +	if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>  		ret = rkisp1_csi_register(rkisp1);
>  		if (ret)
>  			goto error;
> @@ -590,7 +590,7 @@ static int rkisp1_probe(struct platform_device *pdev)
>  		goto err_unreg_v4l2_dev;
>  	}
>  
> -	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
> +	if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>  		ret = rkisp1_csi_init(rkisp1);
>  		if (ret)
>  			goto err_unreg_media_dev;
> @@ -611,7 +611,7 @@ static int rkisp1_probe(struct platform_device *pdev)
>  err_unreg_entities:
>  	rkisp1_entities_unregister(rkisp1);
>  err_cleanup_csi:
> -	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
> +	if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
>  		rkisp1_csi_cleanup(rkisp1);
>  err_unreg_media_dev:
>  	media_device_unregister(&rkisp1->media_dev);
> @@ -630,7 +630,7 @@ static int rkisp1_remove(struct platform_device *pdev)
>  	v4l2_async_nf_cleanup(&rkisp1->notifier);
>  
>  	rkisp1_entities_unregister(rkisp1);
> -	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
> +	if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
>  		rkisp1_csi_cleanup(rkisp1);
>  	rkisp1_debug_cleanup(rkisp1);
Kieran Bingham July 20, 2022, 12:48 p.m. UTC | #2
Quoting Laurent Pinchart (2022-07-19 23:24:32)
> Simplify feature tests with a macro that shortens lines.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Given how we use it on VSP1 too, I certainly prefer this style of
helper!

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>


> ---
> Sending to the correct mailing list this time, sorry for the noise.
> ---
>  .../media/platform/rockchip/rkisp1/rkisp1-common.h |  3 +++
>  .../media/platform/rockchip/rkisp1/rkisp1-dev.c    | 14 +++++++-------
>  2 files changed, 10 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
> index 8056997d5c29..0aae802464ac 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
> @@ -111,6 +111,9 @@ enum rkisp1_feature {
>         RKISP1_FEATURE_MIPI_CSI2 = BIT(0),
>  };
>  
> +#define rkisp1_has_feature(rkisp1, feature) \
> +       ((rkisp1)->info->features & RKISP1_FEATURE_##feature)
> +
>  /*
>   * struct rkisp1_info - Model-specific ISP Information
>   *
> diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
> index f2475c6235ea..e348d8c86861 100644
> --- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
> +++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
> @@ -206,7 +206,7 @@ static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
>                 switch (reg) {
>                 case 0:
>                         /* MIPI CSI-2 port */
> -                       if (!(rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)) {
> +                       if (!rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>                                 dev_err(rkisp1->dev,
>                                         "internal CSI must be available for port 0\n");
>                                 ret = -EINVAL;
> @@ -338,7 +338,7 @@ static int rkisp1_create_links(struct rkisp1_device *rkisp1)
>         unsigned int i;
>         int ret;
>  
> -       if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
> +       if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>                 /* Link the CSI receiver to the ISP. */
>                 ret = media_create_pad_link(&rkisp1->csi.sd.entity,
>                                             RKISP1_CSI_PAD_SRC,
> @@ -390,7 +390,7 @@ static int rkisp1_create_links(struct rkisp1_device *rkisp1)
>  
>  static void rkisp1_entities_unregister(struct rkisp1_device *rkisp1)
>  {
> -       if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
> +       if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
>                 rkisp1_csi_unregister(rkisp1);
>         rkisp1_params_unregister(rkisp1);
>         rkisp1_stats_unregister(rkisp1);
> @@ -423,7 +423,7 @@ static int rkisp1_entities_register(struct rkisp1_device *rkisp1)
>         if (ret)
>                 goto error;
>  
> -       if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
> +       if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>                 ret = rkisp1_csi_register(rkisp1);
>                 if (ret)
>                         goto error;
> @@ -590,7 +590,7 @@ static int rkisp1_probe(struct platform_device *pdev)
>                 goto err_unreg_v4l2_dev;
>         }
>  
> -       if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
> +       if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
>                 ret = rkisp1_csi_init(rkisp1);
>                 if (ret)
>                         goto err_unreg_media_dev;
> @@ -611,7 +611,7 @@ static int rkisp1_probe(struct platform_device *pdev)
>  err_unreg_entities:
>         rkisp1_entities_unregister(rkisp1);
>  err_cleanup_csi:
> -       if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
> +       if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
>                 rkisp1_csi_cleanup(rkisp1);
>  err_unreg_media_dev:
>         media_device_unregister(&rkisp1->media_dev);
> @@ -630,7 +630,7 @@ static int rkisp1_remove(struct platform_device *pdev)
>         v4l2_async_nf_cleanup(&rkisp1->notifier);
>  
>         rkisp1_entities_unregister(rkisp1);
> -       if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
> +       if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
>                 rkisp1_csi_cleanup(rkisp1);
>         rkisp1_debug_cleanup(rkisp1);
>  
> -- 
> Regards,
> 
> Laurent Pinchart
>
diff mbox series

Patch

diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
index 8056997d5c29..0aae802464ac 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-common.h
@@ -111,6 +111,9 @@  enum rkisp1_feature {
 	RKISP1_FEATURE_MIPI_CSI2 = BIT(0),
 };
 
+#define rkisp1_has_feature(rkisp1, feature) \
+	((rkisp1)->info->features & RKISP1_FEATURE_##feature)
+
 /*
  * struct rkisp1_info - Model-specific ISP Information
  *
diff --git a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
index f2475c6235ea..e348d8c86861 100644
--- a/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
+++ b/drivers/media/platform/rockchip/rkisp1/rkisp1-dev.c
@@ -206,7 +206,7 @@  static int rkisp1_subdev_notifier_register(struct rkisp1_device *rkisp1)
 		switch (reg) {
 		case 0:
 			/* MIPI CSI-2 port */
-			if (!(rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)) {
+			if (!rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
 				dev_err(rkisp1->dev,
 					"internal CSI must be available for port 0\n");
 				ret = -EINVAL;
@@ -338,7 +338,7 @@  static int rkisp1_create_links(struct rkisp1_device *rkisp1)
 	unsigned int i;
 	int ret;
 
-	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
+	if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
 		/* Link the CSI receiver to the ISP. */
 		ret = media_create_pad_link(&rkisp1->csi.sd.entity,
 					    RKISP1_CSI_PAD_SRC,
@@ -390,7 +390,7 @@  static int rkisp1_create_links(struct rkisp1_device *rkisp1)
 
 static void rkisp1_entities_unregister(struct rkisp1_device *rkisp1)
 {
-	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
+	if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
 		rkisp1_csi_unregister(rkisp1);
 	rkisp1_params_unregister(rkisp1);
 	rkisp1_stats_unregister(rkisp1);
@@ -423,7 +423,7 @@  static int rkisp1_entities_register(struct rkisp1_device *rkisp1)
 	if (ret)
 		goto error;
 
-	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
+	if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
 		ret = rkisp1_csi_register(rkisp1);
 		if (ret)
 			goto error;
@@ -590,7 +590,7 @@  static int rkisp1_probe(struct platform_device *pdev)
 		goto err_unreg_v4l2_dev;
 	}
 
-	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2) {
+	if (rkisp1_has_feature(rkisp1, MIPI_CSI2)) {
 		ret = rkisp1_csi_init(rkisp1);
 		if (ret)
 			goto err_unreg_media_dev;
@@ -611,7 +611,7 @@  static int rkisp1_probe(struct platform_device *pdev)
 err_unreg_entities:
 	rkisp1_entities_unregister(rkisp1);
 err_cleanup_csi:
-	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
+	if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
 		rkisp1_csi_cleanup(rkisp1);
 err_unreg_media_dev:
 	media_device_unregister(&rkisp1->media_dev);
@@ -630,7 +630,7 @@  static int rkisp1_remove(struct platform_device *pdev)
 	v4l2_async_nf_cleanup(&rkisp1->notifier);
 
 	rkisp1_entities_unregister(rkisp1);
-	if (rkisp1->info->features & RKISP1_FEATURE_MIPI_CSI2)
+	if (rkisp1_has_feature(rkisp1, MIPI_CSI2))
 		rkisp1_csi_cleanup(rkisp1);
 	rkisp1_debug_cleanup(rkisp1);