Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

media: i2c: imx290: Split control initialization to separate function

The imx290_probe() function is too large. Split control initialzation to
a dedicated function to increase code readability.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Alexander Stein <alexander.stein@ew.tq-group.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

authored by

Laurent Pinchart and committed by
Sakari Ailus
72c87b7a 6d7a87f2

+61 -48
+61 -48
drivers/media/i2c/imx290.c
··· 878 878 .link_validate = v4l2_subdev_link_validate, 879 879 }; 880 880 881 + static int imx290_ctrl_init(struct imx290 *imx290) 882 + { 883 + int ret; 884 + 885 + v4l2_ctrl_handler_init(&imx290->ctrls, 5); 886 + imx290->ctrls.lock = &imx290->lock; 887 + 888 + /* 889 + * The sensor has an analog gain and a digital gain, both controlled 890 + * through a single gain value, expressed in 0.3dB increments. Values 891 + * from 0.0dB (0) to 30.0dB (100) apply analog gain only, higher values 892 + * up to 72.0dB (240) add further digital gain. Limit the range to 893 + * analog gain only, support for digital gain can be added separately 894 + * if needed. 895 + * 896 + * The IMX327 and IMX462 are largely compatible with the IMX290, but 897 + * have an analog gain range of 0.0dB to 29.4dB and 42dB of digital 898 + * gain. When support for those sensors gets added to the driver, the 899 + * gain control should be adjusted accordingly. 900 + */ 901 + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, 902 + V4L2_CID_GAIN, 0, 100, 1, 0); 903 + 904 + v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, 905 + V4L2_CID_EXPOSURE, 1, IMX290_VMAX_DEFAULT - 2, 1, 906 + IMX290_VMAX_DEFAULT - 2); 907 + 908 + imx290->link_freq = 909 + v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops, 910 + V4L2_CID_LINK_FREQ, 911 + imx290_link_freqs_num(imx290) - 1, 0, 912 + imx290_link_freqs_ptr(imx290)); 913 + if (imx290->link_freq) 914 + imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; 915 + 916 + imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, 917 + V4L2_CID_PIXEL_RATE, 918 + 1, INT_MAX, 1, 919 + imx290_calc_pixel_rate(imx290)); 920 + 921 + v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops, 922 + V4L2_CID_TEST_PATTERN, 923 + ARRAY_SIZE(imx290_test_pattern_menu) - 1, 924 + 0, 0, imx290_test_pattern_menu); 925 + 926 + imx290->sd.ctrl_handler = &imx290->ctrls; 927 + 928 + if (imx290->ctrls.error) { 929 + ret = imx290->ctrls.error; 930 + v4l2_ctrl_handler_free(&imx290->ctrls); 931 + return ret; 932 + } 933 + 934 + return 0; 935 + } 936 + 881 937 /* 882 938 * Returns 0 if all link frequencies used by the driver for the given number 883 939 * of MIPI data lanes are mentioned in the device tree, or the value of the ··· 1072 1016 */ 1073 1017 imx290_entity_init_cfg(&imx290->sd, NULL); 1074 1018 1075 - v4l2_ctrl_handler_init(&imx290->ctrls, 5); 1076 - imx290->ctrls.lock = &imx290->lock; 1077 - 1078 - /* 1079 - * The sensor has an analog gain and a digital gain, both controlled 1080 - * through a single gain value, expressed in 0.3dB increments. Values 1081 - * from 0.0dB (0) to 30.0dB (100) apply analog gain only, higher values 1082 - * up to 72.0dB (240) add further digital gain. Limit the range to 1083 - * analog gain only, support for digital gain can be added separately 1084 - * if needed. 1085 - * 1086 - * The IMX327 and IMX462 are largely compatible with the IMX290, but 1087 - * have an analog gain range of 0.0dB to 29.4dB and 42dB of digital 1088 - * gain. When support for those sensors gets added to the driver, the 1089 - * gain control should be adjusted accordingly. 1090 - */ 1091 - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, 1092 - V4L2_CID_GAIN, 0, 100, 1, 0); 1093 - 1094 - v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, 1095 - V4L2_CID_EXPOSURE, 1, IMX290_VMAX_DEFAULT - 2, 1, 1096 - IMX290_VMAX_DEFAULT - 2); 1097 - 1098 - imx290->link_freq = 1099 - v4l2_ctrl_new_int_menu(&imx290->ctrls, &imx290_ctrl_ops, 1100 - V4L2_CID_LINK_FREQ, 1101 - imx290_link_freqs_num(imx290) - 1, 0, 1102 - imx290_link_freqs_ptr(imx290)); 1103 - if (imx290->link_freq) 1104 - imx290->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; 1105 - 1106 - imx290->pixel_rate = v4l2_ctrl_new_std(&imx290->ctrls, &imx290_ctrl_ops, 1107 - V4L2_CID_PIXEL_RATE, 1108 - 1, INT_MAX, 1, 1109 - imx290_calc_pixel_rate(imx290)); 1110 - 1111 - v4l2_ctrl_new_std_menu_items(&imx290->ctrls, &imx290_ctrl_ops, 1112 - V4L2_CID_TEST_PATTERN, 1113 - ARRAY_SIZE(imx290_test_pattern_menu) - 1, 1114 - 0, 0, imx290_test_pattern_menu); 1115 - 1116 - imx290->sd.ctrl_handler = &imx290->ctrls; 1117 - 1118 - if (imx290->ctrls.error) { 1119 - dev_err(dev, "Control initialization error %d\n", 1120 - imx290->ctrls.error); 1121 - ret = imx290->ctrls.error; 1122 - goto free_ctrl; 1019 + ret = imx290_ctrl_init(imx290); 1020 + if (ret < 0) { 1021 + dev_err(dev, "Control initialization error %d\n", ret); 1022 + goto free_mutex; 1123 1023 } 1124 1024 1125 1025 v4l2_i2c_subdev_init(&imx290->sd, client, &imx290_subdev_ops); ··· 1116 1104 media_entity_cleanup(&imx290->sd.entity); 1117 1105 free_ctrl: 1118 1106 v4l2_ctrl_handler_free(&imx290->ctrls); 1107 + free_mutex: 1119 1108 mutex_destroy(&imx290->lock); 1120 1109 free_err: 1121 1110 v4l2_fwnode_endpoint_free(&ep);